@@ -309,7 +309,9 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
309
309
response . reference ( llmsDocument . uri ) ;
310
310
311
311
// Add the contents of the file to the prompt
312
- prompts . push ( xml . node ( 'instructions' , llmsText ) ) ;
312
+ const instructionsNode = xml . node ( 'instructions' , llmsText ) ;
313
+ prompts . push ( instructionsNode ) ;
314
+ log . debug ( `[context] adding llms.txt context: ${ llmsText . length } characters` ) ;
313
315
}
314
316
}
315
317
@@ -334,20 +336,21 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
334
336
response . reference ( value . uri ) ;
335
337
336
338
// Add the visible region prompt.
337
- attachmentPrompts . push ( xml . node ( 'attachment' , visibleText , {
339
+ const rangeAttachmentNode = xml . node ( 'attachment' , visibleText , {
338
340
filePath : path ,
339
341
description : 'Visible region of the active file' ,
340
342
language : document . languageId ,
341
343
startLine : value . range . start . line + 1 ,
342
344
endLine : value . range . end . line + 1 ,
343
- } ) ) ;
344
-
345
- // Add the full document text prompt.
346
- attachmentPrompts . push ( xml . node ( 'attachment' , documentText , {
345
+ } ) ;
346
+ const documentAttachmentNode = xml . node ( 'attachment' , documentText , {
347
347
filePath : path ,
348
348
description : 'Full contents of the active file' ,
349
349
language : document . languageId ,
350
- } ) ) ;
350
+ } ) ;
351
+ attachmentPrompts . push ( rangeAttachmentNode , documentAttachmentNode ) ;
352
+ log . debug ( `[context] adding file range attachment context: ${ rangeAttachmentNode . length } characters` ) ;
353
+ log . debug ( `[context] adding file attachment context: ${ documentAttachmentNode . length } characters` ) ;
351
354
} else if ( value instanceof vscode . Uri ) {
352
355
const fileStat = await vscode . workspace . fs . stat ( value ) ;
353
356
if ( fileStat . type === vscode . FileType . Directory ) {
@@ -369,10 +372,12 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
369
372
// response.reference(value);
370
373
371
374
// Attach the folder's contents.
372
- attachmentPrompts . push ( xml . node ( 'attachment' , entriesText , {
375
+ const attachmentNode = xml . node ( 'attachment' , entriesText , {
373
376
filePath : path ,
374
377
description : 'Contents of the directory' ,
375
- } ) ) ;
378
+ } ) ;
379
+ attachmentPrompts . push ( attachmentNode ) ;
380
+ log . debug ( `[context] adding directory attachment context: ${ attachmentNode . length } characters` ) ;
376
381
} else {
377
382
// The user attached a file - usually a manually attached file in the workspace.
378
383
const document = await vscode . workspace . openTextDocument ( value ) ;
@@ -383,11 +388,13 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
383
388
response . reference ( value ) ;
384
389
385
390
// Attach the full document text.
386
- attachmentPrompts . push ( xml . node ( 'attachment' , documentText , {
391
+ const attachmentNode = xml . node ( 'attachment' , documentText , {
387
392
filePath : path ,
388
393
description : 'Full contents of the file' ,
389
394
language : document . languageId ,
390
- } ) ) ;
395
+ } ) ;
396
+ attachmentPrompts . push ( attachmentNode ) ;
397
+ log . debug ( `[context] adding file attachment context: ${ attachmentNode . length } characters` ) ;
391
398
}
392
399
} else if ( value instanceof vscode . ChatReferenceBinaryData ) {
393
400
if ( isChatImageMimeType ( value . mimeType ) ) {
@@ -400,18 +407,20 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
400
407
}
401
408
402
409
// Attach the image.
403
- attachmentPrompts . push ( xml . leaf ( 'img' , {
410
+ const imageNode = xml . leaf ( 'img' , {
404
411
src : reference . name ,
405
- } ) ) ;
412
+ } ) ;
413
+ attachmentPrompts . push ( imageNode ) ;
414
+ log . debug ( `[context] adding image attachment context: ${ data . length } bytes` ) ;
406
415
407
416
userDataParts . push (
408
417
vscode . LanguageModelDataPart . image ( data , value . mimeType ) ,
409
418
) ;
410
419
} else {
411
- console . warn ( `Positron Assistant: Unsupported chat reference binary data type: ${ typeof value } ` ) ;
420
+ log . warn ( `Unsupported chat reference binary data type: ${ typeof value } ` ) ;
412
421
}
413
422
} else {
414
- console . warn ( `Positron Assistant: Unsupported reference type: ${ typeof value } ` ) ;
423
+ log . warn ( `Unsupported reference type: ${ typeof value } ` ) ;
415
424
}
416
425
}
417
426
@@ -429,15 +438,18 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
429
438
const executions = positronContext . activeSession . executions
430
439
. map ( ( e ) => xml . node ( 'execution' , JSON . stringify ( e ) ) )
431
440
. join ( '\n' ) ;
432
- positronContextPrompts . push (
433
- xml . node ( 'session' ,
434
- xml . node ( 'executions' , executions ?? '' ) , {
435
- description : 'Current active session' ,
436
- language : positronContext . activeSession . language ,
437
- version : positronContext . activeSession . version ,
438
- mode : positronContext . activeSession . mode ,
439
- identifier : positronContext . activeSession . identifier ,
440
- } )
441
+ const sessionNode = xml . node ( 'session' ,
442
+ xml . node ( 'executions' , executions ?? '' ) , {
443
+ description : 'Current active session' ,
444
+ language : positronContext . activeSession . language ,
445
+ version : positronContext . activeSession . version ,
446
+ mode : positronContext . activeSession . mode ,
447
+ identifier : positronContext . activeSession . identifier ,
448
+ } ) ;
449
+ positronContextPrompts . push ( sessionNode ) ;
450
+ log . debug (
451
+ `[context] adding active ${ positronContext . activeSession . mode } ${ positronContext . activeSession . language } session context: ` +
452
+ `${ sessionNode . length } characters`
441
453
) ;
442
454
}
443
455
if ( positronContext . variables ) {
@@ -447,33 +459,33 @@ abstract class PositronAssistantParticipant implements IPositronAssistantPartici
447
459
const description = content . length > 0 ?
448
460
'Variables defined in the current session' :
449
461
'No variables defined in the current session' ;
450
- positronContextPrompts . push (
451
- xml . node ( 'variables' , content , {
452
- description ,
453
- } )
454
- ) ;
462
+ const variablesNode = xml . node ( 'variables' , content , {
463
+ description ,
464
+ } ) ;
465
+ positronContextPrompts . push ( variablesNode ) ;
466
+ log . debug ( `[context] adding variables context: ${ variablesNode . length } characters` ) ;
455
467
}
456
468
if ( positronContext . shell ) {
457
- positronContextPrompts . push (
458
- xml . node ( ' shell', positronContext . shell , {
459
- description : 'Current active shell' ,
460
- } )
461
- ) ;
469
+ const shellNode = xml . node ( 'shell' , positronContext . shell , {
470
+ description : 'Current active shell',
471
+ } ) ;
472
+ positronContextPrompts . push ( shellNode ) ;
473
+ log . debug ( `[context] adding shell context: ${ shellNode . length } characters` ) ;
462
474
}
463
475
if ( positronContext . plots && positronContext . plots . hasPlots ) {
464
- positronContextPrompts . push (
465
- xml . node ( 'plots' , 'A plot is visible.' )
466
- ) ;
476
+ const plotsNode = xml . node ( 'plots' , 'A plot is visible.' ) ;
477
+ positronContextPrompts . push ( plotsNode ) ;
478
+ log . debug ( `[context] adding plots context: ${ plotsNode . length } characters` ) ;
467
479
}
468
480
if ( positronContext . positronVersion ) {
469
- positronContextPrompts . push (
470
- xml . node ( 'version' , `Positron version: ${ positronContext . positronVersion } ` ) ,
471
- ) ;
481
+ const versionNode = xml . node ( 'version' , `Positron version: ${ positronContext . positronVersion } ` ) ;
482
+ positronContextPrompts . push ( versionNode ) ;
483
+ log . debug ( `[context] adding positron version context: ${ versionNode . length } characters` ) ;
472
484
}
473
485
if ( positronContext . currentDate ) {
474
- positronContextPrompts . push (
475
- xml . node ( 'date' , `Today's date is: ${ positronContext . currentDate } ` ) ,
476
- ) ;
486
+ const dateNode = xml . node ( 'date' , `Today's date is: ${ positronContext . currentDate } ` ) ;
487
+ positronContextPrompts . push ( dateNode ) ;
488
+ log . debug ( `[context] adding date context: ${ dateNode . length } characters` ) ;
477
489
}
478
490
if ( positronContextPrompts . length > 0 ) {
479
491
prompts . push ( xml . node ( 'context' , positronContextPrompts . join ( '\n\n' ) ) ) ;
@@ -738,7 +750,7 @@ export class PositronAssistantEditorParticipant extends PositronAssistantPartici
738
750
const selectedText = document . getText ( selection ) ;
739
751
const documentText = document . getText ( ) ;
740
752
const filePath = uriToString ( document . uri ) ;
741
- return xml . node ( 'editor' ,
753
+ const editorNode = xml . node ( 'editor' ,
742
754
[
743
755
xml . node ( 'document' , documentText , {
744
756
description : 'Full contents of the active file' ,
@@ -756,6 +768,8 @@ export class PositronAssistantEditorParticipant extends PositronAssistantPartici
756
768
documentOffset : document . offsetAt ( selection . active ) ,
757
769
} ,
758
770
) ;
771
+ log . debug ( `[context] adding editor context: ${ editorNode . length } characters` ) ;
772
+ return editorNode ;
759
773
}
760
774
761
775
}
0 commit comments