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 @@ -56,7 +56,7 @@ A repository can already have worktrees that Threadlines did not make (git workt

The agent and model a new thread starts with is {place:threads.agent}. You can switch model or agent at any time from the model button in the composer, which also holds the agent's effort. Beside it sit Build or Plan (one click switches, as does Shift+Tab in the message box) and the access level; on a narrow window they show just their icons, and on phones both live in the model button's panel instead.

While an agent works, the arrow beside the send button picks how a message goes: Steer now adds it to the reply in progress, Send when done holds it for the next one, and the choice sticks. Enter sends that way; Cmd+Enter (Ctrl+Enter on Windows and Linux) sends that one message the other way.
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.

Expand Down
58 changes: 54 additions & 4 deletions apps/server/src/provider/acp/AcpAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const ACP_SESSION_COMMANDS_INTERVAL_MS = 5_000;
* conversation in a fresh one.
*/
const ACP_CANCEL_DEADLINE = Duration.seconds(15);
/** How long a steer waits to be written to the agent before failing so Stop is never blocked. */
const ACP_STEER_DELIVERY_TIMEOUT = Duration.seconds(15);
/** How long a revert lets the agent stop its work before its session ends. */
const ACP_REVERT_WIND_DOWN = Duration.seconds(3);
/**
Expand Down Expand Up @@ -448,7 +450,7 @@ interface AcpMachinePrompt {
readonly resolvedModel: string | undefined;
/** The context preamble this prompt carries; back to the session if it never goes out. */
readonly preamble: string | undefined;
/** A send's: hears whether its prompt was written to the agent (`reportDelivery`). */
/** A send's or a steer's: hears whether its prompt was written to the agent (`reportDelivery`). */
readonly delivered: Deferred.Deferred<boolean> | undefined;
}

Expand Down Expand Up @@ -497,6 +499,8 @@ interface AcpMachineSession {
readonly model: string | undefined;
readonly resolvedModel: string | undefined;
readonly planMode: AcpPromptPlanMode | undefined;
/** Set when the turn's opening prompt failed before being written to the agent. */
setupFailed?: Cause.Cause<unknown>;
readonly suggestNextMessage: boolean;
readonly suggestionGeneration: number;
}
Expand All @@ -510,6 +514,8 @@ interface AcpMachineSession {
* every prompt the machine sent before it.
*/
readonly outbox: Queue.Queue<number>;
/** Interrupted on session stop before draining `sessionStopping` so no late write slips through. */
senderFiber?: Fiber.Fiber<void, never>;
}

/**
Expand Down Expand Up @@ -1570,6 +1576,9 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
// after everything already queued (an answer and its usage, a turn's
// end), and only then is it stopped.
const machine = ctx.machine;
if (machine?.senderFiber !== undefined) {
yield* Fiber.interrupt(machine.senderFiber);
}
const drained =
machine === undefined || ctx.notificationFiber === undefined
? false
Expand Down Expand Up @@ -2935,7 +2944,9 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(

ctx.notificationFiber = notificationFiber;
if (ctx.machine !== undefined) {
yield* runPromptSender(ctx, ctx.machine).pipe(Effect.forkIn(sessionScope));
ctx.machine.senderFiber = yield* runPromptSender(ctx, ctx.machine).pipe(
Effect.forkIn(sessionScope),
);
}
sessions.set(input.threadId, ctx);
// A turn the machine holds open waits on no request the exit would
Expand Down Expand Up @@ -3325,11 +3336,25 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
) =>
Effect.gen(function* () {
const sent = machine.prompts.get(prompt);
if (sent === undefined) return;
if (sent === undefined || ctx.stopped) return;
const turnData = machine.turns.get(sent.turnId);
// If the turn's opening prompt failed before reaching the agent, a
// steer queued behind it must never go out alone under the old mode.
if (sent.index > 1 && turnData?.setupFailed !== undefined) {
const setupFailure = turnData.setupFailed;
yield* ctx.acp.inOrder(
Effect.suspend(() => {
sent.exit = Exit.failCause(setupFailure);
return answerMachinePrompt(ctx, prompt);
}).pipe(Effect.asVoid),
);
return;
}
const exit = yield* Effect.exit(
Effect.gen(function* () {
if (sent.configure !== undefined) yield* sent.configure;
yield* seam({ point: "promptSetup", prompt });
if (ctx.stopped) return;
// Where the agent's records stand as this prompt goes out.
sent.watch =
machineOptions?.outcome === undefined
Expand All @@ -3345,6 +3370,7 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
}).pipe(Effect.as(undefined)),
),
);
if (ctx.stopped) return;
const promptMeta = descriptor.promptMeta?.(sent.turnId);
yield* ctx.acp.promptInOrder(
prompt,
Expand All @@ -3358,6 +3384,9 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
);
// A stopping session ends the turn itself.
if (Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause)) return;
if (sent.index === 1 && turnData !== undefined) {
turnData.setupFailed = exit.cause;
}
yield* ctx.acp.inOrder(
Effect.suspend(() => {
sent.exit = Exit.failCause(exit.cause);
Expand Down Expand Up @@ -3940,6 +3969,7 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
"turn/steer",
);
const reply = yield* Deferred.make<AcpMachineReply>();
const delivered = yield* Deferred.make<boolean>();
const steerId = `steer:${crypto.randomUUID()}`;
machine.callers.set(steerId, {
prompt: {
Expand All @@ -3948,7 +3978,7 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
model: undefined,
resolvedModel: undefined,
preamble: undefined,
delivered: undefined,
delivered,
},
...(text.length > 0 ? { userMessageText: text } : {}),
planMode: undefined,
Expand All @@ -3975,6 +4005,26 @@ export function makeAcpAdapter<Settings extends AcpProviderSettings>(
answer.rejected,
);
}
// Returns once the prompt was written to the agent: if the process
// exited or the session stopped first, the steer never reached it.
// Bounded so a stalled stdin pipe cannot block Stop behind this call.
const written = yield* Deferred.await(delivered).pipe(
Effect.timeoutOption(ACP_STEER_DELIVERY_TIMEOUT),
);
if (Option.isNone(written)) {
return yield* new ProviderAdapterRequestError({
provider: PROVIDER,
method: "turn/steer",
detail: `${descriptor.presentation.displayName} did not accept this message in time.`,
});
}
if (!written.value) {
return yield* new ProviderAdapterRequestError({
provider: PROVIDER,
method: "turn/steer",
detail: `${descriptor.presentation.displayName} stopped before this message could be sent.`,
});
}
return {
threadId: input.threadId,
turnId: answer.accepted,
Expand Down
9 changes: 8 additions & 1 deletion apps/server/src/provider/acp/AcpSessionRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,14 @@ const makeAcpSessionRuntime = (
// sent after it is handled before this is queued.
const onAnswer = (answer: Exit.Exit<unknown, EffectAcpErrors.AcpError>) =>
Effect.gen(function* () {
yield* queueSent;
// Only a reply from the agent (success or JSON-RPC error) proves
// the prompt was written; a synthetic transport failure does not.
if (
Exit.isSuccess(answer) ||
Schema.is(EffectAcpErrors.AcpRequestError)(Cause.squash(answer.cause))
) {
yield* queueSent;
}
yield* Ref.update(promptsInFlightRef, (count) => count - 1);
// As `prompt`: the answer ends the prompt's reply, unless a turn
// the agent began itself, or a newer prompt, carries one on.
Expand Down
97 changes: 63 additions & 34 deletions apps/server/src/provider/antigravity/AntigravityTurns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ const startAgy = (
};
});

/** Steering, which Antigravity ships without (`ANTIGRAVITY_STEERS`), on for one test. */
const withSteering = (descriptor: AgyDescriptor): AgyDescriptor => ({
...descriptor,
turnMachine: { ...descriptor.turnMachine!, steer: true },
});

const completedTurns = (events: ReadonlyArray<ProviderRuntimeEvent>) =>
events.flatMap((event) => (event.type === "turn.completed" ? [event] : []));

Expand Down Expand Up @@ -414,7 +408,7 @@ describe("Antigravity turns", () => {

it.live("steers a running turn with a second prompt, never cancelling it", () =>
Effect.gen(function* () {
const agy = yield* startAgy("steer", withSteering);
const agy = yield* startAgy("steer");
expect(agy.adapter.capabilities.activeTurnSteering).toBe("supported");
const { turnId } = yield* agy.adapter.sendTurn({
threadId: agy.threadId,
Expand Down Expand Up @@ -732,7 +726,7 @@ describe("Antigravity turns, the hard cases", () => {

it.live("steers without inheriting the error the earlier prompt left in the log", () =>
Effect.gen(function* () {
const agy = yield* startAgy("steer-log-error", withSteering);
const agy = yield* startAgy("steer-log-error");
const { turnId } = yield* agy.adapter.sendTurn({
threadId: agy.threadId,
input: "go",
Expand All @@ -751,7 +745,7 @@ describe("Antigravity turns, the hard cases", () => {

it.live("steers without inheriting an error the earlier prompt writes late", () =>
Effect.gen(function* () {
const agy = yield* startAgy("steer-late-log-error", withSteering);
const agy = yield* startAgy("steer-late-log-error");
const { turnId } = yield* agy.adapter.sendTurn({
threadId: agy.threadId,
input: "go",
Expand All @@ -772,7 +766,7 @@ describe("Antigravity turns, the hard cases", () => {
"fails a steer whose own error is logged before the earlier prompt answers (finding 5)",
() =>
Effect.gen(function* () {
const agy = yield* startAgy("steer-own-log-error", withSteering);
const agy = yield* startAgy("steer-own-log-error");
const { turnId } = yield* agy.adapter.sendTurn({
threadId: agy.threadId,
input: "go",
Expand Down Expand Up @@ -1063,28 +1057,30 @@ describe("Antigravity turn driver, the orderings", () => {
it.live("sends a steer only after the prompt it steers, whose setup ran first (finding 2)", () =>
Effect.gen(function* () {
const gate = yield* makeGate((seam) => seam.point === "promptSetup" && seam.prompt === 1);
const agy = yield* startAgy("steer", withSteering, "full-access", gate.seams);
// The send returns once its prompt is written, so it waits on the gate too.
const agy = yield* startAgy("steer", undefined, "full-access", gate.seams);
// Both calls return once their prompts are written, so both wait on the gate.
const sending = yield* agy.adapter
.sendTurn({ threadId: agy.threadId, input: "first message", attachments: [] })
.pipe(Effect.forkScoped);
yield* gate.reached;
const started = agy.events.find((event) => event.type === "turn.started");
const turnId = started!.turnId!;
// The first prompt's setup hasn't returned; the steer is taken anyway.
yield* agy.adapter.steerTurn!({
// The first prompt's setup hasn't returned; the steer queues behind it and waits to write.
const steering = yield* agy.adapter.steerTurn!({
threadId: agy.threadId,
expectedTurnId: turnId,
input: "the steer",
});
}).pipe(Effect.forkScoped);
yield* Effect.sleep("200 millis");
expect(steering.pollUnsafe()).toBeUndefined();
const prompts = (frames: ReadonlyArray<Record<string, unknown>>) =>
frames.flatMap((frame) =>
frame.method === "session/prompt" ? [JSON.stringify(frame.params)] : [],
);
expect(prompts(yield* agy.frames())).toEqual([]);
yield* gate.release;
expect((yield* Fiber.join(sending)).turnId).toBe(turnId);
expect((yield* Fiber.join(steering)).turnId).toBe(turnId);
yield* agy.waitFor((events) => completedTurns(events).length === 1);
const sent = prompts(yield* agy.frames());
expect(sent).toHaveLength(2);
Expand Down Expand Up @@ -1311,7 +1307,7 @@ describe("Antigravity turn driver, the orderings", () => {
it.live("lets go of each prompt's record once its answer is in, a steered one's too", () =>
Effect.gen(function* () {
const gate = yield* makeGate(() => false);
const agy = yield* startAgy("steer", withSteering, "full-access", gate.seams);
const agy = yield* startAgy("steer", undefined, "full-access", gate.seams);
const { turnId } = yield* agy.adapter.sendTurn({
threadId: agy.threadId,
input: "go",
Expand Down Expand Up @@ -1432,29 +1428,62 @@ describe("Antigravity turn driver, the orderings", () => {
}).pipe(Effect.scoped, Effect.provide(testServices)),
);

it.live("queues a message sent mid-turn, steering being off for Antigravity", () =>
it.live("fails a steer when the session stops before the steer is written to the agent", () =>
Effect.gen(function* () {
const agy = yield* startAgy("background");
expect(agy.adapter.steerTurn).toBeUndefined();
expect(agy.adapter.capabilities.activeTurnSteering).toBeUndefined();
const first = yield* agy.adapter.sendTurn({
const gate = yield* makeGate((seam) => seam.point === "promptSetup" && seam.prompt === 1);
const agy = yield* startAgy("steer", undefined, "full-access", gate.seams);
expect(agy.adapter.capabilities.activeTurnSteering).toBe("supported");
const sending = yield* agy.adapter
.sendTurn({ threadId: agy.threadId, input: "first message", attachments: [] })
.pipe(Effect.forkScoped);
yield* gate.reached;
const started = agy.events.find((event) => event.type === "turn.started");
const turnId = started!.turnId!;
const steering = yield* agy.adapter.steerTurn!({
threadId: agy.threadId,
input: "build it",
attachments: [],
expectedTurnId: turnId,
input: "never written",
}).pipe(Effect.exit, Effect.forkScoped);
yield* agy.waitFor(() =>
gate.seen.some((seam) => seam.point === "stepCommitted" && seam.event === "steer"),
);
yield* agy.adapter.stopSession(agy.threadId);
expect((yield* Fiber.join(sending)).undelivered).toBe(true);
expect(Exit.isFailure(yield* Fiber.join(steering))).toBe(true);
const prompts = (yield* agy.frames()).filter((frame) => frame.method === "session/prompt");
expect(prompts).toHaveLength(0);
}).pipe(Effect.scoped, Effect.provide(testServices)),
);

it.live("does not send a steer alone when its turn's opening prompt fails mode setup first", () =>
Effect.gen(function* () {
const agy = yield* startAgy("mode-fails-once", undefined, "auto-accept-edits", undefined, {
version: 1,
fromProvider: ProviderDriverKind.make("claudeAgent"),
entries: [{ kind: "message", role: "user", text: "the earlier conversation" }],
});
// Sent while the first prompt runs: it waits for that turn to end.
const second = yield* agy.adapter.sendTurn({
const sending = yield* agy.adapter
.sendTurn({
threadId: agy.threadId,
input: "plan it",
interactionMode: "plan",
attachments: [],
})
.pipe(Effect.forkScoped);
yield* agy.waitFor((events) => events.some((event) => event.type === "turn.started"));
const turnId = agy.events.find((event) => event.type === "turn.started")!.turnId!;
const steering = yield* agy.adapter.steerTurn!({
threadId: agy.threadId,
input: "and then lint",
attachments: [],
});
yield* agy.waitFor((events) => completedTurns(events).length === 2);
expect(completedTurns(agy.events).map((event) => event.turnId)).toEqual([
first.turnId,
second.turnId,
]);
expectedTurnId: turnId,
input: "also check tests",
}).pipe(Effect.exit, Effect.forkScoped);
const first = yield* Fiber.join(sending);
expect(first.undelivered).toBe(true);
expect(Exit.isFailure(yield* Fiber.join(steering))).toBe(true);
yield* agy.waitFor((events) => completedTurns(events).length === 1);
expect(completedTurns(agy.events)[0]?.payload.state).toBe("failed");
const prompts = (yield* agy.frames()).filter((frame) => frame.method === "session/prompt");
expect(prompts).toHaveLength(2);
expect(prompts).toHaveLength(0);
}).pipe(Effect.scoped, Effect.provide(testServices)),
);
});
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/provider/antigravity/AntigravityTurns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export const ANTIGRAVITY_SILENT_WORK_LIMIT = Duration.minutes(30);
* Whether a message sent mid-turn steers the running turn (a second
* `session/prompt`, 1.5.0+). Off, it waits for the turn to end.
*/
// Off until this is fixed: a steer is recorded as an accepted follow-up before the sender writes it, so a process exit then shows one the agent never got.
export const ANTIGRAVITY_STEERS = false;
export const ANTIGRAVITY_STEERS = true;

const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value);
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/ChatView.browser-harness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { closeProjectSetupDialog } from "./ProjectSetupDialog";
import { closeThreadMoveDialog } from "./ThreadMoveDialog";
import { closeMoveThreadsDialog } from "./MoveThreadsDialog";
import { useComposerDraftStore, DraftId } from "../composerDraftStore";
import { resetFollowUpDeliveryOverridesForTests } from "../followUpDeliveryStore";
import { connectEnvironmentBrowserHost } from "./browser/previewAutomationHost";
import { closeThreadBrowser, useBrowserPageWatchers } from "./browser/BrowserHostLayer";
import {
Expand Down Expand Up @@ -3489,6 +3490,7 @@ export function registerChatViewSuiteHooks(): void {
resetSavedEnvironmentRegistryStoreForTests();
resetSavedEnvironmentRuntimeStoreForTests();
resetRightPanelTabsForTests();
resetFollowUpDeliveryOverridesForTests();
__resetComposerPullRequestDismissalsForTests();
Reflect.deleteProperty(window, "desktopBridge");
useComposerDraftStore.setState({
Expand Down
Loading
Loading