buildproof 3.12.2 → 3.12.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.
- package/bin/buildproof.js +12 -9
- package/core/hunt-client.js +18 -3
- package/core/service.js +5 -2
- package/package.json +1 -1
package/bin/buildproof.js
CHANGED
|
@@ -33,7 +33,8 @@ const ROOT = path.resolve(__dirname, '..');
|
|
|
33
33
|
const config = require('../core/config');
|
|
34
34
|
|
|
35
35
|
const args = process.argv.slice(2);
|
|
36
|
-
const cmd = args[0] || 'help';
|
|
36
|
+
const cmd = ['-h', '--help'].includes(args[0]) ? 'help' : (args[0] || 'help');
|
|
37
|
+
if (['-v', '--version', 'version'].includes(cmd)) { console.log(require('../package.json').version); process.exit(0); }
|
|
37
38
|
const flag = (n) => { const a = args.find((x) => x === `--${n}` || x.startsWith(`--${n}=`)); return a == null ? null : a.includes('=') ? a.split('=').slice(1).join('=') : true; };
|
|
38
39
|
const hook = flag('hook');
|
|
39
40
|
const force = !!flag('force');
|
|
@@ -52,14 +53,15 @@ function readStdin() {
|
|
|
52
53
|
function parse(s) { try { return JSON.parse(s); } catch { return {}; } }
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
function api(method, p, body) {
|
|
56
|
+
function api(method, p, body, timeoutMs = 30 * 60 * 1000) {
|
|
56
57
|
const c = config.load();
|
|
57
58
|
return new Promise((resolve) => {
|
|
58
59
|
const data = body ? JSON.stringify(body) : null;
|
|
59
|
-
const req = http.request({ host: '127.0.0.1', port: c.port, path: p, method, headers: { authorization: `Bearer ${c.token}`, ...(data ? { 'content-type': 'application/json', 'content-length': Buffer.byteLength(data) } : {}) }, timeout:
|
|
60
|
+
const req = http.request({ host: '127.0.0.1', port: c.port, path: p, method, headers: { authorization: `Bearer ${c.token}`, ...(data ? { 'content-type': 'application/json', 'content-length': Buffer.byteLength(data) } : {}) }, timeout: timeoutMs }, (res) => {
|
|
60
61
|
let raw = ''; res.on('data', (d) => { raw += d; }); res.on('end', () => { try { resolve(JSON.parse(raw)); } catch { resolve({ ok: false, error: 'bad_response' }); } });
|
|
61
62
|
});
|
|
62
|
-
req.on('
|
|
63
|
+
req.on('timeout', () => req.destroy(new Error('timeout')));
|
|
64
|
+
req.on('error', (e) => resolve(e && e.message === 'timeout' ? { ok: false, error: 'no_answer' } : { ok: false, error: 'service_not_running', down: true }));
|
|
63
65
|
if (data) req.write(data);
|
|
64
66
|
req.end();
|
|
65
67
|
});
|
|
@@ -207,7 +209,7 @@ async function main() {
|
|
|
207
209
|
}
|
|
208
210
|
if (['license', 'activate', 'status', 'open'].includes(cmd)) { // these need the local service: start it if it is not running
|
|
209
211
|
const sv = await require('../core/service').ensure({ autostart: false });
|
|
210
|
-
if (!sv.ok) out(`DOWN BuildProof could not start on port ${sv.port} (if another program uses it, pick a free port: set MGR_PORT=38711)`, 1);
|
|
212
|
+
if (!sv.ok) out(sv.how === 'port_busy' ? `DOWN port ${sv.port} is used by another program, not BuildProof - pick a free port: set MGR_PORT=38711` : `DOWN BuildProof could not start on port ${sv.port} (if another program uses it, pick a free port: set MGR_PORT=38711)`, 1);
|
|
211
213
|
}
|
|
212
214
|
if (cmd === 'license' || cmd === 'activate') {
|
|
213
215
|
if (cmd === 'activate') {
|
|
@@ -228,8 +230,8 @@ async function main() {
|
|
|
228
230
|
const r = await api('POST', '/api/license', { key });
|
|
229
231
|
out(r.ok ? `ACTIVATED ${r.license.label} until ${String(r.license.expires).slice(0, 10)}` : `ACTIVATE_FAIL ${r.error}`, r.ok ? 0 : 1);
|
|
230
232
|
}
|
|
231
|
-
const r = await api('GET', '/api/license');
|
|
232
|
-
if (!r.ok) out(`DOWN ${r.error}`, 1);
|
|
233
|
+
const r = await api('GET', '/api/license', null, 15000);
|
|
234
|
+
if (!r.ok || !r.label) out(`DOWN ${r.error || 'unexpected answer on port ' + config.load().port}`, 1);
|
|
233
235
|
out(`LICENSE ${r.label} ${r.status}${r.daysLeft != null ? ' days_left=' + r.daysLeft : ''}${r.projects ? ' projects_max=' + r.projects : ''}`, r.status === 'expired' ? 1 : 0);
|
|
234
236
|
}
|
|
235
237
|
if (cmd === 'init') {
|
|
@@ -269,8 +271,9 @@ async function main() {
|
|
|
269
271
|
}
|
|
270
272
|
if (cmd === 'open') { const u = `http://127.0.0.1:${config.load().port || 38700}/connect`; openUrl(u); out('OPEN ' + u, 0); }
|
|
271
273
|
if (cmd === 'status') {
|
|
272
|
-
const r = await api('GET', '/api/status');
|
|
273
|
-
|
|
274
|
+
const r = await api('GET', '/api/status', null, 15000);
|
|
275
|
+
if (r.ok && typeof r.version !== 'string') out(`DOWN unexpected answer on port ${config.load().port}`, 1);
|
|
276
|
+
out(r.ok ? `BUILDPROOF v${r.version} AI=${r.ai && r.ai.ok ? 'OK' : 'DOWN'} fixes=${r.fixes} key=${r.fingerprint}` : `DOWN ${r.error}`, r.ok ? 0 : 1);
|
|
274
277
|
}
|
|
275
278
|
if (!['start', 'check', 'accept', 'rollback', 'connect', 'try'].includes(cmd)) {
|
|
276
279
|
out(fs.readFileSync(__filename, 'utf8').split('\n').slice(3, 22).map((l) => l.replace(/^ \* ?/, '')).join('\n'), cmd === 'help' ? 0 : 1);
|
package/core/hunt-client.js
CHANGED
|
@@ -52,8 +52,20 @@ function localLlm(cfg, env = process.env) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/** Is the customer's own model reachable (and pulled)? Checked before any code is sent. */
|
|
56
|
+
async function localReady(cfg, env = process.env) {
|
|
57
|
+
const endpoint = (env.BUILDPROOF_AI_URL || (cfg.ollama && cfg.ollama.endpoint) || 'http://127.0.0.1:11434').replace(/\/$/, '');
|
|
58
|
+
const model = env.BUILDPROOF_AI_MODEL || (cfg.ollama && cfg.ollama.model) || 'qwen3-coder:30b';
|
|
59
|
+
const r = await request('GET', endpoint + '/api/tags', {}, null, 3000);
|
|
60
|
+
if (r.code !== 200 || !r.j) return { ok: false, why: `no local AI model answers at ${endpoint} - install Ollama (ollama.com) and run: ollama pull ${model}, or use --cloud` };
|
|
61
|
+
const names = (Array.isArray(r.j.models) ? r.j.models : []).map((m) => (m && (m.name || m.model)) || '');
|
|
62
|
+
if (!names.some((n) => n === model || n === model + ':latest' || n.split(':')[0] === model)) return { ok: false, why: `the model ${model} is not pulled - run: ollama pull ${model}, or use --cloud` };
|
|
63
|
+
return { ok: true };
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
async function run({ root, base, cloud, intent, cfg, license, server, llm, log = () => {}, pollMs = 2000, maxMs = 40 * 60000 }) {
|
|
56
67
|
const headers = authHeaders(license);
|
|
68
|
+
if (!cloud && !llm) { const lr = await localReady(cfg || {}); if (!lr.ok) return { code: 2, text: 'CANNOT_HUNT ' + lr.why }; }
|
|
57
69
|
let a; try { a = archives(root, base); } catch (e) { return { code: 2, text: 'CANNOT_HUNT git: ' + String(e.message).split('\n')[0] }; }
|
|
58
70
|
const start = await request('POST', server + '/api/hunt', headers, { before: a.before, after: a.after, mode: cloud ? 'cloud' : 'local', intent }, 300000);
|
|
59
71
|
if (start.code !== 200 || !start.j || !start.j.ok) {
|
|
@@ -63,6 +75,7 @@ async function run({ root, base, cloud, intent, cfg, license, server, llm, log =
|
|
|
63
75
|
}
|
|
64
76
|
const id = start.j.id;
|
|
65
77
|
const ask = llm || localLlm(cfg || {});
|
|
78
|
+
let unanswered = 0;
|
|
66
79
|
log(`HUNT_STARTED ${id} mode=${start.j.mode}`);
|
|
67
80
|
const t0 = Date.now();
|
|
68
81
|
for (;;) {
|
|
@@ -71,7 +84,8 @@ async function run({ root, base, cloud, intent, cfg, license, server, llm, log =
|
|
|
71
84
|
if (st.code !== 200 || !st.j) { await sleep(pollMs); continue; }
|
|
72
85
|
for (const p of st.j.prompts || []) { // the server's AI questions, answered by the local model
|
|
73
86
|
const text = await ask(p.prompt);
|
|
74
|
-
await request('POST', `${server}/api/hunt/${id}/answer`, headers, { id: p.id, text }, 60000);
|
|
87
|
+
const sent = await request('POST', `${server}/api/hunt/${id}/answer`, headers, { id: p.id, text }, 60000);
|
|
88
|
+
if (!String(text || '').trim() || sent.code !== 200) unanswered += 1;
|
|
75
89
|
}
|
|
76
90
|
if (st.j.status === 'done' || st.j.status === 'error') {
|
|
77
91
|
const dir = path.join(root, '.buildproof'); fs.mkdirSync(dir, { recursive: true });
|
|
@@ -79,6 +93,7 @@ async function run({ root, base, cloud, intent, cfg, license, server, llm, log =
|
|
|
79
93
|
fs.writeFileSync(file, JSON.stringify({ report: st.j.report, certificate: st.j.certificate, signature: st.j.signature, algo: st.j.algo }, null, 2));
|
|
80
94
|
if (st.j.status === 'error') return { code: 2, text: `CANNOT_HUNT ${(st.j.report && st.j.report.error) || 'hunter error'}`, file };
|
|
81
95
|
const proven = (st.j.report.findings || []).filter((f) => f.proven);
|
|
96
|
+
if (!proven.length && unanswered) return { code: 2, text: `CANNOT_HUNT the AI model did not answer ${unanswered} question(s), so "no bugs" would not be honest - check your local model (ollama), or run with --cloud`, file };
|
|
82
97
|
const lines = proven.map((f) => ` - ${f.oracle} ${f.file}${f.line ? ':' + f.line : ''} ${f.why || ''}`);
|
|
83
98
|
return { code: proven.length ? 1 : 0, text: `${proven.length ? 'BUGS_PROVEN ' + proven.length : 'NO_PROVEN_BUGS'} files=${(st.j.report.files || []).length} report=${file}${lines.length ? '\n' + lines.join('\n') : ''}`, file, report: st.j.report };
|
|
84
99
|
}
|
|
@@ -93,11 +108,11 @@ async function credits({ license, server, buy, open }) {
|
|
|
93
108
|
const r = await request('POST', server + '/api/credits/order', headers, { pack: String(buy) });
|
|
94
109
|
if (r.code !== 200 || !r.j || !r.j.ok) return { code: 2, text: 'CANNOT_BUY ' + ((r.j && r.j.error) || 'server_unavailable') };
|
|
95
110
|
open(r.j.approve);
|
|
96
|
-
return { code: 0, text: `PAY ${r.j.checks} cloud checks for $${r.j.usd} in the
|
|
111
|
+
return { code: 0, text: `PAY ${r.j.checks} cloud checks for $${r.j.usd} in the checkout page that opened: ${r.j.approve}` };
|
|
97
112
|
}
|
|
98
113
|
const r = await request('GET', server + '/api/credits', headers);
|
|
99
114
|
if (r.code !== 200 || !r.j) return { code: 2, text: 'CANNOT_READ ' + ((r.j && r.j.error) || 'server_unavailable') };
|
|
100
115
|
return { code: 0, text: `CLOUD_CHECKS ${r.j.cloudChecks} (buy more: buildproof credits --buy 20)` };
|
|
101
116
|
}
|
|
102
117
|
|
|
103
|
-
module.exports = { run, credits, archives, authHeaders, localLlm };
|
|
118
|
+
module.exports = { run, credits, archives, authHeaders, localLlm, localReady };
|
package/core/service.js
CHANGED
|
@@ -95,18 +95,21 @@ async function ensure({ autostart = true } = {}) {
|
|
|
95
95
|
const VERSION = require('../package.json').version;
|
|
96
96
|
let info = await healthInfo(cfg.port);
|
|
97
97
|
const older = (a, b) => { const x = String(a).split('.').map(Number), y = String(b).split('.').map(Number); for (let i = 0; i < 3; i++) { if ((x[i] || 0) !== (y[i] || 0)) return (x[i] || 0) < (y[i] || 0); } return false; };
|
|
98
|
-
if (info && info.ok && info.version && older(info.version, VERSION)) { // updated: replace the older service
|
|
98
|
+
if (info && info.ok === true && typeof info.version === 'string' && older(info.version, VERSION)) { // updated: replace the older service
|
|
99
99
|
if (stopOld(info)) {
|
|
100
100
|
for (let i = 0; i < 20 && info; i++) { await new Promise((r) => setTimeout(r, 300)); info = await healthInfo(cfg.port, 800); }
|
|
101
101
|
}
|
|
102
102
|
if (info) return { ok: true, how: `old-version-running(${info.version})`, autostart: null, port: cfg.port }; // could not replace it safely: keep using it
|
|
103
103
|
how = 'updated';
|
|
104
104
|
}
|
|
105
|
+
const isBp = (x) => !!(x && x.ok === true && typeof x.version === 'string');
|
|
106
|
+
if (info && !isBp(info)) return { ok: false, how: 'port_busy', port: cfg.port }; // another program answers on this port: never treat it as BuildProof
|
|
105
107
|
if (!info) {
|
|
106
108
|
startDetached();
|
|
107
109
|
if (how !== 'updated') how = 'started';
|
|
108
110
|
let ok = false;
|
|
109
|
-
|
|
111
|
+
const until = Date.now() + 20000; // at most 20 seconds, even when something on the port never answers
|
|
112
|
+
while (!ok && Date.now() < until) { await new Promise((r) => setTimeout(r, 500)); ok = isBp(await healthInfo(cfg.port, 1000)); }
|
|
110
113
|
if (!ok) return { ok: false, how: 'start_failed', port: cfg.port };
|
|
111
114
|
}
|
|
112
115
|
let auto = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "buildproof",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.3",
|
|
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": {
|