@@ -36,12 +36,15 @@ import {
3636 DEFAULT_SERVER_SETTINGS ,
3737 EventId ,
3838 GitCommandError ,
39+ MessageId ,
3940 ProjectId ,
4041 ProviderDriverKind ,
4142 ProviderInstanceId ,
43+ RunId ,
4244 SourceControlProviderError as SourceControlProviderFailure ,
4345 TextGenerationError ,
4446 ThreadId ,
47+ TurnItemId ,
4548} from "@t3tools/contracts" ;
4649import * as DateTime from "effect/DateTime" ;
4750import { decodeGitHubPullRequestListJson } from "@t3tools/source-control-github/server/gitHubPullRequests" ;
@@ -4726,6 +4729,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
47264729 yield * runGit ( repoDir , [ "config" , "branch.feature-create-pr.gh-merge-base" , "main" ] ) ;
47274730 let generatedPolicy : TextGeneration . PrContentGenerationInput [ "policy" ] = undefined ;
47284731 let generatedChangeRequestTemplate : string | undefined ;
4732+ let generatedThreadContext : string | undefined ;
47294733
47304734 const { manager, ghCalls } = yield * makeManager ( {
47314735 serverSettings : {
@@ -4738,6 +4742,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
47384742 generatePrContent : ( input ) => {
47394743 generatedPolicy = input . policy ;
47404744 generatedChangeRequestTemplate = input . changeRequestTemplate ;
4745+ generatedThreadContext = input . threadContext ;
47414746 return Effect . succeed ( {
47424747 title : "Add stacked git actions" ,
47434748 body : "## What changed?\nAdded stacked git actions." ,
@@ -4771,6 +4776,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
47714776 changeRequestInstructions : "Lead with user impact." ,
47724777 } ) ;
47734778 expect ( generatedChangeRequestTemplate ) . toBe ( "## What changed?\n\n## Verification" ) ;
4779+ expect ( generatedThreadContext ) . toBeUndefined ( ) ;
47744780 expect ( ghCalls . filter ( ( call ) => call . startsWith ( "pr list " ) ) ) . toHaveLength ( 2 ) ;
47754781 expect (
47764782 ghCalls . some ( ( call ) => call . includes ( "pr create --base main --head feature-create-pr" ) ) ,
@@ -4779,6 +4785,157 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
47794785 } ) ,
47804786 ) ;
47814787
4788+ it . effect ( "create_pr gives the PR writer the thread's checks and skips rolled-back runs" , ( ) =>
4789+ Effect . gen ( function * ( ) {
4790+ const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
4791+ yield * initRepo ( repoDir ) ;
4792+ yield * runGit ( repoDir , [ "checkout" , "-b" , "feature/thread-context" ] ) ;
4793+ NodeFS . writeFileSync ( NodePath . join ( repoDir , "thread-context.txt" ) , "context\n" ) ;
4794+ yield * runGit ( repoDir , [ "add" , "thread-context.txt" ] ) ;
4795+ yield * runGit ( repoDir , [ "commit" , "-m" , "Thread context" ] ) ;
4796+ const remoteDir = yield * createBareRemote ( ) ;
4797+ yield * runGit ( repoDir , [ "remote" , "add" , "origin" , remoteDir ] ) ;
4798+ const threadId = ThreadId . make ( "thread:pr-thread-context" ) ;
4799+ const providerInstanceId = ProviderInstanceId . make ( "codex" ) ;
4800+ const createdAt = DateTime . makeUnsafe ( "2026-09-27T00:00:00.000Z" ) ;
4801+ const run = ( ordinal : number , status : "completed" | "rolled_back" ) => ( {
4802+ id : RunId . make ( `run:pr-thread-context:${ ordinal } ` ) ,
4803+ threadId,
4804+ ordinal,
4805+ providerInstanceId,
4806+ modelSelection : { instanceId : providerInstanceId , model : "gpt-5" } ,
4807+ providerThreadId : null ,
4808+ userMessageId : MessageId . make ( `message:pr-thread-context:${ ordinal } ` ) ,
4809+ rootNodeId : null ,
4810+ activeAttemptId : null ,
4811+ status,
4812+ requestedAt : createdAt ,
4813+ startedAt : createdAt ,
4814+ completedAt : createdAt ,
4815+ checkpointId : null ,
4816+ contextHandoffId : null ,
4817+ } ) ;
4818+ const itemBase = ( ordinal : number , runId : RunId ) => ( {
4819+ id : TurnItemId . make ( `item:pr-thread-context:${ ordinal } ` ) ,
4820+ threadId,
4821+ runId,
4822+ nodeId : null ,
4823+ providerThreadId : null ,
4824+ providerTurnId : null ,
4825+ nativeItemRef : null ,
4826+ parentItemId : null ,
4827+ ordinal,
4828+ status : "completed" as const ,
4829+ title : null ,
4830+ startedAt : createdAt ,
4831+ completedAt : createdAt ,
4832+ updatedAt : createdAt ,
4833+ } ) ;
4834+ let generatedThreadContext : string | undefined ;
4835+
4836+ const { manager } = yield * makeManager ( {
4837+ textGeneration : {
4838+ generatePrContent : ( input ) => {
4839+ generatedThreadContext = input . threadContext ;
4840+ return Effect . succeed ( { title : "Thread context" , body : "Body" } ) ;
4841+ } ,
4842+ } ,
4843+ seed : Effect . gen ( function * ( ) {
4844+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
4845+ const completedRun = run ( 1 , "completed" ) ;
4846+ const abandonedRun = run ( 2 , "rolled_back" ) ;
4847+ yield * store . apply ( {
4848+ id : EventId . make ( "event:pr-thread-context:thread" ) ,
4849+ type : "thread.created" ,
4850+ threadId,
4851+ providerInstanceId,
4852+ occurredAt : createdAt ,
4853+ payload : {
4854+ createdBy : "user" ,
4855+ creationSource : "web" ,
4856+ id : threadId ,
4857+ projectId : ProjectId . make ( "project:pr-thread-context" ) ,
4858+ title : "PR thread context" ,
4859+ providerInstanceId,
4860+ modelSelection : { instanceId : providerInstanceId , model : "gpt-5" } ,
4861+ runtimeMode : "full-access" ,
4862+ interactionMode : "default" ,
4863+ branch : null ,
4864+ worktreePath : repoDir ,
4865+ activeProviderThreadId : null ,
4866+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
4867+ forkedFrom : null ,
4868+ createdAt,
4869+ updatedAt : createdAt ,
4870+ archivedAt : null ,
4871+ settledOverride : null ,
4872+ settledAt : null ,
4873+ lastVisitedAt : null ,
4874+ deletedAt : null ,
4875+ } ,
4876+ } ) ;
4877+ for ( const payload of [ completedRun , abandonedRun ] ) {
4878+ yield * store . apply ( {
4879+ id : EventId . make ( `event:pr-thread-context:run:${ payload . ordinal } ` ) ,
4880+ type : "run.updated" ,
4881+ threadId,
4882+ runId : payload . id ,
4883+ occurredAt : createdAt ,
4884+ payload,
4885+ } ) ;
4886+ }
4887+ const items = [
4888+ {
4889+ ...itemBase ( 1 , completedRun . id ) ,
4890+ type : "user_message" as const ,
4891+ messageId : completedRun . userMessageId ,
4892+ createdBy : "user" as const ,
4893+ creationSource : "web" as const ,
4894+ inputIntent : "turn_start" as const ,
4895+ text : "Make the PR writer see the thread" ,
4896+ attachments : [ ] ,
4897+ } ,
4898+ {
4899+ ...itemBase ( 3 , completedRun . id ) ,
4900+ type : "command_execution" as const ,
4901+ input : "vp test run" ,
4902+ output : "Tests 12 passed" ,
4903+ exitCode : 0 ,
4904+ } ,
4905+ {
4906+ ...itemBase ( 4 , abandonedRun . id ) ,
4907+ type : "command_execution" as const ,
4908+ input : "vp run abandoned" ,
4909+ output : "abandoned output" ,
4910+ exitCode : 0 ,
4911+ } ,
4912+ ] ;
4913+ for ( const payload of items ) {
4914+ yield * store . apply ( {
4915+ id : EventId . make ( `event:pr-thread-context:${ payload . id } ` ) ,
4916+ type : "turn-item.updated" ,
4917+ threadId,
4918+ runId : payload . runId ,
4919+ occurredAt : createdAt ,
4920+ payload,
4921+ } ) ;
4922+ }
4923+ } ) ,
4924+ } ) ;
4925+
4926+ yield * manager . runStackedAction ( {
4927+ actionId : "test-action-id" ,
4928+ cwd : repoDir ,
4929+ action : "create_pr" ,
4930+ threadId,
4931+ } ) ;
4932+
4933+ expect ( generatedThreadContext ) . toContain ( "Command: vp test run\nExit code: 0" ) ;
4934+ expect ( generatedThreadContext ) . toContain ( "Make the PR writer see the thread" ) ;
4935+ expect ( generatedThreadContext ) . not . toContain ( "vp run abandoned" ) ;
4936+ } ) ,
4937+ ) ;
4938+
47824939 it . effect ( "generates PR content from branch changes when the remote base advances" , ( ) =>
47834940 Effect . gen ( function * ( ) {
47844941 const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
0 commit comments