Skip to content
38 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Every agent can have its own computer. A session that needs one wakes it: a home of its own on g1t cloud, one per agent and never shared, where it runs commands, reads and writes files and keeps what it made, with each session working in its own folder under a shared home; after ten idle minutes it sleeps, its home kept as a snapshot and restored when it wakes, and Reset wipes the home while memory and artifacts stay. Its shell and files are abilities with the usual choices, Alone, Alone when asked, Ask first or Never, offered only inside sessions and never to a chat reply; every command shows on the session with its output, and the agent's new Computer tab shows the state, the disk used of the five gigabytes included, the recent commands, and Wake, Put to sleep and Reset. Machine time counts only while it is awake, on the sandbox lines of the ledger that name the agent and who asked, held to the same spend caps as the session; the disk itself costs nothing in this version. The runner gained a long-lived supervisor that answers the computer's requests inside the container, and the runner service a computer per agent that keeps its snapshot in the agent homes bucket when one is attached, and says so when none is. The REST API and the agent tool can read a computer, wake it, put it to sleep and reset it. The agents, abilities, sessions, runners, billing and deploy guides say how it works and what an operator sets up; pinning a computer to your own runner, its browser and take-over come next.1/**
2 * A session's transcript (`agent_session_events`): one statement per entry,
3 * appended in order. Here on its own so that whatever writes an entry
4 * (sessions, cards, the computer) needs nothing else from sessions.ts.
5 */
6import type { AgentComputerCommand, SessionEvent } from "@g1t/contracts";
7
8const iso = () => new Date().toISOString();
9
10/** Appends to a session's transcript. */
11export function eventStatement(db: D1Database, id: string, kind: SessionEvent["kind"], by: string | null, body: string, tool: string | null = null, outcome: string | null = null): D1PreparedStatement {
12 return db
13 .prepare(
14 `INSERT INTO agent_session_events (session_id, seq, kind, by_name, body, tool, outcome, created_at)
15 SELECT ?1, COALESCE(MAX(seq), 0) + 1, ?2, ?3, ?4, ?5, ?6, ?7 FROM agent_session_events WHERE session_id = ?1`,
16 )
17 .bind(id, kind, by, body.slice(0, 20_000), tool, outcome, iso());
18}
19
20/** How much of a command's output a session's transcript keeps: the page shows it folded. */
21const COMMAND_OUTPUT_CHARS = 8_000;
22
23/** `outcome` for a command: `exit 0 · 1.2 s`, with what went wrong. */
24export function commandOutcome(command: Pick<AgentComputerCommand, "exit_code" | "duration_ms" | "timed_out" | "truncated">): string {
25 const seconds = command.duration_ms / 1000;
26 const took = seconds < 10 ? `${seconds.toFixed(1)} s` : seconds < 90 ? `${Math.round(seconds)} s` : `${Math.round(seconds / 60)} min`;
27 return [`exit ${command.exit_code}`, took, command.timed_out ? "timed out" : null, command.truncated ? "output cut" : null].filter(Boolean).join(" · ");
28}
29
30/**
31 * A command the agent ran on its computer, as the transcript keeps it: the
32 * command on the first line, then its output (cut), the directory as
33 * `tool`, and how it ended as `outcome`.
34 */
35export function commandEvent(db: D1Database, sessionId: string, by: string, command: AgentComputerCommand): D1PreparedStatement {
36 const output = command.output.length > COMMAND_OUTPUT_CHARS ? `${command.output.slice(0, COMMAND_OUTPUT_CHARS)}\n[cut: ${command.output.length - COMMAND_OUTPUT_CHARS} more characters]` : command.output;
37 return eventStatement(db, sessionId, "command", by, `${command.cmd.split("\n")[0].slice(0, 500)}\n${output}`, command.cwd, commandOutcome(command));
38}