web-agent-presets.e2e.ts 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. import { randomUUID } from 'node:crypto'
  2. import { mkdir, mkdtemp, readFile, stat, symlink, writeFile } from 'node:fs/promises'
  3. import { tmpdir } from 'node:os'
  4. import { fileURLToPath } from 'node:url'
  5. import { dirname, join } from 'node:path'
  6. import { Context } from '@deepseek-ai/cordis'
  7. import { boot, healProfilesModuleFallback, loadOverlayPatches, loadProfile } from '@deepseek-ai/dsh-app-boot'
  8. import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
  9. import { SessionId } from '@deepseek-ai/dsh-session'
  10. import type { Agent } from '@deepseek-ai/dsh-agent'
  11. import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
  12. import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
  13. import { settingsNamespace } from '@deepseek-ai/dsh-settings'
  14. import { resolveSessionPreset, SETTINGS_NAMESPACE, SHIPPED_PRESET_ROOT } from '@deepseek-ai/dsh-agent-presets'
  15. import { applyChildComposition, childSessionMeta } from '@deepseek-ai/dsh-subagent'
  16. import { CallId } from '@deepseek-ai/dsh-llm'
  17. import type {} from '@deepseek-ai/dsh-compaction-basic'
  18. import type {} from '@deepseek-ai/dsh-skill'
  19. import type {} from '@deepseek-ai/dsh-tools'
  20. // Type-only: resolves `ctx.get('sessionProjections')` and `ctx.get('tokenMeter')`.
  21. import type {} from '@deepseek-ai/dsh-session-projection'
  22. import type {} from '@deepseek-ai/dsh-token-meter'
  23. const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url))
  24. /** The shipped Web surface: the dsh-base and dsh-web-app bundle patches over an empty preset root. */
  25. const BASE_PATCH = join(REPO_ROOT, 'packages/bundle/base/cordis.patch.yml')
  26. const WEB_PATCH = join(REPO_ROOT, 'packages/bundle/web-app/cordis.patch.yml')
  27. const CODEX_PACKAGE_DIR = join(REPO_ROOT, 'packages/subagent/subagent-codex')
  28. const CLAUDE_CODE_PACKAGE_DIR = join(REPO_ROOT, 'packages/subagent/subagent-claude-code')
  29. /** The installation anchor whose dependency surface the preset module fallback mirrors. */
  30. const INSTALL_ANCHOR = join(REPO_ROOT, 'apps/cli/package.json')
  31. const MINIMAL_PROMPT = 'You are a helpful software engineer assistant.'
  32. const MINIMAL_BASH_DESCRIPTION = `Run commands in a bash shell
  33. * When invoking this tool, the contents of the "command" parameter does NOT need to be XML-escaped.
  34. * You don't have access to the internet via this tool.
  35. * You do have access to a mirror of common linux and python packages via apt and pip.
  36. * State is persistent across command calls and discussions with the user.
  37. * To inspect a particular line range of a file, e.g. lines 10-25, try 'sed -n 10,25p /path/to/the/file'.
  38. * Please avoid commands that may produce a very large amount of output.
  39. * Please run long lived commands in the background, e.g. 'sleep 10 &' or start a server in the background.`
  40. /**
  41. * Boot the shipped Web composition, minus the rows that would bind a port,
  42. * touch the network, or write outside the test. Everything that decides an
  43. * agent's capabilities is the real thing, including both shipped presets.
  44. */
  45. async function bootWeb(
  46. settingsFile: string,
  47. extra: PatchOptions[] = [],
  48. profilePackages: readonly string[] = [],
  49. profileBundles?: readonly string[],
  50. ): Promise<Context> {
  51. const storageRoot = join(dirname(settingsFile), 'storages')
  52. const overrides: PatchOptions[] = [
  53. // The settings row defaults to `$DSH_HOME/settings.yaml`. Left alone it
  54. // reads the developer's own document — and since the default preset is a
  55. // setting, a stored `agent-presets.default` would decide this file's
  56. // outcome. Point it at a temp file for the same reason the roster row
  57. // below pins `includeUserRoot` off.
  58. { id: 'settings', config: { path: settingsFile, watch: false } },
  59. // storage-json's root is anchored to the real $DSH_HOME. Unpinned, this
  60. // file writes the developer's own `~/.dsh/storages/` — and then reads it
  61. // back on the next run, so a stored document from any other build decides
  62. // this test's boot. Same reason the settings row above is pinned.
  63. { id: 'storage-json', config: { root: storageRoot } },
  64. // Host rows with side effects outside this process: a bound port, a served
  65. // asset tree, a telemetry exporter. `api-gateway` and `directory-picker`
  66. // stay ENABLED on purpose — the api-proxy is the host row that injects
  67. // `subagents`, `workspace`, and the rest of the agent plane, so disabling
  68. // it would hide exactly the breakage this file exists to catch: a service
  69. // moved into the presets that a host row still waits for. The boot audit
  70. // is that assertion.
  71. { id: 'webserver', disabled: true },
  72. // The web bundle's runtime row injects `webServer`, so it cannot
  73. // activate without the bound port disabled above. It owns dist serving
  74. // and the URL prompt line — surface glue, not anything that decides an
  75. // agent's capabilities, which is all this file asserts.
  76. { id: 'web-runtime', disabled: true },
  77. { id: 'session-telemetry-otel', disabled: true },
  78. // A deployment-level skill on the host registry's GLOBAL layer — the same
  79. // registration shape a repository plugin's skill root uses. The layered
  80. // skills test below proves it reaches preset-composed agents.
  81. { id: 'skill-badge', disabled: false },
  82. { id: 'modules', disabled: true },
  83. { id: 'connection', disabled: true },
  84. // The always-on reload chain waits for the browser roster and bound port
  85. // disabled above.
  86. { id: 'client-hmr', disabled: true },
  87. // The shipped `-auto` chooser resolves its interaction from a running
  88. // host and so waits for the webserver disabled above; the browse variant
  89. // supplies `directoryPicker` without one.
  90. { id: 'directory-picker', disabled: true },
  91. { insert: [
  92. { id: 'directory-picker-browse', name: '@deepseek-ai/dsh-host-directory-picker-browse' },
  93. { id: 'ui-directory-picker-browse', name: '@deepseek-ai/dsh-client-ui-directory-picker-browse' },
  94. ] },
  95. // Pin the roster away from the developer's machine: `includeUserRoot`
  96. // false keeps `~/.dsh/.agent-presets` from changing a test's outcome.
  97. // `default` here is the COMPOSITION default — the base layer the settings
  98. // document overrides. No `roots` entry: the plugin bundles the shipped
  99. // presets itself and prepends their root.
  100. { id: 'agent-presets', config: { default: 'standard', includeUserRoot: false } },
  101. ...extra,
  102. ]
  103. // The surface is patch layers over an empty preset root, so the root sits
  104. // outside this workspace and bare plugin names cannot resolve by Node's
  105. // upward walk. The flat fallback the preset boot maintains is what makes
  106. // them resolvable — the same mechanism, not a test-only shim.
  107. const home = dirname(settingsFile)
  108. healProfilesModuleFallback(INSTALL_ANCHOR, home)
  109. const profileDir = join(home, 'profiles', 'spec')
  110. await mkdir(profileDir, { recursive: true })
  111. // Product Bundles are installed into the Profile, not the dsh app. Model
  112. // pnpm's package link for only the selected products; their own production
  113. // dependencies resolve from the linked workspace packages, while shared
  114. // peers still resolve through the installation fallback above.
  115. for (const packageDir of profilePackages) {
  116. const manifest = JSON.parse(await readFile(join(packageDir, 'package.json'), 'utf8')) as { name: string }
  117. const link = join(profileDir, 'node_modules', manifest.name)
  118. await mkdir(dirname(link), { recursive: true })
  119. await symlink(packageDir, link, 'junction')
  120. }
  121. let bundlePatches: PatchOptions[] = [
  122. ...loadOverlayPatches('dsh-test', BASE_PATCH),
  123. ...loadOverlayPatches('dsh-test', WEB_PATCH),
  124. ]
  125. if (profileBundles !== undefined) {
  126. await writeFile(join(profileDir, 'package.json'), JSON.stringify({
  127. private: true,
  128. dependencies: Object.fromEntries(profileBundles.map(name => [name, 'workspace:*'])),
  129. dsh: { profile: { bundles: profileBundles } },
  130. }, null, 2) + '\n')
  131. const profile = loadProfile('dsh-test', 'spec', INSTALL_ANCHOR, home, { userLayer: false })
  132. bundlePatches = profile.layers.flatMap(layer => layer.patches)
  133. }
  134. const rootConfig = join(profileDir, 'cordis.yml')
  135. await writeFile(rootConfig, '[]\n')
  136. return await boot('dsh-test', rootConfig, [...bundlePatches, ...overrides], (bootCtx) => {
  137. provideCmdline(bootCtx, { args: [], exit: () => {} })
  138. })
  139. }
  140. const toolNames = (ctx: Context, agent?: Agent): string[] =>
  141. ctx.tools.schemas(agent).map(schema => schema.name).sort()
  142. function toolParameterNames(ctx: Context, agent: Agent, toolName: string): string[] {
  143. const schema = ctx.tools.schemas(agent).find(tool => tool.name === toolName)
  144. if (schema === undefined) throw new Error(`missing tool schema ${toolName}`)
  145. const properties = schema.parameters.properties
  146. if (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {
  147. throw new Error(`${toolName} has invalid parameter properties`)
  148. }
  149. return Object.keys(properties).sort()
  150. }
  151. function enablePresetTool(composition: string, id: string): string {
  152. const row = ` - id: ${id}\n`
  153. const start = composition.indexOf(row)
  154. if (start < 0) throw new Error(`missing preset row ${id}`)
  155. const end = composition.indexOf('\n - id:', start + row.length)
  156. const disabled = composition.indexOf(' disabled: true\n', start)
  157. if (disabled < 0 || (end >= 0 && disabled > end)) {
  158. throw new Error(`preset row ${id} is not disabled`)
  159. }
  160. return composition.slice(0, disabled) + composition.slice(disabled + ' disabled: true\n'.length)
  161. }
  162. let ctx: Context
  163. beforeAll(async () => {
  164. const settingsFile = join(await mkdtemp(join(tmpdir(), 'dsh-web-presets-')), 'settings.yaml')
  165. await writeFile(settingsFile, '{}\n')
  166. ctx = await bootWeb(settingsFile)
  167. }, 120_000)
  168. describe('the shipped Web composition', () => {
  169. it('leaves the global tool layer empty', () => {
  170. // Every model-facing tool belongs to a preset, `ask_user_question`
  171. // included: a tool in the global layer reaches EVERY agent regardless of
  172. // which preset composed it, so a two-tool benchmark surface would really
  173. // present three. A regression here means an agent-plane row came back to
  174. // the host composition.
  175. expect(toolNames(ctx)).toEqual([])
  176. })
  177. it('keeps the token meter and its context-meter projections on the host plane', async () => {
  178. // Read before any preset in this file mounts, which is what makes this an
  179. // ownership assertion rather than a mount-order coincidence: a preset-side
  180. // meter sits behind an `isolate` realm and is invisible to `ctx.get`.
  181. //
  182. // The projection registry is process-wide rather than scope-layered, so a
  183. // preset-side meter would also make the browser's context meter appear for
  184. // a `minimal` session the moment some OTHER session mounted a preset that
  185. // carries one, and vanish entirely in a process that only ever ran
  186. // `minimal`. Host ownership is what makes the meter a per-session fact.
  187. expect(ctx.get('tokenMeter')).toBeDefined()
  188. const projections = ctx.get('sessionProjections')
  189. if (projections === undefined) throw new Error('the Web composition must compose a projection registry')
  190. const handle = await ctx.agents.create({
  191. sessionId: SessionId('preset-minimal-meter'),
  192. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  193. })
  194. try {
  195. // A subset assertion: `tasks`, `goal`, and the rest register into the
  196. // same process-wide table, and this is about the meter's three units.
  197. expect(Object.keys(projections.snapshot(handle.agent.session).values))
  198. .toEqual(expect.arrayContaining(['contextBreakdown', 'contextPressure', 'tokenUsage']))
  199. } finally {
  200. await handle.dispose()
  201. }
  202. })
  203. it('supplies both shipped presets, and only those, from the system root', async () => {
  204. const listed = await ctx.agentPresets.list()
  205. expect(listed.map(preset => preset.id).sort()).toEqual(['code', 'cordis', 'minimal', 'standard'])
  206. expect(listed.every(preset => preset.trust === 'system')).toBe(true)
  207. expect(ctx.agentPresets.defaultId).toBe('standard')
  208. })
  209. it('composes the full agent from `standard`', async () => {
  210. const handle = await ctx.agents.create({
  211. sessionId: SessionId('preset-standard'),
  212. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  213. })
  214. try {
  215. // The EXACT catalog, not a spot-check: an omission is this design's
  216. // quietest failure mode, because a row that registers into the wrong
  217. // layer mounts cleanly and simply contributes nothing. `glob`/`grep` are
  218. // excluded for the reason the TUI composition e2e excludes them — they
  219. // depend on ripgrep being present on the machine.
  220. expect(toolNames(ctx, handle.agent).filter(name => name !== 'glob' && name !== 'grep')).toEqual([
  221. 'ask_user_question', 'bash', 'create_goal', 'edit', 'exit_plan_mode',
  222. 'get_goal', 'interrupt_agent', 'job_kill', 'job_list', 'job_output', 'list_agents', 'ralph', 'read', 'read_image', 'send_message', 'skill',
  223. 'subagent', 'subagent_fork', 'todo_write', 'update_goal', 'web_search',
  224. 'workflow', 'write',
  225. ])
  226. expect(ctx.commands.find(handle.agent, 'goal')).toBeDefined()
  227. } finally {
  228. await handle.dispose()
  229. }
  230. })
  231. it('composes the exact RL prompt and two tools from `minimal`', async () => {
  232. const handle = await ctx.agents.create({
  233. sessionId: SessionId('preset-minimal'),
  234. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  235. })
  236. try {
  237. const assembly = await ctx.systemPrompt.assemble({ scope: handle.agent })
  238. expect(assembly.sections).toEqual([
  239. { name: 'deployment:persona', text: MINIMAL_PROMPT },
  240. ])
  241. expect(assembly.tools.map(tool => tool.name)).toEqual(['bash', 'str_replace_editor'])
  242. expect(assembly.tools.find(tool => tool.name === 'bash')?.description).toBe(MINIMAL_BASH_DESCRIPTION)
  243. expect(JSON.stringify(assembly.tools.find(tool => tool.name === 'str_replace_editor')?.parameters))
  244. .toContain('Absolute path')
  245. expect(ctx.commands.find(handle.agent, 'goal')).toBeUndefined()
  246. expect(ctx.agentPresets.serviceFor(handle.agent, 'compaction')).toBeUndefined()
  247. expect(handle.agent.ctx.get('compaction')).toBeUndefined()
  248. } finally {
  249. await handle.dispose()
  250. }
  251. })
  252. it('keeps two differently composed sessions independent', async () => {
  253. const full = await ctx.agents.create({
  254. sessionId: SessionId('preset-both-full'),
  255. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  256. })
  257. const minimal = await ctx.agents.create({
  258. sessionId: SessionId('preset-both-minimal'),
  259. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  260. })
  261. try {
  262. expect(toolNames(ctx, minimal.agent)).toEqual(['bash', 'str_replace_editor'])
  263. expect(toolNames(ctx, full.agent).length).toBeGreaterThan(10)
  264. await minimal.dispose()
  265. // Tearing the minimal session down leaves the full one whole.
  266. expect(toolNames(ctx, full.agent).length).toBeGreaterThan(10)
  267. expect(toolNames(ctx)).toEqual([])
  268. } finally {
  269. await full.dispose()
  270. }
  271. })
  272. it('composes the cordis agent with its own toolset', async () => {
  273. const handle = await ctx.agents.create({
  274. sessionId: SessionId('preset-cordis'),
  275. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'cordis').then(() => undefined),
  276. })
  277. try {
  278. const tools = toolNames(ctx, handle.agent)
  279. // The self-referential toolset is what distinguishes this preset.
  280. expect(tools).toEqual(expect.arrayContaining([
  281. 'cordis_inspect_list', 'cordis_inspect_query', 'cordis_inspect_self',
  282. 'cordis_define', 'cordis_run', 'cordis_stop', 'cordis_undefine',
  283. ]))
  284. // And it keeps the standard agent's own tools rather than replacing them.
  285. expect(tools).toEqual(expect.arrayContaining(['bash', 'read', 'edit', 'skill']))
  286. expect(tools).not.toContain('str_replace_editor')
  287. expect(ctx.commands.find(handle.agent, 'goal')).toBeDefined()
  288. // The preset's own authoring skill registers into ITS layer of the host
  289. // registry: the cordis agent's view carries it, the global view does not.
  290. const scoped = (await ctx.skills.list({ scope: handle.agent })).map(skill => skill.name)
  291. expect(scoped).toContain('editing-cordis-compositions')
  292. expect((await ctx.skills.list()).map(skill => skill.name)).not.toContain('editing-cordis-compositions')
  293. } finally {
  294. await handle.dispose()
  295. }
  296. })
  297. it('presents `code` as Code Mode without disturbing a native session beside it', async () => {
  298. const coded = await ctx.agents.create({
  299. sessionId: SessionId('preset-code'),
  300. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'code').then(() => undefined),
  301. })
  302. const native = await ctx.agents.create({
  303. sessionId: SessionId('preset-code-native'),
  304. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  305. })
  306. try {
  307. // One tool reaches the MODEL: the transport. The registry's catalog for
  308. // this agent is unchanged — a code mode collapses the presentation, not
  309. // the capabilities — so the assembly is what carries the claim.
  310. const assembly = await ctx.systemPrompt.assemble({ scope: coded.agent })
  311. expect(assembly.tools.map(tool => tool.name)).toEqual(['run_code'])
  312. expect(toolNames(ctx, coded.agent)).not.toContain('str_replace_editor')
  313. expect(ctx.commands.find(coded.agent, 'goal')).toBeDefined()
  314. const sdk = assembly.sections.find(section => section.name === 'tools:sdk')?.text ?? ''
  315. expect(sdk).not.toContain('str_replace_editor')
  316. expect(sdk).toContain('web_search')
  317. // The presentation is this agent's alone: the deployment default is
  318. // native, and the session composed from `standard` still sees it.
  319. const nativeAssembly = await ctx.systemPrompt.assemble({ scope: native.agent })
  320. expect(nativeAssembly.tools.map(tool => tool.name)).toContain('bash')
  321. expect(nativeAssembly.tools.map(tool => tool.name)).not.toContain('run_code')
  322. expect(nativeAssembly.sections.some(section => section.name === 'tools:sdk')).toBe(false)
  323. } finally {
  324. await native.dispose()
  325. await coded.dispose()
  326. }
  327. })
  328. it('keeps the self-referential toolset out of every other preset', async () => {
  329. const handle = await ctx.agents.create({
  330. sessionId: SessionId('preset-no-cordis'),
  331. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  332. })
  333. try {
  334. // Editing the live runtime is opt-in per session, not ambient.
  335. expect(toolNames(ctx, handle.agent)).not.toContain('cordis_define')
  336. } finally {
  337. await handle.dispose()
  338. }
  339. })
  340. it('ships the composition-authoring skill inside the preset directory', async () => {
  341. // The preset's skill root is derived from its own `baseUrl`, so the skill
  342. // travels with the directory wherever the preset is installed.
  343. const skill = join(
  344. SHIPPED_PRESET_ROOT, 'cordis', 'skills', 'editing-cordis-compositions', 'SKILL.md',
  345. )
  346. expect((await readFile(skill, 'utf8')).startsWith('---\nname: editing-cordis-compositions')).toBe(true)
  347. })
  348. it('merges the global skill layer into a preset agent\'s catalog, keeping local discovery preset-side', async () => {
  349. const proj = await mkdtemp(join(tmpdir(), 'dsh-preset-skill-proj-'))
  350. await mkdir(join(proj, '.dsh', 'skills', 'project-proof'), { recursive: true })
  351. await writeFile(join(proj, '.dsh', 'skills', 'project-proof', 'SKILL.md'), [
  352. '---',
  353. 'name: project-proof',
  354. 'description: Proves the preset layer discovers project skills beside global ones.',
  355. '---',
  356. '',
  357. 'Project proof body.',
  358. '',
  359. ].join('\n'))
  360. const handle = await ctx.agents.create({
  361. // Unique per run: the composition persists into the ambient DSH home,
  362. // and a fixed id would collide with a log an earlier run left there.
  363. sessionId: SessionId(`preset-skills-standard-${randomUUID()}`),
  364. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  365. })
  366. try {
  367. // The host (global) view carries the deployment-level provider alone:
  368. // local discovery moved behind the presets with `skill-filesystem`.
  369. expect((await ctx.skills.list({ cwd: proj })).map(skill => skill.name)).toEqual(['dsh-badge'])
  370. // The standard agent's view merges the global layer with its preset's
  371. // own local discovery over the session cwd.
  372. const scoped = (await ctx.skills.list({ cwd: proj, scope: handle.agent })).map(skill => skill.name)
  373. expect(scoped).toContain('dsh-badge')
  374. expect(scoped).toContain('project-proof')
  375. // The preset's own loader tool resolves the global-layer skill.
  376. const loaded = await ctx.tools.execute({
  377. callId: CallId('preset-skills-load'),
  378. name: 'skill',
  379. arguments: { name: 'dsh-badge' },
  380. signal: new AbortController().signal,
  381. agent: handle.agent,
  382. })
  383. expect(loaded.isError).toBe(false)
  384. expect(JSON.stringify(loaded.content)).toContain('powered by dsh')
  385. } finally {
  386. await handle.dispose()
  387. }
  388. })
  389. it('shows a minimal agent the global layer but no loader tool', async () => {
  390. const handle = await ctx.agents.create({
  391. sessionId: SessionId(`preset-skills-minimal-${randomUUID()}`),
  392. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  393. })
  394. try {
  395. // Layer visibility is the registry's; whether an agent can USE skills
  396. // stays the preset's choice — minimal mounts no `tool-skill`, so its
  397. // tool table has no loader even though the global layer is readable.
  398. expect((await ctx.skills.list({ scope: handle.agent })).map(skill => skill.name)).toContain('dsh-badge')
  399. expect(toolNames(ctx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  400. } finally {
  401. await handle.dispose()
  402. }
  403. })
  404. it('never rewrites the preset file it composed from', async () => {
  405. // The Loader persists a tree whose plugin self-disposed, and tearing an
  406. // agent down disposes its whole subtree. Inherited, that rewrote the
  407. // shipped composition — truncating it to `[]` the first time a session
  408. // ended — so `PresetTree` refuses to write at all.
  409. const path = join(SHIPPED_PRESET_ROOT, 'standard', 'agent.cordis.yml')
  410. const before = await readFile(path, 'utf8')
  411. const handle = await ctx.agents.create({
  412. sessionId: SessionId('preset-readonly'),
  413. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  414. })
  415. await handle.dispose()
  416. // Slack, not a race the number has to win. The write is driven by the
  417. // Loader's fiber-unload listener, which fires as the subtree's fibers
  418. // settle rather than when `dispose()` resolves, and the Loader exposes no
  419. // flush to await. A regression writes synchronously inside that listener,
  420. // so any wait past settlement fails; a longer one only slows the test.
  421. await new Promise(resolve => setTimeout(resolve, 50))
  422. expect(await readFile(path, 'utf8')).toBe(before)
  423. })
  424. })
  425. describe('product Bundle and user-preset intersection', () => {
  426. const presetIds = ['products-none', 'products-codex', 'products-claude', 'products-both'] as const
  427. type Product = 'codex' | 'claude-code'
  428. type PresetId = typeof presetIds[number]
  429. async function bootProducts(installed: readonly Product[]): Promise<Context> {
  430. const root = await mkdtemp(join(tmpdir(), 'dsh-product-presets-'))
  431. const userRoot = join(root, 'presets')
  432. const settingsFile = join(root, 'settings.yaml')
  433. const standard = await readFile(join(SHIPPED_PRESET_ROOT, 'standard', 'agent.cordis.yml'), 'utf8')
  434. await writeFile(settingsFile, '{}\n')
  435. for (const id of presetIds) {
  436. let composition = standard
  437. if (id === 'products-codex' || id === 'products-both') {
  438. composition = enablePresetTool(composition, 'tool-subagent-codex')
  439. }
  440. if (id === 'products-claude' || id === 'products-both') {
  441. composition = enablePresetTool(composition, 'tool-subagent-claude-code')
  442. }
  443. const directory = join(userRoot, id)
  444. await mkdir(directory, { recursive: true })
  445. await writeFile(join(directory, 'agent.cordis.yml'), composition)
  446. }
  447. const packageDir = (product: Product): string => (
  448. product === 'codex' ? CODEX_PACKAGE_DIR : CLAUDE_CODE_PACKAGE_DIR
  449. )
  450. const packageName = (product: Product): string => (
  451. product === 'codex'
  452. ? '@deepseek-ai/dsh-subagent-codex'
  453. : '@deepseek-ai/dsh-subagent-claude-code'
  454. )
  455. return await bootWeb(settingsFile, [
  456. {
  457. id: 'agent-presets',
  458. config: {
  459. default: 'standard',
  460. // The shipped root is the plugin's own, prepended before this.
  461. roots: [{ path: userRoot, trust: 'user' }],
  462. includeUserRoot: false,
  463. },
  464. },
  465. ], installed.map(packageDir), [
  466. '@deepseek-ai/dsh-base',
  467. '@deepseek-ai/dsh-web-app',
  468. ...installed.map(packageName),
  469. ])
  470. }
  471. it('composes the intersection of installed Bundles and enabled preset rows', async () => {
  472. const enabledByPreset: Record<PresetId, Product[]> = {
  473. 'products-none': [],
  474. 'products-codex': ['codex'],
  475. 'products-claude': ['claude-code'],
  476. 'products-both': ['codex', 'claude-code'],
  477. }
  478. const scenarios: Array<{ installed: Product[]; presets: readonly PresetId[] }> = [
  479. { installed: [], presets: ['products-both'] },
  480. { installed: ['codex'], presets: ['products-both'] },
  481. { installed: ['claude-code'], presets: ['products-both'] },
  482. { installed: ['codex', 'claude-code'], presets: presetIds },
  483. ]
  484. for (const { installed, presets } of scenarios) {
  485. const productCtx = await bootProducts(installed)
  486. const spawn = vi.spyOn(productCtx.subprocess, 'spawn')
  487. try {
  488. expect(productCtx.subagents.list()
  489. .filter(name => name === 'codex' || name === 'claude-code')
  490. .sort())
  491. .toEqual([...installed].sort())
  492. for (const id of presets) {
  493. const handle = await productCtx.agents.create({
  494. sessionId: SessionId(`preset-${id}-${installed.join('-') || 'none'}-${randomUUID()}`),
  495. setup: agentCtx => productCtx.agentPresets.mount(agentCtx, id).then(() => undefined),
  496. })
  497. try {
  498. const productTools = enabledByPreset[id]
  499. .filter(product => installed.includes(product))
  500. .map(product => product === 'codex' ? 'subagent_codex' : 'subagent_claude_code')
  501. .sort()
  502. const tools = toolNames(productCtx, handle.agent)
  503. expect(tools.filter(name => name === 'subagent_codex' || name === 'subagent_claude_code'))
  504. .toEqual(productTools)
  505. expect(tools).toEqual(expect.arrayContaining(['job_kill', 'job_list', 'job_output']))
  506. for (const productTool of productTools) {
  507. expect(toolParameterNames(productCtx, handle.agent, productTool)).toEqual([
  508. 'description', 'prompt', 'run_in_background',
  509. ])
  510. }
  511. } finally {
  512. await handle.dispose()
  513. }
  514. }
  515. expect(spawn).not.toHaveBeenCalled()
  516. } finally {
  517. spawn.mockRestore()
  518. await productCtx.fiber.dispose()
  519. }
  520. }
  521. }, 120_000)
  522. it('applies a product-row edit only to later sessions on the preset', async () => {
  523. const productCtx = await bootProducts(['codex'])
  524. const preset = await productCtx.agentPresets.resolve('products-none')
  525. const original = await readFile(preset.path, 'utf8')
  526. const existing = await productCtx.agents.create({
  527. sessionId: SessionId('preset-product-generation-existing'),
  528. setup: agentCtx => productCtx.agentPresets.mount(agentCtx, 'products-none').then(() => undefined),
  529. })
  530. try {
  531. expect(toolNames(productCtx, existing.agent)).not.toContain('subagent_codex')
  532. await writeFile(preset.path, enablePresetTool(original, 'tool-subagent-codex'))
  533. const later = await productCtx.agents.create({
  534. sessionId: SessionId('preset-product-generation-later'),
  535. setup: agentCtx => productCtx.agentPresets.mount(agentCtx, 'products-none').then(() => undefined),
  536. })
  537. try {
  538. expect(toolNames(productCtx, existing.agent)).not.toContain('subagent_codex')
  539. expect(toolNames(productCtx, later.agent)).toContain('subagent_codex')
  540. } finally {
  541. await later.dispose()
  542. }
  543. } finally {
  544. await existing.dispose()
  545. await writeFile(preset.path, original)
  546. await productCtx.fiber.dispose()
  547. }
  548. }, 120_000)
  549. })
  550. describe('a switch survives the session', () => {
  551. it('records the choice so the log states what the agent runs', async () => {
  552. const handle = await ctx.agents.create({
  553. sessionId: SessionId('preset-switch-logged'),
  554. meta: { agentPreset: 'standard' },
  555. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  556. })
  557. try {
  558. // The api-proxy's select does exactly this pair while the session is blank.
  559. expect(ctx.commands.find(handle.agent, 'goal')).toBeDefined()
  560. await ctx.agentPresets.recompose(handle.agent.ctx, 'minimal')
  561. handle.agent.session.append('agent-preset/selected', { agentPreset: 'minimal' })
  562. expect(ctx.commands.find(handle.agent, 'goal')).toBeUndefined()
  563. // The header keeps the creation fact; the log carries what it runs.
  564. expect(handle.agent.session.header.agentPreset).toBe('standard')
  565. expect(resolveSessionPreset(handle.agent.session)).toBe('minimal')
  566. } finally {
  567. await handle.dispose()
  568. }
  569. })
  570. it('rebuilds a switched session from the log, not the creation header', () => {
  571. // The exact shape a resume reads back from disk: the header says standard,
  572. // the log records the switch the user made while the session was blank.
  573. const rebuilt = resolveSessionPreset({
  574. header: { version: 0, id: SessionId('x'), createdAt: 0, agentPreset: 'standard' },
  575. events: [
  576. { type: 'agent-preset/selected', seq: 1, time: 0, data: { agentPreset: 'minimal' } },
  577. { type: 'turn/start', seq: 2, time: 0, data: { turn: 0, trigger: { kind: 'message', source: { kind: 'user' } } } },
  578. ] as never,
  579. })
  580. // Reading the header alone would compose the creation-time preset over a
  581. // history another one produced — the replay the blank-only lock prevents.
  582. expect(rebuilt).toBe('minimal')
  583. })
  584. })
  585. describe('a forked session', () => {
  586. it('inherits the composition its seeded history was produced under', async () => {
  587. const parent = await ctx.agents.create({
  588. sessionId: SessionId('preset-fork-parent'),
  589. meta: { agentPreset: 'minimal' },
  590. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  591. })
  592. const inherited = resolveSessionPreset(parent.agent.session)
  593. const child = await ctx.agents.create({
  594. sessionId: SessionId('preset-fork-child'),
  595. meta: {
  596. parentSession: SessionId('preset-fork-parent'),
  597. seedLength: 0,
  598. ...inherited === undefined ? {} : { agentPreset: inherited },
  599. },
  600. setup: agentCtx => ctx.agentPresets.mount(agentCtx, inherited).then(() => undefined),
  601. })
  602. try {
  603. // Composing nothing would leave the child empty: this layer moved every
  604. // model-facing row out of the host plane, so there is nothing to inherit
  605. // for free any more.
  606. expect(toolNames(ctx, child.agent)).toEqual(toolNames(ctx, parent.agent))
  607. expect(toolNames(ctx, child.agent).length).toBeGreaterThan(0)
  608. } finally {
  609. await child.dispose()
  610. await parent.dispose()
  611. }
  612. })
  613. })
  614. describe('a delegated child', () => {
  615. it('runs on the composition its parent runs on', async () => {
  616. const parent = await ctx.agents.create({
  617. sessionId: SessionId('preset-child-parent'),
  618. meta: { agentPreset: 'standard' },
  619. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  620. })
  621. // Exactly what an in-process subagent driver's creation window does.
  622. const child = await parent.agent.ctx.agents.create({
  623. sessionId: SessionId('preset-child'),
  624. meta: childSessionMeta(parent.agent, 1, 0),
  625. setup: (agentCtx) => {
  626. applyChildComposition(agentCtx, parent.agent, {})
  627. },
  628. })
  629. try {
  630. expect(toolNames(ctx, child.agent)).toEqual(toolNames(ctx, parent.agent))
  631. // The shipped `standard` preset is the whole coding agent; an empty
  632. // child here is the defect, and equality alone would not catch it.
  633. expect(toolNames(ctx, child.agent)).toContain('bash')
  634. expect(child.agent.session.header.agentPreset).toBe('standard')
  635. } finally {
  636. await child.dispose()
  637. await parent.dispose()
  638. }
  639. })
  640. it('follows a parent that switched preset while blank', async () => {
  641. const parent = await ctx.agents.create({
  642. sessionId: SessionId('preset-child-switch-parent'),
  643. meta: { agentPreset: 'standard' },
  644. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  645. })
  646. await ctx.agentPresets.recompose(parent.agent.ctx, 'minimal')
  647. const child = await parent.agent.ctx.agents.create({
  648. sessionId: SessionId('preset-child-switch'),
  649. meta: childSessionMeta(parent.agent, 1, 0),
  650. setup: (agentCtx) => {
  651. applyChildComposition(agentCtx, parent.agent, {})
  652. },
  653. })
  654. try {
  655. // The live scope chain is the authority, not the parent's creation
  656. // header — which still names `standard`.
  657. expect(toolNames(ctx, child.agent)).toEqual(toolNames(ctx, parent.agent))
  658. expect(child.agent.session.header.agentPreset).toBe('minimal')
  659. } finally {
  660. await child.dispose()
  661. await parent.dispose()
  662. }
  663. })
  664. })
  665. describe('a launcher that configures no writable root', () => {
  666. // The claim this default exists for, asserted through the real shipped
  667. // bundles rather than a hand-built context: `apps/cli` patches in only the
  668. // system root, and a person's own presets are found anyway because the
  669. // roster derives `<dshHome>/.agent-presets` itself. `$DSH_HOME` is pointed
  670. // at a temp home BEFORE boot — the derived root is resolved when the plugin
  671. // is constructed, and an unpinned run would read the developer's own.
  672. let derivedCtx: Context
  673. let previousHome: string | undefined
  674. beforeAll(async () => {
  675. const home = await mkdtemp(join(tmpdir(), 'dsh-preset-derived-'))
  676. previousHome = process.env.DSH_HOME
  677. process.env.DSH_HOME = home
  678. await mkdir(join(home, '.agent-presets', 'derived-mine'), { recursive: true })
  679. await writeFile(
  680. join(home, '.agent-presets', 'derived-mine', 'agent.cordis.yml'),
  681. '- id: tool-todo\n name: \'@deepseek-ai/dsh-tool-todo\'\n config:\n allowParallelInProgress: true\n',
  682. )
  683. const settingsFile = join(await mkdtemp(join(tmpdir(), 'dsh-preset-derived-settings-')), 'settings.yaml')
  684. await writeFile(settingsFile, '{}\n')
  685. // No configured roots: the shipped one is the plugin's own, and the
  686. // writable one is the roster's own default rather than this patch's job.
  687. derivedCtx = await bootWeb(settingsFile, [{
  688. id: 'agent-presets',
  689. config: { default: 'standard', includeUserRoot: true },
  690. }])
  691. }, 120_000)
  692. afterAll(async () => {
  693. if (previousHome === undefined) delete process.env.DSH_HOME
  694. else process.env.DSH_HOME = previousHome
  695. await derivedCtx.fiber.dispose()
  696. })
  697. it('discovers and mounts a preset the person authored under the harness home', async () => {
  698. const listed = await derivedCtx.agentPresets.list()
  699. const mine = listed.find(preset => preset.id === 'derived-mine')
  700. expect(mine).toMatchObject({ trust: 'user' })
  701. // Omitted rather than undefined: a healthy row carries no `broken` key.
  702. expect(mine?.broken).toBeUndefined()
  703. expect(derivedCtx.agentPresets.authorable).toBe(true)
  704. const handle = await derivedCtx.agents.create({
  705. sessionId: SessionId('preset-derived-root'),
  706. setup: agentCtx => derivedCtx.agentPresets.mount(agentCtx, 'derived-mine').then(() => undefined),
  707. })
  708. try {
  709. expect(toolNames(derivedCtx, handle.agent)).toContain('todo_write')
  710. } finally {
  711. await handle.dispose()
  712. }
  713. })
  714. })
  715. describe('authoring a preset on the shipped composition', () => {
  716. let authorCtx: Context
  717. let userRoot: string
  718. beforeAll(async () => {
  719. userRoot = join(await mkdtemp(join(tmpdir(), 'dsh-preset-authoring-')), 'profiles')
  720. const settingsFile = join(await mkdtemp(join(tmpdir(), 'dsh-preset-authoring-settings-')), 'settings.yaml')
  721. await writeFile(settingsFile, '{}\n')
  722. authorCtx = await bootWeb(settingsFile, [{
  723. id: 'agent-presets',
  724. config: {
  725. default: 'standard',
  726. // The root does not exist yet: a deployment whose user has authored
  727. // nothing is the normal first-run state. The shipped root is the
  728. // plugin's own, prepended before this.
  729. roots: [{ path: userRoot, trust: 'user' }],
  730. includeUserRoot: false,
  731. },
  732. }])
  733. })
  734. it('refuses to copy over or delete a shipped preset', async () => {
  735. await expect(authorCtx.agentPresets.copy('minimal', 'standard')).rejects.toThrow(/already exists/)
  736. await expect(authorCtx.agentPresets.remove('standard')).rejects.toThrow(/ships with the deployment/)
  737. })
  738. it.each(['../escape', 'a/b', '/abs', 'Upper'])('refuses the uncontainable id %j', async (id) => {
  739. // The id becomes a directory name under the user root, so containment is
  740. // checked on the id rather than on the joined path afterwards.
  741. await expect(authorCtx.agentPresets.copy('minimal', id)).rejects.toThrow()
  742. })
  743. it('copies a shipped preset a session then really composes from', async () => {
  744. await authorCtx.agentPresets.copy('minimal', 'my-agent', '我的模式')
  745. // Round-trips through the roster as a `user` row carrying the given name
  746. // and the source's description, over the source's own composition text.
  747. const preset = await authorCtx.agentPresets.resolve('my-agent')
  748. const source = await authorCtx.agentPresets.resolve('minimal')
  749. expect(preset.trust).toBe('user')
  750. expect(preset.name).toBe('我的模式')
  751. expect(preset.description).toBe(source.description)
  752. expect(await authorCtx.agentPresets.read('my-agent')).toBe(await authorCtx.agentPresets.read('minimal'))
  753. // Owner-only, in an owner-only directory: a composition is executable
  754. // configuration on a machine that may have other users.
  755. expect((await stat(preset.path)).mode & 0o777).toBe(0o600)
  756. const handle = await authorCtx.agents.create({
  757. sessionId: SessionId('preset-authored'),
  758. setup: agentCtx => authorCtx.agentPresets.mount(agentCtx, 'my-agent').then(() => undefined),
  759. })
  760. try {
  761. // The same tools the shipped `minimal` composes, from a directory copied
  762. // through the service into a root outside the installed harness.
  763. expect(toolNames(authorCtx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  764. } finally {
  765. await handle.dispose()
  766. }
  767. })
  768. it('deletes what it copied', async () => {
  769. await authorCtx.agentPresets.copy('minimal', 'doomed')
  770. await authorCtx.agentPresets.remove('doomed')
  771. expect((await authorCtx.agentPresets.list()).map(preset => preset.id)).not.toContain('doomed')
  772. })
  773. })
  774. /**
  775. * Which preset an unnamed session gets is a user setting layered over the
  776. * composition's own default. The package suite proves the layering against a
  777. * hand-built context; this proves it through the shipped `cordis.yml` — that
  778. * the roster and the settings provider are actually wired to each other, and
  779. * that the id the setting names is the one a session composes from.
  780. */
  781. describe('the default preset as a user setting', () => {
  782. it('composes an unnamed session from the stored default, not the composed one', async () => {
  783. expect(ctx.agentPresets.defaultId).toBe('standard')
  784. await ctx.settings.update(settingsNamespace(SETTINGS_NAMESPACE), { default: 'minimal' })
  785. try {
  786. expect(ctx.agentPresets.defaultId).toBe('minimal')
  787. const handle = await ctx.agents.create({
  788. sessionId: SessionId('preset-user-default'),
  789. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  790. })
  791. try {
  792. // `mount()` with no id resolves the effective default. Two tools, not
  793. // `standard`'s catalog: the setting decided the composition.
  794. expect(toolNames(ctx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  795. } finally {
  796. await handle.dispose()
  797. }
  798. } finally {
  799. // The context is shared with the rest of the file. `replace({})` drops
  800. // the user section wholesale so the field re-inherits the composition
  801. // base; `update` merges, and would leave the override standing.
  802. await ctx.settings.replace(settingsNamespace(SETTINGS_NAMESPACE), {})
  803. }
  804. expect(ctx.agentPresets.defaultId).toBe('standard')
  805. })
  806. })
  807. describe('a session keeps the preset it was created with', () => {
  808. it('refuses to adopt a live session under a different preset', async () => {
  809. const handle = await ctx.agents.create({
  810. sessionId: SessionId('preset-locked'),
  811. meta: { agentPreset: 'minimal' },
  812. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  813. })
  814. try {
  815. // The api-proxy guard reads exactly this: the header records what the
  816. // session runs, so naming anything else is a caller error rather than a
  817. // switch. Its history was produced under `minimal`'s two tools.
  818. expect(handle.agent.session.header.agentPreset).toBe('minimal')
  819. } finally {
  820. await handle.dispose()
  821. }
  822. })
  823. })
  824. describe('a composition that configures its own preset roots', () => {
  825. let rootsCtx: Context
  826. let teamRoot: string
  827. beforeAll(async () => {
  828. const home = await mkdtemp(join(tmpdir(), 'dsh-preset-roots-'))
  829. const settingsFile = join(home, 'settings.yaml')
  830. await writeFile(settingsFile, '{}\n')
  831. // A workspace-shared root beside the deployment: one preset of its own,
  832. // plus a directory that claims a shipped id.
  833. teamRoot = join(home, 'team-presets')
  834. const minimalComposition = await readFile(join(SHIPPED_PRESET_ROOT, 'minimal', 'agent.cordis.yml'), 'utf8')
  835. for (const id of ['team-spec', 'minimal']) {
  836. await mkdir(join(teamRoot, id), { recursive: true })
  837. await writeFile(join(teamRoot, id, 'agent.cordis.yml'), minimalComposition)
  838. }
  839. // The user layer of the reported regression: a profile's cordis.patch.yml
  840. // configuring a shared preset root. The plugin must EXTEND it with its
  841. // own shipped root, never lose it.
  842. rootsCtx = await bootWeb(settingsFile, [{
  843. id: 'agent-presets',
  844. config: {
  845. default: 'standard',
  846. roots: [{ path: teamRoot, trust: 'user' }],
  847. includeUserRoot: false,
  848. },
  849. }])
  850. }, 120_000)
  851. afterAll(async () => {
  852. await rootsCtx.fiber.dispose()
  853. })
  854. it('keeps configured roots alongside the always-prepended shipped root', async () => {
  855. expect(rootsCtx.agentPresets.roots.map(root => root.path)).toEqual([
  856. SHIPPED_PRESET_ROOT,
  857. teamRoot,
  858. ])
  859. const listed = await rootsCtx.agentPresets.list()
  860. expect(listed.map(preset => preset.id).sort()).toEqual(['code', 'cordis', 'minimal', 'standard', 'team-spec'])
  861. expect(listed.every(preset => preset.broken === undefined)).toBe(true)
  862. // The shipped root comes first: a configured directory claiming a shipped
  863. // id is shadowed, never the other way around.
  864. expect(listed.find(preset => preset.id === 'minimal')?.trust).toBe('system')
  865. expect(listed.find(preset => preset.id === 'team-spec')?.trust).toBe('user')
  866. })
  867. it('composes an agent from a configured-root preset', async () => {
  868. const handle = await rootsCtx.agents.create({
  869. sessionId: SessionId('preset-team-spec'),
  870. setup: agentCtx => rootsCtx.agentPresets.mount(agentCtx, 'team-spec').then(() => undefined),
  871. })
  872. try {
  873. expect(toolNames(rootsCtx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  874. } finally {
  875. await handle.dispose()
  876. }
  877. })
  878. })