@neurcode-ai/cli 0.6.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,YAAY,kBA6CjC"}
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAsB,YAAY,kBAyDjC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.watchCommand = watchCommand;
4
4
  const Sentinel_1 = require("../services/watch/Sentinel");
5
+ const CommandPoller_1 = require("../services/watch/CommandPoller");
5
6
  /**
6
7
  * Watch command - Start the Neurcode Watch service
7
8
  *
@@ -15,6 +16,9 @@ async function watchCommand() {
15
16
  // Create and initialize Sentinel
16
17
  const sentinel = new Sentinel_1.Sentinel(projectRoot);
17
18
  await sentinel.initialize();
19
+ // Create and start CommandPoller for remote commands
20
+ const commandPoller = new CommandPoller_1.CommandPoller(projectRoot);
21
+ commandPoller.start();
18
22
  // Start watching
19
23
  await sentinel.start();
20
24
  console.log('āœ… Neurcode Watch is running...');
@@ -27,10 +31,18 @@ async function watchCommand() {
27
31
  console.log('šŸ“¦ Cloud sync: DISABLED (local-only mode)');
28
32
  console.log(' Run "neurcode config --key <your_api_key>" to enable cloud sync');
29
33
  }
34
+ // Check if command polling is configured
35
+ if (commandPoller.isConfigured()) {
36
+ console.log('šŸ”„ Remote commands: ENABLED (will execute revert commands from dashboard)');
37
+ }
38
+ else {
39
+ console.log('šŸ“¦ Remote commands: DISABLED (no API key configured)');
40
+ }
30
41
  console.log(' Press Ctrl+C to stop\n');
31
42
  // Handle graceful shutdown
32
43
  const shutdown = async () => {
33
44
  console.log('\nšŸ›‘ Shutting down...');
45
+ commandPoller.st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;QACpF,CAAC;QAED,yCAAyC;QACzC,IAAI,aAAa,CAAC,YAAY,EAAE,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,2EAA2E,CAAC,CAAC;QAC3F,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;QACtE,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;QAEzC,2BAA2B;QAC3B,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YACrC,aAAa,CAAC,IAAI,EAAE,CAAC;YACrB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEhC,yBAAyB;QACzB,6CAA6C;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * CommandPoller - Polls for remote commands and executes them locally
3
+ *
4
+ * Polls the cloud API every 3 seconds for pending commands (like file reverts).
5
+ * When a command is received, executes it locally and updates the status.
6
+ */
7
+ export interface Command {
8
+ id: string;
9
+ userId: string;
10
+ organizationId: string;
11
+ type: string;
12
+ payload: {
13
+ filePath: string;
14
+ blobHash: string;
15
+ };
16
+ status: string;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ }
20
+ export interface PollResponse {
21
+ command: Command | null;
22
+ }
23
+ /**
24
+ * CommandPoller - Handles polling and execution of remote commands
25
+ */
26
+ export declare class CommandPoller {
27
+ private apiUrl;
28
+ private apiKey;
29
+ private projectRoot;
30
+ private pollInterval;
31
+ private readonly pollIntervalMs;
32
+ private isRunning;
33
+ constructor(projectRoot: string);
34
+ /**
35
+ * Start polling for commands
36
+ */
37
+ start(): void;
38
+ /**
39
+ * Stop polling for commands
40
+ */
41
+ stop(): void;
42
+ /**
43
+ * Poll for pending commands and execute them
44
+ */
45
+ private poll;
46
+ /**
47
+ * Execute a command locally
48
+ */
49
+ private executeCommand;
50
+ /**
51
+ * Execute a FILE_REVERT command
52
+ */
53
+ private executeFileRevert;
54
+ /**
55
+ * Update command status on the server
56
+ */
57
+ private updateCommandStatus;
58
+ /**
59
+ * Check if poller is configured (has API key)
60
+ */
61
+ isConfigured(): boolean;
62
+ /**
63
+ * Reload API key from config (useful if user logs in after watch starts)
64
+ */
65
+ reloadConfig(): void;
66
+ }
67
+ //# sourceMappingURL=CommandPoller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandPoller.d.ts","sourceRoot":"","sources":["../../../src/services/watch/CommandPoller.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,SAAS,CAAkB;gBAEvB,WAAW,EAAE,MAAM;IAO/B;;OAEG;IACH,KAAK,IAAI,IAAI;IAsBb;;OAEG;IACH,IAAI,IAAI,IAAI;IASZ;;OAEG;YACW,IAAI;IAyClB;;OAEG;YACW,cAAc;IAe5B;;OAEG;YACW,iBAAiB;IA0B/B;;OAEG;YACW,mBAAmB;IA+BjC;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,YAAY,IAAI,IAAI;CAUrB"}
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ /**
3
+ * CommandPoller - Polls for remote commands and executes them locally
4
+ *
5
+ * Polls the cloud API every 3 seconds for pending commands (like file reverts).
6
+ * When a command is received, executes it locally and updates the status.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.CommandPoller = void 0;
43
+ const config_1 = require("../../config");
44
+ const restore_1 = require("../../utils/restore");
45
+ const path = __importStar(require("path"));
46
+ const fs_1 = require("fs");
47
+ /**
48
+ * CommandPoller - Handles polling and execution of remote commands
49
+ */
50
+ class CommandPoller {
51
+ apiUrl;
52
+ apiKey;
53
+ projectRoot;
54
+ pollInterval = null;
55
+ pollIntervalMs = 3000; // Poll every 3 seconds
56
+ isRunning = false;
57
+ constructor(projectRoot) {
58
+ this.projectRoot = projectRoot;
59
+ const config = (0, config_1.loadConfig)();
60
+ this.apiUrl = config.apiUrl || config_1.DEFAULT_API_URL;
61
+ this.apiKey = (0, config_1.getApiKey)();
62
+ }
63
+ /**
64
+ * Start polling for commands
65
+ */
66
+ start() {
67
+ if (this.isRunning) {
68
+ console.warn('āš ļø CommandPoller is already running');
69
+ return;
70
+ }
71
+ // If no API key, skip silently (local-only mode)
72
+ if (!this.apiKey) {
73
+ console.log('šŸ“¦ Command polling: DISABLED (no API key configured)');
74
+ return;
75
+ }
76
+ this.isRunning = true;
77
+ console.log('šŸ”„ Command polling: ENABLED (checking every 3s)');
78
+ // Start polling immediately, then every 3 seconds
79
+ this.poll();
80
+ this.pollInterval = setInterval(() => {
81
+ this.poll();
82
+ }, this.pollIntervalMs);
83
+ }
84
+ /**
85
+ * Stop polling for commands
86
+ */
87
+ stop() {
88
+ if (this.pollInterval) {
89
+ clearInterval(this.pollInterval);
90
+ this.pollInterval = null;
91
+ }
92
+ this.isRunning = false;
93
+ console.log('šŸ›‘ Command polling stopped');
94
+ }
95
+ /**
96
+ * Poll for pending commands and execute them
97
+ */
98
+ async poll() {
99
+ if (!this.apiKey) {
100
+ return;
101
+ }
102
+ try {
103
+ // Poll for pending commands
104
+ const response = await fetch(`${this.apiUrl}/api/v1/commands/poll`, {
105
+ method: 'GET',
106
+ headers: {
107
+ 'Authorization': `Bearer ${this.apiKey}`,
108
+ },
109
+ });
110
+ if (!response.ok) {
111
+ if (response.status === 401 || response.status === 403) {
112
+ // API key invalid, stop polling
113
+ console.warn('āš ļø Command polling: API key invalid, stopping');
114
+ this.stop();
115
+ return;
116
+ }
117
+ // For other errors, log but continue polling
118
+ console.warn(`āš ļø Command poll failed: ${response.status}`);
119
+ return;
120
+ }
121
+ const data = await response.json();
122
+ if (!data.command) {
123
+ // No pending commands
124
+ return;
125
+ }
126
+ // Execute the command
127
+ await this.executeCommand(data.command);
128
+ }
129
+ catch (error) {
130
+ // Log error but continue polling (network issues, etc.)
131
+ console.warn(`āš ļø Command poll error: ${error.message}`);
132
+ }
133
+ }
134
+ /**
135
+ * Execute a command locally
136
+ */
137
+ async executeCommand(command) {
138
+ console.log(`šŸ“„ Received command: ${command.type} (${command.id.substring(0, 8)}...)`);
139
+ try {
140
+ if (command.type === 'FILE_REVERT') {
141
+ await this.executeFileRevert(command);
142
+ }
143
+ else {
144
+ throw new Error(`Unknown command type: ${command.type}`);
145
+ }
146
+ }
147
+ catch (error) {
148
+ console.error(`āŒ Command execution failed: ${error.message}`);
149
+ await this.updateCommandStatus(command.id, 'FAILED', error.message);
150
+ }
151
+ }
152
+ /**
153
+ * Execute a FILE_REVERT command
154
+ */
155
+ async executeFileRevert(command) {
156
+ const { filePath, blobHash } = command.payload;
157
+ if (!filePath || !blobHash) {
158
+ throw new Error('Missing filePath or blobHash in command payload');
159
+ }
160
+ // Check if blob exists locally
161
+ const blobPath = path.join(this.projectRoot, '.neurcode', 'blobs', blobHash);
162
+ try {
163
+ await fs_1.promises.access(blobPath);
164
+ }
165
+ catch {
166
+ throw new Error(`Blob not found locally: ${blobHash}. Make sure neurcode watch is running.`);
167
+ }
168
+ // Restore the file using existing restoreFile utility
169
+ // Note: restoreFile expects hash and targetPath, and handles decompression
170
+ await (0, restore_1.restoreFile)(blobHash, filePath, this.projectRoot);
171
+ console.log(`āœ… File reverted: ${filePath} (${blobHash.substring(0, 8)}...)`);
172
+ // Update command status to COMPLETED
173
+ await this.updateCommandStatus(command.id, 'COMPLETED');
174
+ }
175
+ /**
176
+ * Update command status on the server
177
+ */
178
+ async updateCommandStatus(commandId, status, errorMessage) {
179
+ if (!this.apiKey) {
180
+ return;
181
+ }
182
+ try {
183
+ const response = await fetch(`${this.apiUrl}/api/v1/commands/${commandId}/status`, {
184
+ method: 'POST',
185
+ headers: {
186
+ 'Content-Type': 'application/json',
187
+ 'Authorization': `Bearer ${this.apiKey}`,
188
+ },
189
+ body: JSON.stringify({
190
+ status,
191
+ errorMessage,
192
+ }),
193
+ });
194
+ if (!response.ok) {
195
+ const errorText = await response.text();
196
+ console.warn(`āš ļø Failed to update command status: ${response.status} ${errorText}`);
197
+ }
198
+ }
199
+ catch (error) {
200
+ console.warn(`āš ļø Failed to update command status: ${error.message}`);
201
+ }
202
+ }
203
+ /**
204
+ * Check if poller is configured (has API key)
205
+ */
206
+ isConfigured() {
207
+ return this.apiKey !== null;
208
+ }
209
+ /**
210
+ * Reload API key from config (useful if user logs in after watch starts)
211
+ */
212
+ reloadConfig() {
213
+ const config = (0, config_1.loadConfig)();
214
+ this.apiUrl = config.apiUrl || config_1.DEFAULT_API_URL;
215
+ this.apiKey = (0, config_1.getApiKey)();
216
+ // Restart polling if we now have an API key and weren't running before
217
+ if (this.apiKey && !this.isRunning) {
218
+ this.start();
219
+ }
220
+ }
221
+ }
222
+ exports.CommandPoller = CommandPoller;
223
+ //# sourceMappingURL=CommandPoller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandPoller.js","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KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,YAAY;QACV,MAAM,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,wBAAe,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;QAE1B,uEAAuE;QACvE,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;CACF;AArMD,sCAqMC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Restore a file from a blob hash
3
+ *
4
+ * Reads a GZIP-compressed blob from .neurcode/blobs/<hash> and
5
+ * writes it to the target file path.
6
+ *
7
+ * @param hash - SHA-256 hash of the file content
8
+ * @param targetPath - Relative path to the file to restore (e.g., "src/components/Button.tsx")
9
+ * @param projectRoot - Root directory of the project
10
+ * @returns Promise that resolves when the file is restored
11
+ * @throws Error if the blob doesn't exist, path is invalid, or write fails
12
+ */
13
+ export declare function restoreFile(hash: string, targetPath: string, projectRoot: string): Promise<void>;
14
+ //# sourceMappingURL=restore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restore.d.ts","sourceRoot":"","sources":["../../src/utils/restore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAyCf"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /**
3
+ * Restore a file from a blob hash
4
+ *
5
+ * Reads a GZIP-compressed blob from .neurcode/blobs/<hash> and
6
+ * writes it to the target file path.
7
+ *
8
+ * @param hash - SHA-256 hash of the file content
9
+ * @param targetPath - Relative path to the file to restore (e.g., "src/components/Button.tsx")
10
+ * @param projectRoot - Root directory of the project
11
+ * @returns Promise that resolves when the file is restored
12
+ * @throws Error if the blob doesn't exist, path is invalid, or write fails
13
+ */
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.restoreFile = restoreFile;
49
+ const zlib_1 = require("zlib");
50
+ const fs_1 = require("fs");
51
+ const path = __importStar(require("path"));
52
+ const fsExtra = __importStar(require("fs-extra"));
53
+ async function restoreFile(hash, targetPath, projectRoot) {
54
+ // Resolve the target file path relative to project root
55
+ const resolvedTargetPath = path.resolve(projectRoot, targetPath);
56
+ // Security: Ensure the target path is within the project root
57
+ // This prevents path traversal attacks (e.g., ../../../etc/passwd)
58
+ const resolvedProjectRoot = path.resolve(projectRoot);
59
+ if (!resolvedTargetPath.startsWith(resolvedProjectRoot)) {
60
+ throw new Error(`Invalid file path: ${targetPath} - Path traversal detected`);
61
+ }
62
+ // Resolve blob path
63
+ const blobPath = path.join(projectRoot, '.neurcode', 'blobs', hash);
64
+ // Check if blob exists
65
+ try {
66
+ await fs_1.promises.access(blobPath);
67
+ }
68
+ catch {
69
+ throw new Error(`Blob not found: ${hash}`);
70
+ }
71
+ // Read the compressed blob
72
+ const compressedData = await fs_1.promises.readFile(blobPath);
73
+ // Decompress using GZIP
74
+ let decompressedData;
75
+ try {
76
+ decompressedData = (0, zlib_1.gunzipSync)(compressedData);
77
+ }
78
+ catch (error) {
79
+ throw new Error(`Failed to decompress blob: ${error instanceof Error ? error.message : 'Unknown error'}`);
80
+ }
81
+ // Convert to string (assuming UTF-8 encoding)
82
+ const fileContent = decompressedData.toString('utf-8');
83
+ // Ensure the target directory exists
84
+ const targetDir = path.dirname(resolvedTargetPath);
85
+ await fsExtra.ensureDir(targetDir);
86
+ // Write the file
87
+ await fs_1.promises.writeFile(resolvedTargetPath, fileContent, 'utf-8');
88
+ }
89
+ //# sourceMappingURL=restore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restore.js","sourceRoot":"","sources":["../../src/utils/restore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOH,kCA6CC;AAlDD,+BAAkC;AAClC,2BAAoC;AACpC,2CAA6B;AAC7B,kDAAoC;AAE7B,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,UAAkB,EAClB,WAAmB;IAEnB,wDAAwD;IACxD,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UA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SAAS,CAAC,kBAAkB,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neurcode-ai/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Neurcode CLI - AI code governance and diff analysis",
5
5
  "bin": {
6
6
  "neurcode": "./dist/index.js"