Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/src/components/machine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const noLinked: Atom.Atom<AsyncResult.AsyncResult<ReadonlyArray<Relay.Machine>,
AsyncResult.success([]),
);

const availabilityOf = (status: ServerStatus): Availability => {
export const availabilityOf = (status: ServerStatus): Availability => {
if (status.kind === "local") return status.server._tag === "Running" ? { kind: "ready" } : { kind: "stopped" };
if (!status.paired) return { kind: "unpaired" };
if (status.mismatch !== null) return { kind: "mismatch", what: status.mismatch.kind };
Expand Down Expand Up @@ -167,7 +167,7 @@ export function useStartMachine() {
}

/** What keeps a machine from being picked, in a few words. */
function useReason(machine: MachineEntry) {
export function useReason(machine: Pick<MachineEntry, "availability">) {
const now = useNowMinute();
const a = machine.availability;
switch (a.kind) {
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/widgets/session/composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Composer, ComposerButton, ComposerSubmit, type Submit } from "@/compone
import { ModelPicker, type ModelRef, ThinkingPicker } from "@/components/model";
import type { Delivery, ThinkingLevel } from "@codeworksh/widget/codework";
import { useSent } from "./display";
import { SessionPlace } from "./place";
import { type Info, Json, type ThreadRef, threadKey, topics } from "./schema";

const decodeReply = Schema.decodeUnknownOption(Json.Reply);
Expand Down Expand Up @@ -166,6 +167,7 @@ export const SessionComposer = memo(function SessionComposer({
onChange={setText}
onSubmit={(submit) => void send(submit)}
placeholder={running ? "Steer the agent, or queue a follow-up…" : "Ask for changes or send a follow-up…"}
tray={<SessionPlace thread={thread} info={info} />}
controls={
<>
<ModelPicker
Expand Down
75 changes: 75 additions & 0 deletions apps/web/src/widgets/session/place.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useAtomValue } from "@effect/atom-react";
import { GitBranchIcon, GitForkIcon, HardDrivesIcon, LaptopIcon } from "@phosphor-icons/react";
import { Option } from "effect";
import { AsyncResult } from "effect/reactivity";

import { availabilityOf, useMachineName, useReason } from "@/components/machine";
import { serversAtom } from "@/kernel/servers";
import { statusAtom } from "../changes/data";
import { projectsAtom } from "./projects";
import type { Info, ThreadRef } from "./schema";

/** The end of a branch tells worktrees apart, so a long one is cut in its middle. */
const TAIL = 7;

/**
* Where the session runs, under its composer: the machine and whether it can be reached, then the
* branch, with a fork for a worktree. A folder without git shows no branch.
*/
export function SessionPlace({ thread, info }: { readonly thread: ThreadRef; readonly info: Info }) {
const servers = useAtomValue(serversAtom);
const projects = useAtomValue(projectsAtom);
const name = useMachineName(info.machineId);
const status = AsyncResult.isSuccess(servers)
? servers.value.find((candidate) => candidate.id === info.machineId)
: undefined;
const availability = status === undefined ? undefined : availabilityOf(status);
const reason = useReason({ availability: availability ?? { kind: "ready" } });
const changes = Option.getOrUndefined(
AsyncResult.value(useAtomValue(statusAtom(`${info.machineId}/${info.spaceId}`))),
);
const branch = changes?.branch ?? changes?.head?.slice(0, 7);
// The sidebar knows its session's space; a fork may sit in another one, so only the main thread asks.
const worktree =
thread.threadId === undefined &&
AsyncResult.isSuccess(projects) &&
projects.value.some((project) =>
project.sessions.some((session) => session.id === thread.sessionId && session.spaceKind === "linked"),
);

const Machine = status?.kind === "local" ? LaptopIcon : HardDrivesIcon;
const Branch = worktree ? GitForkIcon : GitBranchIcon;
const cut = branch !== undefined && branch.length > TAIL * 2 ? branch.length - TAIL : branch?.length;
return (
// Always laid out, so the composer keeps its height while the machine and branch load.
<div className="flex h-6 min-w-0 flex-1 items-center gap-3 text-[12px] whitespace-nowrap text-ink-muted">
{name !== undefined && availability !== undefined && (
<span
title={[name, status?.host, reason ?? "Online"].filter(Boolean).join("\n")}
className="flex min-w-0 items-center gap-1.5"
>
<Machine className="size-3.5 shrink-0" aria-hidden />
<span className="truncate text-ink-secondary">{name}</span>
<span
aria-hidden
className={`size-1.5 shrink-0 rounded-full ${reason === null ? "bg-success" : "bg-ink-muted/60"}`}
/>
<span className={reason === null ? "sr-only" : "shrink-0"}>{reason ?? "Online"}</span>
</span>
)}
{branch !== undefined && (
<span
title={worktree ? `${branch}\nWorktree` : branch}
className="flex max-w-[45%] min-w-0 items-center gap-1.5"
>
<Branch className="size-3 shrink-0" aria-hidden />
{worktree && <span className="sr-only">Worktree, </span>}
<span className="flex min-w-0">
<span className="truncate">{branch.slice(0, cut)}</span>
<span className="shrink-0">{branch.slice(cut)}</span>
</span>
</span>
)}
</div>
);
}