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
2 changes: 1 addition & 1 deletion apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The agent and model a new thread starts with is {place:threads.agent}. You can s

While an agent works, {place:general.followUpDelivery} sets how a message goes by default (Steer now adds it to the reply in progress, Send when done holds it for the next one), and the arrow beside the send button overrides it for the current thread. Enter sends that way; Cmd+Enter (Ctrl+Enter on Windows and Linux) sends that one message the other way.

After a reply to your message, Claude, Codex, or Antigravity can suggest what you might send next: gray text in the empty message box, taken with Tab (Use on a phone), hidden with Escape. Claude makes its own and skips them when you're on track to run out of usage early, unless {place:providers.claudeSuggestions} is on. Codex's are made by Threadlines with one extra Codex answer each, only after messages you sent, never while a usage limit is 90% used, and {place:providers.codexSuggestions} turns them off. Antigravity's are made by Threadlines with a short isolated answer on a fast Gemini model (preferring Gemini Hydrogen, then Flash, at low thinking), only after messages you sent, never while that model's usage limit is 90% used, and {place:providers.antigravitySuggestions} turns them off.
After a reply to you, Claude, Codex, or Antigravity can suggest what you might send next: gray text in the empty message box, taken with Tab (Use on a phone), hidden with Escape. Claude makes its own and skips them when you're on track to run out of usage early, unless {place:providers.claudeSuggestions} is on. Codex's are made by Threadlines with one extra Codex answer each, after replies to you (including child-thread reports, room replies, and continued turns), never while a usage limit is 90% used, and {place:providers.codexSuggestions} turns them off. Antigravity's are made by Threadlines with a short isolated answer on a fast Gemini model (preferring Gemini Hydrogen, then Flash, at low thinking), after replies to you (including child-thread reports, room replies, and continued turns), never while that model's usage limit is 90% used, and {place:providers.antigravitySuggestions} turns them off.

A goal (type /goal and what to reach in the message box) keeps the agent working toward it across turns; the bar above the message box shows it, with pause, resume and clear. A Codex goal pauses by itself while the thread waits for your answer on a card or for threads it started to report back, so it doesn't spend turns asking whether you answered yet; the bar says why, and it carries on once the wait is over. Pausing, resuming or clearing it yourself in between is yours to keep. Claude's goals have no pause and carry on as before.

Expand Down
16 changes: 13 additions & 3 deletions apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import { ensureGeneralChatThreadScratchCwd } from "../generalChats.ts";
import { makeSessionLaunchGenerations, withoutLaunchMark } from "../sessionLaunches.ts";
import { buildIndependentReviewPrompt } from "../roomReviewPrompt.ts";
import { messageSentFromNote, previousMessageSentFrom } from "../messageSentFrom.ts";
import { turnMessageOrigin } from "../turnOrigin.ts";
import { shouldSuggestNextMessage, turnMessageOrigin } from "../turnOrigin.ts";
import { AnalyticsService } from "../../telemetry/Services/AnalyticsService.ts";
import { agentMessageFrame, buildRoomCatchUp } from "../roomCatchUp.ts";
import { isContinueTrigger, latestTurnStartFor } from "../continueTurns.ts";
Expand Down Expand Up @@ -3968,14 +3968,24 @@ const make = Effect.gen(function* () {
let providerTookTurn = false;
// None of the context in front of the message went (see below).
let contextDeferred = false;
const suggestionThread =
origin === "person" ? thread : ((yield* resolveThread(event.payload.threadId)) ?? thread);
yield* providerService
.sendTurn({
...turnRequest,
requestedAt,
origin,
lane: "main",
// Its sender reads the reply here: Codex suggests their next message.
...(origin === "person" ? { suggestNextMessage: true } : {}),
// The user reads the reply here: Codex and Antigravity suggest their next message.
...(shouldSuggestNextMessage({
origin,
message,
fromThread: event.payload.fromThread,
participantId: event.payload.participantId,
thread: suggestionThread,
})
? { suggestNextMessage: true }
: {}),
...(resend !== undefined ? { resend } : {}),
handoffSteps: {
queueMs,
Expand Down
246 changes: 244 additions & 2 deletions apps/server/src/orchestration/turnOrigin.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { ChildRequestId, OutsideAgentConnectionId, ThreadId } from "@threadlines/contracts";
import {
ChildRequestId,
EMPTY_AGENT_REQUEST_STATE,
EnvironmentId,
MessageId,
OutsideAgentConnectionId,
RoomAgentRequestId,
ScheduledTaskId,
ThreadId,
ThreadParticipantId,
TurnId,
} from "@threadlines/contracts";
import { describe, expect, it } from "vite-plus/test";

import { turnMessageOrigin } from "./turnOrigin.ts";
import { shouldSuggestNextMessage, turnMessageOrigin } from "./turnOrigin.ts";

const USER_THREAD = {
parentThreadId: null,
attachedToParent: false,
remoteOrigin: null,
scheduledRun: null,
outsideOrigin: null,
outsideWork: [],
agentRequests: EMPTY_AGENT_REQUEST_STATE,
} as const;

describe("turnMessageOrigin", () => {
it("counts a message as a person's only when a client app sent it for them", () => {
Expand Down Expand Up @@ -35,3 +56,224 @@ describe("turnMessageOrigin", () => {
]).toEqual(["room_agent", "room_agent", "other_thread", "outside_agent", "task"]);
});
});

describe("shouldSuggestNextMessage", () => {
const childReport = {
threadId: ThreadId.make("thread-child"),
requestId: ChildRequestId.make("request-1"),
kind: "report" as const,
};
const childRequest = {
threadId: ThreadId.make("thread-parent"),
requestId: ChildRequestId.make("request-2"),
kind: "request" as const,
};

it("suggests for user messages and user-facing wakeups on a top-level thread", () => {
expect(
shouldSuggestNextMessage({
origin: "person",
message: {},
thread: USER_THREAD,
}),
).toBe(true);
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
thread: USER_THREAD,
}),
).toBe(true);
expect(
shouldSuggestNextMessage({
origin: "room_agent",
message: {
fromAgent: { participantId: ThreadParticipantId.make("reviewer") },
requestKind: "reply",
},
thread: USER_THREAD,
}),
).toBe(true);
expect(
shouldSuggestNextMessage({
origin: "automatic",
message: { trigger: "serverRestart" },
thread: USER_THREAD,
}),
).toBe(true);
expect(
shouldSuggestNextMessage({
origin: "automatic",
message: { trigger: "usageLimitReset" },
thread: USER_THREAD,
}),
).toBe(true);
});

it("skips agent-to-agent requests, automatic alerts, and non-user threads", () => {
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childRequest },
fromThread: childRequest,
thread: USER_THREAD,
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "room_agent",
message: {
fromAgent: { participantId: null },
requestKind: "hand_off",
},
thread: USER_THREAD,
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "automatic",
message: {},
thread: USER_THREAD,
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "outside_agent",
message: {},
thread: USER_THREAD,
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "task",
message: {},
thread: USER_THREAD,
}),
).toBe(false);
// Child report waking an attached child, remote child, scheduled task, or outside-agent thread.
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
thread: {
...USER_THREAD,
parentThreadId: ThreadId.make("thread-grandparent"),
attachedToParent: true,
},
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
thread: {
...USER_THREAD,
remoteOrigin: {
linkDeviceId: "device-remote",
environmentId: EnvironmentId.make("env-remote"),
environmentLabel: "Remote Mac",
threadId: ThreadId.make("thread-remote-parent"),
threadTitle: "Remote parent",
},
},
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
thread: {
...USER_THREAD,
scheduledRun: {
taskId: ScheduledTaskId.make("task-1"),
taskName: "Nightly",
slotUtc: "2026-11-24T00:00:00.000Z",
},
},
}),
).toBe(false);
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
thread: {
...USER_THREAD,
outsideOrigin: {
connectionId: OutsideAgentConnectionId.make("conn-1"),
name: "Grok Bot",
},
},
}),
).toBe(false);
// Outside work is scoped per participant: another participant's mark does not block primary.
const otherAgent = ThreadParticipantId.make("agent-outside");
const outsideWork = [
{
participantId: otherAgent,
since: "2026-11-24T00:00:00.000Z",
version: 1,
connections: [
{
connectionId: OutsideAgentConnectionId.make("conn-1"),
name: "Grok Bot",
},
],
},
];
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
participantId: null,
thread: { ...USER_THREAD, outsideWork },
}),
).toBe(true);
expect(
shouldSuggestNextMessage({
origin: "other_thread",
message: { fromThread: childReport },
fromThread: childReport,
participantId: otherAgent,
thread: { ...USER_THREAD, outsideWork },
}),
).toBe(false);
// A nested room reply back to an agent still answering an outer hand-off.
const nestedAgent = ThreadParticipantId.make("agent-b");
expect(
shouldSuggestNextMessage({
origin: "room_agent",
message: {
fromAgent: { participantId: ThreadParticipantId.make("agent-c") },
requestKind: "reply",
},
participantId: nestedAgent,
thread: {
...USER_THREAD,
agentRequests: {
...EMPTY_AGENT_REQUEST_STATE,
chainEpoch: 1,
open: [
{
requestId: RoomAgentRequestId.make("req-outer"),
kind: "hand_off",
status: "running",
from: { participantId: null },
to: { participantId: nestedAgent },
callerTurnId: TurnId.make("turn-1"),
requestMessageId: MessageId.make("msg-1"),
chainEpoch: 1,
createdAt: "2026-11-24T00:00:00.000Z",
},
],
},
},
}),
).toBe(false);
});
});
69 changes: 68 additions & 1 deletion apps/server/src/orchestration/turnOrigin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import type { OrchestrationMessage, ProviderTurnOrigin } from "@threadlines/contracts";
import type {
OrchestrationMessage,
OrchestrationThread,
ProviderTurnOrigin,
ThreadMessageOrigin,
ThreadParticipantId,
} from "@threadlines/contracts";
import { isAttachedChild } from "@threadlines/shared/childThreads";

import { isContinueTrigger } from "./continueTurns.ts";
import { isOutsideMarked } from "./outsideTurns.ts";

/**
* Who the message that starts a turn came from (ProviderTurnOrigin), read
Expand Down Expand Up @@ -37,3 +47,60 @@ export function turnMessageOrigin(input: {
}
return "automatic";
}

/**
* Whether a completed turn's reply will wait for a person in the composer, so
* Codex or Antigravity should sample a next-message suggestion.
*
* A person's own message always qualifies. On a top-level user thread (not an
* attached child, remote child, scheduled run, outside-agent thread, or an
* agent answering a hand-off), turns that finish back to the user also qualify:
* a child thread's report waking its parent (such as a Lead chat), a room
* hand-off or review reply returning control to the agent, or an automatic
* continue after a server restart or usage-limit reset.
*/
export function shouldSuggestNextMessage(input: {
readonly origin: ProviderTurnOrigin;
readonly message: Pick<
OrchestrationMessage,
"fromThread" | "fromAgent" | "requestKind" | "trigger"
>;
readonly fromThread?: ThreadMessageOrigin | undefined;
readonly participantId?: ThreadParticipantId | null | undefined;
readonly thread: Pick<
OrchestrationThread,
| "parentThreadId"
| "attachedToParent"
| "remoteOrigin"
| "scheduledRun"
| "outsideOrigin"
| "outsideWork"
| "agentRequests"
>;
}): boolean {
if (input.origin === "person") return true;

const targetParticipantId = input.participantId ?? null;
if (
isAttachedChild(input.thread) ||
(input.thread.remoteOrigin ?? null) !== null ||
(input.thread.scheduledRun ?? null) !== null ||
(input.thread.outsideOrigin ?? null) !== null ||
isOutsideMarked(input.thread, targetParticipantId)
) {
return false;
}

const answeringHandOff = input.thread.agentRequests.open.some(
(request) =>
request.kind === "hand_off" && (request.to.participantId ?? null) === targetParticipantId,
);
if (answeringHandOff) return false;

const effectiveFromThread = input.fromThread ?? input.message.fromThread;
if (effectiveFromThread?.kind === "report") return true;
if (input.message.fromAgent !== undefined && input.message.requestKind === "reply") return true;
if (input.origin === "automatic" && isContinueTrigger(input.message.trigger)) return true;

return false;
}
Loading