Skip to content
Merged
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
1 change: 1 addition & 0 deletions apps/server/src/environment/Layers/ServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const makeServerEnvironment = Effect.fn("makeServerEnvironment")(function
pushAlerts: true,
phoneAlertControls: true,
projectLead: true,
childStartSelection: true,
deviceNames: true,
draftGoalSetup: true,
pullRequestSwitchesByNumber: true,
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ A project's lead chat is a thread set up to coordinate the project; see the lead

Any thread can be the lead. Use "Make this the lead chat" in a thread's menu (right-click its row, or click the title above the chat), or the command palette. The project's menu in the project picker has Open lead chat, or New lead chat, which starts a thread in the project folder and makes it the lead. "Go to lead chat" in the command palette opens it.

The lead can also pass a message to a thread you started by hand in the project. That is one-way: the thread works on it and answers there, not back in the lead, and it can't start threads of its own for it until you write there. The lead can't pass work into a room, a thread another thread still owns, or one you stopped. A pass never runs with more access than the lead had.

When an agent asks to start several threads, the card has a checkbox per thread, so you can start some and leave the rest; the agent is told which.

Only one thread leads a project; making another the lead replaces it. "Stop using as lead chat" turns it back into an ordinary thread, and the threads it started stay with it. Archiving or deleting the lead ends it. A lead can't move to another computer, and each computer keeps its own lead for a project.

The lead's row sits at the top of the sidebar with a flag, says Lead where the project name goes, and never wraps up on its own. The chat shows a Lead chat label beside the title.
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/links/LinkMoves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,8 @@ const make = Effect.gen(function* () {
...(message.completesTurn !== undefined ? { completesTurn: message.completesTurn } : {}),
...(message.agentModels !== undefined ? { agentModels: message.agentModels } : {}),
...(message.sentFrom !== undefined ? { sentFrom: message.sentFrom } : {}),
// Never reached the agent there: no history here may carry it either.
...(message.notSent === true ? { notSent: true as const } : {}),
createdAt: message.createdAt,
}));
const activities = row.manifest.thread.activities.map((activity) => ({
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/mcp/McpRoomServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* (scheduleTools.ts) are served here too: they need the same caller identity
* and the same per-runtime grant.
*/
import { PullRequestObservations } from "../pullRequest/PullRequestObservations.ts";
import {
agentInvitesMode,
agentThreadsMode,
Expand Down Expand Up @@ -187,6 +188,7 @@ const RoomToolHandlersLive = RoomEndpointToolkit.toLayer(
const linkClient = yield* Effect.serviceOption(ComputerLinkClient);
const linkRepo = yield* Effect.serviceOption(ComputerLinkRepository);
const identities = yield* Effect.serviceOption(RepositoryIdentityResolver);
const pullRequestObservations = yield* Effect.serviceOption(PullRequestObservations);
const links =
Option.isSome(linkClient) && Option.isSome(linkRepo) && Option.isSome(identities)
? makeThreadToolLinks({
Expand Down Expand Up @@ -268,6 +270,9 @@ const RoomToolHandlersLive = RoomEndpointToolkit.toLayer(
snapshots
.getProjectShellById(projectId)
.pipe(Effect.map(Option.getOrUndefined), Effect.orDie),
...(Option.isSome(pullRequestObservations)
? { knownPullRequests: pullRequestObservations.value.known }
: {}),
providers: providers.getProviders,
userDefaultModel,
threadsMode: settings.getSettings.pipe(
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/mcp/roomHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface RoomHistoryEntry {
readonly text: string;
readonly clipped?: boolean;
readonly streaming?: boolean;
/** It never reached the agent (OrchestrationMessage.notSent): shown, never acted on. */
readonly notSent?: boolean;
readonly attachments?: ReadonlyArray<RoomHistoryAttachment>;
}

Expand Down Expand Up @@ -75,6 +77,7 @@ function labelMessage(
...(message.requestKind !== undefined ? { requestKind: message.requestKind } : {}),
...(onTheSide ? { onTheSide: true } : {}),
...(message.streaming ? { streaming: true } : {}),
...(message.notSent === true ? { notSent: true } : {}),
...(message.attachments !== undefined && message.attachments.length > 0
? {
attachments: message.attachments.map((attachment) => ({
Expand Down
75 changes: 72 additions & 3 deletions apps/server/src/mcp/threadToolHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ const shellOf = (thread: OrchestrationThread): OrchestrationThreadShell =>
pendingChildApproval: false,
awaitedChildThreadCount: 0,
doneOverride: null,
// Every real thread carries it (decoding defaults it); some fixtures leave it out.
linkedPullRequests: (thread as Partial<OrchestrationThread>).linkedPullRequests ?? [],
}) as unknown as OrchestrationThreadShell;

const mainCaller = (): McpInvocationScope => ({
Expand Down Expand Up @@ -210,6 +212,8 @@ const makeTools = (options: {
/** The branch checked out in a folder; any other folder has none. */
readonly branches?: Readonly<Record<string, string>>;
readonly moves?: ThreadToolMoves;
/** The project's lead chat (docs/design/lead-chat.md). */
readonly leadThreadId?: ThreadId;
}) =>
Effect.gen(function* () {
let caller = options.caller ?? makeThread();
Expand Down Expand Up @@ -259,7 +263,12 @@ const makeTools = (options: {
.filter((thread) => thread.projectId === PROJECT)
.map(shellOf),
),
readProject: () => Effect.succeed({ kind: "workspace" as const, workspaceRoot: "/project" }),
readProject: () =>
Effect.succeed({
kind: "workspace" as const,
workspaceRoot: "/project",
leadThreadId: options.leadThreadId ?? null,
}),
providers: Effect.succeed(PROVIDERS),
userDefaultModel: Effect.succeed(options.userDefault ?? null),
threadsMode: Effect.succeed(options.mode ?? "auto"),
Expand Down Expand Up @@ -638,6 +647,47 @@ describe("thread_send", () => {
);
});

describe("thread_send from the project's lead chat", () => {
it.effect("passes a message to a thread the user started, one-way", () =>
Effect.gen(function* () {
const handMade = makeChild({ id: STRANGER, parentThreadId: null, attachedToParent: false });
const tools = yield* makeTools({ others: [handMade], leadThreadId: PARENT });
const result = yield* tools.handlers.thread_send(mainCaller(), {
threadId: STRANGER,
message: "Fix the flaky test.",
});
expect(result).toMatchObject({ outcome: "sent", reportsBack: false, threadId: STRANGER });
const [passed] = ofType(tools.dispatched, "thread.lead.pass");
expect(passed).toMatchObject({ threadId: PARENT, targetThreadId: STRANGER });
expect(ofType(tools.dispatched, "thread.child.send")).toHaveLength(0);
}),
);

it.effect(
"refuses a thread another thread owns, and anything from a thread that isn't the lead",
() =>
Effect.gen(function* () {
const owned = makeChild({ id: STRANGER, parentThreadId: ThreadId.make("someone-else") });
const lead = yield* makeTools({ others: [owned], leadThreadId: PARENT });
const refused = yield* lead.handlers.thread_send(mainCaller(), {
threadId: STRANGER,
message: "Fix it.",
});
expect(refused.outcome).toBe("not_yours");
expect(refused.detail).toContain("Message the thread that started it");

const handMade = makeChild({ id: STRANGER, parentThreadId: null, attachedToParent: false });
const plain = yield* makeTools({ others: [handMade] });
const notLead = yield* plain.handlers.thread_send(mainCaller(), {
threadId: STRANGER,
message: "Fix it.",
});
expect(notLead.outcome).toBe("not_yours");
expect(lead.dispatched.length + plain.dispatched.length).toBe(0);
}),
);
});

describe("an existing checkout", () => {
/** A thread the parent started that has finished its work, on its own branch. */
const coder = (patch: Partial<OrchestrationThread> = {}) =>
Expand Down Expand Up @@ -942,6 +992,18 @@ describe("thread_read", () => {
}),
message({ eventSequence: 2, text: "Also look at the index." }),
message({ eventSequence: 3, role: "assistant", text: "It is safe." }),
// A lead chat's pass that never ran: shown, labelled.
message({
eventSequence: 4,
text: "Run the migration.",
notSent: true,
fromThread: {
threadId: PARENT,
requestId: "request-2" as never,
kind: "request",
ceiling: { runtimeMode: "approval-required", interactionMode: "default" },
},
}),
],
});
const tools = yield* makeTools({ others: [child] });
Expand All @@ -951,15 +1013,22 @@ describe("thread_read", () => {
["thread_request", `Request from thread "Parent" (${PARENT})`],
["user", "User"],
["agent", "GPT-6 Astra"],
["thread_request", `Request from thread "Parent" (${PARENT})`],
]);
expect(result.messages.map((entry) => entry.notSent ?? false)).toEqual([
false,
false,
false,
true,
]);
expect(result.thread).toMatchObject({ threadId: CHILD, startedBy: "you", attached: true });
expect(result.next).toBe(3);
expect(result.next).toBe(4);

const later = yield* tools.handlers.thread_read(mainCaller(), {
threadId: CHILD,
after: 2,
});
expect(later.messages.map((entry) => entry.sequence)).toEqual([3]);
expect(later.messages.map((entry) => entry.sequence)).toEqual([3, 4]);
}),
);

Expand Down
Loading
Loading