@@ -6,10 +6,6 @@ import {
66 appendRecordingExtensionWhenMissing ,
77 recordingExtensionForPlatform ,
88} from '@agent-device/capture-kit/recording-output-path' ;
9- import {
10- buildRemoteTempArtifactDirPath ,
11- buildRemoteTempArtifactPath ,
12- } from './remote-temp-artifact-path.ts' ;
139import { uploadArtifact } from './upload-client.ts' ;
1410import { createStderrUploadProgressReporter , type UploadProgressSink } from './upload-progress.ts' ;
1511
@@ -345,6 +341,37 @@ function hasNonEmptyString(value: unknown): value is string {
345341 return typeof value === 'string' && value . trim ( ) . length > 0 ;
346342}
347343
344+ const REMOTE_TEMP_DIR = '/tmp' ;
345+
346+ /** The daemon-host temp path a remote client names for an artifact it downloads afterwards. */
347+ function buildRemoteTempArtifactPath ( prefix : string , extension : string ) : string {
348+ const safeExtension = extension . startsWith ( '.' ) ? extension : `.${ extension } ` ;
349+ return path . posix . join ( REMOTE_TEMP_DIR , `${ remoteTempArtifactStem ( prefix ) } ${ safeExtension } ` ) ;
350+ }
351+
352+ /** A directory temp path — unlike `buildRemoteTempArtifactPath`, no extension is ever appended. */
353+ function buildRemoteTempArtifactDirPath ( prefix : string ) : string {
354+ return path . posix . join ( REMOTE_TEMP_DIR , remoteTempArtifactStem ( prefix ) ) ;
355+ }
356+
357+ /** Whether `value` has the shape `buildRemoteTempArtifactPath(prefix, extension)` returns. */
358+ export function isRemoteTempArtifactPath (
359+ value : string ,
360+ prefix : string ,
361+ extension : string ,
362+ ) : boolean {
363+ const stem = path . posix . basename ( value , extension ) ;
364+ return (
365+ value === path . posix . join ( REMOTE_TEMP_DIR , `${ stem } ${ extension } ` ) &&
366+ stem . startsWith ( `agent-device-${ prefix } -` ) &&
367+ / ^ \d + - [ a - z 0 - 9 ] + $ / . test ( stem . slice ( `agent-device-${ prefix } -` . length ) )
368+ ) ;
369+ }
370+
371+ function remoteTempArtifactStem ( prefix : string ) : string {
372+ return `agent-device-${ prefix } -${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 8 ) } ` ;
373+ }
374+
348375export async function materializeRemoteArtifacts (
349376 info : DaemonArtifactEndpoint ,
350377 req : DaemonRequest ,
0 commit comments