@rigour-labs/core 4.0.1 → 4.0.3

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.
@@ -12,4 +12,5 @@ export declare class SidecarProvider implements InferenceProvider {
12
12
  dispose(): void;
13
13
  private getPlatformKey;
14
14
  private resolveBinaryPath;
15
+ private installSidecarBinary;
15
16
  }
@@ -8,6 +8,7 @@ import { promisify } from 'util';
8
8
  import path from 'path';
9
9
  import os from 'os';
10
10
  import fs from 'fs-extra';
11
+ import { createRequire } from 'module';
11
12
  import { ensureModel, isModelCached, getModelInfo } from './model-manager.js';
12
13
  const execFileAsync = promisify(execFile);
13
14
  /** Platform → npm package mapping */
@@ -33,15 +34,22 @@ export class SidecarProvider {
33
34
  return binary !== null;
34
35
  }
35
36
  async setup(onProgress) {
37
+ const platformKey = this.getPlatformKey();
38
+ const packageName = PLATFORM_PACKAGES[platformKey];
36
39
  // 1. Check/resolve binary
37
40
  this.binaryPath = await this.resolveBinaryPath();
38
- if (this.binaryPath) {
39
- onProgress?.('✓ Inference engine ready');
41
+ // Auto-bootstrap local sidecar once before failing.
42
+ if (!this.binaryPath && packageName) {
43
+ const installed = await this.installSidecarBinary(packageName, onProgress);
44
+ if (installed) {
45
+ this.binaryPath = await this.resolveBinaryPath();
46
+ }
40
47
  }
41
- else {
48
+ if (!this.binaryPath) {
42
49
  onProgress?.('⚠ Inference engine not found. Install @rigour/brain-* or add llama-cli to PATH');
43
- throw new Error('Sidecar binary not found. Run: npm install @rigour/brain-' + this.getPlatformKey());
50
+ throw new Error('Sidecar binary not found. Run: npm install @rigour/brain-' + platformKey);
44
51
  }
52
+ onProgress?.('✓ Inference engine ready');
45
53
  // 2. Ensure model is downloaded
46
54
  if (!isModelCached(this.tier)) {
47
55
  const modelInfo = getModelInfo(this.tier);
@@ -100,11 +108,28 @@ export class SidecarProvider {
100
108
  // Strategy 1: Check @rigour/brain-{platform} optional dependency
101
109
  const packageName = PLATFORM_PACKAGES[platformKey];
102
110
  if (packageName) {
111
+ try {
112
+ const require = createRequire(import.meta.url);
113
+ const pkgJsonPath = require.resolve(path.posix.join(packageName, 'package.json'));
114
+ const pkgDir = path.dirname(pkgJsonPath);
115
+ const resolvedBin = path.join(pkgDir, 'bin', 'rigour-brain');
116
+ const resolvedBinPath = os.platform() === 'win32' ? resolvedBin + '.exe' : resolvedBin;
117
+ if (await fs.pathExists(resolvedBinPath)) {
118
+ return resolvedBinPath;
119
+ }
120
+ }
121
+ catch {
122
+ // Package not resolvable from current runtime
123
+ }
103
124
  try {
104
125
  // Try to resolve from node_modules
105
126
  const possiblePaths = [
127
+ // From current working directory
128
+ path.join(process.cwd(), 'node_modules', ...packageName.split('/'), 'bin', 'rigour-brain'),
106
129
  // From rigour-core node_modules
107
130
  path.join(__dirname, '..', '..', '..', 'node_modules', ...packageName.split('/'), 'bin', 'rigour-brain'),
131
+ // From monorepo root when rigour-core is nested under packages/
132
+ path.join(__dirname, '..', '..', '..', '..', '..', 'node_modules', ...packageName.split('/'), 'bin', 'rigour-brain'),
108
133
  // From global node_modules
109
134
  path.join(os.homedir(), '.npm-global', 'lib', 'node_modules', ...packageName.split('/'), 'bin', 'rigour-brain'),
110
135
  ];
@@ -150,4 +175,21 @@ export class SidecarProvider {
150
175
  }
151
176
  return null;
152
177
  }
178
+ async installSidecarBinary(packageName, onProgress) {
179
+ onProgress?.(`⬇ Inference engine missing. Attempting automatic install: ${packageName}`);
180
+ try {
181
+ await execFileAsync('npm', ['install', '--no-save', '--no-package-lock', packageName], {
182
+ cwd: process.cwd(),
183
+ timeout: 120000,
184
+ maxBuffer: 10 * 1024 * 1024,
185
+ });
186
+ }
187
+ catch (error) {
188
+ const reason = typeof error?.message === 'string' ? error.message : 'unknown install error';
189
+ onProgress?.(`⚠ Auto-install failed: ${reason}`);
190
+ return false;
191
+ }
192
+ onProgress?.(`✓ Installed ${packageName}`);
193
+ return true;
194
+ }
153
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rigour-labs/core",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Deterministic quality gate engine for AI-generated code. AST analysis, drift detection, and Fix Packet generation across TypeScript, JavaScript, Python, Go, Ruby, and C#.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://rigour.run",