Skip to content

Commit eb97d82

Browse files
feat: text generators let model APIs write titles, commits, and transcript cleanup (#33147)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 1d5404a commit eb97d82

40 files changed

Lines changed: 2482 additions & 144 deletions

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const RPC_AGGREGATES = {
8888
[WS_METHODS.serverGetResourceTelemetryHistory]: "server",
8989
[WS_METHODS.serverRetryResourceTelemetry]: "server",
9090
[WS_METHODS.serverCheckOtlpEndpoint]: "server",
91+
[WS_METHODS.serverListTextGeneratorModels]: "server",
9192
[WS_METHODS.serverPrepareTriage]: "server",
9293
[WS_METHODS.serverGetUsageSummary]: "server",
9394
[WS_METHODS.serverRefreshUsageRates]: "server",

‎apps/server/src/policy/managedProviders.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ export function makeManagedProviders(
389389
const result: ServerSettings = {
390390
...settings,
391391
providerInstances: providerInstances as ServerSettings["providerInstances"],
392+
// An allow-list names agent drivers; text generators would send code to any other API.
393+
...(allowed === undefined ? {} : { textGenerators: {} }),
392394
sourceControlWriterModelSelection: allowedSelection(
393395
settings,
394396
settings.sourceControlWriterModelSelection,

‎apps/server/src/serverSettings.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,17 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("server settings"
17511751
const antigravity = ProviderInstanceId.make("antigravity");
17521752
const openCode = ProviderInstanceId.make("opencode");
17531753
const hub = UsageLimitSourceId.make("hub");
1754+
const router = ProviderInstanceId.make("openrouter");
17541755
const withUsage = yield* serverSettings.updateSettings({
17551756
cloudSpeechCredentials: { openai: usageReference, xai: "literal-fixture" },
1757+
textGenerators: {
1758+
[router]: {
1759+
kind: "openaiCompatible",
1760+
baseUrl: "https://openrouter.ai/api/v1",
1761+
apiKey: usageReference,
1762+
enabled: true,
1763+
},
1764+
},
17561765
usageLimitSources: {
17571766
[hub]: {
17581767
kind: "cliproxy",
@@ -1805,6 +1814,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("server settings"
18051814
});
18061815
assert.equal(legacy.sourceControlHosts.bitbucket?.accessToken, SECRET_REDACTED);
18071816
assert.equal(legacy.usageLimitSources[hub]?.managementKey, SECRET_REDACTED);
1817+
assert.equal(legacy.textGenerators[router]?.apiKey, SECRET_REDACTED);
18081818
assert.equal(legacy.easDeviceHosts[0]?.accessToken, SECRET_REDACTED);
18091819
assert.equal(legacy.simlockDeviceHosts[0]?.agentToken, SECRET_REDACTED);
18101820
const configOf = (settings: ServerSettings, id: ProviderInstanceId) =>
@@ -1815,6 +1825,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("server settings"
18151825
cloudSpeechCredentials: legacy.cloudSpeechCredentials,
18161826
sourceControlHosts: legacy.sourceControlHosts,
18171827
usageLimitSources: legacy.usageLimitSources,
1828+
textGenerators: legacy.textGenerators,
18181829
easDeviceHosts: legacy.easDeviceHosts,
18191830
simlockDeviceHosts: legacy.simlockDeviceHosts,
18201831
providerInstances: legacy.providerInstances,
@@ -1825,6 +1836,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("server settings"
18251836
"ghe.acme.test": "ghp_ghe",
18261837
});
18271838
assert.deepEqual(echoed.usageLimitSources[hub]?.managementKey, usageReference);
1839+
assert.deepEqual(echoed.textGenerators[router]?.apiKey, usageReference);
18281840
assert.deepEqual(echoed.cloudSpeechCredentials, {
18291841
openai: usageReference,
18301842
xai: "literal-fixture",
@@ -1930,6 +1942,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("server settings"
19301942
"easDeviceHosts.[].accessToken",
19311943
"simlockDeviceHosts.[].agentToken",
19321944
"usageLimitSources.*.managementKey",
1945+
"textGenerators.*.apiKey",
19331946
]);
19341947
}),
19351948
);

‎apps/server/src/settingsSecrets.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type ServerSettings,
99
type SettingsSecretValue,
1010
SimlockDeviceHostConfig,
11+
TextGeneratorConfig,
1112
UsageLimitSourceConfig,
1213
isSecretReference,
1314
secretSettingsFields,
@@ -46,6 +47,7 @@ const providerSecretFields = new Map([
4647
),
4748
]);
4849
const usageLimitSecretFields = secretSettingsFields(UsageLimitSourceConfig);
50+
const textGeneratorSecretFields = secretSettingsFields(TextGeneratorConfig);
4951
const voiceSecretFields = secretSettingsFields(CloudSpeechCredentials);
5052
const easDeviceHostSecretFields = secretSettingsFields(EasDeviceHostConfig);
5153
const simlockDeviceHostSecretFields = secretSettingsFields(SimlockDeviceHostConfig);
@@ -209,6 +211,19 @@ function mapSecretFieldGroups(
209211
]),
210212
) as ServerSettings["usageLimitSources"];
211213

214+
const textGenerators = Object.fromEntries(
215+
Object.entries(settings.textGenerators).map(([id, generator]) => [
216+
id,
217+
mapFields(
218+
generator,
219+
textGeneratorSecretFields,
220+
(field, serverHost) =>
221+
`text-generator-${encode(id)}-${encode(field)}` +
222+
(serverHost === null ? "" : `-${encode(serverHost)}`),
223+
),
224+
]),
225+
) as ServerSettings["textGenerators"];
226+
212227
const easDeviceHosts = settings.easDeviceHosts.map(
213228
(host) =>
214229
mapFields(
@@ -242,6 +257,7 @@ function mapSecretFieldGroups(
242257
providerInstances,
243258
sourceControlHosts,
244259
usageLimitSources,
260+
textGenerators,
245261
easDeviceHosts,
246262
simlockDeviceHosts,
247263
};

‎apps/server/src/sourceControl/sourceControlHostSecrets.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ it.effect("reads a collected reference again once it is invalidated", () =>
178178
sourceControlHosts: hosts,
179179
cloudSpeechCredentials: { openai: source("voice#key"), xai: "", openrouter: "" },
180180
usageLimitSources,
181+
textGenerators: {},
181182
easDeviceHosts,
182183
simlockDeviceHosts,
183184
}),

‎apps/server/src/sourceControl/sourceControlHostSecrets.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const invalidateSettingsSecrets = Effect.fn("SettingsSecrets.invalidate")
120120
ServerSettings,
121121
| "sourceControlHosts"
122122
| "usageLimitSources"
123+
| "textGenerators"
123124
| "easDeviceHosts"
124125
| "simlockDeviceHosts"
125126
| "cloudSpeechCredentials"
@@ -131,6 +132,9 @@ export const invalidateSettingsSecrets = Effect.fn("SettingsSecrets.invalidate")
131132
Effect.map((current) => [
132133
...collectSourceControlHostSecretReferences(current.sourceControlHosts),
133134
...collectUsageLimitSecretReferences(current.usageLimitSources),
135+
...Object.values(current.textGenerators).flatMap(({ apiKey }) =>
136+
isSecretReference(apiKey) ? [apiKey] : [],
137+
),
134138
...collectDeviceHostSecretReferences(current),
135139
...Object.values(current.cloudSpeechCredentials).filter(isSecretReference),
136140
]),

‎apps/server/src/textGeneration/CodexTextGeneration.test.ts‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { CodexSettings, ProviderInstanceId } from "@t3tools/contracts";
2727
import * as ServerConfig from "../config.ts";
2828
import { makeProcessProbe, processProbeSource } from "../testUtils/processProbe.ts";
2929
import * as TextGeneration from "./TextGeneration.ts";
30+
import * as TextGenerators from "./TextGenerators.ts";
3031
import { makeCodexTextGeneration } from "./CodexTextGeneration.ts";
3132
import { writeFakeCli } from "@t3tools/provider-testing/fakeCli";
3233
const decodeCodexSettings = Schema.decodeSync(CodexSettings);
@@ -625,6 +626,7 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
625626
[fallback]: { driver: ProviderDriverKind.make("claudeAgent"), config: {} },
626627
},
627628
}),
629+
Layer.mock(TextGenerators.TextGenerators)({ runner: () => Effect.undefined }),
628630
Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
629631
resolveLink: () => Effect.die("unused"),
630632
}),
@@ -652,3 +654,90 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
652654
]);
653655
}),
654656
);
657+
658+
it.effect(
659+
"a review guide aimed at a text generator falls back to an agent that can read the checkout",
660+
() =>
661+
Effect.gen(function* () {
662+
const claude = ProviderInstanceId.make("claudeAgent");
663+
const driver = ProviderDriverKind.make("claudeAgent");
664+
const calls: ModelSelection[] = [];
665+
const instance = {
666+
instanceId: claude,
667+
driverKind: driver,
668+
continuationIdentity: { driverKind: driver, continuationKey: claude },
669+
displayName: undefined,
670+
enabled: true,
671+
snapshot: {
672+
getSnapshot: Effect.succeed<ServerProvider>({
673+
instanceId: claude,
674+
driver,
675+
enabled: true,
676+
installed: true,
677+
status: "ready",
678+
auth: { status: "authenticated" },
679+
version: null,
680+
checkedAt: "1970-01-01T00:00:00Z",
681+
models: [],
682+
slashCommands: [],
683+
skills: [],
684+
}),
685+
} as ProviderInstance["snapshot"],
686+
orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
687+
textGeneration: TextGeneration.TextGeneration.of({
688+
generateCommitMessage: () => Effect.die("unused"),
689+
generatePrContent: () => Effect.die("unused"),
690+
generateBranchName: () => Effect.die("unused"),
691+
generateThreadTitle: () => Effect.die("unused"),
692+
generateTranscriptionPostProcessing: () => Effect.die("unused"),
693+
generateReviewGuide: (input) =>
694+
Effect.sync(() => {
695+
calls.push(input.modelSelection);
696+
return {} as TextGeneration.ReviewGuideGenerationResult;
697+
}),
698+
}),
699+
} satisfies ProviderInstance;
700+
const serviceWith = (instances: ReadonlyArray<ProviderInstance>) =>
701+
TextGeneration.make.pipe(
702+
Effect.provide(
703+
Layer.mergeAll(
704+
Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
705+
listInstances: Effect.succeed(instances),
706+
getInstance: (id) =>
707+
Effect.succeed(instances.find((candidate) => candidate.instanceId === id)),
708+
}),
709+
ServerSettings.layerTest({}),
710+
Layer.mock(TextGenerators.TextGenerators)({
711+
runner: (id) =>
712+
Effect.succeed(
713+
id === "openrouter"
714+
? () => Effect.die("a text generator cannot investigate")
715+
: undefined,
716+
),
717+
}),
718+
Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
719+
resolveLink: () => Effect.die("unused"),
720+
}),
721+
),
722+
),
723+
);
724+
const input = {
725+
cwd: "/tmp",
726+
number: 1,
727+
title: "Change",
728+
description: "",
729+
baseBranch: "main",
730+
baseCommit: "abc",
731+
settledReview: "",
732+
modelSelection: { instanceId: ProviderInstanceId.make("openrouter"), model: "some/model" },
733+
};
734+
yield* (yield* serviceWith([instance])).generateReviewGuide(input);
735+
expect(calls.map((selection) => selection.instanceId)).toEqual([claude]);
736+
737+
// With no agent ready, it says what is missing instead of looking up a provider by that id.
738+
const failure = yield* Effect.flip((yield* serviceWith([])).generateReviewGuide(input));
739+
expect(failure.detail).toMatch(
740+
/^Review guides need a coding agent that can read the checkout/,
741+
);
742+
}),
743+
);

‎apps/server/src/textGeneration/TextGeneration.ts‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import * as ProviderInstanceRegistry from "../provider/ProviderInstanceRegistry.
2121
import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
2222
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
2323
import * as ThreadTitleLinks from "./ThreadTitleLinks.ts";
24+
import * as TextGenerators from "./TextGenerators.ts";
25+
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
2426

2527
export type {
2628
BranchNameGenerationInput,
@@ -75,6 +77,7 @@ export const make = Effect.gen(function* () {
7577
const registry = yield* ProviderInstanceRegistry.ProviderInstanceRegistry;
7678
const sourceControl = yield* SourceControlProviderRegistry.SourceControlProviderRegistry;
7779
const serverSettings = yield* ServerSettings.ServerSettingsService;
80+
const textGenerators = yield* TextGenerators.TextGenerators;
7881
const generate = Effect.fn("TextGeneration.generate")(function* <A>(
7982
operation: TextGenerationOp,
8083
selection: ModelSelection,
@@ -83,6 +86,17 @@ export const make = Effect.gen(function* () {
8386
modelSelection: ModelSelection,
8487
) => Effect.Effect<A, TextGenerationError>,
8588
) {
89+
const textGenerator = yield* textGenerators.runner(selection.instanceId);
90+
// A review guide reaches a text generator only through a fallback; it needs an agent instead.
91+
const textGeneratorId = selection.instanceId;
92+
const textGeneratorCannotRun =
93+
textGenerator !== undefined && operation === "generateReviewGuide";
94+
if (textGenerator !== undefined && !textGeneratorCannotRun) {
95+
return yield* invoke(
96+
TextGenerationOperations.fromRunner("TextGenerator", textGenerator),
97+
selection,
98+
);
99+
}
86100
const snapshots = yield* registry.listInstances.pipe(
87101
Effect.flatMap((instances) =>
88102
Effect.forEach(instances, (instance) => instance.snapshot.getSnapshot),
@@ -92,9 +106,10 @@ export const make = Effect.gen(function* () {
92106
const selected = snapshots.find((provider) => provider.instanceId === selection.instanceId);
93107
// Only a failed probe counts: a pending one is also not installed yet.
94108
const unusable =
95-
selected?.enabled === true &&
96-
selected.status === "error" &&
97-
(!selected.installed || selected.auth.status === "unauthenticated");
109+
textGeneratorCannotRun ||
110+
(selected?.enabled === true &&
111+
selected.status === "error" &&
112+
(!selected.installed || selected.auth.status === "unauthenticated"));
98113
if (unusable || exhaustedUsageWindow(selected, now, selection.model)) {
99114
const settings = yield* serverSettings.getSettings.pipe(
100115
Effect.mapError(
@@ -127,6 +142,13 @@ export const make = Effect.gen(function* () {
127142
{ includeConfiguredInstances: true },
128143
) ?? selection;
129144
}
145+
if (textGeneratorCannotRun && selection.instanceId === textGeneratorId) {
146+
return yield* new TextGenerationError({
147+
operation,
148+
detail:
149+
"Review guides need a coding agent that can read the checkout. None is ready. Pick Codex or Claude as the review guide model in Settings → Source control.",
150+
});
151+
}
130152
return yield* resolveInstance(registry, operation, selection.instanceId).pipe(
131153
Effect.flatMap((service) => invoke(service, selection)),
132154
);
@@ -187,4 +209,6 @@ export const make = Effect.gen(function* () {
187209
});
188210
});
189211

190-
export const layer = Layer.effect(TextGeneration, make);
212+
export const layer = Layer.effect(TextGeneration, make).pipe(
213+
Layer.provideMerge(TextGenerators.layer),
214+
);

0 commit comments

Comments
 (0)