Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/import{ Code }from'./code';import{ IModelConfigSection, readModelConfigSections }from'./modelConfigPicker';constCHAT_VIEW='div[id="workbench.panel.chat"]';constCHAT_EDITOR='.editor-instance .interactive-session';constCHAT_INPUT_EDITOR=`${CHAT_VIEW} .interactive-input-part .monaco-editor[role="code"]`;constCHAT_INPUT_EDITOR_FOCUSED=`${CHAT_VIEW} .interactive-input-part .monaco-editor.focused[role="code"]
code Code
code
retryCount
code retryCount
code
text
codedrivercurrentPage
hasText text
state
message
code
sanitizedMessage message
codechatInputSelector sanitizedMessage
code
code
message
code
code
sanitizedMessage message
codechatEditorInputSelector sanitizedMessage
code
code
retryCount expectedCount
code els elslength expectedCount retryCount
retryCount expectedCount
code els elslength expectedCount retryCount
predicate RegExp timeoutMs options acceptToolConfirmations
predicate timeoutMs optionsacceptToolConfirmations
predicate RegExp timeoutMs options acceptToolConfirmations
matched predicate timeoutMs optionsacceptToolConfirmations
matched
timeoutMs
selector
codedriverselector state timeout timeoutMs
bubbleSelector renderedSelector predicate RegExp timeoutMs acceptToolConfirmations
deadline Date timeoutMs
text predicate textpredicate predicatetext
Date deadline
acceptToolConfirmations
code
elements codedriverrenderedSelector
matched elementsel eltextContent matches
matchedlength
bubbleSelector
matchedmatchedlength
r r
bubbleSelector timeoutMs fallbackQuietMs
settledSelector
start Date
deadline start timeoutMs
Date deadline
settled codedriversettledSelector
settledlength
r r
elapsed Date start
elapsed fallbackQuietMs
r r fallbackQuietMs elapsed
response codedrivercurrentPage
response
response codedrivercurrentPage
response
code el
elel
text el eltextContent eltextContent
text textlength
modelName timeoutMs
page codedrivercurrentPage
nameButton page
row page hasText modelName
deadline Date timeoutMs
lastError
Date deadline
nameButton
code
pagekeyboardmodelName
row state timeout
row force
page
state timeout
error
lastError error
pagekeyboard
r r
timeoutMs
page codedrivercurrentPage
configButton page
auxBar page
deadline Date timeoutMs
Date deadline
configButton
pagemouse
box auxBar
box
sashX boxx
sashY boxy Mathboxheight
pagemousesashX sashY
pagemouse
pagemousesashX sashY
pagemousesashX sashY
pagemouse
r r
timeoutMs
page codedrivercurrentPage
configButton page
configWidget page
has page
deadline Date timeoutMs
lastError
Date deadline
configButton state timeout
configButton force
configWidget state timeout
error
lastError error
pagekeyboard
r r
label timeoutMs
page codedrivercurrentPage
row page hasText label
deadline Date timeoutMs
lastError
Date deadline
row state timeout
row force
row state timeout
error
lastError error
Math deadline Date
page codedrivercurrentPage
pagekeyboard
page
sel c documentsel c c
timeout
page
state timeout
timeoutMs
page codedrivercurrentPage
button page
button state timeout timeoutMs
deadline Date timeoutMs
label
Date deadline
label button
label
r r
label
IModelConfigSection
codedrivercurrentPage
timeoutMs
page codedrivercurrentPage
widget page
widget state timeout timeoutMs
label page
deadline Date timeoutMs
lastError
Date deadline
box widget
box
pagemouse
pagemouseboxx boxwidth boxy boxheight
label state timeout
text label
text
error
lastError error
r r
timeoutMs
page codedrivercurrentPage
details page
deadline Date timeoutMs
Date deadline
pagemouse
details
r r
code Code
allowButtonSelector
buttons codedriverallowButtonSelector
buttons buttonslength buttonstextContent
allowButtons codedrivercurrentPage
hasText
total allowButtons
i i total i
b allowButtonsi
b
b timeout
// Insert via Monaco's executeEdits rather than character-by-character
// keypresses so suggestion widgets (e.g. the `[`-triggered chat reference
// picker) cannot intercept characters and corrupt the prompt.
// Newlines are replaced with spaces since Enter submits in chat input.
const
=
.
replace
(
/\n/g
,
' '
)
;
await
this
.
.
waitForTypeInEditor
(
this
.
,
)
;
// Wait for the send button to be enabled before clicking. The send
// button stays disabled until the chat participant is fully ready to
// receive a request — relying on Enter alone is fragile for providers
// that initialize asynchronously.
await
this
.
.
waitForElement
(
CHAT_SEND_BUTTON_ENABLED
,
undefined
,
600
)
;
await
this
.
.
waitAndClick
(
CHAT_SEND_BUTTON_ENABLED
)
;
}
async
sendEditorMessage
(
:
string
)
:
Promise
<
void
>
{
await
this
.
.
waitAndClick
(
CHAT_EDITOR_INPUT_EDITOR
)
;
await
this
.
.
waitForElement
(
CHAT_EDITOR_INPUT_EDITOR_FOCUSED
)
;
// Insert via Monaco's executeEdits rather than character-by-character
// keypresses so suggestion widgets (e.g. the `[`-triggered chat reference
// picker) cannot intercept characters and corrupt the prompt.
const
=
.
replace
(
/\n/g
,
' '
)
;
await
this
.
.
waitForTypeInEditor
(
this
.
,
)
;
// Wait for the send button to be enabled before clicking. The send
// button stays disabled until the chat session participant is fully
// ready to receive a request — relying on Enter alone is fragile for
// session types whose providers initialize asynchronously (e.g. Claude
// Agent).
await
this
.
.
waitForElement
(
CHAT_EDITOR_SEND_BUTTON_ENABLED
,
undefined
,
600
)
;
await
this
.
.
waitAndClick
(
CHAT_EDITOR_SEND_BUTTON_ENABLED
)
;
}
async
waitForResponse
(
?
:
number
,
:
number
=
1
)
:
Promise
<
void
>
{
// Wait until at least `expectedCount` completed (non-loading) response
// bubbles are present. Using a count-aware wait is needed for follow-up
// messages: after the first response is complete, a naive
// `waitForElement` would immediately satisfy on the prior response and
// miss the in-flight one.
await
this
.
.
waitForElements
(
CHAT_RESPONSE_COMPLETE
,
false
,
=>
.
>=
,
)
;
}
async
waitForEditorResponse
(
?
:
number
,
:
number
=
1
)
:
Promise
<
void
>
{
await
this
.
.
waitForElements
(
CHAT_EDITOR_RESPONSE_COMPLETE
,
false
,
=>
.
>=
,
)
;
}
/**
* Poll until at least one response bubble contains rendered markdown whose
* text matches `predicate`. Returns the matched text of the last matching
* bubble.
*
* Unlike {@link waitForResponse} this does NOT gate on the bubble losing
* the `chat-response-loading` class — some chat session types (notably
* Copilot CLI) keep the loading class on the bubble even after the
* assistant text has been fully streamed and rendered, which would
* otherwise cause a 180s timeout. Polling for the expected text makes the
* wait robust against that lingering loading state while still ensuring
* the content has actually arrived (avoiding false matches on placeholder
* text like "Considering" that appears before streaming begins).
*/
async
waitForResponseText
(
:
string
|
,
:
number
=
60_000
,
?
:
{
?
:
boolean
}
)
:
Promise
<
string
>
{
return
await
this
.
pollForResponseText
(
CHAT_RESPONSE
,
CHAT_RESPONSE_RENDERED
,
,
,
?.
)
;
}
async
waitForEditorResponseText
(
:
string
|
,
:
number
=
60_000
,
?
:
{
?
:
boolean
}
)
:
Promise
<
string
>
{
const
=
await
this
.
pollForResponseText
(
CHAT_EDITOR_RESPONSE
,
CHAT_EDITOR_RESPONSE_RENDERED
,
,
,
?.
)
;
// After a contributed chat session (e.g. Copilot CLI, Claude) returns
// its first response, the workbench commits the untitled session into
// a real (titled) one and `replaceEditors` swaps the chat editor over.
// If a follow-up message is sent during that swap, the participant
// request can be cancelled mid-flight by the editor swap. The
// {@link ChatEditor} sets `data-bound-chat-resource` on its editor
// container after binding its widget to the loaded chat model, and
// clears it during rebind — so we can wait for the swap to land via
// Playwright's push-based `waitForSelector` (no polling on our side).
await
this
.
waitForEditorChatBoundToCommittedResource
(
)
;
return
;
}
/**
* Wait until the chat editor's root container advertises a non-untitled
* chat resource via `data-bound-chat-resource`. Uses Playwright's
* `page.waitForSelector` which is push-based (MutationObserver in the
* renderer). Soft no-op when the selector never matches within
* `timeoutMs` (e.g. for local sessions that don't go through the
* untitled → committed swap).
*/
// Soft failure: caller already verified the response text is on
// screen, so proceed and let downstream assertions surface any
// actual problem.
}
}
private
async
pollForResponseText
(
:
string
,
:
string
,
:
string
|
,
:
number
,
?
:
boolean
)
:
Promise
<
string
>
{
const
=
.
now
(
)
+
;
const
matches
=
(
:
string
)
=>
typeof
===
'string'
?
.
includes
(
)
:
.
test
(
)
;
while
(
.
now
(
)
<
)
{
// When requested, accept any pending terminal tool confirmation so
// the agentic loop can proceed to render the final response. This
// is a no-op for sessions that auto-approve their shell commands.
if
(
)
{
await
acceptToolConfirmationIfPresent
(
this
.
)
;
}
const
=
await
this
.
.
.
getElements
(
,
/* recursive */
true
)
;
const
=
.
map
(
=>
.
??
''
)
.
filter
(
)
;
if
(
.
>
0
)
{
// Give the chat session a grace period to transition out of the
// in-progress state before returning. The chat-request lifecycle
// in extensions (notably Copilot CLI) has post-response async
// work (usage metrics, metadata persistence, session bookkeeping)
// that runs after the markdown is rendered. Sending a follow-up
// message while that work is in flight routes the second request
// through the steering code path, which does not reliably
// surface the response in the UI. We wait (with a generous cap)
// for any response bubble to drop the `chat-response-loading`
// class. Some providers leave the class set even after content
// has rendered, so we additionally enforce a small minimum
// quiet period before returning.
await
this
.
waitForResponseSettled
(
,
15_000
,
4_000
)
;
return
[
.
-
1
]
;
}
await
new
Promise
(
=>
setTimeout
(
,
250
)
)
;
}
throw
new
Error
(
`Timed out waiting for response matching ${predicate} in '${renderedSelector}'`
)
;
}
private
async
waitForResponseSettled
(
:
string
,
:
number
,
:
number
)
:
Promise
<
void
>
{
const
=
`${bubbleSelector}:not(.chat-response-loading)`
;
const
=
.
now
(
)
;
const
=
+
;
while
(
.
now
(
)
<
)
{
const
=
await
this
.
.
.
getElements
(
,
/* recursive */
true
)
;
if
(
.
>
0
)
{
return
;
}
await
new
Promise
(
=>
setTimeout
(
,
200
)
)
;
}
// Loading class never cleared (e.g. Copilot CLI). Wait a bit longer
// unconditionally so the underlying session has time to finish its
// post-response bookkeeping before the next request is dispatched.
const
=
.
now
(
)
-
;
if
(
<
)
{
await
new
Promise
(
=>
setTimeout
(
,
-
)
)
;
}
}
async
getLatestEditorResponseText
(
)
:
Promise
<
string
>
{
const
=
this
.
.
.
.
locator
(
CHAT_EDITOR_RESPONSE
)
.
last
(
)
;
return
(
await
.
textContent
(
)
)
??
''
;
}
async
getLatestResponseText
(
)
:
Promise
<
string
>
{
const
=
this
.
.
.
.
locator
(
CHAT_RESPONSE
)
.
last
(
)
;
return
(
await
.
textContent
(
)
)
??
''
;
}
async
waitForModelInFooter
(
)
:
Promise
<
void
>
{
await
this
.
.
waitForElements
(
CHAT_FOOTER_DETAILS
,
false
,
=>
{
return
.
some
(
=>
{
const
=
&&
typeof
.
===
'string'
?
.
:
''
;
return
!
!
&&
.
>
0
;
}
)
;
}
)
;
}
/**
* Opens the model picker (in the panel chat input) and selects the model
* whose displayed name contains `modelName`. Clicks the model-picker name
* button to open the popup, waits for the matching row to appear (models may
* still be registering), clicks it, then confirms the selection committed.
*
* The row click can occasionally fail to commit — e.g. absorbed by the
* action-widget's animating `context-view-pointerBlock` overlay — silently
* leaving the previous model (often "Auto") selected. That model advertises
* no configurable options, so the config button never appears and a later
* `openModelConfig` wedges. To absorb this, re-open the picker and retry until
* the name button reflects the chosen model or `timeoutMs` elapses.
*/
async
selectModel
(
:
string
,
:
number
=
60_000
)
:
Promise
<
void
>
{
const
=
this
.
.
.
;
const
=
.
locator
(
`${CHAT_MODEL_PICKER_NAME}:visible`
)
.
first
(
)
;
const
=
.
locator
(
ACTION_WIDGET_ROW
,
{
:
}
)
.
first
(
)
;
const
=
.
now
(
)
+
;
let
:
unknown
;
while
(
.
now
(
)
<
)
{
try
{
await
.
click
(
)
;
await
this
.
.
waitForElement
(
ACTION_WIDGET
)
;
// The picker opens with a focused filter input. Type the model name to
// narrow the list — otherwise the model may be hidden in a collapsed
// "Other Models" section.
await
.
.
type
(
)
;
await
.
waitFor
(
{
:
'visible'
,
:
10_000
}
)
;
// `force` bypasses the transient `context-view-pointerBlock` overlay
// that intercepts pointer events while the action widget animates open.
await
.
click
(
{
:
true
}
)
;
// Confirm the selection actually committed: the picker name button must
// now reflect the chosen model. (A non-committing click leaves the old
// model selected and the picker dismissed, so waiting only for the
// popup to close would miss it.) Match on the button's accessible name
// (aria-label, e.g. "Models, <modelName>") rather than the visible text:
// when the input is narrow the picker collapses to an icon-only button and
// no longer renders the model name as visible text. Scope to `:visible` so
// a hidden overflow duplicate of the name button can't produce a false
// Dismiss the (possibly empty / stale) picker so the next attempt
// re-opens a freshly-populated one.
try
{
await
.
.
press
(
'Escape'
)
;
}
catch
{
/* picker already gone */
}
await
new
Promise
(
=>
setTimeout
(
,
500
)
)
;
}
}
throw
new
Error
(
`Timed out selecting model "${modelName}". Last error: ${lastError instanceofError? lastError.message :String(lastError)}`
)
;
}
/**
* Widens the panel chat (its host auxiliary bar) until the model picker leaves
* its width-driven compact layout, i.e. until the inline model-config button
* renders. At the auxiliary bar's default width the picker collapses to an
* icon-only layout that omits the config button (and the model-name text), so
* tests that drive the inline config UI must first expand the panel.
*
* The panel is widened by dragging the auxiliary bar's leading sash outward.
* This is a no-op once the button is already visible, so it is safe to call
* repeatedly and cheap on the common (already-expanded) path.
*/
private
async
ensureModelPickerExpanded
(
:
number
=
20_000
)
:
Promise
<
void
>
{
const
=
this
.
.
.
;
const
=
.
locator
(
`${CHAT_MODEL_PICKER_CONFIG}:visible`
)
.
first
(
)
;
const
=
.
locator
(
AUXILIARYBAR_PART
)
.
first
(
)
;
const
=
.
now
(
)
+
;
while
(
.
now
(
)
<
)
{
if
(
await
.
isVisible
(
)
.
catch
(
(
)
=>
false
)
)
{
// Park the pointer away from the sash so a lingering cursor can't
// keep a resize hover active over the picker we're about to click.
await
.
.
move
(
0
,
0
)
.
catch
(
(
)
=>
{
/* no page */
}
)
;
return
;
}
const
=
await
.
boundingBox
(
)
.
catch
(
(
)
=>
null
)
;
if
(
)
{
// The auxiliary bar sits at the right edge of the workbench; its
// leading (left) sash lies on the bar's left border. Drag it left to
// widen the bar (and shrink the editor). Move the pointer onto the
// sash, then in two steps — a small nudge engages the drag before the
// larger travel — so the resize registers reliably.
const
=
.
;
const
=
.
+
.
min
(
.
/
2
,
200
)
;
await
.
.
move
(
,
)
;
await
.
.
down
(
)
;
await
.
.
move
(
-
20
,
)
;
await
.
.
move
(
-
160
,
)
;
await
.
.
up
(
)
;
}
// Let the ResizeObserver-driven relayout recompute the picker's compact
// state before re-checking / dragging again.
await
new
Promise
(
=>
setTimeout
(
,
300
)
)
;
}
}
/**
* Size) by clicking the model picker's configuration button. The button is
* only visible when the selected model advertises configurable options, so
* this waits for it to become visible before clicking.
*
* The config popup is shown through the singleton action-widget service and
* its rows are built once at open (rebuilt only on selection), so a popup
* observed mid-teardown of a previous open never self-heals. Waiting only for
* the popup container would therefore race a half-open / tearing-down popup
* that has no rows. To absorb that, this waits for actual option rows to
* render and re-opens (Escape + re-click) until they do — mirroring
* {@link selectModel}.
*/
async
openModelConfig
(
:
number
=
30_000
)
:
Promise
<
void
>
{
const
=
this
.
.
.
;
// There can be a hidden duplicate of the config button (e.g. an overflow
// copy); target the visible one.
const
=
.
locator
(
`${CHAT_MODEL_PICKER_CONFIG}:visible`
)
.
first
(
)
;
const
=
.
locator
(
`${ACTION_WIDGET}:visible`
,
{
:
.
locator
(
'.monaco-list-row.group-header'
)
}
)
.
first
(
)
;
const
=
.
now
(
)
+
;
let
:
unknown
;
// A context-usage details hover from a prior `readContextUsageTokenLabel`
// can linger as a body-level overlay over the model-config button; a forced
// click would then land on the popup instead of opening the dropdown,
// wedging it open without rows. Park the pointer away and wait for the
// overlay to detach before clicking.
await
this
.
dismissContextUsageDetails
(
)
;
// The inline model-config button only renders when the model picker is in
// its full layout. At the panel's default width the picker collapses to a
// compact, icon-only layout that omits the config button entirely, so widen
// the panel until the button appears before waiting on it below.
await
this
.
ensureModelPickerExpanded
(
)
;
while
(
.
now
(
)
<
)
{
try
{
await
.
waitFor
(
{
:
'visible'
,
:
15_000
}
)
;
await
.
click
(
{
:
true
}
)
;
await
.
locator
(
'.monaco-list-row.action'
)
.
first
(
)
.
waitFor
(
{
:
'visible'
,
:
5_000
}
)
;
return
;
}
catch
(
)
{
=
;
// Dismiss the (possibly empty / stale) popup so the next attempt
// re-opens a freshly-built one.
try
{
await
.
.
press
(
'Escape'
)
;
}
catch
{
/* popup already gone */
}
await
new
Promise
(
=>
setTimeout
(
,
250
)
)
;
}
}
throw
new
Error
(
`Timed out opening the model configuration dropdown. Last error: ${lastError instanceofError? lastError.message :String(lastError)}`
)
;
}
/**
* Clicks the option whose label contains `label` in the open model
* configuration dropdown, then waits until that option reads back as checked
* (the dropdown stays open and rebuilds in place after each selection, so the
* checked state confirms the underlying async configuration write resolved).
*
* The config picker only rebuilds its rows on selection, so a popup that
* opened without this option's row (e.g. mid-teardown of a previous open)
* never gains it. If the row doesn't appear, re-open the popup and retry;
* prior selections persist as configuration writes, so re-opening is safe.
*/
async
selectModelConfigOption
(
:
string
,
:
number
=
30_000
)
:
Promise
<
void
>
{
const
=
this
.
.
.
;
const
=
.
locator
(
ACTION_WIDGET_ROW
,
{
:
}
)
.
first
(
)
;
const
=
.
now
(
)
+
;
let
:
unknown
;
while
(
.
now
(
)
<
)
{
try
{
await
.
waitFor
(
{
:
'visible'
,
:
5_000
}
)
;
await
.
click
(
{
:
true
}
)
;
await
.
locator
(
'.codicon-check'
)
.
waitFor
(
{
:
'visible'
,
:
15_000
}
)
;
return
;
}
catch
(
)
{
=
;
// Re-open the popup so the next attempt sees a freshly-built list
// containing this option's row.
try
{
await
this
.
openModelConfig
(
.
max
(
5_000
,
-
.
now
(
)
)
)
;
}
catch
{
/* will retry until the outer deadline */
}
}
}
throw
new
Error
(
`Timed out selecting model config option "${label}". Last error: ${lastError instanceofError? lastError.message :String(lastError)}`
)
;
}
/**
* Dismisses the open model configuration dropdown.
*/
async
closeModelConfig
(
)
:
Promise
<
void
>
{
const
=
this
.
.
.
;
await
.
.
press
(
'Escape'
)
;
await
.
waitForFunction
(
(
:
string
)
=>
{
const
=
.
querySelector
(
)
;
return
!
||
.
getAttribute
(
'aria-expanded'
)
!==
'true'
;
}
,
CHAT_MODEL_PICKER_CONFIG
,
{
:
15_000
}
,
)
;
// Also wait for the popup's option rows to detach so a subsequent open
// starts from a clean state rather than racing this teardown. Best-effort:
// the rows may already be gone (the locator then resolves immediately).
await
.
locator
(
`${ACTION_WIDGET_ROW}:visible`
)
.
first
(
)
.
waitFor
(
{
:
'hidden'
,
:
5_000
}
)
.
catch
(
(
)
=>
{
/* already detached */
}
)
;
}
/**
* Returns the visible model-configuration button label (the combined
* "Effort Context" summary, e.g. "High 200K", shown in UBB mode).
*
* The button only renders in the model picker's full (non-compact) layout, so
* this widens the panel first — callers may read the label before ever opening
* the dropdown. The label is (re-)rendered when the selected model and its
* configuration resolve, so this polls until it carries text rather than
* returning an empty intermediate state.
*/
async
getModelConfigLabel
(
:
number
=
15_000
)
:
Promise
<
string
>
{
const
=
this
.
.
.
;
await
this
.
ensureModelPickerExpanded
(
)
;
const
=
.
locator
(
`${CHAT_MODEL_PICKER_CONFIG}:visible`
)
.
first
(
)
;
await
.
waitFor
(
{
:
'visible'
,
:
}
)
;
const
=
.
now
(
)
+
;
let
=
''
;
while
(
.
now
(
)
<
)
{
=
(
(
await
.
textContent
(
)
)
??
''
)
.
trim
(
)
;
if
(
)
{
break
;
}
await
new
Promise
(
=>
setTimeout
(
,
100
)
)
;
}
return
;
}
/**
* Returns the section headers and option rows of the open model configuration
* dropdown. Call after {@link openModelConfig}.
*/
async
getModelConfigSections
(
)
:
Promise
<
[
]
>
{
return
readModelConfigSections
(
this
.
.
.
)
;
}
/**
* Open the panel chat's context-usage details popup and return the full
* "{used} / {total} tokens" label text. The inline gauge only renders a
* percentage; the absolute context-window denominator lives in the details
* hover (a body-level overlay).
*
* Reads via a *hover* rather than a click on purpose: clicking the gauge opens
* a sticky, focus-trapping details hover that Escape cannot close and that
* then overlaps — and wedges — the model-config button on the next operation.
* The delayed (mouse) hover shows the same details and auto-hides once the
* pointer leaves the gauge. The gauge stays hidden until a response carrying
* token usage has rendered, so this waits for it first, then retries the
* hover + read since the delayed hover can occasionally need a second attempt.
* Moves the pointer off the gauge before returning so nothing lingers.
*/
async
readContextUsageTokenLabel
(
:
number
=
30_000
)
:
Promise
<
string
>
{
const
=
this
.
.
.
;
const
=
.
locator
(
`${CHAT_CONTEXT_USAGE_WIDGET}:visible`
)
.
first
(
)
;
await
.
waitFor
(
{
:
'visible'
,
:
}
)
;
const
=
.
locator
(
CONTEXT_USAGE_TOKEN_LABEL
)
.
first
(
)
;
const
=
.
now
(
)
+
;
let
:
unknown
;
while
(
.
now
(
)
<
)
{
try
{
// Trigger the gauge's delayed (non-sticky) hover with a raw pointer
// move to its center. A normal hover() waits on Playwright
// actionability — the gauge expands on hover and its progress arc
// animates, so the stability check can hang for the full timeout and
// eat the whole deadline (defeating this retry loop). Moving the
// pointer away first guarantees a fresh mouse-enter that (re-)opens
// the hover on every attempt.
const
=
await
.
boundingBox
(
)
;
if
(
!
)
{
throw
new
Error
(
'context-usage gauge has no bounding box'
)
;
}
await
.
.
move
(
0
,
0
)
;
await
.
.
move
(
.
+
.
/
2
,
.
+
.
/
2
)
;
await
.
waitFor
(
{
:
'visible'
,
:
5_000
}
)
;
const
=
(
await
.
textContent
(
)
)
??
''
;
// Move the pointer off the gauge so the non-sticky hover auto-hides
// and leaves no overlay to intercept later clicks.
await
this
.
dismissContextUsageDetails
(
)
;
return
.
trim
(
)
;
}
catch
(
)
{
=
;
await
this
.
dismissContextUsageDetails
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
500
)
)
;
}
}
throw
new
Error
(
`Timed out reading the context-usage details token label. Last error: ${lastError instanceofError? lastError.message :String(lastError)}`
)
;
}
/**
* Dismiss the context-usage details hover by moving the pointer off the gauge
* and waiting for the overlay to fully detach. The details popup is shown as a
* hover anchored to the context-usage gauge; the read path uses a non-sticky
* hover that hides once the pointer leaves, so parking the pointer away from
* every widget dismisses it (Escape does not close it). Best-effort: if it
* never detaches within the budget, the caller proceeds regardless.
*/
private
async
dismissContextUsageDetails
(
:
number
=
5_000
)
:
Promise
<
void
>
{
const
=
this
.
.
.
;
const
=
.
locator
(
CONTEXT_USAGE_DETAILS
)
;
const
=
.
now
(
)
+
;
while
(
.
now
(
)
<
)
{
// Park the pointer away from the gauge (and every other widget) so the
// hover hides and cannot be re-triggered by a lingering cursor.
try
{
await
.
.
move
(
0
,
0
)
;
}
catch
{
/* no page */
}
if
(
await
.
count
(
)
===
0
)
{
return
;
}
await
new
Promise
(
=>
setTimeout
(
,
150
)
)
;
}
}
}
/**
* Click the "Allow" button of a pending terminal tool confirmation if one is
* present. No-op when there is no confirmation (e.g. the session auto-approved
* its shell command). Shared by {@link Chat} and the Agents Window driver so
* shell-tool tests can drive the real confirmation flow without per-agent
* special-casing.
*
* The terminal confirmation renders as a `.chat-confirmation-widget2` whose
* action buttons are `.monaco-button.monaco-text-button` anchors — the primary
* "Allow" (rendered first), then "Skip". The dropdown chevron next to "Allow"
* is a `.monaco-dropdown-button.codicon` (no `.monaco-text-button`) and the
* carousel's "Allow All" lives on `.chat-tool-carousel-allow-all-button`, so
* neither is matched here. We verify the first text button actually reads
* "Allow" before clicking to avoid ever hitting "Skip".
*
* Uses the VS Code driver (`getElements`/`click`) rather than a raw Playwright
* locator: the confirmation renders outside the chat response/editor
* containers, and the driver reliably resolves it workbench-wide.
*/