@@ -3,7 +3,7 @@ import { buildAgenticExecutionSummary } from '@bitcode/api/src/executions/agenti
33import type { PipelineExecution } from '@/types/api' ;
44
55import type { TerminalClosureState } from './terminal-closure-state' ;
6- import type { TerminalDepositReadWorkbench } from './terminal-deposit-read-workbench' ;
6+ import type { TerminalDepositReadWorkbench , TerminalSourceRevision } from './terminal-deposit-read-workbench' ;
77import type { TerminalReadScenariosState } from './terminal-read-scenarios' ;
88import type { TerminalExternalRuntimeSnapshot } from './terminal-external-runtime' ;
99import type { WorkspaceRun } from './terminal-run-data' ;
@@ -17,6 +17,7 @@ export interface TerminalActivityRecordDraft {
1717 summary : string ;
1818 detailSection ?: TerminalTransactionDetailSection ;
1919 selectAfterRecord ?: boolean ;
20+ sourceRevision ?: TerminalSourceRevision | null ;
2021 status ?: string ;
2122 input ?: Record < string , unknown > | null ;
2223 output ?: Record < string , unknown > | null ;
@@ -31,6 +32,7 @@ function buildBitcodeWorkbenchState(workbench: TerminalDepositReadWorkbench) {
3132 branchMode : workbench . branchMode ,
3233 scenarioLabel : workbench . scenarioLabel ,
3334 profileLabel : workbench . profileLabel ,
35+ sourceRevision : workbench . sourceRevision ,
3436 deposit : workbench . deposit ,
3537 read : workbench . read ,
3638 fit : workbench . fit ,
@@ -130,7 +132,18 @@ function readRowValue(rows: Array<{ label: string; value: string }>, label: stri
130132function buildRepoSnapshot (
131133 repositoryContext ?: TerminalRepositoryContextState | null ,
132134 fallbackRun ?: WorkspaceRun | null ,
135+ sourceRevision ?: TerminalSourceRevision | null ,
133136) {
137+ const sourceRevisionParts = splitRepositoryFullName ( sourceRevision ?. repositoryFullName ) ;
138+ if ( sourceRevisionParts ) {
139+ return {
140+ org : sourceRevisionParts . org ,
141+ repo : sourceRevisionParts . repo ,
142+ branch : normalizeWhitespace ( sourceRevision ?. branch ) || 'main' ,
143+ commit : normalizeWhitespace ( sourceRevision ?. commit ) ,
144+ } ;
145+ }
146+
134147 const selectedRepository = repositoryContext ?. selectedRepository || null ;
135148 const selectedRepositoryParts = splitRepositoryFullName ( selectedRepository ?. fullName ) ;
136149 if ( selectedRepository && selectedRepositoryParts ) {
@@ -161,7 +174,7 @@ export function buildTerminalExecutionHistoryRequest(
161174 } ,
162175) {
163176 const summary = normalizeWhitespace ( draft . summary ) || 'Bitcode activity recorded from the Bitcode Terminal.' ;
164- const repoSnapshot = buildRepoSnapshot ( options . repositoryContext , options . fallbackRun ) ;
177+ const repoSnapshot = buildRepoSnapshot ( options . repositoryContext , options . fallbackRun , draft . sourceRevision ) ;
165178 const repositoryFullName = repoSnapshot ? `${ repoSnapshot . org } /${ repoSnapshot . repo } ` : null ;
166179 const draftOutput = isRecord ( draft . output ) ? draft . output : null ;
167180 const assetPackCompletionPatch = isRecord ( draftOutput ?. assetPackCompletion ) ? draftOutput . assetPackCompletion : null ;
@@ -269,6 +282,7 @@ export function buildTerminalDepositWorkbenchDraft(
269282 return {
270283 type : 'agentic-execution:asset-pack' ,
271284 detailSection : 'transaction' ,
285+ sourceRevision : workbench . sourceRevision ,
272286 summary : `Recorded deposit-side share posture for ${ repository } .` ,
273287 input : {
274288 selectedEntryLabels,
@@ -302,6 +316,7 @@ export function buildTerminalDepositWorkbenchDraft(
302316export function buildTerminalReadMeasurementDraft (
303317 needState : TerminalReadScenariosState ,
304318 scenarioOverride ?: TerminalReadScenariosState [ 'scenarios' ] [ number ] ,
319+ options ?: { sourceRevision ?: TerminalSourceRevision | null } ,
305320) : TerminalActivityRecordDraft {
306321 const scenario =
307322 scenarioOverride ||
@@ -319,6 +334,7 @@ export function buildTerminalReadMeasurementDraft(
319334 type : 'agentic-execution:read-measurement' ,
320335 detailSection : 'activity' ,
321336 selectAfterRecord : false ,
337+ sourceRevision : options ?. sourceRevision || null ,
322338 summary : `Recorded read measurement for ${ scenario . label } .` ,
323339 output : {
324340 readMeasurement : {
@@ -377,6 +393,7 @@ export function buildTerminalReadAdmissionDraft(
377393 type : 'agentic-execution:read-measurement' ,
378394 detailSection : 'activity' ,
379395 selectAfterRecord : false ,
396+ sourceRevision : workbench . sourceRevision ,
380397 summary : `Accepted measured Read for fit search for ${ workbench . scenarioLabel } .` ,
381398 output : {
382399 readMeasurement,
@@ -450,6 +467,7 @@ export function buildTerminalFitWorkbenchDraft(
450467 return {
451468 type : 'agentic-execution:proof-refresh' ,
452469 detailSection : 'closure' ,
470+ sourceRevision : workbench . sourceRevision ,
453471 summary : `Recorded asset-pack fit and settlement posture for ${ workbench . scenarioLabel } .` ,
454472 output : {
455473 fit : {
@@ -575,6 +593,12 @@ export function mapExecutionHistoryRunToWorkspaceRun(run: PipelineExecution): Wo
575593 type : run . type ,
576594 status : run . status ,
577595 } ) ;
596+ const repoSnapshot = run . repo_snapshot || run . asset_pack_completion ?. repoSnapshot || null ;
597+ const context = isRecord ( run . context ) ? run . context : null ;
598+ const contextString = ( key : string ) => {
599+ const value = context ?. [ key ] ;
600+ return typeof value === 'string' && value . trim ( ) ? value . trim ( ) : null ;
601+ } ;
578602
579603 return {
580604 id : run . id ,
@@ -592,11 +616,15 @@ export function mapExecutionHistoryRunToWorkspaceRun(run: PipelineExecution): Wo
592616 run . asset_pack_completion ?. deliveryMechanism ?. summary ||
593617 null ,
594618 repository :
595- run . repo_snapshot || run . asset_pack_completion ?. repoSnapshot
596- ? `${ ( run . repo_snapshot || run . asset_pack_completion ?. repoSnapshot ) ? .org } /${ ( run . repo_snapshot || run . asset_pack_completion ?. repoSnapshot ) ? .repo } `
619+ repoSnapshot
620+ ? `${ repoSnapshot . org } /${ repoSnapshot . repo } `
597621 : null ,
598- branch : ( run . repo_snapshot || run . asset_pack_completion ?. repoSnapshot ) ?. branch || null ,
599- participant : ( run . repo_snapshot || run . asset_pack_completion ?. repoSnapshot ) ?. org || 'connected account' ,
622+ branch : repoSnapshot ?. branch || contextString ( 'sourceBranch' ) ,
623+ sourceCommit : repoSnapshot ?. commit || contextString ( 'sourceCommit' ) ,
624+ contextSource : contextString ( 'source' ) ,
625+ contextWorkbench : contextString ( 'workbench' ) ,
626+ candidateAssetId : contextString ( 'candidateAssetId' ) ,
627+ participant : repoSnapshot ?. org || 'connected account' ,
600628 isOwnTransaction : true ,
601629 transactionLens : agenticExecution . lens ,
602630 itemCount : run . items ?. length || 0 ,
0 commit comments