@goodandready/dsh-context-lens 0.1.24 → 0.1.26
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 +14 -0
- package/README.md +47 -96
- package/README.ru.md +39 -113
- package/README.zh.md +42 -116
- package/lib/auto-compress.js +23 -4
- package/lib/client.js +356 -891
- package/lib/compression/log-compressor.js +53 -28
- package/lib/index.js +58 -173
- package/lib/tools.js +99 -113
- package/package.json +5 -12
- package/lib/http.js +0 -114
- package/lib/tokens/estimate.js +0 -6
- package/lib/tokens/tracker.js +0 -89
- package/lib/updater.js +0 -237
package/README.zh.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
<h3>DeepSeek Harness
|
|
5
|
+
<h3>DeepSeek Harness 语义 AST 代码骨架提取与测试日志压缩插件</h3>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/@goodandready/dsh-context-lens"><img src="https://img.shields.io/npm/v/@goodandready/dsh-context-lens.svg?style=for-the-badge&color=6366f1&labelColor=1e1b4b" alt="npm version"></a>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node-20%2B-f59e0b.svg?style=for-the-badge&labelColor=451a03" alt="Node version"></a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
<!--
|
|
14
|
+
<!-- Showcase Button -->
|
|
15
15
|
<p align="center">
|
|
16
16
|
<a href="https://goodandready.app/"><img src="https://img.shields.io/badge/作者全部项目-goodandready.app-ff4500.svg?style=for-the-badge&logo=rocket&logoColor=white&labelColor=1a1a2e" alt="作者全部项目"></a>
|
|
17
17
|
</p>
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
<table align="center">
|
|
26
26
|
<tr>
|
|
27
27
|
<td align="center">
|
|
28
|
-
⭐ <strong
|
|
28
|
+
⭐ <strong>如果您喜欢本插件,请在 GitHub 上点亮 Star</strong> —— 这能让我了解插件对您有所帮助,并激励我持续维护和演进它。
|
|
29
29
|
<br><br>
|
|
30
|
-
🐛 <strong
|
|
30
|
+
🐛 <strong>如遇问题或有功能建议</strong>,欢迎使用任意语言提交 GitHub Issue —— 您的所有实用建议都将在后续版本中得到评估和实现。
|
|
31
31
|
</td>
|
|
32
32
|
</tr>
|
|
33
33
|
</table>
|
|
@@ -36,143 +36,69 @@
|
|
|
36
36
|
|
|
37
37
|
---
|
|
38
38
|
|
|
39
|
-
## ⚡
|
|
39
|
+
## ⚡ 核心定位与职责划分
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
**`dsh-context-lens`**
|
|
44
|
-
1.
|
|
45
|
-
2.
|
|
46
|
-
3.
|
|
47
|
-
4. **会话 Token 遥测与预算守卫**:实时精确统计压缩前后节省的 Token 数量,支持自定义预算水位预警并在 DSH 界面直观显示。
|
|
41
|
+
> **说明:**
|
|
42
|
+
> 上下文预算控制、Token 计数、工具输出头尾截断 (`dsh-compaction-tool-result-pruner`) 以及大文件溢出落盘 (`dsh-spill-policy`, `dsh-token-meter`) 由 **DSH 核心引擎 (>= 0.1.5)** 原生负责。
|
|
43
|
+
> **`dsh-context-lens`** 专注于核心不具备的能力 —— **语义压缩**:
|
|
44
|
+
> 1. **AST 代码骨架生成**:提取函数签名、接口、类型定义及文档注释,去除冗长实现体(支持 9+ 种语言)。
|
|
45
|
+
> 2. **焦点路径机制**:正在编辑的文件保留全量内容,周边工作区文件生成骨架。
|
|
46
|
+
> 3. **测试与构建日志压缩**:保留失败信息、错误栈及汇总结果,剔除冗余输出。
|
|
48
47
|
|
|
49
48
|
```mermaid
|
|
50
49
|
graph LR
|
|
51
|
-
subgraph RawContext [
|
|
52
|
-
Code[📁
|
|
53
|
-
Logs[📋
|
|
50
|
+
subgraph RawContext [原始输入]
|
|
51
|
+
Code[📁 源代码] --> Lens[dsh-context-lens 语义引擎]
|
|
52
|
+
Logs[📋 测试与构建日志] --> Lens
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
subgraph
|
|
57
|
-
|
|
58
|
-
Focus
|
|
59
|
-
Focus
|
|
60
|
-
|
|
55
|
+
subgraph Lens [语义压缩处理]
|
|
56
|
+
Lens --> Focus{路径焦点判断}
|
|
57
|
+
Focus -->|聚焦文件| FullCode[保留完整代码]
|
|
58
|
+
Focus -->|周边文件| AST[AST 骨架提取]
|
|
59
|
+
Lens --> LogCompress[日志压缩: 错误/堆栈/汇总]
|
|
61
60
|
end
|
|
62
61
|
|
|
63
|
-
subgraph
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Agent -->
|
|
62
|
+
subgraph Output [优化后上下文]
|
|
63
|
+
FullCode --> Agent[🤖 Agent 上下文]
|
|
64
|
+
AST --> Agent
|
|
65
|
+
LogCompress --> Agent
|
|
66
|
+
Agent --> Core[⚙️ DSH 核心截断与溢出策略]
|
|
68
67
|
end
|
|
69
68
|
|
|
70
69
|
style RawContext fill:#1e1e2e,stroke:#89b4fa,stroke-width:2px,color:#cdd6f4
|
|
71
|
-
style
|
|
72
|
-
style
|
|
70
|
+
style Lens fill:#181825,stroke:#cba6f7,stroke-width:2px,color:#cdd6f4
|
|
71
|
+
style Output fill:#11111b,stroke:#a6e3a1,stroke-width:2px,color:#cdd6f4
|
|
73
72
|
```
|
|
74
73
|
|
|
75
74
|
---
|
|
76
75
|
|
|
77
|
-
##
|
|
78
|
-
|
|
79
|
-
### 1. 🧬 跨语言 AST 结构骨架提取器
|
|
80
|
-
* **支持语言**:TypeScript, JavaScript, Python, Go, C/C++, Rust 以及 SQL DDL。
|
|
81
|
-
* **架构完整性**:保留所有模块导入、类定义、接口、导出类型、函数签名与文档注释,剔除内部庞大实现细节。
|
|
82
|
-
* **多行签名提取**:无缝解析复杂的跨行泛型参数、长参数列表与返回类型注解。
|
|
83
|
-
* **纯正则轻量化实现**:零重型原生依赖,零二进制解析器包袱,极速跨平台运行。
|
|
84
|
-
|
|
85
|
-
### 2. 📋 启发式终端日志精简引擎
|
|
86
|
-
* **支持测试与构建工具**:Jest, Vitest, Pytest, Go test, Cargo, Webpack, Vite, TSC, Maven, Gradle。
|
|
87
|
-
* **定向错误萃取**:精准识别报错摘要、异常调用堆栈、断言匹配差异 (`Expected ... Received ...`) 与错误上下文窗口。
|
|
88
|
-
* **3 种压缩模式**:
|
|
89
|
-
- `raw`:过滤基础噪音行,保留总体执行日志。
|
|
90
|
-
- `balanced`:在压缩率与报错上下文之间保持平衡(默认推荐)。
|
|
91
|
-
- `aggressive`:严格仅保留报错行与堆栈帧。
|
|
92
|
-
* **ANSI 码清理**:预先剥离终端控制字符与彩色 ANSI 转义序列。
|
|
93
|
-
|
|
94
|
-
### 3. 🎯 会话文件焦点范围管理 (`context_lens_focus`)
|
|
95
|
-
* 允许针对当前任务设定一组活跃聚焦文件或目录。
|
|
96
|
-
* 焦点文件保持完整代码,未聚焦文件自动折叠为 AST 结构骨架。
|
|
97
|
-
* 焦点状态在会话级别严格隔离 (`sessionId`),可通过 UI 或 API 一键清除。
|
|
98
|
-
|
|
99
|
-
### 4. 📊 Token 消耗遥测与预算守卫
|
|
100
|
-
* 采用精准分词估算逻辑,实时计算压缩前后的 Token 变化。
|
|
101
|
-
* 统计累计节省 Token、压缩比率与会话预算百分比。
|
|
102
|
-
* 支持设置预警阈值 (`budgetAlertPercent`),预算临界时动态发出提示。
|
|
103
|
-
|
|
104
|
-
### 5. 🖥️ 视觉界面与双侧边栏原生集成
|
|
105
|
-
完全遵循 `.cl-*` 设计标准与 DeepSeek Harness `--dsw-alias-*` 主题变量系统:
|
|
106
|
-
* **对话顶栏微件**:挂载于 `conversation.session.header.utilities` 槽位(`order: 7`)。常态化显示效率徽章(`◐ Lens`, `◐ <N>%` 或 `⚠` 警告),点击展开包含详细数据与操作记录的交互式 Popover。
|
|
107
|
-
* **双侧边栏深度兼容**:同时支持 DSH 原生右侧边栏(`ctx.sidebarRightTabs` + `sidebar.right.pane.tab`)及旧版 `dsh-better-sidebar`,独立 ID 互不冲突。
|
|
108
|
-
* **ErrorBoundary 容灾屏障**:所有视图组件(`PluginCard`, `LensTab`, `StatusPanel`)均包裹在独立 React 错误边界内,避免页面崩溃。
|
|
109
|
-
* **一键平滑升级**:设置卡片实时检测 npm 最新版本并支持免命令行一键升级。
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## 🛠️ 智能体工具参考 (5 Tools)
|
|
114
|
-
|
|
115
|
-
所有工具严格遵循 DeepSeek Harness 核心工具契约规范,`output.render` 均返回规范的 `ContentBlock[]` 数组 (`[{ type: 'text', text: ... }]`),保障底层会话日志投影 100% 稳定可靠。
|
|
116
|
-
|
|
117
|
-
| 工具名称 | 参数 | 说明 |
|
|
118
|
-
|---|---|---|
|
|
119
|
-
| `context_lens_focus` | `paths: string[]`, `sessionId?: string` | 设定当前会话的活跃聚焦文件/路径;未聚焦代码自动折叠为 AST 骨架 |
|
|
120
|
-
| `context_lens_compress_log` | `text: string` *(或 `log`)*, `mode?: "raw"|"balanced"|"aggressive"`, `maxLines?: number`, `auto?: boolean` | 精简终端与测试输出日志,仅保留核心错误信息与报错堆栈 |
|
|
121
|
-
| `context_lens_compress_code` | `code: string`, `language?: string`, `maxDepth?: number`, `filePath?: string`, `sessionId?: string` | 将源代码提炼为紧凑的结构化 AST 骨架 |
|
|
122
|
-
| `context_lens_track` | `sessionId?: string` | 获取当前会话的累计 Token 节省统计、历史记录与预算状态 |
|
|
123
|
-
| `context_lens_reset` | `sessionId?: string` | 开启新任务时重置 Token 追踪计数器与历史记录 |
|
|
124
|
-
|
|
125
|
-
---
|
|
76
|
+
## 🛠️ Agent 工具参考 (归并至 2 个工具)
|
|
126
77
|
|
|
127
|
-
|
|
78
|
+
所有工具完全符合 DeepSeek Harness 规范,`output.render` 统一返回 `ContentBlock[]` 数组。
|
|
128
79
|
|
|
129
|
-
|
|
|
80
|
+
| 工具名 | 操作模式 | 参数 | 描述 |
|
|
130
81
|
|---|---|---|---|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
82
|
+
| `context_lens_code` | `action: "skeleton"` (默认) | `code`, `language?`, `maxDepth?`, `filePath?`, `sessionId?` | 从源代码生成 AST 骨架(若文件处于焦点内则返回完整代码) |
|
|
83
|
+
| `context_lens_code` | `action: "focus"` | `paths: string[]`, `sessionId?` | 设置当前会话的焦点路径列表 |
|
|
84
|
+
| `context_lens_code` | `action: "get_focus"` | `sessionId?` | 获取当前会话的焦点状态 |
|
|
85
|
+
| `context_lens_code` | `action: "clear_focus"` | `sessionId?` | 清空当前会话的焦点路径 |
|
|
86
|
+
| `context_lens_log` | N/A | `text` *(或 `log`)*, `mode?`, `maxLines?`, `auto?`, `command?` | 压缩测试或构建日志,保留错误、堆栈及总结信息 |
|
|
135
87
|
|
|
136
88
|
---
|
|
137
89
|
|
|
138
|
-
## ⚙️
|
|
90
|
+
## ⚙️ 配置项
|
|
139
91
|
|
|
140
|
-
|
|
92
|
+
在 DSH 设置中心 (`plugins.row.config` / `plugins.item`) 中配置:
|
|
141
93
|
|
|
142
|
-
|
|
143
|
-
dsh-context-lens:
|
|
144
|
-
compressionMode: balanced # 日志精简策略: 'raw', 'balanced', 或 'aggressive'
|
|
145
|
-
astSkeletonMaxDepth: 3 # AST 结构骨架最大解析深度 (1..10)
|
|
146
|
-
tokenSavingsTracking: true # 开启并展示实时 Token 节省监控
|
|
147
|
-
autoCompressThreshold: 4000 # 自动触发日志精简的字符长度阈值 (设为 0 禁用)
|
|
148
|
-
budgetLimit: 100000 # 单会话 Token 预算上限限额
|
|
149
|
-
budgetAlertPercent: 90 # 触发预警徽章的预算百分比水位 (50..99)
|
|
150
|
-
autoCollapse: true # 预算临界时在界面显示警告徽章
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
| 参数项 | 类型 | 默认值 | 功能说明 |
|
|
94
|
+
| 配置项 | 类型 | 默认值 | 描述 |
|
|
154
95
|
|---|---|---|---|
|
|
155
|
-
| `compressionMode` | `string` | `balanced` |
|
|
156
|
-
| `astSkeletonMaxDepth` | `number` | `3` | AST
|
|
157
|
-
| `
|
|
158
|
-
| `autoCompressThreshold` | `number` | `4000` | 超过该字符长度时自动执行日志压缩 |
|
|
159
|
-
| `budgetLimit` | `number` | `100000` | 单会话分配的最大 Token 预算上限 |
|
|
160
|
-
| `budgetAlertPercent` | `number` | `90` | 触发低预算预警的百分比阈值(50 至 99) |
|
|
161
|
-
| `autoCollapse` | `boolean` | `true` | 在设置卡片与顶栏徽章中显示预算告急提示 |
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
## 📦 快速安装
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
dsh plugin --profile web add @goodandready/dsh-context-lens
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
> [!TIP]
|
|
172
|
-
> 安装完成后,请刷新 DSH Web 界面或重启服务 (`systemctl --user restart dsh-web`) 以激活上下文压缩工具。
|
|
96
|
+
| `compressionMode` | `string` | `'balanced'` | 日志压缩模式 (`raw`, `balanced`, `aggressive`) |
|
|
97
|
+
| `astSkeletonMaxDepth` | `number` | `3` | AST 骨架最大嵌套深度 |
|
|
98
|
+
| `autoCompressThreshold` | `number` | `4000` | 自动压缩触发字符阈值(设为 0 禁用) |
|
|
173
99
|
|
|
174
100
|
---
|
|
175
101
|
|
|
176
|
-
## 📄
|
|
102
|
+
## 📄 授权协议
|
|
177
103
|
|
|
178
|
-
MIT © [GooDAnDReaDY](https://github.com/GooDAnDReaDY)
|
|
104
|
+
MIT © [GooDAnDReaDY](https://github.com/GooDAnDReaDY)
|
package/lib/auto-compress.js
CHANGED
|
@@ -14,10 +14,29 @@ export function hasAtLeastLines(text, minLines) {
|
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const TEST_BUILD_CMD_RE = /\b(test|pytest|jest|vitest|mocha|ava|tap|build|compile|tsc|cargo|mvn|gradle|make|rake|bundle\s+exec)\b/i;
|
|
18
|
+
const TEST_BUILD_SIG_RE = /(TAP version|# Subtest:|tests?\s+(passed|failed|run)|===.*FAILURES.*===|test result:|running \d+ test|BUILD (FAILED|SUCCESS)|npm ERR!|ERR!|error\[E\d+\]|compilation (error|failed)|Traceback \(most recent call last\)|AssertionError|panic:|\bFAIL\b|\bPASS\b|Ran \d+ tests?|modules transformed|built in \d+|ok\s+\d+|not ok\s+\d+)/i;
|
|
19
|
+
|
|
20
|
+
/** Check whether command or text signatures indicate test or build logs */
|
|
21
|
+
export function isTestOrBuildLog(text, command) {
|
|
22
|
+
if (command && typeof command === 'string' && TEST_BUILD_CMD_RE.test(command)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (!text || typeof text !== 'string') return false;
|
|
26
|
+
return TEST_BUILD_SIG_RE.test(text);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Decide whether auto-compress should trigger.
|
|
31
|
+
* Only triggers if the output is large enough AND matches test/build signatures.
|
|
32
|
+
* Non-test/build outputs are left to DSH core pruner/spill policy.
|
|
33
|
+
*/
|
|
34
|
+
export function shouldAutoCompress(text, threshold = 4000, command) {
|
|
19
35
|
if (!threshold || threshold <= 0) return false;
|
|
20
|
-
|
|
36
|
+
if (!text || typeof text !== 'string') return false;
|
|
37
|
+
const isLarge = text.length > threshold || hasAtLeastLines(text, 101);
|
|
38
|
+
if (!isLarge) return false;
|
|
39
|
+
return isTestOrBuildLog(text, command);
|
|
21
40
|
}
|
|
22
41
|
|
|
23
|
-
export default { shouldAutoCompress, hasAtLeastLines };
|
|
42
|
+
export default { shouldAutoCompress, isTestOrBuildLog, hasAtLeastLines };
|