Это 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 assert from'assert';import{ ensureNoDisposablesAreLeakedInTestSuite }from'../../../../../base/test/common/utils.js';import{
compute4GramTextSimilarity,
computeChunkedEditSurvival,
computeChunkedFourGramSurvival,
computeFractionPresentIn,
computeWholeFileEditSurvival,}from'../../../node/shared/editSurvivalTracker.js';suite('agentHost editSurvivalTracker',()=>{ensureNoDisposablesAreLeakedInTestSuite();suite('compute4GramTextSimilarity',()=>{test('identical strings → 1',
assert
score
assertscore
assert
assert
a
b
score a b
assertscore
before
after
scores before after after
assertscoresfourGram
assertscoresnoRevert
before
after
scores before after before
assertscoresfourGram
assertscoresnoRevert
before
after
current
scores before after current
assertscoresfourGram scoresfourGram
assertscoresnoRevert
text
scores text text text
assertscoresfourGram
assertscoresnoRevert
chunk
file chunk
assertchunk file
chunk
file
assertchunk file
chunk
file
score chunk file
assertscore score
assert
assert
assert
chunk
small chunk
big chunk
assertchunk small
assertchunk big
assert
longChunk
shortChunk
file longChunk
score longChunk shortChunk file
assertscore
a
b
file
asserta b file
file
chunks length _ i
start Date
score chunks file
elapsedMs Date start
assertscore score
assertelapsedMs
before
after
expected before after after
actual before after after
assertactual expected
before
chunk
after before chunk
current after
scores before after chunk current
assertscoresfourGram
assertscoresnoRevert
id
before
after
aiChunks
n
Mathn
edits ReadonlyArrayIEdit Map ReadonlyArray
result
i i editslength i
edit editsi
samples
stream editafter editsi e eafter
currentText stream
fourGram noRevert editaiChunks
editbefore editafter editaiChunks currentText
editbefore editafter currentText
samples
resulteditid samples
result
base
afterE1 base
afterE2 afterE1
samples
id before base after afterE1
id before afterE1 after afterE2
assertObjectsamples
e1
e2
base
e1Chunk
e2Chunk
afterE1 base e1Chunk
afterE2 e2Chunk afterE1
samples
id before base after afterE1 aiChunks e1Chunk
id before afterE1 after afterE2 aiChunks e2Chunk
assertObjectsamples
e1
e2
original
appended
afterWrite original
afterEdit original appended
samples
id before after afterWrite aiChunks original
id before afterWrite after afterEdit aiChunks appended
assertObjectsamples
write
edit
base
chunkA
chunkB
chunkC
chunkD
afterMulti base chunkA chunkB chunkC
afterEdit afterMulti chunkD
samples
id before base after afterMulti aiChunks chunkA chunkB chunkC
id before afterMulti after afterEdit aiChunks chunkD
assertObjectsamples
multi
edit
base
afterE1 base
afterE2 base
samples
id before base after afterE1
id before afterE1 after afterE2
assertObjectsamples
e1
e2
base
afterE1
afterE2 afterE1
afterE3
samples
id before base after afterE1
id before afterE1 after afterE2
id before afterE2 after afterE3
assertObjectsamples
original
shrunken
samples
id before original after shrunken
id before shrunken after original
assertObjectsamples
base
afterAI
afterUser
samples
id before base after afterAI
id before afterAI after afterUser
aiSamples samples
assertaiSamples
fg nr aiSamplesNumber
assertfg fg
assertnr
before
after
samples
id before after
id before after after before
aiSamples samples
assertaiSamples
fg nr aiSamplesNumber
assertfg
assertnr
// Refinement diverges from AI text but stays equally far from
// the original — should not be counted as a revert.
.
strictEqual
(
.
,
1
)
;
}
)
;
test
(
'AI produced same text as before → noRevert defaults to 1'
,
(
)
=>
{
const
=
'unchanged\n'
;
const
=
computeWholeFileEditSurvival
(
,
,
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
.
,
1
)
;
}
)
;
}
)
;
suite
(
'computeFractionPresentIn'
,
(
)
=>
{
test
(
'chunk fully present in current → 1'
,
(
)
=>
{
const
=
'export function greet() { return "hello"; }\n'
;
const
=
'// header\n'
+
+
'// footer\n'
;
.
strictEqual
(
computeFractionPresentIn
(
,
)
,
1
)
;
}
)
;
test
(
'chunk fully absent from current → 0'
,
(
)
=>
{
const
=
'xxxxxxxxxxxxxxxxxxxxxxxxxxxx\n'
;
const
=
'completely unrelated content here\n'
;
.
strictEqual
(
computeFractionPresentIn
(
,
)
,
0
)
;
}
)
;
test
(
'partial overlap → fraction between 0 and 1'
,
(
)
=>
{
const
=
'function add(a, b) { return a + b; }\n'
;
const
=
'function add(a, b) { return a - b; }\n'
;
const
=
computeFractionPresentIn
(
,
)
;
.
ok
(
>
0.5
&&
<
1
,
`expected fraction in (0.5, 1), got ${score}`
)
;
}
)
;
test
(
'empty chunk → 1'
,
(
)
=>
{
.
strictEqual
(
computeFractionPresentIn
(
''
,
'anything'
)
,
1
)
;
}
)
;
test
(
'chunk shorter than 4 chars falls back to substring match'
,
(
)
=>
{
.
strictEqual
(
computeFractionPresentIn
(
'ab'
,
'cabd'
)
,
1
)
;
.
strictEqual
(
computeFractionPresentIn
(
'ab'
,
'cxd'
)
,
0
)
;
}
)
;
test
(
'immune to file growth: score stays at 1 when content is appended'
,
(
)
=>
{
const
=
'export function greet() { return "hello"; }\n'
;
const
=
;
const
=
+
'x'
.
repeat
(
10_000
)
;
.
strictEqual
(
computeFractionPresentIn
(
,
)
,
1
)
;
.
strictEqual
(
computeFractionPresentIn
(
,
)
,
1
)
;
}
)
;
}
)
;
suite
(
'computeChunkedFourGramSurvival'
,
(
)
=>
{
test
(
'empty chunks → 0 (caller should branch and fall back)'
,
(
)
=>
{
.
strictEqual
(
computeChunkedFourGramSurvival
(
[
]
,
'file'
)
,
0
)
;
}
)
;
test
(
'multiple chunks weighted by length'
,
(
)
=>
{
// A long chunk fully present, a short chunk fully absent.
// The long chunk should dominate, dragging the average up.
const
=
'a'
.
repeat
(
200
)
;
const
=
'xyz9'
;
// 4-gram absent from file
const
=
;
const
=
computeChunkedFourGramSurvival
(
[
,
]
,
)
;
// long ≈ 200 ngrams * 1.0 + short ≈ 1 ngram * 0.0,
// weighted: 200 / 201 ≈ 0.995
.
ok
(
>
0.99
,
`expected near 1, got ${score}`
)
;
}
)
;
test
(
'all chunks fully present → 1'
,
(
)
=>
{
const
=
'export const x = 1;\n'
;
const
=
'export const y = 2;\n'
;
const
=
`// header\n${a}// mid\n${b}// footer\n`
;
.
strictEqual
(
computeChunkedFourGramSurvival
(
[
,
]
,
)
,
1
)
;
}
)
;
test
(
'scales linearly with chunks: file n-gram set is built once'
,
(
)
=>
{
// Regression guard: a previous implementation rebuilt the
// file n-gram set inside the per-chunk loop, making cost
// O(|chunks| × |file|). With the set built once, scoring
// 50 chunks against a 500 KB file should finish well
// under a second on any developer machine.
const
=
'x'
.
repeat
(
500_000
)
;
const
=
Array
.
from
(
{
:
50
}
,
(
,
)
=>
`chunk${i}-${'x'.repeat(40)}`
)
;
const
=
.
now
(
)
;
const
=
computeChunkedFourGramSurvival
(
,
)
;
const
=
.
now
(
)
-
;
.
ok
(
>=
0
&&
<=
1
,
`score out of range: ${score}`
)
;
.
ok
(
<
1000
,
`expected < 1000ms, took ${elapsedMs}ms`
)
;
}
)
;
}
)
;
suite
(
'computeChunkedEditSurvival'
,
(
)
=>
{
test
(
'falls back to whole-file scoring when chunks are empty'
,
(
)
=>
{
const
=
'aaaaaaaaaaaaaaaaaaaa\n'
;
const
=
'bbbbbbbbbbbbbbbbbbbb\n'
;
const
=
computeWholeFileEditSurvival
(
,
,
)
;
const
=
computeChunkedEditSurvival
(
,
,
[
]
,
)
;
.
deepStrictEqual
(
,
)
;
}
)
;
test
(
'fourGram from chunks, noRevert still from whole-file'
,
(
)
=>
{
// File grows around the chunk — chunked fourGram stays at 1
// while noRevert stays at 1 because the file did not move
// back toward `before`.
const
=
'// empty\n'
;
const
=
'export function greet() { return "hello"; }\n'
;
const
=
+
;
const
=
+
'\n// later append\n'
;
const
=
computeChunkedEditSurvival
(
,
,
[
]
,
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
.
,
1
)
;
}
)
;
}
)
;
suite
(
'multi-tracker scenarios'
,
(
)
=>
{
// Each scenario simulates several reporters running concurrently
// against the same file, the way the agent host launches one
// per `takeCompletedEdit`. We snapshot the scores each reporter
// would compute at every subsequent file state — i.e. what
// telemetry would show across the 7 timer ticks if those ticks
// landed at the corresponding file states.
//
// Each table cell is `fourGram/noRevert`, both rounded to 2dp.
interface
IEdit
{
readonly
:
string
;
/** File content right before this edit landed. */
readonly
:
string
;
/** File content right after this edit landed. */
readonly
:
string
;
/**
* Optional explicit AI-written text chunks for this edit
* (the way the Claude observer extracts them from
* `Edit.new_string`, `MultiEdit.edits[*].new_string`, or
* `Write.content`). When provided, the simulation uses the
* chunked scoring path so the snapshot mirrors what the
* reporter would actually emit.
*/
readonly
?
:
readonly
string
[
]
;
}
function
round
(
:
number
)
:
number
{
return
.
round
(
*
100
)
/
100
;
}
/**
* For each edit, sample its survival scores against every later
* file state (the state when that edit completed, then each
* state produced by subsequent edits). Returns a `Map<editId, scores[]>`
* where `scores[i]` is the score the reporter for `editId` would
* emit if a timer tick landed on file state `i` (counting from
* when that edit completed).
*/
function
simulate
(
:
<
>
)
:
<
string
,
<
string
>>
{
const
=
new
Map<string,string[]>
(
)
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
;
const
:
string
[
]
=
[
]
;
// The reporter samples at t=0 (its own `after`) and then
// at each later edit's `after`.
const
=
[
.
,
...
.
slice
(
+
1
)
.
map
(
=>
.
)
]
;
for
(
const
of
)
{
const
{
,
}
=
.
?
computeChunkedEditSurvival
(
.
,
.
,
.
,
)
:
computeWholeFileEditSurvival
(
.
,
.
,
)
;
.
push
(
`${round(fourGram)}/${round(noRevert)}`
)
;
}
.
set
(
.
,
)
;
}
return
;
}
test
(
'two non-overlapping additions both survive (whole-file scoring)'
,
(
)
=>
{
// Agent adds a line at the bottom, then adds another at the
// top. Neither edit disturbs the other's content.
const
=
'alpha\nbravo\ncharlie\n'
;
const
=
+
'delta added by e1\n'
;
const
=
'echo added by e2\n'
+
;
const
=
simulate
(
[
{
:
'e1'
,
:
,
:
}
,
{
:
'e2'
,
:
,
:
}
,
]
)
;
.
deepStrictEqual
(
.
fromEntries
(
)
,
{
// e1: t=0 perfect. After e2 lands, e1's added line is
// still present (noRevert=1) but the file has *more*
// text than e1 wrote, so the fourGram ratio falls.
// This is the whole-file scoring artifact — chunked
// scoring fixes it (see the chunked test below).
:
[
'1/1'
,
'0.8/1'
]
,
:
[
'1/1'
]
,
}
)
;
}
)
;
test
(
'two non-overlapping additions both survive (chunked scoring)'
,
(
)
=>
{
// Same scenario as above, but each edit now carries its
// AI-written chunk (mirroring what `Edit.new_string` /
// `Write.content` extraction passes through to the reporter).
// The chunked path scores each edit against its own
// AI-written text, so file growth elsewhere does not drag
// the score down.
const
=
'alpha\nbravo\ncharlie\n'
;
const
=
'delta added by e1\n'
;
const
=
'echo added by e2\n'
;
const
=
+
;
const
=
+
;
const
=
simulate
(
[
{
:
'e1'
,
:
,
:
,
:
[
]
}
,
{
:
'e2'
,
:
,
:
,
:
[
]
}
,
]
)
;
.
deepStrictEqual
(
.
fromEntries
(
)
,
{
// e1's chunk is still entirely present after e2 lands
// (it's just deeper in the file) → fourGram stays at 1.
:
[
'1/1'
,
'1/1'
]
,
:
[
'1/1'
]
,
}
)
;
}
)
;
test
(
'write then edit that appends — write stays at 1 under chunked scoring'
,
(
)
=>
{
// The motivating case: agent writes a file at T1, then a
// later Edit appends new content. Whole-file scoring would
// drag the Write's fourGram down because the file is now
// bigger than what the Write produced; chunked scoring
// keeps the Write at 1 because its content is still fully
// present.
const
=
'export function a() { return 1; }\n'
;
const
=
'export function b() { return 2; }\n'
;
const
=
;
const
=
+
;
const
=
simulate
(
[
{
:
'write'
,
:
''
,
:
,
:
[
]
}
,
{
:
'edit'
,
:
,
:
,
:
[
]
}
,
]
)
;
.
deepStrictEqual
(
.
fromEntries
(
)
,
{
:
[
'1/1'
,
'1/1'
]
,
:
[
'1/1'
]
,
}
)
;
}
)
;
test
(
'MultiEdit with several chunks survives a later unrelated append'
,
(
)
=>
{
// MultiEdit lands three new functions. A subsequent Edit
// appends a fourth function. Each MultiEdit chunk is still
// fully present, so the length-weighted average stays at 1.
const
=
'// existing module\n'
;
const
=
'export function alpha() { return 1; }\n'
;
const
=
'export function bravo() { return 2; }\n'
;
const
=
'export function charlie() { return 3; }\n'
;
const
=
'export function delta() { return 4; }\n'
;
const
=
+
+
+
;
const
=
+
;
const
=
simulate
(
[
{
:
'multi'
,
:
,
:
,
:
[
,
,
]
}
,
{
:
'edit'
,
:
,
:
,
:
[
]
}
,
]
)
;
.
deepStrictEqual
(
.
fromEntries
(
)
,
{
:
[
'1/1'
,
'1/1'
]
,
:
[
'1/1'
]
,
}
)
;
}
)
;
test
(
'add a line, then modify the same line — fourGram drops, noRevert stays high'
,
(
)
=>
{
const
=
'alpha\nbravo\ncharlie\n'
;
const
=
+
'delta the original\n'
;
const
=
+
'delta after edit two changed it\n'
;
const
=
simulate
(
[
{
:
'e1'
,
:
,
:
}
,
{
:
'e2'
,
:
,
:
}
,
]
)
;
.
deepStrictEqual
(
.
fromEntries
(
)
,
{
// e1: at t=0 perfect; once e2 lands the modified line
// is no longer e1's text → fourGram drops. noRevert
// holds at 1 because the file did not move back toward
// `base`, it moved further away.
:
[
'1/1'
,
'0.54/1'
]
,
:
[
'1/1'
]
,
}
)
;
}
)
;
test
(
'change a line, add a line, delete a line — mixed survival'
,
(
)
=>
{
// Three disjoint edits in different regions. The final file
// reflects all three; everyone should look healthy.