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
10 changes: 10 additions & 0 deletions .cloudflare/preview-resources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"account_id": "6fe100eefdfd984dd38a91a1a5643520",
"worker": "github-flow-analytics",
"cache_namespace": "github-flow-analytics-preview-cache",
"users_database": "github-flow-analytics-preview-users",
"rate_limit_namespaces": {
"ANALYZE_LIMIT": "2001",
"CHAT_LIMIT": "2002"
}
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ matches can misread context. Review rationales before interpreting distributions
Existing caches remain usable with title-only classification. Use `python analyze.py OWNER/REPO --refresh` to collect bodies.
`/api/analyze` exposes the additive `value_classification` field; AI contribution
classification remains in `classification`.

### Expected product value

When `GEMINI_API_KEY` is configured, each analysis also judges the value each sampled
PR is expected to deliver to the repository's product (`product_value.py`). One Gemini
call turns the repository description, topics and README into product context: a
summary, value proposition, lean canvas, and the strategic goals the repository
appears focused on. Only public repositories are assessed, and the README is fetched
without the GitHub token so GitHub refuses it if the repository has just gone private;
unauthenticated GitHub calls are limited to 60 per hour per IP, so when that limit is
hit the context uses the description and topics alone. One Gemini call per PR, for the 30 most recent sampled PRs (up to
10 open), then rates expected value as High, Medium, Low or Unclear with confidence,
who benefits, why it matters, the matching goal, and missing context. Content framing
is passed as evidence, but clear outcome language alone does not imply high value.
These are expectations, not verified realized impact. Without a key, or if the context
Comment thread
tessl-app[bot] marked this conversation as resolved.
Resolved
call fails, `/api/analyze` returns `product_value` with a status and reason and the
rest of the analysis is unchanged. The hosted Worker caches each analysis for up to six
hours (ten minutes when a Gemini call failed), so adding or removing the key shows on the
next uncached or force-refreshed analysis. The dashboard shows the context and per-PR
assessments under Content framing.
## Cloudflare deployment

This project uses Cloudflare Python Workers (FastAPI), Workers Static Assets, KV for cached public results, and native Worker rate-limit bindings.
Expand All @@ -82,6 +102,23 @@ runtime dependencies and SDK, and stages only the runtime source files under
Local and CI pip dependencies live in `requirements-local.txt` and
`requirements-dev.txt`; Pywrangler rejects a root `requirements.txt`.

Branch builds use `npx wrangler preview` (Wrangler 4.135.0 or newer), which requires
an explicit `previews` block. Preview resources are declared in
`.cloudflare/preview-resources.json`. Run `python scripts/configure-cloudflare-previews.py`
to inspect the setup. After authorizing resource creation, export the existing
Cloudflare API token from Bitwarden and run the same command with `--apply`.
It reuses or creates the named Preview KV namespace and D1 database, initializes
the empty users/session schema, and writes their real IDs to `wrangler.jsonc`.
Rerunning it reuses those resources. It preserves production bindings and data.

Previews share these staging resources with other branches. They require Google
sign-in and use separate rate-limit namespaces with the same request limits.
Preview URLs are public; protected API endpoints still require a session. The
configured Google OAuth client must allow the Preview's JavaScript origin before
sign-in can work there. This setup leaves Google OAuth settings unchanged.
Preview service secrets are configured separately in Cloudflare's Previews Base;
Gemini assessment requires a Preview `GEMINI_API_KEY`.

The `public/` assets are synced from the root HTML files during deployment. Do not add credentials to `.dev.vars`, source files, or commits. The deployed API only accepts public repositories.

Check current Cloudflare plan limits and pricing before deployment; repository analysis and AI requests incur provider usage.
Expand Down
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import sys
sys.path.insert(0, str(Path(__file__).parent))
from analyze import collect_data, compute_flow_metrics
from product_value import assess_product_value

# ---------------------------------------------------------------------------
# App Setup
Expand Down Expand Up @@ -110,6 +111,8 @@ def _run_analysis(repo: str, force: bool) -> dict:
raise HTTPException(status_code=400, detail="Only public repositories are supported.")
raw = collect_data(repo)
metrics = compute_flow_metrics(raw)
metrics["product_value"] = asyncio.run(assess_product_value(
repo, raw, _get_gemini_key(), os.environ.get("GITHUB_TOKEN")))
return metrics


Expand Down
9 changes: 7 additions & 2 deletions cloudflare_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
from analyze import collect_public_data, compute_flow_metrics
from github_api import request_json
from google_auth import verify_id_token
from product_value import assess_product_value

app = FastAPI(title="GitHub Flow Analytics")
METRICS_CACHE_PREFIX = "metrics:v2:"
METRICS_CACHE_PREFIX = "metrics:v3:"
SESSION_COOKIE = "gha_session"
NONCE_COOKIE = "gha_nonce"
SESSION_SECONDS = 60 * 60 * 24 * 14
Expand Down Expand Up @@ -240,8 +241,12 @@ async def analyze_repo(req: AnalyzeRequest, request: Request):
raise HTTPException(status_code=502, detail="Repository analysis failed. Please try again.") from exc
if not metrics.get("recent_stats", {}).get("total"):
raise HTTPException(status_code=422, detail="No merged pull requests were found for this public repository.")
metrics["product_value"] = await assess_product_value(repo, raw, getattr(env, "GEMINI_API_KEY", None) if env else None, token)
Comment thread
tessl-app[bot] marked this conversation as resolved.
Resolved
if cache:
await cache.put(cache_key, json.dumps(metrics, separators=(",", ":")), expiration_ttl=21600)
value = metrics["product_value"]
# Keep Gemini failures briefly so a later analysis can recover once the service does.
ttl = 600 if value.get("status") == "failed" or value.get("failed") else 21600
await cache.put(cache_key, json.dumps(metrics, separators=(",", ":")), expiration_ttl=ttl)
return metrics


Expand Down
45 changes: 45 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ <h2>Batch Size & Flow Timeline</h2>
<label for="value-level"> Framing </label><select id="value-level" onchange="renderValueItems()"><option value="">All</option></select></p>
<div style="overflow-x:auto;max-height:420px"><table class="issue-table" id="value-items"></table></div>
</div>
<div class="chart-card charts-full" id="product-value-card" style="display:none">
<div class="chart-title">Expected product value (PRs)</div>
<p class="issue-note" id="product-value-note"></p>
<div id="product-value-context"></div>
<div style="overflow-x:auto;max-height:520px"><table class="issue-table" id="product-value-items"></table></div>
</div>
</section>

<!-- Issues -->
Expand Down Expand Up @@ -781,6 +787,45 @@ <h3>Antigravity AI Coach</h3>
renderComet(d.comet_points);
renderIssues(d.issues);
renderValueClassification(d.value_classification);
renderProductValue(d.product_value);
}

function renderProductValue(value) {
const card = document.getElementById('product-value-card');
card.style.display = value ? 'block' : 'none';
if (!value) return;
const note = document.getElementById('product-value-note');
const contextEl = document.getElementById('product-value-context');
const table = document.getElementById('product-value-items');
if (value.status !== 'ok') {
note.textContent = `Not assessed: ${value.reason || 'unavailable.'} ${value.disclaimer}`;
contextEl.innerHTML = '';
table.innerHTML = '';
return;
}
const sources = value.sources || {};
note.textContent = `${value.disclaimer} Assessed ${value.assessed} of the ${value.selected} most recent of ${value.total_prs} sampled PRs` +
(value.failed ? ` (${value.failed} failed)` : '') + '. ' +
value.levels.map(level => `${level}: ${value.counts[level]}`).join(' · ') +
`. Context from ${[sources.description && 'description', sources.readme && (sources.readme_truncated ? 'README (truncated)' : 'README')].filter(Boolean).join(' and ') || 'no repository text'} via ${value.model}.`;
const ctx = value.context || {};
const goals = (ctx.strategic_goals || []).map(goal => `<li>${escapeHtml(goal)}</li>`).join('');
const canvas = Object.entries(ctx.lean_canvas || {}).map(([key, text]) =>
`<tr><td>${escapeHtml(key.replace(/_/g, ' '))}</td><td>${escapeHtml(text)}</td></tr>`).join('');
contextEl.innerHTML = `<p><strong>Product:</strong> ${escapeHtml(ctx.product_summary || 'Unknown')}</p>` +
`<p><strong>Value proposition:</strong> ${escapeHtml(ctx.value_proposition || 'Unknown')}</p>` +
(goals ? `<p><strong>Strategic goals (inferred)</strong></p><ol>${goals}</ol>` : '') +
(canvas ? `<details><summary>Lean canvas (inferred)</summary><table class="issue-table">${canvas}</table></details>` : '') +
(ctx.missing_context ? `<p class="issue-note">Missing context: ${escapeHtml(ctx.missing_context)}</p>` : '');
table.innerHTML = '<thead><tr><th>PR</th><th>State</th><th>Framing</th><th>Expected value</th><th>What, who, why</th><th>Uncertainty</th></tr></thead><tbody>' +
(value.items.map(item => item.status !== 'assessed' ?
`<tr><td>#${escapeHtml(item.number)} ${escapeHtml(item.title)}</td><td>${escapeHtml(item.cohort)}</td><td>${escapeHtml(item.framing)}</td><td colspan="3">Assessment failed.</td></tr>` :
`<tr><td>#${escapeHtml(item.number)} ${escapeHtml(item.title)}</td><td>${escapeHtml(item.cohort)}</td><td>${escapeHtml(item.framing)}</td>` +
`<td>${escapeHtml(item.expected_value)}<br><span class="issue-note">${escapeHtml(item.confidence)} confidence</span></td>` +
`<td>${escapeHtml(item.value_summary)}<br><strong>Benefits:</strong> ${escapeHtml(item.beneficiaries)}<br><strong>Why:</strong> ${escapeHtml(item.why_it_matters)}` +
(item.strategic_goal && item.strategic_goal !== 'None' ? `<br><strong>Goal:</strong> ${escapeHtml(item.strategic_goal)}` : '') + '</td>' +
`<td>${escapeHtml(item.missing_context)}</td></tr>`).join('') ||
'<tr><td colspan="6">No PRs in this sample.</td></tr>') + '</tbody>';
}

let valueClassification = null;
Expand Down
1 change: 1 addition & 0 deletions privacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h2>Information saved</h2>
<p>When you sign in, we save your verified Google email address, Google's stable account identifier, the first and most recent sign-in times, and a sign-in count. We use this information to recognize returning users and understand account usage. We do not use it for marketing, sell it, or send it to the AI coach.</p>
<h2>Repository and AI requests</h2>
<p>Repository analysis uses public GitHub data. If you ask the AI coach a question, the question and repository metrics are sent to Google's Gemini service. Your Google sign-in details are not included in that request.</p>
<p>When an analysis estimates each pull request's expected product value, the repository name, description, topics, homepage and README, and the titles, bodies and change sizes of up to 30 recent pull requests are sent to Google's Gemini service to infer the product's context and judge each pull request. These requests contain only public repository data and no sign-in details.</p>
<h2>Storage and deletion</h2>
<p>Account records and short-lived sign-in sessions are stored in Cloudflare's database. Choose <strong>Delete account</strong> in the app to remove your account record and sign-in sessions. A session cookie stays in your browser for up to fourteen days and is protected from JavaScript access.</p>
<p><a href="/">Return to the dashboard</a></p>
Expand Down
Loading
Loading