Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
966b1d9
FIX-2154: wire the Teammates lab to the real packages
claude Oct 28, 2026
830c32d
FIX-2154: record the goal's verdicts and controls, file the gaps
claude Oct 28, 2026
944bbca
FIX-2154: say user, not person, in the lab's comments
claude Oct 28, 2026
2fd0c09
FIX-2154: name the Teammates lab's server config as a fallow entry
claude Oct 28, 2026
95fe4cf
FIX-2154: keep host.mts's own constants unexported
claude Oct 28, 2026
4d397d8
FIX-2154: answer review on the adapter and the goal
claude Oct 28, 2026
0660cd6
FIX-2154: read the feed's snapshot again when the history moves while…
claude Oct 28, 2026
ed88b9f
FIX-2154: hand the lab's Codex runs only the environment Codex needs
claude Oct 28, 2026
e8207d9
FIX-2154: follow a task's run by the session its card already names
claude Oct 28, 2026
e7ea812
FIX-2154: name the issue in the Codex pass-list changeset
claude Oct 28, 2026
ffb6fdd
FIX-2280: the Teammates lab reads a worker's project from its convers…
claude Oct 28, 2026
6e31e6b
FIX-2280: show a pick made here at once, before the next read confirm…
claude Oct 28, 2026
4e01de4
FIX-2289: render worker text as Markdown in the Teammates lab
claude Oct 28, 2026
9790706
Merge remote-tracking branch 'origin/claude/project-thread-e54cfm' in…
claude Oct 28, 2026
920da34
FIX-2289: keep MessageResponse internal to the lab's Markdown component
claude Oct 28, 2026
ecb5e55
FIX-2280: recount the lab inventory after the merge
claude Oct 28, 2026
6ee5d73
FIX-2280: a project set back elsewhere shows after a pick here
claude Oct 28, 2026
649e971
FIX-2289: read the lab's entries as shown in the goal check
claude Oct 28, 2026
7102c9e
FIX-2289: show a worker's answer as it is written
claude Oct 28, 2026
5258966
Merge remote-tracking branch 'origin/claude/project-thread-e54cfm' in…
claude Oct 28, 2026
49dd1b3
Merge main into FIX-2280 (keep both session-read tests; take main's p…
claude Oct 28, 2026
c295253
Merge main into FIX-2154 lab branch
claude Oct 28, 2026
2480d98
Merge remote-tracking branch 'origin/claude/project-thread-e54cfm' in…
claude Oct 28, 2026
0b3fc04
FIX-2280: recount the Teammates inventory after merging #4079
claude Oct 28, 2026
7bd40d0
Teammates lab: an unlinked task answer is not drawn as failed; lead n…
claude Oct 28, 2026
b82f66d
Teammates lab: researcher answers only through sendMessage; goal wait…
claude Oct 28, 2026
7f9874b
Merge remote-tracking branch 'origin/claude/project-thread-e54cfm' in…
claude Oct 28, 2026
a1dd201
FIX-2280: recount the Teammates inventory after merging #4079 at b82f…
claude Oct 28, 2026
78ce1ac
Merge main into FIX-2280 after #4079 landed
claude Oct 28, 2026
623e4db
Port fix: a task-board test still named the old human_input suspensio…
claude Oct 28, 2026
50789cc
FIX-2280: recount the Teammates inventory after the main merge settled
claude Oct 28, 2026
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
11 changes: 11 additions & 0 deletions apps/docs/docs/workforce/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,17 @@ await workforce.setWorkProject("main", { visibility: "shared", id: "apollo" }, {

Without `sessionId`, it sets the user's default conversation with that worker, creating the conversation if there isn't one. With `sessionId`, it sets that session, which must be the user's own and run that worker. It resolves to `{ project: { visibility, id } }`. A new session takes two calls, as above: create it, then set its project. A create that puts `workProjectId` in `state` is refused with a 400 naming the field.

To show the project on screen, read the session. Its state carries `workProjectId` as `<visibility>/<id>`, whoever set it and however long ago, and `parseProjectRef` from `@flow-state-dev/workforce/browser` splits it:

```ts
import { parseProjectRef, WORK_PROJECT_STATE_KEY } from "@flow-state-dev/workforce/browser";

const { state } = await fsd.sessions.get(session.id);
const project = parseProjectRef(String(state[WORK_PROJECT_STATE_KEY] ?? "")); // { visibility: "shared", id: "apollo" }
```

The field is read only. `setWorkProject` is the only way to change it.

Calling it again with another project replaces the first. Tasks already filed keep the project they were filed in, including one still waiting on the board for a delegate and one handed to a delegate's ongoing session, along with whatever that delegate files while working it. A run that has already started stays where it is. There's no way to clear the project: once set, the conversation always has one.

The worker flows the package ships take the call as they are: `agent`, `coordinator` and the [Error Reporter](./error-reporter.md)'s flow. A worker flow of your own declares the action under its name:
Expand Down
11 changes: 4 additions & 7 deletions labs/teammates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ names the package call it makes.
|---|---|
| The worker list, sending, the conversation, busy status | the workforce client's `roster()` and `ensureWorkerSession`, the flow's `respond`, session items, `listSessionRequests` |
| Workers messaging each other, the Talk panel | `sendMessage`, the received-message item (`workforce:received`), and the message log |
| A worker's project, and picking it | `setWorkProject`, read back from that action's own answer |
| A worker's project, and picking it | `setWorkProject`, read back as the conversation's `workProjectId` on the session read |
| Task cards, the refusal for want of a project | the conversation board's rows, and `projectWorkspace()`'s `no-project` refusal |
| coder's runs | the task row's `run` link, read as the run session's items |

Not wired yet:

- **The divider and its *summarized* label** wait on the history window's mark (G1, FIX-1613). Until
then the screen draws no divider.
- **A worker's project, read from its conversation.** The package keeps it on the conversation as
`workProjectId`, but doesn't show that state to a client, so the screen reads the last
`setWorkProject` answer instead. A pick made anywhere else isn't seen (FIX-2280).
- **Which harness coder runs on.** The roster doesn't carry a worker's settings, so the screen names
the harness from the run's own steps once it starts (FIX-2281).
- **A task whose input has an `issue` field** is refused by the coding run as half a feature payload
Expand All @@ -98,8 +95,8 @@ and on a flow over 200 lines; `--wired` also fails on any fixture.
<!-- inventory:start -->
| Kind | Files | Lines |
|---|---:|---:|
| Configuration | 16 | 524 |
| React UI | 19 | 1677 |
| Configuration | 16 | 521 |
| React UI | 19 | 1691 |
| Small flows | 1 | 148 |
| Checks (not app code) | 7 | 891 |
| Checks (not app code) | 8 | 921 |
<!-- inventory:end -->
80 changes: 47 additions & 33 deletions labs/teammates/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* | `watchActivity` | `listSessionRequests` on the worker's conversation |
* | `watchWindow` | the mark the history window leaves: gap G1 (FIX-1613), not yet in the package |
* | `listProjects` | the user's projects, read through their roster session |
* | `watchWorkProject` | the last `setWorkProject` answer, read once, then each pick made here (FIX-2280) |
* | `watchWorkProject` | the conversation's `workProjectId`, from the session read |
* | `setWorkProject` | the workforce client's `setWorkProject(worker, project)` |
* | `watchTasks` | the board's rows, as the conversation's stream carries each one (`task-change`) |
* | `watchRun` | the items of the session the task's row names as its run |
Expand All @@ -30,10 +30,12 @@ import type { OutputItem } from "@flow-state-dev/core/items";
import { readBearerToken, readUserId, withBearerToken } from "@flow-state-dev/devtool/react";
import {
createWorkforceClient,
parseProjectRef,
RECEIVED_MESSAGE_COMPONENT,
ROSTER_FLOW,
SEND_MESSAGE_TOOL,
SET_WORK_PROJECT_ACTION,
WORK_PROJECT_STATE_KEY,
WORKER_MESSAGES_RESOURCE,
workerMessageRowSchema,
type WorkforceClient,
Expand Down Expand Up @@ -158,8 +160,6 @@ export interface LabAdapter {
watchRun(runSessionId: string, onChange: (steps: RunStep[]) => void): Unsubscribe;
}

/** How many finished requests one read of a conversation's history takes. */
const REQUEST_PAGE = 200;
/** How often the reads with no stream are read again. */
const POLL_MS = 1_500;
/** The accessor the user's shared projects are read under, on their roster session. */
Expand Down Expand Up @@ -296,6 +296,32 @@ function connect(): Client {
return createClient({ userId: readUserId(), baseUrl: "", fetcher: withBearerToken(readBearerToken()) });
}

/**
* The project a conversation works in, as the screen names it: the id of the
* `workProjectId` its session read shows. The screen lists only shared
* projects, so it joins on visibility and id both, and a private one names none.
*/
export function workProjectOf(state: Readonly<Record<string, unknown>> | undefined): string | undefined {
const stored = state?.[WORK_PROJECT_STATE_KEY];
const ref = typeof stored === "string" ? parseProjectRef(stored) : undefined;
return ref?.visibility === "shared" ? ref.id : undefined;
}

/**
* `onChange`, called only when the value differs from the one it last passed on. A
* watch fed both by reads and by a pick made on this page compares with what the
* screen shows, not with the last read: a change made elsewhere back to that read
* still reaches the screen.
*/
export function shownOnChange<T>(onChange: (value: T) => void): (value: T) => void {
let shown: { value: T } | undefined;
return (value) => {
if (shown !== undefined && shown.value === value) return;
shown = { value };
onChange(value);
};
}

/** The adapter the app runs on: the package, through one client. */
export function createLabAdapter(client: Client = connect()): LabAdapter {
const workforce: WorkforceClient = createWorkforceClient(client);
Expand All @@ -307,10 +333,8 @@ export function createLabAdapter(client: Client = connect()): LabAdapter {
let workerIds = new Set<string>();
/** Each shared project's visibility, as listed. */
const visibility = new Map<string, "shared" | "private">();
/** Each worker's project as this page knows it: read once, then set by each pick here. */
const picked = new Map<string, string>();
/** Who is told when a pick here changes a worker's project. */
const pickWatchers = new Map<string, Set<(project: string | undefined) => void>>();
/** Who watches each worker's project, told at once when a pick here is stored. */
const projectWatchers = new Map<string, Set<(project: string | undefined) => void>>();

const conversationOf = async (worker: string) => {
const known = conversations.get(worker);
Expand Down Expand Up @@ -420,37 +444,27 @@ export function createLabAdapter(client: Client = connect()): LabAdapter {
});
},
watchWorkProject(worker, onChange) {
// Read once, from every page of the conversation's finished requests; after that only a pick
// made here changes it. A pick made elsewhere shows on the next load (FIX-2280).
let live = true;
const watchers = pickWatchers.get(worker) ?? new Set();
pickWatchers.set(worker, watchers);
watchers.add(onChange);
void (async () => {
if (!picked.has(worker)) {
const { sessionId } = await conversationOf(worker);
let last: SessionRequestSummary | undefined;
for (let offset = 0; ; offset += REQUEST_PAGE) {
const page = await client.sessions.requests(sessionId, { status: "completed", includeResultOutput: true, limit: REQUEST_PAGE, offset });
for (const r of page) {
if (r.actionName === SET_WORK_PROJECT_ACTION && (last === undefined || (r.completedAtMs ?? 0) > (last.completedAtMs ?? 0))) last = r;
}
if (page.length < REQUEST_PAGE) break;
}
const project = (last?.result?.output as { project?: { id?: string } } | undefined)?.project?.id;
if (project !== undefined && !picked.has(worker)) picked.set(worker, project);
}
if (live) onChange(picked.get(worker));
})().catch((error: unknown) => console.error(`teammates: ${worker}'s project could not be read`, error));
// The project stored on the conversation, whoever set it: the session read shows it, read only.
// A pick here shows at once, so each read is checked against what was last shown.
const show = shownOnChange(onChange);
const watchers = projectWatchers.get(worker) ?? new Set();
projectWatchers.set(worker, watchers);
watchers.add(show);
let reads = 0;
const stop = poll(async () => {
const { sessionId } = await conversationOf(worker);
// Numbered, so `poll` passes every read on rather than only a changed one.
return { read: reads++, project: workProjectOf((await client.sessions.get(sessionId)).state) };
}, ({ project }) => show(project));
return () => {
live = false;
watchers.delete(onChange);
watchers.delete(show);
stop();
};
},
async setWorkProject(worker, project) {
await workforce.setWorkProject(worker, { visibility: visibility.get(project) ?? "shared", id: project });
Comment thread
jhoffner marked this conversation as resolved.
Resolved
picked.set(worker, project);
for (const watcher of pickWatchers.get(worker) ?? []) watcher(project);
// Stored: say so now rather than on the next read, which confirms it.
for (const watcher of projectWatchers.get(worker) ?? []) watcher(project);
Comment thread
jhoffner marked this conversation as resolved.
Resolved
},
watchTasks(sessionId, onChange) {
return watchFeed(sessionId, (items) => [...boardRows(items).values()].map(toBoardTask), onChange);
Expand Down
30 changes: 30 additions & 0 deletions labs/teammates/test/work-project.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* The project the screen names for a worker comes from the conversation's own
* `workProjectId`, as the session read shows it, so a pick made in another tab
* or client shows too (FIX-2280).
*/
import { describe, expect, it } from "vitest";
import { shownOnChange, workProjectOf } from "../src/adapter";

describe("a worker's project, read from its conversation", () => {
it("names the shared project the session read shows, whoever set it", () => {
expect(workProjectOf({ workerId: "lead", workProjectId: "shared/apollo" })).toBe("apollo");
});

it("names none before a pick, and none for a private project the screen doesn't list", () => {
expect(workProjectOf({ workerId: "lead" })).toBeUndefined();
expect(workProjectOf(undefined)).toBeUndefined();
expect(workProjectOf({ workProjectId: "private/apollo" })).toBeUndefined();
expect(workProjectOf({ workProjectId: "apollo" })).toBeUndefined();
});

it("shows a change made elsewhere back to the project last read, after a pick here", () => {
const seen: (string | undefined)[] = [];
const show = shownOnChange<string | undefined>((project) => seen.push(project));
show("apollo"); // read
show("beta"); // picked here, shown at once
show("apollo"); // read: another client set it back
show("apollo"); // read again: nothing new
expect(seen).toEqual(["apollo", "beta", "apollo"]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ describe("a steer no request took gives the task one more turn before it settles
await (await h.ledger()).answer!("t1", { questionId: question, message: "EU", from: "user", by: "u1" });
// That owed turn asks the user to review its work before it finishes, as a thread does.
h.setSteerTurn(async (_steers, ctx) => {
const resolution = await ctx.suspend!({ reason: "human_input", message: "review the EU draft" });
const resolution = await ctx.suspend!({ reason: "user_input", message: "review the EU draft" });
return { reviewed: resolution };
});
const turn = await h.runLater("steerTurn");
Expand Down
4 changes: 3 additions & 1 deletion packages/workforce/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ that worker on every turn with `installation.resolveWorker(ctx, flowKind)`. `hir
worker flow that doesn't declare it. The same session state (`installation.sessionStateShape`)
carries `workProjectId` (`WORK_PROJECT_STATE_KEY`), the project a user set their own conversation
to work in, as `<visibility>/<id>`. Only the `setWorkProject` action writes it, and a create that
seeds it is refused with a 400 naming the field (see [Projects](#projects)).
seeds it is refused with a 400 naming the field (see [Projects](#projects)). A user's session read,
the session listing and the state read show it, read only, so a screen can name the project. It is
not `projectId`: that readonly field is the project coordinator's link to its project, set at create.

A worker takes a user's message through its flow's **door**: the one public action the flow
declares with `userMessage` and a `{ message }` input. `openInventory` writes it on the worker's
Expand Down
7 changes: 4 additions & 3 deletions packages/workforce/test/projects-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export async function bootProjectsHost(extras: HostExtras, options: { stores?: S
const more = extras.flows?.(installation) ?? {};
// A lead given a task entry takes tasks.
flows = { lead: { flow: lead, roles: extras.leadTask === undefined ? [] : ["contributor"] }, lead2, quiet, ...more };
const flowOf = (entry: unknown): (() => unknown) =>
(typeof entry === "function" ? entry : (entry as { flow: () => unknown }).flow) as () => unknown;
const flowOf = (entry: unknown): ((options: { id: string }) => unknown) =>
(typeof entry === "function" ? entry : (entry as { flow: () => unknown }).flow) as (options: { id: string }) => unknown;

const hireBlocks = createWorkerHireBlocks(installation);
const roster = defineWorkerRosterFlow(installation, {
Expand All @@ -145,7 +145,8 @@ export async function bootProjectsHost(extras: HostExtras, options: { stores?: S
quiet: quiet() as unknown as FlowInstance,
[ROSTER_FLOW]: roster() as unknown as FlowInstance,
...Object.fromEntries(
Object.entries(more).map(([name, flow]) => [name, flowOf(flow)() as unknown as FlowInstance])
// Named by its key, which a collection flow (the built-in agent flow) needs.
Object.entries(more).map(([name, flow]) => [name, flowOf(flow)({ id: name }) as unknown as FlowInstance])
)
};
const state = createFlowState({
Expand Down
26 changes: 25 additions & 1 deletion packages/workforce/test/work-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { defineFlow, handler } from "@flow-state-dev/core";
import type { BlockContext } from "@flow-state-dev/core/types";
import { mockGenerator } from "@flow-state-dev/testing";
import { z } from "zod";
import { AGENT_FLOW, defineAgentWorkerFlow } from "../src/agent-worker-flow";
import { createWorkforceClient } from "../src/browser";
import {
COORDINATOR_FLOW,
Expand Down Expand Up @@ -118,6 +119,8 @@ const standardWorkers: WorkerManifest[] = [
// Two task-taking delegates, so a task filed with no assignee waits on the board.
worker("lead", { flow: COORDINATOR_FLOW, delegates: ["eng.taker", "eng.coder"] }),
worker("main", { flow: COORDINATOR_FLOW, delegates: ["eng.taker"] }),
// A worker on the built-in agent flow, the one a lab's talking workers run on.
worker("writer", { flow: AGENT_FLOW }),
worker("eng.taker", { flow: "taker", description: "Takes tasks.", delegates: ["eng.coder"] }),
worker("eng.coder", { flow: "taker", description: "Codes." })
];
Expand All @@ -137,7 +140,8 @@ async function boot() {
leadInternal: () => ({ [WORKSTREAM_OPENED_ENTRY]: workstreamOpenedEntry() }),
flows: (installation) => ({
taker: { flow: takerFlow(installation, runs), roles: ["contributor", "manager"] },
[COORDINATOR_FLOW]: defineCoordinatorFlow({ installation, routeModel: "typesafe-ai/jev" })
[COORDINATOR_FLOW]: defineCoordinatorFlow({ installation, routeModel: "typesafe-ai/jev" }),
[AGENT_FLOW]: defineAgentWorkerFlow({ installation })
}),
models: { generators: { "coordinator-judgment": judgment } },
// A step in a session of its own parks its request until the step ends.
Expand Down Expand Up @@ -198,6 +202,26 @@ describe("a user's conversation with a worker, set to a project", () => {
expect(h.runs[0]!.state).toMatchObject({ filingProjectId: "shared/apollo" });
});

it("read elsewhere: on the agent flow, a project another client set shows on this client's read and listing, and can't be seeded", async () => {
const h = await withProjects();
const reader = createClient({ userId: "alice", fetcher: h.fetcherFor("alice", ORG) });
const writer = await createWorkforceClient(reader).ensureWorkerSession({ worker: "writer" });
expect((await reader.sessions.get(writer.id)).state).not.toHaveProperty("workProjectId");
// Set from a second client: the reader sent no setWorkProject of its own.
await h.client("alice").setWorkProject("writer", apollo);
expect((await reader.sessions.get(writer.id)).state).toMatchObject({ workProjectId: "shared/apollo" });
const [row] = await createWorkforceClient(reader).listWorkerSessions("writer");
expect(row!.session.state).toMatchObject({ workProjectId: "shared/apollo" });
await h.client("alice").setWorkProject("writer", beta);
expect((await reader.sessions.get(writer.id)).state).toMatchObject({ workProjectId: "shared/beta" });
// Reading it gives no way to write it.
const forged = await h.tryOpenSession("alice", AGENT_FLOW, { workerId: "writer", workProjectId: "shared/apollo" });
expect(forged.status).toBe(400);
// Another user can't read it.
const bob = createClient({ userId: "bob", fetcher: h.fetcherFor("bob", ORG) });
await expect(bob.sessions.get(writer.id)).rejects.toThrow();
});

it("read: the session read shows the project a conversation works in once it is set, so a screen can name it", async () => {
const h = await withProjects();
const session = await h.openSession("alice", COORDINATOR_FLOW, { workerId: "main" });
Expand Down
Loading