@rigstate/cli 0.7.21 → 0.7.23
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/.rigstate/daemon.state.json +3 -3
- package/.rigstate/rules-cache.json +1 -1
- package/dist/index.cjs +654 -643
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +651 -640
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/link.ts +7 -6
- package/src/commands/mcp.ts +20 -5
- package/src/daemon/core.ts +64 -45
- package/.rigstate/daemon.pid +0 -1
package/package.json
CHANGED
package/src/commands/link.ts
CHANGED
|
@@ -30,12 +30,17 @@ export function createLinkCommand() {
|
|
|
30
30
|
|
|
31
31
|
const manifestPath = path.join(process.cwd(), '.rigstate');
|
|
32
32
|
|
|
33
|
-
const content = {
|
|
33
|
+
const content: any = {
|
|
34
34
|
project_id: projectId,
|
|
35
|
-
api_url: getApiUrl(),
|
|
36
35
|
linked_at: new Date().toISOString()
|
|
37
36
|
};
|
|
38
37
|
|
|
38
|
+
// Only store api_url locally if it's NOT the production default
|
|
39
|
+
const currentUrl = getApiUrl();
|
|
40
|
+
if (currentUrl !== 'https://app.rigstate.com') {
|
|
41
|
+
content.api_url = currentUrl;
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
try {
|
|
40
45
|
await fs.writeFile(manifestPath, JSON.stringify(content, null, 2), 'utf-8');
|
|
41
46
|
console.log(chalk.green(`✔ Linked to project ID: ${projectId}`));
|
|
@@ -105,10 +110,6 @@ async function installHooks(cwd: string) {
|
|
|
105
110
|
// Actually, let's just use the `hooks` command logic if possible, or a lightweight version
|
|
106
111
|
|
|
107
112
|
try {
|
|
108
|
-
const { installHooks: runInstall } = await import('./hooks.js');
|
|
109
|
-
// We need to mock the command context or extract logic.
|
|
110
|
-
// For simplicity/robustness in this iteration, let's just suggest it or verify
|
|
111
|
-
|
|
112
113
|
// Simpler approach: Check if pre-commit exists
|
|
113
114
|
const preCommitPath = path.join(cwd, '.git/hooks/pre-commit');
|
|
114
115
|
try {
|
package/src/commands/mcp.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { spawn } from 'child_process';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
7
|
+
import { getApiKey, getApiUrl } from '../utils/config.js';
|
|
7
8
|
|
|
8
9
|
// ESM compatibility for __dirname
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -45,15 +46,29 @@ export function createMcpCommand() {
|
|
|
45
46
|
|
|
46
47
|
console.log(chalk.dim(`Starting MCP server from: ${serverPath}`));
|
|
47
48
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// SMART INJECTION: Inject global config into MCP environment
|
|
50
|
+
const env = { ...process.env };
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const apiKey = getApiKey();
|
|
54
|
+
if (apiKey) {
|
|
55
|
+
env.RIGSTATE_API_KEY = apiKey;
|
|
56
|
+
// Also inject the URL for consistency
|
|
57
|
+
env.RIGSTATE_APP_URL = getApiUrl();
|
|
58
|
+
env.RIGSTATE_API_URL = getApiUrl();
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If not logged in, we carry on and let the MCP server show the final error
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Map VIBE_API_KEY if needed
|
|
65
|
+
if (env.VIBE_API_KEY && !env.RIGSTATE_API_KEY) {
|
|
66
|
+
env.RIGSTATE_API_KEY = env.VIBE_API_KEY;
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
// Spawn the MCP server as a child process
|
|
54
|
-
// MCP uses stdio for communication, so we inherit it
|
|
55
70
|
const worker = spawn('node', [serverPath], {
|
|
56
|
-
env
|
|
71
|
+
env,
|
|
57
72
|
stdio: ['inherit', 'inherit', 'inherit']
|
|
58
73
|
});
|
|
59
74
|
|
package/src/daemon/core.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { DaemonConfig, DaemonState } from './types.js';
|
|
|
20
20
|
import { trackSkillUsage } from './telemetry.js';
|
|
21
21
|
import { jitProvisionSkill } from '../utils/skills-provisioner.js';
|
|
22
22
|
import { syncProjectRules } from '../commands/sync-rules.js';
|
|
23
|
+
import { Logger } from '../utils/logger.js';
|
|
23
24
|
|
|
24
25
|
export class GuardianDaemon extends EventEmitter {
|
|
25
26
|
private config: DaemonConfig;
|
|
@@ -60,10 +61,10 @@ export class GuardianDaemon extends EventEmitter {
|
|
|
60
61
|
|
|
61
62
|
// 2. Load and Sync Rules
|
|
62
63
|
await this.guardianMonitor.loadRules();
|
|
63
|
-
|
|
64
|
+
Logger.info(`Loaded ${this.guardianMonitor.getRuleCount()} rules`);
|
|
64
65
|
|
|
65
66
|
// Auto-Sync Brain to IDE (The "Missing Link")
|
|
66
|
-
|
|
67
|
+
Logger.info('Syncing Brain to IDE (.cursor/rules)...');
|
|
67
68
|
await syncProjectRules(this.config.projectId, this.config.apiKey, this.config.apiUrl);
|
|
68
69
|
|
|
69
70
|
await this.syncHeuristics();
|
|
@@ -104,65 +105,83 @@ export class GuardianDaemon extends EventEmitter {
|
|
|
104
105
|
private async syncHeuristics() {
|
|
105
106
|
if (!this.heuristicEngine) return;
|
|
106
107
|
const synced = await this.heuristicEngine.refreshRules(this.config.projectId, this.config.apiUrl, this.config.apiKey);
|
|
107
|
-
if (synced)
|
|
108
|
+
if (synced) Logger.info('Synced heuristic rules');
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
private setupFileWatcher() {
|
|
111
|
-
|
|
112
|
+
Logger.info('Starting file watcher...');
|
|
112
113
|
this.fileWatcher = createFileWatcher(this.config.watchPath);
|
|
113
114
|
this.fileWatcher.on('change', (path) => this.handleFileChange(path));
|
|
114
115
|
this.fileWatcher.start();
|
|
115
|
-
|
|
116
|
+
Logger.info('File watcher active');
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
private async handleFileChange(filePath: string) {
|
|
119
120
|
this.state.lastActivity = new Date().toISOString();
|
|
120
|
-
if (this.config.verbose)
|
|
121
|
+
if (this.config.verbose) Logger.debug(`File changed: ${filePath}`);
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
const lineCount = await this.getLineCount(filePath);
|
|
124
|
+
|
|
125
|
+
// A. Predictive Analysis
|
|
126
|
+
await this.runPredictiveAnalysis(filePath, lineCount);
|
|
127
|
+
|
|
128
|
+
// B. Integrity Check
|
|
129
|
+
await this.runIntegrityCheck(filePath);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private async getLineCount(filePath: string): Promise<number> {
|
|
124
133
|
try {
|
|
125
134
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
126
|
-
|
|
127
|
-
} catch (e) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const matches = await this.heuristicEngine.analyzeFile(filePath, {
|
|
132
|
-
lineCount,
|
|
133
|
-
rules: this.guardianMonitor.getRules()
|
|
134
|
-
});
|
|
135
|
-
for (const match of matches) {
|
|
136
|
-
console.log(chalk.magenta(` 💡 PREDICTIVE ACTIVATION: ${match.skillId}`));
|
|
137
|
-
console.log(chalk.dim(` Reason: ${match.reason}`));
|
|
138
|
-
|
|
139
|
-
const decision = this.interventionProtocol.evaluateTrigger(match.skillId, match.confidence);
|
|
140
|
-
this.interventionProtocol.enforce(decision);
|
|
135
|
+
return content.split('\n').length;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
private async runPredictiveAnalysis(filePath: string, lineCount: number) {
|
|
142
|
+
if (!this.heuristicEngine || !this.interventionProtocol || !this.guardianMonitor) return;
|
|
143
|
+
|
|
144
|
+
const matches = await this.heuristicEngine.analyzeFile(filePath, {
|
|
145
|
+
lineCount,
|
|
146
|
+
rules: this.guardianMonitor.getRules()
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
for (const match of matches) {
|
|
150
|
+
Logger.info(`PREDICTIVE ACTIVATION: ${match.skillId} (${match.reason})`);
|
|
151
|
+
|
|
152
|
+
const decision = this.interventionProtocol.evaluateTrigger(match.skillId, match.confidence);
|
|
153
|
+
this.interventionProtocol.enforce(decision);
|
|
154
|
+
|
|
155
|
+
await jitProvisionSkill(match.skillId, this.config.apiUrl, this.config.apiKey, this.config.projectId, process.cwd());
|
|
156
|
+
await trackSkillUsage(this.config.apiUrl, this.config.apiKey, this.config.projectId, match.skillId);
|
|
157
|
+
this.emit('skill:suggestion', match);
|
|
146
158
|
}
|
|
159
|
+
}
|
|
147
160
|
|
|
148
|
-
|
|
149
|
-
if (this.guardianMonitor)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
private async runIntegrityCheck(filePath: string) {
|
|
162
|
+
if (!this.guardianMonitor) return;
|
|
163
|
+
|
|
164
|
+
if (this.interventionProtocol) this.interventionProtocol.clear(filePath);
|
|
165
|
+
const result = await this.guardianMonitor.checkFile(filePath);
|
|
166
|
+
this.state.filesChecked++;
|
|
167
|
+
|
|
168
|
+
if (result.violations.length > 0) {
|
|
169
|
+
this.handleViolations(filePath, result.violations);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private handleViolations(filePath: string, violations: any[]) {
|
|
174
|
+
this.state.violationsFound += violations.length;
|
|
175
|
+
this.emit('violation', { file: filePath, violations });
|
|
176
|
+
|
|
177
|
+
for (const v of violations) {
|
|
178
|
+
const level = v.severity === 'critical' ? 'error' : v.severity === 'warning' ? 'warn' : 'info';
|
|
179
|
+
Logger[level as 'info'](`[${v.severity.toUpperCase()}] ${filePath}: ${v.message}`);
|
|
180
|
+
|
|
181
|
+
if (this.interventionProtocol) {
|
|
182
|
+
const decision = this.interventionProtocol.evaluateViolation(v.message, v.severity as any);
|
|
183
|
+
this.interventionProtocol.enforce(decision);
|
|
184
|
+
this.interventionProtocol.registerViolation(filePath, decision);
|
|
166
185
|
}
|
|
167
186
|
}
|
|
168
187
|
}
|
package/.rigstate/daemon.pid
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
32037
|