@rigstate/cli 0.7.21 → 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.state.json +3 -3
- package/.rigstate/rules-cache.json +1 -1
- package/dist/index.cjs +223 -212
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +223 -212
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/daemon/core.ts +64 -45
package/package.json
CHANGED
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
|
}
|