// Server-rendered views (hono/html) β€” faithful Tailwind/Alpine markup. // The original Tailwind classes + Alpine/HTMX attributes are reproduced verbatim; the browser-runtime // Tailwind (static/vendor/tailwind.js) and vendored Alpine/HTMX/Flatpickr/marked render them identically. import { html, raw } from "hono/html"; import type { HtmlEscapedString } from "hono/utils/html"; import type { CourseWithSteps, KnowledgeEntry, Lesson, Settings } from "../core/models"; import type { SharedLesson } from "../core/share"; type Html = HtmlEscapedString | Promise; /** JSON encoded for safe embedding inside a ${o.head ?? ""}
${o.body}
${o.scripts ?? ""} `; } // ── Profile (profile.html) ─────────────────────────────────────────────────── export interface ProfileData { categorised: Record; allGroups: string[]; stats: Record; rateLimit: { allowed: boolean; reason?: string | null }; maxPerDay: number; uiTheme: string; } export function profilePage(d: ProfileData): Html { const groupOptions = (current: string) => d.allGroups .filter((g) => g !== "Other") .map((g) => html``); const body = html`

Knowledge Map

${Number(d.stats.total_lessons ?? 0)} lessons total Β· ${Number(d.stats.lessons_today ?? 0)} / ${d.maxPerDay} today Β· ${Number(d.stats.lessons_this_week ?? 0)} this week Β· ${ d.rateLimit.allowed ? html`Available now` : html`${d.rateLimit.reason}` }
${Object.entries(d.categorised).map(([category, topics]) => { return html`

${category}

${ category !== "Other" ? html`
` : "" }
${topics.map((entry) => { const rowId = domId("topic-row-", entry.topic); const conf = entry.confidence; const pct = Math.trunc((conf / 10) * 100); const color = conf >= 7 ? "bg-green-500" : conf >= 4 ? "bg-yellow-500" : "bg-red-500"; const textColor = conf >= 7 ? "text-green-600 dark:text-green-400" : conf >= 4 ? "text-yellow-600 dark:text-yellow-400" : "text-red-600 dark:text-red-400"; return html`
${entry.topic}
${conf}
`; })}
`; })}
`; return layout({ title: "Profile β€” devcoach", currentPath: "/knowledge", uiTheme: d.uiTheme, body, }); } // ── Lessons (lessons.html) ─────────────────────────────────────────────────── export interface LessonsSelected { period: string; category: string; level: string; project: string; repository: string; branch: string; commit: string; starred: boolean; /** "" = all, "1" = shared with me, "0" = my own. */ imported: string; /** Exact sender name; implies imported = "1". */ shared_by: string; search: string; feedback: string; date_from: string; date_to: string; sort: string; order: string; } export interface LessonsData { /** `?import=1` β€” open the import popover (after an error, or from a deep link). */ importOpen: boolean; importError: "invalid" | "cross" | null; lessons: Lesson[]; allCategories: string[]; allProjects: string[]; allRepositories: string[]; allBranches: string[]; allCommits: string[]; /** Every sender of a shared lesson, one dropdown entry each. */ allSharedBy: string[]; s: LessonsSelected; page: number; perPage: number; total: number; totalPages: number; uiTheme: string; } const PERIOD_LABELS: Record = { all: "All time", today: "Today", week: "Last 7 days", month: "Last 30 days", year: "Last year", }; const FEEDBACK_LABELS: Record = { know: "βœ“ Knew it", understood: "πŸ’‘ Understood", dont_know: "βœ— Couldn't follow", none: "β€” No response", }; const LEVEL_EMOJI: Record = { junior: "🟒", mid: "🟑", senior: "πŸ”΄" }; function lessonsQs(s: LessonsSelected, overrides: Record = {}): string { const params: Record = { period: s.period, category: s.category, level: s.level, project: s.project, repository: s.repository, branch: s.branch, commit: s.commit, feedback: s.feedback, imported: s.imported, shared_by: s.shared_by, search: s.search, date_from: s.date_from, date_to: s.date_to, sort: s.sort, order: s.order, }; if (s.starred) params.starred = "1"; Object.assign(params, overrides); const q = new URLSearchParams(); for (const [k, v] of Object.entries(params)) if (v) q.set(k, v); return `?${q.toString()}`; } export function lessonsPage(d: LessonsData): Html { const s = d.s; const customDate = Boolean(s.date_from || s.date_to); const anyFilter = (s.period !== "all" && !customDate) || customDate || Boolean( s.category || s.level || s.project || s.repository || s.branch || s.commit || s.starred || s.imported || s.shared_by || s.search || s.feedback, ); const periodLabel = customDate ? s.date_from && s.date_to ? `${s.date_from} β†’ ${s.date_to}` : s.date_from ? `From ${s.date_from}` : `Until ${s.date_to}` : (PERIOD_LABELS[s.period] ?? "All time"); const feedbackLabel = s.feedback ? (FEEDBACK_LABELS[s.feedback] ?? "Feedback") : "Feedback"; const sharedLabel = s.shared_by ? `🀝 from ${s.shared_by}` : s.imported === "1" ? "🀝 Shared with me" : s.imported === "0" ? "πŸ‘€ My own" : "🀝 Shared"; // [imported value, sender, label] β€” the sender travels in data attributes, never in a JS literal. const sharedOptions: [string, string, string][] = [ ["", "", "All lessons"], ["0", "", "πŸ‘€ My own"], ["1", "", "🀝 Shared with me"], ...d.allSharedBy.map((name): [string, string, string] => ["1", name, `🀝 from ${name}`]), ]; const levelTextColor: Record = { junior: "text-teal-600 dark:text-teal-400 bg-teal-50 dark:bg-teal-900/20", mid: "text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20", senior: "text-rose-600 dark:text-rose-400 bg-rose-50 dark:bg-rose-900/20", }; const chip = (label: string, clearUrl: string) => html`${label}Γ—`; const sortTh = (label: string, col: string, extra = "") => { const active = s.sort === col; const next = active && s.order === "desc" ? "asc" : "desc"; return html` ${label} ${ active ? html`${s.order === "asc" ? "↑" : "↓"}` : html`↕` } `; }; const caret = html``; const head = html` `; const countLabel = d.total === 0 ? "No lessons" : d.totalPages === 1 ? `${d.total} lesson${d.total !== 1 ? "s" : ""}` : `${(d.page - 1) * d.perPage + 1}–${Math.min(d.page * d.perPage, d.total)} of ${d.total}`; const pageIds = JSON.stringify(d.lessons.map((l) => l.id)); const body = html`
πŸ” ${s.search ? html`` : ""}

${countLabel}

${ d.allCategories.length || d.allProjects.length || d.allRepositories.length || d.allBranches.length || d.allCommits.length ? html`
` : "" } ${anyFilter ? html`Clear all` : ""} ${moreMenu( html` `, anyFilter ? "" : "ml-auto", 'x-show="!selectMode"', )}
${ anyFilter ? html`
${customDate ? chip(`πŸ“… ${periodLabel}`, lessonsQs(s, { date_from: "", date_to: "" })) : ""} ${s.period !== "all" && !customDate ? chip(`πŸ• ${periodLabel}`, lessonsQs(s, { period: "all" })) : ""} ${s.feedback ? chip(FEEDBACK_LABELS[s.feedback] ?? s.feedback, lessonsQs(s, { feedback: "" })) : ""} ${s.starred ? html`β˜… StarredΓ—` : ""} ${s.imported || s.shared_by ? chip(sharedLabel, lessonsQs(s, { imported: "", shared_by: "" })) : ""} ${s.search ? chip(`πŸ” "${s.search}"`, lessonsQs(s, { search: "" })) : ""} ${s.category ? chip(s.category, lessonsQs(s, { category: "" })) : ""} ${s.level ? chip(`${LEVEL_EMOJI[s.level] ?? ""} ${s.level}`, lessonsQs(s, { level: "" })) : ""} ${s.project ? chip(`πŸ“ ${s.project}`, lessonsQs(s, { project: "" })) : ""} ${s.repository ? chip(`βŽ‡ ${s.repository}`, lessonsQs(s, { repository: "" })) : ""} ${s.branch ? chip(`βŽ‡ ${s.branch}`, lessonsQs(s, { branch: "" })) : ""} ${s.commit ? chip(s.commit.slice(0, 7), lessonsQs(s, { commit: "" })) : ""}
` : "" }
${ d.lessons.length ? html`
${sortTh("Date", "timestamp")} ${sortTh("Topic", "topic_id", "hidden sm:table-cell")} ${sortTh("Title", "title")} ${sortTh("Level", "level")} ${sortTh("Feedback", "feedback", "hidden xl:table-cell")} ${d.lessons.map((lesson) => { const rowId = domId("lesson-row-", lesson.id); const date = lesson.timestamp.slice(0, 10); const tip = lesson.timestamp.slice(0, 16).replace("T", " "); return html``; })}
Share
${date}
${tip}
${lesson.title} ${lesson.level}
${ d.totalPages > 1 ? html`

Page ${d.page} of ${d.totalPages}

${ d.page > 1 ? html`← Prev` : html`← Prev` } ${pageNumbers(d.page, d.totalPages).map((p) => p === 0 ? html`…` : p === d.page ? html`${p}` : html`${p}`, )} ${ d.page < d.totalPages ? html`Next β†’` : html`Next β†’` }
` : "" }` : html`

πŸ“­

No lessons match the current filters.

${anyFilter ? html`Clear all filters` : ""}
` } ${dangerDialog( "confirmOpen", "confirmOpen = false", html``, html`

They will be removed from your log. This cannot be undone.

`, html`
`, )}
`; const scripts = html` `; return layout({ title: "Lessons β€” devcoach", currentPath: "/lessons", uiTheme: d.uiTheme, head, body, scripts, }); } /** Windowed page list: 1, currentΒ±2, last, with 0 marking an ellipsis gap. */ function pageNumbers(page: number, totalPages: number): number[] { const out: number[] = []; let prev = 0; for (let p = 1; p <= totalPages; p++) { if (p === 1 || p === totalPages || (p >= page - 2 && p <= page + 2)) { if (prev && p - prev > 1) out.push(0); out.push(p); prev = p; } } return out; } // ── Lesson detail (lesson_detail.html) ─────────────────────────────────────── const REPO_DOMAINS: Record = { github: "github.com", gitlab: "gitlab.com", bitbucket: "bitbucket.org", }; /** Everything the share popover needs, pre-rendered server-side for the current name/context. */ export interface ShareState { id: string; open: boolean; name: string; includeContext: boolean; text: string; link: string; } /** * The popover's action row: the payloads travel as data-* attributes so a click copies * synchronously (Safari refuses clipboard writes after an await). Re-rendered by HTMX * whenever the name or the context checkbox changes. */ export function shareFragment(sh: ShareState): Html { const dl = `/lessons/${encodeURIComponent(sh.id)}/share?format=md&name=${encodeURIComponent(sh.name)}&include_context=${sh.includeContext ? "1" : "0"}`; return html`
⬇ Download .md

${sh.name ? html`Shared by ${sh.name}` : "Shared anonymously"} Β· ${sh.includeContext ? "includes project, branch and commit" : "only the lesson travels β€” no paths, no project"}.

`; } /** * The share panel (sender name, context toggle, the copy/download payloads). It lives inside the * lesson page's popover and, with `heading`, inside the lessons list's modal β€” the same route * (`?format=panel`) serves it there so the list never has to leave the page. */ export function sharePanel(lessonId: string, sh: ShareState, heading: string | null = null): Html { return html`

Share this lesson

${heading ? html`

${heading}

` : ""}
${shareFragment(sh)} `; } export function lessonDetailPage(d: { lesson: Lesson; uiTheme: string; share: ShareState; /** Flash after POST /lessons/import: freshly stored, or already in the log. */ imported: "new" | "dup" | null; /** The course this lesson seeded, if any (newest). */ course: { id: string; title: string; done: number; total: number; status: string } | null; }): Html { const l = d.lesson; const sh = d.share; const levelClass = l.level === "junior" ? "text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-900/30 border-green-300 dark:border-green-700" : l.level === "mid" ? "text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-900/30 border-yellow-300 dark:border-yellow-700" : "text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-900/30 border-red-300 dark:border-red-700"; const isLocal = l.repository_platform === "local"; let repoUrl: string | null = null; if (isLocal && l.repository) repoUrl = `vscode://file/${l.repository}`; else if (l.repository_platform && REPO_DOMAINS[l.repository_platform] && l.repository) repoUrl = `https://${REPO_DOMAINS[l.repository_platform]}/${l.repository}`; let commitUrl: string | null = null; if (repoUrl && l.commit_hash && !isLocal) { commitUrl = l.repository_platform === "gitlab" ? `${repoUrl}/-/commit/${l.commit_hash}` : l.repository_platform === "bitbucket" ? `${repoUrl}/commits/${l.commit_hash}` : `${repoUrl}/commit/${l.commit_hash}`; } const hasMeta = Boolean(l.project || l.repository || l.branch || l.commit_hash || l.folder); const date = l.timestamp.slice(0, 10); const tip = l.timestamp.slice(0, 16).replace("T", " "); // One feedback POST re-renders both regions: the badge row (target) and, out of band, // the footer buttons β€” the markdown body is client-rendered, so a full-page swap would blank it. const feedbackHx = `hx-post="/lessons/${encodeURIComponent(l.id)}/feedback" hx-target="#lesson-meta" hx-select="#lesson-meta" hx-swap="outerHTML" hx-select-oob="#lesson-feedback:outerHTML"`; const body = html`
${ d.imported ? html`
${d.imported === "new" ? html`βœ“ Imported β€œ${l.title}”${l.shared_by ? html`, shared by ${l.shared_by}` : ""}. It's in your log now β€” feedback works as usual and it never counts against your daily limit.` : html`β€œ${l.title}” was already in your log β€” nothing changed.`}
` : "" }

${l.title}

${l.level} ${moreMenu( html``, "shrink-0", )}
πŸ—“ ${date} ${tip} 🏷 ${l.topic_id} ${l.imported ? html`🀝 shared by ${l.shared_by ?? "anonymous"}` : ""} ${d.course ? html`πŸŽ“ Course Β· ${d.course.done}/${d.course.total}${d.course.status === "completed" ? " βœ“" : ""}` : ""} ${l.categories.map((cat) => html`${cat}`)} ${ l.feedback ? html`${ l.feedback === "know" ? html`βœ“ I knew this` : l.feedback === "understood" ? html`πŸ’‘ Understood` : html`βœ— Couldn't follow` }
` : "" }

TL;DR

${l.task_context ? html`
Context: ${l.task_context}
` : ""} ${ hasMeta ? html`
${l.project ? html`project ${repoUrl ? html`${l.project}` : html`${l.project}`}` : ""} ${l.repository ? html`repo${l.repository_platform && REPO_DOMAINS[l.repository_platform] ? html`` : ""}${repoUrl ? html`${l.repository}` : html`${l.repository}`}` : ""} ${l.branch ? html`branch ${l.branch}` : ""} ${l.commit_hash ? html`commit ${commitUrl ? html`${l.commit_hash.slice(0, 7)}` : html`${l.commit_hash.slice(0, 7)}`}` : ""} ${l.folder ? html`folder${l.folder}` : ""}
` : "" }
${ !l.feedback ? html`
` : "" }
ID: ${l.id}
${dangerDialog( "confirmOpen", "confirmOpen = false", html`Delete this lesson?`, html`

β€œ${l.title}”

${l.imported ? html`It was shared with you${l.shared_by ? html` by ${l.shared_by}` : ""}; you can import it again later. ` : ""}It will be removed from your log. This cannot be undone.

`, html`
`, )}
`; const head = html``; const scripts = html` `; return layout({ title: `${l.title} β€” devcoach`, currentPath: "/lessons", uiTheme: d.uiTheme, head, body, scripts, }); } // ── Import (GET /lessons/import) ───────────────────────────────────────────── const LEVEL_BADGE: Record = { junior: "text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-900/30 border-green-300 dark:border-green-700", mid: "text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-900/30 border-yellow-300 dark:border-yellow-700", senior: "text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-900/30 border-red-300 dark:border-red-700", }; /** * The receiving end of a share link (the docs page sends the browser here with `?code=`) and * the plain paste form. Rendering is read-only: the lesson is stored only when the visitor * clicks "Add to my lessons", a same-origin POST. */ export function importPage(d: { code: string; preview: SharedLesson | null; error: string | null; uiTheme: string; }): Html { const p = d.preview; const pasteForm = html`

You can also drop the file anywhere on this page.

`; const body = html`

${p ? "Someone shared a lesson with you" : "Import a shared lesson"}

${d.error ? html`
${d.error}
` : ""} ${ p ? html`

${p.lesson.title}

${p.lesson.level}
🏷 ${p.lesson.topic_id} ${p.lesson.categories.map((cat) => html`${cat}`)} 🀝 shared by ${p.shared_by ?? "anonymous"} · ${p.shared_at.slice(0, 10)}

TL;DR

Full lesson
${p.lesson.task_context ? html`
Context: ${p.lesson.task_context}
` : ""}

Nothing is saved until you click. It joins your log like your own lessons and never counts against the daily limit.

` : pasteForm }
`; const head = html``; const scripts = html` `; return layout({ title: p ? `${p.lesson.title} β€” devcoach` : "Import a lesson β€” devcoach", currentPath: "/lessons", uiTheme: d.uiTheme, head, body, scripts, }); } // ── Settings (settings.html) ───────────────────────────────────────────────── const GAP_OPTIONS: [number, string][] = [ [0, "No cooldown"], [15, "15 minutes"], [30, "30 minutes"], [60, "1 hour"], [90, "1 hour 30 min"], [120, "2 hours"], [180, "3 hours"], [240, "4 hours"], [360, "6 hours"], [480, "8 hours"], [720, "12 hours"], [1440, "24 hours"], ]; // ── Courses (GET /courses, GET /courses/:id) ──────────────────────────────── const COURSE_STATUS_BADGE: Record = { active: "bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300 border-accent-200 dark:border-accent-700", completed: "bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-400 border-green-200 dark:border-green-700", abandoned: "bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 border-gray-200 dark:border-gray-700", }; const STEP_ICON: Record = { todo: "β—‹", done: "●", skipped: "β—Œ" }; function statusBadge(status: string): Html { return html`${status}`; } export interface CoursesData { courses: (CourseWithSteps & { lesson_title: string | null })[]; uiTheme: string; } export function coursesPage(d: CoursesData): Html { const body = html`

Courses

${d.courses.length} course${d.courses.length !== 1 ? "s" : ""}

${ d.courses.length ? html`
${d.courses.map((c) => { const done = c.steps.filter((s) => s.status !== "todo").length; const pct = c.steps.length ? Math.round((done / c.steps.length) * 100) : 0; return html``; })}
CourseProgressStatusUpdated
${c.title} ${c.lesson_id ? html`from ${c.lesson_title ?? c.lesson_id}` : ""}
${done}/${c.steps.length}
${statusBadge(c.status)} ${c.updated_at.slice(0, 10)}
` : html`

πŸŽ“

No courses yet.

A course starts in your agent: answer n (couldn't follow) under a lesson card and say yes to the offer, or run /devcoach:course on any lesson or concept. The AI first asks what you already know, then writes the course here.

` }`; const scripts = html``; return layout({ title: "Courses β€” devcoach", currentPath: "/courses", uiTheme: d.uiTheme, body, scripts, }); } /** The 503 a write gets when this devcoach is older than the database (see core/db). */ export function readOnlyPage(message: string): Html { return html`Read-only β€” devcoach

This devcoach is older than your database

${message}

← Back

`; } export interface CourseDetailData { course: CourseWithSteps; lessonTitle: string | null; /** 1-based position of the step shown in the frame. */ selected: number; hasDocument: boolean; uiTheme: string; } export function courseDetailPage(d: CourseDetailData): Html { const c = d.course; const done = c.steps.filter((s) => s.status !== "todo").length; const current = c.steps.find((s) => s.position === d.selected) ?? c.steps[0]; const frameSrc = `/courses/${encodeURIComponent(c.id)}/index.html${current ? `#${current.anchor}` : ""}`; const stepAction = (position: number, status: string, label: string, cls: string) => html`
`; const btn = "inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-medium border transition bg-white dark:bg-gray-900 border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-200 hover:border-accent-400"; // The document carries its own title and intro, so the page adds nothing above it: a slim // sticky bar (back Β· title Β· status Β· progress Β· β‹―) that is only navigation, a pinned step // list at the side, and the frame itself β€” the page scrolls as one. const body = html`
← ${c.title} ${statusBadge(c.status)} ${done}/${c.steps.length} steps ${moreMenu( html``, "ml-auto shrink-0", )}
${ d.hasDocument ? html`` : html`

✍️

The course document hasn't been written yet. Ask your agent to continue the course β€” it writes index.html in the course folder, and it appears here.
` }
${dangerDialog( "confirmOpen", "confirmOpen = false", html`Delete this course?`, html`

β€œ${c.title}”

The course, its steps and its document folder will be removed. This cannot be undone.${c.lesson_id ? " The lesson it grew from stays." : ""}

`, html`
`, )}
`; return layout({ title: `${c.title} β€” devcoach`, currentPath: "/courses", uiTheme: d.uiTheme, body, scripts: html``, wide: true, }); } export interface SettingsData { settings: Settings; notebookContent: string; notebookPath: string; uiTheme: string; flash?: { imported: number; skipped: number; invalid: number; groups: number; notebook: number; } | null; } export function settingsPage(d: SettingsData): Html { const gap = d.settings.min_gap_minutes; const themeRadios: [string, string, string][] = [ ["system", "System", "πŸŒ“"], ["light", "Light", "β˜€οΈ"], ["dark", "Dark", "πŸŒ™"], ]; const homeRadios: [string, string, string][] = [ ["auto", "Auto", "🏠"], ["lessons", "Lessons", "πŸ“š"], ["knowledge", "Knowledge map", "🧭"], ]; const f = d.flash; const body = html`

Settings

${ f ? html`
${f.imported} lesson${f.imported !== 1 ? "s" : ""} imported.${f.skipped ? ` ${f.skipped} skipped (already in DB).` : ""}${f.invalid ? ` ${f.invalid} rejected (failed validation).` : ""}${f.groups ? ` ${f.groups} group${f.groups !== 1 ? "s" : ""} added.` : ""}${f.notebook ? " Notebook restored." : ""}
` : "" }

Coaching

Lessons in a 24h window.

Minimum gap between lessons.

Cue at most once every N (0 = every turn).

Per-chat or across all sessions.

Proposed as the sender when you share a lesson. Empty β†’ your git name.

UI theme
${themeRadios.map( ([value, label, icon]) => html``, )}

System follows your OS preference.

Home page
${homeRadios.map( ([value, label, icon]) => html``, )}

Auto opens Lessons once you have one, the knowledge map before.

Backup & Restore

Full backup

Settings + knowledge map + lessons + coaching notebook as a zip file.

↓ Download backup

Restore backup

Overwrites settings, knowledge map & coaching notebook; duplicate lessons are skipped.

Lessons only

Export just the lesson log as JSON (no settings).

↓ Download lessons

Import lessons

Merge a lessons JSON file; duplicates are skipped.

Coaching Notebook

`; const scripts = html` `; return layout({ title: "Settings β€” devcoach", currentPath: "/settings", uiTheme: d.uiTheme, body, scripts, }); }