{highlight(command, 'sh')}
) : Object.keys(rest).length ? (
{highlight(JSON.stringify(rest, null, 2), 'json')}
) : null}
{t.output ? {t.output} : {t.output} : null}
Also changes {about.files.length + (about.more ?? 0)} file{about.files.length + (about.more ?? 0) === 1 ? '' : 's'} changed here:
{path}
{f.you.length || f.them.length ? (
{f.you.length ? [here, ' ', places(f.you, both)] : null}
{f.you.length && f.them.length ? ' · ' : null}
{f.them.length ? [{there}, ' ', places(f.them, both)] : null}
) : null}
midas say --re {note.id}
{highlight(input.command, 'sh')}
const file = typeof input.file_path === 'string' ? input.file_path : ''
const ext = file.split('.').pop()?.toLowerCase() ?? ''
// A file it would write: what goes in it, as it will read (Markdown drawn), not as JSON.
if (typeof input.content === 'string')
return ext === 'md' ? (
{highlight(input.content, ext)}
)
// A change to one: the lines that go, and the lines that come.
if (typeof input.old_string === 'string' && typeof input.new_string === 'string')
return (
{input.old_string} : null}
{highlight(input.new_string, ext)}
{highlight(JSON.stringify(rest, null, 2), 'json')} : null
}
/**
* A request to write or change a file, in words: "write docs/x.md", the path
* from its worktree on (where every session's files are; the rest says nothing).
*/
function fileAsk(it: LogItem): string | null {
const path = it.input?.file_path
if (typeof path !== 'string') return null
const verb = typeof it.input?.content === 'string' ? 'write' : typeof it.input?.new_string === 'string' ? 'change' : null
if (!verb) return null
return `${verb} ${path.replace(/^.*\/worktrees\/[^/]+\//, '')}`
}
/** What the person is writing to the open session; kept while they look elsewhere. */
const draft = local({text: ''})
/** Follow the conversation down as it grows, unless the person scrolled up to read. */
let pinned = true
/**
* Until when, just opened, the conversation is put at its end at once as it grows rather
* than glided to: its log comes over the socket after the page is drawn, and pictures
* load after that, so gliding opened a long session at its top and slid all the way
* down. Each growth meanwhile holds it a little longer; the person's own hand ends it.
*/
let landing = 0
const LANDING = 1500
const LANDING_MAX = 8000
let openedAt = 0
const landed = () => (landing = 0)
const HANDS = ['wheel', 'touchstart', 'pointerdown', 'keydown'] as const
/** The Shell's content column scrolls, not the log: that is what follows the conversation down. */
const followDown = {
oncreate: (v: m.VnodeDOM) => {
openedAt = performance.now()
landing = openedAt + LANDING
const el = (v.dom as HTMLElement).closest('.m-shell__content')
for (const h of HANDS) el?.addEventListener(h, landed, {passive: true})
// Opened, it is at its end at once: only what arrives after glides.
stick(v.dom as HTMLElement, true)
// A picture or a film grows the log after it is drawn: follow that too.
const watch = new ResizeObserver(() => stick(v.dom as HTMLElement))
watch.observe(v.dom)
;(v.dom as HTMLElement & {watch?: ResizeObserver}).watch = watch
},
// The observer above sees the log grow, after layout. Measuring here on every redraw (a
// keystroke, a board update) made the browser lay the whole conversation out mid-redraw.
// Only a search hit, which grows nothing, still needs it.
onupdate: (v: m.VnodeDOM) => {
if (jump) stick(v.dom as HTMLElement)
},
onremove: (v: m.VnodeDOM) => {
;(v.dom as HTMLElement & {watch?: ResizeObserver}).watch?.disconnect()
const el = (v.dom as HTMLElement).closest('.m-shell__content')
for (const h of HANDS) el?.removeEventListener(h, landed)
landing = 0
// Its blocks left the page with it: drawn again from nothing when it comes back.
drawn.session = ''
},
}
/** Scrolled up to read while more arrived: a chip says so, and brings the person down to it. */
function showNew(dom: HTMLElement, on: boolean) {
dom.parentElement?.querySelector('.jump-new')?.classList.toggle('is-shown', on)
}
/** To the end of the conversation, gliding. */
function toLatest(e: Event) {
const el = (e.currentTarget as HTMLElement).closest('.m-shell__content')
pinned = true
el?.scrollTo({top: el.scrollHeight, behavior: 'smooth'})
showNew(e.currentTarget as HTMLElement, false)
}
/** The conversation gliding down to its end: the frame it waits on, and where it last put the scroll. */
const glide = {frame: 0, at: 0}
/**
* Down to the end of the conversation, a share of the way each frame. Set in one go, the
* page jumped by a whole message as it came; chasing the end, a reply that streams in
* chunk by chunk keeps sliding up as one movement.
*/
function glideDown(el: HTMLElement) {
if (glide.frame) return
const step = () => {
const gap = el.scrollHeight - el.clientHeight - el.scrollTop
if (!pinned || gap < 1) {
glide.frame = 0
return
}
el.scrollTop += Math.max(1, gap * 0.18)
glide.at = el.scrollTop
glide.frame = requestAnimationFrame(step)
}
glide.frame = requestAnimationFrame(step)
}
/** A block that grew by itself (Typed pacing a reply in), with no redraw of the page: followed down as `stick` would. */
function following(dom: HTMLElement) {
const el = dom.closest('.m-shell__content') as HTMLElement | null
if (!el || !pinned) return
if (reduced() || performance.now() < landing) el.scrollTop = el.scrollHeight
else glideDown(el)
}
function stick(dom: HTMLElement, at = false) {
const el = (dom.closest('.m-shell__content') as HTMLElement | null) ?? dom
el.onscroll = () => {
// The glide's own scrolling, short of the end while it moves: still following.
if (glide.frame && el.scrollTop >= glide.at - 1) return
pinned = el.scrollHeight - el.scrollTop - el.clientHeight < 80
if (pinned) showNew(dom, false)
}
const grew = el.scrollHeight > Number(el.dataset.height ?? 0) + 8
el.dataset.height = String(el.scrollHeight)
if (!pinned && grew) showNew(dom, true)
if (jump && jump.id === live.following && live.logNext >= jump.n) {
// The last block at or before the item: an agent's text is many items in one.
const at = [...dom.querySelectorAll{s.branch} keeps its work{s.finished ? ': reopen it to go on.' : '.'}
{text.split('\n').map((l) => (
{l + '\n'}
))}
)
}
function filesTab(s: Hosted): m.Children {
const r = sheet.filesFor === s.id ? sheet.files : null
const with_ = shared(s)
const sharedBy = (f: string) => with_.filter((o) => o.files.includes(f))
if (!r) return Asking the hub…
const add = r.files.reduce((n, f) => n + f.add, 0) const del = r.files.reduce((n, f) => n + f.del, 0) return [ r.files.length ? ({r.at ? 'Its branch changes nothing yet.' : 'Nothing reported yet: the runner says what its branch changes at the end of each turn.'}
), r.files.length ? ({ended(s) ? `Its branch ${s.branch} keeps its work; the message box reopens it.` : 'Ending keeps its branch, and it can be reopened. A session finishes on your answer to "Shall it land?", on Mark done, or by itself once idle 15 minutes with nothing to land. Model, mode and context are in the message box.'}
, ] } /** The sheet itself, over the conversation while a tab is open. */ function sessionSheet(s: Hosted): m.Children { if (!sheet.tab) return null const n = fileCount(s) // To live while it is on its way; once it is not, the tab it was on falls to About. const way = !!journeyOf(s) const tab = sheet.tab === 'live' && !way ? 'about' : sheet.tab return (None at work. Start one with +.
)}{agentName(fresh.agent)} in a folder of its own, a worktree of each project in it, on a branch of its own off {freshProject() ? `${freshProject()!.name}'s main` : several() ? "the main of each project it works in: it adds those the task needs, one or several, or none for a question" : 'main'}.
{live.loaded ? ( <> No session {id}: it may have been deleted. Start a new one > ) : ( `Loading session ${id}…` )}