Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* `WarmQuery` stub that records `query()` calls and async-dispose count.
* Tests in this file deliberately do NOT drive the consumer loop — they
* exercise the synchronous lifecycle surface (abort, dispose, rebind
* gating). Driving the SDK message stream end-to-end is covered by
* `claudeAgent.test.ts`.
*
* `query()` returns a stub `Query` whose async iterator immediately
* resolves done. That keeps the pipeline's consumer loop from hanging
* even when a test happens to call `send()`.
*/
/**
* `WarmQuery` whose bound `Query` records every `applyFlagSettings` call so
* tests can assert the exact effort payload pushed to the SDK (including the
* `{ effortLevel: null }` clear emitted when switching to a model that does
* not support reasoning effort).
*
* Unlike {@link ImmediatelyDoneQuery}, its async iterator BLOCKS rather than
* ending immediately — otherwise the consumer loop would hit "stream ended
* without a result", null out `_query`, and the runtime setters would no-op
* before the test can observe them. A blocking iterator models a live turn.
*
* The block is abort-aware: `next()` resolves `{ done: true }` once the
* pipeline's {@link AbortController} fires (on dispose/teardown), so the
* consumer loop and the fire-and-forget `send()` promise unwind instead of
* pinning the pipeline/query graph for the rest of the run.
*/
class
RecordingQuery
extends
ImmediatelyDoneQuery
{
constructor
(
private
readonly
:
Array
<
<
[
'applyFlagSettings'
]
>
[
0
]
>
,
private
readonly
:
,
)
{
super
(
)
;
}
next
(
)
:
Promise
<
<
never
,
void
>>
{
if
(
this
.
.
)
{
return
Promise
.
resolve
(
{
:
true
,
:
undefined
}
)
;
}
return
new
Promise<IteratorResult<never,void>>
(
=>
{
this
.
.
addEventListener
(
'abort'
,
(
)
=>
resolve
(
{
:
true
,
:
undefined
}
)
,
{
:
true
}
)
;
}
)
;
}
async
applyFlagSettings
(
:
<
[
'applyFlagSettings'
]
>
[
0
]
)
:
Promise
<
void
>
{
this
.
.
push
(
)
;
}
}
class
RecordingWarmQuery
extends
FakeWarmQuery
{
readonly
:
Array
<
<
[
'applyFlagSettings'
]
>
[
0
]
>
=
[
]
;
constructor
(
private
readonly
:
)
{
super
(
)
;
}
query
(
:
string
|
<
>
)
:
{
this
.
++
;
return
new
RecordingQuery
(
this
.
,
this
.
)
;
}
}
/** A {@link Query}-shaped stub whose async stream the test ends on demand. */
type
IControllableQuery
=
&
{
/** Ends the stream (models a dispose-driven close of the underlying query). */
end
(
)
:
void
;
/** How many times the consumer loop has pulled from this query's iterator. */
readonly
:
number
;
}
;
/**
* Builds a {@link Query} whose async iterator blocks (modelling a live turn)
* until {@link IControllableQuery.end}, and records how many times the consumer
* loop pulled from it. Lets a test hold the consumer loop on one query while a
* rebind swaps in the next, then observe whether the new query gets drained.
*/
function
makeControllableQuery
(
)
:
{
let
=
false
;
let
:
(
(
)
=>
void
)
|
undefined
;
const
=
.
assign
(
new
ImmediatelyDoneQuery
(
)
,
{
:
0
,
end
(
)
:
void
{
=
true
;
?.
(
)
;
=
undefined
;
}
,
[
.
]
(
)
{
return
this
;
}
,
async
next
(
this
:
{
:
number
}
)
:
Promise
<
<
,
void
>>
{
this
.
++
;
while
(
!
)
{
await
new
Promise<void>
(
=>
{
=
;
}
)
;
}
return
{
:
true
,
:
undefined
}
;
}
,
async
return
(
)
{
return
{
:
true
,
:
undefined
}
;
}
,
async
throw
(
:
unknown
)
{
throw
;
}
,
}
)
;
return
as
unknown
as
;
}
/** {@link WarmQuery} that hands out {@link makeControllableQuery} instances and records them. */
class
ControllableWarmQuery
extends
FakeWarmQuery
{
readonly
:
[
]
=
[
]
;
query
(
:
string
|
<
>
)
:
{
this
.
++
;
const
=
makeControllableQuery
(
)
;
this
.
.
push
(
)
;
return
;
}
}
// ===== Harness =====
interface
IPipelineHarness
{
readonly
:
;
readonly
:
;
readonly
:
;
}
function
createPipeline
(
:
<
,
'add'
>
,
:
|
(
(
:
)
=>
)
=
new
FakeWarmQuery
(
)
,
)
:
{
const
=
new
AbortController
(
)
;
const
=
typeof
===
'function'
?
warmOrFactory
(
.
)
:
;
const
=
.
add
(
new
FileService
(
new
NullLogService
(
)
)
)
;
const
=
.
add
(
new
InMemoryFileSystemProvider
(
)
)
;
.
add
(
.
registerProvider
(
'file'
,
)
)
;
const
=
new
TestSessionDatabase
(
)
;
const
:
<
>
=
{
:
,
dispose
:
(
)
=>
{
}
}
;
const
=
new
ServiceCollection
(
[
,
new
NullLogService
(
)
]
,
[
,
]
,
[
,
createZeroDiffComputeService
(
)
]
,
)
;
const
:
=
.
add
(
new
InstantiationService
(
)
)
;
const
=
.
add
(
new
SubagentRegistry
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
'sess-1'
,
URI
.
parse
(
buildDefaultChatUri
(
'claude:/sess-1'
)
)
,
URI
.
parse
(
'claude:/sess-1'
)
,
,
,
,
,
undefined
,
)
)
;
return
{
,
,
}
;
}
function
makePrompt
(
:
string
,
:
string
=
)
:
{
return
{
:
'user'
,
:
makeUuid
(
)
,
:
null
,
:
{
:
'user'
,
:
}
,
}
;
}
/** Build a SDK-shaped UUID from a short label so test ids stay readable. */
/**
* Let the pipeline's fire-and-forget `send()` run far enough to bind the
* Query and finish its synchronous `_replayCurrentConfig` (a no-op when the
* seeded config already matches). A few microtask turns is enough; the stub
* Query never awaits real I/O.
*/
async
function
flushMicrotasks
(
)
:
Promise
<
void
>
{
for
(
let
=
0
;
<
5
;
++
)
{
await
Promise
.
resolve
(
)
;
}
}
suite
(
'ClaudeSdkPipeline'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
suite
(
'reloadPlugins'
,
(
)
=>
{
test
(
'forwards to the SDK Query'
,
async
(
)
=>
{
let
=
0
;
class
WarmWithReload
extends
FakeWarmQuery
{
query
(
:
string
|
<
>
)
:
{
this
.
++
;
const
=
new
ImmediatelyDoneQuery
(
)
;
(
as
unknown
as
{
reloadPlugins
:
(
)
=>
Promise
<
{
:
{
:
string
}
[
]
}
>
}
)
.
reloadPlugins
=
async
(
)
=>
{
++
;
return
{
:
[
]
}
;
}
;
return
;
}
}
const
=
new
AbortController
(
)
;
const
=
new
WarmWithReload
(
)
;
const
=
.
add
(
new
FileService
(
new
NullLogService
(
)
)
)
;
const
=
.
add
(
new
InMemoryFileSystemProvider
(
)
)
;
.
add
(
.
registerProvider
(
'file'
,
)
)
;
const
=
new
TestSessionDatabase
(
)
;
const
:
<
>
=
{
:
,
dispose
:
(
)
=>
{
}
}
;
const
=
new
ServiceCollection
(
[
,
new
NullLogService
(
)
]
,
[
,
]
,
[
,
createZeroDiffComputeService
(
)
]
,
)
;
const
:
=
.
add
(
new
InstantiationService
(
)
)
;
const
=
.
add
(
new
SubagentRegistry
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
'sess-2'
,
URI
.
parse
(
buildDefaultChatUri
(
'claude:/sess-2'
)
)
,
URI
.
parse
(
'claude:/sess-2'
)
,
,
,
,
,
undefined
,
)
)
;
// Bind the query by issuing a send (iterator closes immediately).
.
send
(
makePrompt
(
'p1'
)
,
'turn-A'
)
.
catch
(
(
)
=>
{
/* expected */
}
)
;
await
Promise
.
resolve
(
)
;
await
.
reloadPlugins
(
)
;
.
strictEqual
(
,
1
)
;
}
)
;
}
)
;
suite
(
'initial state'
,
(
)
=>
{
test
(
'isResumed starts false and isAborted starts false'
,
(
)
=>
{
const
{
}
=
createPipeline
(
)
;
.
strictEqual
(
.
,
false
)
;
.
strictEqual
(
.
,
false
)
;
}
)
;
}
)
;
suite
(
'abort'
,
(
)
=>
{
test
(
'flips the controller signal and isAborted'
,
(
)
=>
{
const
{
,
}
=
createPipeline
(
)
;
.
abort
(
)
;
.
strictEqual
(
.
.
,
true
)
;
.
strictEqual
(
.
,
true
)
;
}
)
;
test
(
'is idempotent'
,
(
)
=>
{
const
{
,
}
=
createPipeline
(
)
;
.
abort
(
)
;
.
abort
(
)
;
.
strictEqual
(
.
.
,
true
)
;
}
)
;
test
(
'send after abort with no rematerializer attached throws a clear error (not a silent hang)'
,
async
(
)
=>
{
const
{
}
=
createPipeline
(
)
;
.
abort
(
)
;
await
.
send
(
makePrompt
(
'p1'
)
,
'turn-A'
)
.
then
(
(
)
=>
.
fail
(
'expected rejection'
)
,
=>
{
// _rebindQuery throws synchronously when no rematerializer is attached
.
match
(
String
(
)
,
/no rematerializer attached/
)
;
}
,
)
;
}
)
;
}
)
;
suite
(
'rematerializer wiring'
,
(
)
=>
{
test
(
'after abort, send invokes the attached rematerializer in "recover" mode and clears the rebind flag'
,
async
(
)
=>
{
const
{
}
=
createPipeline
(
)
;
const
:
Array
<
'restart'
|
'recover'
>
=
[
]
;
const
:
{
:
;
:
}
[
]
=
[
]
;
const
:
IRematerializer
=
async
(
)
=>
{
.
push
(
)
;
const
=
new
AbortController
(
)
;
const
=
new
FakeWarmQuery
(
)
;
.
push
(
{
,
:
}
)
;
return
{
,
:
}
;
}
;
.
attachRematerializer
(
)
;
.
abort
(
)
;
// Don't await — the consumer loop on the rebound query will end
// almost immediately, but the matching SDK `result` never
// arrives (FakeWarmQuery's iterator just closes), so the
// deferred ends up failed with the "stream ended without
// result" guard. We only care that the rematerializer ran.
.
send
(
makePrompt
(
'p1'
)
,
'turn-A'
)
.
catch
(
(
)
=>
{
/* expected */
}
)
;
// Yield a microtask for the async rebind to call the callback.
await
Promise
.
resolve
(
)
;
await
Promise
.
resolve
(
)
;
.
deepStrictEqual
(
,
[
'recover'
]
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
.
,
false
,
'rebind installed a fresh, non-aborted controller'
)
;
}
)
;
test
(
'rematerializer rejection propagates from send'
,
async
(
)
=>
{
const
{
}
=
createPipeline
(
)
;
const
=
new
Error
(
'rematerialize failed'
)
;
let
=
0
;
.
attachRematerializer
(
async
(
)
=>
{
++
;
throw
;
}
)
;
.
abort
(
)
;
await
.
send
(
makePrompt
(
'p1'
)
,
'turn-A'
)
.
then
(
(
)
=>
.
fail
(
'expected rejection'
)
,
=>
.
strictEqual
(
,
)
,
)
;
.
strictEqual
(
,
1
)
;
}
)
;
test
(
'abort issued while the rematerializer is still resolving cancels the freshly-built controller (rebind-window race)'