@rigstate/cli 0.7.9 ā 0.7.10
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/dist/index.cjs +229 -206
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +229 -206
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/daemon/core.ts +1 -0
- package/src/daemon/guardian-monitor.ts +9 -1
- package/src/utils/config.ts +28 -11
package/package.json
CHANGED
package/src/daemon/core.ts
CHANGED
|
@@ -79,6 +79,7 @@ export class GuardianDaemon extends EventEmitter {
|
|
|
79
79
|
private printWelcome() {
|
|
80
80
|
console.log(chalk.bold.blue('\nš”ļø Guardian Daemon Starting...'));
|
|
81
81
|
console.log(chalk.dim(`Project: ${this.config.projectId}`));
|
|
82
|
+
console.log(chalk.dim(`API URL: ${this.config.apiUrl}`));
|
|
82
83
|
console.log(chalk.dim(`Watch Path: ${this.config.watchPath}`));
|
|
83
84
|
console.log(chalk.dim('ā'.repeat(50)));
|
|
84
85
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import axios from 'axios';
|
|
6
|
+
import chalk from 'chalk';
|
|
6
7
|
import fs from 'fs/promises';
|
|
7
8
|
import path from 'path';
|
|
8
9
|
import { checkFile, type EffectiveRule, type Violation, type CheckResult } from '../utils/rule-engine.js';
|
|
@@ -54,10 +55,17 @@ export function createGuardianMonitor(
|
|
|
54
55
|
await saveCachedRules(projectId, rules);
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
|
-
} catch (error) {
|
|
58
|
+
} catch (error: any) {
|
|
59
|
+
// Log error for debugging
|
|
60
|
+
console.error(chalk.red(` ā ļø Failed to fetch rules from API: ${error.message}`));
|
|
61
|
+
if (error.response) {
|
|
62
|
+
console.error(chalk.red(` Status: ${error.response.status} - ${JSON.stringify(error.response.data)}`));
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
// Try cache fallback
|
|
59
66
|
const cached = await loadCachedRules(projectId);
|
|
60
67
|
if (cached) {
|
|
68
|
+
console.log(chalk.yellow(' ā¹ļø Using cached rules as fallback'));
|
|
61
69
|
rules = cached.rules;
|
|
62
70
|
lastFetch = Date.now();
|
|
63
71
|
return;
|
package/src/utils/config.ts
CHANGED
|
@@ -79,35 +79,52 @@ export function getApiUrl(): string {
|
|
|
79
79
|
export async function discoverApiUrl(): Promise<string> {
|
|
80
80
|
const configuredUrl = getApiUrl();
|
|
81
81
|
|
|
82
|
+
// Dynamic import to avoid top-level await issues
|
|
83
|
+
const { default: axios } = await import('axios');
|
|
84
|
+
const { default: chalk } = await import('chalk');
|
|
85
|
+
|
|
86
|
+
console.log(chalk.gray(`š Discovering local Rigstate API URL... Configured: ${configuredUrl}`));
|
|
87
|
+
|
|
82
88
|
// If not localhost, trust the config
|
|
83
89
|
if (!configuredUrl.includes('localhost') && !configuredUrl.includes('127.0.0.1')) {
|
|
90
|
+
console.log(chalk.gray(` Configured URL is not localhost, trusting: ${configuredUrl}`));
|
|
84
91
|
return configuredUrl;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
//
|
|
94
|
+
// Try to find the real port
|
|
88
95
|
const ports = [3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010];
|
|
89
96
|
|
|
90
|
-
// Dynamic import to avoid top-level await issues in some contexts
|
|
91
|
-
const { default: axios } = await import('axios');
|
|
92
|
-
|
|
93
97
|
for (const port of ports) {
|
|
98
|
+
const url = `http://localhost:${port}`;
|
|
94
99
|
try {
|
|
95
|
-
|
|
96
|
-
// Try
|
|
97
|
-
await axios.get(`${url}/api/v1/system/health`, { timeout:
|
|
98
|
-
|
|
100
|
+
console.log(chalk.gray(` Attempting to connect to ${url}/api/v1/system/health...`));
|
|
101
|
+
// Try the health endpoint
|
|
102
|
+
await axios.get(`${url}/api/v1/system/health`, { timeout: 800 });
|
|
103
|
+
|
|
104
|
+
console.log(chalk.green(` ā
Found Rigstate API at ${url}`));
|
|
99
105
|
if (url !== configuredUrl) {
|
|
106
|
+
console.log(chalk.gray(` Updating stored API URL from ${configuredUrl} to ${url}`));
|
|
100
107
|
// Update config for next time
|
|
101
108
|
setApiUrl(url);
|
|
102
109
|
}
|
|
103
110
|
return url;
|
|
104
|
-
} catch (e) {
|
|
105
|
-
// Check
|
|
111
|
+
} catch (e: any) {
|
|
112
|
+
// Check if it's a 404 on the health endpoint - if so, it might still be our server
|
|
113
|
+
// But we prefer a positive match on health.
|
|
114
|
+
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
|
|
115
|
+
console.log(chalk.yellow(` ā ļø ${url} responded with 404, but might still be a Rigstate server. Skipping for now.`));
|
|
116
|
+
} else if (axios.isAxiosError(e) && e.code === 'ECONNABORTED') {
|
|
117
|
+
console.log(chalk.gray(` Connection to ${url} timed out.`));
|
|
118
|
+
} else if (axios.isAxiosError(e) && e.code === 'ECONNREFUSED') {
|
|
119
|
+
console.log(chalk.gray(` Connection to ${url} refused.`));
|
|
120
|
+
} else {
|
|
121
|
+
console.log(chalk.gray(` Failed to connect to ${url}: ${e.message}`));
|
|
122
|
+
}
|
|
106
123
|
continue;
|
|
107
124
|
}
|
|
108
125
|
}
|
|
109
126
|
|
|
110
|
-
|
|
127
|
+
console.log(chalk.yellow(` ā No local Rigstate API found on scanned ports. Falling back to configured URL: ${configuredUrl}`));
|
|
111
128
|
return configuredUrl;
|
|
112
129
|
}
|
|
113
130
|
|