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/evals/toolUse/runCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const decodeCodexSettings = Schema.decodeEffect(CodexSettings);
*/
export const EVAL_SERVER_SETTINGS = {
codexSuggestions: false,
antigravitySuggestions: false,
enableAgentPages: false,
enableCommandRequests: false,
} as const;
Expand Down
5 changes: 4 additions & 1 deletion apps/server/integration/replay/runReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const decodeCodexSettings = Schema.decodeEffect(CodexSettings);
const decodeClaudeSettings = Schema.decodeEffect(ClaudeSettings);

/** Settings that would make our code send requests at times a replay can't reproduce. */
const REPLAY_SERVER_SETTINGS = { codexSuggestions: false } as const;
const REPLAY_SERVER_SETTINGS = {
codexSuggestions: false,
antigravitySuggestions: false,
} as const;

type ProviderMode =
| { readonly kind: "replay"; readonly transcript: Transcript }
Expand Down
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, 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.

After a reply to your message, Claude or Codex 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:threads.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:threads.codexSuggestions} turns them off.
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.

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
69 changes: 67 additions & 2 deletions apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@
*/
import { join } from "node:path";

import * as Clock from "effect/Clock";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Option from "effect/Option";
import { HttpClient } from "effect/http";
import { ChildProcessSpawner } from "effect/process";

import { ServerConfig } from "../../config.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
import {
ANTIGRAVITY_DRIVER_KIND,
ANTIGRAVITY_PRESENTATION,
makeAntigravityDescriptor,
validateAntigravityRuntime,
} from "../acp/AntigravityAcpSupport.ts";
import { type AcpProviderDriverEnv, makeAcpProviderDriver } from "../acp/AcpProviderDriver.ts";
import { sampleAcpPromptSuggestion } from "../acp/AcpTextGeneration.ts";
import {
isAntigravitySuggestionUsageNearLimit,
selectAntigravitySuggestionTarget,
} from "../antigravity/AntigravityPromptSuggestions.ts";
import { buildTranscriptPromptSuggestionPrompt } from "../promptSuggestions.ts";
import { antigravityReleaseFor } from "../antigravity/AntigravityRelease.ts";
import {
type AntigravityReleaseSource,
Expand Down Expand Up @@ -53,7 +62,7 @@ import type { ProviderDriver } from "../ProviderDriver.ts";
import { AntigravitySettings } from "@threadlines/contracts";
import * as Schema from "effect/Schema";

export type AntigravityDriverEnv = AcpProviderDriverEnv;
export type AntigravityDriverEnv = AcpProviderDriverEnv | ServerSettingsService;

/** Linux's C library: Alpine and other musl systems get Google's musl build. */
function hostLibc(): "glibc" | "musl" {
Expand Down Expand Up @@ -157,7 +166,63 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
skillsCwd: serverConfig.cwd,
usage,
});
const instance = yield* makeAcpProviderDriver(descriptor).create(input);
const serverSettings = yield* ServerSettingsService;
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const fileSystem = yield* FileSystem.FileSystem;
const instance = yield* makeAcpProviderDriver(descriptor, {
promptSuggestions: ({ settings: effectiveSettings, environment, getSnapshot }) => {
const isAllowed = (targetModelName: string | undefined) =>
Effect.gen(function* () {
const on = yield* serverSettings.getSettings.pipe(
Effect.map((current) => current.antigravitySuggestions),
Effect.orElseSucceed(() => false),
);
if (!on) return false;
const current = yield* getSnapshot;
return !isAntigravitySuggestionUsageNearLimit(
current.accountUsage,
targetModelName,
yield* Clock.currentTimeMillis,
);
});
return Effect.succeed({
shouldSuggest: (model) =>
Effect.gen(function* () {
const current = yield* getSnapshot;
const target = selectAntigravitySuggestionTarget(current.models, model);
return yield* isAllowed(target.modelName);
}),
sample: ({ cwd, model, messages }) =>
Effect.gen(function* () {
const prompt = buildTranscriptPromptSuggestionPrompt(messages);
if (prompt === undefined) return undefined;
// Select and quota-check one target from a single snapshot so
// a catalog refresh cannot switch models between check and call.
const current = yield* getSnapshot;
const target = selectAntigravitySuggestionTarget(current.models, model);
if (!(yield* isAllowed(target.modelName))) return undefined;
let checkedModelName = target.modelName;
const sampled = yield* sampleAcpPromptSuggestion({
descriptor,
settings: effectiveSettings,
environment,
commandSpawner,
fileSystem,
cwd,
prompt,
model: target.model,
options: target.options,
allowLiveModel: ({ name }) => {
checkedModelName = name;
return isAllowed(name);
},
});
if (sampled === undefined) return undefined;
return (yield* isAllowed(checkedModelName)) ? sampled : undefined;
}),
});
},
}).create(input);
usage.attach(instance.snapshot);
const builtEnvironment = providerInstanceEnvironmentKey(input.environment);
const authFlows = makeAntigravityAuthFlows({
Expand Down
88 changes: 14 additions & 74 deletions apps/server/src/provider/Layers/CodexPromptSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,25 @@
* composer, taken with Tab), made by Threadlines since Codex makes none of its
* own: after a turn the user started, one `thread/sample` answer from a hidden
* copy of the thread (CodexSessionRuntime.sampleThread) reusing its cached
* context. This module holds what is asked and what of the answer is kept.
* context. Shared prompt, sanitizer, and effort selection live in
* `provider/promptSuggestions.ts`.
*
* @module provider/Layers/CodexPromptSuggestions
*/
import type { ServerProviderModel } from "@threadlines/contracts";
import { findReasoningOptionDescriptor } from "@threadlines/shared/model";
import {
PROMPT_SUGGESTION_INSTRUCTIONS,
PROMPT_SUGGESTION_USAGE_CEILING_PERCENT,
modelReasoningEfforts,
sanitizePromptSuggestion,
selectSuggestionEffort,
} from "../promptSuggestions.ts";

/** What the hidden copy is asked (Codex takes at most 4,000 bytes). */
export const CODEX_SUGGESTION_PROMPT = `Stop being the assistant for a moment. Predict the next message the user will type in this conversation, so it can be offered in their message box.

Read what they asked for and how the last reply ended. Suggest what they would most likely send next, in their own words and style: a next step, a yes to an option the reply offered, a request to run, check, or fix something. Never suggest thanks, praise, or comments on the reply, and never speak as the assistant.

If there is no clear next message, reply with nothing. Otherwise reply with only the message: one line, at most 12 words, no quotes.`;
export const CODEX_SUGGESTION_PROMPT = PROMPT_SUGGESTION_INSTRUCTIONS;

/** No suggestions while any plan-wide usage window is this far used. */
export const CODEX_SUGGESTION_USAGE_CEILING_PERCENT = 90;

/**
* The reasoning a suggestion asks for, best first, among the levels a model
* lists: the answer is a dozen words, and the lowest levels can read thin.
*/
const SUGGESTION_EFFORTS = ["low", "minimal", "medium", "none"] as const;

const MAX_SUGGESTION_CHARS = 120;
const MAX_SUGGESTION_WORDS = 20;
const QUOTE_PAIRS: ReadonlyArray<readonly [string, string]> = [
['"', '"'],
["'", "'"],
["“", "”"],
["‘", "’"],
["`", "`"],
];
const NO_SUGGESTION = /^\(?(?:none|nothing|no suggestion|n\/a)\)?\.?$/iu;

/**
* The suggestion in a sample's answer, or undefined when it isn't one: no
* text, more than one line, too long for the box's one line, or a word for
* "nothing". Quotes the model wrapped it in come off.
*/
export function codexSuggestionFromSample(text: string | null | undefined): string | undefined {
let line = text?.trim() ?? "";
for (const [open, close] of QUOTE_PAIRS) {
if (line.length > 1 && line.startsWith(open) && line.endsWith(close)) {
line = line.slice(open.length, -close.length).trim();
break;
}
}
if (line.length === 0 || /[\r\n]/u.test(line) || NO_SUGGESTION.test(line)) return undefined;
if (line.length > MAX_SUGGESTION_CHARS) return undefined;
if (line.split(/\s+/u).length > MAX_SUGGESTION_WORDS) return undefined;
return line;
}
export const CODEX_SUGGESTION_USAGE_CEILING_PERCENT = PROMPT_SUGGESTION_USAGE_CEILING_PERCENT;

/**
* The reasoning effort to ask a sample for, from the levels the thread's
* model lists; none (the thread's own) when it lists none of the light ones
* or isn't known. Codex applies it only where the model can change effort
* without losing the cache.
*/
export function codexSuggestionEffort(
modelEfforts: ReadonlyArray<string> | undefined,
): string | undefined {
if (modelEfforts === undefined) return undefined;
return SUGGESTION_EFFORTS.find((effort) => modelEfforts.includes(effort));
}

/**
* The reasoning levels a model lists, from the instance's catalog; the
* catalog's default model stands for a turn that named none. Undefined for a
* model the catalog doesn't know.
*/
export function modelReasoningEfforts(
models: ReadonlyArray<ServerProviderModel>,
model: string | undefined,
): ReadonlyArray<string> | undefined {
const entry =
model === undefined
? models.find((candidate) => candidate.isDefault === true)
: models.find((candidate) => candidate.slug === model);
const descriptor = findReasoningOptionDescriptor(entry?.capabilities?.optionDescriptors ?? []);
return descriptor?.options.map((option) => option.id);
}
export const codexSuggestionFromSample = sanitizePromptSuggestion;
export const codexSuggestionEffort = selectSuggestionEffort;
export { modelReasoningEfforts };
Loading
Loading