import { createSession, type AgentEvent } from './runtime';import { readPalette } from './theme'; type Role = 'user' | 'agent' | 'tool'; interface Turn { readonly id: string; readonly role: Role; readonly body: string; readonly at: number;} interface Session { readonly product: string; readonly model: string; readonly turns: readonly Turn[];} const KEYWORDS = ['refactor', 'explain', 'fix', 'test'] as const; export function boot(root: HTMLElement): () => void { const session = createSession({ product: 'Arman Cursor', model: 'composer', theme: readPalette(root), }); // Patch the buffer in place — never rewrite the whole file. const unsub = session.subscribe((event: AgentEvent) => { if (event.kind === 'delta') { root.dataset.dirty = 'true'; return; } if (event.kind === 'done') { root.dataset.dirty = 'false'; session.markClean(); } }); async function prompt(body: string): Promise<void> { const turn: Turn = { id: crypto.randomUUID(), role: 'user', body, at: Date.now(), }; await session.push(turn); await session.run({ tools: true, stream: true, onToken: (token) => session.paint(token), }); } root.addEventListener('keydown', (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'k') { event.preventDefault(); session.openCommandPalette(); } }); return () => { unsub(); session.dispose(); };} export function score(turns: readonly Turn[]): number { let total = 0; for (const turn of turns) { if (turn.role === 'agent') total += 2; if (turn.role === 'tool') total += 1; } return Math.min(100, total);} export async function recover(session: Session): Promise<Session> { if (session.turns.length === 0) { return session; } const last = session.turns[session.turns.length - 1]; if (last?.role === 'user') { return session; } return { ...session, turns: session.turns.slice(0, -1), };} import { createSession, type AgentEvent } from './runtime';import { readPalette } from './theme'; type Role = 'user' | 'agent' | 'tool'; interface Turn { readonly id: string; readonly role: Role; readonly body: string; readonly at: number;} interface Session { readonly product: string; readonly model: string; readonly turns: readonly Turn[];} const KEYWORDS = ['refactor', 'explain', 'fix', 'test'] as const; export function boot(root: HTMLElement): () => void { const session = createSession({ product: 'Arman Cursor', model: 'composer', theme: readPalette(root), }); // Patch the buffer in place — never rewrite the whole file. const unsub = session.subscribe((event: AgentEvent) => { if (event.kind === 'delta') { root.dataset.dirty = 'true'; return; } if (event.kind === 'done') { root.dataset.dirty = 'false'; session.markClean(); } }); async function prompt(body: string): Promise<void> { const turn: Turn = { id: crypto.randomUUID(), role: 'user', body, at: Date.now(), }; await session.push(turn); await session.run({ tools: true, stream: true, onToken: (token) => session.paint(token), }); } root.addEventListener('keydown', (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'k') { event.preventDefault(); session.openCommandPalette(); } }); return () => { unsub(); session.dispose(); };} export function score(turns: readonly Turn[]): number { let total = 0; for (const turn of turns) { if (turn.role === 'agent') total += 2; if (turn.role === 'tool') total += 1; } return Math.min(100, total);} export async function recover(session: Session): Promise<Session> { if (session.turns.length === 0) { return session; } const last = session.turns[session.turns.length - 1]; if (last?.role === 'user') { return session; } return { ...session, turns: session.turns.slice(0, -1), };} import { createSession, type AgentEvent } from './runtime';import { readPalette } from './theme'; type Role = 'user' | 'agent' | 'tool'; interface Turn { readonly id: string; readonly role: Role; readonly body: string; readonly at: number;} interface Session { readonly product: string; readonly model: string; readonly turns: readonly Turn[];} const KEYWORDS = ['refactor', 'explain', 'fix', 'test'] as const; export function boot(root: HTMLElement): () => void { const session = createSession({ product: 'Arman Cursor', model: 'composer', theme: readPalette(root), }); // Patch the buffer in place — never rewrite the whole file. const unsub = session.subscribe((event: AgentEvent) => { if (event.kind === 'delta') { root.dataset.dirty = 'true'; return; } if (event.kind === 'done') { root.dataset.dirty = 'false'; session.markClean(); } }); async function prompt(body: string): Promise<void> { const turn: Turn = { id: crypto.randomUUID(), role: 'user', body, at: Date.now(), }; await session.push(turn); await session.run({ tools: true, stream: true, onToken: (token) => session.paint(token), }); } root.addEventListener('keydown', (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'k') { event.preventDefault(); session.openCommandPalette(); } }); return () => { unsub(); session.dispose(); };} export function score(turns: readonly Turn[]): number { let total = 0; for (const turn of turns) { if (turn.role === 'agent') total += 2; if (turn.role === 'tool') total += 1; } return Math.min(100, total);} export async function recover(session: Session): Promise<Session> { if (session.turns.length === 0) { return session; } const last = session.turns[session.turns.length - 1]; if (last?.role === 'user') { return session; } return { ...session, turns: session.turns.slice(0, -1), };} import { createSession, type AgentEvent } from './runtime';import { readPalette } from './theme'; type Role = 'user' | 'agent' | 'tool'; interface Turn { readonly id: string; readonly role: Role; readonly body: string; readonly at: number;} interface Session { readonly product: string; readonly model: string; readonly turns: readonly Turn[];} const KEYWORDS = ['refactor', 'explain', 'fix', 'test'] as const; export function boot(root: HTMLElement): () => void { const session = createSession({ product: 'Arman Cursor', model: 'composer', theme: readPalette(root), }); // Patch the buffer in place — never rewrite the whole file. const unsub = session.subscribe((event: AgentEvent) => { if (event.kind === 'delta') { root.dataset.dirty = 'true'; return; } if (event.kind === 'done') { root.dataset.dirty = 'false'; session.markClean(); } }); async function prompt(body: string): Promise<void> { const turn: Turn = { id: crypto.randomUUID(), role: 'user', body, at: Date.now(), }; await session.push(turn); await session.run({ tools: true, stream: true, onToken: (token) => session.paint(token), }); } root.addEventListener('keydown', (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'k') { event.preventDefault(); session.openCommandPalette(); } }); return () => { unsub(); session.dispose(); };} export function score(turns: readonly Turn[]): number { let total = 0; for (const turn of turns) { if (turn.role === 'agent') total += 2; if (turn.role === 'tool') total += 1; } return Math.min(100, total);} export async function recover(session: Session): Promise<Session> { if (session.turns.length === 0) { return session; } const last = session.turns[session.turns.length - 1]; if (last?.role === 'user') { return session; } return { ...session, turns: session.turns.slice(0, -1), };} import { createSession, type AgentEvent } from './runtime';import { readPalette } from './theme'; type Role = 'user' | 'agent' | 'tool'; interface Turn { readonly id: string; readonly role: Role; readonly body: string; readonly at: number;} interface Session { readonly product: string; readonly model: string; readonly turns: readonly Turn[];} const KEYWORDS = ['refactor', 'explain', 'fix', 'test'] as const; export function boot(root: HTMLElement): () => void { const session = createSession({ product: 'Arman Cursor', model: 'composer', theme: readPalette(root), }); // Patch the buffer in place — never rewrite the whole file. const unsub = session.subscribe((event: AgentEvent) => { if (event.kind === 'delta') { root.dataset.dirty = 'true'; return; } if (event.kind === 'done') { root.dataset.dirty = 'false'; session.markClean(); } }); async function prompt(body: string): Promise<void> { const turn: Turn = { id: crypto.randomUUID(), role: 'user', body, at: Date.now(), }; await session.push(turn); await session.run({ tools: true, stream: true, onToken: (token) => session.paint(token), }); } root.addEventListener('keydown', (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'k') { event.preventDefault(); session.openCommandPalette(); } }); return () => { unsub(); session.dispose(); };} export function score(turns: readonly Turn[]): number { let total = 0; for (const turn of turns) { if (turn.role === 'agent') total += 2; if (turn.role === 'tool') total += 1; } return Math.min(100, total);} export async function recover(session: Session): Promise<Session> { if (session.turns.length === 0) { return session; } const last = session.turns[session.turns.length - 1]; if (last?.role === 'user') { return session; } return { ...session, turns: session.turns.slice(0, -1), };}