import m, {MithrilComponent} from '@garage44/mithril' import {Badge, Button, Card, FieldText, NavGroup, NavItem} from '@garage44/mithril/components' import {toast} from '@garage44/mithril/components' import {askConfirm, confirmButton} from '@/components/confirm' import {foldable} from '@/components/fold' import {Elapsed} from '@/components/elapsed' import {activity} from '@/lib/activity' import {gauge, gaugeOf, journeyOf, milestones, wayButton, wayToLive} from '@/components/landing' import {nodeFoot, nodeStepLine} from '@/components/nodeline' import {icon} from '@/components/icons' import {who} from '@/components/who' import {nameOf, speaker} from '@/lib/names' import {act, toastModel} from '@/lib/actions' import {api} from '@/lib/api' import {age, ahead, now, shortName, since, span, when} from '@/lib/format' import {FEED_KINDS, buildFeed, involving} from '@/lib/feed' import type {Message} from '@/lib/feed' import {bind, local} from '@/lib/reactive' import {go, here} from '@/lib/route' import {placeChip} from '@/components/place' import {goalLine, originIcon, originPips, themeOf} from '@/components/pips' import {showTech} from '@/components/research' import {runnerAwayLine} from '@/components/runners' import {STATUS, awaitsPerson, turnOf} from '@/lib/status' import {$s, steers} from '@/lib/store' import {cards, connect, expect, follow, followedLog, hosted, live, todos} from '@/lib/stream' import {toolCalls} from '@/lib/tools' import {nodeStep} from '@/lib/nodeline' import type {Hosted, LogItem, Mode, PageNote, ResearchOrigin, SearchHit} from '@/lib/stream' import type {FilesReport} from '@/lib/types' import {NewSessionButton, stepsBar} from '@/components/home' import {answersOf, answerTo} from '@/lib/answers' import {mentions, recommended} from '@/lib/mentions' import type {Mentions} from '@/lib/mentions' import {highlight} from '@/lib/highlight' import {inline, markdown, sessions} from '@/lib/markdown' import {reduced} from '@/lib/motion' import {continueList} from '@/lib/lists' import {checkAvailable, hooks} from '@/lib/discuss' import {byTech, grouped} from '@/lib/groups' import type {Group} from '@/lib/groups' import {deployAt, shortWords} from '@/lib/landing' import {PILOT, autopilotChip, pilotDeciding, pilotLine, pilotState, pilotWhy, plane} from '@/components/autopilot' import {startGuard} from '@/components/focus' import {askProjects, inView, projectName, projectSelect, projects, projectTag, reposOf, several, shown} from '@/lib/projects' import type {Project} from '@/lib/projects' /** * Claude Code's modes through `midas acp`, for a session not started yet (a * running one offers its agent's own list). Trusted (bypassPermissions) does everything without asking. */ const START_MODES: Mode[] = [ {id: 'default', name: 'Manual'}, {id: 'acceptEdits', name: 'Accept edits'}, {id: 'plan', name: 'Plan'}, {id: 'auto', name: 'Auto'}, {id: 'bypassPermissions', name: 'Trusted'}, ] const BYPASS = 'bypassPermissions' /** The models a session can start on: Claude Code's aliases, each the current model of its kind. */ const START_MODELS: Mode[] = [ {id: 'default', name: 'Default'}, {id: 'fable', name: 'Fable'}, {id: 'opus', name: 'Opus'}, {id: 'opus-fast', name: 'Opus ⚡ fast'}, {id: 'sonnet', name: 'Sonnet'}, {id: 'haiku', name: 'Haiku'}, ] /** The models a session's agent offers, and the one it is on, from its log. */ function modelsOf(items: LogItem[]): {available: Mode[]; current: string | null} { let available: Mode[] = [] let current: string | null = null for (const it of items) { if (it.kind === 'models') available = it.available ?? [] if (it.kind === 'model') current = it.current ?? null } return {available, current} } /** Its models, for the dropdown: the one it is on; choosing asks it to change. */ function modelModel(s: Hosted) { const {available, current} = modelsOf(live.following === s.id ? followedLog() : []) const model = { get value() { return current }, set value(v: string | null) { if (v && v !== current) void act(`model: ${modeName(available, v)}`, () => api.setModel(s.id, v)) }, } return {available, model} } /** The modes a session's agent offers, and the one it is in, from its log. */ function modesOf(items: LogItem[]): {available: Mode[]; current: string | null} { let available: Mode[] = [] let current: string | null = null for (const it of items) { // Sessions opened before it was renamed still list "Bypass permissions". if (it.kind === 'modes') available = (it.available ?? []).map((x) => (x.id === BYPASS ? {...x, name: 'Trusted'} : x)) if (it.kind === 'mode') current = it.current ?? null } return {available, current} } const modeName = (modes: Mode[], id: string | undefined) => modes.find((x) => x.id === id)?.name ?? id ?? '?' /** A file the agent showed: a picture, a sound or a film, in place; anything else as a link. */ function media(session: string, it: LogItem) { const src = `/v1/hosted/${session}/media/${encodeURIComponent(it.file ?? '')}` const mime = it.mime ?? '' const body = mime.startsWith('image/') ? ( {it.caption ) : mime.startsWith('audio/') ? (