Files
deepseek-harness/examples/headless-agent
Tianyi Cui f5866fc202 fix(e2b): address review round on cadence config, disposal, and SDK edge cases
- subprocess-e2b: the 20 ms remote poll cadence becomes a validated pollMs
  Config field (each tick is one control-plane request); the README documents
  the latency-versus-request-count trade.
- subprocess-e2b: extract src/remote.ts owning asError, signalOpts,
  commandOpts, delay, waitTick, and one tolerant signalRemoteGroups shared by
  the pgid-keyed process ladder and sid-keyed terminal ladder, so the two
  teardown paths keep identical error tolerance.
- subprocess-e2b: service disposal aggregates sibling cleanup failures into
  one AggregateError instead of discarding all but the first.
- subprocess-e2b: waitForProcessGroupId refuses published group ids <= 1, so
  a same-UID rewrite of the pid file cannot aim termination at kill -- -1;
  README documents the same-UID control-state limitation.
- subprocess-e2b: drain-grace expiry now releases an inherited-output E2B
  callback blocked on host backpressure before disconnecting, so the SDK
  settlement cannot stay pinned behind an unread host stream.
- subprocess-e2b: spawn/spawnTerminal stop validating typed spec fields
  (trust-TypeScript rule; pty-local validates its config before specs exist);
  resolveExecutable rejects separator-containing relative paths per the seam
  contract; terminal setups tracked as a Set of records.
- subprocess-e2b: PTY output push-without-backpressure is a documented
  contract (flowing consumer folds bytes; paused consumer buffers).
- fs-e2b: streamText normalizes the pinned SDK's empty-file '' return into an
  empty stream instead of throwing on getReader().
- e2b overlays: comment the one-world cwd invariant across e2b.cwd,
  workspaceRoot, and bash-local's implicit default workdir.
2026-08-08 22:19:13 +08:00
..
2026-08-08 15:08:07 +08:00

headless-agent

English | 中文

Headless one-shot agent wiring: DeepSeek V4 + local bash and filesystem tools + subagent delegation + workflows and fresh-agent Ralph iteration + todo_write + JSONL persistence, with @deepseek-ai/dsh-cli-demo as the app front door.

Run it

# repo root .env (gitignored) or exported env:
#   DEEPSEEK_API_KEY=sk-…
#   DEEPSEEK_BASE_URL=https://…   # optional; defaults to the public API
pnpm run demo:headless "fix the failing test in this workspace"
pnpm run demo:headless --output-format json -- "summarize the implementation"
pnpm run demo:headless --output-format stream-json -- "run the focused tests"

Exactly one nonblank positional task is required; quote tasks containing spaces. There is no -p flag. text prints the last text-bearing assistant message, json prints one DSH-native result record, and stream-json emits the top-level session's canonical task-turn events before that record. Child sessions surface only through parent tool events and results.

Each invocation creates and persists a fresh session, runs all model and tool steps in one turn, flushes, disposes, and exits. This is non-interactive automation: there is no prompt, approval, resume, second turn, or stdin context. The configured tools can mutate the launch workspace, run commands, spawn child agents, and consume provider tokens.

E2B POC overlay

e2b.cordis.yml replaces the local filesystem and subprocess providers with one shared E2B sandbox while retaining dsh-bash-local and the same model-facing tools. Put E2B_API_KEY beside DEEPSEEK_API_KEY in the gitignored root .env, then run:

pnpm run demo:e2b "create hello.txt, read it back, and run pwd"

The overlay creates the same absolute cwd inside the sandbox, but it does not upload or mount the host workspace. File and Bash mutations exist only in E2B; Cordis, model calls, agent/session state, session logs, skills, and SDK buffers remain on the host. The demo kills its sandbox on timeout and disposal. It is a provider-composition POC, not a whole-harness migration or a workspace-sync feature.

Advanced and snapshot wiring

advanced.cordis.yml adds Code Mode and the Cordis tools to the shipped leaf. advanced.cordis.snapshot.yml replaces only the live LLM with replay. The tests under tests/ own the keyless real-Loader smoke, key-gated world-verified smoke, and the stream-json replay snapshot with its parent and child session fixtures.

The package-level CLI contract documents output records, exit status, cancellation, persistence, and model/token effects.