diff --git a/labs/teammates/README.md b/labs/teammates/README.md index 7ff20bb21b..b0064613df 100644 --- a/labs/teammates/README.md +++ b/labs/teammates/README.md @@ -5,8 +5,8 @@ the workforce package. It is one half of the evidence that the same package piec apps: an app adds only configuration, React UI and a few small flows, and anything else it needs is a gap filed against the package. -- **Left:** the workers, lead, researcher and writer. Each row is a worker with an ongoing role, - never a list of sessions. A row shows what the worker is doing and how many new entries its +- **Left:** the workers, lead, researcher, writer and coder. Each row is a worker with an ongoing + role, never a list of sessions. A row shows what the worker is doing and how many new entries its conversation has since you last looked. - **Center:** the chosen worker's one conversation. It goes on for weeks. A divider marks where the turns the worker reads word for word begin; it reads *summarized* only when the earlier turns were @@ -19,6 +19,13 @@ shows in lead's conversation and the message lands in researcher's. The reply la conversation under researcher's name. A message never interrupts the turn you are in: while lead is answering you, researcher's reply shows as a pending line, and lead reads it right after. +coder is different: it takes tasks only, so it has no conversation and you can't message it. Ask +lead for a code change and lead files a task for coder, which runs it through Claude Code in lead's +project. A card in lead's conversation shows the task and opens to its run, and the result lands +as a line from coder. Talking to a worker never needs a project. The first time a job needs files, +the card asks you to pick one for lead; nothing runs until you do, and the pick sticks to lead. +Picking one from the header works too. + Scope is core messaging and session management. There are no group chats, no new-chat button and no session list. The design and the decisions behind it are in the [spec](../../specs/issues/FIX-2154/SPEC.md). @@ -36,6 +43,10 @@ lead answers and messages researcher. Before researcher replies, send lead a sec shows as pending, then lands after lead's answer. lead's conversation already runs past the 50-turn history window, so the divider is in view. +Then ask lead *"Have coder fix the typo in the README's first line."* The task card asks for a +project. Pick `relay`: lead files the task again, coder's run shows its steps, and the result lands +in lead's conversation. + After wiring, the lab runs against a real model and a durable store: ```bash @@ -43,7 +54,9 @@ fsdev dev --app @flow-state-dev/teammates ``` Wiring adds the host file, which composes `@flow-state-dev/memory` into each worker's flow: the -capability in `uses` to read it, and `afterAnswer: mem.captureFromItems` to record each turn. +capability in `uses` to read it, and `afterAnswer: mem.captureFromItems` to record each turn. It +also adds the lab's one small flow: coder's worker flow, one `harnessManager` per harness over +`projectWorkspace()`, routing each task by the worker's `harness` setting. ## Fixtures @@ -57,6 +70,9 @@ names the package call it stands for, and until wiring they run on `src/fixtures | The pending line, joined to the conversation by message id | G2: a received message as its own item, carrying its id (an ask of FIX-2070) | | Workers messaging each other, the Talk panel | `sendMessage`, `receive` and the message log, as FIX-2070 ships them | | The worker list, sending, the conversation, busy status | `roster()`, `ensureWorkerSession`, `respond`, session items, `listSessionRequests` | +| A worker's project, and picking it | FIX-2161's `setWorkProject` and the `workProjectId` it writes on the worker's default conversation | +| Task cards, the refusal for want of a project | the conversation board's rows (`listTasks_tasks`), and `projectWorkspace()`'s `no-project` refusal | +| coder's runs | the task row's `run` link, followed with `followRequest` and `useSession`, on a harness picked by coder's `harness` setting | ## What this app adds @@ -66,9 +82,9 @@ and on a flow over 200 lines; `--wired` also fails while a fixture is left. | Kind | Files | Lines | |---|---:|---:| -| Configuration | 13 | 253 | -| React UI | 14 | 822 | +| Configuration | 14 | 279 | +| React UI | 16 | 1108 | | Small flows | 0 | 0 | -| Fixtures (deleted at wiring) | 1 | 267 | -| Checks (not app code) | 3 | 275 | +| Fixtures (deleted at wiring) | 1 | 353 | +| Checks (not app code) | 3 | 340 | diff --git a/labs/teammates/src/App.tsx b/labs/teammates/src/App.tsx index 6e9388ae7c..e904923bfa 100644 --- a/labs/teammates/src/App.tsx +++ b/labs/teammates/src/App.tsx @@ -1,16 +1,19 @@ import { useEffect, useState } from "react"; -import type { LabAdapter, WorkerRow } from "./adapter"; +import type { LabAdapter, ProjectRow, WorkerRow } from "./adapter"; import { Conversation } from "./components/Conversation"; +import { Runs } from "./components/Runs"; import { TalkPanel } from "./components/TalkPanel"; import { WorkersList } from "./components/WorkersList"; /** * The screen: the workers on the left, the chosen worker's one conversation - * in the center, and its talk with the other workers on the right. The app - * opens on the first worker on the roster. + * in the center, and its talk with the other workers on the right. A worker + * that takes tasks only has no conversation; the center shows its runs. The + * app opens on the first worker on the roster. */ export function App({ adapter }: { adapter: LabAdapter }) { const [workers, setWorkers] = useState([]); + const [projects, setProjects] = useState([]); const [sessions, setSessions] = useState>({}); const [selected, setSelected] = useState(); const [talkOpen, setTalkOpen] = useState(true); @@ -18,11 +21,13 @@ export function App({ adapter }: { adapter: LabAdapter }) { useEffect(() => { let live = true; void (async () => { - const roster = await adapter.listWorkers(); - const ids = await Promise.all(roster.map((w) => adapter.openConversation(w.id))); + const [roster, projectRows] = await Promise.all([adapter.listWorkers(), adapter.listProjects()]); + const talking = roster.filter((w) => !w.takesTasks); + const ids = await Promise.all(talking.map((w) => adapter.openConversation(w.id))); if (!live) return; setWorkers(roster); - setSessions(Object.fromEntries(roster.map((w, i) => [w.id, ids[i]]))); + setProjects(projectRows); + setSessions(Object.fromEntries(talking.map((w, i) => [w.id, ids[i]]))); setSelected((current) => current ?? roster[0]?.id); })(); return () => { @@ -39,11 +44,14 @@ export function App({ adapter }: { adapter: LabAdapter }) { style={{ gridTemplateColumns: talkOpen ? "15rem minmax(0,1fr) 18rem" : "15rem minmax(0,1fr)" }} > - {worker && sessionId ? ( + {worker?.takesTasks ? ( + + ) : worker && sessionId ? ( setTalkOpen((open) => !open)} diff --git a/labs/teammates/src/adapter.ts b/labs/teammates/src/adapter.ts index 5621c47b7c..10aaa911cb 100644 --- a/labs/teammates/src/adapter.ts +++ b/labs/teammates/src/adapter.ts @@ -16,6 +16,11 @@ * | `watchTalk` | the user's message log, as `sendMessage` and `receive` write its rows | * | `watchActivity` | `listSessionRequests` on the worker's conversation | * | `watchWindow` | the mark the history window leaves where the turns read word for word begin | + * | `listProjects` | the user's projects, as the workforce client lists them | + * | `watchWorkProject` | the worker's `workProjectId`, on its default conversation (FIX-2161) | + * | `setWorkProject` | FIX-2161's `setWorkProject(worker, project)` | + * | `watchTasks` | the conversation board's rows (`listTasks_tasks`) | + * | `watchRun` | the task row's `run` link, followed (`followRequest`, `useSession`) | */ import { createFixtureLab } from "./fixtures"; @@ -30,6 +35,38 @@ export interface WorkerRow { name: string; /** Its `WORKER.md` description: the ongoing role. */ role: string; + /** It takes tasks only: it has no conversation, and work reaches it as a task. */ + takesTasks?: boolean; + /** The coding harness its tasks run through, from its `WORKER.md` `harness` setting. */ + harness?: string; +} + +/** One of the user's projects: where a worker's runs get their files. */ +export interface ProjectRow { + id: string; + name: string; +} + +/** + * A task a conversation filed for a worker that takes tasks, from the board's + * row. `needs-project` is a run refused `no-project` before any file existed. + */ +export interface BoardTask { + id: string; + /** The worker it was filed for. */ + to: string; + title: string; + status: "needs-project" | "running" | "done"; + /** The project its run works in; none when it was refused. */ + project?: string; + /** What the run reported when it ended. */ + result?: string; +} + +/** One step of a task's run, as the harness reported it. */ +export interface RunStep { + id: string; + text: string; } /** One entry of a worker's conversation, in the order it happened. */ @@ -39,7 +76,11 @@ export type ConversationEntry = /** The worker messaged another worker (`sendMessage`). */ | { kind: "sent"; id: string; messageId: string; to: string; text: string } /** A message another worker sent, as the `receive` turn that read it. */ - | { kind: "received"; id: string; messageId: string; from: string; text: string; inReplyTo?: string }; + | { kind: "received"; id: string; messageId: string; from: string; text: string; inReplyTo?: string } + /** The worker filed a task; the card reads the board's row by its id. */ + | { kind: "task"; id: string; taskId: string } + /** A task it filed ended, as a line under the name of the worker that ran it. */ + | { kind: "result"; id: string; taskId: string; from: string; text: string }; /** What a conversation shows now. */ export interface ConversationView { @@ -88,6 +129,14 @@ export interface LabAdapter { watchActivity(worker: string, onChange: (activity: Activity) => void): Unsubscribe; /** `undefined` while the whole conversation is inside the window. */ watchWindow(sessionId: string, onChange: (mark: WindowMark | undefined) => void): Unsubscribe; + listProjects(): Promise; + /** The project `worker`'s runs work in; `undefined` until one is picked. */ + watchWorkProject(worker: string, onChange: (project: string | undefined) => void): Unsubscribe; + setWorkProject(worker: string, project: string): Promise; + /** The tasks a conversation filed, oldest first. */ + watchTasks(sessionId: string, onChange: (tasks: BoardTask[]) => void): Unsubscribe; + /** A task's run, read only: the worker that runs it takes no messages. */ + watchRun(taskId: string, onChange: (steps: RunStep[]) => void): Unsubscribe; } /** The adapter the app runs on. */ diff --git a/labs/teammates/src/components/Conversation.tsx b/labs/teammates/src/components/Conversation.tsx index 1bdfe914fe..79713af9bf 100644 --- a/labs/teammates/src/components/Conversation.tsx +++ b/labs/teammates/src/components/Conversation.tsx @@ -1,20 +1,24 @@ import { Fragment, useEffect, useRef } from "react"; -import type { LabAdapter, WorkerRow } from "../adapter"; +import type { LabAdapter, ProjectRow, WorkerRow } from "../adapter"; import { pendingFor } from "../lib/talk"; import { useWatch } from "../lib/use-watch"; import { cn } from "../lib/utils"; import { Composer } from "./Composer"; import { Entry } from "./Entry"; +import { TaskCard } from "./TaskCard"; /** * The center: the worker's one conversation. A divider marks where the turns * the worker reads word for word begin. A message another worker sent that - * waits for the current answer shows as a pending line until it lands. + * waits for the current answer shows as a pending line until it lands. The + * header carries the worker's project: none is needed to talk, and the first + * job that needs files asks for one on its task card. */ export function Conversation({ adapter, worker, sessionId, + projects, nameOf, talkOpen, onToggleTalk, @@ -22,6 +26,7 @@ export function Conversation({ adapter: LabAdapter; worker: WorkerRow; sessionId: string; + projects: ProjectRow[]; nameOf: (id: string) => string; talkOpen: boolean; onToggleTalk: () => void; @@ -32,18 +37,49 @@ export function Conversation({ const entries = view?.entries ?? []; const running = view?.running ?? false; const pending = pendingFor(worker.id, talk, entries); + const tasks = useWatch(adapter.watchTasks, sessionId) ?? []; + const workProject = useWatch(adapter.watchWorkProject, worker.id); + // A job refused for want of a project waits on the pick, from its card or the header. + const waiting = !workProject && tasks.some((t) => t.status === "needs-project"); + // The pick is stored on the worker, then said to it as your line, so it files the job again. + const pick = async (project: string) => { + await adapter.setWorkProject(worker.id, project); + await adapter.send(sessionId, `Work in ${projects.find((p) => p.id === project)?.name ?? project}.`); + }; const end = useRef(null); useEffect(() => { end.current?.scrollIntoView?.({ block: "end" }); }, [entries.length, running, pending.length, sessionId]); + // A card shows once the board's row has arrived. + const taskTile = (taskId: string) => { + const task = tasks.find((t) => t.id === taskId); + if (!task) return null; + return void pick(p)} />; + }; + const markAt = mark ? entries.findIndex((e) => e.id === mark.firstVerbatimEntryId) : -1; return (

{worker.name}

{worker.role} + {running ? ( working @@ -75,7 +111,11 @@ export function Conversation({ ) : null}
= markAt ? "true" : "false"}> - + {entry.kind === "task" ? ( + taskTile(entry.taskId) + ) : ( + + )}
))} diff --git a/labs/teammates/src/components/Entry.tsx b/labs/teammates/src/components/Entry.tsx index 2c9d71a954..186888dbce 100644 --- a/labs/teammates/src/components/Entry.tsx +++ b/labs/teammates/src/components/Entry.tsx @@ -5,8 +5,8 @@ import { cn } from "../lib/utils"; /** * One entry of a conversation. Your lines sit on the right; the worker's * answers on the left. A message the worker sent another worker is a one-line - * card that opens to its full text; a message it received lands under the - * sender's name. + * card that opens to its full text; a message it received, or a task it + * filed coming back, lands under the sender's name. */ export function Entry({ entry, workerName, nameOf }: { entry: ConversationEntry; workerName: string; nameOf: (id: string) => string }) { switch (entry.kind) { @@ -41,6 +41,16 @@ export function Entry({ entry, workerName, nameOf }: { entry: ConversationEntry;

{entry.text}

); + case "result": + return ( +
+
← {nameOf(entry.from)} · task done
+

{entry.text}

+
+ ); + case "task": + // Drawn by the conversation, from the board's row. + return null; } } diff --git a/labs/teammates/src/components/Runs.tsx b/labs/teammates/src/components/Runs.tsx new file mode 100644 index 0000000000..157964ec2f --- /dev/null +++ b/labs/teammates/src/components/Runs.tsx @@ -0,0 +1,70 @@ +import type { LabAdapter, ProjectRow, WorkerRow } from "../adapter"; +import { useWatch } from "../lib/use-watch"; +import { TaskCard } from "./TaskCard"; + +/** + * The center, for a worker that takes tasks only: its runs, read only. It has + * no conversation and takes no messages, so there is no composer; work + * reaches it as a task another worker files. + */ +export function Runs({ + adapter, + worker, + workers, + sessions, + projects, + nameOf, +}: { + adapter: LabAdapter; + worker: WorkerRow; + workers: WorkerRow[]; + sessions: Record; + projects: ProjectRow[]; + nameOf: (id: string) => string; +}) { + return ( +
+
+

{worker.name}

+ {worker.role} + takes tasks · {worker.harness} +
+
+
+

+ {worker.name} takes tasks only, so it has no conversation. Ask another worker to hand it a job; each run shows here and on the card in that + conversation. +

+ {workers + .filter((w) => sessions[w.id]) + .map((w) => ( + + ))} +
+
+
+ ); +} + +/** The tasks one conversation filed for `runner`. */ +function FiledBy({ + adapter, + filer, + sessionId, + runner, + projects, + nameOf, +}: { + adapter: LabAdapter; + filer: WorkerRow; + sessionId: string; + runner: string; + projects: ProjectRow[]; + nameOf: (id: string) => string; +}) { + const tasks = (useWatch(adapter.watchTasks, sessionId) ?? []).filter((t) => t.to === runner); + const workProject = useWatch(adapter.watchWorkProject, filer.id); + return tasks.map((t) => ( + + )); +} diff --git a/labs/teammates/src/components/TaskCard.tsx b/labs/teammates/src/components/TaskCard.tsx new file mode 100644 index 0000000000..50309405bf --- /dev/null +++ b/labs/teammates/src/components/TaskCard.tsx @@ -0,0 +1,107 @@ +import { useState } from "react"; +import type { LabAdapter, ProjectRow, BoardTask } from "../adapter"; +import { useWatch } from "../lib/use-watch"; +import { cn } from "../lib/utils"; + +/** + * A task a conversation filed for a worker that takes tasks: one line with + * what it is and where it runs, opening to the run, read only. A run refused + * for want of a project asks for one on the card; picking it is the only + * thing that starts a run. + */ +export function TaskCard({ + adapter, + task, + filer, + workProject, + projects, + nameOf, + onPick, + defaultOpen = false, +}: { + adapter: LabAdapter; + task: BoardTask; + /** The worker whose conversation filed it. */ + filer: string; + /** The filer's project, once picked. */ + workProject: string | undefined; + projects: ProjectRow[]; + nameOf: (id: string) => string; + /** Present where a pick can be made: the filer's own conversation. */ + onPick?: (project: string) => void; + defaultOpen?: boolean; +}) { + const [open, setOpen] = useState(defaultOpen); + const steps = useWatch(adapter.watchRun, open ? task.id : undefined) ?? []; + const to = nameOf(task.to); + const status = + task.status === "needs-project" + ? workProject + ? "refused · no project" + : "needs a project" + : task.status === "running" + ? `running in ${task.project}` + : `done in ${task.project}`; + const asking = task.status === "needs-project" && !workProject && onPick; + return ( +
+ + {asking ? : null} + {open ? ( +
    + {task.status === "needs-project" ?
  1. No run started: {filer} had no project.
  2. : null} + {steps.map((s) => ( +
  3. · {s.text}
  4. + ))} + {task.result ?
  5. {task.result}
  6. : null} +
+ ) : null} +
+ ); +} + +/** The ask for a project, the first time a job needs files. */ +function ProjectPrompt({ filer, to, projects, onPick }: { filer: string; to: string; projects: ProjectRow[]; onPick: (project: string) => void }) { + const [project, setProject] = useState(projects[0]?.id ?? ""); + return ( +
+ + {to} needs a project to work in. Pick one for {filer}; it sticks to {filer}. + + + +
+ ); +} diff --git a/labs/teammates/src/components/WorkersList.tsx b/labs/teammates/src/components/WorkersList.tsx index d430ab9629..fe8cf4d57e 100644 --- a/labs/teammates/src/components/WorkersList.tsx +++ b/labs/teammates/src/components/WorkersList.tsx @@ -84,7 +84,9 @@ function WorkerItem({ const unread = count !== undefined && seen !== undefined ? Math.max(0, count - seen) : 0; const waiting = waitingOn(worker.id, talk); - const status = activity?.running + const status = worker.takesTasks + ? `${activity?.running ? "running" : "tasks"} · ${worker.harness}` + : activity?.running ? "working" : waiting.length > 0 ? `waiting on ${waiting.map(nameOf).join(", ")}` diff --git a/labs/teammates/src/fixtures.ts b/labs/teammates/src/fixtures.ts index a8b47b8cc1..ba82e84350 100644 --- a/labs/teammates/src/fixtures.ts +++ b/labs/teammates/src/fixtures.ts @@ -6,13 +6,16 @@ * pieces it needs exist. It proves the UI only. The README lists which gap * each part stands for. * - * Three workers, each with one conversation. Your first ask to lead makes it - * message researcher; researcher looks the fact up and replies. Each worker + * Three workers, each with one conversation, and coder, which takes tasks + * only. Your first ask to lead makes it message researcher; researcher looks + * the fact up and replies. Ask lead to have coder fix something and lead files + * a task: with no project picked for lead, the run is refused before it + * touches a file, and once you pick one lead files it again. Each worker * answers one request at a time: a line you send, or a message from another * worker, waits while the worker is answering, and runs when it is done. * lead's conversation starts past the 50-turn history window. */ -import type { ConversationEntry, LabAdapter, TalkRow, Unsubscribe, WindowMark, WorkerRow } from "./adapter"; +import type { ConversationEntry, LabAdapter, ProjectRow, RunStep, TalkRow, BoardTask, Unsubscribe, WindowMark, WorkerRow } from "./adapter"; /** How the fixtures keep time, and what they stand in for. */ export interface FixtureOptions { @@ -32,12 +35,21 @@ const ROSTER: WorkerRow[] = [ { id: "teammates.lead", name: "lead", role: "Plans the launch with you, and asks the other workers when it needs a fact or a draft." }, { id: "teammates.researcher", name: "researcher", role: "Finds facts for the team, and replies to whoever asked." }, { id: "teammates.writer", name: "writer", role: "Drafts and tightens copy when you or another worker asks." }, + { id: "teammates.coder", name: "coder", role: "Makes code changes lead hands it, in lead's project.", takesTasks: true, harness: "Claude Code" }, +]; +const PROJECTS: ProjectRow[] = [ + { id: "relay", name: "relay" }, + { id: "relay-site", name: "relay-site" }, ]; const LEAD = "teammates.lead"; const RESEARCHER = "teammates.researcher"; const WRITER = "teammates.writer"; +const CODER = "teammates.coder"; + +type Job = { kind: "user"; entryId: string; text: string } | { kind: "receive"; message: TalkRow } | { kind: "result"; task: BoardTask }; -type Job = { kind: "user"; entryId: string; text: string } | { kind: "receive"; message: TalkRow }; +/** A board row, and the conversation that filed it. */ +type FixtureTask = BoardTask & { sessionId: string }; interface FixtureWorker { row: WorkerRow; @@ -79,6 +91,11 @@ export function createFixtureLab(options: FixtureOptions = {}): LabAdapter { return found; }; const bySession = (sessionId: string) => [...workers.values()].find((w) => w.sessionId === sessionId); + const workProjects = new Map(); + let tasks: FixtureTask[] = []; + const runs = new Map(); + /** Refused tasks lead has filed again. */ + const refiled = new Set(); const notify = () => { for (const listener of [...listeners]) listener(); @@ -107,7 +124,41 @@ export function createFixtureLab(options: FixtureOptions = {}): LabAdapter { startNext(recipient); }; + const updateTask = (id: string, patch: Partial) => { + tasks = tasks.map((t) => (t.id === id ? { ...t, ...patch } : t)); + notify(); + }; + const step = (taskId: string, text: string): Step[1] => () => { + runs.set(taskId, [...(runs.get(taskId) ?? []), { id: nextId("step"), text }]); + notify(); + }; + + /** `createTask` for coder: a card in the filer's conversation. The run gets the filer's project, or is refused before it starts. */ + const fileTask = (w: FixtureWorker, title: string): Step[1] => () => { + const project = workProjects.get(w.row.id); + const task: FixtureTask = { id: nextId("t"), to: CODER, title, status: project ? "running" : "needs-project", project, sessionId: w.sessionId }; + tasks = [...tasks, task]; + push(w, { kind: "task", id: nextId("k"), taskId: task.id }); + if (!project) return; + const result = "Fixed the typo in README.md, line 1."; + let at = 0; + for (const [delay, run] of [ + [600, step(task.id, "Read README.md")], + [1200, step(task.id, 'Edited line 1: "Relay keps" → "Relay keeps"')], + [800, step(task.id, "Ran the docs check: passed")], + [400, () => { + updateTask(task.id, { status: "done", result }); + w.queue.push({ kind: "result", task: { ...task, status: "done", result } }); + startNext(w); + }], + ] as Step[]) { + at += delay; + setTimeout(run, at * speed); + } + }; + const script = (w: FixtureWorker, job: Job): Step[] => { + if (job.kind === "result") return [[900, say(w, `coder is done: "${job.task.result}" That's in ${job.task.project}.`)]]; if (job.kind === "receive") { const { message } = job; const from = worker(message.from).row.name; @@ -117,6 +168,15 @@ export function createFixtureLab(options: FixtureOptions = {}): LabAdapter { } return [[700, say(w, "On it.")], [2000, sendMessage(w, message.from, "Done. It's in the doc.", message.id)]]; } + if (w.row.id === LEAD && /\bcoder\b/i.test(job.text)) { + return [[800, say(w, "Handing it to coder.")], [400, fileTask(w, "Fix the typo in the README's first line")]]; + } + const project = workProjects.get(w.row.id); + const refused = tasks.find((t) => t.sessionId === w.sessionId && t.status === "needs-project" && !refiled.has(t.id)); + if (w.row.id === LEAD && refused && project) { + refiled.add(refused.id); + return [[600, say(w, `Filing it again, in ${project}.`)], [300, fileTask(w, refused.title)]]; + } if (w.row.id === LEAD && !log.some((m) => m.from === LEAD && m.to === RESEARCHER)) { return [ [800, say(w, "Asking researcher now. An outline:\n1 · the problem\n2 · what ships\n3 · how to try it")], @@ -135,6 +195,9 @@ export function createFixtureLab(options: FixtureOptions = {}): LabAdapter { w.lastActiveAt = now(); if (job.kind === "user") { w.entries = w.entries.map((e) => (e.id === job.entryId && e.kind === "user" ? { ...e, queued: false } : e)); + } else if (job.kind === "result") { + const { task } = job; + w.entries = [...w.entries, { kind: "result", id: nextId("r"), taskId: task.id, from: task.to, text: task.result ?? "" }]; } else { const { message } = job; w.entries = [...w.entries, { kind: "received", id: nextId("r"), messageId: message.id, from: message.from, text: message.text, inReplyTo: message.inReplyTo }]; @@ -249,7 +312,9 @@ export function createFixtureLab(options: FixtureOptions = {}): LabAdapter { watchActivity(workerId, onChange) { return watch(() => { const w = worker(workerId); - onChange({ running: w.running, lastActiveAt: w.lastActiveAt }); + // A worker that takes tasks is busy while one of its runs is. + const running = w.row.takesTasks ? tasks.some((t) => t.to === workerId && t.status === "running") : w.running; + onChange({ running, lastActiveAt: w.lastActiveAt }); }); }, @@ -263,5 +328,26 @@ export function createFixtureLab(options: FixtureOptions = {}): LabAdapter { onChange(mark); }); }, + + async listProjects() { + return PROJECTS; + }, + + watchWorkProject(workerId, onChange) { + return watch(() => onChange(workProjects.get(workerId))); + }, + + async setWorkProject(workerId, project) { + workProjects.set(workerId, project); + notify(); + }, + + watchTasks(sessionId, onChange) { + return watch(() => onChange(tasks.filter((t) => t.sessionId === sessionId).map(({ sessionId: _, ...card }) => card))); + }, + + watchRun(taskId, onChange) { + return watch(() => onChange(runs.get(taskId) ?? [])); + }, }; } diff --git a/labs/teammates/test/screen.test.tsx b/labs/teammates/test/screen.test.tsx index 20f38a9736..014eb4d73c 100644 --- a/labs/teammates/test/screen.test.tsx +++ b/labs/teammates/test/screen.test.tsx @@ -3,8 +3,10 @@ * The screen, on fixtures. These prove the UI only: a list of workers rather * than sessions, worker talk drawn in both conversations and the Talk panel * (D1), a reply that waits for your turn and shows as pending (D2), and a - * divider that never calls a window boundary a summary. The goal check proves - * the package at wiring. + * divider that never calls a window boundary a summary, and a coding job that + * asks for a project the first time it needs one (D3) and runs on coder, a + * worker that takes tasks only (D4). The goal check proves the package at + * wiring. */ import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import { afterEach, describe, expect, it } from "vitest"; @@ -36,7 +38,7 @@ async function tell(worker: string, text: string) { describe("the teammates screen", () => { it("lists workers, not sessions, and opens on lead's one conversation", async () => { render(); - await waitFor(() => expect(within(workers()).getAllByRole("listitem")).toHaveLength(3)); + await waitFor(() => expect(within(workers()).getAllByRole("listitem")).toHaveLength(4)); expect(workerRow("lead").getAttribute("aria-current")).toBe("true"); expect(within(conversation()).getByRole("heading", { name: "lead" })).toBeTruthy(); // Grok Bot's sidebar has no session list and no new chat. @@ -117,4 +119,67 @@ describe("the teammates screen", () => { fireEvent.click(within(conversation()).getByRole("button", { name: "Talk" })); expect(within(talk()).getByRole("region", { name: "with writer" })).toBeTruthy(); }); + + it("talks to lead with no project, and asks for one only when a job needs files", async () => { + const adapter = fast(); + render(); + // Talking needs no project: lead answers with none picked. + const chip = (await screen.findByLabelText("Project for lead")) as HTMLSelectElement; + expect(chip.value).toBe(""); + await tell("lead", "Have coder fix the typo in the README's first line."); + + // Step 5: lead files a task; with no project its run is refused before any file, and the card asks. + const card = await within(conversation()).findByRole("button", { name: "Task for coder: Fix the typo in the README's first line" }); + const tile = card.closest("[data-entry=task]")!; + await waitFor(() => expect(tile.querySelector("[data-task-status]")?.textContent).toBe("needs a project")); + const prompt = within(tile).getByRole("group", { name: "Pick a project" }); + + // Nothing runs while you haven't picked. + await new Promise((resolve) => setTimeout(resolve, 300)); + expect(workerRow("coder").querySelector("[data-status]")?.textContent).toBe("tasks · Claude Code"); + fireEvent.click(card); + expect(within(tile).getByRole("list", { name: /Run of/ }).textContent).toMatch(/No run started: lead had no project/); + + // The pick sticks to lead, is said to lead as your line, and lead files the task again in it. + fireEvent.change(within(prompt).getByLabelText("Project"), { target: { value: "relay" } }); + await act(async () => fireEvent.click(within(prompt).getByRole("button", { name: "Use project" }))); + expect(await within(conversation()).findByText("Work in relay.")).toBeTruthy(); + expect(chip.value).toBe("relay"); + expect(tile.querySelector("[data-task-status]")?.textContent).toBe("refused · no project"); + expect(within(tile).queryByRole("group", { name: "Pick a project" })).toBeNull(); + + await waitFor(() => expect(within(conversation()).getAllByRole("button", { name: /Task for coder/ })).toHaveLength(2), { timeout: 2000 }); + const rerun = within(conversation()).getAllByRole("button", { name: /Task for coder/ })[1].closest("[data-entry=task]")!; + await waitFor(() => expect(rerun.querySelector("[data-task-status]")?.textContent).toBe("running in relay")); + await waitFor(() => expect(workerRow("coder").querySelector("[data-status]")?.textContent).toBe("running · Claude Code")); + + // The result lands as a line from coder, and lead's next line uses it. + expect(await within(conversation()).findByRole("region", { name: "From coder" }, { timeout: 2000 })).toBeTruthy(); + expect(rerun.querySelector("[data-task-status]")?.textContent).toBe("done in relay"); + expect(await within(conversation()).findByText(/coder is done: "Fixed the typo in README.md, line 1\." That's in relay\./, {}, { timeout: 2000 })).toBeTruthy(); + }); + + it("shows coder's runs read only, with no composer, since it takes tasks only", async () => { + const adapter = fast(); + await adapter.setWorkProject("teammates.lead", "relay"); + render(); + await tell("lead", "Have coder fix the typo in the README's first line."); + await within(conversation()).findByRole("button", { name: /Task for coder/ }); + + fireEvent.click(workerRow("coder")); + const runs = await screen.findByRole("main", { name: "Runs" }); + expect(within(runs).getByRole("heading", { name: "coder" })).toBeTruthy(); + expect(screen.queryByLabelText("Message coder")).toBeNull(); + const run = await within(runs).findByRole("list", { name: "Run of Fix the typo in the README's first line" }); + await waitFor(() => expect(run.textContent).toMatch(/Edited line 1/), { timeout: 2000 }); + }); + + it("files the refused job again when you pick lead's project from the header instead of the card", async () => { + render(); + await tell("lead", "Have coder fix the typo in the README's first line."); + await within(conversation()).findByRole("group", { name: "Pick a project" }); + await act(async () => fireEvent.change(screen.getByLabelText("Project for lead"), { target: { value: "relay" } })); + expect(await within(conversation()).findByText("Work in relay.")).toBeTruthy(); + await waitFor(() => expect(within(conversation()).getAllByRole("button", { name: /Task for coder/ })).toHaveLength(2), { timeout: 2000 }); + }); }); diff --git a/labs/teammates/workforce/teams/teammates/TEAM.md b/labs/teammates/workforce/teams/teammates/TEAM.md index ee873841d6..841c92b8fa 100644 --- a/labs/teammates/workforce/teams/teammates/TEAM.md +++ b/labs/teammates/workforce/teams/teammates/TEAM.md @@ -1,4 +1,4 @@ --- name: Teammates -description: Three workers, each with one long conversation, who message each other when they need a hand. +description: Three workers, each with one long conversation, who message each other when they need a hand, and coder, which takes their code changes as tasks. --- diff --git a/labs/teammates/workforce/teams/teammates/workers/coder/WORKER.md b/labs/teammates/workforce/teams/teammates/workers/coder/WORKER.md new file mode 100644 index 0000000000..1c7c83721f --- /dev/null +++ b/labs/teammates/workforce/teams/teammates/workers/coder/WORKER.md @@ -0,0 +1,8 @@ +--- +name: coder +description: Makes code changes lead hands it, in lead's project. +harness: claude-code +--- + +You take tasks only. Each task is a code change another worker filed; make it in the project the +task runs in, check it, and say in one line what changed. diff --git a/labs/teammates/workforce/teams/teammates/workers/lead/WORKER.md b/labs/teammates/workforce/teams/teammates/workers/lead/WORKER.md index 776560e9b3..efbf575578 100644 --- a/labs/teammates/workforce/teams/teammates/workers/lead/WORKER.md +++ b/labs/teammates/workforce/teams/teammates/workers/lead/WORKER.md @@ -1,9 +1,11 @@ --- name: lead description: Plans the launch with you, and asks the other workers when it needs a fact or a draft. +delegates: [teammates.coder] --- You plan the launch with the user, in one conversation that goes on for weeks. When you need a fact, message researcher with `sendMessage`; when you need copy, message writer. Keep answering the user while they work. A reply reaches you as its own message after your current answer: use it then, and -say what changed. +say what changed. Hand a code change to coder with `createTask`; its result reaches you when the +run ends.