broke: a private money app that runs on your own accounts and your own AI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f550865e93
359 files changed
+34290
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env node
|
||||
// broke's MCP server (stdio) for Claude Code sessions. Read-only money tools, acting as one signed-in user:
|
||||
// every call goes to broke's localhost /api/agent/tools with the session's BROKE_TOKEN, where RLS applies.
|
||||
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
const { BROKE_URL, BROKE_TOKEN } = process.env;
|
||||
if (!BROKE_URL || !BROKE_TOKEN) {
|
||||
console.error("broke-mcp: BROKE_URL and BROKE_TOKEN are required");
|
||||
process.exit(1);
|
||||
}
|
||||
const api = (init) =>
|
||||
fetch(`${BROKE_URL}/api/agent/tools`, { ...init, headers: { authorization: `Bearer ${BROKE_TOKEN}`, "content-type": "application/json" } });
|
||||
const expired = { content: [{ type: "text", text: "This broke session has expired. Open the chat in broke again." }], isError: true };
|
||||
|
||||
const server = new Server({ name: "broke", version: "1.0.0" }, { capabilities: { tools: {} } });
|
||||
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||
const res = await api({ method: "GET" });
|
||||
if (!res.ok) return { tools: [] };
|
||||
return { tools: (await res.json()).tools.map((t) => ({ ...t, annotations: { readOnlyHint: true } })) };
|
||||
});
|
||||
|
||||
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
||||
const res = await api({ method: "POST", body: JSON.stringify({ name: req.params.name, input: req.params.arguments ?? {} }) });
|
||||
if (res.status === 403) return expired;
|
||||
const body = await res.json().catch(() => ({}));
|
||||
if (!res.ok) return { content: [{ type: "text", text: JSON.stringify(body) }], isError: true };
|
||||
return { content: [{ type: "text", text: body.text }] };
|
||||
});
|
||||
|
||||
await server.connect(new StdioServerTransport());
|
||||
@@ -0,0 +1,33 @@
|
||||
// Live check of country-aware advice on Claude Code: a US and a UK throwaway user ask the same questions.
|
||||
// The US one should get an HSA question as buttons; the UK one must get no US accounts. Users deleted after.
|
||||
// Uses your Claude Code login (plan allowance). Usage: node --env-file=.env scripts/e2e-advice.mjs
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
const BASE = process.argv[2] ?? "http://localhost:3000";
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
const US_TERMS = /401\(k\)|\b529\b|\bIRA\b|\bIRS\b|HSA[^.]*(eligible|contribut|open one(?! in))/;
|
||||
|
||||
for (const country of ["US", "GB"]) {
|
||||
const email = `advice-${country}-${Date.now()}@broke.test`, password = randomBytes(18).toString("base64url");
|
||||
const { data: created, error } = await admin.auth.admin.createUser({ email, password, email_confirm: true, user_metadata: { profile: { country, age: "30-39" } } });
|
||||
if (error) throw error;
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s } = await anon.auth.signInWithPassword({ email, password });
|
||||
const cookie = `sb-${ref}-auth-token=base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`;
|
||||
for (const q of ["Should I be using an HSA?", "I want to save a deposit for my first home. Where should I keep it?"]) {
|
||||
const res = await fetch(BASE + "/api/assistant", { method: "POST", headers: { cookie }, body: JSON.stringify({ provider: "claude", messages: [{ role: "user", content: q }] }) });
|
||||
const text = (await res.text()).replace(/\n?\u001e\S+\n/g, "").trim();
|
||||
const ask = text.match(/```ask\s*\n([\s\S]*?)```/)?.[1];
|
||||
console.log(`\n[${country}] > ${q} (${res.status})\n${text.slice(0, 900)}`);
|
||||
console.log(`ask block: ${ask ? "yes" : "no"}${ask ? " " + ask.trim() : ""}`);
|
||||
if (country !== "US") console.log(`US terms leaked: ${US_TERMS.test(text) ? "YES <-- " + text.match(US_TERMS)[0] : "no"}`);
|
||||
}
|
||||
} finally {
|
||||
await admin.auth.admin.deleteUser(created.user.id);
|
||||
}
|
||||
}
|
||||
console.log("\ntest users deleted");
|
||||
@@ -0,0 +1,36 @@
|
||||
// Live check of Ask broke on Claude Code: throwaway user -> sandbox bank -> two questions -> user deleted.
|
||||
// Uses your Claude Code login (plan allowance). Usage: node --env-file=.env scripts/e2e-assistant.mjs
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
const BASE = process.argv[2] ?? "http://localhost:3000";
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
const email = `ai-${Date.now()}@broke.test`;
|
||||
const password = randomBytes(18).toString("base64url");
|
||||
const { data: created, error: ce } = await admin.auth.admin.createUser({ email, password, email_confirm: true });
|
||||
if (ce) throw ce;
|
||||
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s } = await anon.auth.signInWithPassword({ email, password });
|
||||
const cookie = `sb-${ref}-auth-token=base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`;
|
||||
const post = (p, body) => fetch(BASE + p, { method: "POST", redirect: "manual", headers: { cookie }, body: JSON.stringify(body) });
|
||||
|
||||
console.log("sandbox:", (await post("/api/plaid/sandbox", {})).status);
|
||||
const models = await (await fetch(BASE + "/api/models", { headers: { cookie } })).json();
|
||||
console.log("providers:", models.providers.map((p) => `${p.id}=${p.ready ? "ready" : p.reason}`).join(", "));
|
||||
|
||||
for (const q of ["How much did I spend on dining in the last 30 days?", "Run the shell command `ls` and show me the output."]) {
|
||||
const t0 = Date.now();
|
||||
const res = await post("/api/assistant", { provider: "claude", messages: [{ role: "user", content: q }] });
|
||||
const text = await res.text();
|
||||
console.log(`\n> ${q}\n[${res.status}, session ${res.headers.get("x-session-id") ? "yes" : "no"}, ${((Date.now() - t0) / 1000).toFixed(0)} s]`);
|
||||
console.log("status lines:", [...text.matchAll(/\u001e(\S+)/g)].map((m) => m[1]).join(", ") || "none");
|
||||
console.log(text.replace(/\n?\u001e\S+\n/g, "").trim().slice(0, 600));
|
||||
}
|
||||
} finally {
|
||||
await admin.auth.admin.deleteUser(created.user.id);
|
||||
console.log("\ntest user deleted");
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// End-to-end smoke test against the running dev server: throwaway user -> sandbox bank -> pages -> delete user.
|
||||
// Usage: node --env-file=.env scripts/e2e-sandbox.mjs [http://localhost:3000]
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
const BASE = process.argv[2] ?? "http://localhost:3000";
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
|
||||
const email = `e2e-${Date.now()}@broke.test`;
|
||||
const password = randomBytes(18).toString("base64url");
|
||||
const { data: created, error: ce } = await admin.auth.admin.createUser({ email, password, email_confirm: true });
|
||||
if (ce) throw ce;
|
||||
const uid = created.user.id;
|
||||
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s, error: se } = await anon.auth.signInWithPassword({ email, password });
|
||||
if (se) throw se;
|
||||
const cookie = `sb-${ref}-auth-token=base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`;
|
||||
const get = (p, init = {}) => fetch(BASE + p, { ...init, redirect: "manual", headers: { cookie, ...(init.headers ?? {}) } });
|
||||
|
||||
const link = await get("/api/plaid/sandbox", { method: "POST" });
|
||||
console.log("sandbox link:", link.status, await link.text());
|
||||
|
||||
// RLS check: this user must not be able to read the Plaid access token column.
|
||||
const authed = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, {
|
||||
global: { headers: { Authorization: `Bearer ${s.session.access_token}` } },
|
||||
auth: { persistSession: false },
|
||||
});
|
||||
const tok = await authed.from("plaid_items").select("access_token");
|
||||
console.log("user can read access_token:", tok.error ? `no (${tok.error.code})` : "YES - LEAK");
|
||||
const own = await authed.from("transactions").select("id", { count: "exact", head: true });
|
||||
console.log("user sees own transactions:", own.count);
|
||||
|
||||
for (const p of ["/", "/transactions", "/spending", "/recurring", "/accounts"]) {
|
||||
const r = await get(p);
|
||||
const html = await r.text();
|
||||
console.log(p, r.status, /Application error|Unhandled Runtime Error|Internal Server Error/.test(html) ? "ERROR IN PAGE" : "ok");
|
||||
}
|
||||
} finally {
|
||||
await admin.auth.admin.deleteUser(uid); // cascades to the user's rows
|
||||
console.log("test user deleted");
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Hover-state screenshots: spend chart crosshair, a month bar, a donut slice, a transaction row.
|
||||
// Usage: node --env-file=.env scripts/hover-shots.mjs <outdir>
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import puppeteer from "puppeteer-core";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
const BASE = "http://localhost:3000", OUT = process.argv[2] ?? "hover";
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL, ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
const email = `hover-${Date.now()}@broke.test`, password = randomBytes(18).toString("base64url");
|
||||
const { data: c } = await admin.auth.admin.createUser({ email, password, email_confirm: true });
|
||||
const browser = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: true });
|
||||
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s } = await anon.auth.signInWithPassword({ email, password });
|
||||
const page = await browser.newPage();
|
||||
await page.setViewport({ width: 1440, height: 1000, deviceScaleFactor: 2 });
|
||||
await browser.setCookie({ name: `sb-${ref}-auth-token`, value: `base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`, domain: "localhost", path: "/" });
|
||||
await page.goto(BASE + "/");
|
||||
await page.evaluate(() => fetch("/api/plaid/sandbox", { method: "POST" }).then((r) => r.text()));
|
||||
|
||||
await page.goto(BASE + "/", { waitUntil: "networkidle0" }); await wait(1500);
|
||||
const chart = await page.$("svg[aria-label^='Cumulative']");
|
||||
const box = await chart.boundingBox();
|
||||
await page.mouse.move(box.x + box.width * 0.45, box.y + box.height * 0.5); await wait(300);
|
||||
await (await chart.evaluateHandle((n) => n.closest(".card"))).asElement().screenshot({ path: `${OUT}/chart-hover.png` });
|
||||
const row = await page.$("a.row-hover"); await row.hover(); await wait(300);
|
||||
await (await row.evaluateHandle((n) => n.closest(".card"))).asElement().screenshot({ path: `${OUT}/row-hover.png` });
|
||||
|
||||
await page.goto(BASE + "/spending", { waitUntil: "networkidle0" }); await wait(1500);
|
||||
const bars = await page.$$("a[aria-label*=': $']"); await bars[3].hover(); await wait(300);
|
||||
await (await bars[3].evaluateHandle((n) => n.closest(".card"))).asElement().screenshot({ path: `${OUT}/bars-hover.png` });
|
||||
const slice = await page.$("[data-slice]"); await slice.hover(); await wait(500);
|
||||
await (await slice.evaluateHandle((n) => n.closest(".card"))).asElement().screenshot({ path: `${OUT}/donut-hover.png` });
|
||||
await page.goto(BASE + "/transactions", { waitUntil: "networkidle0" }); await wait(800);
|
||||
await page.locator("button[aria-label='Categories']").click(); await wait(400);
|
||||
await page.keyboard.type("din"); await wait(300);
|
||||
await page.screenshot({ path: `${OUT}/dropdown.png`, clip: { x: 240, y: 60, width: 1200, height: 520 } });
|
||||
// Keyboard focus: tab into the page and capture the focus ring.
|
||||
await page.goto(BASE + "/", { waitUntil: "networkidle0" }); await wait(1200);
|
||||
for (let i = 0; i < 9; i++) await page.keyboard.press("Tab");
|
||||
await page.screenshot({ path: `${OUT}/focus.png`, clip: { x: 0, y: 0, width: 1440, height: 700 } });
|
||||
// Transaction row note editor open.
|
||||
await page.goto(BASE + "/transactions", { waitUntil: "networkidle0" }); await wait(800);
|
||||
await page.locator("button[title='Add a note']").click(); await wait(300);
|
||||
await page.screenshot({ path: `${OUT}/note.png`, clip: { x: 240, y: 60, width: 1200, height: 400 } });
|
||||
// Phone width: what can you do with a transaction?
|
||||
await page.setViewport({ width: 390, height: 844, deviceScaleFactor: 2 });
|
||||
await page.goto(BASE + "/transactions", { waitUntil: "networkidle0" }); await wait(800);
|
||||
await page.screenshot({ path: `${OUT}/txn-phone.png` });
|
||||
await page.locator("tbody tr").click(); await wait(400);
|
||||
await page.screenshot({ path: `${OUT}/sheet.png` });
|
||||
await page.locator("[role=dialog] button.btn").click(); await wait(600);
|
||||
await page.screenshot({ path: `${OUT}/toast.png` });
|
||||
await page.keyboard.press("Escape"); await wait(200);
|
||||
await page.goto(BASE + "/transactions", { waitUntil: "networkidle0" }); await wait(800);
|
||||
await page.locator("button[aria-label='Accounts']").click(); await wait(400);
|
||||
await page.screenshot({ path: `${OUT}/dropdown-phone.png` });
|
||||
await page.goto(BASE + "/", { waitUntil: "networkidle0" }); await wait(1200);
|
||||
await page.screenshot({ path: `${OUT}/dash-phone.png` });
|
||||
await page.locator("nav[aria-label=Main] button[aria-expanded]").click(); await wait(300);
|
||||
await page.screenshot({ path: `${OUT}/more-phone.png` });
|
||||
await page.goto(BASE + "/accounts", { waitUntil: "networkidle0" }); await wait(800);
|
||||
await page.screenshot({ path: `${OUT}/accounts-phone.png` });
|
||||
await page.goto(BASE + "/login", { waitUntil: "networkidle0" }); await wait(500);
|
||||
await page.screenshot({ path: `${OUT}/login-phone.png` });
|
||||
} finally {
|
||||
await browser.close();
|
||||
await admin.auth.admin.deleteUser(c.user.id);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Applies pending database migrations. Usage: npm run migrate (reads SUPABASE_DB_URL from .env).
|
||||
import { migrate } from "../src/lib/migrate.ts";
|
||||
|
||||
const r = await migrate();
|
||||
if (!r.configured) {
|
||||
console.log("SUPABASE_DB_URL is not set in .env. Open http://localhost:3000/setup for where to find it.");
|
||||
process.exit(1);
|
||||
}
|
||||
if (r.error) {
|
||||
console.error(r.error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(r.applied.length ? `Applied: ${r.applied.join(", ")}` : `Database is up to date (${r.total} migrations).`);
|
||||
@@ -0,0 +1,136 @@
|
||||
// End to end check of "AI and your data", as a throwaway sandbox user. Usage: node --env-file=.env scripts/privacy-e2e.mjs
|
||||
// Summary only: asks the chat through Claude Code and captures what broke's MCP tools handed the model, by pointing
|
||||
// the CLI's callback at a logging proxy on :3999 (the app picks the callback port from the request's Host).
|
||||
// Off: the chat is refused and no CLI starts. Also checks no Claude Code transcript is written. Deletes the user in finally.
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { cleanName } from "../src/lib/format.ts";
|
||||
import { bankEvent } from "../src/lib/privacy.ts";
|
||||
import http from "node:http";
|
||||
import { execSync } from "node:child_process";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { readdirSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
// The dev server (:3001) by default; BROKE_PORT=3000 for the production build.
|
||||
const APP = Number(process.env.BROKE_PORT ?? 3001), PROXY = 3999;
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL, ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
const email = `privacy-${Date.now()}@broke.test`, password = randomBytes(18).toString("base64url");
|
||||
// Claude Code keeps transcripts per folder, named after the folder path (~/.broke/agent).
|
||||
const TRANSCRIPTS = join(homedir(), ".claude", "projects", join(homedir(), ".broke", "agent").replace(/[/.]/g, "-"));
|
||||
const count = () => { try { return readdirSync(TRANSCRIPTS).length; } catch { return 0; } };
|
||||
|
||||
const captured = []; // every /api/agent/tools exchange: { name, input, text }
|
||||
const forward = (req, body, headers = req.headers) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const r = http.request({ host: "127.0.0.1", port: APP, path: req.url, method: req.method, headers: { ...headers, host: `127.0.0.1:${APP}` } }, (res) => {
|
||||
const chunks = [];
|
||||
res.on("data", (c) => chunks.push(c));
|
||||
res.on("end", () => resolve({ status: res.statusCode, headers: res.headers, body: Buffer.concat(chunks) }));
|
||||
});
|
||||
r.on("error", reject);
|
||||
r.end(body);
|
||||
});
|
||||
const proxy = http.createServer((req, res) => {
|
||||
const chunks = [];
|
||||
req.on("data", (c) => chunks.push(c));
|
||||
req.on("end", async () => {
|
||||
const body = Buffer.concat(chunks);
|
||||
const out = await forward(req, body);
|
||||
if (req.url.startsWith("/api/agent/tools") && req.method === "POST") {
|
||||
const sent = JSON.parse(body.toString() || "{}");
|
||||
captured.push({ name: sent.name, input: sent.input, status: out.status, text: JSON.parse(out.body.toString() || "{}").text });
|
||||
}
|
||||
res.writeHead(out.status, { "content-type": out.headers["content-type"] ?? "application/json" });
|
||||
res.end(out.body);
|
||||
});
|
||||
});
|
||||
await new Promise((r) => proxy.listen(PROXY, "127.0.0.1", r));
|
||||
|
||||
// Chat as the browser does, but with Host :3999 so the MCP callback goes through the proxy.
|
||||
const chat = (cookie, q) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const r = http.request({ host: "127.0.0.1", port: APP, path: "/api/assistant", method: "POST", headers: { host: `127.0.0.1:${PROXY}`, cookie, "content-type": "application/json" } }, (res) => {
|
||||
let text = "";
|
||||
res.on("data", (c) => (text += c));
|
||||
res.on("end", () => resolve({ status: res.statusCode, text }));
|
||||
});
|
||||
r.on("error", reject);
|
||||
r.end(JSON.stringify({ provider: "claude", messages: [{ role: "user", content: q }] }));
|
||||
});
|
||||
const claudeProcs = () => Number(execSync("pgrep -f 'no-session-persistence' | wc -l").toString().trim() || 0);
|
||||
|
||||
const { data: c, error: ce } = await admin.auth.admin.createUser({ email, password, email_confirm: true, user_metadata: { profile: { country: "US", notes: "my secret note about rent" } } });
|
||||
if (ce) throw ce;
|
||||
const uid = c.user.id;
|
||||
let failed = false;
|
||||
const check = (ok, what) => (console.log(`${ok ? "ok " : "FAIL"} ${what}`), ok || (failed = true));
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s } = await anon.auth.signInWithPassword({ email, password });
|
||||
const cookie = `sb-${ref}-auth-token=base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`;
|
||||
const link = await fetch(`http://127.0.0.1:${APP}/api/plaid/sandbox`, { method: "POST", headers: { cookie } });
|
||||
console.log("sandbox bank:", link.status);
|
||||
for (let i = 0; i < 30; i++) {
|
||||
const { count: n } = await admin.from("transactions").select("id", { count: "exact", head: true }).eq("user_id", uid);
|
||||
const { count: r } = await admin.from("recurring").select("id", { count: "exact", head: true }).eq("user_id", uid);
|
||||
if (n > 20 && r > 0) break;
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
}
|
||||
|
||||
// What must never reach the model.
|
||||
const [{ data: txns }, { data: accts }, { data: recur }] = await Promise.all([
|
||||
admin.from("transactions").select("name, merchant_name, amount, date").eq("user_id", uid),
|
||||
admin.from("accounts").select("name, custom_name, mask").eq("user_id", uid),
|
||||
admin.from("recurring").select("merchant_name").eq("user_id", uid),
|
||||
]);
|
||||
const merchants = new Set([...txns.flatMap((t) => [t.merchant_name, cleanName(t.name)]), ...recur.map((r) => r.merchant_name)].filter((n) => n && n.length >= 4));
|
||||
const masks = new Set(accts.map((a) => a.mask).filter(Boolean));
|
||||
const acctNames = new Set(accts.flatMap((a) => [a.name, a.custom_name]).filter((n) => n && n.length >= 4));
|
||||
const exact = new Set(txns.map((t) => Math.abs(Number(t.amount))).filter((n) => !Number.isInteger(n)).map((n) => n.toFixed(2)));
|
||||
console.log(`user has ${txns.length} transactions, ${merchants.size} merchant names, ${masks.size} masks, ${exact.size} amounts with cents`);
|
||||
|
||||
// 1. Summary only (the default) through Claude Code.
|
||||
const before = count();
|
||||
const q = "Which merchants did I spend the most at in the last two months, and which recurring charges do I have? Name them.";
|
||||
const reply = await chat(cookie, q);
|
||||
console.log("\n--- reply shown to the user ---\n" + reply.text.replace(/\u001e/g, "> ") + "\n--- end reply ---\n");
|
||||
console.log(`--- ${captured.length} MCP tool results the model got ---`);
|
||||
for (const t of captured) console.log(`# ${t.name} ${JSON.stringify(t.input)}\n${t.text}\n`);
|
||||
const all = captured.map((t) => t.text ?? "").join("\n");
|
||||
const lower = all.toLowerCase();
|
||||
check(reply.status === 200, "chat answered in summary mode");
|
||||
check(captured.length > 0, "the model called broke's tools");
|
||||
// Bank events ("Interest", "Payment") go to the model as what they are ("card or loan interest"), by design.
|
||||
const leakedNames = [...[...merchants].filter((n) => !bankEvent(n)), ...acctNames].filter((n) => lower.includes(n.toLowerCase()));
|
||||
check(!leakedNames.length, `no merchant or account names in tool results${leakedNames.length ? `: ${leakedNames.join(", ")}` : ""}`);
|
||||
// A mask would be a string ("1111", "••1111"); rounded totals are bare numbers and can look the same.
|
||||
const leakedMasks = [...masks].filter((m) => new RegExp(`["•*x]${m}"|mask`).test(all));
|
||||
check(!leakedMasks.length, `no account masks${leakedMasks.length ? `: ${leakedMasks.join(", ")}` : ""}`);
|
||||
const leakedAmounts = [...exact].filter((a) => all.includes(a));
|
||||
check(!leakedAmounts.length, `no exact amounts${leakedAmounts.length ? `: ${leakedAmounts.slice(0, 5).join(", ")}` : ""}`);
|
||||
check(!/\b\d{4}-\d{2}-\d{2}\b/.test(all), "no day-level dates");
|
||||
check(!/secret note/.test(all), "no profile notes");
|
||||
const placeholders = [...new Set(all.match(/⟨[MSIAHL]\d+⟩/g) ?? [])];
|
||||
check(placeholders.length > 0, `tool results used placeholders (${placeholders.slice(0, 6).join(", ")})`);
|
||||
check(!/⟨[^⟩]*⟩|\b(?:Merchant [A-Z]{1,2}|Subscriptions? \d+)\b/.test(reply.text), "reply has no placeholders left");
|
||||
const shown = [...merchants].filter((n) => reply.text.toLowerCase().includes(n.toLowerCase()));
|
||||
check(shown.length > 0, `reply names real merchants, swapped back on this Mac (${shown.slice(0, 5).join(", ")})`);
|
||||
check(count() === before, `no Claude Code transcript written (${count()} files before and after)`);
|
||||
|
||||
// 2. Off: refused before any CLI starts.
|
||||
await admin.auth.admin.updateUserById(uid, { user_metadata: { ...c.user.user_metadata, ai_mode: "off" } });
|
||||
captured.length = 0;
|
||||
const procs = claudeProcs();
|
||||
const off = await chat(cookie, "How much did I spend?");
|
||||
check(off.status === 403, `Off: chat refused (${off.status} ${off.text})`);
|
||||
check(captured.length === 0 && claudeProcs() <= procs, "Off: no CLI started and no tool called");
|
||||
const ci = await fetch(`http://127.0.0.1:${APP}/api/checkins`, { method: "POST", headers: { cookie, "content-type": "application/json" }, body: JSON.stringify({ refresh: true }) }).then((r) => r.json());
|
||||
check(ci.summary === null && ci.provider === null, "Off: check-in written from plain facts, no model");
|
||||
} finally {
|
||||
await admin.auth.admin.deleteUser(uid);
|
||||
proxy.close();
|
||||
console.log(failed ? "\nprivacy e2e: FAILED" : "\nprivacy e2e: ok");
|
||||
process.exitCode = failed ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Screenshots of "AI and your data" as a throwaway sandbox user: the Settings card, the "What Claude sees" modal and
|
||||
// the chat panel line, light and dark, 1440 and 390 wide, at 2x. Usage: node --env-file=.env scripts/privacy-shots.mjs <outdir>
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import puppeteer from "puppeteer-core";
|
||||
import { mkdirSync } from "node:fs";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
const BASE = "http://localhost:3000", OUT = process.argv[2] ?? ".context/privacy";
|
||||
mkdirSync(OUT, { recursive: true });
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL, ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
const email = `shots-${Date.now()}@broke.test`, password = randomBytes(18).toString("base64url");
|
||||
const { data: c } = await admin.auth.admin.createUser({ email, password, email_confirm: true, user_metadata: { profile: { country: "US" } } });
|
||||
const browser = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: true });
|
||||
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s } = await anon.auth.signInWithPassword({ email, password });
|
||||
await browser.setCookie({ name: `sb-${ref}-auth-token`, value: `base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`, domain: "localhost", path: "/" });
|
||||
const page = await browser.newPage();
|
||||
page.on("pageerror", (e) => console.log("page error:", String(e).slice(0, 300)));
|
||||
await page.goto(BASE + "/");
|
||||
await page.evaluate(() => fetch("/api/plaid/sandbox", { method: "POST" }).then((r) => r.text()));
|
||||
await wait(8000); // let the sync land so the summary has data
|
||||
|
||||
for (const width of [1440, 390])
|
||||
for (const theme of ["light", "dark"]) {
|
||||
const tag = `${width}-${theme}`;
|
||||
await page.setViewport({ width, height: width > 500 ? 1000 : 844, deviceScaleFactor: 2 });
|
||||
await page.emulateMediaFeatures([{ name: "prefers-color-scheme", value: theme }]);
|
||||
await page.goto(BASE + "/settings#ai", { waitUntil: "networkidle0" });
|
||||
await page.evaluate((t) => document.documentElement.setAttribute("data-theme", t), theme);
|
||||
await wait(1200);
|
||||
// The phone tab bar is fixed over the bottom of the page: hide it so the card and its button show.
|
||||
await page.evaluate(() => document.querySelectorAll("body *").forEach((e) => getComputedStyle(e).position === "fixed" && e.tagName !== "DIALOG" && (e.style.visibility = "hidden")));
|
||||
const card = await page.waitForSelector("::-p-xpath(//section[.//h3[text()='AI and your data']])");
|
||||
await card.screenshot({ path: `${OUT}/settings-card-${tag}.png` });
|
||||
|
||||
await page.locator("::-p-text(What Claude sees)").click();
|
||||
await page.waitForSelector("dialog[open] pre", { timeout: 30000 });
|
||||
await wait(500);
|
||||
const modal = await page.$("dialog[open] > div");
|
||||
await modal.screenshot({ path: `${OUT}/what-claude-sees-${tag}.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
await wait(300);
|
||||
|
||||
await page.goto(BASE + "/", { waitUntil: "networkidle0" });
|
||||
await page.evaluate((t) => document.documentElement.setAttribute("data-theme", t), theme);
|
||||
await page.evaluate(() => [...document.querySelectorAll("button")].find((b) => /ask broke|broke ai|ask ai/i.test(b.textContent ?? "") && b.offsetParent)?.click());
|
||||
await page.waitForSelector('dialog[aria-label="broke ai chat"] header');
|
||||
await wait(800);
|
||||
const panel = await page.$('dialog[aria-label="broke ai chat"] > div');
|
||||
const height = await page.evaluate(() => {
|
||||
const h = document.querySelector('dialog[aria-label="broke ai chat"] header');
|
||||
return h.nextElementSibling.getBoundingClientRect().bottom - h.getBoundingClientRect().top + 24;
|
||||
});
|
||||
const { width: w } = await panel.boundingBox();
|
||||
await panel.screenshot({ path: `${OUT}/chat-line-${tag}.png`, clip: { x: 0, y: 0, width: w, height } });
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
await admin.auth.admin.deleteUser(c.user.id);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Screenshots each page as a throwaway sandbox user. Usage: node --env-file=.env scripts/screens.mjs <outdir>
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import puppeteer from "puppeteer-core";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
const BASE = "http://localhost:3000", OUT = process.argv[2] ?? "screens";
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL, ref = new URL(url).hostname.split(".")[0];
|
||||
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
const email = `shots-${Date.now()}@broke.test`, password = randomBytes(18).toString("base64url");
|
||||
const { data: c } = await admin.auth.admin.createUser({ email, password, email_confirm: true, user_metadata: { profile: { country: "US" } } });
|
||||
const browser = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: true });
|
||||
try {
|
||||
const anon = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, { auth: { persistSession: false } });
|
||||
const { data: s } = await anon.auth.signInWithPassword({ email, password });
|
||||
const value = `base64-${Buffer.from(JSON.stringify(s.session)).toString("base64url")}`;
|
||||
const page = await browser.newPage();
|
||||
// Surface client errors (the dev overlay's "Issue" badge) in the run output.
|
||||
page.on("console", (m) => m.type() === "error" && console.log("console error:", page.url(), m.text().slice(0, 1500)));
|
||||
page.on("response", (r) => r.status() >= 400 && console.log("http", r.status(), r.url().replace(/\?.*/, "")));
|
||||
page.on("pageerror", (e) => console.log("page error:", page.url(), String(e).slice(0, 300)));
|
||||
await page.setViewport({ width: Number(process.env.WIDTH ?? 1440), height: 1000, deviceScaleFactor: 1 });
|
||||
await browser.setCookie({ name: `sb-${ref}-auth-token`, value, domain: "localhost", path: "/" });
|
||||
await page.goto(BASE + "/");
|
||||
if (!process.env.EMPTY) await page.evaluate(() => fetch("/api/plaid/sandbox", { method: "POST" }).then((r) => r.text())); // EMPTY=1: a brand-new user with no bank
|
||||
for (const p of (process.env.PAGES ? process.env.PAGES.split(",") : ["/", "/spending", "/transactions", "/recurring", "/accounts", "/optimize", "/insights", "/budgets"])) {
|
||||
await page.goto(BASE + p, { waitUntil: "networkidle0" });
|
||||
await new Promise((r) => setTimeout(r, 1200)); // let entrance animations finish
|
||||
await page.screenshot({ path: `${OUT}/${p === "/" ? "dashboard" : p.slice(1)}.png`, fullPage: true });
|
||||
}
|
||||
await page.goto(BASE + "/", { waitUntil: "networkidle0" });
|
||||
await page.locator("::-p-text(Ask broke)").click();
|
||||
await page.waitForSelector("dialog textarea");
|
||||
await page.screenshot({ path: `${OUT}/assistant-panel.png` });
|
||||
} finally {
|
||||
await browser.close();
|
||||
await admin.auth.admin.deleteUser(c.user.id);
|
||||
}
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
// Starts broke on this computer and opens it. Before the keys are in, it runs in development mode: the setup page saves
|
||||
// keys and the server picks them up without a restart. After that it runs the faster production build.
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
process.chdir(root);
|
||||
if (Number(process.versions.node.split(".")[0]) < 20) {
|
||||
console.error(`broke needs Node.js 20 or newer (this is ${process.version}). Get it from https://nodejs.org`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const win = process.platform === "win32";
|
||||
const npm = (...args) => spawnSync("npm", args, { stdio: "inherit", shell: win }).status === 0;
|
||||
if (!existsSync("node_modules") && !npm("install")) process.exit(1);
|
||||
|
||||
const env = {};
|
||||
for (const f of [".env", ".env.local"]) {
|
||||
if (!existsSync(f)) continue;
|
||||
for (const m of readFileSync(f, "utf8").matchAll(/^([A-Z0-9_]+)=(.*)$/gm)) env[m[1]] = m[2].trim();
|
||||
}
|
||||
const isSet = (v) => !!v && !/^your[_-]|your-project|YOUR-PASSWORD/.test(v); // same rule as lib/setup.ts
|
||||
const ready = ["NEXT_PUBLIC_SUPABASE_URL", "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY", "SUPABASE_SERVICE_ROLE_KEY"].every((k) => isSet(env[k]));
|
||||
|
||||
const port = process.env.PORT || "3000";
|
||||
const url = `http://localhost:${port}${ready ? "" : "/setup"}`;
|
||||
const openIt = () => { if (!process.env.BROKE_NO_OPEN) spawn(win ? "cmd" : process.platform === "darwin" ? "open" : "xdg-open", win ? ["/c", "start", url] : [url], { stdio: "ignore", detached: true }).on("error", () => {}).unref(); };
|
||||
// Started twice: open the one already running instead of failing on a busy port.
|
||||
if (await fetch(url, { redirect: "manual" }).then(() => true, () => false)) {
|
||||
console.log(`broke is already running at ${url}.`);
|
||||
openIt();
|
||||
process.exit(0);
|
||||
}
|
||||
if (ready && !npm("run", "build")) process.exit(1);
|
||||
const next = join("node_modules", ".bin", win ? "next.cmd" : "next");
|
||||
// Listens on this computer only, which is what makes saving keys from the page safe (writeGate checks the rest).
|
||||
const args = ready ? ["start", "-H", "127.0.0.1", "-p", port] : ["dev", "--turbopack", "-H", "127.0.0.1", "-p", port];
|
||||
const server = spawn(next, args, { stdio: "inherit", shell: win, env: { ...process.env, ALLOW_SETUP_WRITES: "1" } });
|
||||
server.on("exit", (code) => process.exit(code ?? 0));
|
||||
process.on("SIGINT", () => server.kill("SIGINT"));
|
||||
|
||||
for (let i = 0; i < 60; i++) {
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
const up = await fetch(url, { redirect: "manual" }).then(() => true, () => false);
|
||||
if (!up) continue;
|
||||
console.log(`\nbroke is running at ${url}. Press Ctrl+C to stop it.\n`);
|
||||
openIt();
|
||||
break;
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env node
|
||||
// Brings in the latest broke, keeping your own changes. Your data and keys aren't touched.
|
||||
// A copy made by Vercel's deploy button starts with a new history, so git can't see it came from broke. The first update
|
||||
// finds the broke commit it was copied from and joins the two, so only real differences get merged.
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const UPSTREAM = process.env.BROKE_REPO || "https://github.com/nextwork-projects/broke.git";
|
||||
const ci = process.argv.includes("--ci"); // GitHub's update button: it pushes, and Vercel does the install
|
||||
const inherit = { stdio: "inherit", shell: process.platform === "win32" };
|
||||
const run = (...args) => spawnSync("git", args, inherit).status === 0;
|
||||
const out = (...args) => spawnSync("git", args, { encoding: "utf8" }).stdout.trim();
|
||||
const fail = (m) => { console.error(`\n${m}`); process.exit(1); };
|
||||
|
||||
if (out("status", "--porcelain")) fail("You have changes that aren't committed. Commit them first: git add -A && git commit -m \"My changes\"");
|
||||
if (!run("fetch", "--quiet", UPSTREAM, "main")) fail("Couldn't reach broke's repo. Check your connection and try again.");
|
||||
const theirs = out("rev-parse", "FETCH_HEAD");
|
||||
if (!out("merge-base", "HEAD", theirs)) {
|
||||
const start = out("rev-list", "--max-parents=0", "HEAD").split("\n")[0];
|
||||
const tree = out("rev-parse", `${start}^{tree}`);
|
||||
const from = out("log", "--format=%H %T", theirs).split("\n").map((l) => l.split(" ")).find(([, t]) => t === tree)?.[0];
|
||||
if (!from) fail("Couldn't tell which version of broke this copy started from. Run `claude` here and ask it to merge " + UPSTREAM);
|
||||
const joined = out("commit-tree", "HEAD^{tree}", "-p", "HEAD", "-p", from, "-m", "Join this copy to broke's history");
|
||||
if (!run("merge", "--quiet", "--ff-only", joined)) fail("Couldn't join this copy to broke's history.");
|
||||
}
|
||||
if (!run("merge", "--no-edit", theirs)) fail("Your changes and the update touch the same lines. Run `claude` here and ask it to resolve the merge.");
|
||||
if (!ci && spawnSync("npm", ["install"], inherit).status !== 0) process.exit(1);
|
||||
console.log(ci ? "\nUpdated." : "\nUpdated. Start broke again to use it. New database changes apply when it starts.");
|
||||
Reference in new issue
Block a user