buildproof 3.10.0 → 3.12.0

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/README.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # BuildProof v3 - proof gate for AI-written code
2
2
 
3
+ **Quick start (30 seconds):**
4
+
5
+ ```
6
+ npx buildproof try # see it first, on a throw-away sample: a skipped test is caught, the real fix is proven
7
+ npx buildproof init # then on your project: hooks for Claude Code / Cursor / git, 14-day free trial (add --ci for the GitHub PR check)
8
+ ```
9
+
10
+ After `init`, keep working as usual. When your AI tool finishes, BuildProof re-runs your real checks; if a test was skipped, deleted or weakened, or "all tests pass" is not true, it answers NOT PROVEN and sends the reason back to the AI.
11
+
3
12
  Works two ways, same guarantees:
4
13
 
5
14
  **A. BuildProof fixes it** - task from phone / tablet / PC -> diagnose (baseline build/test) -> scope proposal (tests locked) -> your approval -> fix library or local AI (Ollama) under supervision -> proof -> signed certificate.
@@ -18,11 +27,11 @@ One-tap hooks (Projects -> AI tools, or `buildproof connect git,claude,cursor`):
18
27
  Projects: Node / Web (npm scripts typecheck, lint, build, test) and Python (syntax check of every file without writing .pyc, ruff and mypy when configured, pytest or unittest).
19
28
  Also (3.7.1): Go (go build, go vet, go test), Rust (cargo build, cargo test - also tests inside the source file), Java with Maven or Gradle (JUnit results), .NET (dotnet build, dotnet test), Ruby (syntax check, RSpec or Minitest), PHP (syntax check, PHPUnit). Each uses its own toolchain on your computer; a missing toolchain or unreadable test results is reported, never counted as proven.
20
29
 
21
- Pull request checks (3.8.0; free trial, then Team and Enterprise): `buildproof ci --init` adds a GitHub workflow; every pull request is compared with its base branch - test-integrity rules on the changed files, build/test on both sides, fail-closed verdict in the job summary. Spec check (free trial, then Pro and up; `buildproof spec` locally or inside `buildproof ci`): `.buildproof/spec.md`, one requirement per line with the test that proves it (`- Free shipping from $50 => test: free shipping from 50`); a requirement without a passing test is never accepted. Live demo: https://buildproof.mgrprosnetwork.com/demo
30
+ Pull request checks (3.8.0; free trial, then Team and Enterprise): `buildproof ci --init` adds a GitHub workflow; every pull request is compared with its base branch - test-integrity rules on the changed files, build/test on both sides, fail-closed verdict in the job summary. A check that fails is run once more: if it then passes it is reported as FLAKY (not blamed on the pull request); `--no-retry` keeps it strict (3.11). Spec check (free trial, then Pro and up; `buildproof spec` locally or inside `buildproof ci`): `.buildproof/spec.md`, one requirement per line with the test that proves it (`- Free shipping from $50 => test: free shipping from 50`); a requirement without a passing test is never accepted. Live demo: https://buildproof.mgrprosnetwork.com/demo
22
31
 
23
32
  Audit report (3.9.0; free trial, then Enterprise): `buildproof audit --since 2026-01-01` writes a signed HTML + JSON report of every accepted and rejected change; `buildproof audit --verify report.json` shows any later edit. Team dashboard (Team and Enterprise): `buildproof team` opens it; your licence key unlocks your own team's certificates.
24
33
 
25
- AI bug hunt (3.10.0; Pro and up, and the trial): `buildproof hunt --base main` uploads the change to the BuildProof server, where the hunter runs your code and the AI-written tests in a locked-down container (no network) and reports only bugs it PROVED (a test that fails on the new code and passes on the old). By default your own local model (Ollama) answers the AI's questions - free; `--cloud` uses the server's AI (one cloud check; 5 in the trial; `buildproof credits --buy 20`). Your code is deleted from the server when the check ends.
34
+ AI bug hunt (3.10.0; Pro and up, and the trial): `buildproof hunt --base main` uploads the change to the BuildProof server, where the hunter runs your code and the AI-written tests in a locked-down container (no network) and reports only bugs it PROVED (a test that fails on the new code and passes on the old). By default your own local model (Ollama) answers the AI's questions - free; `--cloud` uses the server's AI (one cloud check; 5 in the trial; `buildproof credits --buy 20`). Your code is deleted from the server when the check ends. Since 3.12 the hunter is told what the change was meant to do: taken from `--intent "..."`, else from the pull request (GitHub) or merge request (GitLab) title and description, else from the commit messages since the base. This helps it tell a real bug from an intended change. `--no-intent` turns it off.
26
35
 
27
36
  CLI: `buildproof start | check [--claim "..."] | accept [--force] | rollback | connect | verify <cert.html> | status | ci [--base origin/main] [--spec spec.md]`. `buildproof check` exits 0 only when proven.
28
37
 
package/bin/buildproof.js CHANGED
@@ -11,13 +11,14 @@
11
11
  * buildproof status service and AI status
12
12
  * buildproof verify <certificate.html|.json> [--rerun folder] verify a certificate (and re-run its checks)
13
13
  * buildproof repro <evidence.json> [folder] replay one hidden-bug finding (isolated copy)
14
- * buildproof init [folder] one-time setup: background service, project, AI tool hooks
14
+ * buildproof init [folder] [--ci] one-time setup: background service, project, AI tool hooks (--ci also adds the GitHub PR check)
15
+ * buildproof try 30-second demo on a throw-away sample project: a skipped test is caught, the real fix is proven
15
16
  * buildproof activate <key> activate a license key buildproof license show the plan
16
17
  * buildproof open open BuildProof in the browser
17
18
  * buildproof ci [folder] [--base origin/main] [--spec spec.md] pull request check for CI (--init writes the GitHub workflow)
18
19
  * buildproof spec [folder] [--base main] check the change against .buildproof/spec.md (every requirement needs a passing test)
19
20
  * buildproof audit [--since 2026-01-01] [--out report.html] signed audit report of every checked change buildproof team team dashboard
20
- * buildproof hunt [folder] [--base main] [--cloud] AI bug hunt on the server (your own model by default) buildproof credits [--buy 20]
21
+ * buildproof hunt [folder] [--base main] [--cloud] [--intent "..."] [--no-intent] AI bug hunt on the server (your own model by default) buildproof credits [--buy 20]
21
22
  *
22
23
  * Hook mode (installed by "connect"): --hook=claude | --hook=cursor | --hook=git
23
24
  */
@@ -92,6 +93,25 @@ async function activeGuard(projectId) {
92
93
  return (r.tasks || []).find((t) => t.kind === 'guard' && t.projectId === projectId && ['baselining', 'watching', 'checking'].includes(t.state));
93
94
  }
94
95
 
96
+ /** Plain-language result of `buildproof init`: what is protected now, what is missing, what to do next. */
97
+ function initSummary({ project, connected, lic, ciNote, git }) {
98
+ const L = [''];
99
+ const ok = (t) => L.push(' [ok] ' + t), warn = (t) => L.push(' [!] ' + t);
100
+ ok(`project ${project.name} (${project.type})`);
101
+ if ((project.verify || []).length) ok(`proof steps: ${project.verify.join(', ')} - these run before and after every AI change`);
102
+ else warn('no build/test scripts found - BuildProof can only prove what your checks cover. Add a "test" script, then run init again.');
103
+ if (connected.includes('claude')) ok('Claude Code: checked automatically every time Claude finishes');
104
+ if (connected.includes('cursor')) ok('Cursor: checked automatically every time the agent finishes');
105
+ if (connected.includes('git')) ok('git: checked before every commit');
106
+ if (!connected.length) warn('no AI tool found here - open this folder in Claude Code or Cursor, then run: buildproof connect');
107
+ if (ciNote) ok(ciNote); else if (git) L.push(' [+] pull requests too: buildproof init --ci');
108
+ L.push(` licence: ${lic.label || 'unknown'}${lic.status && String(lic.status).toLowerCase() !== String(lic.label || '').toLowerCase() ? ' (' + lic.status + ')' : ''}${lic.daysLeft != null ? ' - ' + lic.daysLeft + ' days left' : ''}`);
109
+ L.push('');
110
+ L.push(' Next: ask your AI tool for a change as usual. If it skips, deletes or weakens a test, or says "all tests pass" when they do not,');
111
+ L.push(' BuildProof says NOT PROVEN and sends the reason back to the AI. See it on a sample first: buildproof try');
112
+ return L.join('\n');
113
+ }
114
+
95
115
  async function main() {
96
116
  if (cmd === 'hunt' || cmd === 'credits') { // AI bug hunt on the BuildProof server (Pro and up, and the trial)
97
117
  const hc = require('../core/hunt-client');
@@ -100,7 +120,10 @@ async function main() {
100
120
  if (cmd === 'credits') { const r = await hc.credits({ license, server, buy: typeof flag('buy') === 'string' ? flag('buy') : null, open: openUrl }); out(r.text, r.code); }
101
121
  const root = path.resolve(positional[0] || process.cwd());
102
122
  const base = typeof flag('base') === 'string' ? flag('base') : (require('../core/ci').findBase(root, null) || 'HEAD~1');
103
- const r = await hc.run({ root, base, cloud: !!flag('cloud'), intent: typeof flag('intent') === 'string' ? flag('intent') : '', cfg: config.load(), license, server, log: (l) => console.log(l) });
123
+ const intent = require('../core/intent'); // 3.12: the judge gets the change intent from --intent, the PR / MR, or the commit messages
124
+ const it = intent.resolve({ flag: flag('intent'), off: !!flag('no-intent'), root, base });
125
+ if (it.intent) console.log(` intent ${intent.LABEL[it.source]}: ${it.intent.split('\n')[0].slice(0, 100)}`);
126
+ const r = await hc.run({ root, base, cloud: !!flag('cloud'), intent: it.intent, cfg: config.load(), license, server, log: (l) => console.log(l) });
104
127
  out(r.text, r.code);
105
128
  }
106
129
  if (cmd === 'audit') { // Enterprise audit report: signed HTML + JSON of every checked change in a period
@@ -127,7 +150,7 @@ async function main() {
127
150
  const lic = ci.licensed(require('../core/license'), cmd);
128
151
  if (!lic.ok) out(`CANNOT_CHECK ${lic.why}`, 2);
129
152
  const base = typeof flag('base') === 'string' ? flag('base') : null;
130
- const r = await ci.check(folder, { base, spec: typeof flag('spec') === 'string' ? flag('spec') : null, requireSpec: cmd === 'spec', noBaseline: !!flag('no-baseline') });
153
+ const r = await ci.check(folder, { base, spec: typeof flag('spec') === 'string' ? flag('spec') : null, requireSpec: cmd === 'spec', noBaseline: !!flag('no-baseline'), noRetry: !!flag('no-retry') });
131
154
  const sum = typeof flag('summary') === 'string' ? flag('summary') : process.env.GITHUB_STEP_SUMMARY;
132
155
  if (sum) { try { fs.appendFileSync(sum, r.md + '\n'); } catch { /* summary is optional */ } }
133
156
  out(r.text, r.code);
@@ -216,16 +239,30 @@ async function main() {
216
239
  const lic = await api('GET', '/api/license');
217
240
  const connected = Object.entries(hk.hooks || {}).filter(([, v]) => v.connected).map(([k]) => k);
218
241
  console.log(`INIT project=${pr.project.name} type=${pr.project.type} proof=${pr.project.verify.join(',') || 'none'} tools=${connected.join(',') || 'none'} service=${sv.how}${sv.autostart ? '/' + sv.autostart : ''} license=${lic.label}:${lic.status}${lic.daysLeft != null ? '(' + lic.daysLeft + 'd)' : ''}`);
242
+ let ciNote = '';
243
+ if (flag('ci')) { const w = require('../core/ci').init(dir); ciNote = w.ok ? `pull request check added: ${path.relative(dir, w.file)} - add your licence key as the BUILDPROOF_LICENSE secret in GitHub` : `pull request check already there: ${path.relative(dir, w.file)}`; }
244
+ console.log(initSummary({ project: pr.project, connected, lic, ciNote, git: tools.includes('git') }));
219
245
  if (!process.env.MGR_NO_AUTOSTART && !process.env.MGR_NO_OPEN) openUrl(`http://127.0.0.1:${sv.port}/connect`);
220
246
  out(`OPEN http://127.0.0.1:${sv.port}/connect (BuildProof on this computer + add your phone)`, 0);
221
247
  }
248
+ if (cmd === 'try') { // 30-second demo on a throw-away sample project, never on your code
249
+ const service = require('../core/service');
250
+ const sv = await service.ensure({ autostart: !process.env.MGR_NO_AUTOSTART });
251
+ if (!sv.ok) out(`TRY_FAIL BuildProof could not start on port ${sv.port}`, 1);
252
+ const r = await require('../core/try-demo').run({ api, sleep, say: (t) => console.log(t) });
253
+ if (!r.ok) out(`TRY_FAIL ${r.error}${r.error === 'license_required' ? ' (start the free trial: buildproof init)' : ''}${r.limit ? ' (limit ' + r.limit + ' projects in this plan)' : ''}`, 1);
254
+ const good = !r.round1.proven && r.round2.proven;
255
+ console.log('');
256
+ console.log(good ? 'That is BuildProof: the shortcut was caught and undone, the real fix was proven. Set it up on your project: npx buildproof init' : 'The demo did not end as expected - please tell us: https://buildproof.mgrprosnetwork.com');
257
+ out(`TRY ${good ? 'OK' : 'UNEXPECTED'} shortcut=${r.round1.proven ? 'PROVEN' : 'NOT_PROVEN'} real_fix=${r.round2.proven ? 'PROVEN' : 'NOT_PROVEN'}`, good ? 0 : 1);
258
+ }
222
259
  if (cmd === 'open') { const u = `http://127.0.0.1:${config.load().port || 38700}/connect`; openUrl(u); out('OPEN ' + u, 0); }
223
260
  if (cmd === 'status') {
224
261
  const r = await api('GET', '/api/status');
225
262
  out(r.ok ? `BUILDPROOF v${r.version} AI=${r.ai.ok ? 'OK' : 'DOWN'} fixes=${r.fixes} key=${r.fingerprint}` : `DOWN ${r.error}`, r.ok ? 0 : 1);
226
263
  }
227
- if (!['start', 'check', 'accept', 'rollback', 'connect'].includes(cmd)) {
228
- out(fs.readFileSync(__filename, 'utf8').split('\n').slice(3, 21).map((l) => l.replace(/^ \* ?/, '')).join('\n'), cmd === 'help' ? 0 : 1);
264
+ if (!['start', 'check', 'accept', 'rollback', 'connect', 'try'].includes(cmd)) {
265
+ out(fs.readFileSync(__filename, 'utf8').split('\n').slice(3, 22).map((l) => l.replace(/^ \* ?/, '')).join('\n'), cmd === 'help' ? 0 : 1);
229
266
  }
230
267
 
231
268
  const input = await readStdin();
package/core/ci.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * CI / pull request check: compare the pull request (HEAD) with its base branch, without the background service.
4
4
  *
5
- * buildproof ci [folder] [--base origin/main] [--spec spec.md] [--no-baseline] [--summary file.md]
5
+ * buildproof ci [folder] [--base origin/main] [--spec spec.md] [--no-baseline] [--no-retry] [--summary file.md]
6
6
  *
7
7
  * 1. test-integrity rules on every changed file (deleted / skipped / weakened tests, silenced checkers...)
8
8
  * 2. the project's build / test scripts on the base and on the pull request
@@ -54,14 +54,27 @@ async function installDeps(dir, info, timeoutMs) {
54
54
  return run(pm, args, { cwd: dir, timeoutMs });
55
55
  }
56
56
 
57
- async function verifyDir(dir, info, commandFor, timeoutMs) {
57
+ /**
58
+ * Run every check step. A step that really ran and FAILED is run once more (retries=1 by default):
59
+ * if it passes the second time it is reported as FLAKY - in the summary, in the text line and in the verdict -
60
+ * instead of blaming the pull request for a test that fails at random. A step that did not really run
61
+ * (timeout, no tests found) is never retried, and a test that fails every time still fails.
62
+ */
63
+ async function verifyDir(dir, info, commandFor, timeoutMs, retries = 1) {
58
64
  const results = {};
59
65
  for (const step of info.verify) {
60
66
  const { cmd, args } = commandFor(info, step);
61
- // NODE_TEST_CONTEXT would make a nested `node --test` report to its parent instead of failing here
62
- const r = await run(cmd, args, { cwd: dir, timeoutMs, env: { PYTHONDONTWRITEBYTECODE: '1', NODE_TEST_CONTEXT: undefined } });
63
- const g = gate.evaluate(step, r, { strictCounts: STRICT_TYPES.has(info.type) });
64
- results[step] = { ...g, tail: String(r.output || '').slice(-1500) };
67
+ const once = async () => {
68
+ // NODE_TEST_CONTEXT would make a nested `node --test` report to its parent instead of failing here
69
+ const r = await run(cmd, args, { cwd: dir, timeoutMs, env: { PYTHONDONTWRITEBYTECODE: '1', NODE_TEST_CONTEXT: undefined } });
70
+ return { ...gate.evaluate(step, r, { strictCounts: STRICT_TYPES.has(info.type) }), tail: String(r.output || '').slice(-1500) };
71
+ };
72
+ let g = await once();
73
+ for (let i = 0; i < retries && !g.pass && g.ran; i++) {
74
+ const again = await once();
75
+ if (again.pass) { g = { ...again, flaky: true, firstFailure: g.tail }; break; }
76
+ }
77
+ results[step] = g;
65
78
  }
66
79
  return results;
67
80
  }
@@ -130,11 +143,13 @@ function checkSpec(items, { root, baseDir, testFiles, after, baseline }) {
130
143
  function stepLine(s, r) {
131
144
  if (!r) return `- ${s}: did not run`;
132
145
  const t = r.tests ? ` (${r.tests.passed}/${r.tests.total} tests)` : '';
133
- return `- ${s}: ${r.pass ? 'pass' : r.ran ? 'FAIL' : 'did not really run (' + r.reason + ')'}${t}`;
146
+ return `- ${s}: ${r.pass ? (r.flaky ? '**FLAKY** - failed, then passed when run again' : 'pass') : r.ran ? 'FAIL' : 'did not really run (' + r.reason + ')'}${t}`;
134
147
  }
135
148
 
136
149
  function markdown(res) {
137
150
  const L = [`## BuildProof: ${res.proven ? 'PROVEN' : 'NOT PROVEN'}`, '', res.why, ''];
151
+ const flaky = (res.steps || []).filter((st) => res.after && res.after[st] && res.after[st].flaky);
152
+ if (flaky.length) L.push(`> **Flaky:** ${flaky.join(', ')} failed once and passed when run again. Not blamed on this pull request - but fix or quarantine the flaky test (\`--no-retry\` turns the re-run off).`, '');
138
153
  L.push(`Compared with \`${res.base}\`: ${res.changes.length} changed file(s).`, '');
139
154
  if (res.integrity.findings.length) {
140
155
  L.push('### Checks weakened in this change');
@@ -186,12 +201,12 @@ async function check(root, opts = {}) {
186
201
  const steps = info.verify || [];
187
202
  let after = null, baseline = null, verdict = null;
188
203
  if (steps.length) {
189
- after = await verifyDir(root, info, projects.commandFor, timeoutMs);
204
+ after = await verifyDir(root, info, projects.commandFor, timeoutMs, opts.noRetry ? 0 : 1);
190
205
  if (!opts.noBaseline) {
191
206
  const binfo = projects.detect(baseDir);
192
207
  binfo.verify = steps.filter((s) => (binfo.verify || []).includes(s));
193
208
  await installDeps(baseDir, binfo, timeoutMs);
194
- baseline = await verifyDir(baseDir, binfo, projects.commandFor, timeoutMs);
209
+ baseline = await verifyDir(baseDir, binfo, projects.commandFor, timeoutMs, opts.noRetry ? 0 : 1);
195
210
  }
196
211
  // no baseline: every step must pass on its own (stricter)
197
212
  verdict = gate.judge(baseline || after, after, steps, true); // a pull request must leave every check passing
@@ -211,7 +226,8 @@ async function check(root, opts = {}) {
211
226
  : (integ.clean && verdict && verdict.ok ? `Spec not met: ${specBad.slice(0, 3).map((x) => `${x.req} (${x.why})`).join('; ')}` : gate.whyNot(verdict, integ));
212
227
  const res = { proven, why, base, changes, integrity: integ, steps, after, baseline, spec };
213
228
  const md = markdown(res);
214
- const text = `${proven ? 'PROVEN' : 'NOT_PROVEN'} files=${changes.length} base=${base} | ${why}`;
229
+ const flaky = steps.filter((st) => after && after[st] && after[st].flaky);
230
+ const text = `${proven ? 'PROVEN' : 'NOT_PROVEN'} files=${changes.length} base=${base}${flaky.length ? ' flaky=' + flaky.join(',') : ''} | ${why}${flaky.length ? ` Flaky: ${flaky.join(', ')} failed once and passed when run again - fix or quarantine it.` : ''}`;
215
231
  return { code: proven ? 0 : 1, proven, why, text, md };
216
232
  } finally {
217
233
  try { git(['worktree', 'remove', '--force', baseDir], root); } catch { /* ignore */ }
package/core/intent.js ADDED
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+ /**
3
+ * Automatic change intent for `buildproof hunt` (3.12).
4
+ * The bug hunter's judge works far better when it knows what the change was meant to do.
5
+ * Order: explicit --intent, then the pull/merge request (GitHub, GitLab), then the commit messages base..HEAD.
6
+ * The text is untrusted: it is only ever passed as data to the judge, trimmed and cleaned here.
7
+ */
8
+ const fs = require('fs');
9
+ const { execFileSync } = require('child_process');
10
+
11
+ const MAX = 1500;
12
+
13
+ function clean(s) {
14
+ return String(s || '')
15
+ .replace(/<!--[\s\S]*?-->/g, ' ') // PR templates: hidden comments
16
+ .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '')
17
+ .replace(/\r\n?/g, '\n')
18
+ .replace(/\n{3,}/g, '\n\n')
19
+ .trim();
20
+ }
21
+
22
+ function cut(s) { return s.length > MAX ? s.slice(0, MAX - 3).trimEnd() + '...' : s; }
23
+
24
+ function join(title, body) {
25
+ const t = clean(title), b = clean(body);
26
+ return cut(t && b ? `${t}\n\n${b}` : t || b);
27
+ }
28
+
29
+ function fromGitHub(env) {
30
+ const p = env.GITHUB_EVENT_PATH;
31
+ if (!p) return '';
32
+ let ev; try { ev = JSON.parse(fs.readFileSync(p, 'utf8')); } catch { return ''; }
33
+ const pr = ev && (ev.pull_request || (ev.issue && ev.issue.pull_request && ev.issue));
34
+ return pr ? join(pr.title, pr.body) : '';
35
+ }
36
+
37
+ function fromGitLab(env) {
38
+ return env.CI_MERGE_REQUEST_TITLE ? join(env.CI_MERGE_REQUEST_TITLE, env.CI_MERGE_REQUEST_DESCRIPTION) : '';
39
+ }
40
+
41
+ function fromCommits(root, base) {
42
+ if (!base) return '';
43
+ try {
44
+ const out = execFileSync('git', ['log', '--no-merges', '-n', '20', '--format=%s%n%n%b%x1e', `${base}..HEAD`], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true, timeout: 15000 });
45
+ const msgs = out.split('\x1e').map(clean).filter(Boolean);
46
+ return cut(msgs.join('\n\n'));
47
+ } catch { return ''; }
48
+ }
49
+
50
+ /** -> { intent, source } ; source: 'flag' | 'github-pr' | 'gitlab-mr' | 'commits' | 'none' | 'off' */
51
+ function resolve({ flag, off, root, base, env = process.env } = {}) {
52
+ if (typeof flag === 'string' && flag.trim()) return { intent: cut(clean(flag)), source: 'flag' };
53
+ if (off) return { intent: '', source: 'off' };
54
+ let t = fromGitHub(env); if (t) return { intent: t, source: 'github-pr' };
55
+ t = fromGitLab(env); if (t) return { intent: t, source: 'gitlab-mr' };
56
+ t = fromCommits(root, base); if (t) return { intent: t, source: 'commits' };
57
+ return { intent: '', source: 'none' };
58
+ }
59
+
60
+ const LABEL = { flag: 'from --intent', 'github-pr': 'from the pull request title and description', 'gitlab-mr': 'from the merge request title and description', commits: 'from the commit messages' };
61
+
62
+ module.exports = { resolve, LABEL, MAX };
package/core/server.js CHANGED
@@ -266,7 +266,9 @@ ${links.map((l, i) => `<div class="q"><div id="q${i}"></div><p>${l.replace(/toke
266
266
  if (need('guard', 'license_required')) return;
267
267
  const all = store.list('projects');
268
268
  const known = all.some((x) => path.resolve(x.root).toLowerCase() === path.resolve(String(b.root || '')).toLowerCase());
269
- if (!known && lic.projects != null && all.length >= lic.projects) return send(res, 402, { ok: false, error: 'plan_limit_projects', limit: lic.projects, license: lic });
269
+ // `buildproof try` sample: a throw-away folder in the temp dir, removed right after - never counts against the plan
270
+ const tryDemo = b.demo === true && /^buildproof-try-/.test(path.basename(String(b.root || ''))) && path.resolve(String(b.root || '')).toLowerCase().startsWith(path.resolve(require('os').tmpdir()).toLowerCase() + path.sep);
271
+ if (!known && !tryDemo && lic.projects != null && all.length >= lic.projects) return send(res, 402, { ok: false, error: 'plan_limit_projects', limit: lic.projects, license: lic });
270
272
  const r = projects.add({ name: b.name, root: b.root });
271
273
  return send(res, r.ok ? 200 : 400, r);
272
274
  }
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+ /**
3
+ * `buildproof try` - a 30-second, safe demo on a throw-away sample project (never on your code).
4
+ * 1. An "AI" says "Fixed, all tests pass" after skipping the failing test -> BuildProof: NOT PROVEN, rolled back.
5
+ * 2. The real fix of the bug -> BuildProof: PROVEN.
6
+ * The sample project is created in the temp folder and removed at the end, together with its project entry,
7
+ * so it does not use a project slot of your plan.
8
+ */
9
+ const fs = require('fs');
10
+ const os = require('os');
11
+ const path = require('path');
12
+
13
+ const PKG = { name: 'buildproof-try', version: '1.0.0', private: true, scripts: { test: 'node --test' } };
14
+ const BUGGY = `'use strict';
15
+ /** Order total with shipping: shipping is free from $50. */
16
+ function total(items) {
17
+ const sum = items.reduce((s, i) => s + i.price * i.qty, 0);
18
+ const shipping = sum > 50 ? 0 : 7;
19
+ return sum + shipping;
20
+ }
21
+ module.exports = { total };
22
+ `;
23
+ const FIXED = BUGGY.replace('sum > 50', 'sum >= 50');
24
+ const TEST = `'use strict';
25
+ const test = require('node:test');
26
+ const assert = require('node:assert');
27
+ const { total } = require('./price');
28
+
29
+ test('small order pays shipping', () => { assert.strictEqual(total([{ price: 10, qty: 1 }]), 17); });
30
+ test('large order ships free', () => { assert.strictEqual(total([{ price: 30, qty: 3 }]), 90); });
31
+ test('free shipping from 50', () => { assert.strictEqual(total([{ price: 25, qty: 2 }]), 50); });
32
+ `;
33
+ const CHEAT = TEST.replace("test('free shipping from 50'", "test.skip('free shipping from 50'");
34
+
35
+ function makeSample() {
36
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'buildproof-try-'));
37
+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(PKG, null, 2) + '\n');
38
+ fs.writeFileSync(path.join(dir, 'price.js'), BUGGY);
39
+ fs.writeFileSync(path.join(dir, 'price.test.js'), TEST);
40
+ return dir;
41
+ }
42
+
43
+ /** api(method, path, body) talks to the local BuildProof service; say(text) prints one line. */
44
+ async function run({ api, say, sleep, keepFolder = false }) {
45
+ const dir = makeSample();
46
+ let projectId = null;
47
+ const waitGuard = async (g) => {
48
+ for (let i = 0; g && ['baselining', 'checking'].includes(g.state) && i < 600; i++) { await sleep(500); g = (await api('GET', `/api/tasks/${g.id}`)).task; }
49
+ return g;
50
+ };
51
+ const startGuard = async () => {
52
+ const r = await api('POST', '/api/guards', { projectId, source: 'try' });
53
+ if (!r.ok) throw new Error(r.error || 'guard_not_started');
54
+ const g = await waitGuard(r.task);
55
+ if (!g || g.state !== 'watching') throw new Error(g ? g.resultText || g.state : 'guard_not_started');
56
+ return g;
57
+ };
58
+ try {
59
+ const pr = await api('POST', '/api/projects', { root: dir, name: 'buildproof-try', demo: true });
60
+ if (!pr.ok) return { ok: false, error: pr.error === 'license_required' ? 'license_required' : pr.error || 'project_not_added', limit: pr.limit };
61
+ projectId = pr.project.id;
62
+ say('Sample shop project (not your code): price.js has a bug - an order of exactly $50 pays shipping, but it should be free.');
63
+ say('Its test "free shipping from 50" fails, as it should.');
64
+ say('');
65
+
66
+ // round 1: the shortcut many AI agents take
67
+ let g = await startGuard();
68
+ fs.writeFileSync(path.join(dir, 'price.test.js'), CHEAT);
69
+ say('Round 1 - the AI skips the failing test and says: "Fixed, all tests pass."');
70
+ let c = await api('POST', `/api/guards/${g.id}/check`, { claim: 'Fixed the shipping bug, all tests pass.' });
71
+ let full = (await api('GET', `/api/tasks/${g.id}`)).task || {};
72
+ const why = [
73
+ ...((full.integrity && full.integrity.findings) || []).map((f) => f.text),
74
+ ...((full.claims || []).filter((x) => x.truth === false).map((x) => `claim "${x.text}" is not true`)),
75
+ ];
76
+ const round1 = { proven: !!c.proven, why };
77
+ say(` BuildProof: ${c.proven ? 'PROVEN (unexpected)' : 'NOT PROVEN'}${why.length ? ' - ' + why.slice(0, 3).join('; ') : ''}`);
78
+ const rb = await api('POST', `/api/guards/${g.id}/rollback`, {});
79
+ say(` Rolled back: ${rb.ok ? 'the project is exactly as before' : 'rollback failed: ' + rb.error}`);
80
+ say('');
81
+
82
+ // round 2: the real fix
83
+ g = await startGuard();
84
+ fs.writeFileSync(path.join(dir, 'price.js'), FIXED);
85
+ say('Round 2 - the AI fixes the real cause in price.js (sum >= 50) and leaves the tests alone.');
86
+ c = await api('POST', `/api/guards/${g.id}/check`, { claim: 'Fixed the shipping bug, all tests pass.' });
87
+ full = (await api('GET', `/api/tasks/${g.id}`)).task || {};
88
+ const round2 = { proven: !!c.proven, revert: full.revertCheck ? full.revertCheck.verdict : null };
89
+ say(` BuildProof: ${c.proven ? 'PROVEN' : 'NOT PROVEN - ' + (full.resultText || '')}${round2.revert ? ' (revert check: ' + round2.revert + ')' : ''}`);
90
+ await api('POST', `/api/guards/${g.id}/rollback`, {}); // end the demo guard; this is a throw-away folder
91
+ return { ok: true, round1, round2, dir };
92
+ } catch (e) {
93
+ return { ok: false, error: String(e.message || e) };
94
+ } finally {
95
+ if (projectId) await api('DELETE', `/api/projects/${projectId}`);
96
+ if (!keepFolder) { try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* temp folder */ } }
97
+ }
98
+ }
99
+
100
+ module.exports = { run, makeSample, BUGGY, FIXED, TEST, CHEAT };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "buildproof",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
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/update-check.test.js test/audit.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/try-demo.test.js test/update-check.test.js test/audit.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
  },