Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Build with DeepSeek Harness as a coding agent (#1005)

BFlatb13a765384b7
diff --git a/crates/ai/src/cli_agents/adapters.rs b/crates/ai/src/cli_agents/adapters.rs
index 0b37dbe7..0d2a155a 100644
--- a/crates/ai/src/cli_agents/adapters.rs
+++ b/crates/ai/src/cli_agents/adapters.rs
@@ -7,11 +7,13 @@ use super::*;
mod antigravity;
mod copilot;
+mod dsh;
mod hermes;
mod maki;
mod opencode;
pub use antigravity::Antigravity;
pub use copilot::Copilot;
+pub use dsh::DeepSeekHarness;
pub use hermes::Hermes;
pub use maki::Maki;
pub use opencode::OpenCode;
@@ -241,6 +243,7 @@ impl AgentAdapters {
Arc::new(Hermes),
Arc::new(Maki),
Arc::new(Copilot),
+ Arc::new(DeepSeekHarness),
],
}
}
diff --git a/crates/ai/src/cli_agents/adapters/dsh.rs b/crates/ai/src/cli_agents/adapters/dsh.rs
new file mode 100644
index 00000000..26f57e98
--- /dev/null
+++ b/crates/ai/src/cli_agents/adapters/dsh.rs
@@ -0,0 +1,247 @@
+//! DeepSeek Harness (`dsh --profile headless "<task>"`).
+//!
+//! The harness answers one task, streams its reasoning to stderr and prints its last message on
+//! stdout, so its output is the answer text, not JSON lines.
+//!
+//! It has no flag for a tool server the way other agents do: servers come from the profile's patch
+//! layers. Our tool server therefore arrives as one generated `--patch` overlay for this run, which
+//! the launcher applies after the profile's own layer, so the person's saved profile is untouched.
+//! The overlay is written into a folder of the run's own, owner-only on Unix, so a shared temporary
+//! folder can't be used to reach it.
+//! Its headless profile keeps no session to continue, so a build that stops starts again from the
+//! brief (as it does with the plain adapter).
+
+use super::*;
+
+use std::sync::atomic::{AtomicU64, Ordering};
+
+/// The tool server's id inside the overlay. Distinct from the one a person may have added to their
+/// own profile by hand, so the two never replace each other.
+const OVERLAY_ID: &str = "mcp-craft-anything-run";
+
+/// DeepSeek Harness run as a coding agent: one task in, its last message out.
+pub struct DeepSeekHarness;
+
+impl AgentAdapter for DeepSeekHarness {
+ fn ids(&self) -> &'static [&'static str] {
+ &["dsh", "deepseek-harness"]
+ }
+
+ fn args(&self, cx: &ArgsCx) -> Vec<String> {
+ let mut v = cx.options.args.clone();
+ v.extend(["--profile".into(), "headless".into()]);
+ // A question about a build may only read the project's files, so it gets no tool server.
+ if !cx.question {
+ v.extend(["--patch".into(), tool_server_patch(cx.mcp)]);
+ }
+ v.push(format!("{}{}", cx.preamble, cx.prompt));
+ v
+ }
+
+ fn streams_json(&self) -> bool {
+ false
+ }
+
+ /// `--help` lists `--profile`, which the plain `dsh <task>` form would need anyway.
+ fn required_flags(&self) -> (&'static [&'static str], &'static [&'static str]) {
+ (&["--help"], &["--profile"])
+ }
+
+ /// Without `--profile headless` the harness boots a whole application instead of answering, so a
+ /// failed flag check keeps this adapter rather than falling back to the plain one.
+ fn plain_fallback(&self) -> bool {
+ false
+ }
+
+ fn check_tool_server(&self, stop: &CancelToken) -> Result<(), ToolError> {
+ cli_can_start(craft_anything_platform::self_cli_path().as_deref(), stop)?;
+ // The folder and the write a run uses, once, before the build starts: a temporary folder
+ // that can't take the overlay stops the build here with a fix, not part-way through one.
+ let dir = overlay_dir()?;
+ let written = craft_anything_platform::write_atomic_private(&dir.join(PROBE_FILE), b"[]\n");
+ let _ = std::fs::remove_dir_all(&dir);
+ written
+ }
+}
+
+/// The overlay's file name inside a run's folder.
+const OVERLAY_FILE: &str = "tool-server.yml";
+
+/// The file a preflight writes and removes to prove the folder takes one.
+const PROBE_FILE: &str = "probe.yml";
+
+/// A folder of this process's own for one run, in the system temporary folder: two builds at once
+/// never share one, and because it's owner-only nothing another user could prepare in a shared
+/// temporary folder is ever written through.
+fn overlay_dir() -> Result<std::path::PathBuf, ToolError> {
+ static NEXT: AtomicU64 = AtomicU64::new(0);
+ let n = NEXT.fetch_add(1, Ordering::Relaxed);
+ let dir = std::env::temp_dir().join(format!("craft-anything-dsh-{}-{n}", std::process::id()));
+ // `create_dir` refuses a path that is already there, so a folder prepared beforehand is never
+ // used (`create_dir_all` would accept one).
+ private_dir().create(&dir).map_err(|e| {
+ ToolError::io(dir.display(), e).with_remediation(
+ "Free space on the drive that holds the temporary folder, or point TMP at one that can be written, then start the build again.".to_string(),
+ )
+ })?;
+ Ok(dir)
+}
+
+/// A builder for one run's own folder, owner-only from the moment it exists.
+#[cfg(unix)]
+fn private_dir() -> std::fs::DirBuilder {
+ use std::os::unix::fs::DirBuilderExt as _;
+ let mut builder = std::fs::DirBuilder::new();
+ // Made owner-only as it's created, so it's never readable by anyone else, not even briefly.
+ builder.mode(0o700);
+ builder
+}
+
+/// A builder for one run's own folder; Windows keeps each person's temporary folder to themselves.
+#[cfg(not(unix))]
+fn private_dir() -> std::fs::DirBuilder {
+ std::fs::DirBuilder::new()
+}
+
+/// Our tool server as a patch overlay for this run. A folder that can't take it leaves the harness
+/// a path that isn't there, so the run fails at startup instead of building without the tool server
+/// it was promised; [`check_tool_server`](AgentAdapter::check_tool_server) reports the everyday
+/// causes first, with a fix.
+fn tool_server_patch(mcp: &McpCommand) -> String {
+ let Ok(dir) = overlay_dir() else { return missing_overlay() };
+ let path = dir.join(OVERLAY_FILE);
+ match craft_anything_platform::write_atomic_private(&path, overlay_yaml(mcp).as_bytes()) {
+ Ok(()) => path.display().to_string(),
+ Err(e) => {
+ log::warn!("the DeepSeek Harness tool-server overlay couldn't be written: {}", e.message);
+ missing_overlay()
+ }
+ }
+}
+
+/// A path no run wrote anything to.
+fn missing_overlay() -> String {
+ std::env::temp_dir().join(format!("craft-anything-dsh-{}-missing.yml", std::process::id())).display().to_string()
+}
+
+/// The overlay in the harness's patch format: a list of loader entries, one server inserted.
+fn overlay_yaml(mcp: &McpCommand) -> String {
+ let q = |s: &str| format!("'{}'", s.replace('\'', "''"));
+ let args: String = mcp.args.iter().map(|a| format!("\n - {}", q(a))).collect();
+ format!(
+ "# Craft Anything's tool server for this run. Generated; safe to delete.\n\
+ - insert:\n \
+ - id: {OVERLAY_ID}\n \
+ name: '@deepseek-ai/dsh-mcp-client'\n \
+ config:\n \
+ serverName: craft-anything\n \
+ transport: stdio\n \
+ command: {}\n \
+ args:{args}\n \
+ toolCallTimeoutMs: 300000\n",
+ q(&mcp.command)
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// A tool server command for a run's project.
+ fn mcp() -> McpCommand {
+ McpCommand {
+ command: r"C:\Program Files\Craft Anything\craft-anything-cli.exe".into(),
+ args: vec!["mcp".into(), "--project".into(), r"C:\w\p\investigation.cany".into()],
+ notes: None,
+ }
+ }
+
+ /// The arguments for one message, and the server they name.
+ fn args(options: &BackendOptions, question: bool) -> (Vec<String>, McpCommand) {
+ let mcp = mcp();
+ let cx = ArgsCx { options, prompt: "make a game", preamble: "PRE ", mcp: &mcp, resume: None, builder: !question, reads_checked: false, question };
+ (DeepSeekHarness.args(&cx), mcp.clone())
+ }
+
+ /// The task goes last, after the profile and any extra arguments.
+ #[test]
+ fn one_task_goes_to_the_headless_profile_last() {
+ let (a, _) = args(&BackendOptions::default(), false);
+ assert_eq!(a[0..2], ["--profile", "headless"], "{a:?}");
+ assert_eq!(a.last().map(String::as_str), Some("PRE make a game"), "{a:?}");
+ let with_args = BackendOptions { args: vec!["--patch".into(), "extra.yml".into()], ..Default::default() };
+ let (a, _) = args(&with_args, false);
+ assert_eq!(a[0..4], ["--patch", "extra.yml", "--profile", "headless"], "{a:?}");
+ }
+
+ /// The run's tool server, as an overlay in a folder of its own that only its owner can read.
+ #[test]
+ fn the_tool_server_arrives_as_a_patch_overlay_in_the_runs_own_folder() {
+ let (a, mcp) = args(&BackendOptions::default(), false);
+ let i = a.iter().position(|x| x == "--patch").expect("a --patch overlay");
+ let path = std::path::PathBuf::from(&a[i + 1]);
+ assert!(path.exists(), "{path:?}");
+ let written = std::fs::read_to_string(&path).expect("read the overlay");
+ assert!(written.contains("- insert:"), "{written}");
+ assert!(written.contains(OVERLAY_ID), "{written}");
+ assert!(written.contains("serverName: craft-anything"), "{written}");
+ // The server's own arguments, including the run's project, quoted for YAML.
+ assert!(written.contains("- 'mcp'"), "{written}");
+ assert!(written.contains(&format!("- '{}'", mcp.args[2])), "{written}");
+ // A folder of the run's own, so nothing another user prepared in a shared temporary folder
+ // is written through.
+ let folder = path.parent().expect("a folder of its own").to_path_buf();
+ let own = format!("craft-anything-dsh-{}-", std::process::id());
+ assert!(folder.file_name().and_then(|n| n.to_str()).is_some_and(|n| n.starts_with(&own)), "{folder:?}");
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt as _;
+ let bits = |p: &std::path::Path| std::fs::metadata(p).expect("metadata").permissions().mode() & 0o777;
+ assert_eq!(bits(&folder), 0o700, "folder {:o}", bits(&folder));
+ assert_eq!(bits(&path), 0o600, "overlay {:o}", bits(&path));
+ }
+ // Two runs never share one.
+ let (b, _) = args(&BackendOptions::default(), false);
+ let other = std::path::PathBuf::from(&b[b.iter().position(|x| x == "--patch").expect("--patch") + 1]);
+ let other_dir = other.parent().expect("a folder of its own").to_path_buf();
+ assert_ne!(folder, other_dir);
+ for dir in [folder, other_dir] {
+ let _ = std::fs::remove_dir_all(dir);
+ }
+ }
+
+ /// A folder that can't take the overlay stops the run, rather than building without the tool
+ /// server it was promised.
+ #[test]
+ fn a_folder_that_cannot_take_the_overlay_leaves_a_path_that_is_not_there() {
+ let missing = missing_overlay();
+ assert!(!std::path::Path::new(&missing).exists(), "{missing}");
+ }
+
+ /// A question may only read, so it gets no tool server.
+ #[test]
+ fn a_question_gets_no_tool_server() {
+ let (a, _) = args(&BackendOptions::default(), true);
+ assert!(!a.iter().any(|x| x == "--patch"), "{a:?}");
+ assert_eq!(a.last().map(String::as_str), Some("PRE make a game"), "{a:?}");
+ }
+
+ /// The agent is registered under both ids, not handed to the plain adapter.
+ #[test]
+ fn registered_not_the_plain_adapter() {
+ assert!(AgentAdapters::built_in().for_agent("dsh").ids().contains(&"dsh"));
+ assert!(AgentAdapters::built_in().for_agent("deepseek-harness").ids().contains(&"dsh"));
+ assert_eq!(DeepSeekHarness.required_flags(), (&["--help"][..], &["--profile"][..]));
+ assert!(!DeepSeekHarness.plain_fallback());
+ assert!(!DeepSeekHarness.streams_json());
+ }
+
+ /// A path or a flag with a quote in it must not break the overlay's YAML.
+ #[test]
+ fn quotes_are_escaped_for_yaml() {
+ let mcp = McpCommand { command: "cli's.exe".into(), args: vec!["--project".into(), r"C:\it's here".into()], notes: None };
+ let y = overlay_yaml(&mcp);
+ assert!(y.contains("command: 'cli''s.exe'"), "{y}");
+ assert!(y.contains("- 'C:\\it''s here'"), "{y}");
+ }
+}
diff --git a/crates/ai/src/cli_agents/mod.rs b/crates/ai/src/cli_agents/mod.rs
index e2b11844..023e01d7 100644
--- a/crates/ai/src/cli_agents/mod.rs
+++ b/crates/ai/src/cli_agents/mod.rs
@@ -49,6 +49,7 @@ pub const KNOWN: &[(&str, &str, &str)] = &[
("qwen-code", "qwen", "Qwen Code"),
("goose", "goose", "Goose"),
("maki", "maki", "Maki"),
+ ("dsh", "dsh", "DeepSeek Harness"),
];
pub fn program_for(agent: &str) -> String {
@@ -2350,7 +2351,10 @@ echo '{"type":"turn.completed","usage":{"input_tokens":1,"output_tokens":1}}'
assert!(reg.for_agent("claude").resumes() && !reg.for_agent("codex").resumes() && reg.for_agent("antigravity").resumes());
// Registering an adapter for an existing id replaces that one.
reg.register(Arc::new(EchoAgent));
- assert_eq!(format!("{reg:?}"), r#"["claude-code", "codex", "gemini-cli", "opencode", "antigravity", "hermes", "maki", "copilot", "echo-agent"]"#);
+ assert_eq!(
+ format!("{reg:?}"),
+ r#"["claude-code", "codex", "gemini-cli", "opencode", "antigravity", "hermes", "maki", "copilot", "dsh", "echo-agent"]"#
+ );
}
#[test]
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rs
index 40200fb7..6bc6452b 100644
--- a/crates/ai/src/lib.rs
+++ b/crates/ai/src/lib.rs
@@ -77,7 +77,7 @@ impl BackendKind {
BackendKind::Openrouter => openai::OPENROUTER_MODELS,
BackendKind::Gemini => openai::GEMINI_MODELS,
BackendKind::OpenaiCompatible => &[],
- BackendKind::AgentCli => &["claude-code", "codex", "copilot", "gemini-cli", "opencode", "antigravity", "hermes", "maki"],
+ BackendKind::AgentCli => &["claude-code", "codex", "copilot", "gemini-cli", "opencode", "antigravity", "hermes", "maki", "dsh"],
}
}
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index b5149e89..f1aa1c69 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -718,6 +718,14 @@ Owner: open · Status: in progress
(#62)
- [ ] Gemini CLI's sign-in reportedly refuses individuals now (#400): check, and stop recommending
it in the builder setup dialog if so
+- [x] DeepSeek Harness: an adapter runs `dsh --profile headless "<task>"` and hands it our tool
+ server as a generated `--patch` overlay for that run (its own project, inbox and mode), since
+ the harness reads tool servers only from profile layers; a question gets none and the person's
+ own profile is left untouched. Verified with adapter and overlay tests and a live follow-up
+ website build whose journal shows `rebuild_check`, `core_unknown_add` and `core_handoff_write`
+ going through our server — claimed: 0231071, branch `feature/dsh-agent-adapter`
+- [ ] DeepSeek Harness: no resume (its headless profile keeps no session), a build on the harness's
+ desktop profile is untried, and the task still goes over in argv (see the argv note above)
### R2.4 Runtime study for apps and games (with consent)
Owner: maintainers · Status: in progress
diff --git a/docs/STATUS.md b/docs/STATUS.md
index e5264f1a..550b237e 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -86,6 +86,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi
| Auto mode | Settings → Safety, on by default. Builder actions go ahead without asking, except a fixed set that is never done unasked (deleting outside the project, system changes, publishing…); questions get "decide yourself"; asset spending stops at the budget | Unit tests |
| Generated assets | Off until the person turns them on for a game (the switch on Make and on the project, `project_assets_allow`, `rebuild --generate-assets`, saved in craft.json; turning it on without a fal.ai key asks for one); the brief and the asset tools need both that and a key. `assets_image_generate` (Nano Banana Pro by default) and `assets_model_generate` (picture → Tripo P1 low-poly GLB with a face limit) through the person's key for each asset provider (fal.ai today), with agent apps and API-key builds alike; per-project budget, $5 by default (`[assets] budget_usd` in config.toml); models and prices from the `assets.toml` table (picture model selectable: Nano Banana Pro, FLUX dev or schnell; priced per picture or per megapixel); every call reports its cost | Unit tests; a live 3D generation with a real key (picture, then model) with FLUX dev; Nano Banana Pro not yet run with a real key; an API-key build not yet run with one |
| Claude Code builder | Runs the person's own `claude` in headless mode (Opus 5.5, high effort unless configured) with our MCP server, a permission-prompt tool and `core_person_ask`; preflights for our CLI (a build stops plainly if it's missing or won't start) and sign-in | Argument and stream-parser tests; live preflight; live builder turns; see [claude-code.md](claude-code.md) |
+| DeepSeek Harness builder | Runs the person's own `dsh --profile headless "<task>"`, which answers one task and prints its last message as text. The harness takes its tool servers from profile patch layers and has no per-run flag for one, so our tool server arrives as a generated `--patch` overlay for that run (the run's project, inbox and mode included); the person's own profile is untouched, a question gets no tool server, and its headless profile keeps no session to resume. An npm `.cmd` shim is unwrapped to its interpreter, so `dsh` found on PATH runs as `node …/dsh/lib/bin.js` | Adapter and YAML-overlay tests; live preflight (`ai test`); live builder turns on a website (follow-up build, 3 min 10 s, 100% alike at 1440/768/390 px, Ready) where the builder's own journal entries show `rebuild_check`, `core_unknown_add`, `core_plan_update` and `core_handoff_write` going through our tool server, and that server started with the run's `--project`/`--inbox`. Not checked: resume (none exists), a build with the harness's desktop profile, and macOS |
| Agents over ACP | Opt-in per backend (`acp = true`): Gemini CLI, Qwen Code, opencode, goose, Hermes and Maki in their ACP mode, one agent process per chat or build with our MCP server; Maki's ACP mode takes the backend's model (`cli_model`). In chat, permission requests become consent questions; in builds they go through the same approval policy as Claude Code's (inbox, Auto mode). While a saved session loads, replayed updates are withheld from the new turn | Protocol unit tests against scripted agent messages and an approval-policy test. Run live with Maki 0.7.0 only (2026-11-02, Linux, headless CLI): a static page built to Ready in 38 s, a follow-up continued the same session with `session/load`, and with Auto mode off its command and tool requests were refused in an unattended run. Replay suppression passes scripted load-history, success/error and cancellation tests; this correction has not been rerun with a live agent. Turns report 0 tokens over ACP |
| GitHub Copilot | Installed `copilot` through ACP by default, with CLI-owned login (no credential import), explicit Craft Anything MCP tool allowlist, model selection and fresh read-only build questions. Target handoff retains the last 128 entries with the active target last; context discovery respects tool cancellation and shared picker warnings name the agent | Authenticated builds, model discovery and real-account session resume confirmed by the person using the app. Target-boundary, cancellation and agent-warning regressions supplement unit tests and an offline CLI 1.0.105 compatibility test covering all five access modes. See [copilot.md](copilot.md) |
| Shared investigation for local agents | A worker saves session-only investigations before starting MCP, shares open targets in a mode-aware handoff, and reloads externally recorded evidence/findings. Builder refresh failures warn rather than ending the turn. The workbench Evidence pane shows `fnd_*` records with proof links; `core_finding_edit` preserves ids and omitted confidence while checking evidence and stale revisions | Engine persistence/correction tests, process-level MCP target tests in both modes, and headless findings-rendering test; live authenticated target-to-finding workflow confirmed by the person using the app |