Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>CAUSE — prototype</title><script type="module" src="shared/atproto-wc.js"></script><style> :root { color-scheme: light dark; --accent: #2f6f5e; --accent-fill: #2f6f5e; --bg: #ffffff; --fg: #1a1a1a; --muted: #6b7280; --border: #e5e7eb; --label-bg: #eff6f3; --label-fg: #2f6f5e; } @media (prefers-color-scheme: dark) { :root { --accent: #4e9d85; --accent-fill: #2a6353; --bg: #17181c; --fg: #e8e8e8; --muted: #9aa0a6; --border: #2c2d33; --label-bg: #1f2a26; --label-fg: #4e9d85; } } * { box-sizing: border-box; } body { margin: 0; font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; background: var(--bg); color: var(--fg); } .wrap { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; } header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; } header h1 { font-size: 20px; margin: 0; font-weight: 650; } header .tag { color: var(--muted); font-size: 12px; border: 1px solid var(--border); padding: 2px 8px; border-radius: 999px; } #loginbar { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 10px; } #loginbar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--t-danger, #b91c1c); display: inline-block; } #loginbar.logged .dot { background: var(--accent); } #loginbar button { font: inherit; font-size: 12.5px; color: var(--accent); background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; } #loginbar button:hover { border-color: var(--accent); }
.layout { display: grid; gap: 24px; grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
.panel { border: 1px solid var(--border); border-radius: 12px; padding: 16px; background: var(--bg); } .panel h2 { font-size: 13px; margin: 0 0 4px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; } .panel .hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; } input[type=text], textarea { width: 100%; font: inherit; font-size: 14px; background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; } textarea { min-height: 72px; resize: vertical; } input[type=text]:focus, textarea:focus { outline: none; border-color: var(--accent); }
.addrow { display: flex; gap: 8px; margin-top: 10px; } .addrow button { font: inherit; font-size: 13px; flex: none; background: none; color: var(--accent); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; } .addrow button:hover { border-color: var(--accent); }
.items { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; } .item { display: flex; align-items: baseline; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13.5px; } .item .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--fg); } .item .src { color: var(--muted); font-size: 11px; flex: none; } .item .del { flex: none; background: none; border: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; } .item .del:hover { color: var(--t-danger, #b91c1c); } .kw .txt { font-weight: 600; }
#notesbox { margin-top: 16px; } #runrow { margin-top: 16px; display: flex; align-items: center; gap: 12px; } #play { font: inherit; font-weight: 650; font-size: 15px; background: var(--accent-fill); color: #fff; border: none; border-radius: 8px; padding: 10px 22px; cursor: pointer; } #play:disabled { opacity: .55; cursor: default; } #status { font-size: 13px; color: var(--muted); min-height: 1.2em; } #status.err { color: var(--t-danger, #b91c1c); }
#results { display: flex; flex-direction: column; gap: 14px; } .post { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; } .who { display: flex; align-items: baseline; gap: 8px; } .who .handle { font-weight: 650; font-size: 13.5px; } .who .time { color: var(--muted); font-size: 12px; } .why { margin: 8px 0 10px; font-size: 12.5px; } .why .reason { display: block; background: var(--label-bg); color: var(--label-fg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; } .why .reason b { font-weight: 650; } .why .notes { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; } .why .notes span { font-size: 11.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; } .post atproto-post { display: block; width: 100%; } .empty { color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; padding: 28px; text-align: center; } #loginprompt { margin-bottom: 14px; display: none; } #loginprompt form { display: flex; gap: 8px; } #loginprompt input { flex: 1; } #loginprompt button { font: inherit; color: #fff; background: var(--accent-fill); border: none; border-radius: 6px; padding: 8px 14px; cursor: pointer; flex: none; }</style></head><body><div class="wrap"> <header> <h1>CAUSE</h1> <span class="tag">prototype</span> <div id="loginbar"> <span class="dot"></span> <span id="logintext">checking…</span> </div> </header>
<div id="loginprompt" class="panel"> <h2>Log in to search Bluesky</h2> <p class="hint">Keyword search is made as a real account. Enter your Bluesky handle to authorise on this machine.</p> <form id="loginform"> <input id="handle" type="text" placeholder="you.bsky.social" autocomplete="username"> <button type="submit">Log in</button> </form> </div>
<div class="layout"> <div> <div class="panel"> <h2>Keywords</h2> <p class="hint">Broad recall terms. Each is an item — one day its own atproto record, from its own author.</p> <input id="kwinput" type="text" placeholder="repair cafe" autocomplete="off"> <div class="addrow"><button id="kwadd">add keyword</button></div> <div id="kwitems" class="items"></div> </div> <div class="panel" id="notesbox"> <h2>Prompt notes</h2> <p class="hint">The cause's judgment — one line, one note. Only agents that see a surfaced post inspect these.</p> <textarea id="notesinput" placeholder="Stories about mending, repurposing, and the local, not about buying new."></textarea> <div class="addrow"><button id="noteadd">add note</button></div> <div id="noteitems" class="items"></div> <div id="runrow"> <button id="play">Play</button> <div id="status"></div> </div> </div> </div>
<div id="results" aria-live="polite"> <div class="empty">A cause surfaces; only a member endorses. Press Play to see what this one surfaces.</div> </div> </div></div>
<script>const $ = (id) => document.getElementById(id);const newId = () => crypto.randomUUID().slice(0, 12);
let kwItems = [];let noteItems = [];
function renderItems(container, items) { container.innerHTML = ''; if (!items.length) return; for (const it of items) { const d = document.createElement('div'); d.className = 'item'; const txt = document.createElement('span'); txt.className = 'txt'; txt.textContent = it.text; const who = document.createElement('span'); who.className = 'src'; who.textContent = 'you'; const del = document.createElement('button'); del.className = 'del'; del.textContent = '×'; del.title = 'remove'; del.addEventListener('click', () => { const list = container === $('kwitems') ? kwItems : noteItems; list.splice(list.indexOf(it), 1); renderItems(container, list); }); d.appendChild(txt); d.appendChild(who); d.appendChild(del); container.appendChild(d); }}
$('kwinput').addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); addKeyword(); }});$('kwadd').addEventListener('click', addKeyword);function addKeyword() { const t = $('kwinput').value.trim(); if (!t) return; kwItems.push({ id: newId(), text: t }); $('kwinput').value = ''; renderItems($('kwitems'), kwItems);}
$('noteadd').addEventListener('click', addNotes);function addNotes() { const raw = $('notesinput').value; const lines = raw.split('\n').map((s) => s.trim()).filter(Boolean); if (!lines.length) return; for (const line of lines) noteItems.push({ id: newId(), text: line }); $('notesinput').value = ''; renderItems($('noteitems'), noteItems);}
async function refreshState() { const r = await fetch('/state'); const s = await r.json(); const bar = $('loginbar'); $('loginprompt').style.display = s.logged_in ? 'none' : 'block'; if (s.logged_in) { bar.classList.add('logged'); $('logintext').textContent = 'logged in · ' + shortDid(s.did); } else { bar.classList.remove('logged'); $('logintext').textContent = s.note ? 'sidecar unreachable' : 'not logged in'; }}function shortDid(did) { return did ? did.slice(0, 12) + '…' : '—'; }
$('loginform').addEventListener('submit', (e) => { e.preventDefault(); const h = $('handle').value.trim(); if (h) location.href = '/oauth/login?handle=' + encodeURIComponent(h);});
function dbPostUrl(post) { const m = (post.uri || '').match(/at:\/\/did:[^/]+\/app\.bsky\.feed\.post\/([\w-]+)$/); return m ? 'https://bsky.app/profile/' + (post.did || post.handle) + '/post/' + m[1] : post.uri;}
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''}[c]));}
function postCard(p) { const time = (p.createdAt || '').replace('T', ' ').slice(0, 16) || '?'; const el = document.createElement('div'); el.className = 'post';
const who = document.createElement('div'); who.className = 'who'; who.innerHTML = '<span class="handle">@' + esc(p.handle) + '</span>' + '<span class="time">' + esc(time) + '</span>'; el.appendChild(who);
const why = document.createElement('div'); why.className = 'why'; why.innerHTML = '<span class="reason"><b>why this surfaced</b> — ' + esc(p.reason || '') + '</span>'; if (p.note_texts && p.note_texts.length) { const notes = document.createElement('div'); notes.className = 'notes'; for (const nt of p.note_texts) { const s = document.createElement('span'); s.textContent = nt; notes.appendChild(s); } why.appendChild(notes); } el.appendChild(why);
const post = document.createElement('atproto-post'); post.setAttribute('src', p.uri); post.setAttribute('compact', ''); el.appendChild(post);
const meta = document.createElement('div'); meta.className = 'meta'; meta.style.cssText = 'margin-top:8px;font-size:11.5px;color:var(--muted);'; const a = document.createElement('a'); a.href = dbPostUrl(p); a.target = '_blank'; a.rel = 'noopener'; a.textContent = 'open in Bluesky'; a.style.color = 'var(--accent)'; meta.appendChild(a); el.appendChild(meta);
return el;}
function status(msg, cls) { const el = $('status'); el.textContent = msg; el.className = cls || '';}
async function run() { const kw = kwItems.map((i) => i.text).join('\n'); const notes = noteItems.map((i) => i.text).join('\n'); if (!kw.trim() || !notes.trim()) { status('add keywords and at least one note first', 'err'); return; }
$('play').disabled = true; status('recall: searching Bluesky for the keywords…'); $('results').innerHTML = '<div class="empty">running…</div>';
try { const r = await fetch('/run', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ keywords: kw, notes }), }); const d = await r.json();
if (!d.ok) { if (d.error === 'login') { status('log in to search', 'err'); $('loginprompt').style.display = 'block'; $('results').innerHTML = '<div class="empty">Login required to search Bluesky.</div>'; } else { status(d.error || 'something went wrong', 'err'); $('results').innerHTML = '<div class="empty">' + esc(d.error || '') + '</div>'; } return; }
$('results').innerHTML = ''; if (!d.surfaced.length) { const empty = document.createElement('div'); empty.className = 'empty'; empty.textContent = d.candidates + ' candidates retrieved — none matched the prompt notes.'; $('results').appendChild(empty); } else { d.surfaced.forEach((p) => $('results').appendChild(postCard(p))); } status(d.surfaced.length + ' surfaced of ' + d.candidates + ' candidates'); } catch (e) { status('request failed: ' + e.message, 'err'); } finally { $('play').disabled = false; }}
$('play').addEventListener('click', run);renderItems($('kwitems'), kwItems);renderItems($('noteitems'), noteItems);refreshState();</script></body></html>