feat: major platform expansion — Brain service, RSS reader, iOS app, AI assistants, Firefox extension
All checks were successful
Security Checks / dependency-audit (push) Successful in 1m13s
Security Checks / secret-scanning (push) Successful in 3s
Security Checks / dockerfile-lint (push) Successful in 3s

Brain Service:
- Playwright stealth crawler replacing browserless (og:image, Readability, Reddit JSON API)
- AI classification with tag definitions and folder assignment
- YouTube video download via yt-dlp
- Karakeep migration complete (96 items)
- Taxonomy management (folders with icons/colors, tags)
- Discovery shuffle, sort options, search (Meilisearch + pgvector)
- Item tag/folder editing, card color accents

RSS Reader Service:
- Custom FastAPI reader replacing Miniflux
- Feed management (add/delete/refresh), category support
- Full article extraction via Readability
- Background content fetching for new entries
- Mark all read with confirmation
- Infinite scroll, retention cleanup (30/60 day)
- 17 feeds migrated from Miniflux

iOS App (SwiftUI):
- Native iOS 17+ app with @Observable architecture
- Cookie-based auth, configurable gateway URL
- Dashboard with custom background photo + frosted glass widgets
- Full fitness module (today/templates/goals/food library)
- AI assistant chat (fitness + brain, raw JSON state management)
- 120fps ProMotion support

AI Assistants (Gateway):
- Unified dispatcher with fitness/brain domain detection
- Fitness: natural language food logging, photo analysis, multi-item splitting
- Brain: save/append/update/delete notes, search & answer, undo support
- Madiha user gets fitness-only (brain disabled)

Firefox Extension:
- One-click save to Brain from any page
- Login with platform credentials
- Right-click context menu (save page/link/image)
- Notes field for URL saves
- Signed and published on AMO

Other:
- Reader bookmark button routes to Brain (was Karakeep)
- Fitness food library with "Add" button + add-to-meal popup
- Kindle send file size check (25MB SMTP2GO limit)
- Atelier UI as default (useAtelierShell=true)
- Mobile upload box in nav drawer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yusuf Suleman
2026-04-03 00:56:29 -05:00
parent af1765bd8e
commit 4592e35732
97 changed files with 11009 additions and 532 deletions

View File

@@ -0,0 +1,250 @@
"use strict";
var API_BASE = "https://dash.quadjourney.com";
console.log("[Brain] Background script loaded");
// ── Auth helpers ──
function getSession() {
return browser.storage.local.get("brainSession").then(function(data) {
return data.brainSession || null;
});
}
function apiRequest(path, opts) {
return getSession().then(function(session) {
if (!session) throw new Error("Not logged in");
opts = opts || {};
opts.headers = opts.headers || {};
opts.headers["Cookie"] = "platform_session=" + session;
opts.credentials = "include";
return fetch(API_BASE + path, opts).then(function(resp) {
if (resp.status === 401 || resp.status === 403) {
browser.storage.local.remove("brainSession");
throw new Error("Session expired");
}
if (!resp.ok) throw new Error("API error: " + resp.status);
return resp.json();
});
});
}
// ── Save functions ──
function saveLink(url, title, note) {
var body = { type: "link", url: url };
if (title) body.title = title;
if (note && note.trim()) body.raw_content = note.trim();
return apiRequest("/api/brain/items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
}
function saveNote(text) {
return apiRequest("/api/brain/items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ type: "note", raw_content: text }),
});
}
function saveImage(imageUrl) {
return fetch(imageUrl).then(function(resp) {
if (!resp.ok) throw new Error("Failed to download image");
return resp.blob();
}).then(function(blob) {
var parts = imageUrl.split("/");
var filename = (parts[parts.length - 1] || "image.jpg").split("?")[0];
var formData = new FormData();
formData.append("file", blob, filename);
return getSession().then(function(session) {
if (!session) throw new Error("Not logged in");
return fetch(API_BASE + "/api/brain/items/upload", {
method: "POST",
headers: { "Cookie": "platform_session=" + session },
credentials: "include",
body: formData,
});
});
}).then(function(resp) {
if (!resp.ok) throw new Error("Upload failed: " + resp.status);
return resp.json();
});
}
// ── Badge helpers ──
function showBadge(tabId, text, color, duration) {
browser.action.setBadgeText({ text: text, tabId: tabId });
browser.action.setBadgeBackgroundColor({ color: color, tabId: tabId });
setTimeout(function() {
browser.action.setBadgeText({ text: "", tabId: tabId });
}, duration || 2000);
}
// ── Context menus ──
browser.runtime.onInstalled.addListener(function() {
console.log("[Brain] Creating context menus");
browser.contextMenus.create({
id: "save-page",
title: "Save page to Brain",
contexts: ["page"],
});
browser.contextMenus.create({
id: "save-link",
title: "Save link to Brain",
contexts: ["link"],
});
browser.contextMenus.create({
id: "save-image",
title: "Save image to Brain",
contexts: ["image"],
});
});
browser.contextMenus.onClicked.addListener(function(info, tab) {
getSession().then(function(session) {
if (!session) {
browser.action.openPopup();
return;
}
var promise;
if (info.menuItemId === "save-page") {
promise = saveLink(tab.url, tab.title);
} else if (info.menuItemId === "save-link") {
promise = saveLink(info.linkUrl, info.linkText);
} else if (info.menuItemId === "save-image") {
promise = saveImage(info.srcUrl);
}
if (promise) {
promise.then(function() {
showBadge(tab.id, "OK", "#059669", 2000);
}).catch(function(e) {
showBadge(tab.id, "ERR", "#DC2626", 3000);
console.error("[Brain] Save failed:", e);
});
}
});
});
// ── Keyboard shortcut ──
browser.commands.onCommand.addListener(function(command) {
if (command === "save-page") {
browser.tabs.query({ active: true, currentWindow: true }).then(function(tabs) {
var tab = tabs[0];
if (!tab || !tab.url) return;
getSession().then(function(session) {
if (!session) {
browser.action.openPopup();
return;
}
saveLink(tab.url, tab.title).then(function() {
showBadge(tab.id, "OK", "#059669", 2000);
}).catch(function(e) {
showBadge(tab.id, "ERR", "#DC2626", 3000);
});
});
});
}
});
// ── Message handler (from popup) ──
browser.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
console.log("[Brain] Got message:", msg.action);
if (msg.action === "login") {
fetch(API_BASE + "/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
username: msg.username,
password: msg.password,
}),
credentials: "include",
}).then(function(resp) {
if (!resp.ok) {
sendResponse({ success: false, error: "Invalid credentials" });
return;
}
// Wait for cookie to be set
return new Promise(function(r) { setTimeout(r, 300); }).then(function() {
return browser.cookies.get({
url: API_BASE,
name: "platform_session",
});
}).then(function(cookie) {
if (cookie && cookie.value) {
return browser.storage.local.set({ brainSession: cookie.value }).then(function() {
sendResponse({ success: true });
});
}
sendResponse({ success: false, error: "Login OK but could not capture session" });
});
}).catch(function(e) {
console.error("[Brain] Login error:", e);
sendResponse({ success: false, error: e.message || "Connection failed" });
});
return true;
}
if (msg.action === "logout") {
browser.storage.local.remove("brainSession").then(function() {
sendResponse({ success: true });
});
return true;
}
if (msg.action === "check-auth") {
getSession().then(function(session) {
if (!session) {
sendResponse({ authenticated: false });
return;
}
return apiRequest("/api/auth/me").then(function(data) {
sendResponse({ authenticated: true, user: data.user || data });
}).catch(function() {
sendResponse({ authenticated: false });
});
});
return true;
}
if (msg.action === "save-link") {
saveLink(msg.url, msg.title, msg.note).then(function(result) {
sendResponse(result);
}).catch(function(e) {
sendResponse({ error: e.message });
});
return true;
}
if (msg.action === "save-note") {
saveNote(msg.text).then(function(result) {
sendResponse(result);
}).catch(function(e) {
sendResponse({ error: e.message });
});
return true;
}
if (msg.action === "save-image") {
saveImage(msg.url).then(function(result) {
sendResponse(result);
}).catch(function(e) {
sendResponse({ error: e.message });
});
return true;
}
});

Binary file not shown.

View File

@@ -0,0 +1,49 @@
{
"manifest_version": 3,
"name": "Brain - Save to Second Brain",
"version": "1.0.0",
"description": "One-click save pages, notes, and images to your Second Brain",
"permissions": [
"activeTab",
"contextMenus",
"storage",
"cookies"
],
"host_permissions": [
"https://dash.quadjourney.com/*"
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/brain-16.png",
"32": "icons/brain-32.png",
"48": "icons/brain-48.png"
}
},
"background": {
"scripts": ["background.js"]
},
"commands": {
"save-page": {
"suggested_key": {
"default": "Alt+Shift+S"
},
"description": "Save current page to Brain"
}
},
"icons": {
"16": "icons/brain-16.png",
"32": "icons/brain-32.png",
"48": "icons/brain-48.png",
"128": "icons/brain-128.png"
},
"browser_specific_settings": {
"gecko": {
"id": "brain@quadjourney.com",
"data_collection_permissions": {
"required": ["none"],
"optional": []
}
}
}
}

View File

@@ -0,0 +1,259 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
width: 340px;
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background: #f5efe6;
color: #1e1812;
font-size: 14px;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px;
border-bottom: 1px solid rgba(35,26,17,0.1);
}
.header-left {
display: flex;
align-items: center;
gap: 10px;
}
.header-mark {
width: 28px; height: 28px;
border-radius: 8px;
background: linear-gradient(135deg, #211912, #5d4c3f);
color: white;
display: grid; place-items: center;
font-size: 12px; font-weight: 700;
}
.header-title {
font-size: 14px;
font-weight: 600;
letter-spacing: -0.02em;
}
.header-user {
font-size: 11px;
color: #8c7b69;
}
.logout-btn {
background: none; border: none;
color: #8c7b69; font-size: 11px;
cursor: pointer; text-decoration: underline;
}
/* ── Login ── */
.login-view { padding: 24px 16px; }
.login-title {
font-size: 16px; font-weight: 600;
margin-bottom: 4px;
}
.login-sub {
font-size: 12px; color: #8c7b69;
margin-bottom: 16px;
}
.field { margin-bottom: 12px; }
.field label {
display: block; font-size: 11px; font-weight: 600;
text-transform: uppercase; letter-spacing: 0.06em;
color: #6b6256; margin-bottom: 4px;
}
.field input {
width: 100%; padding: 10px 12px;
border: 1px solid rgba(35,26,17,0.15);
border-radius: 10px; font-size: 14px;
background: rgba(255,255,255,0.7);
color: #1e1812; outline: none;
font-family: inherit;
}
.field input:focus {
border-color: rgba(35,26,17,0.35);
}
.login-btn, .save-btn {
width: 100%; padding: 12px;
border: none; border-radius: 12px;
background: linear-gradient(135deg, #211912, #5d4c3f);
color: white; font-size: 14px; font-weight: 600;
cursor: pointer; font-family: inherit;
transition: opacity 150ms;
}
.login-btn:hover, .save-btn:hover { opacity: 0.9; }
.login-btn:disabled, .save-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error {
color: #8f3928; font-size: 12px;
margin-bottom: 10px;
}
/* ── Save view ── */
.save-view { padding: 12px 16px 16px; }
.mode-tabs {
display: flex; gap: 4px;
margin-bottom: 12px;
}
.mode-tab {
flex: 1; padding: 8px;
border: 1px solid rgba(35,26,17,0.12);
border-radius: 10px;
background: rgba(255,255,255,0.4);
color: #6b6256; font-size: 12px; font-weight: 600;
cursor: pointer; text-align: center;
font-family: inherit;
transition: all 150ms;
}
.mode-tab.active {
background: rgba(255,255,255,0.9);
color: #1e1812;
border-color: rgba(35,26,17,0.25);
}
.url-preview {
padding: 10px 12px;
border-radius: 10px;
background: rgba(255,255,255,0.6);
border: 1px solid rgba(35,26,17,0.08);
margin-bottom: 10px;
}
.url-title {
font-size: 13px; font-weight: 600;
white-space: nowrap; overflow: hidden;
text-overflow: ellipsis;
}
.url-domain {
font-size: 11px; color: #8c7b69;
white-space: nowrap; overflow: hidden;
text-overflow: ellipsis;
}
.note-toggle {
background: none; border: none;
color: #8c7b69; font-size: 12px;
cursor: pointer; padding: 0;
margin-bottom: 8px;
font-family: inherit;
}
.note-toggle:hover { color: #1e1812; }
.note-area {
width: 100%; min-height: 80px;
padding: 10px 12px;
border: 1px solid rgba(35,26,17,0.15);
border-radius: 10px; font-size: 13px;
background: rgba(255,255,255,0.7);
color: #1e1812; outline: none;
font-family: inherit; resize: vertical;
margin-bottom: 10px;
}
.note-area:focus {
border-color: rgba(35,26,17,0.35);
}
/* ── Success state ── */
.success-view {
padding: 32px 16px;
text-align: center;
}
.success-check {
width: 48px; height: 48px;
border-radius: 50%;
background: #059669;
display: inline-flex; align-items: center; justify-content: center;
margin-bottom: 12px;
}
.success-check svg { color: white; }
.success-text {
font-size: 16px; font-weight: 600;
}
.success-sub {
font-size: 12px; color: #8c7b69;
margin-top: 4px;
}
/* ── Error ── */
.error-msg {
padding: 8px 12px;
border-radius: 8px;
background: rgba(143,57,40,0.08);
color: #8f3928;
font-size: 12px;
margin-bottom: 10px;
}
.hidden { display: none; }
</style>
</head>
<body>
<!-- Login View -->
<div id="login-view" class="login-view hidden">
<div class="login-title">Sign in to Brain</div>
<div class="login-sub">Use your Platform credentials</div>
<div id="login-error" class="login-error hidden"></div>
<div class="field">
<label>Username</label>
<input id="login-user" type="text" placeholder="admin" autocomplete="username">
</div>
<div class="field">
<label>Password</label>
<input id="login-pass" type="password" placeholder="" autocomplete="current-password">
</div>
<button id="login-btn" class="login-btn">Sign in</button>
</div>
<!-- Save View -->
<div id="save-view" class="hidden">
<div class="header">
<div class="header-left">
<div class="header-mark">B</div>
<div>
<div class="header-title">Brain</div>
<div class="header-user" id="user-name"></div>
</div>
</div>
<button class="logout-btn" id="logout-btn">Logout</button>
</div>
<div class="save-view">
<div class="mode-tabs">
<button class="mode-tab active" id="tab-link" data-mode="link">Save page</button>
<button class="mode-tab" id="tab-note" data-mode="note">Quick note</button>
</div>
<!-- Link mode -->
<div id="link-mode">
<div class="url-preview">
<div class="url-title" id="page-title"></div>
<div class="url-domain" id="page-url"></div>
</div>
<button class="note-toggle" id="note-toggle-btn">+ Add a note</button>
<textarea id="link-note" class="note-area hidden" placeholder="Optional note about this page..."></textarea>
<button id="save-link-btn" class="save-btn">Save page</button>
</div>
<!-- Note mode -->
<div id="note-mode" class="hidden">
<textarea id="note-text" class="note-area" placeholder="Write a note..." style="min-height:120px;"></textarea>
<button id="save-note-btn" class="save-btn">Save note</button>
</div>
<div id="save-error" class="error-msg hidden"></div>
</div>
</div>
<!-- Success View -->
<div id="success-view" class="success-view hidden">
<div class="success-check">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round"><path d="M20 6L9 17l-5-5"/></svg>
</div>
<div class="success-text">Saved!</div>
<div class="success-sub">AI is classifying in the background</div>
</div>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -0,0 +1,202 @@
const loginView = document.getElementById("login-view");
const saveView = document.getElementById("save-view");
const successView = document.getElementById("success-view");
const loginBtn = document.getElementById("login-btn");
const loginUser = document.getElementById("login-user");
const loginPass = document.getElementById("login-pass");
const loginError = document.getElementById("login-error");
const logoutBtn = document.getElementById("logout-btn");
const userName = document.getElementById("user-name");
const tabLink = document.getElementById("tab-link");
const tabNote = document.getElementById("tab-note");
const linkMode = document.getElementById("link-mode");
const noteMode = document.getElementById("note-mode");
const pageTitle = document.getElementById("page-title");
const pageUrl = document.getElementById("page-url");
const noteToggleBtn = document.getElementById("note-toggle-btn");
const linkNote = document.getElementById("link-note");
const saveLinkBtn = document.getElementById("save-link-btn");
const noteText = document.getElementById("note-text");
const saveNoteBtn = document.getElementById("save-note-btn");
const saveError = document.getElementById("save-error");
let currentTab = null;
// ── View management ──
function showView(view) {
loginView.classList.add("hidden");
saveView.classList.add("hidden");
successView.classList.add("hidden");
view.classList.remove("hidden");
}
function showError(el, msg) {
el.textContent = msg;
el.classList.remove("hidden");
}
function hideError(el) {
el.classList.add("hidden");
}
// ── Init ──
async function init() {
const resp = await browser.runtime.sendMessage({ action: "check-auth" });
if (resp.authenticated) {
userName.textContent = resp.user?.display_name || resp.user?.username || "";
showView(saveView);
await loadCurrentTab();
} else {
showView(loginView);
loginUser.focus();
}
}
async function loadCurrentTab() {
const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
if (tab) {
currentTab = tab;
pageTitle.textContent = tab.title || "Untitled";
try {
pageUrl.textContent = new URL(tab.url).hostname;
} catch {
pageUrl.textContent = tab.url;
}
}
}
// ── Login ──
loginBtn.addEventListener("click", async () => {
const user = loginUser.value.trim();
const pass = loginPass.value;
if (!user || !pass) return;
loginBtn.disabled = true;
loginBtn.textContent = "Signing in...";
hideError(loginError);
try {
const resp = await browser.runtime.sendMessage({
action: "login",
username: user,
password: pass,
});
if (resp && resp.success) {
const auth = await browser.runtime.sendMessage({ action: "check-auth" });
userName.textContent = auth.user?.display_name || auth.user?.username || "";
showView(saveView);
await loadCurrentTab();
} else {
showError(loginError, (resp && resp.error) || "Login failed");
}
} catch (e) {
showError(loginError, "Error: " + (e.message || e));
}
loginBtn.disabled = false;
loginBtn.textContent = "Sign in";
});
loginPass.addEventListener("keydown", (e) => {
if (e.key === "Enter") loginBtn.click();
});
// ── Logout ──
logoutBtn.addEventListener("click", async () => {
await browser.runtime.sendMessage({ action: "logout" });
showView(loginView);
loginUser.value = "";
loginPass.value = "";
});
// ── Mode tabs ──
tabLink.addEventListener("click", () => {
tabLink.classList.add("active");
tabNote.classList.remove("active");
linkMode.classList.remove("hidden");
noteMode.classList.add("hidden");
hideError(saveError);
});
tabNote.addEventListener("click", () => {
tabNote.classList.add("active");
tabLink.classList.remove("active");
noteMode.classList.remove("hidden");
linkMode.classList.add("hidden");
hideError(saveError);
noteText.focus();
});
// ── Note toggle on link mode ──
noteToggleBtn.addEventListener("click", () => {
linkNote.classList.toggle("hidden");
if (!linkNote.classList.contains("hidden")) {
noteToggleBtn.textContent = "- Hide note";
linkNote.focus();
} else {
noteToggleBtn.textContent = "+ Add a note";
}
});
// ── Save link ──
saveLinkBtn.addEventListener("click", async () => {
if (!currentTab?.url) return;
saveLinkBtn.disabled = true;
saveLinkBtn.textContent = "Saving...";
hideError(saveError);
try {
await browser.runtime.sendMessage({
action: "save-link",
url: currentTab.url,
title: currentTab.title,
note: linkNote.value.trim() || undefined,
});
showView(successView);
setTimeout(() => window.close(), 1500);
} catch (e) {
showError(saveError, e.message || "Save failed");
saveLinkBtn.disabled = false;
saveLinkBtn.textContent = "Save page";
}
});
// ── Save note ──
saveNoteBtn.addEventListener("click", async () => {
const text = noteText.value.trim();
if (!text) return;
saveNoteBtn.disabled = true;
saveNoteBtn.textContent = "Saving...";
hideError(saveError);
try {
await browser.runtime.sendMessage({ action: "save-note", text });
showView(successView);
setTimeout(() => window.close(), 1500);
} catch (e) {
showError(saveError, e.message || "Save failed");
saveNoteBtn.disabled = false;
saveNoteBtn.textContent = "Save note";
}
});
// ── Start ──
init().catch((e) => {
console.error("[Brain popup] Init failed:", e);
// Show login view as fallback
showView(loginView);
loginUser.focus();
});

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body style="width:300px;padding:20px;font-family:sans-serif;">
<h2>Brain Extension</h2>
<p>If you see this, the popup works.</p>
</body>
</html>