DeepSeek Harness(dsh)架构解析:本地优先 AI Agent 的 Profile、Plugin 与 Tool 体系

说明:本文基于现有 dsh 项目材料与源码结构整理,重点讨论架构与使用思路。项目归属、发行包名、具体版本与默认配置请以你实际使用的源码仓库为准。

摘要:本文从整体架构、Profile 机制、Plugin 系统、Tool / Skill 工具链、配置加载、Web / Headless / TUI 多模式运行、MCP 集成及开发流程等角度拆解 dsh,并通过架构图、数据流和示例说明如何组织一个本地优先、可扩展的 AI 编程 Agent 运行时。

关键词:AI Agent、dsh、本地优先、Profile、Plugin、Tool、Skill、MCP、LLM、编程助手


📋 目录


1. 项目概述

1.1 什么是 DeepSeek Harness?

DeepSeek Harness(dsh)可以理解为一个本地优先的 AI Agent 运行时框架,面向编程辅助与自动化开发场景。它把 Agent、Profile、Plugin、Tool、Skill 等能力拆分为可组合模块,让开发者能够按场景装配文件系统、Shell、网络检索、工作流、子代理等能力,并接入不同的 LLM 后端。

这里的“本地优先”强调运行时、工具链、配置与数据路径优先由本机掌控,并不等同于“完全离线”。如果所选 LLM 后端是云端模型,模型请求仍会经过对应的远程 API;如果接入本地模型,则可以进一步减少数据外发。

1.2 核心理念

DeepSeek Harness

Local First

Modular Architecture

Agent System

运行时与工具链优先本地执行

数据路径与权限可控

模型后端可本地或远程

Profile 分层管理

Plugin 可插拔扩展

Tool 独立封装

支持 Subagent

工作流编排

任务规划与跟踪

1.3 关键特性

特性 描述 价值
本地优先 运行时、工具链与配置优先在本机执行;模型后端可本地或远程 数据路径更可控、便于私有化部署
模块化架构 Profile + Plugin + Tool 三层结构 高度可扩展、可定制
多模式运行 Web UI / Headless / TUI 适应不同使用场景
MCP 支持 可通过 Model Context Protocol 对接外部工具或上下文能力 提升工具生态兼容性
技能规范 Skill 定义标准接口 统一的能力暴露方式

2. 核心架构图

2.1 整体系统架构

Model Layer
LLM 接口

Tools Layer
功能工具箱

Core Engine
cordis 配置引擎

Profile 执行层

Launcher 层
dsh 命令入口

用户交互层

JSON-RPC

WebSocket

通信协议层

JSON-RPC HTTP

WebSocket/SSE

IDEA/VSCode IDE

命令行终端

Web 浏览器

参数解析器

模式路由器

Web Profile

Headless Profile

TUI Profile

自定义 Profile

配置加载器

插件管理器

会话管理器

文件系统

Shell 执行

网络检索

目标管理

任务队列

工作流

子代理

LLM 客户端

Token 计量

cordis 引擎

Tools Layer

2.2 三层架构模型

🔌 Plugin / Tool 层

🎭 Profile 层 · Profile Layer

👤 用户层 · User Layer

选择运行模式

装配与加载能力

命令输入

参数配置

结果展示

CLI / Web / IDE

web
Web UI 模式

headless
无头模式

tui
终端界面

custom
自定义配置

定义能力组合包

Cordis
配置管理

DSH-Agent
Agent 核心

Tools
功能实现

Skills
能力规范


3. 组件依赖关系

3.1 核心包依赖树

Infrastructure

UI 层

Tool 层

Profile 层

Core 层

Boot 层

顶层入口

dsh CLI
包名以实际项目为准

dsh-app-boot
环境变量加载

dsh-cmdline
命令行规范

dsh-launch-environment
环境感知

dsh-agent
Agent 核心逻辑

dsh-session
会话管理

dsh-settings
配置管理

dsh-persona
角色定义

dsh-web-app
Web 应用

dsh-headless
无头模式

dsh-command-goal
目标命令

dsh-command-compact
紧凑输出

dsh-tool-fs

dsh-tool-bash

dsh-tool-pwsh

dsh-tool-web

dsh-tool-subagent

dsh-tool-workflow

dsh-tool-jobs

dsh-client-ui-cordis

dsh-client-ui-agent-preset

cordis
配置引擎

dsh-base
基础框架

dsh-mcp-client
MCP 客户端

3.2 插件系统架构

manages

loads

exposes

uses

hot-reload

PluginSystem

+loadPlugins()

+unloadPlugins()

+reloadPlugin()

+listPlugins()

Profile

+name: string

+bundles: Array<string>

+patchFile: string

CordisEngine

+applyPatch()

+mergeConfigs()

+evaluateRules()

+generateAST()

ToolRegistry

+registerTool()

+getTool()

+listTools()

+validateSchema()

SkillDefinition

+name: string

+description: string

+parameters: Object

+implementation: Function

3.3 关键第三方依赖类型

与其给出容易随版本变化的“依赖数量统计”,更适合按职责理解依赖结构:

依赖类别 主要职责
UI / Web Web 界面、状态管理与交互组件
AI / LLM SDK 模型请求、流式响应与工具调用协议适配
Network / HTTP HTTP、WebSocket、SSE 等网络通信
Text Processing 文本解析、搜索、格式化与内容处理
Build / Tooling TypeScript、构建、测试与开发工具链
Type Definitions 类型声明与跨包接口约束

具体依赖名称与版本请以项目 package.json、lockfile 及实际构建结果为准。


4. 启动流程详解

4.1 从命令行到运行的完整流程

应用实例 Cordis 引擎 插件加载器 环境变量 Profile Booter 模式路由器 参数解析器 dsh 命令行 用户 应用实例 Cordis 引擎 插件加载器 环境变量 Profile Booter 模式路由器 参数解析器 dsh 命令行 用户 Application ready for use dsh --profile web parseDshArgs() validate profile name route to web profile loadProfile('web') loadLayeredEnv('dsh') env vars snapshot initialize plugins load cordis.config.yml apply bundle patches sequentially merge user overrides composed config tree instantiate with config register tools & skills Web 服务启动(端口按配置)

4.2 Web 模式启动时序

Token 监控器 LLM 客户端 Agent 核心 工具服务 插件管理器 dsh Web Server 用户 (浏览器) Token 监控器 LLM 客户端 Agent 核心 工具服务 插件管理器 dsh Web Server 用户 (浏览器) alt [需要工具调用] alt [Token 限制检查] loop [Event Loop] GET / (初始化连接) loadWebPlugins() registerTools([fs,bash,web...]) tools registered injectServices(tools) initialized ready serve SPA POST /api/chat (用户消息) processMessage(msg) analyze intent execute(tool, params) run tool logic tool result checkBudget() remaining budget generateResponse(context) response chunks streamResponse() SSE 推送响应 updateSessionState()

4.3 Headless 模式执行流程

进程退出 输出格式化 任务执行器 计划器 Headless Profile dsh Launcher 用户 (CLI) 进程退出 输出格式化 任务执行器 计划器 Headless Profile dsh Launcher 用户 (CLI) alt [需要外部工具] alt [需要 LLM 推理] loop [Task Execution Steps] dsh --profile headless "analyze codebase" bootWithArgs(task) createPlan(task) decomposeToSteps() executeStep(i) call tool (e.g., readFile) step result query LLM reasoning result reportProgress() update plan state compileResults() print final answer exit (non-zero if error)

5. 数据流转图

5.1 单次对话的数据流

信息查询

代码编辑

执行命令

复杂任务

预算充足

预算不足

用户输入消息

意图识别

检索工具调用

文件系统工具

Shell 工具

工作流编排

工具执行上下文

Prompt 构建

Token 预算检查

LLM 推理

终止响应

响应生成

是否需要工具反馈

Tool Call 序列化

直接返回结果

等待工具执行

SSE 流式推送

前端渲染

5.2 工具调用闭环

Agent Loop

Tool Execution

Client Layer

Agent Core

自动允许

需审批

批准

拒绝

Agent 决定调用工具

序列化 Tool Call

发送给客户端

接收 Tool Call

审批类型

立即执行

显示确认对话框

用户决策

返回拒绝原因

执行工具逻辑

收集执行结果

返回给 Agent

更新对话上下文

继续执行?

生成最终响应

5.3 配置文件加载链

开始配置加载

读取 Bundle 配置

dsh-base/default.yml

dsh-web-app/config.yml

dsh-tools/tools.yml

合并配置对象

是否有 Profile 级配置?

读取 profiles/<name>/cordis.patch.yml

跳过 Profile 层

叠加到基础配置

是否有全局配置?

读取 $DSH_HOME/cordis.patch.yml

叠加全局配置

有 --patch 参数?

依次加载指定 patch 文件

输出最终配置

依次叠加 patch

5.4 Token 消耗监控流

启动 Token 计量器

设置预算上限

记录初始值

LLM 请求发出

追踪 Input Tokens

是否超预算?

记录剩余预算

标记超限警告

LLM 响应接收

追踪 Output Tokens

累计是否超预算?

更新总消耗

触发提前终止

更多对话轮次?

输出详细报告


6. 命令使用指南

6.1 命令层次结构

Plugin Commands

Profile Commands

Launcher Flags

dsh <command>

--help 查看帮助

--version 查看版本

--profile <name>

web

plugin

启动任意 Profile

启动 Web UI

管理插件

--patch <file>: 额外配置层

--dump-config: 输出配置树

--dump-default-config: 默认配置

headless '任务': 无头执行

tui: 终端界面

add <pkg>: 添加插件

remove <pkg>: 删除插件

why <pkg>: 查询依赖

6.2 常用命令示例

# 1. 基础启动命令
dsh --profile web                 # 启动 Web UI(同:dsh web)
dsh --profile headless "任务描述"  # 单次任务执行
dsh --profile tui                # 终端模式(如果已安装)

# 2. 带配置的启动
dsh --profile web --port 8080    # 自定义端口
dsh --profile headless --patch ./extra.yml "任务"  # 自定义配置

# 3. 配置诊断
dsh --profile web --dump-config         # 查看当前完整配置
dsh --profile web --dump-default-config # 查看默认配置(不含用户覆盖)

# 4. 插件管理
dsh plugin --profile web add @my/plugin     # 添加插件
dsh plugin --profile web remove @old/plugin # 删除插件
dsh plugin --profile web why some-package   # 查看依赖关系

# 5. 查看帮助
dsh --help                    # Launcher 帮助
dsh web --help                # Web 模式帮助
dsh --profile headless --help # Headless 模式帮助

6.3 配置覆盖顺序

配置更适合用“后加载覆盖前加载”来理解,而不是用没有实际含义的百分比分数表示:

系统默认配置

Bundle 预设配置

Profile 配置

$DSH_HOME 全局配置

Launcher --patch

最终生效配置

通常越靠后的配置层优先级越高;如果你的实现采用不同合并规则,应以 Cordis 的实际 merge / patch 行为为准。


7. Profile 机制解析

7.1 Profile 的概念

Profile 是预定义的功能组合包,通过叠加多个插件和工具来实现特定用途。每个 Profile 都是一组可复用的能力集合。

7.2 Profile 文件结构

$DSH_HOME/profiles/<name>/

package.json

dsh.profile

cordis.patch.yml

node_modules/

依赖声明

脚本定义

bundles 列表

元数据定义

用户配置覆盖

pnpm 安装的插件

7.3 Profile 加载顺序

文件系统 Cordis Engine Profile Directory Launcher 用户请求 文件系统 Cordis Engine Profile Directory Launcher 用户请求 loop [Bundle Loading (in order)] Ready for execution dsh --profile myprofile locate profiles/myprofile/ return path read dsh.profile bundles=[base,web,tools] read bundle packages package content apply patch partial config read cordis.patch.yml user overrides read $DSH_HOME/cordis.patch.yml global overrides merge all layers final config load node_modules plugins loaded

7.4 内置 Profile 对比

Profile 用途 适用场景 包含的主要 Bundles
web Web UI 界面 图形化交互、IDE 集成 base, web-app, client-ui, tools
headless 无头任务执行 CI/CD、自动化脚本 base, headless, goal, compact
tui 终端界面 命令行交互 base, terminal, session
minimal 最小化配置 资源受限环境 base only
custom 用户自定义 特殊需求场景 用户指定的 bundles

8. Plugin System

8.1 插件体系结构

Plugin System

Cordis Plugins

DSH Plugins

Tool Plugins

cordis-plugin-loader

cordis-plugin-hmr

cordis-plugin-include

cordis-plugin-timer

dsh-skill

Skill 定义

Skill 规范

dsh-session

会话状态

会话历史

Tool Registry

fs 工具

shell 工具

web 工具

8.2 插件生命周期

pnpm add

dependencies resolved

enabled

file changed (HMR)

reload complete

disabled by config

enabled again

pnpm remove

Unloaded

Installing

Loaded

Active

HotReloading

Disabled

Unloading

插件已加载
服务已注册
可用工具已暴露

热更新中
无需重启进程
无缝切换版本

8.3 插件注册流程

Plugin Cache Tool Registry Cordis Loader package.json pnpm installer Plugin Cache Tool Registry Cordis Loader package.json pnpm installer loop [For each exported tool] Plugin ready for use read plugin metadata @scope/name version cache dependencies install success registerPlugin(spec) parse cordis config resolve bundle paths registerTool(schema) validate schema registered store loaded state ready plugin activated

8.4 常用 Cordis Plugin

Plugin 功能 版本 使用场景
cordis-plugin-loader 插件加载器 ^1.0.2 核心加载逻辑
cordis-plugin-hmr 热更新 ^1.0.16 开发时快速迭代
cordis-plugin-include 配置包含 ^1.0.6 复用配置片段
cordis-plugin-timer 定时器 ^1.1.3 周期性任务调度

9. 工具箱

9.1 工具分类矩阵

类别 主要功能 核心包 典型用法
文件系统 文件读写、搜索 dsh-tool-fsdsh-tool-fs-search 代码分析、文本编辑
Shell 执行 命令运行 dsh-tool-bashdsh-tool-pwsh Git 操作、构建脚本
网络能力 HTTP 请求、Web 检索 dsh-tool-web API 调用、信息获取
任务管理 作业队列、Todo 列表 dsh-tool-jobsdsh-tool-todo 异步任务跟踪
工作流 流程编排 dsh-tool-workflow 复杂任务自动化
子代理 Subagent 控制 dsh-tool-subagent 多层级 Agent 协作
技能 Skill 管理 dsh-tool-skill 能力扩展注册
目标 Goal 驱动 dsh-tool-goaldsh-command-goal 长期任务规划
算法推理 Ralph 推理引擎 dsh-tool-ralph 数学计算、逻辑推理

9.2 工具注册与调用

通过

失败

准备参数

合法

非法

工具定义文件

工具 Schema 验证

注册到 Tool Registry

抛出错误

存储工具元数据

绑定实现函数

暴露为 Tool Definition

Agent 调用时

参数验证

工具执行

参数错误

收集执行结果

格式化为标准响应

返回给 Agent

9.3 核心工具详细说明

以下函数签名用于说明工具职责与调用方式,属于概念示意;真实 API、参数类型与返回值请以实际源码定义为准。

文件系统工具 (dsh-tool-fs)
// 典型用法
readFile(path: string): Promise<string>
writeFile(path: string, content: string): Promise<void>
searchFiles(pattern: string, options?: SearchOptions): Promise<string[]>
createDirectory(path: string): Promise<void>
Shell 工具 (dsh-tool-bash, dsh-tool-pwsh)
// Unix Bash
execBash(command: string, options?: ExecOptions): Promise<ExecResult>

// Windows PowerShell  
execPowerShell(command: string, options?: ExecOptions): Promise<ExecResult>

interface ExecResult {
    stdout: string
    stderr: string
    exitCode: number
}
网络工具 (dsh-tool-web)
fetchURL(url: string, options?: FetchOptions): Promise<ResponseData>
searchWeb(query: string): Promise<SearchResult[]>
parseHTML(html: string): Promise<ParsedContent>
工作流工具 (dsh-tool-workflow)
startWorkflow(steps: WorkflowStep[]): Promise<WorkflowInstance>
awaitCompletion(instanceId: string, timeout?: number): Promise<WorkflowResult>
cancelWorkflow(instanceId: string): Promise<void>

10. Agent Presets 配置

10.1 Preset 配置系统

Agent Presets

presets/

config/agent-presets/minimal/

config/agent-presets/standard/

config/agent-presets/code/

config/agent-presets/cordis/

preset.yml

agent.cordis.yml

preset.yml

agent.cordis.yml

preset.yml

agent.cordis.yml

preset.yml

agent.cordis.yml

skills/

cordis-plugin-development

editing-compositions

10.2 Preset 配置文件内容

standard/preset.yml:

name: 标准模式
description: 功能完整的编码 Agent,支持文件编辑、Shell、文件与网页检索、Skills、计划、目标、子代理和工作流。
order: 1  # 在列表中优先显示

minimal/preset.yml:

name: 最小化配置
description: 仅包含基础功能的精简配置
order: 3

10.3 Cordis 配置示例

下例用于展示“通过配置组合能力”的思路,字段名与插件名请以实际项目 Schema 为准。

standard/agent.cordis.yml:

# 定义 Agent 的核心能力和行为规则
plugins:
  - name: dsh-skill
    enabled: true
    config:
      maxConcurrent: 5
      
  - name: dsh-tool-fs
    enabled: true
    permissions:
      readOnly: false
      allowedPaths:
        - "."
        
  - name: dsh-tool-bash
    enabled: true
    sandboxed: true

rules:
  - when: task.type == 'code_edit'
    then: allow_tool(dsh-tool-fs)
    
  - when: task.type == 'shell_exec'
    then: require_confirmation(dsh-tool-bash)

10.4 Preset 选择指南

使用场景 推荐 Preset 理由
日常编码辅助 standard 功能完整,开箱即用
代码审查/重构 code 专注于代码相关能力
快速原型开发 minimal 轻量级,启动快
自定义开发 cordis 包含 Cordis 插件开发能力

11. 开发工作流

11.1 从源码构建

通过

失败

成功

失败

克隆仓库

环境检查

运行 pnpm install

安装依赖: Node.js 20+, pnpm

执行 pnpm build

构建成功?

生成产物到 dist/

查看错误日志

修复问题

测试运行

构建完成

调试测试用例

11.2 开发循环流程

测试套件 dsh 运行时 构建监听器 代码编辑器 开发者 测试套件 dsh 运行时 构建监听器 代码编辑器 开发者 热更新触发 alt [测试通过] [测试失败] 持续迭代优化 修改源代码 保存文件 rebuild changed modules hot reload trigger 提示重载完成 运行快速验证 ✅ All passed ❌ Failed tests 修复 bug

11.3 调试技巧

方式一:使用 dump-config 诊断
# 查看所有配置的组成
dsh --profile web --dump-default-config

# 查看用户覆盖后的完整配置
dsh --profile web --dump-config
方式二:启用详细日志
# 设置环境变量
export DEBUG=dsh:*
export LOG_LEVEL=debug

# 运行
dsh --profile web
方式三:单步调试
# 使用 Node.js inspect 模式
node --inspect lib/bin.js --profile web

12. 实战应用案例

12.1 场景一:在 IDEA 中集成 DSH

以下时序图为集成思路示意,接口路径与快捷键应按实际插件实现调整。

dsh web server JS Bridge DSH Plugin IntelliJ IDEA 用户 dsh web server JS Bridge DSH Plugin IntelliJ IDEA 用户 alt [需要工具调用] loop [后台会话保持] 选中代码 + Ctrl+Alt+H showToolWindow() sendMessage(prompt) POST /api/chat process message invoke tool (e.g., readFile) get result streamResponse (SSE) handleStreamPart updatePanel(response) 显示 AI 响应 background updates refresh UI

12.2 场景二:CI/CD 自动化流水线

Git Repository dsh headless Runner Script CI/CD Pipeline Git Repository dsh headless Runner Script CI/CD Pipeline Automated Code Review Complete trigger task dsh --profile headless "analyze changes" read changed files file list analyze impact generate recommendations return results upload artifacts notify result

runner.sh 示例:

#!/bin/bash
set -e

echo "Starting automated analysis..."

# Run DSH headless mode
RESULT=$(dsh --profile headless <<EOF
Analyze the following changes:
$(git diff --stat HEAD^ HEAD)

Generate a summary of potential issues:
1. Breaking API changes
2. Security concerns
3. Performance regressions
EOF
)

echo "$RESULT" | tee analysis-report.md

# Optional: Submit to PR
gh pr comment $PR_NUMBER --body-file analysis-report.md

12.3 场景三:自定义 Tool 开发

下例用于说明 Tool 的 Schema + Handler 组织方式,不应视为稳定公开 API。

合法

非法

通过

失败

识别需求

定义 Tool Schema

Schema 验证

实现 Tool Logic

注册 Tool

Tool 测试

文档编写

修复 Bug

发布为 Plugin

Tool 定义示例:

// my-awesome-tool.ts
// import { defineTool } from '<your-dsh-skill-package>'; // 以实际包名为准

export const myAwesomeTool = defineTool({
  name: 'analyze-code-quality',
  description: 'Analyze code quality and suggest improvements',
  inputSchema: {
    type: 'object',
    properties: {
      filePath: { type: 'string', description: 'Path to source file' },
      rules: { 
        type: 'array', 
        items: { type: 'string' },
        description: 'Analysis rules to apply'
      }
    },
    required: ['filePath']
  },
  handler: async ({ filePath, rules = [] }) => {
    // Implementation here
    return {
      issues: [],
      suggestions: [],
      score: 85
    };
  }
});

13. 总结:dsh 的价值在“可组合的 Agent 运行时”

从架构上看,dsh 的重点并不是把所有能力塞进一个单体 Agent,而是通过 Profile 决定运行方式和能力组合,通过 Plugin 承载可扩展模块,通过 Tool / Skill 暴露可调用能力,再由配置引擎把这些组件组合成具体的编程助手。

这套设计的实际价值主要体现在三点:

  1. 本地优先、边界清晰:工具执行、权限控制、配置与项目文件都可以放在本地运行时中管理;是否调用远程模型则由模型后端决定。
  2. 按需装配:Web、Headless、TUI 等模式可以复用同一套底层能力,不必为每个入口复制一份 Agent 实现。
  3. 适合二次开发:文件系统、Shell、检索、工作流、子代理、MCP 等能力都可以围绕统一的注册与调用机制扩展。

如果你的目标是搭建一个可控、可扩展的 AI 编程助手,那么比“换一个更强的模型”更重要的,往往是把 运行时、工具权限、上下文、工作流与模型接口组织成一套稳定的 Harness。


📚 附录

A. 参考资料

资源 建议核对位置 说明
项目仓库 你实际使用的源码仓库 核对项目归属、分支与发布版本
包信息 package.json / lockfile 核对真实包名、版本与依赖
CLI 文档 项目 README.md / --help 核对命令、参数与默认值
配置 Schema 项目源码 / 配置文档 核对 Cordis、Profile、Plugin 与 Tool 字段

发布前建议再做一次“源码对照”:尤其核对包名、默认端口、内置 Profile、插件版本和对外 API,避免把内部实现或示例代码误写成稳定接口。

B. 术语表

术语 英文 解释
Profile 配置集 预定义的功能组合包
Plugin 插件 可扩展的功能模块
Tool 工具 具体的功能实现单元
Skill 技能 Agent 能力的规范定义
Patch 补丁 配置覆盖层
Cordis Cordis 配置管理引擎
Bundle 组合包 一组相关的插件集合

C. 故障排除速查

问题 可能原因 解决方法
dsh: command not found npm 未加入 PATH 检查 npm config get prefix
Web 无法启动 端口被占用 换端口:dsh --profile web --port 8081
工具调用失败 Schema 不匹配 检查 Tool 定义和参数
配置冲突 Patch 重叠 使用 --dump-config 检查
插件加载慢 依赖太多 使用 minimal Profile

最后整理:2026-08-16
发布建议:项目元信息与外部链接请以实际源码仓库为准。

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐