diff --git a/site/index.html b/site/index.html index b522b07..c2b7c82 100644 --- a/site/index.html +++ b/site/index.html @@ -27,6 +27,7 @@ Dopamine menu One thing Brain dump + Done-Wall + + +
@@ -278,6 +291,24 @@ + +
@@ -352,6 +383,8 @@ + + diff --git a/site/static/app.js b/site/static/app.js index f600668..3954209 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -475,6 +475,46 @@ timerPersist(); timerPaint(); } + /* ---------- AI Auto-Deconstruct Contract (Tier 1 & 2) ---------- */ + window.aiBreakdownTask = async function(taskText) { + // Shared Interface for Sibyl's Tier 3 + const prompt = `Break down this intimidating task into 3-5 tiny, actionable micro-steps: "${taskText}". Return only the list of steps.`; + + // Tier 1: Browser Native (window.ai) + if (window.ai && window.ai.languageModel) { + try { + const caps = await window.ai.languageModel.capabilities(); + if (caps.available !== 'no') { + const session = await window.ai.languageModel.create(); + const result = await session.prompt(prompt); + return result.split('\n').filter(s => s.trim().length > 0); + } + } catch (e) { + console.warn("window.ai failed, falling back", e); + } + } + + // Tier 2: BYOK (Bring Your Own Key) Fallback + const key = store('byok_key'); + if (!key) { + throw new Error("NO_AI_AVAILABLE"); // Let UI prompt for key or let Tier 3 try + } + const resp = await fetch('https://api.openai.com/v1/chat/completions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + key + }, + body: JSON.stringify({ + model: 'gpt-4o-mini', + messages: [{ role: 'user', content: prompt }] + }) + }); + if (!resp.ok) throw new Error("API_ERROR"); + const data = await resp.json(); + return data.choices[0].message.content.split('\n').filter(s => s.trim().length > 0); + }; + $('#timer-reset').addEventListener('click', timerReset); $$('.preset').forEach(function (p) { @@ -509,6 +549,7 @@ $('#timer-complete').hidden = true; // Mark the current one-thing step as done in the breaker var nowData = store('now'); + var taskText = $('#now-text').textContent || (nowData && nowData.text) || ''; if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') { var b = store(breakerKey); if (b && b.steps[nowData.stepIndex]) { @@ -517,6 +558,7 @@ breakerRender(); } } + handleNewDoneTasks(taskText); // Reset timer so it's fresh for the next step timerReset(); // Clear one-thing and show next step prompt @@ -719,8 +761,15 @@ $('#now-input').focus(); }); + function handleNewDoneTasks(taskString) { + if (window.dbRecordTask && taskString) { + window.dbRecordTask(taskString).then(() => { if (window.renderDoneWall) window.renderDoneWall(); }).catch(() => {}); + } + } + $('#now-done').addEventListener('click', function () { var nowData = store('now'); + var taskText = $('#now-text').textContent || (nowData && nowData.text) || ''; tickSound(); // If from breaker, mark that step done if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') { @@ -731,6 +780,7 @@ breakerRender(); } } + handleNewDoneTasks(taskText); localStorage.removeItem('myadhd.now'); // Check if there's a next step from breaker var b2 = store(breakerKey); @@ -998,6 +1048,32 @@ /* ---------- keyboard shortcuts ---------- */ document.addEventListener('keydown', function (e) { + // Quick Capture (Alt+P) - active globally + if (e.altKey && (e.key === 'p' || e.key === 'P')) { + e.preventDefault(); + var overlay = document.getElementById('quick-capture-overlay'); + if (overlay.hidden) { + overlay.hidden = false; + document.getElementById('quick-capture-input').value = ''; + document.getElementById('quick-capture-input').focus(); + } else { + overlay.hidden = true; + } + return; + } + // Quick capture handling inside input + if (e.target.id === 'quick-capture-input') { + if (e.key === 'Escape') { + document.getElementById('quick-capture-overlay').hidden = true; + } else if (e.key === 'Enter' && e.target.value.trim() !== '') { + var unTasks = store('unsorted_tasks') || []; + unTasks.push({ text: e.target.value.trim(), created: Date.now() }); + store('unsorted_tasks', unTasks); + if (typeof unPaint === 'function') unPaint(); + document.getElementById('quick-capture-overlay').hidden = true; + e.target.value = ''; + } + } // Don't trigger shortcuts when typing in an input or contenteditable var tag = e.target.tagName; if (tag === 'INPUT' || tag === 'TEXTAREA' || e.target.contentEditable === 'true') return; diff --git a/site/static/audio.js b/site/static/audio.js index fd26e24..3a24983 100644 --- a/site/static/audio.js +++ b/site/static/audio.js @@ -7,21 +7,26 @@ let noiseNode; let gainNode; let currentNoiseType = 'off'; -/** - * Procedural noise generation (Brownian, Pink) - */ function createNoiseBuffer(type) { - const bufferSize = audioCtx.sampleRate * 2; // 2 seconds of noise + const bufferSize = audioCtx.sampleRate * 2; const buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate); const output = buffer.getChannelData(0); - if (type === 'brown') { + if (type === 'rain') { + let lastOut = 0; + for (let i = 0; i < bufferSize; i++) { + let white = Math.random() * 2 - 1; + output[i] = (lastOut + (0.05 * white)) / 1.05; + lastOut = output[i]; + output[i] *= 2.0; + } + } else if (type === 'brown') { let lastOut = 0; for (let i = 0; i < bufferSize; i++) { let white = Math.random() * 2 - 1; output[i] = (lastOut + (0.02 * white)) / 1.02; lastOut = output[i]; - output[i] *= 3.5; // Compensate for gain + output[i] *= 3.5; } } else if (type === 'pink') { let b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0; @@ -34,7 +39,7 @@ function createNoiseBuffer(type) { b4 = 0.55000 * b4 + white * 0.5329522; b5 = -0.7616 * b5 - white * 0.0168980; output[i] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362; - output[i] *= 0.11; // Compensate for gain + output[i] *= 0.11; b6 = white * 0.115926; } } @@ -69,6 +74,40 @@ function playNoise(type) { if (type === 'off') return; + if (type === 'gamma') { + // 40Hz Gamma true binaural setup + const oscLeft = audioCtx.createOscillator(); + const oscRight = audioCtx.createOscillator(); + const pannerLeft = audioCtx.createStereoPanner(); + const pannerRight = audioCtx.createStereoPanner(); + + oscLeft.frequency.value = 200; // Base carrier frequency + oscRight.frequency.value = 240; // 40Hz beat frequency difference + + pannerLeft.pan.value = -1; // Hard left + pannerRight.pan.value = 1; // Hard right + + oscLeft.connect(pannerLeft); + oscRight.connect(pannerRight); + + pannerLeft.connect(gainNode); + pannerRight.connect(gainNode); + + oscLeft.start(); + oscRight.start(); + + noiseNode = { + stop: () => { + oscLeft.stop(); oscRight.stop(); + }, + disconnect: () => { + oscLeft.disconnect(); oscRight.disconnect(); + pannerLeft.disconnect(); pannerRight.disconnect(); + } + }; + return; + } + noiseNode = audioCtx.createBufferSource(); noiseNode.buffer = createNoiseBuffer(type); noiseNode.loop = true; @@ -83,11 +122,9 @@ function setupAudioUI() { soundBtns.forEach(btn => { btn.addEventListener('click', () => { - // Update UI soundBtns.forEach(b => b.classList.remove('active')); btn.classList.add('active'); - // Update audio const soundType = btn.dataset.sound; currentNoiseType = soundType; playNoise(soundType); @@ -97,7 +134,6 @@ function setupAudioUI() { if (volControl) { volControl.addEventListener('input', (e) => { if (gainNode) { - // Logarithmic volume scaling for smoother feel const val = Number(e.target.value); gainNode.gain.setTargetAtTime(val * val, audioCtx.currentTime, 0.05); } @@ -105,18 +141,16 @@ function setupAudioUI() { } } -// Wire it up on app load document.addEventListener('DOMContentLoaded', () => { setupAudioUI(); }); - window.playGroundingPing = function() { if (!audioCtx) initAudio(); var osc = audioCtx.createOscillator(); var gain = audioCtx.createGain(); osc.type = 'sine'; - osc.frequency.setValueAtTime(528, audioCtx.currentTime); // 528hz droplet + osc.frequency.setValueAtTime(528, audioCtx.currentTime); gain.gain.setValueAtTime(0, audioCtx.currentTime); gain.gain.linearRampToValueAtTime(0.3, audioCtx.currentTime + 0.1); gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + 1.5); diff --git a/site/static/done.js b/site/static/done.js new file mode 100644 index 0000000..32e57a0 --- /dev/null +++ b/site/static/done.js @@ -0,0 +1,90 @@ +window.renderDoneWall = function() { + if (!window.dbGetAllTasks) return; + window.dbGetAllTasks().then(tasks => { + var list = document.querySelector('#done-list'); + var empty = document.querySelector('#done-empty'); + if (!list || !empty) return; + + if (tasks.length === 0) { + list.innerHTML = ''; + empty.hidden = false; + return; + } + empty.hidden = true; + list.innerHTML = ''; + + // Group by Date string (local date) + const groups = {}; + const todayStr = new Date().toDateString(); + + tasks.forEach(t => { + let d = new Date(t.completedAt); + let dStr = d.toDateString(); + if (dStr === todayStr) dStr = "Today"; + else if (dStr === new Date(Date.now() - 86400000).toDateString()) dStr = "Yesterday"; + else dStr = d.toLocaleDateString(undefined, { weekday: 'long', month: 'short', day: 'numeric' }); + + if (!groups[dStr]) groups[dStr] = []; + groups[dStr].push(t); + }); + + Object.keys(groups).forEach(dateLabel => { + let head = document.createElement('h3'); + head.textContent = dateLabel; + head.style.marginTop = '1.5rem'; + head.style.marginBottom = '0.5rem'; + head.style.color = 'var(--text-muted)'; + list.appendChild(head); + + groups[dateLabel].forEach(task => { + let li = document.createElement('li'); + li.style.padding = '0.5rem 0'; + li.style.borderBottom = '1px solid var(--border)'; + + let row = document.createElement('div'); + row.style.display = 'flex'; + row.style.justifyContent = 'space-between'; + + let textSpan = document.createElement('span'); + textSpan.textContent = "✓ " + task.text; + textSpan.style.color = 'var(--primary)'; + + // Time + let timeSpan = document.createElement('span'); + let d = new Date(task.completedAt); + timeSpan.textContent = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + timeSpan.style.color = 'var(--text-muted)'; + timeSpan.style.fontSize = '0.85em'; + + row.appendChild(textSpan); + row.appendChild(timeSpan); + li.appendChild(row); + list.appendChild(li); + }); + }); + }).catch(e => console.error(e)); +}; + +document.addEventListener('DOMContentLoaded', () => { + var clearBtn = document.querySelector('#done-clear'); + if (clearBtn) { + clearBtn.addEventListener('click', () => { + if (window.confirm("Are you sure you want to clear your entire accomplishment history?")) { + if (window.dbClearTasks) { + window.dbClearTasks().then(() => { + if (window.renderDoneWall) window.renderDoneWall(); + }); + } + } + }); + } + + // Bind to tab switch + document.querySelectorAll('.tab').forEach(tab => { + tab.addEventListener('click', e => { + if (tab.dataset.tab === 'done') { + if (window.renderDoneWall) window.renderDoneWall(); + } + }); + }); +}); diff --git a/site/static/store.js b/site/static/store.js new file mode 100644 index 0000000..24de0ba --- /dev/null +++ b/site/static/store.js @@ -0,0 +1,65 @@ +const DB_NAME = 'MyADHDSyncDB'; +const DB_VERSION = 1; +const DONE_STORE_NAME = 'done_cache'; + +let db = null; + +function getStoreDB() { + return new Promise((resolve, reject) => { + if (db) return resolve(db); + const request = indexedDB.open(DB_NAME, DB_VERSION); + request.onupgradeneeded = (event) => { + const adb = event.target.result; + if (!adb.objectStoreNames.contains(DONE_STORE_NAME)) { + adb.createObjectStore(DONE_STORE_NAME, { keyPath: 'id', autoIncrement: true }); + } + }; + request.onsuccess = (event) => { + db = event.target.result; + resolve(db); + }; + request.onerror = (event) => reject(event.target.error); + }); +} + +window.dbRecordTask = function(text) { + return getStoreDB().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction(DONE_STORE_NAME, 'readwrite'); + const store = tx.objectStore(DONE_STORE_NAME); + const req = store.add({ + text: text, + completedAt: new Date().toISOString() + }); + req.onsuccess = () => resolve(); + req.onerror = () => reject(req.error); + }); + }); +}; + +window.dbGetAllTasks = function() { + return getStoreDB().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction(DONE_STORE_NAME, 'readonly'); + const store = tx.objectStore(DONE_STORE_NAME); + const req = store.getAll(); + req.onsuccess = () => { + const sorted = (req.result || []).sort((a,b) => new Date(b.completedAt) - new Date(a.completedAt)); + resolve(sorted); + }; + req.onerror = () => reject(req.error); + }); + }); +}; + +window.dbClearTasks = function() { + return getStoreDB().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction(DONE_STORE_NAME, 'readwrite'); + const store = tx.objectStore(DONE_STORE_NAME); + const req = store.clear(); + req.onsuccess = () => resolve(); + req.onerror = () => reject(req.error); + }); + }); +};