mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Implements docs/rfc/.../2026-06-20-extract-example-app-packages.md. Each
example was thick — a hand-rolled start.ts, an infra preamble, nested
base.yml/base-core.yml/acp-tail.yml includes, and a coupled front-door
cluster enforced only by prose. This moves the composition into packages so
each example is a thin leaf cordis.yml: pick the swappable backends, load one
app package.
New packages:
- @deepseek-ai/dsh-agent-core (packages/core/agent-core): one bundle plugin
that loads the providerless/executor-less/UI-less spine (timer + llm +
sessions + system-prompt + tools + agents + invariants + tool-bash +
agent-loop) via ctx.plugin(...) inside apply(), and forwards agent-loop's
`agents` list as its own Config (export const Config = AgentLoop.Config,
default []).
- @deepseek-ai/dsh-stdio-agent (packages/ui/stdio-agent): terminal chat APP —
agent-core + console logger + readline UI + a pre-created `main` agent, with
a bin. The demo:echo/coding front door.
- @deepseek-ai/dsh-acp-agent (packages/ui/acp-agent): ACP server APP —
agent-core + JSONL persistence + the acp bridge, NO stdout logger, with a
bin. The stdout-purity footgun is structurally unreachable from the leaf.
Amendment to the RFC: hmr stays a LEAF cordis.yml entry, not baked into
dsh-stdio-agent. hmr is a Loader-only dev plugin (throws without
--expose-internals; the in-process test tier can't even import its decorator
form), so a package statically importing it could never carry the per-file
coverage gate. Unlike the console logger, a stray hmr is not a stdout-purity
footgun, so leaving it at the leaf costs no safety. With hmr out, all three new
packages carry in-process unit specs at 100%.
Boot glue (Loader tail, .env load, snapshot-mode selection, stdin-dispose
lifecycle) moves into each app's bin; start.ts and base.yml/base-core.yml/
acp-tail.yml are deleted. Each app package gets a keyless real-load-path test
that boots through its bin + the cordis Loader (guarding the unwrapExports
export-shape bug class, postmortem 0001). ACP snapshot replay stays green
against the existing committed goldens (pure boot restructuring). RFC moved
proposed->implemented with the amendment recorded; package/example/architecture
docs and the module graph updated.
148 lines
5.9 KiB
TypeScript
148 lines
5.9 KiB
TypeScript
import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process'
|
|
import { Readable, Writable } from 'node:stream'
|
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import {
|
|
ClientSideConnection,
|
|
ndJsonStream,
|
|
PROTOCOL_VERSION,
|
|
type Agent as AcpAgent,
|
|
type Client,
|
|
type RequestPermissionRequest,
|
|
type RequestPermissionResponse,
|
|
type SessionNotification,
|
|
} from '@agentclientprotocol/sdk'
|
|
|
|
/**
|
|
* REAL-load-path smoke for @deepseek-ai/dsh-acp-agent: boot the app through its
|
|
* own `bin` (the demo:acp entry) as a subprocess, driving the cordis Loader and
|
|
* `unwrapExports` over a minimal `cordis.yml` that loads THIS package. This is
|
|
* the guard a hand-built `ctx.plugin({...})` mount structurally cannot be — that
|
|
* bypasses `unwrapExports`, the exact path that once dropped the bridge's
|
|
* `inject` and shipped (docs/postmortem/0001). It exercises the headline ACP
|
|
* operations end-to-end: `initialize` → `session/new` → `session/load`.
|
|
*
|
|
* KEYLESS: `session/new` and `session/load` reach the agent FACTORY but never
|
|
* the model (no prompt is sent), so no DEEPSEEK_API_KEY is needed. A dummy key
|
|
* lets `llm-deepseek`'s `apply()` (key-PRESENT check only) boot the tree.
|
|
*
|
|
* The config is written into a temp dir whose cwd IS the session workspace, so
|
|
* the bash workdir validation passes. We point tsx at the repo-root tsconfig
|
|
* (TSX_TSCONFIG_PATH) because the child's cwd is outside the repo and the
|
|
* unbuilt `paths` map is found by searching UP from cwd.
|
|
*/
|
|
|
|
const binScript = fileURLToPath(new URL('../src/bin.ts', import.meta.url))
|
|
const tsxLoader = fileURLToPath(import.meta.resolve('tsx'))
|
|
// Repo root is four levels up from packages/ui/acp-agent/tests.
|
|
const repoTsconfig = fileURLToPath(new URL('../../../../tsconfig.json', import.meta.url))
|
|
|
|
// A minimal leaf that loads this app + the two backends — the same shape as
|
|
// examples/acp-agent/cordis.yml, inlined so the package test owns its fixture.
|
|
const CORDIS_YML = `
|
|
- id: llm-deepseek
|
|
name: '@deepseek-ai/dsh-llm-deepseek'
|
|
config:
|
|
apiKey: !!js process.env.DEEPSEEK_API_KEY
|
|
models: [deepseek-v4-flash]
|
|
- id: bash
|
|
name: '@deepseek-ai/dsh-bash-local'
|
|
- id: acp-agent
|
|
name: '@deepseek-ai/dsh-acp-agent'
|
|
config:
|
|
model: deepseek-v4-flash
|
|
systemPrompt: 'You are a test agent.'
|
|
`
|
|
|
|
interface Spawned {
|
|
child: ChildProcessWithoutNullStreams
|
|
client: ClientSideConnection
|
|
stderr: string[]
|
|
}
|
|
|
|
let spawned: Spawned | undefined
|
|
let workdir: string | undefined
|
|
|
|
afterEach(async () => {
|
|
if (spawned !== undefined) {
|
|
spawned.child.kill('SIGKILL')
|
|
spawned = undefined
|
|
}
|
|
if (workdir !== undefined) await rm(workdir, { recursive: true, force: true })
|
|
workdir = undefined
|
|
})
|
|
|
|
async function boot(): Promise<Spawned & { cwd: string }> {
|
|
workdir = await mkdtemp(join(tmpdir(), 'acp-agent-pkg-'))
|
|
const cwd = workdir
|
|
const configPath = join(cwd, 'cordis.yml')
|
|
await writeFile(configPath, CORDIS_YML)
|
|
const child = spawn(
|
|
process.execPath,
|
|
['--import', tsxLoader, binScript, configPath],
|
|
{
|
|
cwd,
|
|
env: {
|
|
...process.env,
|
|
TSX_TSCONFIG_PATH: repoTsconfig,
|
|
// Key-present check only; no prompt is sent, so the model is never called.
|
|
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY ?? 'keyless-acp-agent-smoke',
|
|
},
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
},
|
|
)
|
|
const stderr: string[] = []
|
|
child.stderr.setEncoding('utf8')
|
|
child.stderr.on('data', (chunk: string) => stderr.push(chunk))
|
|
const stream = ndJsonStream(
|
|
Writable.toWeb(child.stdin) as WritableStream<Uint8Array>,
|
|
Readable.toWeb(child.stdout) as ReadableStream<Uint8Array>,
|
|
)
|
|
const makeClient = (_agent: AcpAgent): Client => ({
|
|
sessionUpdate(_params: SessionNotification): Promise<void> {
|
|
return Promise.resolve()
|
|
},
|
|
requestPermission(_params: RequestPermissionRequest): Promise<RequestPermissionResponse> {
|
|
return Promise.resolve({ outcome: { outcome: 'cancelled' } })
|
|
},
|
|
})
|
|
const client = new ClientSideConnection(makeClient, stream)
|
|
spawned = { child, client, stderr }
|
|
return { ...spawned, cwd }
|
|
}
|
|
|
|
describe('dsh-acp-agent real-load-path smoke (bin + Loader, keyless)', () => {
|
|
it('boots via its bin and answers initialize → session/new → session/load', async () => {
|
|
const { client, cwd, stderr } = await boot()
|
|
// initialize: a broken export shape (collapsed bridge plugin, dropped inject)
|
|
// crashes the tree on the first service read here — see postmortem 0001.
|
|
const init = await client.initialize({
|
|
protocolVersion: PROTOCOL_VERSION,
|
|
clientCapabilities: {},
|
|
})
|
|
expect(init.agentCapabilities?.loadSession).toBe(true)
|
|
|
|
// session/new reaches the agent FACTORY (create) without the model.
|
|
const { sessionId } = await client.newSession({ cwd, mcpServers: [] })
|
|
expect(sessionId).toBeTruthy()
|
|
|
|
// session/load reaches the resume FACTORY + persistence without the model:
|
|
// load an UNKNOWN id (loading the live `sessionId` would correctly reject as
|
|
// "already loaded"). The bridge consults `sessionPersistence.list()` then
|
|
// `agents.resume()`, both of which run from the JSON-RPC read loop OUTSIDE
|
|
// the bridge's inject scope — the exact path postmortem 0001 crashed. A
|
|
// healthy tree rejects with a not-found error; a broken export shape would
|
|
// instead throw "cannot get property … without inject" before reaching it.
|
|
const unknownId = '00000000-0000-4000-8000-000000000000'
|
|
await client.loadSession({ sessionId: unknownId, cwd, mcpServers: [] }).then(
|
|
() => { throw new Error('expected session/load of an unknown id to reject') },
|
|
(error: unknown) => { expect(String(error)).not.toContain('without inject') },
|
|
)
|
|
|
|
expect(stderr.join('')).not.toContain('without inject')
|
|
}, 30_000)
|
|
})
|