mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
Merge branches 'feat/sprint-5-timer-anchor', 'feat/sprint-5-quick-capture' and 'feat/sprint-6-webllm'
All checks were successful
Build and Deploy / deploy (push) Successful in 47s
All checks were successful
Build and Deploy / deploy (push) Successful in 47s
This commit is contained in:
commit
0dbbad450d
4 changed files with 290 additions and 1 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
<a href="#dopamine" data-tab="dopamine" class="tab" role="tab" id="tab-dopamine" aria-selected="false" aria-controls="dopamine">Dopamine menu</a>
|
<a href="#dopamine" data-tab="dopamine" class="tab" role="tab" id="tab-dopamine" aria-selected="false" aria-controls="dopamine">Dopamine menu</a>
|
||||||
<a href="#now" data-tab="now" class="tab" role="tab" id="tab-now" aria-selected="false" aria-controls="now">One thing</a>
|
<a href="#now" data-tab="now" class="tab" role="tab" id="tab-now" aria-selected="false" aria-controls="now">One thing</a>
|
||||||
<a href="#inbox" data-tab="inbox" class="tab" role="tab" id="tab-inbox" aria-selected="false" aria-controls="inbox">Brain dump</a>
|
<a href="#inbox" data-tab="inbox" class="tab" role="tab" id="tab-inbox" aria-selected="false" aria-controls="inbox">Brain dump</a>
|
||||||
|
<a href="#done" data-tab="done" class="tab" role="tab" id="tab-done" aria-selected="false" aria-controls="done">Done-Wall</a>
|
||||||
</nav>
|
</nav>
|
||||||
<div id="ambient-pill" class="ambient-pill" role="button" aria-expanded="false" tabindex="0">
|
<div id="ambient-pill" class="ambient-pill" role="button" aria-expanded="false" tabindex="0">
|
||||||
<span class="pill-dot">🟢</span>
|
<span class="pill-dot">🟢</span>
|
||||||
|
|
@ -40,6 +41,18 @@
|
||||||
</ul>
|
</ul>
|
||||||
<div id="ambient-cheer-btn" class="ambient-cheer" role="button" tabindex="0">Send a gentle nod 🎉</div>
|
<div id="ambient-cheer-btn" class="ambient-cheer" role="button" tabindex="0">Send a gentle nod 🎉</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Quick Capture Overlay -->
|
||||||
|
<div id="quick-capture-overlay" class="completion-overlay" hidden>
|
||||||
|
<div class="completion-card">
|
||||||
|
<h2>Brain Dump (Parking Lot)</h2>
|
||||||
|
<p style="margin-top:-5px; font-size:0.9rem; color:var(--dim);">Clear your mind. We'll save it to your unsorted list.</p>
|
||||||
|
<input type="text" id="quick-capture-input" placeholder="What's distracting you?" autocomplete="off" style="width:100%;font-size:1.2rem;padding:15px;background:var(--bg-hover);border:2px solid var(--border);color:var(--text);border-radius:8px;margin-bottom:10px;margin-top:15px;" />
|
||||||
|
<div style="text-align:right;">
|
||||||
|
<span class="tiny dim">Press Esc to cancel, Enter to save</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
@ -278,6 +291,24 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="done" class="tool" role="tabpanel" aria-labelledby="tab-done" hidden>
|
||||||
|
<div class="tool-head">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
|
||||||
|
<div>
|
||||||
|
<h1>Done-Wall</h1>
|
||||||
|
<p class="sub">Everything you've finished, stored securely in your browser cache.</p>
|
||||||
|
</div>
|
||||||
|
<button class="btn ghost" id="done-clear" style="margin-left: 1rem;">Clear History</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<ul id="done-list" class="done-items" role="list" style="list-style: none; padding: 0; margin: 0;"></ul>
|
||||||
|
<div id="done-empty" class="tiny" style="text-align: center; padding: 2rem 0; opacity: 0.7;">
|
||||||
|
No tasks recorded yet. Complete something in the 'One Thing' tab to see it here!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<!-- Celebration canvas (confetti) -->
|
<!-- Celebration canvas (confetti) -->
|
||||||
|
|
@ -352,6 +383,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="/static/store.js" defer></script>
|
||||||
|
<script src="/static/done.js" defer></script>
|
||||||
<script src="/static/app.js" defer></script>
|
<script src="/static/app.js" defer></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,71 @@
|
||||||
timerPersist(); timerPaint();
|
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 3: WebLLM In-Browser (Advanced Opt-in)
|
||||||
|
// Checks if the user explicitly opted in to download the model
|
||||||
|
if (localStorage.getItem('ai_webllm_enabled') === 'true') {
|
||||||
|
try {
|
||||||
|
if (!window.webLLMEngine) {
|
||||||
|
// Initialize engine using the MLC WebLLM CDN
|
||||||
|
const { CreateMLCEngine } = await import('https://cdn.jsdelivr.net/npm/@mlc-ai/web-llm@0.2.46/+esm');
|
||||||
|
// Use a 1B parameter model as decided: Llama-3.2-1B-Instruct
|
||||||
|
window.webLLMEngine = await CreateMLCEngine('Llama-3.2-1B-Instruct-q4f16_1-MLC', {
|
||||||
|
initProgressCallback: (progress) => {
|
||||||
|
// Hook this up to a UI later to show MB downloaded
|
||||||
|
console.log(`Downloading WebLLM model: ${progress.text}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const reply = await window.webLLMEngine.chat.completions.create({
|
||||||
|
messages: [{ role: 'user', content: prompt }]
|
||||||
|
});
|
||||||
|
return reply.choices[0].message.content.split('\n').filter(s => s.trim().length > 0);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('WebLLM Context Loss/OOM. Graded fallback to BYOK:', e);
|
||||||
|
// Graded fallback automatically drops through to Tier 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
$('#timer-reset').addEventListener('click', timerReset);
|
||||||
|
|
||||||
$$('.preset').forEach(function (p) {
|
$$('.preset').forEach(function (p) {
|
||||||
|
|
@ -509,6 +574,7 @@
|
||||||
$('#timer-complete').hidden = true;
|
$('#timer-complete').hidden = true;
|
||||||
// Mark the current one-thing step as done in the breaker
|
// Mark the current one-thing step as done in the breaker
|
||||||
var nowData = store('now');
|
var nowData = store('now');
|
||||||
|
var taskText = $('#now-text').textContent || (nowData && nowData.text) || '';
|
||||||
if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') {
|
if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') {
|
||||||
var b = store(breakerKey);
|
var b = store(breakerKey);
|
||||||
if (b && b.steps[nowData.stepIndex]) {
|
if (b && b.steps[nowData.stepIndex]) {
|
||||||
|
|
@ -517,6 +583,7 @@
|
||||||
breakerRender();
|
breakerRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleNewDoneTasks(taskText);
|
||||||
// Reset timer so it's fresh for the next step
|
// Reset timer so it's fresh for the next step
|
||||||
timerReset();
|
timerReset();
|
||||||
// Clear one-thing and show next step prompt
|
// Clear one-thing and show next step prompt
|
||||||
|
|
@ -719,8 +786,15 @@
|
||||||
$('#now-input').focus();
|
$('#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 () {
|
$('#now-done').addEventListener('click', function () {
|
||||||
var nowData = store('now');
|
var nowData = store('now');
|
||||||
|
var taskText = $('#now-text').textContent || (nowData && nowData.text) || '';
|
||||||
tickSound();
|
tickSound();
|
||||||
// If from breaker, mark that step done
|
// If from breaker, mark that step done
|
||||||
if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') {
|
if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') {
|
||||||
|
|
@ -731,6 +805,7 @@
|
||||||
breakerRender();
|
breakerRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleNewDoneTasks(taskText);
|
||||||
localStorage.removeItem('myadhd.now');
|
localStorage.removeItem('myadhd.now');
|
||||||
// Check if there's a next step from breaker
|
// Check if there's a next step from breaker
|
||||||
var b2 = store(breakerKey);
|
var b2 = store(breakerKey);
|
||||||
|
|
@ -998,6 +1073,32 @@
|
||||||
|
|
||||||
/* ---------- keyboard shortcuts ---------- */
|
/* ---------- keyboard shortcuts ---------- */
|
||||||
document.addEventListener('keydown', function (e) {
|
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
|
// Don't trigger shortcuts when typing in an input or contenteditable
|
||||||
var tag = e.target.tagName;
|
var tag = e.target.tagName;
|
||||||
if (tag === 'INPUT' || tag === 'TEXTAREA' || e.target.contentEditable === 'true') return;
|
if (tag === 'INPUT' || tag === 'TEXTAREA' || e.target.contentEditable === 'true') return;
|
||||||
|
|
@ -1269,4 +1370,4 @@
|
||||||
if(timerTabBtn) timerTabBtn.click();
|
if(timerTabBtn) timerTabBtn.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
90
site/static/done.js
Normal file
90
site/static/done.js
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
65
site/static/store.js
Normal file
65
site/static/store.js
Normal file
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue