Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
'Reminder: This chat currently has an auto-generated or placeholder title. If the user references an issue or PR, fetch it first. Please give the chat a short, descriptive title based on the user\'s intent by calling `rename_chat` with `automatic: true`, silently and without a preamble. The user must not know that you are renaming. Do not skip it.'
;
/**
* Soft upper bound, in characters, for the whole context fed to the utility
* model when titling a session, including any appended GitHub context. Sized
* to stay well within the small model's context window while leaving room for
* the prompt scaffolding.
*/
const
MAX_TITLE_CONTEXT_CHARS
=
20000
;
/**
* Slice of {@link MAX_TITLE_CONTEXT_CHARS} always available to GitHub context,
* so a referenced issue title survives even a budget-filling conversation.
*/
const
MIN_GITHUB_CONTEXT_CHARS
=
4_000
;
type
GitHubReferenceKind
=
'issue'
|
'pull request'
;
interface
IGitHubReference
{
readonly
:
string
;
readonly
:
string
;
readonly
number
:
number
;
readonly
:
;
}
interface
IGitHubReferenceContext
{
readonly
:
;
readonly
:
;
}
/** Everything the utility model is told about when asked for a title. */
interface
ITitlePromptContext
{
/** The request or conversation to title. */
readonly
:
string
;
/** Whether {@link content} is a whole conversation rather than a single request. */
readonly
:
boolean
;
/** Text scanned for GitHub links to enrich {@link content} with, or `undefined` to skip enrichment. */
readonly
?
:
string
;
/** The title in place already, offered to the model as the incumbent. */
readonly
?
:
string
;
}
export
interface
IAgentHostSessionTitleControllerOptions
{
readonly
:
;
readonly
?
:
(
)
=>
string
|
undefined
;
readonly
?
:
(
)
=>
string
|
undefined
;
readonly
?
:
(
)
=>
string
|
undefined
;
readonly
?
:
number
;
readonly
?
:
;
readonly
?
:
;
readonly
?
:
(
)
=>
boolean
;
}
export
const
=
createDecorator<IAgentHostSessionTitleController>
(
'agentHostSessionTitleController'
)
;
/** Coordinates automatic, generated, and user-renamed session and chat titles. */
export
interface
IAgentHostSessionTitleController
{
readonly
:
undefined
;
seedTitleFromFirstMessage
(
:
,
:
string
,
?
:
)
:
void
;
seedProvisionalTitle
(
:
,
:
string
,
?
:
)
:
void
;
refineTitleFromFirstTurn
(
:
,
?
:
)
:
void
;
generateForkedTitle
(
:
,
:
|
undefined
,
:
readonly
[
]
,
:
string
,
?
:
string
)
:
void
;
generateExternalSessionTitle
(
:
,
:
string
)
:
Promise
<
void
>
;
cancelTitleGeneration
(
:
)
:
void
;
clearSession
(
:
,
:
readonly
[
]
)
:
void
;
markTitleAuto
(
:
,
:
|
undefined
,
:
string
)
:
void
;
markTitleRenamed
(
:
,
?
:
)
:
void
;
prepareInstructionForAgent
(
:
,
:
)
:
Promise
<
string
|
undefined
>
;
}
export
class
AgentHostSessionTitleController
extends
Disposable
implements
IAgentHostSessionTitleController
{
declare
readonly
:
undefined
;
private
readonly
=
new
Map<ProtocolURI, CancellationTokenSource>
(
)
;
/**
* The most recent title this controller applied for a given session/chat
* key. Used to detect whether the title was changed (e.g. a manual
* `/rename` or user edit) since we last set it, so we never clobber a
* deliberate title with an auto-generated one.
*/
private
readonly
=
new
Map<ProtocolURI,string>
(
)
;
/**
* Session/chat keys whose current title is a provisional placeholder set by
* {@link seedProvisionalTitle} (e.g. from a `!command`). Such a title does
* not describe the session's topic, so the first subsequent request that
* carries real intent replaces it with a generated title via
* {@link seedTitleFromFirstMessage}.
*/
private
readonly
=
new
Set<ProtocolURI>
(
)
;
private
readonly
=
new
Set<ProtocolURI>
(
)
;
private
readonly
=
new
Set<ProtocolURI>
(
)
;
constructor
(
private
readonly
:
,
private
readonly
:
,
@ILogService
private
readonly
:
,
)
{
super
(
)
;
}
seedTitleFromFirstMessage
(
:
,
:
string
,
?
:
)
:
void
{
if
(
this
.
_isEphemeralSession
(
)
)
{
return
;
}
const
=
this
.
_isActiveAgentTitleGenerationEnabled
(
)
;
const
=
?
this
.
_normalizeActiveAgentFallbackTitle
(
)
:
this
.
_normalizeTitle
(
)
;
if
(
!
)
{
return
;
}
const
=
this
.
_independentChatChannel
(
,
)
;
const
=
??
;
const
=
?
this
.
.
getChatState
(
)
:
this
.
.
getSessionState
(
)
;
if
(
!
||
!
this
.
_canSeedFirstMessageTitle
(
,
.
.
,
.
)
)
{
return
;
}
const
=
this
.
.
has
(
)
;
this
.
.
delete
(
)
;
this
.
_applySeedTitle
(
,
,
)
;
if
(
)
{
this
.
markTitleAuto
(
,
,
)
;
return
;
}
if
(
)
{
this
.
_persistAutoTitle
(
,
,
)
;
}
this
.
_generateTitleSoon
(
,
{
:
,
:
false
,
:
}
,
,
=>
this
.
_applySeedTitle
(
,
,
)
,
(
)
=>
this
.
_currentSeedTitle
(
,
)
===
this
.
.
get
(
)
,
=>
this
.
_persistAutoTitle
(
,
,
)
,
)
;
}
/** Seeds and persists a provisional title suggested by a locally handled command. */
seedProvisionalTitle
(
:
,
:
string
,
?
:
)
:
void
{
if
(
this
.
_isEphemeralSession
(
)
)
{
return
;
}
const
=
this
.
_normalizeTitle
(
,
this
.
_isActiveAgentTitleGenerationEnabled
(
)
?
MAX_ACTIVE_AGENT_FALLBACK_TITLE_LENGTH
:
MAX_TITLE_LENGTH
)
;
if
(
!
)
{
return
;
}
const
=
this
.
_independentChatChannel
(
,
)
;
const
=
??
;
const
=
?
this
.
.
getChatState
(
)
:
this
.
.
getSessionState
(
)
;
if
(
!
||
!
this
.
_canSeedProvisionalTitle
(
,
.
)
)
{
return
;
}
this
.
.
add
(
)
;
this
.
_applySeedTitle
(
,
,
)
;
this
.
_persistAutoTitle
(
,
,
)
;
}
/** Trims, collapses whitespace, and length-caps a candidate title. */
/**
* The independently titled chat a seed should target, or `undefined` to
* title the session-backed sole default chat.
*/
private
_independentChatChannel
(
:
,
?
:
)
:
|
undefined
{
if
(
!
||
!
isAhpChatChannel
(
)
)
{
return
undefined
;
}
return
!
isDefaultChatUri
(
)
||
(
this
.
.
getSessionState
(
)
?.
.
??
1
)
>
1
?
:
undefined
;
}
/**
* Applies `title` to the independently titled chat (`independentChat`) or, when
* that is `undefined`, to the session itself, recording it as last-applied.
*/
private
_applySeedTitle
(
:
,
:
|
undefined
,
:
string
)
:
void
{
if
(
)
{
this
.
_applyTitle
(
,
,
=>
this
.
.
updateChatTitle
(
,
,
)
)
;
this
.
_persistAutoTitleSource
(
,
)
;
}
else
{
this
.
_applyTitle
(
,
,
=>
this
.
.
dispatchServerAction
(
,
{
:
.
,
:
,
}
)
)
;
this
.
_persistAutoTitleSource
(
,
undefined
)
;
}
}
/** Persists `title` as the custom title of the addressed independent chat or session. */
private
_persistAutoTitle
(
:
,
:
|
undefined
,
:
string
)
:
void
{
if
(
)
{
this
.
_persistSessionFlag
(
,
customChatTitleMetadataKey
(
)
,
)
;
this
.
_persistSessionFlag
(
,
customChatTitleSourceMetadataKey
(
)
,
AGENT_HOST_TITLE_SOURCE_AUTO
)
;
return
;
}
this
.
_persistSessionFlag
(
,
SESSION_CUSTOM_TITLE_KEY
,
)
;
this
.
_persistSessionFlag
(
,
SESSION_CUSTOM_TITLE_SOURCE_KEY
,
AGENT_HOST_TITLE_SOURCE_AUTO
)
;
}
private
_persistAutoTitleSource
(
:
,
:
|
undefined
)
:
void
{
this
.
_persistSessionFlag
(
,
?
customChatTitleSourceMetadataKey
(
)
:
SESSION_CUSTOM_TITLE_SOURCE_KEY
,
AGENT_HOST_TITLE_SOURCE_AUTO
)
;
}
/** The live title of the addressed independent chat or session. */
private
_currentSeedTitle
(
:
,
:
|
undefined
)
:
string
|
undefined
{
return
?
this
.
.
getChatState
(
)
?.
:
this
.
.
getSessionState
(
)
?.
;
}
/**
* Whether {@link seedTitleFromFirstMessage} may (re)title `key`: true for a
* fresh, untitled target (its first message) or when its title is a
* provisional placeholder we applied and no one has changed it since — the
* first real request supersedes the placeholder.
*/
private
_canSeedFirstMessageTitle
(
:
,
:
number
,
:
string
|
undefined
)
:
boolean
{
if
(
===
0
&&
!
)
{
return
true
;
}
return
this
.
.
has
(
)
&&
!
!
&&
===
this
.
.
get
(
)
;
}
/**
* Whether {@link seedProvisionalTitle} may (re)title `key`: true when it is
* untitled (the first message carried a suggestion) or when its title is a
* provisional placeholder we applied and no one has changed it since —
* successive suggestions keep the newest one visible without clobbering a
* manual rename.
*/
private
_canSeedProvisionalTitle
(
:
,
:
string
|
undefined
)
:
boolean
{
if
(
!
)
{
return
true
;
}
return
this
.
.
has
(
)
&&
===
this
.
.
get
(
)
;
}
/**
* Re-generates the title once the first turn has completed, this time
* using the full first-turn context (the user request plus the agent's
* textual response) rather than just the opening message. This only runs
* for the very first turn and only when the current title is still the one
* this controller last applied — a manual `/rename`, a user edit, or a
* forked session's inherited title all suppress it.
*
* Only normal text response parts are considered (tool calls, reasoning,
* and other parts are ignored). If the context still exceeds the budget
* the middle is removed (marked with `...`). The user's first request is
* always preserved.
*/
refineTitleFromFirstTurn
(
:
,
?
:
)
:
void
{
if
(
this
.
_isEphemeralSession
(
)
)
{
return
;
}
if
(
this
.
_isActiveAgentTitleGenerationEnabled
(
)
)
{
return
;
}
const
=
!
!
&&
isAhpChatChannel
(
)
&&
!
isDefaultChatUri
(
)
;
if
(
)
{
const
=
this
.
.
getChatState
(
)
;
if
(
!
||
.
.
!==
1
)
{
return
;
}
const
=
this
.
.
get
(
)
;
if
(
===
undefined
||
.
!==
)
{
return
;
}
const
=
.
[
0
]
;
const
=
this
.
_buildFirstTurnContext
(
)
;
if
(
!
)
{
return
;
}
const
apply
=
(
:
string
)
=>
{
this
.
_applyTitle
(
,
,
=>
this
.
.
updateChatTitle
(
,
,
)
)
;
this
.
_persistAutoTitleSource
(
,
)
;
}
;
this
.
_generateTitleSoon
(
,
{
:
,
:
true
,
:
.
.
,
:
}
,
,
,
(
)
=>
this
.
.
getChatState
(
)
?.
===
this
.
.
get
(
)
,
=>
this
.
_persistAutoTitle
(
,
,
)
,
)
;
return
;
}
const
=
this
.
.
getSessionState
(
)
;
if
(
!
||
.
.
!==
1
)
{
return
;
}
const
=
this
.
.
get
(
)
;
if
(
===
undefined
||
.
!==
)
{
return
;
}
const
=
.
[
0
]
;
const
=
this
.
_buildFirstTurnContext
(
)
;
if
(
!
)
{
return
;
}
const
apply
=
(
:
string
)
=>
{
this
.
_applyTitle
(
,
,
=>
this
.
.
dispatchServerAction
(
,
{
:
.
,
:
,
}
)
)
;
this
.
_persistAutoTitleSource
(
,
undefined
)
;
}
;
this
.
_generateTitleSoon
(
,
{
:
,
:
true
,
:
.
.
,
:
}
,
,
,
(
)
=>
this
.
.
getSessionState
(
)
?.
===
this
.
.
get
(
)
,
=>
this
.
_persistAutoTitle
(
,
undefined
,
)
,
)
;
}
/**
* Generates a title for a freshly forked session or chat from its
* inherited conversation context. Forks copy the source history up to the
* fork point, so neither {@link seedTitleFromFirstMessage} nor
* {@link refineTitleFromFirstTurn} (which require an empty / single-turn
* state) ever fire for them. This is the fork equivalent, run once at fork
* time over the kept turns, so the new chat gets a content-derived title
* instead of permanently inheriting the source's `Forked: …` title.
*
* `fallbackTitle` is the title the caller already applied to the new
* session/chat (e.g. `Forked: <source>`); it is recorded as the
* last-applied title so a concurrent manual rename suppresses the
* generated title, and stays visible until generation completes. The
* context is bounded to {@link MAX_TITLE_CONTEXT_CHARS} (middle-truncated),
* so generation costs at most a single small-model call.
*/
generateForkedTitle
(
:
,
:
|
undefined
,
:
readonly
[
]
,
:
string
,
?
:
string
)
:
void
{
if
(
this
.
_isEphemeralSession
(
)
)
{
return
;
}
if
(
this
.
_isActiveAgentTitleGenerationEnabled
(
)
)
{
this
.
markTitleAuto
(
,
,
)
;
return
;
}
const
=
this
.
_buildConversationContext
(
,
)
;
if
(
!
)
{
return
;
}
const
=
!
!
&&
isAhpChatChannel
(
)
&&
!
isDefaultChatUri
(
)
;
if
(
)
{
const
=
;
this
.
.
set
(
,
)
;
this
.
_persistAutoTitleSource
(
,
)
;
const
apply
=
(
:
string
)
=>
this
.
_applyTitle
(
,
,
=>
this
.
.
updateChatTitle
(
,
,
)
)
;
this
.
_generateTitleSoon
(
,
{
:
,
:
true
}
,
,
,
(
)
=>
this
.
.
getChatState
(
)
?.
===
this
.
.
get
(
)
,
=>
this
.
_persistAutoTitle
(
,
,
)
,
)
;
return
;
}
this
.
.
set
(
,
)
;
this
.
_persistAutoTitleSource
(
,
undefined
)
;
const
apply
=
(
:
string
)
=>
this
.
_applyTitle
(
,
,
=>
this
.
.
dispatchServerAction
(
,
{
:
.
,
:
,
}
)
)
;
this
.
_generateTitleSoon
(
,
{
:
,
:
true
}
,
,
,
(
)
=>
this
.
.
getSessionState
(
)
?.
===
this
.
.
get
(
)
,
=>
this
.
_persistAutoTitle
(
,
undefined
,
)
,
)
;
}
private
_applyTitle
(
:
,
:
string
,
dispatch
:
(
:
string
)
=>
void
)
:
void
{
this
.
.
set
(
,
)
;
dispatch
(
)
;
}
/**
* Generates a title for an external session whose provider surfaced it
* without one, from the user's first prompt. Such a session usually has no
* live state (it is materialized when opened), so the generated title is
* persisted and pushed onto its surfaced summary. A session that already
* carries a persisted title keeps it; a rename during generation cancels it.
*
* Unlike the other entry points this awaits generation, so the caller's
* deferred-work lane stays serialized against it.
*/
async
generateExternalSessionTitle
(
:
,
:
string
)
:
Promise
<
void
>
{
if
(
this
.
_isEphemeralSession
(
)
||
await
this
.
_readPersistedTitleMetadata
(
,
SESSION_CUSTOM_TITLE_KEY
)
)
{
return
;
}
await
this
.
_startTitleGeneration
(
,
{
:
,
:
false
,
:
}
,
''
,
=>
this
.
_applyExternalSessionTitle
(
,
)
,
(
)
=>
true
,
=>
this
.
_persistAutoTitle
(
,
undefined
,
)
,
)
;
}
private
_applyExternalSessionTitle
(
:
,
:
string
)
:
void
{
if
(
this
.
.
getSessionState
(
)
)
{
this
.
_applySeedTitle
(
,
undefined
,
)
;
}
else
{
this
.
_applyTitle
(
,
,
=>
this
.
.
updateSurfacedSessionTitle
(
,
)
)
;
}
}
cancelTitleGeneration
(
:
)
:
void
{
this
.
_cancelTitleGeneration
(
)
;
}
clearSession
(
:
,
:
readonly
[
]
)
:
void
{
for
(
const
of
[
,
buildDefaultChatUri
(
)
,
...
]
)
{
this
.
_cancelTitleGeneration
(
)
;
this
.
.
delete
(
)
;
this
.
.
delete
(
)
;
this
.
.
delete
(
)
;
this
.
.
delete
(
)
;
}
}
markTitleAuto
(
:
,
:
|
undefined
,
:
string
)
:
void
{
const
=
this
.
_independentChatChannel
(
,
)
;
const
=
??
;
this
.
.
set
(
,
)
;
this
.
.
add
(
)
;
this
.
.
delete
(
)
;
this
.
_persistAutoTitle
(
,
,
)
;
}
markTitleRenamed
(
:
,
?
:
)
:
void
{
const
=
this
.
_independentChatChannel
(
,
)
??
;
this
.
_cancelTitleGeneration
(
)
;
this
.
.
delete
(
)
;
this
.
.
delete
(
)
;
this
.
.
add
(
)
;
}
async
prepareInstructionForAgent
(
:
,
:
)
:
Promise
<
string
|
undefined
>
{
if
(
this
.
_isEphemeralSession
(
)
)
{
return
undefined
;
}
if
(
!
this
.
_isActiveAgentTitleGenerationEnabled
(
)
)
{
return
undefined
;
}
const
=
this
.
_independentChatChannel
(
,
)
;
const
=
??
;
if
(
this
.
.
has
(
)
)
{
return
undefined
;
}
const
=
?
customChatTitleSourceMetadataKey
(
)
:
SESSION_CUSTOM_TITLE_SOURCE_KEY
;
const
=
await
this
.
_readPersistedTitleMetadata
(
,
)
;
if
(
===
AGENT_HOST_TITLE_SOURCE_USER
||
===
AGENT_HOST_TITLE_SOURCE_AGENT
)
{
this
.
markTitleRenamed
(
,
)
;
return
undefined
;
}
if
(
!==
AGENT_HOST_TITLE_SOURCE_AUTO
&&
!
this
.
.
has
(
)
)
{
return
undefined
;
}
return
CHAT_RENAME_REMINDER
;
}
private
_generateTitleSoon
(
:
,
:
,
:
string
,
apply
:
(
:
string
)
=>
void
,
currentTitleMatchesFallback
:
(
)
=>
boolean
,
persist
:
(
:
string
)
=>
void
,
)
:
void
{
void
this
.
_startTitleGeneration
(
,
,
,
,
,
)
;
}
/** Starts generation and resolves once the title has been applied and persisted. */
private
_startTitleGeneration
(
:
,
:
,
:
string
,
apply
:
(
:
string
)
=>
void
,
currentTitleMatchesFallback
:
(
)
=>
boolean
,
persist
:
(
:
string
)
=>
void
,
)
:
Promise
<
void
>
{
this
.
_cancelTitleGeneration
(
)
;
const
=
new
CancellationTokenSource
(
)
;
this
.
.
set
(
,
)
;
return
this
.
_generateTitle
(
,
,
,
,
,
,
.
)
.
catch
(
=>
{
if
(
!
.
.
)
{
this
.
.
warn
(
`[AgentHostSessionTitleController] Failed to apply generated title for ${key}`
,
)
;
}
}
)
.
finally
(
(
)
=>
{
if
(
this
.
.
get
(
)
===
)
{
this
.
.
delete
(
)
;
.
dispose
(
)
;
}
}
)
;
}
private
async
_generateTitle
(
:
,
:
,
:
string
,
apply
:
(
:
string
)
=>
void
,
currentTitleMatchesFallback
:
(
)
=>
boolean
,
persist
:
(
:
string
)
=>
void
,
:
,
)
:
Promise
<
void
>
{
const
=
await
this
.
_generateTitleFromPrompt
(
,
)
;
if
(
.
||
!
)
{
return
;
}
if
(
!
currentTitleMatchesFallback
(
)
)
{
return
;
}
if
(
!==
)
{
apply
(
)
;
}
persist
(
)
;
}
private
async
_generateTitleFromPrompt
(
:
,
:
)
:
Promise
<
string
|
undefined
>
{
if
(
.
)
{
return
undefined
;
}
const
=
this
.
.
?.
(
)
;
const
=
this
.
.
;
if
(
!
||
!
)
{
return
undefined
;
}
const
=
new
AbortController
(
)
;
const
=
.
onCancellationRequested
(
(
)
=>
.
abort
(
)
)
;
try
{
const
=
.
===
undefined
?
.
:
await
this
.
_appendGitHubContext
(
.
,
.
,
.
,
)
;
if
(
.
)
{
return
undefined
;
}
const
=
await
.
utilityChatCompletion
(
,
{
:
this
.
_buildTitlePrompt
(
,
)
,
:
MAX_TITLE_TOKENS
,
}
,
{
:
.
,
}
)
;
return
this
.
_cleanTitle
(
,
)
;
}
catch
(
)
{
if
(
.
)
{
return
undefined
;
}
this
.
.
warn
(
'[AgentHostSessionTitleController] Failed to generate session title'
,
)
;
return
undefined
;
}
finally
{
.
dispose
(
)
;
}
}
/**
* Appends the GitHub issue / pull requests linked from `referenceSource` to
* `promptContent`, keeping the combined text within
* {@link MAX_TITLE_CONTEXT_CHARS}. Enrichment is guaranteed
* {@link MIN_GITHUB_CONTEXT_CHARS}; whatever it leaves over bounds
* `promptContent`, whose middle is dropped so the request at its head and
* the response tail both survive.
*/
private
async
_appendGitHubContext
(
:
string
,
:
string
,
:
,
:
)
:
Promise
<
string
>
{
const
=
this
.
_parseGitHubReferences
(
)
;
const
=
this
.
.
?.
(
)
;
const
=
this
.
.
;
if
(
.
===
0
||
!
||
!
)
{
return
;
}
const
=
.
any
(
[
,
.
timeout
(
this
.
.
??
GITHUB_CONTEXT_REQUEST_TIMEOUT
)
]
)
;
const
=
new
Limiter<IGitHubReferenceContext |undefined>
(
MAX_CONCURRENT_GITHUB_CONTEXT_REQUESTS
)
;
try
{
const
=
await
Promise
.
all
(
.
map
(
=>
.
queue
(
async
(
)
=>
{
try
{
const
=
await
.
getIssueOrPullRequest
(
.
,
.
,
.
number
,
,
,
)
;
return
{
,
}
;
}
catch
(
)
{
if
(
!
.
)
{
this
.
.
warn
(
`[AgentHostSessionTitleController] Failed to fetch GitHub ${reference.kind}${reference.owner}/${reference.repo}#${reference.number}`
`The title of the ${reference.kind} is: ${value.title}`
,
`The body of the ${reference.kind} is:`
,
,
]
.
join
(
'\n'
)
;
}
private
_buildTitlePrompt
(
:
string
,
:
)
:
[
]
{
const
=
.
?
`Please write a brief title for the following conversation:\n\n${promptContent}`
:
`Please write a brief title for the following request:\n\n${promptContent}`
;
const
=
.
?.
trim
(
)
;
const
=
?
`${request}\n\nIts current title is: ${currentTitle}\nReply with that same title unless the text above supports a clearly more accurate one.`
:
;
return
[
{
:
'system'
,
:
[
'You are an expert in crafting ultra-compact titles for chatbot conversations.'
,
'You are presented with a chat request or conversation, and you reply with only a brief title that captures the main topic.'
,
'Write the title in sentence case, not title case.'
,
'Preserve product names, abbreviations, code symbols, and proper nouns.'
,
'Aim for 3-6 words. Prefer the shortest accurate title.'
,
'Drop articles like "a", "an", and "the" unless needed for clarity.'
,
'Drop filler and generic framing like "help with", "question about", "request for", or "issue with".'
,
'Never describe the chat itself as forked, branched, or continued — title only the underlying topic.'
,
'Prefer short, concrete synonyms and omit unnecessary words.'
,
'Do not wrap the title in quotes or add trailing punctuation.'
,
]
.
join
(
' '
)
,
}
,
{
:
'user'
,
:
,
}
,
]
;
}
private
_cleanTitle
(
:
string
,
:
string
)
:
string
|
undefined
{
let
=
.
trim
(
)
;
const
=
.
split
(
/\r?\n/
)
.
map
(
=>
.
trim
(
)
)
.
find
(
=>
.
>
0
)
;
=
??
''
;
if
(
.
startsWith
(
'"'
)
&&
.
endsWith
(
'"'
)
&&
.
>
1
)
{
=
.
slice
(
1
,
-
1
)
.
trim
(
)
;
}
=
.
replace
(
/[.!?]+$/
,
''
)
.
trim
(
)
;
if
(
!
||
.
includes
(
'can\'t assist with that'
)
)
{
return
undefined
;
}
=
.
slice
(
0
,
MAX_TITLE_LENGTH
+
MAX_TRAILING_HAN_SUFFIX_CODE_UNITS
)
;
return
this
.
_stripUnexpectedTrailingHanSuffix
(
,
)
.
slice
(
0
,
MAX_TITLE_LENGTH
)
;
}
private
_stripUnexpectedTrailingHanSuffix
(
:
string
,
:
string
)
:
string
{
if
(
HAN_CHARACTER
.
test
(
)
)
{
return
;
}
const
=
TRAILING_HAN_SUFFIX
.
exec
(
)
;
if
(
!
)
{
return
;
}
const
=
.
slice
(
0
,
.
)
.
trimEnd
(
)
;
const
=
.
match
(
/\p{L}/gu
)
?.
??
0
;
const
=
.
match
(
/\p{sc=Latin}/gu
)
?.
??
0
;
if
(
<
MIN_LATIN_LETTERS_BEFORE_HAN_SUFFIX
||
/
<
MIN_LATIN_LETTER_RATIO
)
{
return
;
}
return
;
}
/**
* Builds the first-turn context string for title refinement. The user's
* request is always kept (truncated in the middle only if it alone exceeds
* half the budget). Only normal text (markdown) response parts are
* considered — tool calls, reasoning, and other parts are ignored. If the
* combined text is over budget, the middle of the response is removed.
*
* @returns the context string, or `undefined` when the turn has no text
* response worth refining from (the opening message already produced a
* title in that case).
*/
private
_buildFirstTurnContext
(
:
)
:
string
|
undefined
{
const
=
renderResponseMarkdown
(
.
)
;
if
(
!
)
{
return
undefined
;
}
const
=
.
floor
(
MAX_TITLE_CONTEXT_CHARS
/
2
)
;
let
=
.
.
.
trim
(
)
;
if
(
.
>
)
{
=
truncateMiddle
(
,
)
;
}
const
=
`User request:\n${userRequest}`
;
const
=
'\n\nAgent response:\n'
;
const
=
.
max
(
0
,
MAX_TITLE_CONTEXT_CHARS
-
.
-
.
)
;
const
=
.
>
?
truncateMiddle
(
,
)
:
;
return
?
`${userBlock}${responseLabel}${trimmedResponse}`
:
;
}
/**
* Builds a conversation context string for forked-title generation by
* concatenating each kept turn's user request and textual response. Only
* normal text (markdown) response parts are considered — tool calls,
* reasoning, and other parts are ignored, mirroring
* {@link _buildFirstTurnContext}. When the fork's `sourceTitle` is known, a
* short framing note is prepended so the model understands the conversation
* is a branch continued from an earlier chat. The conversation is
* middle-truncated to {@link MAX_TITLE_CONTEXT_CHARS} to bound model cost;
* the framing note is always preserved in full.
*
* @returns the context string, or `undefined` when no turn carries any
* text worth titling from.
*/
private
_buildConversationContext
(
:
readonly
[
]
,
?
:
string
)
:
string
|
undefined
{
const
=
?.
trim
(
)
;
const
=
?
`This conversation was branched from an earlier chat titled "${framedTitle}". The turns below, oldest first, are the inherited history up to the branch point.\n\n`
:
undefined
;
return
buildConversationContext
(
,
{
:
MAX_TITLE_CONTEXT_CHARS
,
}
)
;
}
private
_persistSessionFlag
(
:
,
:
string
,
:
string
)
:
void
{
persistSessionMetadata
(
this
.
.
,
this
.
,
,
,
)
;
}
private
_isActiveAgentTitleGenerationEnabled
(
:
)
:
boolean
{
const
=
this
.
.
getSessionState
(
)
?.
;
return
?
.
some
(
=>
.
===
.
)
:
this
.
.
?.
(
)
===
true
;
}
private
_isEphemeralSession
(
:
)
:
boolean
{
return
this
.
.
isEphemeralSession
(
)
;
}
private
async
_readPersistedTitleMetadata
(
:
,
:
string
)
:
Promise
<
string
|
undefined
>
{
try
{
const
=
await
this
.
.
.
?.
(
URI
.
parse
(
)
)
;
if
(
!
)
{
return
undefined
;
}
try
{
return
await
.
.
getMetadata
(
)
;
}
finally
{
.
dispose
(
)
;
}
}
catch
(
)
{
this
.
.
warn
(
`[AgentHostSessionTitleController] Failed to read title metadata '${key}'`