Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
type WorktreeSubmodules,
PROJECT_SCOPED_SERVER_SETTING_KEYS,
type ProjectScopedServerSettingKey,
type ProviderProfileId,
} from "@t3tools/contracts";
import { commonProviderProfiles } from "@t3tools/shared/projectSettings";
import { useRef, useState, type ComponentProps } from "react";
import { Alert, Platform, Pressable, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
Expand Down Expand Up @@ -46,7 +48,12 @@ const PAGE_TITLES: Record<SettingsPage, string> = {
};

const PAGE_PROJECT_KEYS: Record<SettingsPage, readonly ProjectScopedServerSettingKey[]> = {
"new-threads": ["defaultThreadEnvMode", "worktreeSubmodules", "defaultRuntimeMode"],
"new-threads": [
"providerProfileId",
"defaultThreadEnvMode",
"worktreeSubmodules",
"defaultRuntimeMode",
],
"source-control": ["defaultAutoPull", "newWorktreesStartFromOrigin"],
"agent-behavior": ["responseStreamingMode", "enableAgentBrowserAccess"],
maintenance: ["continueThreadsAfterServerUpdate"],
Expand Down Expand Up @@ -208,6 +215,12 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
(target) =>
target.environment.serverConfig.environment.capabilities.threadRestartContinuation === true,
);
// Profiles are per environment: offer only those every write target
// defines, so one choice never saves an id some environment lacks.
const profileChoices = commonProviderProfiles(targets.map((target) => target.settings));
const anyTargetHasProfiles = targets.some(
(target) => Object.keys(target.settings.providerProfiles).length > 0,
);
const disabledFor = (key: string) =>
disabled ||
(projectSelected &&
Expand Down Expand Up @@ -250,6 +263,45 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
) : null}
{props.page === "new-threads" ? (
<>
{anyTargetHasProfiles ? (
<SettingsSection
title="Provider profile"
trailing={
pendingWrites === 0 && isMixed("providerProfileId") ? (
<MixedValuesLabel projectSelected={projectSelected} />
) : null
}
>
{[
...profileChoices.map(([id, profile]) => ({
id: id as ProviderProfileId | null,
label: profile.name,
description: `${profile.instanceIds.length} provider${profile.instanceIds.length === 1 ? "" : "s"}`,
})),
{
id: null,
label: "No profile",
description:
profileChoices.length === 0
? "The selected environments share no profile. Filter to one environment to pick one of its profiles."
: "Offer every provider in the model picker.",
},
].map((choice, index) => (
<ChoiceRow
key={choice.id === null ? "no-profile" : `profile:${choice.id}`}
label={choice.label}
description={choice.description}
selected={
!isMixed("providerProfileId") &&
reference.settings.providerProfileId === choice.id
}
separated={index > 0}
disabled={disabledFor("providerProfileId")}
onPress={() => write({ providerProfileId: choice.id })}
/>
))}
</SettingsSection>
) : null}
<SettingsSection
title="Default workspace"
trailing={
Expand Down
14 changes: 12 additions & 2 deletions apps/mobile/src/features/threads/new-task-flow-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ThreadId,
} from "@t3tools/contracts";
import { sanitizeNewRefName } from "@t3tools/shared/git";
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
import { resolveProjectSettings, resolveProviderProfile } from "@t3tools/shared/projectSettings";
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
import * as Arr from "effect/Array";
import { pipe } from "effect/Function";
Expand Down Expand Up @@ -486,22 +486,32 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
selectedEnvironmentServerConfig,
projectSettings.settings.defaultModelSelection,
);
const providerProfile = useMemo(
() => resolveProviderProfile(projectSettings.settings),
[projectSettings.settings],
);
const storedStickyModelSelection = useStickyComposerModelSelection();
// The last app-wide pick only carries over when the project's profile has it.
const stickyModelSelection = resolveDefaultableModelSelection(
selectedEnvironmentServerConfig,
storedStickyModelSelection,
storedStickyModelSelection &&
(!providerProfile || providerProfile.instanceIdSet.has(storedStickyModelSelection.instanceId))
? storedStickyModelSelection
: null,
);
const modelOptions = useMemo(
() =>
buildModelOptions(
selectedEnvironmentServerConfig,
draftModelSelection ?? projectDefaultModelSelection ?? stickyModelSelection,
providerProfile,
),
[
selectedEnvironmentServerConfig,
draftModelSelection,
projectDefaultModelSelection,
stickyModelSelection,
providerProfile,
],
);

Expand Down
27 changes: 27 additions & 0 deletions apps/mobile/src/lib/modelOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,31 @@ describe("mobile model options", () => {
}),
).toBeNull();
});

it("offers only the provider profile's instances plus an outside current pick", () => {
const provider = (instanceId: string) => ({
instanceId,
driver: "claudeAgent",
displayName: instanceId,
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [{ slug: "opus", name: "Opus", isCustom: false, capabilities: null }],
});
const config = {
providers: [provider("cc-a"), provider("cc-b")],
} as unknown as ServerConfig;
const profile = { instanceIdSet: new Set(["cc-a"]) };

expect(buildModelOptions(config, null, profile).map((option) => option.key)).toEqual([
"cc-a:opus",
]);
expect(
buildModelOptions(
config,
{ instanceId: ProviderInstanceId.make("cc-b"), model: "opus" },
profile,
).map((option) => option.key),
).toEqual(["cc-a:opus", "cc-b:opus"]);
});
});
6 changes: 6 additions & 0 deletions apps/mobile/src/lib/modelOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,20 @@ export function resolveNewTaskModelSelection(input: {
);
}

/**
* With a provider profile, only its instances are offered; the fallback
* selection is still listed so a pick outside the profile stays visible.
*/
export function buildModelOptions(
config: T3ServerConfig | null | undefined,
fallbackModelSelection: ModelSelection | null,
providerProfile?: { readonly instanceIdSet: ReadonlySet<string> } | null,
): ReadonlyArray<ModelOption> {
const options = new Map<string, ModelOption>();

for (const provider of config?.providers ?? []) {
if (
(providerProfile && !providerProfile.instanceIdSet.has(provider.instanceId)) ||
!provider.enabled ||
!provider.installed ||
provider.auth.status === "unauthenticated" ||
Expand Down
61 changes: 59 additions & 2 deletions apps/server/src/automation/AutomationService.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {
type AutomationConfig,
ProjectId,
ProviderDriverKind,
ProviderInstanceId,
ProviderProfileId,
type ServerProvider,
type ServerSettings,
type OrchestrationCommand,
type OrchestrationProjectShell,
} from "@t3tools/contracts";
Expand All @@ -21,6 +25,7 @@ import { OrchestrationEngineService } from "../orchestration/Services/Orchestrat
import { ProjectionSnapshotQuery } from "../orchestration/Services/ProjectionSnapshotQuery.ts";
import { ThreadDeletionReactor } from "../orchestration/Services/ThreadDeletionReactor.ts";
import { ProjectSetupScriptRunner } from "../project/ProjectSetupScriptRunner.ts";
import { ProviderRegistry } from "../provider/Services/ProviderRegistry.ts";
import { ServerSettingsService } from "../serverSettings.ts";
import { GitHubCli } from "../sourceControl/GitHubCli.ts";
import * as AutomationService from "./AutomationService.ts";
Expand Down Expand Up @@ -54,6 +59,8 @@ const makeLayer = (input: {
readonly stateDir: string;
readonly commands: Ref.Ref<ReadonlyArray<OrchestrationCommand>>;
readonly project: OrchestrationProjectShell | null;
readonly settings?: Parameters<typeof ServerSettingsService.layerTest>[0];
readonly providers?: ReadonlyArray<ServerProvider>;
}) =>
AutomationService.layer.pipe(
Layer.provide(
Expand All @@ -72,7 +79,8 @@ const makeLayer = (input: {
Layer.mock(GitWorkflowService)({}),
Layer.mock(ProjectSetupScriptRunner)({}),
Layer.mock(GitHubCli)({}),
ServerSettingsService.layerTest(),
Layer.mock(ProviderRegistry)({ getProviders: Effect.succeed(input.providers ?? []) }),
ServerSettingsService.layerTest(input.settings),
ServerConfig.layerTest(process.cwd(), input.stateDir),
),
),
Expand All @@ -88,13 +96,14 @@ const withService = <A, E>(
readonly commands: Ref.Ref<ReadonlyArray<OrchestrationCommand>>;
},
) => Effect.Effect<A, E>,
environment: Pick<Parameters<typeof makeLayer>[0], "settings" | "providers"> = {},
) =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const stateDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-automations-" });
const commands = yield* Ref.make<ReadonlyArray<OrchestrationCommand>>([]);
const service = yield* AutomationService.AutomationService.pipe(
Effect.provide(makeLayer({ stateDir, commands, project })),
Effect.provide(makeLayer({ stateDir, commands, project, ...environment })),
);
return yield* body(service, { stateDir, commands });
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer));
Expand Down Expand Up @@ -169,4 +178,52 @@ describe("AutomationService", () => {
}),
),
);

it.effect(
"an automation on a profiled project runs inside the profile, not on the environment default",
() => {
const acmeClaude = ProviderInstanceId.make("cc_a");
const otherClaude = ProviderInstanceId.make("cc_b");
const acme = ProviderProfileId.make("acme");
const provider = (instanceId: ProviderInstanceId) =>
({
instanceId,
driver: ProviderDriverKind.make("claudeAgent"),
enabled: true,
installed: true,
status: "ready",
auth: { status: "authenticated" },
models: [{ slug: "opus", name: "Opus", isCustom: false, isDefault: true }],
}) as unknown as ServerProvider;
const settings: Partial<ServerSettings> = {
providerInstances: {
[acmeClaude]: { driver: ProviderDriverKind.make("claudeAgent") },
[otherClaude]: { driver: ProviderDriverKind.make("claudeAgent") },
},
// The environment default belongs to another profile's account.
defaultModelSelection: { instanceId: otherClaude, model: "opus" },
providerProfiles: {
[acme]: { name: "Acme", instanceIds: [acmeClaude], defaultModelSelection: null },
},
projectSettingsOverrides: { [PROJECT_ID]: { providerProfileId: acme } },
};
return withService(
PROJECT,
(service, { commands }) =>
Effect.gen(function* () {
const created = yield* service.create({ ...CONFIG, modelSelection: null });
const run = yield* service.runNow(created.id);
assert.strictEqual(run.error, null);
const turn = (yield* Ref.get(commands)).find(
(command) => command.type === "thread.turn.start",
);
assert.deepStrictEqual(turn?.type === "thread.turn.start" && turn.modelSelection, {
instanceId: acmeClaude,
model: "opus",
});
}),
{ settings, providers: [provider(otherClaude), provider(acmeClaude)] },
);
},
);
});
21 changes: 18 additions & 3 deletions apps/server/src/automation/AutomationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import {
latestTriggerAt,
} from "@t3tools/shared/automationSchedule";
import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git";
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
import {
resolveProjectSettings,
resolveProviderProfile,
resolveProviderProfileFallbackModelSelection,
} from "@t3tools/shared/projectSettings";
import { fromJsonStringPretty } from "@t3tools/shared/schemaJson";
import * as Cause from "effect/Cause";
import * as Clock from "effect/Clock";
Expand All @@ -56,6 +60,7 @@ import * as OrchestrationEngine from "../orchestration/Services/OrchestrationEng
import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
import { ThreadDeletionReactor } from "../orchestration/Services/ThreadDeletionReactor.ts";
import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.ts";
import * as ProviderRegistry from "../provider/Services/ProviderRegistry.ts";
import { forkParked } from "../serverActivation.ts";
import * as ServerSettings from "../serverSettings.ts";
import * as GitHubCli from "../sourceControl/GitHubCli.ts";
Expand Down Expand Up @@ -145,6 +150,7 @@ const make = Effect.gen(function* () {
const setupScriptRunner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
const settingsService = yield* ServerSettings.ServerSettingsService;
const gitHubCli = yield* GitHubCli.GitHubCli;
const providerRegistry = yield* ProviderRegistry.ProviderRegistry;

const filePath = path.join(config.stateDir, "automations.json");
// Captured so writes from RPC handlers and the scheduler fiber need no extra services.
Expand Down Expand Up @@ -294,10 +300,19 @@ const make = Effect.gen(function* () {
return yield* failWith("The automation's project no longer exists.");
}
const settings = yield* settingsService.getSettings;
const projectSettings = resolveProjectSettings(settings, project.id, project).settings;
const providerProfile = resolveProviderProfile(projectSettings);
// With a profile, a missing default resolves inside it; the environment
// default may belong to another profile's account.
const modelSelection =
automation.modelSelection ??
resolveProjectSettings(settings, project.id, project).settings.defaultModelSelection ??
settings.defaultModelSelection;
projectSettings.defaultModelSelection ??
(providerProfile
? resolveProviderProfileFallbackModelSelection(
providerProfile,
yield* providerRegistry.getProviders,
)
: settings.defaultModelSelection);
if (!modelSelection) {
return yield* failWith("Choose a model for this automation.");
}
Expand Down
17 changes: 13 additions & 4 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import {
projectScriptRuntimeEnv,
resolveProjectScripts,
} from "@t3tools/shared/projectScripts";
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
import { resolveProjectSettings, resolveProviderProfile } from "@t3tools/shared/projectSettings";
import { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";
import { truncate } from "@t3tools/shared/String";
import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";
Expand Down Expand Up @@ -259,6 +259,7 @@ import {
applyProviderInstanceSettings,
deriveProviderInstanceEntries,
NO_PROVIDER_MODEL_SELECTION,
leadWithProviderProfile,
sortProviderInstanceEntries,
} from "../providerInstances";
import {
Expand Down Expand Up @@ -2277,6 +2278,10 @@ export default function ChatView(props: ChatViewProps) {
runProjectCloneAction,
]);
const activeProjectDefaultModelSelection = activeProjectSettings.settings.defaultModelSelection;
const activeProviderProfile = useMemo(
() => resolveProviderProfile(activeProjectSettings.settings),
[activeProjectSettings.settings],
);
const handleNewThreadInActiveProject = useCallback(() => {
startNewThreadForProject(activeProjectRef, handleNewThread);
}, [activeProjectRef, handleNewThread]);
Expand Down Expand Up @@ -2871,10 +2876,13 @@ export default function ChatView(props: ChatViewProps) {
]);
const providerInstanceEntries = useMemo(
() =>
sortProviderInstanceEntries(
applyProviderInstanceSettings(deriveProviderInstanceEntries(providerStatuses), settings),
leadWithProviderProfile(
sortProviderInstanceEntries(
applyProviderInstanceSettings(deriveProviderInstanceEntries(providerStatuses), settings),
),
activeProviderProfile,
),
[providerStatuses, settings],
[activeProviderProfile, providerStatuses, settings],
);
const { selectedProviderEntry, requestedDriverKind } = useMemo(
() =>
Expand Down Expand Up @@ -10098,6 +10106,7 @@ export default function ChatView(props: ChatViewProps) {
providerStatuses={providerStatuses as ServerProvider[]}
providerCatalogKnown={serverConfig !== null}
activeProjectDefaultModelSelection={activeProjectDefaultModelSelection}
activeProviderProfile={activeProviderProfile}
activeThreadModelSelection={activeThread?.modelSelection}
activeContextWindow={activeContextWindow}
compactThreadUnavailable={compactThreadUnavailable}
Expand Down
Loading
Loading