buildproof 3.8.0 → 3.8.1

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/bin/buildproof.js CHANGED
@@ -264,4 +264,8 @@ async function main() {
264
264
  }
265
265
  }
266
266
 
267
+ // update notice (cached, never blocks): not in hooks, CI or the pull request check
268
+ if (!hook && !['ci', 'spec'].includes(cmd)) {
269
+ try { const n = require('../core/update-check').notice({ dataDir: config.DATA_DIR, current: require('../package.json').version }); if (n) process.stderr.write(n + '\n'); } catch { /* optional */ }
270
+ }
267
271
  main();
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+ /**
3
+ * "A new version is available" notice. Never slows a command down and never blocks one:
4
+ * the notice comes from a small cache file; when the cache is older than a day a detached process
5
+ * refreshes it from the npm registry in the background. Off in hooks, CI and with BUILDPROOF_NO_UPDATE_CHECK=1.
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const DAY = 864e5;
10
+
11
+ function newer(a, b) { // is version a newer than b?
12
+ const pa = String(a).split('.').map(Number), pb = String(b).split('.').map(Number);
13
+ for (let i = 0; i < 3; i++) { if ((pa[i] || 0) > (pb[i] || 0)) return true; if ((pa[i] || 0) < (pb[i] || 0)) return false; }
14
+ return false;
15
+ }
16
+
17
+ function notice({ dataDir, current, now = Date.now(), env = process.env, spawn = require('child_process').spawn }) {
18
+ if (env.BUILDPROOF_NO_UPDATE_CHECK === '1' || env.CI || env.GITHUB_ACTIONS) return null;
19
+ const file = path.join(dataDir, 'update-check.json');
20
+ let c = {}; try { c = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { /* first run */ }
21
+ if (!c.checked || now - c.checked > DAY) {
22
+ try {
23
+ fs.mkdirSync(dataDir, { recursive: true });
24
+ fs.writeFileSync(file, JSON.stringify({ ...c, checked: now })); // one refresh a day, even if it fails
25
+ const js = `require('https').get('https://registry.npmjs.org/buildproof/latest',{timeout:8000},r=>{let b='';r.on('data',d=>b+=d);r.on('end',()=>{try{const v=JSON.parse(b).version;if(/^\\d+\\.\\d+\\.\\d+$/.test(v))require('fs').writeFileSync(${JSON.stringify(file)},JSON.stringify({checked:${now},latest:v}))}catch{}})}).on('error',()=>{}).on('timeout',function(){this.destroy()})`;
26
+ const ch = spawn(process.execPath, ['-e', js], { detached: true, stdio: 'ignore', windowsHide: true });
27
+ ch.on('error', () => {}); ch.unref();
28
+ } catch { /* never break the command */ }
29
+ }
30
+ return c.latest && newer(c.latest, current) ? `BuildProof ${c.latest} is available (you have ${current}). Update: npm i -g buildproof@latest` : null;
31
+ }
32
+
33
+ module.exports = { notice, newer };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "buildproof",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "BuildProof - proof gate for AI-written code: test-integrity guard, fail-closed checks, scope lock, full rollback, signed certificates, local AI under supervision.",
5
5
  "main": "core/server.js",
6
6
  "scripts": {
7
7
  "start": "node core/server.js",
8
8
  "guard": "node scripts/guard.js",
9
9
  "test": "node test/run-all.js && npm run test:unit",
10
- "test:unit": "node --test test/ci.test.js test/modules.test.js test/guard-process.test.js test/av-scan.test.js test/license-net.test.js test/guard-force.test.js test/guard-security.test.js tools/mutation-runner/acceptance.test.js",
10
+ "test:unit": "node --test test/ci.test.js test/update-check.test.js test/modules.test.js test/guard-process.test.js test/av-scan.test.js test/license-net.test.js test/guard-force.test.js test/guard-security.test.js tools/mutation-runner/acceptance.test.js",
11
11
  "bench": "node tools/benchmark/run.js",
12
12
  "test:hard": "node test/hardening.js"
13
13
  },