@rigstate/cli 0.7.20 → 0.7.22
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.pid +1 -1
- package/.rigstate/daemon.state.json +4 -4
- package/.rigstate/rules-cache.json +1 -1
- package/dist/index.cjs +225 -211
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +225 -211
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/daemon/core.ts +69 -44
package/package.json
CHANGED
package/src/daemon/core.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { createBridgeListener, type BridgeListenerEvents } from './bridge-listen
|
|
|
19
19
|
import { DaemonConfig, DaemonState } from './types.js';
|
|
20
20
|
import { trackSkillUsage } from './telemetry.js';
|
|
21
21
|
import { jitProvisionSkill } from '../utils/skills-provisioner.js';
|
|
22
|
+
import { syncProjectRules } from '../commands/sync-rules.js';
|
|
23
|
+
import { Logger } from '../utils/logger.js';
|
|
22
24
|
|
|
23
25
|
export class GuardianDaemon extends EventEmitter {
|
|
24
26
|
private config: DaemonConfig;
|
|
@@ -59,7 +61,12 @@ export class GuardianDaemon extends EventEmitter {
|
|
|
59
61
|
|
|
60
62
|
// 2. Load and Sync Rules
|
|
61
63
|
await this.guardianMonitor.loadRules();
|
|
62
|
-
|
|
64
|
+
Logger.info(`Loaded ${this.guardianMonitor.getRuleCount()} rules`);
|
|
65
|
+
|
|
66
|
+
// Auto-Sync Brain to IDE (The "Missing Link")
|
|
67
|
+
Logger.info('Syncing Brain to IDE (.cursor/rules)...');
|
|
68
|
+
await syncProjectRules(this.config.projectId, this.config.apiKey, this.config.apiUrl);
|
|
69
|
+
|
|
63
70
|
await this.syncHeuristics();
|
|
64
71
|
|
|
65
72
|
// 3. Setup File Watcher
|
|
@@ -98,65 +105,83 @@ export class GuardianDaemon extends EventEmitter {
|
|
|
98
105
|
private async syncHeuristics() {
|
|
99
106
|
if (!this.heuristicEngine) return;
|
|
100
107
|
const synced = await this.heuristicEngine.refreshRules(this.config.projectId, this.config.apiUrl, this.config.apiKey);
|
|
101
|
-
if (synced)
|
|
108
|
+
if (synced) Logger.info('Synced heuristic rules');
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
private setupFileWatcher() {
|
|
105
|
-
|
|
112
|
+
Logger.info('Starting file watcher...');
|
|
106
113
|
this.fileWatcher = createFileWatcher(this.config.watchPath);
|
|
107
114
|
this.fileWatcher.on('change', (path) => this.handleFileChange(path));
|
|
108
115
|
this.fileWatcher.start();
|
|
109
|
-
|
|
116
|
+
Logger.info('File watcher active');
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
private async handleFileChange(filePath: string) {
|
|
113
120
|
this.state.lastActivity = new Date().toISOString();
|
|
114
|
-
if (this.config.verbose)
|
|
121
|
+
if (this.config.verbose) Logger.debug(`File changed: ${filePath}`);
|
|
122
|
+
|
|
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
|
+
}
|
|
115
131
|
|
|
116
|
-
|
|
117
|
-
let lineCount = 0;
|
|
132
|
+
private async getLineCount(filePath: string): Promise<number> {
|
|
118
133
|
try {
|
|
119
134
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
120
|
-
|
|
121
|
-
} catch (e) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const matches = await this.heuristicEngine.analyzeFile(filePath, {
|
|
126
|
-
lineCount,
|
|
127
|
-
rules: this.guardianMonitor.getRules()
|
|
128
|
-
});
|
|
129
|
-
for (const match of matches) {
|
|
130
|
-
console.log(chalk.magenta(` 💡 PREDICTIVE ACTIVATION: ${match.skillId}`));
|
|
131
|
-
console.log(chalk.dim(` Reason: ${match.reason}`));
|
|
132
|
-
|
|
133
|
-
const decision = this.interventionProtocol.evaluateTrigger(match.skillId, match.confidence);
|
|
134
|
-
this.interventionProtocol.enforce(decision);
|
|
135
|
+
return content.split('\n').length;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
135
140
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
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);
|
|
140
170
|
}
|
|
171
|
+
}
|
|
141
172
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (this.interventionProtocol) {
|
|
155
|
-
const decision = this.interventionProtocol.evaluateViolation(v.message, v.severity as any);
|
|
156
|
-
this.interventionProtocol.enforce(decision);
|
|
157
|
-
this.interventionProtocol.registerViolation(filePath, decision);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
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);
|
|
160
185
|
}
|
|
161
186
|
}
|
|
162
187
|
}
|