Skip to content

Commit 30b4e77

Browse files
wip v28
1 parent 29ed2a1 commit 30b4e77

8 files changed

Lines changed: 286 additions & 34 deletions

uapi/app/terminal/TerminalDepositReadWorkbench.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { TerminalRepositoryContextState } from './terminal-repository-conte
1818
import {
1919
buildLiveTerminalDepositReadWorkbenchSnapshot,
2020
normalizeTerminalDepositReadWorkbench,
21+
type TerminalDepositedSourceRevision,
2122
type TerminalDepositReadWorkbench as TerminalDepositReadWorkbenchState,
2223
} from './terminal-deposit-read-workbench';
2324
import { useTerminalShellBridge } from './terminal-shell-bridge';
@@ -35,12 +36,14 @@ type ReadFitProgressState = 'draft' | 'measured' | 'admitted' | 'fit-recorded';
3536

3637
interface TerminalDepositReadWorkbenchProps {
3738
repositoryContext?: TerminalRepositoryContextState | null;
39+
depositedSourceRevision?: TerminalDepositedSourceRevision | null;
3840
onRecordActivity?: (draft: TerminalActivityRecordDraft) => Promise<unknown>;
3941
showDemonstrationWorkbench?: boolean;
4042
}
4143

4244
export default function TerminalDepositReadWorkbench({
4345
repositoryContext = null,
46+
depositedSourceRevision = null,
4447
onRecordActivity,
4548
showDemonstrationWorkbench = true,
4649
}: TerminalDepositReadWorkbenchProps) {
@@ -50,13 +53,13 @@ export default function TerminalDepositReadWorkbench({
5053
const [readFitProgress, setReadFitProgress] = useState<ReadFitProgressState>('draft');
5154
const workbenchSnapshot = useMemo(() => {
5255
if (showDemonstrationWorkbench) return snapshot;
53-
return buildLiveTerminalDepositReadWorkbenchSnapshot(repositoryContext);
54-
}, [repositoryContext, showDemonstrationWorkbench, snapshot]);
56+
return buildLiveTerminalDepositReadWorkbenchSnapshot(repositoryContext, depositedSourceRevision);
57+
}, [depositedSourceRevision, repositoryContext, showDemonstrationWorkbench, snapshot]);
5558
const workbench = useMemo<TerminalDepositReadWorkbenchState | null>(
5659
() => normalizeTerminalDepositReadWorkbench(workbenchSnapshot, repositoryContext),
5760
[repositoryContext, workbenchSnapshot],
5861
);
59-
const scenarioKey = workbench?.scenarioLabel || '';
62+
const scenarioKey = `${workbench?.scenarioLabel || ''}:${workbench?.sourceRevision?.commit || ''}`;
6063

6164
useEffect(() => {
6265
setReadFitProgress('draft');
@@ -79,21 +82,25 @@ export default function TerminalDepositReadWorkbench({
7982
setRecordMessage('Deposit-side share posture recorded into the Bitcode activity ledger.');
8083
} else if (kind === 'read') {
8184
await onRecordActivity(
82-
buildTerminalReadMeasurementDraft({
83-
selectedScenarioId: workbench.scenarioLabel,
84-
parserKind: readRowValue(workbench.read.rows, 'Parser'),
85-
closureCriteriaCount: Number(readMetricValue(workbench.read.metrics, 'Closure criteria')) || 0,
86-
targetKindCount: Number(readMetricValue(workbench.read.metrics, 'Target kinds')) || 0,
87-
scenarios: [
88-
{
89-
id: workbench.scenarioLabel,
90-
label: workbench.scenarioLabel,
91-
repo: readRowValue(workbench.read.rows, 'Repository'),
92-
profile: readRowValue(workbench.read.rows, 'Profile'),
93-
selected: true,
94-
},
95-
],
96-
}),
85+
buildTerminalReadMeasurementDraft(
86+
{
87+
selectedScenarioId: workbench.scenarioLabel,
88+
parserKind: readRowValue(workbench.read.rows, 'Parser'),
89+
closureCriteriaCount: Number(readMetricValue(workbench.read.metrics, 'Closure criteria')) || 0,
90+
targetKindCount: Number(readMetricValue(workbench.read.metrics, 'Target kinds')) || 0,
91+
scenarios: [
92+
{
93+
id: workbench.scenarioLabel,
94+
label: workbench.scenarioLabel,
95+
repo: readRowValue(workbench.read.rows, 'Repository'),
96+
profile: readRowValue(workbench.read.rows, 'Profile'),
97+
selected: true,
98+
},
99+
],
100+
},
101+
undefined,
102+
{ sourceRevision: workbench.sourceRevision },
103+
),
97104
);
98105
setReadFitProgress('measured');
99106
setRecordMessage(

uapi/app/terminal/TerminalPageClient.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
import { deriveTerminalTransactionReadiness } from './terminal-transaction-readiness-source';
6060
import { resolveTerminalTransactionSource } from './terminal-transaction-source';
6161
import type { WorkspaceRun } from './terminal-run-data';
62+
import type { TerminalDepositedSourceRevision } from './terminal-deposit-read-workbench';
6263
import { buildProtocolProjectedWorkspaceRun } from './terminal-protocol-projection';
6364
import { buildTerminalHref, TERMINAL_ROUTE } from './terminal-routes';
6465
import { readBitcodeDemonstrationShellSnapshot } from './demonstration-witness-runtime';
@@ -290,6 +291,29 @@ export default function TerminalPageClient() {
290291
() => runs.find((run) => run.id === selectedTransactionId) || runs[0] || null,
291292
[runs, selectedTransactionId],
292293
);
294+
const depositedSourceRevision = useMemo<TerminalDepositedSourceRevision | null>(() => {
295+
if (showDemonstrationSurfaces) return null;
296+
const selectedRepository = repositoryContext?.selectedRepository || null;
297+
if (!selectedRepository) return null;
298+
const selectedBranch = repositoryContext?.selectedBranch || selectedRepository.defaultBranch || 'main';
299+
const matchingSubmission = runs.find(
300+
(run) =>
301+
run.contextSource === 'terminal-deposit-composer' &&
302+
run.repository === selectedRepository.fullName &&
303+
run.branch === selectedBranch &&
304+
Boolean(run.sourceCommit) &&
305+
Boolean(run.candidateAssetId),
306+
);
307+
if (!matchingSubmission?.sourceCommit) return null;
308+
309+
return {
310+
repositoryFullName: selectedRepository.fullName,
311+
branch: selectedBranch,
312+
commit: matchingSubmission.sourceCommit,
313+
activityId: matchingSubmission.id,
314+
createdAt: matchingSubmission.created_at,
315+
};
316+
}, [repositoryContext, runs, showDemonstrationSurfaces]);
293317

294318
const handleSelectTransaction = (transactionId: string) => {
295319
replaceTerminalRoute(transactionId);
@@ -564,6 +588,7 @@ export default function TerminalPageClient() {
564588
/>
565589
<TerminalDepositReadWorkbench
566590
repositoryContext={repositoryContext}
591+
depositedSourceRevision={depositedSourceRevision}
567592
onRecordActivity={handleRecordActivity}
568593
showDemonstrationWorkbench={showDemonstrationSurfaces}
569594
/>

uapi/app/terminal/terminal-activity-history.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { buildAgenticExecutionSummary } from '@bitcode/api/src/executions/agenti
33
import type { PipelineExecution } from '@/types/api';
44

55
import 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';
77
import type { TerminalReadScenariosState } from './terminal-read-scenarios';
88
import type { TerminalExternalRuntimeSnapshot } from './terminal-external-runtime';
99
import 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
130132
function 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(
302316
export 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

Comments
 (0)