GeezerVison is showing github.com — fix(server): Pi thread titles use linked PR context (#16210) · pingdotgg/t3code@4ae976d
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/textGeneration
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/textGeneration/AntigravityTextGeneration.ts +6-114Lines changed: 6 additions & 114 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { | 2 | | - type ModelSelection, | 3 | | - type ProviderSetupError, | 4 | | - TextGenerationError, | 5 | | -} from "@t3tools/contracts"; | 6 | | -import { formatGeneratedBranchName, sanitizeFeatureBranchName } from "@t3tools/shared/git"; | 7 | | -import { extractJsonObject } from "@t3tools/shared/schemaJson"; | | 1 | +import { type ProviderSetupError, TextGenerationError } from "@t3tools/contracts"; | 8 | 2 | import * as Deferred from "effect/Deferred"; | 9 | 3 | import * as Effect from "effect/Effect"; | 10 | 4 | import * as Exit from "effect/Exit"; | @@ -20,18 +14,7 @@ import { type AcpError, AcpRequestError } from "effect-acp/errors"; | 20 | 14 | import { applyAntigravityAcpModelSelection } from "../provider/acp/AntigravityAcpSupport.ts"; | 21 | 15 | import { removeAntigravitySessionFiles } from "../provider/acp/AntigravitySessionFiles.ts"; | 22 | 16 | import type { AcpSessionRuntime } from "../provider/acp/AcpSessionRuntime.ts"; | 23 | | -import type * as TextGeneration from "./TextGeneration.ts"; | 24 | | -import { | 25 | | - buildBranchNamePrompt, | 26 | | - buildCommitMessagePrompt, | 27 | | - buildPrContentPrompt, | 28 | | - buildThreadTitlePrompt, | 29 | | -} from "./TextGenerationPrompts.ts"; | 30 | | -import { | 31 | | - sanitizeCommitSubject, | 32 | | - sanitizePrTitle, | 33 | | - sanitizeThreadTitle, | 34 | | -} from "./TextGenerationUtils.ts"; | | 17 | +import * as TextGenerationOperations from "./TextGenerationOperations.ts"; | 35 | 18 |
| 36 | 19 | const ANTIGRAVITY_TIMEOUT_MS = 180_000; | 37 | 20 | const MAX_OUTPUT_CHARS = 128_000; | @@ -119,13 +102,9 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener | 119 | 102 | Effect.provideService(Path.Path, path), | 120 | 103 | ); | 121 | 104 |
| | 105 | + // Ignores `cwd`: the helper runs in an empty temp directory, away from the project. | 122 | 106 | const runAntigravityJson = Effect.fn("AntigravityTextGeneration.runJson")( | 123 | | - function* <S extends Schema.Top>(input: { | 124 | | - readonly operation: keyof TextGeneration.TextGeneration["Service"]; | 125 | | - readonly prompt: string; | 126 | | - readonly outputSchema: S; | 127 | | - readonly modelSelection: ModelSelection; | 128 | | - }) { | | 107 | + function* <S extends Schema.Top>(input: TextGenerationOperations.Request<S>) { | 129 | 108 | const { operation } = input; | 130 | 109 | const scope = yield* Scope.make(); | 131 | 110 | yield* Effect.addFinalizer((exit) => Scope.close(scope, exit)); | @@ -290,17 +269,7 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener | 290 | 269 | detail: "Antigravity returned empty text generation output.", | 291 | 270 | }); | 292 | 271 | } | 293 | | - const decodeOutput = Schema.decodeEffect(Schema.fromJsonString(input.outputSchema)); | 294 | | - return yield* decodeOutput(extractJsonObject(rawResult)).pipe( | 295 | | - Effect.mapError( | 296 | | - (cause) => | 297 | | - new TextGenerationError({ | 298 | | - operation, | 299 | | - detail: "Antigravity returned invalid structured output.", | 300 | | - cause, | 301 | | - }), | 302 | | - ), | 303 | | - ); | | 272 | + return yield* TextGenerationOperations.decodeJsonReply(input, "Antigravity", rawResult); | 304 | 273 | }).pipe( | 305 | 274 | Effect.scoped, | 306 | 275 | Effect.timeoutOption(ANTIGRAVITY_TIMEOUT_MS), | @@ -337,82 +306,5 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener | 337 | 306 | ), | 338 | 307 | ); | 339 | 308 |
| 340 | | - const generateCommitMessage: TextGeneration.TextGeneration["Service"]["generateCommitMessage"] = | 341 | | - Effect.fn("AntigravityTextGeneration.generateCommitMessage")(function* (input) { | 342 | | - const generated = yield* runAntigravityJson({ | 343 | | - operation: "generateCommitMessage", | 344 | | - ...buildCommitMessagePrompt({ | 345 | | - branch: input.branch, | 346 | | - stagedSummary: input.stagedSummary, | 347 | | - stagedPatch: input.stagedPatch, | 348 | | - includeBranch: input.includeBranch === true, | 349 | | - policy: input.policy, | 350 | | - }), | 351 | | - modelSelection: input.modelSelection, | 352 | | - }); | 353 | | - return { | 354 | | - subject: sanitizeCommitSubject(generated.subject), | 355 | | - body: generated.body.trim(), | 356 | | - ...("branch" in generated && typeof generated.branch === "string" | 357 | | - ? { branch: sanitizeFeatureBranchName(generated.branch) } | 358 | | - : {}), | 359 | | - }; | 360 | | - }); | 361 | | - | 362 | | - const generatePrContent: TextGeneration.TextGeneration["Service"]["generatePrContent"] = | 363 | | - Effect.fn("AntigravityTextGeneration.generatePrContent")(function* (input) { | 364 | | - const generated = yield* runAntigravityJson({ | 365 | | - operation: "generatePrContent", | 366 | | - ...buildPrContentPrompt({ | 367 | | - baseBranch: input.baseBranch, | 368 | | - headBranch: input.headBranch, | 369 | | - commitSummary: input.commitSummary, | 370 | | - diffSummary: input.diffSummary, | 371 | | - diffPatch: input.diffPatch, | 372 | | - policy: input.policy, | 373 | | - changeRequestTemplate: input.changeRequestTemplate, | 374 | | - }), | 375 | | - modelSelection: input.modelSelection, | 376 | | - }); | 377 | | - return { title: sanitizePrTitle(generated.title), body: generated.body.trim() }; | 378 | | - }); | 379 | | - | 380 | | - const generateBranchName: TextGeneration.TextGeneration["Service"]["generateBranchName"] = | 381 | | - Effect.fn("AntigravityTextGeneration.generateBranchName")(function* (input) { | 382 | | - const generated = yield* runAntigravityJson({ | 383 | | - operation: "generateBranchName", | 384 | | - ...buildBranchNamePrompt({ | 385 | | - message: input.message, | 386 | | - attachments: input.attachments, | 387 | | - naming: input.naming, | 388 | | - }), | 389 | | - modelSelection: input.modelSelection, | 390 | | - }); | 391 | | - return { branch: formatGeneratedBranchName(generated.branch, input.naming) }; | 392 | | - }); | 393 | | - | 394 | | - const generateThreadTitle: TextGeneration.TextGeneration["Service"]["generateThreadTitle"] = | 395 | | - Effect.fn("AntigravityTextGeneration.generateThreadTitle")(function* (input) { | 396 | | - const generated = yield* runAntigravityJson({ | 397 | | - operation: "generateThreadTitle", | 398 | | - ...buildThreadTitlePrompt({ | 399 | | - message: input.message, | 400 | | - previousTitle: input.previousTitle, | 401 | | - linkedContext: input.linkedContext, | 402 | | - attachments: input.attachments, | 403 | | - }), | 404 | | - modelSelection: input.modelSelection, | 405 | | - }); | 406 | | - return { | 407 | | - title: sanitizeThreadTitle(generated.title), | 408 | | - ...(generated.needsRefinement ? { needsRefinement: true } : {}), | 409 | | - }; | 410 | | - }); | 411 | | - | 412 | | - return { | 413 | | - generateCommitMessage, | 414 | | - generatePrContent, | 415 | | - generateBranchName, | 416 | | - generateThreadTitle, | 417 | | - } satisfies TextGeneration.TextGeneration["Service"]; | | 309 | + return TextGenerationOperations.fromRunner("AntigravityTextGeneration", runAntigravityJson); | 418 | 310 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/textGeneration/ClaudeTextGeneration.ts +11-141Lines changed: 11 additions & 141 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,25 +14,11 @@ import * as Schema from "effect/Schema"; | 14 | 14 | import * as Stream from "effect/Stream"; | 15 | 15 | import { ChildProcess, ChildProcessSpawner } from "effect/process"; | 16 | 16 |
| 17 | | -import { type ClaudeSettings, type ModelSelection } from "@t3tools/contracts"; | 18 | | -import { formatGeneratedBranchName, sanitizeFeatureBranchName } from "@t3tools/shared/git"; | | 17 | +import { type ClaudeSettings, TextGenerationError } from "@t3tools/contracts"; | 19 | 18 | import { resolveSpawnCommand } from "@t3tools/shared/shell"; | 20 | 19 |
| 21 | | -import { TextGenerationError } from "@t3tools/contracts"; | 22 | | -import * as TextGeneration from "./TextGeneration.ts"; | 23 | | -import { | 24 | | - buildBranchNamePrompt, | 25 | | - buildCommitMessagePrompt, | 26 | | - buildPrContentPrompt, | 27 | | - buildThreadTitlePrompt, | 28 | | -} from "./TextGenerationPrompts.ts"; | 29 | | -import { | 30 | | - normalizeCliError, | 31 | | - sanitizeCommitSubject, | 32 | | - sanitizePrTitle, | 33 | | - sanitizeThreadTitle, | 34 | | - toJsonSchemaObject, | 35 | | -} from "./TextGenerationUtils.ts"; | | 20 | +import * as TextGenerationOperations from "./TextGenerationOperations.ts"; | | 21 | +import { normalizeCliError, toJsonSchemaObject } from "./TextGenerationUtils.ts"; | 36 | 22 | import { | 37 | 23 | getModelSelectionStringOptionValue, | 38 | 24 | getProviderOptionDescriptors, | @@ -98,11 +84,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu | 98 | 84 | ); | 99 | 85 |
| 100 | 86 | const encodeJsonForOperation = ( | 101 | | - operation: | 102 | | - | "generateCommitMessage" | 103 | | - | "generatePrContent" | 104 | | - | "generateBranchName" | 105 | | - | "generateThreadTitle", | | 87 | + operation: TextGenerationOperations.Operation, | 106 | 88 | value: unknown, | 107 | 89 | detail: string, | 108 | 90 | ): Effect.Effect<string, TextGenerationError> => | @@ -125,19 +107,13 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu | 125 | 107 | operation, | 126 | 108 | cwd, | 127 | 109 | prompt, | 128 | | - outputSchemaJson, | | 110 | + outputSchema: outputSchemaJson, | 129 | 111 | modelSelection, | 130 | | - }: { | 131 | | - operation: | 132 | | - | "generateCommitMessage" | 133 | | - | "generatePrContent" | 134 | | - | "generateBranchName" | 135 | | - | "generateThreadTitle"; | 136 | | - cwd: string; | 137 | | - prompt: string; | 138 | | - outputSchemaJson: S; | 139 | | - modelSelection: ModelSelection; | 140 | | - }): Effect.fn.Return<S["Type"], TextGenerationError, S["DecodingServices"]> { | | 112 | + }: TextGenerationOperations.Request<S>): Effect.fn.Return< | | 113 | + S["Type"], | | 114 | + TextGenerationError, | | 115 | + S["DecodingServices"] | | 116 | + > { | 141 | 117 | const catalog = yield* scopedModelCatalog; | 142 | 118 | const resolvedModelSelection = { | 143 | 119 | ...modelSelection, | @@ -310,111 +286,5 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu | 310 | 286 | ); | 311 | 287 | }); | 312 | 288 |
| 313 | | - // --------------------------------------------------------------------------- | 314 | | - // TextGeneration service methods | 315 | | - // --------------------------------------------------------------------------- | 316 | | - | 317 | | - const generateCommitMessage: TextGeneration.TextGeneration["Service"]["generateCommitMessage"] = | 318 | | - Effect.fn("ClaudeTextGeneration.generateCommitMessage")(function* (input) { | 319 | | - const { prompt, outputSchema } = buildCommitMessagePrompt({ | 320 | | - branch: input.branch, | 321 | | - stagedSummary: input.stagedSummary, | 322 | | - stagedPatch: input.stagedPatch, | 323 | | - includeBranch: input.includeBranch === true, | 324 | | - policy: input.policy, | 325 | | - }); | 326 | | - | 327 | | - const generated = yield* runClaudeJson({ | 328 | | - operation: "generateCommitMessage", | 329 | | - cwd: input.cwd, | 330 | | - prompt, | 331 | | - outputSchemaJson: outputSchema, | 332 | | - modelSelection: input.modelSelection, | 333 | | - }); | 334 | | - | 335 | | - return { | 336 | | - subject: sanitizeCommitSubject(generated.subject), | 337 | | - body: generated.body.trim(), | 338 | | - ...("branch" in generated && typeof generated.branch === "string" | 339 | | - ? { branch: sanitizeFeatureBranchName(generated.branch) } | 340 | | - : {}), | 341 | | - }; | 342 | | - }); | 343 | | - | 344 | | - const generatePrContent: TextGeneration.TextGeneration["Service"]["generatePrContent"] = | 345 | | - Effect.fn("ClaudeTextGeneration.generatePrContent")(function* (input) { | 346 | | - const { prompt, outputSchema } = buildPrContentPrompt({ | 347 | | - baseBranch: input.baseBranch, | 348 | | - headBranch: input.headBranch, | 349 | | - commitSummary: input.commitSummary, | 350 | | - diffSummary: input.diffSummary, | 351 | | - diffPatch: input.diffPatch, | 352 | | - policy: input.policy, | 353 | | - changeRequestTemplate: input.changeRequestTemplate, | 354 | | - }); | 355 | | - | 356 | | - const generated = yield* runClaudeJson({ | 357 | | - operation: "generatePrContent", | 358 | | - cwd: input.cwd, | 359 | | - prompt, | 360 | | - outputSchemaJson: outputSchema, | 361 | | - modelSelection: input.modelSelection, | 362 | | - }); | 363 | | - | 364 | | - return { | 365 | | - title: sanitizePrTitle(generated.title), | 366 | | - body: generated.body.trim(), | 367 | | - }; | 368 | | - }); | 369 | | - | 370 | | - const generateBranchName: TextGeneration.TextGeneration["Service"]["generateBranchName"] = | 371 | | - Effect.fn("ClaudeTextGeneration.generateBranchName")(function* (input) { | 372 | | - const { prompt, outputSchema } = buildBranchNamePrompt({ | 373 | | - message: input.message, | 374 | | - attachments: input.attachments, | 375 | | - naming: input.naming, | 376 | | - }); | 377 | | - | 378 | | - const generated = yield* runClaudeJson({ | 379 | | - operation: "generateBranchName", | 380 | | - cwd: input.cwd, | 381 | | - prompt, | 382 | | - outputSchemaJson: outputSchema, | 383 | | - modelSelection: input.modelSelection, | 384 | | - }); | 385 | | - | 386 | | - return { | 387 | | - branch: formatGeneratedBranchName(generated.branch, input.naming), | 388 | | - }; | 389 | | - }); | 390 | | - | 391 | | - const generateThreadTitle: TextGeneration.TextGeneration["Service"]["generateThreadTitle"] = | 392 | | - Effect.fn("ClaudeTextGeneration.generateThreadTitle")(function* (input) { | 393 | | - const { prompt, outputSchema } = buildThreadTitlePrompt({ | 394 | | - message: input.message, | 395 | | - previousTitle: input.previousTitle, | 396 | | - linkedContext: input.linkedContext, | 397 | | - attachments: input.attachments, | 398 | | - }); | 399 | | - | 400 | | - const generated = yield* runClaudeJson({ | 401 | | - operation: "generateThreadTitle", | 402 | | - cwd: input.cwd, | 403 | | - prompt, | 404 | | - outputSchemaJson: outputSchema, | 405 | | - modelSelection: input.modelSelection, | 406 | | - }); | 407 | | - | 408 | | - return { | 409 | | - title: sanitizeThreadTitle(generated.title), | 410 | | - ...(generated.needsRefinement ? { needsRefinement: true } : {}), | 411 | | - }; | 412 | | - }); | 413 | | - | 414 | | - return { | 415 | | - generateCommitMessage, | 416 | | - generatePrContent, | 417 | | - generateBranchName, | 418 | | - generateThreadTitle, | 419 | | - } satisfies TextGeneration.TextGeneration["Service"]; | | 289 | + return TextGenerationOperations.fromRunner("ClaudeTextGeneration", runClaudeJson); | 420 | 290 | }); |
|