/** * Server-rendered HTML for the factory app: shared shell, per-view skeletons, * and the no-JS manage page. Pure (no kody:runtime) so it is unit-testable. */ import { CSS } from './styles.ts' import { CLIENT_JS } from './client.ts' import { THEME_BOOT_JS } from './theme.ts' import type { ProjectConfig } from '../projects/model.ts' export type View = 'overview' | 'board' | 'work' | 'plans' | 'projects' | 'project-detail' | 'notifications' | 'health' | 'signals' | 'reports' | 'settings' | 'manage' export const ICONS: Record = { overview: '', queue: '', folder: '', settings: '', plus: '', inbox: '', search: '', close: '', eye: '', alert: '', message: '', branch: '', zap: '', pencil: '', mail: '', external: '', check: '', arrow: '', sun: '', moon: '', pulse: '', monitor: '', bell: '', kanban: '', compass: '', clock: '', move: '', report: '', grip: '', } /** Standalone favicon document: same art as APP_MARK_SVG and public/favicon.svg. */ export function faviconSvg(): string { return APP_MARK_SVG.replace('` } export function esc(s: unknown): string { return String(s ?? '') .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, ''') } /** Factory mark: tiles moving along a line. Same art as public/favicon.svg (unique gradient id for inline use). */ export const APP_MARK_SVG = `` const NAV: Array<[View, string, string, string]> = [ ['overview', '/', 'Overview', 'overview'], ['board', '/board', 'Board', 'kanban'], ['plans', '/plans', 'Plans', 'compass'], ['work', '/work', 'Work queue', 'queue'], ['reports', '/reports', 'Reports', 'report'], ['projects', '/projects', 'Projects', 'folder'], ['notifications', '/notifications', 'Notifications', 'bell'], ['health', '/factory-health', 'Health', 'pulse'], ['signals', '/signals', 'Signals', 'zap'], ] /** Overview placeholders use the real row/card markup with hidden text so data lands in the same boxes. */ export const PH_ROW = `` const PH_PCARD = `` const SKEL_ROW = `` /** Same markup and typical copy as the client's kv rows, shown as skeletons so the real rows land in the same space. */ const skelKv = (rows: Array<[string, string, string]>) => `` const RUN_SAFELY_SKEL: Array<[string, string, string]> = [ ['Shadow mode', 'Agent sessions can start for ready work.', 'Off'], ['Max concurrent sessions', 'Up to 2 agent sessions at a time.', '2'], ['Merge policy', 'Every merge stays with you.', "Agents can't merge"], ['Sweep', 'Every 15 minutes. Moves each item at most one stage per run.', 'Scheduled'], ['Pilot scope', 'Sweep, backfill, and issue intake act on no project until a pilot scope is set.', 'Not set'], ] const CONNECTIONS_SKEL: Array<[string, string, string]> = [ ['Devin', 'Agent runner for building work.', 'Configured'], ['Cloudflare AI', 'Model used to triage new work.', 'Account configured'], ['GitHub intake', 'Issue and CI webhooks are declared and need your approval before events arrive.', 'Setup required'], ['GitHub issue backfill', 'Preview open issues from enabled repositories, then add them in shadow mode. Runs only when you ask.', 'On demand'], ['GitHub Projects', 'Planning board updates are turned off.', 'Not connected'], ] const skel = (h: number, w = '100%') => `
` function navLink(bp: string, current: View, [view, href, label, ic]: [View, string, string, string]) { const active = current === view || (view === 'settings' && current === 'manage') const badge = view === 'notifications' ? '' : '' return `${icon(ic)}${label}${badge}` } function overviewMain(bp: string): string { return `

Move work forward.

Track priorities, see what needs attention, and keep work moving.

${icon('kanban')}Open board

Key numbers

${['Active projects', 'Needs your attention', 'In progress', 'Open work'].map((l) => ``).join('')}
${PH_ROW.repeat(5)}

Priority snapshot

Projects

All projects
${PH_PCARD.repeat(3)}
` } function boardMain(bp: string): string { return `

Board

See where every piece of work is in the ship pipeline.

` } function plansMain(bp: string): string { return `

Plans

What to build and why. The source of truth for decisions.

New plan

` } function notificationsMain(bp: string): string { return `

Notifications

Events from across the factory.

Loading notifications...

${Array.from({ length: 4 }, () => ``).join('')}
` } function projectDetailMain(bp: string): string { const skelCard = (title: string) => `

${title}

` return `
Projects/Project

Loading project

Loading

${skelCard('Agents')} ${skelCard('Automated runs')} ${skelCard('Flow metrics')} ${skelCard('PRs and CI')}
` } function workMain(bp: string): string { const tabs = [['all', 'All'], ['active', 'Active'], ['needs', 'Needs you'], ['complete', 'Complete']] return `

Work queue

One place for everything moving through your factory.

${tabs.map(([v, l]) => ``).join('')}

Loading work…

${SKEL_ROW.repeat(6)}

Looking for setup? Manage projects

` } function projectsMain(bp: string): string { return `

Projects

Every repository the factory can pick up work from.

Manage projects
${skel(90)}
${skel(90)}
` } function settingsMain(bp: string): string { return `

Settings

How the factory runs, and what it's connected to.

Run safely

${skelKv(RUN_SAFELY_SKEL)}

Connections

Credentials are managed in Kody. No secrets appear here.

${skelKv(CONNECTIONS_SKEL)}

Project settings

Add projects and repositories, turn them on or off, or set the model triage account.

Offline and install

This browser keeps the last queue snapshot (titles, projects, states; no settings or account IDs) so the app opens offline, marked with when it last synced. Drafts of new work wait here until you reconnect. Changes to projects, settings, and backfill need a connection.

Push notifications

Get a phone or desktop notification for new Sentry and signal cards and anything that needs you. Each device asks once. Tapping a notification opens the card.

Checking this device...

    Kill switch

    When engaged, the factory will not start new agent runs or merges. Sweeps still run but skip all transitions.

    Config export and import

    Export the factory configuration as a JSON document (no secrets). Import a config to preview and apply changes.

    Templates

    Apply a built-in template to set up projects and settings.

    Loading templates...

    Model check

    Confirm triage can reach its model. It runs only when you click it.

    Appearance

    Saved in this browser only.

    ${themeChoices('theme-settings', 'Theme')}
    ` } const THEME_CHOICES: Array<[string, string, string, string]> = [ ['light', 'Light', 'Always use the light theme', 'sun'], ['dark', 'Dark', 'Always use the dark theme', 'moon'], ['system', 'System', 'Match your device setting', 'monitor'], ] /** Native radio group (arrow keys work); client.ts syncs every group on the page. */ export function themeChoices(name: string, legend: string): string { return `
    ${legend}${THEME_CHOICES.map( ([v, label, sub, ic]) => ``, ).join('')}
    ` } const THEME_CONTROL = `
    ` const STATIC_DIALOGS = `

    Add work

    It joins the queue as New. Nothing starts automatically.

    Are you sure?

    ` export function renderShell(opts: { basePath: string; view: View; title: string; main?: string }): string { const bp = esc(opts.basePath) const main = opts.main ?? { overview: overviewMain, board: boardMain, plans: plansMain, work: workMain, projects: projectsMain, 'project-detail': projectDetailMain, notifications: notificationsMain, settings: settingsMain, health: () => '', signals: () => '', reports: () => '', manage: () => '' }[opts.view](bp) const icons = JSON.stringify(ICONS).replace(/ ${esc(opts.title)} · Kody Factory
    ${main}
    Kody FactoryTimes shown in Mountain Time (America/Denver)
    ${STATIC_DIALOGS} ` } const BAD_FLASH = /^(error|invalid|delete aborted|unknown)/i export function renderManage(opts: { basePath: string projects: ProjectConfig[] flash?: string modelAccountSet: boolean }): string { const bp = esc(opts.basePath) const flash = opts.flash ? `
    ${esc(opts.flash)}
    ` : '' const options = opts.projects .map((p) => ``) .join('') const post = (fields: Record, label: string, cls = 'btn small', confirm?: string) => `
    ${Object.entries( fields, ) .map(([k, v]) => ``) .join('')}
    ` const rows = opts.projects .map((p) => { const repos = p.repos .map( (r) => `
  • ${esc(r.repoRef)}${r.enabled ? 'On' : 'Off'}${post( { action: r.enabled ? 'disable-repo' : 'enable-repo', projectId: p.id, repoRef: r.repoRef }, r.enabled ? 'Turn off repo' : 'Turn on repo', 'btn small', r.enabled ? `Turn off ${r.repoRef}? The factory stops accepting new work from this repository. Existing work stays in the queue.` : undefined, )}
  • `, ) .join('') return `

    ${esc(p.displayName)} ${p.enabled ? 'Enabled' : 'Disabled'}

    ${esc(p.id)}
      ${repos || '
    • No repositories yet
    • '}
    View work${post( { action: p.enabled ? 'disable-project' : 'enable-project', projectId: p.id }, p.enabled ? 'Disable' : 'Enable', 'btn small', p.enabled ? `Disable ${p.displayName}? The sweep stops advancing its work and no new work is accepted. Nothing is deleted.` : undefined, )}
    ` }) .join('') const main = `

    Manage projects

    Keep your projects and connections up to date.

    ${flash}

    Your projects

    ${opts.projects.length} configured
    ${rows || '

    No projects yet. Add one below.

    '}

    Add a project

    Saving an existing project ID replaces its settings.

    Add a repository

    GitHub issue backfill

    On demand

    Reads open issues from enabled GitHub repositories with the package's read-only github credential. Preview never writes. Adding puts eligible issues in the queue as New, in shadow mode: no triage, plan, or agent session starts from here.

    Model triage

    ${opts.modelAccountSet ? 'Account configured' : 'Not configured'}

    Check model connection

    Runs one real triage check. No work is created.

    Delete a project

    Removes the project from the factory. Its existing work items stay in the ledger. Disabling is usually the safer choice.

    ` return renderShell({ basePath: opts.basePath, view: 'manage', title: 'Manage projects', main }) }