@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rigstate/cli",
3
- "version": "0.7.21",
3
+ "version": "0.7.22",
4
4
  "description": "Rigstate CLI - Code audit, sync and supervision tool",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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
- console.log(chalk.green(`Loaded ${this.guardianMonitor.getRuleCount()} rules`));
64
+ Logger.info(`Loaded ${this.guardianMonitor.getRuleCount()} rules`);
64
65
 
65
66
  // Auto-Sync Brain to IDE (The "Missing Link")
66
- console.log(chalk.dim('🧠 Syncing Brain to IDE (.cursor/rules)...'));
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) console.log(chalk.green('Synced heuristic rules'));
108
+ if (synced) Logger.info('Synced heuristic rules');
108
109
  }
109
110
 
110
111
  private setupFileWatcher() {
111
- console.log(chalk.dim('📂 Starting file watcher...'));
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
- console.log(chalk.green('File watcher active'));
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) console.log(chalk.dim(` 📝 File changed: ${filePath}`));
121
+ if (this.config.verbose) Logger.debug(`File changed: ${filePath}`);
121
122
 
122
- // 1. Calculate metrics
123
- let lineCount = 0;
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
- lineCount = content.split('\n').length;
127
- } catch (e) { /* Deleted file or error */ }
128
-
129
- // A. Prediction & JIT
130
- if (this.heuristicEngine && this.interventionProtocol && this.guardianMonitor) {
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
- await jitProvisionSkill(match.skillId, this.config.apiUrl, this.config.apiKey, this.config.projectId, process.cwd());
143
- await trackSkillUsage(this.config.apiUrl, this.config.apiKey, this.config.projectId, match.skillId);
144
- this.emit('skill:suggestion', match);
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
- // B. Guardian Check
149
- if (this.guardianMonitor) {
150
- if (this.interventionProtocol) this.interventionProtocol.clear(filePath);
151
- const result = await this.guardianMonitor.checkFile(filePath);
152
- this.state.filesChecked++;
153
-
154
- if (result.violations.length > 0) {
155
- this.state.violationsFound += result.violations.length;
156
- this.emit('violation', { file: filePath, violations: result.violations });
157
- for (const v of result.violations) {
158
- const color = v.severity === 'critical' ? chalk.red : v.severity === 'warning' ? chalk.yellow : chalk.blue;
159
- console.log(color(` [${v.severity.toUpperCase()}] ${filePath}: ${v.message}`));
160
- if (this.interventionProtocol) {
161
- const decision = this.interventionProtocol.evaluateViolation(v.message, v.severity as any);
162
- this.interventionProtocol.enforce(decision);
163
- this.interventionProtocol.registerViolation(filePath, decision);
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
  }