Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Local-first Python CLI and reusable GitHub Action for verifying Python repositor
- CI-friendly exit codes
- GitHub composite Action
- Local-first scanning
- Modern local GUI dashboard (`codeproof gui`) for scans, findings, policy, and history

## Install
```bash
Expand All @@ -26,8 +27,9 @@ codeproof init
codeproof inventory .
codeproof generate-tests . --output tests/generated
codeproof scan . --format all --fail-under 70
codeproof gui . --host 127.0.0.1 --port 8787
```
Reports are stored under `.codeproof/reports/`.
Reports are stored under `.codeproof/reports/`. The GUI runs locally and uses the same core engine/policy as the CLI. See `ROADMAP.md` for planned enhancements.

## Confidence model
The score is the weighted percentage of included checks that pass. Missing required tools fail policy. Missing optional tools are marked unavailable and excluded from the denominator. A passing report is evidence that configured checks passed, not proof of correctness.
Expand Down
42 changes: 42 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# CodeProof-AI Roadmap

## Vision
Make CodeProof-AI the most trusted, local-first evidence platform for Python repository health—transparent scoring, actionable diagnostics, and seamless workflows from CLI to CI to interactive GUI.

## Current State (v0.1.0)
- Deterministic checks: Ruff, mypy, pytest, Bandit, Semgrep, import-smoke
- Weighted policy engine with required-tool gates and configurable thresholds
- AST-based symbol inventory and reviewable smoke-test generation
- Reports: JSON, Markdown, HTML
- Typer CLI + reusable GitHub Action
- Local-first execution model

## Near-term (v0.2.x) — Usability & Visibility
- **Modern GUI dashboard (in progress)**: local web interface to run scans, view results, inspect findings, browse report history, and edit policy.
- **Scan history & trends**: persist run metadata/summaries; show score trends over time per project.
- **Richer finding details**: normalize adapter outputs (file/line/rule/severity) into structured findings across all tools.
- **Config UX**: validate `.codeproof.yml`, expose presets (strict/balanced/fast), and document all options.
- **Improved HTML reports**: interactive filtering, sortable tables, and deep links to evidence/raw output.
- **Doctor enhancements**: version checks, install hints, and environment diagnostics.

## Mid-term (v0.3.x–v0.4.x) — Depth & Integrations
- **Async/background scans in GUI** with live progress and cancellation.
- **Baseline & diff mode**: compare current scan against a baseline to highlight regressions/new findings (PR-focused).
- **Plugin/adapter system**: stable interface for custom checks (coverage, pip-audit, vulture, complexity, license checks).
- **Coverage integration**: parse `coverage.xml`/pytest-cov output as a first-class evidence source.
- **Multi-language groundwork**: abstract runner/report model to support additional ecosystems (starting with JS/TS) while keeping Python best-in-class.
- **SARIF export** and better GitHub Code Scanning/PR annotation workflows.
- **Caching & incremental checks**: speed up repeated local scans.

## Long-term (v1.0+) — Team & Trust
- **Policy packs & provenance**: signed/shareable policy profiles; clear evidence provenance in reports.
- **Workspace/monorepo support**: per-package policies, aggregated scoring, and targeted scans.
- **Optional hosted/CI insights**: opt-in aggregation for teams (never default; preserve local-first core).
- **AI-assisted, evidence-grounded explanations**: summarize findings and suggest fixes *with citations to check output* (no correctness claims).
- **Stability guarantees**: versioned report schema, backward-compatible config migrations, and documented extension API.

## Guiding Principles
- **Evidence over claims**: reports show what ran, what passed/failed, and what was excluded.
- **Local-first & transparent**: predictable execution, explicit limitations, user-controlled network use.
- **Composable**: CLI, GUI, and CI share the same core engine and config.
- **Safe by default**: clear warnings when scanning executes untrusted code; encourage isolated environments.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ dev=["codeproof-ai[checkers]"]
codeproof="codeproof.cli:app"
[tool.hatch.build.targets.wheel]
packages=["src/codeproof"]

[tool.hatch.build.targets.wheel.force-include]
"src/codeproof/gui" = "codeproof/gui"

[tool.pytest.ini_options]
testpaths=["tests"]

8 changes: 8 additions & 0 deletions src/codeproof/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ def scan(path:Path=Path("."),format:str="all",fail_under:float|None=None,output:
console.print(t);console.print(f"Score {report.score}/100 ({report.grade}); policy {'PASS' if report.policy_passed else 'FAIL'}")
for p in write(report,root/output,format):console.print(f"Report: {p}")
raise typer.Exit(0 if report.policy_passed else 1)

@app.command()
def gui(path:Path=Path("."),host:str="127.0.0.1",port:int=8787,no_open:bool=False):
"""Launch the local CodeProof GUI dashboard."""
from .web import serve
serve(host=host,port=port,target=path.resolve(),open_browser=not no_open)

if __name__=="__main__":app()

1 change: 1 addition & 0 deletions src/codeproof/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

149 changes: 149 additions & 0 deletions src/codeproof/gui/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
const state = { report: null, findings: [] };
const $ = (s) => document.querySelector(s);
const $$ = (s) => Array.from(document.querySelectorAll(s));

function fmt(n, d = 2) { return typeof n === 'number' ? n.toFixed(d).replace(/\.00$/, '') : n; }
function esc(s) { return String(s ?? '').replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c])); }

async function api(path, opts = {}) {
const res = await fetch(path, { headers: { 'Content-Type': 'application/json' }, ...opts });
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || res.statusText);
return data;
}

function setView(name) {
$$('.view').forEach(v => v.classList.toggle('active', v.id === `view-${name}`));
$$('.nav-btn').forEach(b => b.classList.toggle('active', b.dataset.view === name));
const titles = { dashboard: 'Repository overview', findings: 'Findings', inventory: 'Inventory', policy: 'Policy & tools', history: 'Report history' };
$('#view-title').textContent = titles[name];
$('#breadcrumb').textContent = name === 'dashboard' ? 'OVERVIEW' : name.toUpperCase();
if (name === 'policy') { loadPolicy(); loadDoctor(); }
if (name === 'history') loadHistory();
}

function scoreColor(score) {
if (score >= 80) return 'var(--good)';
if (score >= 60) return 'var(--warn)';
return 'var(--bad)';
}

function renderReport(report) {
state.report = report;
state.findings = [];
(report.results || []).forEach(r => (r.findings || []).forEach(f => state.findings.push({ check: r.name, ...f })));
$('#project-meta').textContent = `${report.project} • ${report.target} • ${new Date(report.generated_at).toLocaleString()}`;
$('#score-value').textContent = fmt(report.score, 0);
$('#grade').textContent = `Grade ${report.grade}`;
const deg = Math.max(0, Math.min(100, report.score)) * 3.6;
$('#score-ring').style.background = `conic-gradient(${scoreColor(report.score)} ${deg}deg, rgba(255,255,255,0.06) ${deg}deg)`;
const badge = $('#policy-badge');
badge.textContent = report.policy_passed ? 'Policy PASS' : 'Policy FAIL';
badge.className = 'badge ' + (report.policy_passed ? 'pass' : 'fail');
$('#kpi-checks').textContent = (report.results || []).length;
const passed = (report.results || []).filter(r => r.status === 'passed').length;
$('#kpi-checks-sub').textContent = `${passed} passed`;
$('#kpi-findings').textContent = state.findings.length;
$('#kpi-threshold').textContent = `≥ ${fmt(report.fail_under)}`;
$('#kpi-generated').textContent = `CodeProof ${report.codeproof_version}`;
renderResults();
renderFindings();
$('#limitations').innerHTML = (report.limitations || []).map(l => `<li>${esc(l)}</li>`).join('') || '<li>None.</li>';
}

function renderResults() {
const filter = $('#status-filter').value;
const rows = (state.report?.results || []).filter(r => filter === 'all' || r.status === filter);
$('#results-table tbody').innerHTML = rows.map(r => `<tr>
<td><strong>${esc(r.name)}</strong></td>
<td><span class="status ${esc(r.status)}">${esc(r.status)}</span></td>
<td>${fmt(r.weight)}</td>
<td>${r.required ? 'Yes' : 'No'}</td>
<td>${fmt(r.duration_seconds, 3)}s</td>
<td>${esc(r.summary)}</td>
</tr>`).join('') || `<tr><td colspan="6" class="empty-cell"><strong>No results to show</strong><span>${state.report ? 'Try another status filter.' : 'Run a scan to see your check results here.'}</span></td></tr>`;
}

function renderFindings() {
const q = ($('#finding-search')?.value || '').toLowerCase();
const rows = state.findings.filter(f => !q || JSON.stringify(f).toLowerCase().includes(q));
$('#findings-table tbody').innerHTML = rows.map(f => `<tr>
<td>${esc(f.check)}</td><td>${esc(f.level)}</td><td>${esc(f.rule || '')}</td>
<td>${esc(f.path || '')}</td><td>${f.line ?? ''}</td><td>${esc(f.message)}</td>
</tr>`).join('') || `<tr><td colspan="6" class="empty-cell"><strong>No findings to show</strong><span>${q ? 'Try a different search.' : state.report ? 'No structured findings were reported in this scan.' : 'Run a scan to see reported findings.'}</span></td></tr>`;
}

async function runScan() {
const btn = $('#run-scan');
btn.disabled = true; $('#scan-status').textContent = 'Running scan… this may take a while (tools execute in the target repo).';
try {
const target = $('#target').value.trim();
const report = await api('/api/scan', { method: 'POST', body: JSON.stringify({ path: target }) });
renderReport(report);
$('#scan-status').textContent = `Scan complete. Policy ${report.policy_passed ? 'PASS' : 'FAIL'}.`;
loadHistory();
} catch (e) {
$('#scan-status').textContent = `Error: ${e.message}`;
} finally { btn.disabled = false; }
}

async function loadDoctor() {
try {
const data = await api('/api/doctor');
$('#doctor').innerHTML = (data.tools || []).map(t => `<div class="doctor-item"><div class="name">${esc(t.name)}</div><div class="status ${t.available ? 'passed' : 'unavailable'}">${t.available ? 'Available' : 'Missing'}</div>${t.path ? `<div class="muted small">${esc(t.path)}</div>` : ''}</div>`).join('');
} catch (e) { $('#doctor').innerHTML = `<p class="muted">Error: ${esc(e.message)}</p>`; }
}

async function loadInventory() {
try {
const target = $('#target').value.trim();
const data = await api(`/api/inventory?path=${encodeURIComponent(target)}`);
$('#inventory-table tbody').innerHTML = (data.symbols || []).map(s => `<tr><td>${esc(s.name)}</td><td>${esc(s.file)}</td><td>${s.line}</td></tr>`).join('') || '<tr><td colspan="3" class="muted">No public symbols found.</td></tr>';
} catch (e) { $('#inventory-table tbody').innerHTML = `<tr><td colspan="3" class="muted">Error: ${esc(e.message)}</td></tr>`; }
}

async function loadPolicy() {
try {
const target = $('#target').value.trim();
const data = await api(`/api/policy?path=${encodeURIComponent(target)}`);
$('#policy-json').textContent = JSON.stringify(data, null, 2);
} catch (e) { $('#policy-json').textContent = `Error: ${e.message}`; }
}

async function loadHistory() {
try {
const target = $('#target').value.trim();
const data = await api(`/api/history?path=${encodeURIComponent(target)}`);
$('#history-table tbody').innerHTML = (data.reports || []).map(r => `<tr>
<td>${esc(new Date(r.generated_at).toLocaleString())}</td><td>${esc(r.project)}</td><td>${fmt(r.score)}</td><td>${esc(r.grade)}</td>
<td><span class="badge ${r.policy_passed ? 'pass' : 'fail'}">${r.policy_passed ? 'PASS' : 'FAIL'}</span></td>
<td><button class="ghost" data-load-report="${esc(r.file)}">Load</button></td>
</tr>`).join('') || '<tr><td colspan="6" class="muted">No saved JSON reports found in .codeproof/reports.</td></tr>';
$$('#history-table [data-load-report]').forEach(btn => btn.addEventListener('click', async () => {
try {
const report = await api(`/api/report?path=${encodeURIComponent(target)}&file=${encodeURIComponent(btn.dataset.loadReport)}`);
renderReport(report); setView('dashboard');
} catch (e) {
$('#history-table tbody').innerHTML = `<tr><td colspan="6" class="muted">Error: ${esc(e.message)}</td></tr>`;
}
}));
} catch (e) { $('#history-table tbody').innerHTML = `<tr><td colspan="6" class="muted">Error: ${esc(e.message)}</td></tr>`; }
}

$$('.nav-btn').forEach(b => b.addEventListener('click', () => setView(b.dataset.view)));
$('#run-scan').addEventListener('click', runScan);
$('#status-filter').addEventListener('change', renderResults);
$('#finding-search').addEventListener('input', renderFindings);
$('#refresh-doctor').addEventListener('click', () => setView('policy'));
$('#load-inventory').addEventListener('click', loadInventory);
$('#load-policy').addEventListener('click', () => { loadPolicy(); loadDoctor(); });
$('#load-history').addEventListener('click', loadHistory);
$('#open-reports').addEventListener('click', async () => {
try { await api('/api/open-reports', { method: 'POST', body: JSON.stringify({ path: $('#target').value.trim() }) }); }
catch (e) { alert(e.message); }
});

(async function init() {
try { const info = await api('/api/info'); $('#target').value = info.default_target || ''; } catch {}
loadDoctor(); loadHistory();
})();
Loading
Loading