@@ -427,6 +427,33 @@ export function projectComposerContextForProvider(input: {
427427 return `${ body } \n\n<${ CONTEXT_ENVELOPE_TAG } version="1">\n${ entries . join ( "\n" ) } \n</${ CONTEXT_ENVELOPE_TAG } >` ;
428428}
429429
430+ const ENVELOPE_CLOSE = `</${ CONTEXT_ENVELOPE_TAG } >` ;
431+ const PROVIDER_MARKER = / \[ ( [ A - Z ] [ ^ [ \] : ; \n ] * ) : ( [ ^ [ \] ; \n ] * ) ; r e f = ( [ ^ [ \] \s ] + ) \] / g;
432+ const MARKER_ENVELOPE_PREFIX = `\n\n<${ CONTEXT_ENVELOPE_TAG } version="1">\n<${ CONTEXT_ENTRY_TAG } kind="` ;
433+
434+ /**
435+ * Readable form of a single-reference `projectComposerContextForProvider` output, as question
436+ * answers store it. Only an envelope right after its own marker is removed; typed XML stays.
437+ */
438+ export function composerContextProviderTextForDisplay ( text : string ) : string {
439+ let result = "" ;
440+ let cursor = 0 ;
441+ for ( const match of text . matchAll ( PROVIDER_MARKER ) ) {
442+ if ( match . index < cursor ) continue ;
443+ const markerEnd = match . index + match [ 0 ] . length ;
444+ if ( ! text . startsWith ( MARKER_ENVELOPE_PREFIX , markerEnd ) ) continue ;
445+ const kindEnd = text . indexOf ( '"' , markerEnd + MARKER_ENVELOPE_PREFIX . length ) ;
446+ if ( kindEnd === - 1 || ! text . startsWith ( ` id="${ escapeAttribute ( match [ 3 ] ! ) } "` , kindEnd + 1 ) ) {
447+ continue ;
448+ }
449+ const close = text . indexOf ( ENVELOPE_CLOSE , kindEnd ) ;
450+ if ( close === - 1 ) continue ;
451+ result += `${ text . slice ( cursor , match . index ) } [${ match [ 1 ] } : ${ match [ 2 ] } ]` ;
452+ cursor = close + ENVELOPE_CLOSE . length ;
453+ }
454+ return result + text . slice ( cursor ) ;
455+ }
456+
430457// An agent reads threads on its own machine and on those it links to, even when a draft
431458// moves between machines.
432459export function threadContextsOutsideEnvironment ( input : {
0 commit comments