Add note context visibility in chat and standardize UI design tokens

Improve chat context: build_context() now returns metadata about auto-found
notes, emitted as an SSE event so the frontend can display context pills
showing which notes influenced the response. Users can promote notes for
deeper context (+) or exclude irrelevant ones (x). A note picker lets users
manually attach notes. Multi-word search uses per-term AND matching, and
auto-search iterates keywords individually for broader OR-style coverage.

Standardize styling: introduce CSS design tokens (--radius-sm/md/lg/pill,
--color-success/warning/overlay, --focus-ring) and migrate all components
to use them. Fix header alignment to full-width, add active nav link state,
replace hardcoded colors with CSS variables, and normalize button padding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 06:49:12 -05:00
parent 39bcd7a8fa
commit fb18d2c41d
26 changed files with 1070 additions and 237 deletions
+19 -10
View File
@@ -54,9 +54,7 @@ const statusClass = computed(() => {
border-bottom: 1px solid var(--color-border);
}
.nav {
max-width: 960px;
margin: 0 auto;
padding: 0.5rem 1rem;
padding: 0.5rem 1.25rem;
display: flex;
align-items: center;
justify-content: space-between;
@@ -70,19 +68,29 @@ const statusClass = computed(() => {
.nav-links {
display: flex;
align-items: center;
gap: 1rem;
gap: 0.25rem;
}
.nav-link {
color: var(--color-text-secondary);
text-decoration: none;
font-size: 0.95rem;
font-size: 0.9rem;
padding: 0.3rem 0.6rem;
border-radius: var(--radius-sm);
transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
color: var(--color-primary);
background: var(--color-bg-card);
}
.nav-link.router-link-active {
color: var(--color-primary);
background: var(--color-bg-card);
font-weight: 600;
}
.status-indicator {
display: flex;
align-items: center;
margin-left: 0.5rem;
}
.status-dot {
width: 8px;
@@ -91,14 +99,14 @@ const statusClass = computed(() => {
flex-shrink: 0;
}
.status-green .status-dot {
background: #22c55e;
background: var(--color-success);
}
.status-yellow .status-dot {
background: #eab308;
background: var(--color-warning);
animation: pulse-dot 2s infinite;
}
.status-red .status-dot {
background: #ef4444;
background: var(--color-danger);
}
@keyframes pulse-dot {
0%, 100% { opacity: 1; }
@@ -107,12 +115,13 @@ const statusClass = computed(() => {
.btn-chat-panel {
background: none;
border: 1px solid var(--color-border);
border-radius: 4px;
border-radius: var(--radius-sm);
padding: 0.25rem 0.5rem;
cursor: pointer;
font-size: 1rem;
color: var(--color-text);
line-height: 1;
margin-left: 0.25rem;
}
.btn-chat-panel:hover {
background: var(--color-bg-card);
@@ -120,7 +129,7 @@ const statusClass = computed(() => {
.theme-toggle {
background: none;
border: 1px solid var(--color-border);
border-radius: 4px;
border-radius: var(--radius-sm);
padding: 0.25rem 0.5rem;
cursor: pointer;
font-size: 1.1rem;
+38 -18
View File
@@ -17,6 +17,12 @@ const emit = defineEmits<{
const rendered = computed(() => renderMarkdown(props.message.content));
const formattedTime = computed(() => {
if (!props.message.created_at) return "";
const date = new Date(props.message.created_at);
return date.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
});
const roleLabel = computed(() => {
switch (props.message.role) {
case "user":
@@ -31,24 +37,27 @@ const roleLabel = computed(() => {
<template>
<div class="chat-message" :class="`role-${message.role}`">
<div class="message-bubble">
<div class="message-header">
<span class="role-label">{{ roleLabel }}</span>
<div class="message-actions" v-if="message.role === 'assistant' && !isStreaming">
<button class="btn-save" @click="emit('saveAsNote', message.id)" title="Save as note">
Save as Note
</button>
<div class="message-group">
<div class="message-bubble">
<div class="message-header">
<span class="role-label">{{ roleLabel }}</span>
<div class="message-actions" v-if="message.role === 'assistant' && !isStreaming">
<button class="btn-save" @click="emit('saveAsNote', message.id)" title="Save as note">
Save as Note
</button>
</div>
</div>
<div class="message-content prose" v-html="rendered"></div>
<div
v-if="message.context_note_id"
class="context-badge"
>
<router-link :to="`/notes/${message.context_note_id}`">
Note #{{ message.context_note_id }}
</router-link>
</div>
</div>
<div class="message-content prose" v-html="rendered"></div>
<div
v-if="message.context_note_id"
class="context-badge"
>
<router-link :to="`/notes/${message.context_note_id}`">
Note #{{ message.context_note_id }}
</router-link>
</div>
<span v-if="formattedTime" class="message-timestamp">{{ formattedTime }}</span>
</div>
</div>
</template>
@@ -65,8 +74,11 @@ const roleLabel = computed(() => {
justify-content: flex-start;
}
.message-bubble {
.message-group {
max-width: 80%;
}
.message-bubble {
padding: 0.75rem 1rem;
border-radius: 16px;
}
@@ -136,7 +148,7 @@ const roleLabel = computed(() => {
padding: 0.1rem 0.4rem;
background: transparent;
border: 1px solid var(--color-border);
border-radius: 4px;
border-radius: var(--radius-sm);
color: var(--color-text-secondary);
cursor: pointer;
}
@@ -159,4 +171,12 @@ const roleLabel = computed(() => {
.context-badge a:hover {
text-decoration: underline;
}
.message-timestamp {
display: block;
font-size: 0.7rem;
color: var(--color-text-muted);
margin-top: 0.15rem;
padding: 0 0.5rem;
}
</style>
+377 -48
View File
@@ -2,8 +2,10 @@
import { ref, computed, watch, nextTick } from "vue";
import { useChatStore } from "@/stores/chat";
import { useSettingsStore } from "@/stores/settings";
import { apiGet } from "@/api/client";
import { renderMarkdown } from "@/utils/markdown";
import ChatMessage from "@/components/ChatMessage.vue";
import type { Note } from "@/types/note";
const props = defineProps<{
contextNoteId?: number | null;
@@ -17,6 +19,18 @@ const store = useChatStore();
const settingsStore = useSettingsStore();
const messageInput = ref("");
const messagesEl = ref<HTMLElement | null>(null);
const inputEl = ref<HTMLTextAreaElement | null>(null);
// Note picker state
const attachedNote = ref<{ id: number; title: string } | null>(null);
const showNotePicker = ref(false);
const noteSearchQuery = ref("");
const noteSearchResults = ref<{ id: number; title: string }[]>([]);
const noteSearchLoading = ref(false);
let noteSearchTimer: ReturnType<typeof setTimeout> | null = null;
// Exclude tracking
const excludedNoteIds = ref<Set<number>>(new Set());
const streamingRendered = computed(() => {
if (!store.streamingContent) return "";
@@ -46,9 +60,16 @@ async function sendMessage() {
await store.fetchConversation(conv.id);
}
const contextNoteId = attachedNote.value?.id ?? props.contextNoteId;
attachedNote.value = null;
messageInput.value = "";
resetTextareaHeight();
scrollToBottom();
await store.sendMessage(content, props.contextNoteId);
await store.sendMessage(
content,
contextNoteId,
excludedNoteIds.value.size ? [...excludedNoteIds.value] : undefined,
);
scrollToBottom();
}
@@ -63,12 +84,77 @@ async function handleSaveAsNote(messageId: number) {
}
}
function autoResize() {
const el = inputEl.value;
if (!el) return;
el.style.height = "auto";
el.style.height = Math.min(el.scrollHeight, 150) + "px";
}
function resetTextareaHeight() {
const el = inputEl.value;
if (!el) return;
el.style.height = "auto";
}
function onInputKeydown(e: KeyboardEvent) {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
}
// Note picker
function toggleNotePicker() {
showNotePicker.value = !showNotePicker.value;
if (showNotePicker.value) {
noteSearchQuery.value = "";
noteSearchResults.value = [];
nextTick(() => {
const el = document.querySelector(".panel-note-picker-search") as HTMLInputElement;
el?.focus();
});
}
}
function onNoteSearchInput() {
if (noteSearchTimer) clearTimeout(noteSearchTimer);
noteSearchTimer = setTimeout(async () => {
const q = noteSearchQuery.value.trim();
if (!q) {
noteSearchResults.value = [];
return;
}
noteSearchLoading.value = true;
try {
const data = await apiGet<{ notes: Note[] }>(
`/api/notes?q=${encodeURIComponent(q)}&all=true&limit=5`
);
noteSearchResults.value = data.notes.map((n) => ({ id: n.id, title: n.title }));
} catch {
noteSearchResults.value = [];
} finally {
noteSearchLoading.value = false;
}
}, 250);
}
function selectNote(note: { id: number; title: string }) {
attachedNote.value = note;
showNotePicker.value = false;
}
function removeAttachedNote() {
attachedNote.value = null;
}
function promoteAutoNote(note: { id: number; title: string }) {
attachedNote.value = note;
}
function excludeAutoNote(noteId: number) {
excludedNoteIds.value = new Set([...excludedNoteIds.value, noteId]);
}
</script>
<template>
@@ -83,49 +169,126 @@ function onInputKeydown(e: KeyboardEvent) {
</div>
<div ref="messagesEl" class="panel-messages">
<template v-if="store.currentConversation">
<ChatMessage
v-for="msg in store.currentConversation.messages"
:key="msg.id"
:message="msg"
@save-as-note="handleSaveAsNote"
/>
</template>
<div class="messages-inner">
<template v-if="store.currentConversation">
<ChatMessage
v-for="msg in store.currentConversation.messages"
:key="msg.id"
:message="msg"
@save-as-note="handleSaveAsNote"
/>
</template>
<!-- Streaming bubble -->
<div v-if="store.streaming" class="chat-message role-assistant">
<div class="streaming-bubble">
<div class="message-header">
<span class="role-label">{{ settingsStore.assistantName }}</span>
</div>
<div class="message-content prose" v-html="streamingRendered"></div>
<span class="typing-indicator"></span>
<!-- Context pills -->
<div
v-if="store.lastContextMeta?.auto_notes?.length && (store.streaming || store.currentConversation?.messages.length)"
class="context-pills"
>
<span class="context-pills-label">Context:</span>
<span
v-for="note in store.lastContextMeta.auto_notes"
:key="note.id"
class="context-pill"
>
<router-link :to="`/notes/${note.id}`" class="context-pill-link" @click="emit('close')">
{{ note.title }}
</router-link>
<button
class="context-pill-btn promote"
@click="promoteAutoNote(note)"
title="Attach for next message"
>+</button>
<button
class="context-pill-btn exclude"
@click="excludeAutoNote(note.id)"
title="Exclude from auto-search"
>&times;</button>
</span>
</div>
</div>
<p
v-if="!store.currentConversation?.messages.length && !store.streaming"
class="empty-msg"
>
Start chatting...
</p>
<!-- Streaming bubble -->
<div v-if="store.streaming" class="chat-message role-assistant">
<div class="streaming-bubble">
<div class="message-header">
<span class="role-label">{{ settingsStore.assistantName }}</span>
</div>
<div class="message-content prose" v-html="streamingRendered"></div>
<span class="typing-indicator"></span>
</div>
</div>
<p
v-if="!store.currentConversation?.messages.length && !store.streaming"
class="empty-msg"
>
Start chatting...
</p>
</div>
</div>
<div class="panel-input">
<textarea
v-model="messageInput"
@keydown="onInputKeydown"
:placeholder="store.chatReady ? 'Type a message...' : 'Chat unavailable'"
:disabled="store.streaming || !store.chatReady"
rows="2"
></textarea>
<button
class="btn-send"
@click="sendMessage"
:disabled="!messageInput.trim() || store.streaming || !store.chatReady"
>
&uarr;
</button>
<div class="panel-input-wrapper">
<!-- Attached note pill -->
<div v-if="attachedNote" class="attached-note">
<span class="attached-note-pill">
{{ attachedNote.title }}
<button class="attached-note-remove" @click="removeAttachedNote">&times;</button>
</span>
</div>
<div class="panel-input">
<!-- Note picker -->
<div class="note-picker-wrapper">
<button
class="btn-attach"
@click="toggleNotePicker"
:disabled="store.streaming || !store.chatReady"
title="Attach a note"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"/>
</svg>
</button>
<div v-if="showNotePicker" class="note-picker-dropdown">
<input
class="panel-note-picker-search"
v-model="noteSearchQuery"
@input="onNoteSearchInput"
placeholder="Search notes..."
/>
<div class="note-picker-results">
<div
v-for="note in noteSearchResults"
:key="note.id"
class="note-picker-item"
@click="selectNote(note)"
>
{{ note.title || "Untitled" }}
</div>
<div v-if="noteSearchLoading" class="note-picker-empty">Searching...</div>
<div v-else-if="noteSearchQuery && !noteSearchResults.length" class="note-picker-empty">
No notes found
</div>
</div>
</div>
</div>
<textarea
ref="inputEl"
v-model="messageInput"
@keydown="onInputKeydown"
@input="autoResize"
:placeholder="store.chatReady ? 'Type a message...' : 'Chat unavailable'"
:disabled="store.streaming || !store.chatReady"
rows="1"
></textarea>
<button
class="btn-send"
@click="sendMessage"
:disabled="!messageInput.trim() || store.streaming || !store.chatReady"
>
&uarr;
</button>
</div>
</div>
</aside>
</div>
@@ -135,7 +298,7 @@ function onInputKeydown(e: KeyboardEvent) {
.chat-panel-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.3);
background: var(--color-overlay);
z-index: 100;
display: flex;
justify-content: flex-end;
@@ -168,7 +331,7 @@ function onInputKeydown(e: KeyboardEvent) {
color: var(--color-primary);
background: var(--color-bg-secondary);
padding: 0.15rem 0.5rem;
border-radius: 4px;
border-radius: var(--radius-sm);
}
.btn-close {
background: none;
@@ -187,6 +350,11 @@ function onInputKeydown(e: KeyboardEvent) {
flex: 1;
overflow-y: auto;
padding: 0.75rem;
display: flex;
flex-direction: column;
}
.messages-inner {
margin-top: auto;
}
/* Streaming bubble — matches ChatMessage assistant style */
@@ -238,16 +406,175 @@ function onInputKeydown(e: KeyboardEvent) {
50% { opacity: 1; }
}
/* Dark floating input */
/* Context pills */
.context-pills {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.25rem;
padding: 0.35rem 0;
}
.context-pills-label {
font-size: 0.7rem;
color: var(--color-text-muted);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
}
.context-pill {
display: inline-flex;
align-items: center;
gap: 0.1rem;
background: var(--color-bg-secondary);
border: 1px solid var(--color-border);
border-radius: 10px;
padding: 0.1rem 0.25rem 0.1rem 0.4rem;
font-size: 0.75rem;
}
.context-pill-link {
color: var(--color-primary);
text-decoration: none;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.context-pill-link:hover {
text-decoration: underline;
}
.context-pill-btn {
background: none;
border: none;
cursor: pointer;
font-size: 0.8rem;
line-height: 1;
padding: 0 0.1rem;
color: var(--color-text-muted);
border-radius: 50%;
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.context-pill-btn:hover {
background: var(--color-border);
}
.context-pill-btn.promote:hover {
color: var(--color-primary);
}
.context-pill-btn.exclude:hover {
color: var(--color-danger, #e74c3c);
}
/* Input wrapper */
.panel-input-wrapper {
margin: 0 0.5rem 0.5rem;
}
/* Attached note */
.attached-note {
padding: 0.2rem 0.5rem;
}
.attached-note-pill {
display: inline-flex;
align-items: center;
gap: 0.2rem;
background: var(--color-primary);
color: #fff;
border-radius: 10px;
padding: 0.15rem 0.4rem;
font-size: 0.75rem;
}
.attached-note-remove {
background: none;
border: none;
color: rgba(255, 255, 255, 0.7);
cursor: pointer;
font-size: 0.9rem;
line-height: 1;
padding: 0 0.1rem;
}
.attached-note-remove:hover {
color: #fff;
}
/* Floating input */
.panel-input {
display: flex;
align-items: flex-end;
align-items: center;
gap: 0.5rem;
margin: 0 0.5rem 0.5rem;
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
background: #1c1c1e;
background: var(--color-input-bar-bg);
border-radius: 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
box-shadow: 0 2px 8px var(--color-shadow);
}
/* Note picker */
.note-picker-wrapper {
position: relative;
}
.btn-attach {
background: none;
border: none;
cursor: pointer;
color: var(--color-input-bar-text);
opacity: 0.6;
padding: 0.2rem;
display: flex;
align-items: center;
justify-content: center;
}
.btn-attach:hover {
opacity: 1;
}
.btn-attach:disabled {
opacity: 0.3;
cursor: default;
}
.note-picker-dropdown {
position: absolute;
bottom: calc(100% + 8px);
left: 0;
width: 260px;
background: var(--color-bg-card);
border: 1px solid var(--color-border);
border-radius: var(--radius-md);
box-shadow: 0 4px 16px var(--color-shadow);
z-index: 10;
overflow: hidden;
}
.panel-note-picker-search {
width: 100%;
padding: 0.45rem 0.65rem;
border: none;
border-bottom: 1px solid var(--color-border);
background: transparent;
color: var(--color-text);
font-size: 0.85rem;
outline: none;
font-family: inherit;
box-sizing: border-box;
}
.note-picker-results {
max-height: 180px;
overflow-y: auto;
}
.note-picker-item {
padding: 0.4rem 0.65rem;
cursor: pointer;
font-size: 0.85rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.note-picker-item:hover {
background: var(--color-bg-secondary);
}
.note-picker-empty {
padding: 0.4rem 0.65rem;
color: var(--color-text-muted);
font-size: 0.8rem;
}
.panel-input textarea {
flex: 1;
@@ -258,11 +585,13 @@ function onInputKeydown(e: KeyboardEvent) {
font-family: inherit;
font-size: 0.9rem;
background: transparent;
color: #fff;
color: var(--color-input-bar-text);
outline: none;
max-height: 150px;
overflow-y: auto;
}
.panel-input textarea::placeholder {
color: rgba(255, 255, 255, 0.4);
color: var(--color-input-bar-placeholder);
}
.panel-input textarea:disabled {
opacity: 0.5;
+1 -1
View File
@@ -39,7 +39,7 @@ const buttons = [
.md-btn {
padding: 0.25rem 0.5rem;
border: 1px solid var(--color-input-border);
border-radius: 3px;
border-radius: var(--radius-sm);
background: var(--color-bg-card);
color: var(--color-text);
cursor: pointer;
+1 -1
View File
@@ -33,7 +33,7 @@ function onTagClick(tag: string) {
display: block;
padding: 1rem;
border: 1px solid var(--color-border);
border-radius: 6px;
border-radius: var(--radius-md);
text-decoration: none;
color: inherit;
background: var(--color-bg-card);
+1 -1
View File
@@ -75,7 +75,7 @@ function goToPage(page: number) {
.page-btn {
padding: 0.35rem 0.7rem;
border: 1px solid var(--color-border);
border-radius: 4px;
border-radius: var(--radius-sm);
background: var(--color-bg-card);
color: var(--color-text);
cursor: pointer;
+1 -1
View File
@@ -25,7 +25,7 @@ watch(query, (val) => {
width: 100%;
padding: 0.5rem 0.75rem;
border: 1px solid var(--color-input-border);
border-radius: 4px;
border-radius: var(--radius-sm);
font-size: 1rem;
box-sizing: border-box;
background: var(--color-bg-card);
+1 -1
View File
@@ -60,7 +60,7 @@ function isOverdue(): boolean {
display: block;
padding: 1rem;
border: 1px solid var(--color-border);
border-radius: 6px;
border-radius: var(--radius-md);
text-decoration: none;
color: inherit;
background: var(--color-bg-card);