@lornatang/dsh-caveman 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +202 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +51 -0
- package/README.md +218 -0
- package/README.zh.md +218 -0
- package/cordis.patch.yml +3 -0
- package/examples/caveman-anthropic.patch.yml +14 -0
- package/examples/caveman-auto.patch.yml +15 -0
- package/lib/attribution.js +24 -0
- package/lib/blocks.js +80 -0
- package/lib/cavecrew-git.js +83 -0
- package/lib/cavecrew.js +67 -0
- package/lib/compression.js +434 -0
- package/lib/index.js +127 -0
- package/lib/memory.js +35 -0
- package/lib/mode.js +71 -0
- package/lib/native.js +357 -0
- package/lib/runtime.js +199 -0
- package/lib/skills.js +75 -0
- package/lib/stats.js +189 -0
- package/lib/types/attribution.d.ts +8 -0
- package/lib/types/blocks.d.ts +12 -0
- package/lib/types/cavecrew-git.d.ts +5 -0
- package/lib/types/cavecrew.d.ts +10 -0
- package/lib/types/compression.d.ts +50 -0
- package/lib/types/index.d.ts +30 -0
- package/lib/types/memory.d.ts +3 -0
- package/lib/types/mode.d.ts +33 -0
- package/lib/types/native.d.ts +43 -0
- package/lib/types/runtime.d.ts +23 -0
- package/lib/types/skills.d.ts +3 -0
- package/lib/types/stats.d.ts +6 -0
- package/package.json +129 -0
- package/presets/cavecrew.patch.yml +54 -0
- package/scripts/benchmark.mjs +79 -0
- package/scripts/caveman-cli.mjs +30 -0
- package/scripts/learn-binary.mjs +82 -0
- package/scripts/learn-checksums.json +29 -0
- package/vendor/caveman/LICENSE +202 -0
- package/vendor/caveman/LICENSE-MIT +21 -0
- package/vendor/caveman/NOTICE +49 -0
- package/vendor/caveman/agents/cavecrew-builder.md +46 -0
- package/vendor/caveman/agents/cavecrew-investigator.md +56 -0
- package/vendor/caveman/agents/cavecrew-reviewer.md +47 -0
- package/vendor/caveman/skills/activation-rule.mjs +43 -0
- package/vendor/caveman/skills/cavecrew/README.md +67 -0
- package/vendor/caveman/skills/cavecrew/SKILL.md +78 -0
- package/vendor/caveman/skills/caveman/README.md +68 -0
- package/vendor/caveman/skills/caveman/SKILL.md +89 -0
- package/vendor/caveman/skills/caveman-commit/README.md +44 -0
- package/vendor/caveman/skills/caveman-commit/SKILL.md +63 -0
- package/vendor/caveman/skills/caveman-compress/README.md +262 -0
- package/vendor/caveman/skills/caveman-compress/SECURITY.md +55 -0
- package/vendor/caveman/skills/caveman-compress/SKILL.md +114 -0
- package/vendor/caveman/skills/caveman-compress/scripts/__init__.py +9 -0
- package/vendor/caveman/skills/caveman-compress/scripts/__main__.py +3 -0
- package/vendor/caveman/skills/caveman-compress/scripts/benchmark.py +80 -0
- package/vendor/caveman/skills/caveman-compress/scripts/cli.py +94 -0
- package/vendor/caveman/skills/caveman-compress/scripts/compress.py +1331 -0
- package/vendor/caveman/skills/caveman-compress/scripts/detect.py +192 -0
- package/vendor/caveman/skills/caveman-compress/scripts/validate.py +440 -0
- package/vendor/caveman/skills/caveman-discover/SKILL.md +115 -0
- package/vendor/caveman/skills/caveman-evidence-review/SKILL.md +142 -0
- package/vendor/caveman/skills/caveman-explore/SKILL.md +42 -0
- package/vendor/caveman/skills/caveman-explore/package.json +12 -0
- package/vendor/caveman/skills/caveman-explore/tests/skill-file.test.mjs +44 -0
- package/vendor/caveman/skills/caveman-help/README.md +39 -0
- package/vendor/caveman/skills/caveman-help/SKILL.md +62 -0
- package/vendor/caveman/skills/caveman-learn/CLAUDE.md +32 -0
- package/vendor/caveman/skills/caveman-learn/README.md +38 -0
- package/vendor/caveman/skills/caveman-learn/SKILL.md +185 -0
- package/vendor/caveman/skills/caveman-learn/package.json +12 -0
- package/vendor/caveman/skills/caveman-learn/tests/index.js +1 -0
- package/vendor/caveman/skills/caveman-learn/tests/skill-file.test.mjs +54 -0
- package/vendor/caveman/skills/caveman-manage/SKILL.md +112 -0
- package/vendor/caveman/skills/caveman-optimize/SKILL.md +111 -0
- package/vendor/caveman/skills/caveman-review/README.md +33 -0
- package/vendor/caveman/skills/caveman-review/SKILL.md +53 -0
- package/vendor/caveman/skills/caveman-setup/SKILL.md +222 -0
- package/vendor/caveman/skills/caveman-stats/README.md +48 -0
- package/vendor/caveman/skills/caveman-stats/SKILL.md +17 -0
- package/vendor/caveman/skills/compile.mjs +298 -0
- package/vendor/caveman/skills/engine-mcp-tools.json +10 -0
- package/vendor/caveman/skills/generated/aider/pack.json +163 -0
- package/vendor/caveman/skills/generated/claude/pack.json +163 -0
- package/vendor/caveman/skills/generated/codex/pack.json +163 -0
- package/vendor/caveman/skills/generated/gemini/pack.json +163 -0
- package/vendor/caveman/skills/generated/hermes/pack.json +163 -0
- package/vendor/caveman/skills/generated/opencode/pack.json +163 -0
- package/vendor/caveman/skills/investigate-first/SKILL.md +16 -0
- package/vendor/caveman/skills/investigate-first/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/lean-build/SKILL.md +18 -0
- package/vendor/caveman/skills/lean-build/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/megacave/README.md +11 -0
- package/vendor/caveman/skills/megacave/SKILL.md +65 -0
- package/vendor/caveman/skills/migration/SKILL.md +17 -0
- package/vendor/caveman/skills/migration/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/native/native-core.md +16 -0
- package/vendor/caveman/skills/registry.json +283 -0
- package/vendor/caveman/skills/safe-refactor/SKILL.md +16 -0
- package/vendor/caveman/skills/safe-refactor/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/surgical-patch/SKILL.md +16 -0
- package/vendor/caveman/skills/surgical-patch/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/ultracave/README.md +13 -0
- package/vendor/caveman/skills/ultracave/SKILL.md +63 -0
- package/vendor/caveman/skills/verbs-gate.mjs +213 -0
- package/vendor/caveman/skills/verify-and-stop/SKILL.md +16 -0
- package/vendor/caveman/skills/verify-and-stop/agents/openai.yaml +4 -0
- package/vendor/caveman/src/hooks/caveman-config.js +921 -0
- package/vendor/caveman/src/hooks/caveman-parse.js +342 -0
- package/vendor/caveman/src/hooks/package.json +3 -0
package/README.zh.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "面向 DeepSeek Harness 的 Caveman 回答风格、可恢复压缩、浏览器工具与子代理。"
|
|
3
|
+
kind: "package-bundle"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @lornatang/dsh-caveman
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概要
|
|
11
|
+
|
|
12
|
+
`dsh-caveman` 为 DeepSeek Harness 提供 Caveman 技能和工具,包括按会话隔离的回答风格、可恢复的工具结果压缩、Auto 选模、Blocks 建议、Browse 工具和 Cavecrew 子代理。将 bundle 安装到 profile 后,该 profile 的会话即可使用相应能力。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [延伸阅读](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制](#known-limitations)
|
|
21
|
+
- [开发者注记](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
需要 Node.js 22.19 或更新版本以及 DSH。把 bundle 安装到需要使用 Caveman 的会话所在的 profile。
|
|
29
|
+
|
|
30
|
+
### 安装到 profile
|
|
31
|
+
|
|
32
|
+
使用以下命令安装和移除:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
dsh plugin --profile <name> add @lornatang/dsh-caveman
|
|
36
|
+
dsh plugin --profile <name> remove @lornatang/dsh-caveman
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
也可以从仓库打包并安装:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
git clone https://github.com/Lornatang/dsh-caveman.git
|
|
43
|
+
cd dsh-caveman
|
|
44
|
+
npm ci
|
|
45
|
+
npm pack
|
|
46
|
+
dsh plugin --profile <name> add ./lornatang-dsh-caveman-0.1.0.tgz
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`add` 命令把 bundle 组合进 profile。patch 会插入 `caveman` 行、三个 Cavecrew 预设及其委派工具。`add` 或 `remove` 后重启 DSH,使 profile 重新加载配置。
|
|
50
|
+
|
|
51
|
+
### 你会得到
|
|
52
|
+
|
|
53
|
+
| 暴露面 | 提供方 |
|
|
54
|
+
|---|---|
|
|
55
|
+
| Caveman 技能与按会话隔离的回答风格 | `src/skills.ts`、`src/mode.ts` |
|
|
56
|
+
| 原生编码规则 | `src/index.ts` |
|
|
57
|
+
| 报告当前及历史会话已记录用量的 `/caveman-stats` | `src/stats.ts` |
|
|
58
|
+
| 可恢复的工具结果压缩与 `caveman_retrieve` | `src/compression.ts` 和 middleware 运行时 |
|
|
59
|
+
| 压缩、恢复、统计和 TOON MCP 工具 | DSH MCP manager 和 `caveman-mcp` |
|
|
60
|
+
| 本地记忆与原文恢复 | DSH MCP manager 和 `cavemem` |
|
|
61
|
+
| Auto 自动选模 | DSH pi-ai provider 和 Caveman 代理 |
|
|
62
|
+
| Shell 命令建议 | `src/blocks.ts` 和 Blocks |
|
|
63
|
+
| `mcp__caveman_browse__*` 浏览器工具 | DSH MCP manager 和 Browse |
|
|
64
|
+
| `cavecrew-investigator`、`cavecrew-builder`、`cavecrew-reviewer` | `presets/cavecrew.patch.yml` 和 `src/cavecrew.ts` |
|
|
65
|
+
| 作为 Node 包安装时提供的 `dsh-caveman` 命令 | `scripts/caveman-cli.mjs` 和 `@caveman-ai/cli` |
|
|
66
|
+
|
|
67
|
+
### 配置
|
|
68
|
+
|
|
69
|
+
bundle 自带 `caveman` 行。在 profile 的 `cordis.patch.yml` 中添加覆盖行,只列出需要修改的字段:
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
# $DSH_HOME/profiles/<name>/cordis.patch.yml
|
|
73
|
+
- id: caveman
|
|
74
|
+
config:
|
|
75
|
+
defaultMode: manual
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| 字段 | 默认值 | 含义 |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| `defaultMode` | 由配置决定,未设置时为 `caveman` | 会话的初始回答风格。 |
|
|
81
|
+
| `inputCompression` | 自动 | 可用时使用经过验证的本地运行时;设为 `false` 可关闭,设为 `true` 可使用配置的地址。 |
|
|
82
|
+
| `middlewareEndpoint` | `http://127.0.0.1:8787` | middleware 回环地址。 |
|
|
83
|
+
| `blocksBinary` | 自动查找 | 覆盖 `caveman-blocks` 的绝对路径。 |
|
|
84
|
+
| `browseBinary` | 自动查找 | 覆盖 `caveman-browse` 的绝对路径;需要 DSH MCP manager。 |
|
|
85
|
+
| `mcpBinary` | 自动查找 | 覆盖 `caveman-mcp` 的绝对路径;需要 DSH MCP manager。 |
|
|
86
|
+
| `memoryBinary` | 自动发现 | 覆盖 `cavemem` 的绝对路径;启用本地记忆工具。 |
|
|
87
|
+
|
|
88
|
+
### 回答模式与用量
|
|
89
|
+
|
|
90
|
+
可使用 `/caveman`、`/ultracave`、`/megacave`、`/caveman ultra`、`/caveman wenyan`、`/caveman status` 和 `stop caveman`。模式切换只影响当前会话。22 个 Caveman 技能均可由用户显式调用,元数据允许的技能也可由模型调用。
|
|
91
|
+
|
|
92
|
+
`defaultMode` 可设为 `caveman`、`ultracave`、`megacave`、`manual` 或 `off`。profile 的显式配置优先;否则依次检查 `CAVEMAN_DEFAULT_MODE`、项目配置和用户配置,均未设置时使用 `caveman`。
|
|
93
|
+
|
|
94
|
+
output 模块和 Core 启用时,原生编码规则会加入系统提示词。本地运行时启动后,还会提供任务规则、衔接压缩前后的状态,并在文件确定未变化时提示复用已有观察;只有恢复 MCP 工具可用时才会展示恢复引用。设置 `CAVEMAN_CORE=off`、使用 record 模式或 `record-only` 原生 profile 可关闭活动规则;更改后重启 DSH。`core-lean-build` profile 会额外加入 lean-build 规则。
|
|
95
|
+
|
|
96
|
+
`/caveman-stats` 报告已提交 assistant 消息中记录的用量,并在有记录时按回答模式归属输出。使用 `--all` 查看当前及存储的会话,使用 `--since 7d` 或 `--since 24h` 查看对应时间内的用量,使用 `--share` 生成所选范围的简短报告。历史总数排除分叉继承的事件,并标明不可读取的记录。没有对照数据时,节省量为未知。
|
|
97
|
+
|
|
98
|
+
### 用量分析
|
|
99
|
+
|
|
100
|
+
运行 `npx @lornatang/dsh-caveman learn --json` 生成本地报告,或加上 `--sources dsh` 专门分析 DSH 会话;添加 `--retro` 可回顾压缩效果。首次运行会下载当前平台的分析程序,并按包内 SHA-256 校验;之后复用经过验证的本地文件。`caveman-learn` 技能可协助解读结果,并在获得同意后逐项处理。
|
|
101
|
+
|
|
102
|
+
分析程序默认读取 `$DSH_HOME/sessions` 或 `~/.dsh/sessions`。如果会话持久化目录不同,可通过 `CAVEMAN_DSH_SESSION_ROOT` 指定。
|
|
103
|
+
|
|
104
|
+
### 可恢复压缩
|
|
105
|
+
|
|
106
|
+
安装签名验证的运行组件,启用压缩并启动本地 middleware:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npx @lornatang/dsh-caveman setup --install
|
|
110
|
+
npx @lornatang/dsh-caveman tools config set think.mode compress
|
|
111
|
+
npx @lornatang/dsh-caveman start
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
保持最后一条命令运行。`input` 模块启用时,插件会发现回环地址上的运行时,并在发送工具内容前验证其本地运行状态。将 `inputCompression` 设为 `false` 可以关闭;也可在 profile 中显式指定 middleware 地址:
|
|
115
|
+
|
|
116
|
+
```yaml
|
|
117
|
+
- id: caveman
|
|
118
|
+
config:
|
|
119
|
+
inputCompression: true
|
|
120
|
+
middlewareEndpoint: 'http://127.0.0.1:8787'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
成功的工具结果中,不少于 2048 个 UTF-16 代码单元的文本块可参与压缩,包括 `run_code` 的结果;其余内容保持不变。只有模型能够直接或通过程序 SDK 调用 `caveman_retrieve` 时才会提供恢复句柄。原文保留在会话日志中,模型请求准备好后会恢复到可见会话;运行时不可用时,仍可从会话恢复精确分页。
|
|
124
|
+
|
|
125
|
+
### Auto 自动选模
|
|
126
|
+
|
|
127
|
+
使用 `npx @lornatang/dsh-caveman login` 登录、启用 `routing` 模块,并按上文启动本地代理。通过 DSH 凭证服务或环境变量提供 `OPENAI_API_KEY`。
|
|
128
|
+
|
|
129
|
+
把 [examples/caveman-auto.patch.yml](examples/caveman-auto.patch.yml) 中的 `caveman-auto` provider 加入现有 `llm-pi-ai` 配置,保留其他 provider,然后在 DSH 中选择其 `caveman-auto` 模型。示例只展示 provider map 的一部分;直接用它完整替换 map 会移除其他路由。
|
|
130
|
+
|
|
131
|
+
选择 Auto 并启用 routing 后,代理会把最近两次用户请求、上一次 assistant 回复的末尾及请求信息发送给 Caveman Cloud,以选择模型。免费计划下这些内容可能被保留用于改进路由。routing 关闭时,代理回退到 OpenAI 默认模型,仍可能产生模型费用。详见[隐私说明](https://github.com/JuliusBrussee/caveman/blob/main/docs/technical/security-and-privacy.md)。
|
|
132
|
+
|
|
133
|
+
Anthropic API 请求可将 [examples/caveman-anthropic.patch.yml](examples/caveman-anthropic.patch.yml) 合并到 provider map,并选择账号可用的模型。请求与提供方缓存符合条件时,本地代理会按其策略预热缓存;预热请求计入用量。
|
|
134
|
+
|
|
135
|
+
### MCP、Blocks 和 Browse
|
|
136
|
+
|
|
137
|
+
安装 `caveman-mcp` 后,DSH MCP manager 会提供 `mcp__caveman__*` 工具:`caveman_compress`、`caveman_retrieve`、`caveman_stats`、`caveman_toon_encode` 和 `caveman_toon_decode`。服务使用本地 Caveman 恢复存储保存句柄。设置 `CAVEMAN_MCP=off` 可关闭自动注册。
|
|
138
|
+
|
|
139
|
+
安装 `cavemem` 后,MCP manager 会提供 `mcp__cavemem__*` 工具,用于记住、检索、修订、查看和删除本地事实。`cavemem_recover` 可取回检索句柄对应的完整原文,需要 DSH subprocess 和 working-directory 服务。记忆保存在本地 Caveman 目录。
|
|
140
|
+
|
|
141
|
+
安装 `caveman-blocks` 后,`bash` 和 `pwsh` 调用可收到 Blocks 建议。建议随结果提供,不会改写命令。Blocks 读取本地 `.blocks` 目录,并可能保存脱敏的脚本记录和使用数据;详见[遥测设置](https://github.com/caveman-ai/blocks/blob/main/docs/TELEMETRY.md)。
|
|
142
|
+
|
|
143
|
+
安装 `caveman-browse` 后,DSH MCP manager 会注册 `mcp__caveman_browse__browser_snapshot`、`browser_act`、`browser_eval` 和 `browser_recover`。Browse 默认启动专用的无头 Chrome;工具共享该服务的浏览器状态,可以导航并运行 JavaScript。
|
|
144
|
+
|
|
145
|
+
插件依次从 `CAVEMAN_MCP_BIN`、`CAVEMAN_BLOCKS_BIN`、`CAVEMAN_BROWSE_BIN` 或 `CAVEMEM_BIN`、`PATH`、`$CAVEMAN_HOME/bin`(默认 `~/.caveman/bin`)查找对应程序;profile 中的路径优先。模块开关在启动时读取,修改后重启 DSH。
|
|
146
|
+
|
|
147
|
+
### Cavecrew
|
|
148
|
+
|
|
149
|
+
bundle 提供 `cavecrew-investigator`、`cavecrew-builder` 和 `cavecrew-reviewer` 预设及对应的委派工具。调查和审查角色可读取、搜索文件,并通过 `cavecrew_git` 检查仓库;构建角色可读取并编辑最多两个文件路径。Git 工具提供各角色需要的只读操作。使用时 profile 需要 agent-preset registry 和进程内 subagent provider。
|
|
150
|
+
|
|
151
|
+
各角色默认继承父会话的 provider 和模型。启动 DSH 前可设置 `CAVECREW_INVESTIGATOR_MODEL`、`CAVECREW_BUILDER_MODEL` 或 `CAVECREW_REVIEWER_MODEL`,为对应角色选择该 provider 下的其他模型。
|
|
152
|
+
|
|
153
|
+
### 命令行
|
|
154
|
+
|
|
155
|
+
作为 Node 包安装时,`dsh-caveman` 把参数和退出状态转发给 `@caveman-ai/cli`。在源码目录可运行 `node scripts/caveman-cli.mjs --help`。
|
|
156
|
+
|
|
157
|
+
-----
|
|
158
|
+
|
|
159
|
+
<a id="understand-the-implementation"></a>
|
|
160
|
+
## 理解实现
|
|
161
|
+
|
|
162
|
+
<details>
|
|
163
|
+
<summary>实现内幕</summary>
|
|
164
|
+
|
|
165
|
+
| 路径 | 职责 |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `cordis.patch.yml`、`presets/cavecrew.patch.yml` | 组合宿主插件、预设与委派工具。 |
|
|
168
|
+
| `src/index.ts` | 注册技能、会话回答规则和可选集成。 |
|
|
169
|
+
| `src/skills.ts`、`src/mode.ts` | 提供技能正文并解析会话模式切换。 |
|
|
170
|
+
| `src/stats.ts` | 报告已记录的会话用量。 |
|
|
171
|
+
| `src/compression.ts` | 准备可恢复的工具结果投影,并恢复会话 surface。 |
|
|
172
|
+
| `src/blocks.ts` | 为 shell 调用提供 Blocks 建议。 |
|
|
173
|
+
| `src/cavecrew.ts` | 安装 Cavecrew 角色规则并限定工具作用域。 |
|
|
174
|
+
| `scripts/caveman-cli.mjs` | 转发命令行参数。 |
|
|
175
|
+
| `tests/` | 验证 DSH 服务、运行时集成与包安装。 |
|
|
176
|
+
|
|
177
|
+
模式切换只读取用户直接编写的消息。压缩保留原始会话事件,并在清理时恢复等待中的投影;恢复句柄按会话隔离。
|
|
178
|
+
|
|
179
|
+
</details>
|
|
180
|
+
|
|
181
|
+
-----
|
|
182
|
+
|
|
183
|
+
<a id="further-exploration"></a>
|
|
184
|
+
## 延伸阅读
|
|
185
|
+
|
|
186
|
+
- [CHANGELOG.md](CHANGELOG.md) — 包的变更。
|
|
187
|
+
- [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) — profile 和插件配置。
|
|
188
|
+
- [NOTICE](NOTICE)、[LICENSE](LICENSE) — 许可与归属。
|
|
189
|
+
|
|
190
|
+
-----
|
|
191
|
+
|
|
192
|
+
<a id="model-experience"></a>
|
|
193
|
+
## 模型体验
|
|
194
|
+
|
|
195
|
+
模型在用户轮次收到所选的回答规则。符合条件的工具结果可在模型请求中缩短,并附带 `caveman_retrieve` 句柄;用户提示词本身不会被改写。节省量和质量取决于实际任务,本集成没有对此作量化结论。
|
|
196
|
+
|
|
197
|
+
#### KV Cache 影响
|
|
198
|
+
|
|
199
|
+
切换回答风格以及替换、恢复工具结果 surface 可能改变缓存前缀。实际缓存行为取决于模型提供方。
|
|
200
|
+
|
|
201
|
+
<a id="known-limitations"></a>
|
|
202
|
+
## 已知限制
|
|
203
|
+
|
|
204
|
+
- Auto 需要配置 pi-ai provider、Caveman 代理、Cloud 登录和 OpenAI 凭证;集成测试使用本地模拟服务。
|
|
205
|
+
- Browse 需要 MCP manager、`caveman-browse` 和 Chrome;Blocks 需要 `caveman-blocks` 与本地工作区。
|
|
206
|
+
- 压缩处理工具结果中的文本块。离线恢复提供精确分页,按文本查询需要 middleware。
|
|
207
|
+
- 部分技能需要额外的 CLI、账号或 agent 配置。
|
|
208
|
+
- Cavecrew 的检查角色使用读取、搜索和只读 Git 工具;构建角色可编辑现有文件,限两个文件路径。
|
|
209
|
+
|
|
210
|
+
<a id="dev-note"></a>
|
|
211
|
+
### 开发者注记
|
|
212
|
+
|
|
213
|
+
<details>
|
|
214
|
+
<summary>维护者上下文</summary>
|
|
215
|
+
|
|
216
|
+
`npm run typecheck` 检查 TypeScript;`npm test` 构建并运行测试。将 `CAVEMAN_PROXY_BINARY`、`CAVEMAN_MCP_BINARY`、`CAVEMEM_BINARY`、`CAVEMAN_BLOCKS_BINARY`、`CAVEMAN_BROWSE_BINARY` 分别设为兼容的可执行文件,并将 `CAVEMAN_BROWSE_CHROME` 设为 Chrome,可运行运行时集成测试。将 `DSH_CAVEMAN_LEARN_BINARY` 设为已构建的分析程序,可测试会话分析。Auto 测试还需要 OpenSSL。`npm run test:dsh` 在隔离的 profile 中安装、启动并移除包;`npm pack` 通过 `prepack` 运行测试。`npm run benchmark` 使用合成输入测量技能发现和会话增量处理。
|
|
217
|
+
|
|
218
|
+
</details>
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Merge this provider into the existing llm-pi-ai providers map.
|
|
2
|
+
# Replace the model id with one available to the Anthropic credential.
|
|
3
|
+
- id: llm-pi-ai
|
|
4
|
+
config:
|
|
5
|
+
providers:
|
|
6
|
+
caveman-anthropic:
|
|
7
|
+
displayName: Caveman Anthropic
|
|
8
|
+
api: anthropic-messages
|
|
9
|
+
baseURL: 'http://127.0.0.1:8787'
|
|
10
|
+
apiKeyEnv: ANTHROPIC_API_KEY
|
|
11
|
+
cacheRetention: short
|
|
12
|
+
models:
|
|
13
|
+
- id: claude-sonnet-4-5
|
|
14
|
+
name: Claude Sonnet 4.5
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Example only: merge this provider with the existing llm-pi-ai providers.
|
|
2
|
+
# Replacing the providers map would remove the other configured routes.
|
|
3
|
+
- id: llm-pi-ai
|
|
4
|
+
config:
|
|
5
|
+
providers:
|
|
6
|
+
caveman-auto:
|
|
7
|
+
displayName: Caveman Auto
|
|
8
|
+
api: openai-completions
|
|
9
|
+
baseURL: 'http://127.0.0.1:8787/v1'
|
|
10
|
+
apiKeyEnv: OPENAI_API_KEY
|
|
11
|
+
headers:
|
|
12
|
+
x-cave-agent: dsh
|
|
13
|
+
models:
|
|
14
|
+
- id: caveman-auto
|
|
15
|
+
name: Caveman Auto
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/** Attribute only requests routed to the configured loopback proxy. */
|
|
3
|
+
export function cavemanSessionId(sessionId) {
|
|
4
|
+
return `dsh-${createHash('sha256').update(sessionId).digest('hex').slice(0, 32)}`;
|
|
5
|
+
}
|
|
6
|
+
export function cavemanRequestHeaders(endpoint, request, headers) {
|
|
7
|
+
try {
|
|
8
|
+
const target = new URL(endpoint);
|
|
9
|
+
const base = new URL(request.baseURL);
|
|
10
|
+
if (target.protocol !== 'http:' || target.username || target.password ||
|
|
11
|
+
!['127.0.0.1', 'localhost', '[::1]'].includes(target.hostname) || base.origin !== target.origin || base.username || base.password)
|
|
12
|
+
return headers;
|
|
13
|
+
if (!headers.has('x-cave-agent'))
|
|
14
|
+
headers.set('x-cave-agent', 'dsh');
|
|
15
|
+
if (request.sessionId && !headers.has('x-cave-session')) {
|
|
16
|
+
headers.set('x-cave-session', cavemanSessionId(request.sessionId));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch { /* Invalid or unrelated routes keep their existing headers. */ }
|
|
20
|
+
return headers;
|
|
21
|
+
}
|
|
22
|
+
export function registerAttribution(ctx, endpoint) {
|
|
23
|
+
ctx.on('llm-pi-ai/request-headers', (request, headers, next) => cavemanRequestHeaders(endpoint, request, next()));
|
|
24
|
+
}
|
package/lib/blocks.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
4
|
+
async function callHook(binary, input, signal) {
|
|
5
|
+
if (signal.aborted)
|
|
6
|
+
return undefined;
|
|
7
|
+
return new Promise(resolveHint => {
|
|
8
|
+
const child = spawn(binary, ['hook', '--harness', 'generic', '--phase', 'pre'], {
|
|
9
|
+
cwd: input.cwd, windowsHide: true, stdio: ['pipe', 'pipe', 'ignore'],
|
|
10
|
+
});
|
|
11
|
+
let output = '';
|
|
12
|
+
let settled = false;
|
|
13
|
+
const finish = (hint) => {
|
|
14
|
+
if (settled)
|
|
15
|
+
return;
|
|
16
|
+
settled = true;
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
signal.removeEventListener('abort', abort);
|
|
19
|
+
resolveHint(hint);
|
|
20
|
+
};
|
|
21
|
+
const abort = () => { child.kill('SIGKILL'); };
|
|
22
|
+
const timer = setTimeout(abort, 2500);
|
|
23
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
24
|
+
child.on('error', () => finish());
|
|
25
|
+
child.stdin.on('error', () => { });
|
|
26
|
+
child.stdout.on('data', chunk => {
|
|
27
|
+
output += String(chunk);
|
|
28
|
+
if (output.length > 16384)
|
|
29
|
+
abort();
|
|
30
|
+
});
|
|
31
|
+
child.once('close', code => {
|
|
32
|
+
if (code !== 0 || signal.aborted || output.length > 16384)
|
|
33
|
+
return finish();
|
|
34
|
+
try {
|
|
35
|
+
const result = JSON.parse(output);
|
|
36
|
+
if (typeof result !== 'object' || result === null || !('protocol' in result) || result.protocol !== 1 ||
|
|
37
|
+
!('action' in result) || result.action !== 'allow' || !('hint' in result) || typeof result.hint !== 'string' ||
|
|
38
|
+
!result.hint || result.hint.length > 2000 || /[\r\n]/u.test(result.hint))
|
|
39
|
+
return finish();
|
|
40
|
+
finish(result.hint);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
finish();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
child.stdin.end(JSON.stringify({ protocol: 1, phase: 'pre', harness: 'dsh', ...input, output: null }));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Invoke the generic Blocks hook before shell dispatch; never change the command. */
|
|
50
|
+
export function registerBlocks(ctx, binary) {
|
|
51
|
+
if (!isAbsolute(binary))
|
|
52
|
+
throw new Error('dsh-caveman: blocksBinary must be an absolute path');
|
|
53
|
+
ctx.on('tools/execute', async (exec, next) => {
|
|
54
|
+
if ((exec.name !== 'bash' && exec.name !== 'pwsh') || !exec.agent ||
|
|
55
|
+
typeof exec.arguments !== 'object' || exec.arguments === null || !('command' in exec.arguments) ||
|
|
56
|
+
typeof exec.arguments.command !== 'string')
|
|
57
|
+
return next();
|
|
58
|
+
let hint;
|
|
59
|
+
try {
|
|
60
|
+
const directory = ctx.get('workingDirectory');
|
|
61
|
+
const base = directory ? await directory.ensure(exec.agent, exec.signal) : exec.agent.session.header.cwd;
|
|
62
|
+
if (base && isAbsolute(base)) {
|
|
63
|
+
const requested = 'workdir' in exec.arguments && typeof exec.arguments.workdir === 'string' ? exec.arguments.workdir : '.';
|
|
64
|
+
hint = await callHook(binary, {
|
|
65
|
+
cwd: resolve(base, requested), command: exec.arguments.command,
|
|
66
|
+
session: String(exec.agent.session.id), call_id: String(exec.callId),
|
|
67
|
+
}, exec.signal);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch { /* A missing or failing hook must not change shell execution. */ }
|
|
71
|
+
const result = await next();
|
|
72
|
+
if (!hint || exec.signal.aborted)
|
|
73
|
+
return result;
|
|
74
|
+
const context = createUserMessage({
|
|
75
|
+
source: { kind: 'dsh-caveman-blocks', form: 'notice', summary: 'Blocks suggestion' },
|
|
76
|
+
content: [{ type: 'text', text: hint }],
|
|
77
|
+
});
|
|
78
|
+
return { ...result, additionalContexts: [...result.additionalContexts ?? [], context] };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
function gitArguments(role, args) {
|
|
2
|
+
const supported = role === 'investigator' ? ['grep', 'log'] : ['diff', 'log', 'show'];
|
|
3
|
+
if (!supported.includes(args.operation))
|
|
4
|
+
throw new Error(`Cavecrew ${role} cannot run this Git operation`);
|
|
5
|
+
if (args.revision !== undefined && (!/^[a-zA-Z0-9_@/.~^:+{}-]{1,256}$/u.test(args.revision) || args.revision.startsWith('-'))) {
|
|
6
|
+
throw new Error('Invalid Git revision');
|
|
7
|
+
}
|
|
8
|
+
if (args.path !== undefined && (!args.path || args.path.length > 4096 || args.path.includes('\0')))
|
|
9
|
+
throw new Error('Invalid Git path');
|
|
10
|
+
if (args.query !== undefined && (!args.query || args.query.length > 1024 || args.query.includes('\0')))
|
|
11
|
+
throw new Error('Invalid Git query');
|
|
12
|
+
const path = args.path === undefined ? [] : [args.path];
|
|
13
|
+
if (args.operation === 'grep') {
|
|
14
|
+
if (!args.query)
|
|
15
|
+
throw new Error('Git grep requires a query');
|
|
16
|
+
return ['grep', '--line-number', '--no-color', '-e', args.query, '--', ...path];
|
|
17
|
+
}
|
|
18
|
+
if (args.operation === 'log' && role === 'investigator') {
|
|
19
|
+
if (!args.query)
|
|
20
|
+
throw new Error('Investigator Git log requires a query');
|
|
21
|
+
return ['log', '--no-color', '--no-show-signature', '--max-count=20', '--oneline', `-S${args.query}`, ...(args.revision ? [args.revision] : []), '--', ...path];
|
|
22
|
+
}
|
|
23
|
+
const shared = ['--no-ext-diff', '--no-textconv', '--no-color', '--no-show-signature'];
|
|
24
|
+
if (args.operation === 'log')
|
|
25
|
+
return ['log', ...shared, '--max-count=20', '-p', ...(args.revision ? [args.revision] : []), '--', ...path];
|
|
26
|
+
if (args.operation === 'diff')
|
|
27
|
+
return ['diff', '--no-ext-diff', '--no-textconv', '--no-color', ...(args.revision ? [args.revision] : []), '--', ...path];
|
|
28
|
+
return ['show', ...shared, args.revision ?? 'HEAD', '--', ...path];
|
|
29
|
+
}
|
|
30
|
+
/** Provide the read-only Git operations used by the two inspection roles. */
|
|
31
|
+
export function registerCavecrewGit(ctx, role) {
|
|
32
|
+
const operations = role === 'investigator' ? ['grep', 'log'] : ['diff', 'log', 'show'];
|
|
33
|
+
const tool = {
|
|
34
|
+
name: 'cavecrew_git',
|
|
35
|
+
description: `Read repository history and changes without shell execution. Use instead of Bash for Git ${operations.join(', ')}.`,
|
|
36
|
+
parameters: {
|
|
37
|
+
type: 'object', additionalProperties: false, required: ['operation'],
|
|
38
|
+
properties: {
|
|
39
|
+
operation: { type: 'string', enum: operations },
|
|
40
|
+
query: { type: 'string', description: 'Search expression for grep or text to locate in investigator history.' },
|
|
41
|
+
revision: { type: 'string', description: 'Git revision or revision range.' },
|
|
42
|
+
path: { type: 'string', description: 'Optional file or directory path.' },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
timeoutMs: 15_000,
|
|
46
|
+
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
|
|
47
|
+
async execute(value, exec) {
|
|
48
|
+
if (!exec.agent)
|
|
49
|
+
throw new Error('Cavecrew Git requires an agent session');
|
|
50
|
+
const args = value;
|
|
51
|
+
const command = gitArguments(role, args);
|
|
52
|
+
const cwd = await ctx.workingDirectory.ensure(exec.agent, exec.signal);
|
|
53
|
+
const platform = (await ctx.subprocess.terminalEnvironment(exec.signal)).platform;
|
|
54
|
+
const nullDevice = platform === 'windows' ? 'NUL' : '/dev/null';
|
|
55
|
+
const env = {
|
|
56
|
+
GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_SYSTEM: nullDevice, GIT_CONFIG_GLOBAL: nullDevice,
|
|
57
|
+
GIT_CONFIG_COUNT: '0', GIT_CONFIG_PARAMETERS: undefined, GIT_DIR: undefined, GIT_COMMON_DIR: undefined,
|
|
58
|
+
GIT_WORK_TREE: undefined, GIT_INDEX_FILE: undefined, GIT_OBJECT_DIRECTORY: undefined,
|
|
59
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: undefined, GIT_EXTERNAL_DIFF: undefined, GIT_OPTIONAL_LOCKS: '0',
|
|
60
|
+
GIT_ATTR_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0', GIT_PAGER: 'cat', PAGER: 'cat',
|
|
61
|
+
};
|
|
62
|
+
const binary = await ctx.subprocess.resolveExecutable('git', {}, exec.signal);
|
|
63
|
+
const child = ctx.subprocess.spawn({
|
|
64
|
+
argv: [binary, '--no-pager', '-c', 'core.fsmonitor=false', '-c', 'core.quotePath=false', ...command],
|
|
65
|
+
cwd, env, signal: exec.signal, graceMs: 1000,
|
|
66
|
+
stdio: { stdin: 'ignore', stdout: { maxBytes: 262_144 }, stderr: { maxBytes: 4096 } },
|
|
67
|
+
});
|
|
68
|
+
const outcome = await child.done;
|
|
69
|
+
exec.signal.throwIfAborted();
|
|
70
|
+
const stdout = child.collected.stdout?.readFrom(0);
|
|
71
|
+
const stderr = child.collected.stderr?.readFrom(0);
|
|
72
|
+
if (!stdout || !stderr || outcome.signal || outcome.exitCode === null)
|
|
73
|
+
throw new Error('Git did not complete');
|
|
74
|
+
if (outcome.exitCode !== 0 && !(args.operation === 'grep' && outcome.exitCode === 1)) {
|
|
75
|
+
throw new Error(`Git ${args.operation} failed (exit ${outcome.exitCode}): ${stderr.text.slice(0, 1024)}`);
|
|
76
|
+
}
|
|
77
|
+
if (args.operation === 'grep' && outcome.exitCode === 1)
|
|
78
|
+
return 'No matches.';
|
|
79
|
+
return `${stdout.lossy ? '[Earlier output truncated]\n' : ''}${stdout.text}`;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
ctx.tools.register(tool);
|
|
83
|
+
}
|
package/lib/cavecrew.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { normalize } from 'node:path';
|
|
3
|
+
import z from '@deepseek-ai/schemastery';
|
|
4
|
+
import { registerCavecrewGit } from './cavecrew-git.js';
|
|
5
|
+
export const name = 'cavecrew';
|
|
6
|
+
export const inject = ['tools', 'systemPrompt', 'llm'];
|
|
7
|
+
export const Config = z.object({
|
|
8
|
+
role: z.union([z.const('investigator'), z.const('builder'), z.const('reviewer')]).required(),
|
|
9
|
+
});
|
|
10
|
+
/** Install one original Cavecrew persona and keep its agent's tools bounded. */
|
|
11
|
+
export async function apply(ctx, config) {
|
|
12
|
+
const original = await readFile(new URL(`../vendor/caveman/agents/cavecrew-${config.role}.md`, import.meta.url), 'utf8');
|
|
13
|
+
const frontmatter = /^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/u.exec(original);
|
|
14
|
+
if (!frontmatter)
|
|
15
|
+
throw new Error(`dsh-caveman: missing Cavecrew metadata for ${config.role}`);
|
|
16
|
+
const body = original.slice(frontmatter[0].length).trim();
|
|
17
|
+
ctx.systemPrompt.section({
|
|
18
|
+
name: 'deployment:persona-prefix', order: ctx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
|
|
19
|
+
text: body, interpolate: false,
|
|
20
|
+
});
|
|
21
|
+
ctx.systemPrompt.section({
|
|
22
|
+
name: 'deployment:persona-suffix', order: ctx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_SUFFIX'),
|
|
23
|
+
text: '', interpolate: false,
|
|
24
|
+
});
|
|
25
|
+
const allowed = config.role === 'builder' ? ['read', 'edit'] : ['read', 'glob', 'grep', 'cavecrew_git'];
|
|
26
|
+
if (config.role !== 'builder') {
|
|
27
|
+
const role = config.role;
|
|
28
|
+
ctx.inject(['subprocess', 'workingDirectory'], scoped => registerCavecrewGit(scoped, role));
|
|
29
|
+
ctx.systemPrompt.section({
|
|
30
|
+
name: 'cavecrew:git', order: ctx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
|
|
31
|
+
text: 'Use cavecrew_git for the permitted Git inspection operations. Use glob and grep for file searches; no shell is available.', interpolate: false,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const permitted = new Set(allowed);
|
|
35
|
+
const edited = new WeakMap();
|
|
36
|
+
ctx.tools.guard(exec => {
|
|
37
|
+
if (!permitted.has(exec.name))
|
|
38
|
+
return `Cavecrew ${config.role} does not permit ${exec.name}.`;
|
|
39
|
+
if (config.role !== 'builder' || exec.name !== 'edit')
|
|
40
|
+
return undefined;
|
|
41
|
+
if (!exec.agent || typeof exec.arguments !== 'object' || exec.arguments === null ||
|
|
42
|
+
!('file_path' in exec.arguments) || typeof exec.arguments.file_path !== 'string' || !exec.arguments.file_path.trim()) {
|
|
43
|
+
return 'Cavecrew builder requires an existing file path.';
|
|
44
|
+
}
|
|
45
|
+
const path = normalize(exec.arguments.file_path);
|
|
46
|
+
const paths = edited.get(exec.agent) ?? new Set();
|
|
47
|
+
if (!paths.has(path) && paths.size >= 2)
|
|
48
|
+
return 'Cavecrew builder is limited to two file paths.';
|
|
49
|
+
paths.add(path);
|
|
50
|
+
edited.set(exec.agent, paths);
|
|
51
|
+
return undefined;
|
|
52
|
+
});
|
|
53
|
+
ctx.on('agent/created', async ({ agent }) => {
|
|
54
|
+
const available = allowed.filter(tool => ctx.tools.get(tool, agent) !== undefined);
|
|
55
|
+
agent.ctx.tools.restrict({ allow: available });
|
|
56
|
+
const raw = process.env[`CAVECREW_${config.role.toUpperCase()}_MODEL`];
|
|
57
|
+
const model = raw?.trim();
|
|
58
|
+
if (model && !/[\x00-\x1f\x7f\u0085\u2028\u2029]/u.test(model)) {
|
|
59
|
+
const selected = agent.model.current();
|
|
60
|
+
if (selected) {
|
|
61
|
+
await ctx.llm.resolveModelInfo(selected.provider, model);
|
|
62
|
+
agent.model.select({ provider: selected.provider, model });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
});
|
|
67
|
+
}
|