@@ -6,11 +6,9 @@ import {
66 type EvaluationResult ,
77 type GitListedRun ,
88 type ResultsConfig ,
9- ResultsRepoRunExistsError ,
109 type ResultsRepoStatus ,
1110 directPushResults ,
1211 directorySizeBytes ,
13- findResultsRepoRun ,
1412 getProject ,
1513 getProjectForPath ,
1614 getResultsRepoSyncStatus ,
@@ -29,7 +27,6 @@ import {
2927 listResultFiles ,
3028 listResultFilesFromRunsDir ,
3129} from '../inspect/utils.js' ;
32- import { loadManifestResults } from './manifest.js' ;
3330import {
3431 type RemoteRunTagState ,
3532 assertWritableResultsRepo ,
@@ -100,33 +97,6 @@ export interface RemoteResultsStatus extends ResultsRepoStatus {
10097 readonly run_count : number ;
10198}
10299
103- export interface LocalRunPublishPreview {
104- readonly sourceRunId : string ;
105- readonly targetRepo : string ;
106- readonly targetPath : string ;
107- readonly targetRunId : string ;
108- readonly remoteExists : boolean ;
109- readonly replaceRequired : boolean ;
110- readonly canPublish : boolean ;
111- readonly blockReason ?: string ;
112- readonly remoteStatus : RemoteResultsStatus ;
113- }
114-
115- export interface LocalRunPublishResult extends LocalRunPublishPreview {
116- readonly published : boolean ;
117- readonly replaced : boolean ;
118- }
119-
120- export class LocalRunPublishError extends Error {
121- readonly status : 400 | 409 ;
122-
123- constructor ( message : string , status : 400 | 409 = 400 ) {
124- super ( message ) ;
125- this . name = 'LocalRunPublishError' ;
126- this . status = status ;
127- }
128- }
129-
130100const REMOTE_RUN_PREFIX = 'remote::' ;
131101const SIZE_WARNING_BYTES = 10 * 1024 * 1024 ;
132102
@@ -152,136 +122,6 @@ function getRelativeRunPath(cwd: string, runDir: string): string {
152122 return experiment && experiment !== runName ? path . join ( experiment , runName ) : runName ;
153123}
154124
155- function toPosixPath ( p : string ) : string {
156- return p . split ( path . sep ) . join ( '/' ) ;
157- }
158-
159- function getPublishStatusBlockReason ( status : RemoteResultsStatus ) : string | undefined {
160- if ( ! status . configured ) {
161- return 'Remote results repo is not configured for this project.' ;
162- }
163-
164- if ( status . sync_status === 'syncing' ) {
165- return 'Project sync is already in progress. Wait for it to finish before publishing a run.' ;
166- }
167-
168- if ( status . sync_status && status . sync_status !== 'clean' ) {
169- return 'Sync Project before publishing a selected run so pending result metadata is handled first.' ;
170- }
171-
172- if ( status . blocked ) {
173- return status . block_reason ?? 'Remote results repo sync is blocked.' ;
174- }
175-
176- return undefined ;
177- }
178-
179- function getExperimentFromRunId ( runId : string ) : string {
180- const separatorIndex = runId . lastIndexOf ( '::' ) ;
181- return separatorIndex === - 1 ? 'default' : runId . slice ( 0 , separatorIndex ) ;
182- }
183-
184- async function buildLocalRunPublishPreview ( params : {
185- readonly cwd : string ;
186- readonly config : Required < ResultsConfig > ;
187- readonly meta : Pick < SourcedResultFileMeta , 'source' | 'path' | 'raw_filename' > ;
188- readonly projectId ?: string ;
189- } ) : Promise < LocalRunPublishPreview & { readonly relativeRunPath : string } > {
190- if ( params . meta . source !== 'local' ) {
191- throw new LocalRunPublishError ( 'Selected run publish is only available for local runs' ) ;
192- }
193-
194- const runDir = path . dirname ( params . meta . path ) ;
195- const relativeRunPath = toPosixPath ( getRelativeRunPath ( params . cwd , runDir ) ) ;
196- const targetPath = path . posix . join ( '.agentv/results/runs' , relativeRunPath ) ;
197- const existingRun = await findResultsRepoRun ( params . config , params . meta . raw_filename ) ;
198- const remoteStatus = await getRemoteResultsStatus ( params . cwd , params . projectId ) ;
199- const blockReason = getPublishStatusBlockReason ( remoteStatus ) ;
200- const remoteExists = existingRun !== undefined ;
201-
202- return {
203- sourceRunId : params . meta . raw_filename ,
204- targetRepo : params . config . repo ,
205- targetPath,
206- targetRunId : params . meta . raw_filename ,
207- remoteExists,
208- replaceRequired : remoteExists ,
209- canPublish : ! blockReason && ! remoteExists ,
210- ...( blockReason && { blockReason } ) ,
211- remoteStatus,
212- relativeRunPath,
213- } ;
214- }
215-
216- export async function previewLocalRunPublish (
217- cwd : string ,
218- meta : Pick < SourcedResultFileMeta , 'source' | 'path' | 'raw_filename' > ,
219- projectId ?: string ,
220- ) : Promise < LocalRunPublishPreview > {
221- const config = await loadNormalizedResultsConfig ( cwd , projectId ) ;
222- if ( ! config ) {
223- throw new LocalRunPublishError ( 'Remote results repo is not configured for this project' , 409 ) ;
224- }
225-
226- const { relativeRunPath : _relativeRunPath , ...preview } = await buildLocalRunPublishPreview ( {
227- cwd,
228- config,
229- meta,
230- projectId,
231- } ) ;
232- return preview ;
233- }
234-
235- export async function publishLocalRun ( params : {
236- readonly cwd : string ;
237- readonly meta : Pick < SourcedResultFileMeta , 'source' | 'path' | 'raw_filename' > ;
238- readonly projectId ?: string ;
239- readonly replace ?: boolean ;
240- } ) : Promise < LocalRunPublishResult > {
241- const config = await loadNormalizedResultsConfig ( params . cwd , params . projectId ) ;
242- if ( ! config ) {
243- throw new LocalRunPublishError ( 'Remote results repo is not configured for this project' , 409 ) ;
244- }
245-
246- const preview = await buildLocalRunPublishPreview ( {
247- cwd : params . cwd ,
248- config,
249- meta : params . meta ,
250- projectId : params . projectId ,
251- } ) ;
252- if ( preview . blockReason ) {
253- throw new LocalRunPublishError ( preview . blockReason , 409 ) ;
254- }
255- if ( preview . remoteExists && params . replace !== true ) {
256- throw new ResultsRepoRunExistsError ( preview . targetRunId , preview . relativeRunPath ) ;
257- }
258-
259- await maybeWarnLargeArtifact ( path . dirname ( params . meta . path ) ) ;
260- const results = loadManifestResults ( params . meta . path ) ;
261- const pushed = await directPushResults ( {
262- config,
263- sourceDir : path . dirname ( params . meta . path ) ,
264- destinationPath : preview . relativeRunPath ,
265- commitMessage : buildCommitTitle ( {
266- cwd : params . cwd ,
267- run_dir : path . dirname ( params . meta . path ) ,
268- test_files : [ ] ,
269- results,
270- eval_summaries : [ ] ,
271- experiment : getExperimentFromRunId ( preview . targetRunId ) ,
272- } ) ,
273- replaceExisting : params . replace === true ,
274- } ) ;
275-
276- invalidateGitRunsCache ( config . path ) ;
277- const refreshed = await previewLocalRunPublish ( params . cwd , params . meta , params . projectId ) ;
278- return {
279- ...refreshed ,
280- published : pushed ,
281- replaced : preview . remoteExists && params . replace === true ,
282- } ;
283- }
284-
285125function buildCommitTitle ( payload : RemoteExportPayload ) : string {
286126 const passed = payload . results . filter ( ( result ) => result . score >= DEFAULT_THRESHOLD ) . length ;
287127 const avgScore =
0 commit comments