@songtonyli/dsh-cli 0.1.22 → 0.1.23
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/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-base/cordis.patch.yml +11 -0
- package/node_modules/@deepseek-ai/dsh-base/package.json +1 -0
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-compaction-basic/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-compaction-basic/README.md +32 -3
- package/node_modules/@deepseek-ai/dsh-compaction-basic/README.zh.md +32 -3
- package/node_modules/@deepseek-ai/dsh-compaction-basic/lib/index.js +153 -3
- package/node_modules/@deepseek-ai/dsh-goal-round-driver/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-goal-round-driver/README.md +17 -2
- package/node_modules/@deepseek-ai/dsh-goal-round-driver/README.zh.md +17 -2
- package/node_modules/@deepseek-ai/dsh-goal-round-driver/lib/index.js +153 -2
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-cursor/lib/index.js +48 -24
- package/node_modules/@deepseek-ai/dsh-no-progress-reminder/README.i18n.yaml +6 -0
- package/node_modules/@deepseek-ai/dsh-no-progress-reminder/README.md +164 -0
- package/node_modules/@deepseek-ai/dsh-no-progress-reminder/README.zh.md +164 -0
- package/node_modules/@deepseek-ai/dsh-no-progress-reminder/lib/index.js +1516 -0
- package/node_modules/@deepseek-ai/dsh-no-progress-reminder/package.json +50 -0
- package/node_modules/@deepseek-ai/dsh-repeat-tool-reminder/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-repeat-tool-reminder/README.md +36 -11
- package/node_modules/@deepseek-ai/dsh-repeat-tool-reminder/README.zh.md +36 -11
- package/node_modules/@deepseek-ai/dsh-repeat-tool-reminder/lib/index.js +54 -7
- package/node_modules/@deepseek-ai/dsh-subagent/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-subagent/README.md +2 -2
- package/node_modules/@deepseek-ai/dsh-subagent/README.zh.md +2 -2
- package/node_modules/@deepseek-ai/dsh-subagent/lib/index.js +93 -32
- package/node_modules/@deepseek-ai/dsh-subagent/lib/types/continuation-messages.js +20 -7
- package/node_modules/@deepseek-ai/dsh-subagent/lib/types/diagnostic.js +39 -0
- package/node_modules/@deepseek-ai/dsh-subagent/lib/types/lifecycle.js +36 -4
- package/node_modules/@deepseek-ai/dsh-subagent/lib/types/out-of-process.js +1 -22
- package/node_modules/@deepseek-ai/dsh-tool-skill/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-skill/README.md +21 -4
- package/node_modules/@deepseek-ai/dsh-tool-skill/README.zh.md +21 -4
- package/node_modules/@deepseek-ai/dsh-tool-skill/lib/index.js +194 -16
- package/node_modules/@deepseek-ai/dsh-tool-todo/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-todo/README.md +3 -3
- package/node_modules/@deepseek-ai/dsh-tool-todo/README.zh.md +3 -3
- package/node_modules/@deepseek-ai/dsh-tool-todo/lib/index.js +32 -6
- package/node_modules/@deepseek-ai/dsh-tool-todo/lib/types/index.js +31 -5
- package/package.json +3 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-no-progress-reminder",
|
|
3
|
+
"description": "No-progress guard plugin: advisory reminders when an agent spends turns on a goal without mutating the tree",
|
|
4
|
+
"version": "0.1.6-alpha.2",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/guard/no-progress-reminder"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./src/*": "./src/*",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/index.js",
|
|
26
|
+
"lib/types/**/*.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@deepseek-ai/schemastery": "3.18.2"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@deepseek-ai/dsh-agent": "0.1.6-alpha.2",
|
|
34
|
+
"@deepseek-ai/dsh-tools": "0.1.6-alpha.2",
|
|
35
|
+
"@deepseek-ai/cordis": "4.0.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@deepseek-ai/dsh-agent": "0.1.6-alpha.2",
|
|
39
|
+
"@deepseek-ai/dsh-agent-loop": "0.1.6-alpha.2",
|
|
40
|
+
"@deepseek-ai/dsh-goal": "0.1.6-alpha.2",
|
|
41
|
+
"@deepseek-ai/dsh-llm": "0.1.6-alpha.2",
|
|
42
|
+
"@deepseek-ai/dsh-session": "0.1.6-alpha.2",
|
|
43
|
+
"@deepseek-ai/dsh-session-projection": "0.1.6-alpha.2",
|
|
44
|
+
"@deepseek-ai/dsh-system-prompt": "0.1.6-alpha.2",
|
|
45
|
+
"@deepseek-ai/dsh-tools": "0.1.6-alpha.2",
|
|
46
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
47
|
+
"@deepseek-ai/cordis-plugin-include": "1.0.7",
|
|
48
|
+
"@deepseek-ai/cordis-plugin-loader": "1.0.3"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/guard/repeat-tool-reminder/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 266df5df091ae2dfa59d08f6f30a910e32bd9c75
|
|
6
|
+
README.zh.md: 9d06433068ff470ab49fc1ebdf1fedc5bb01a40f
|
|
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
|
|
|
9
9
|
|
|
10
10
|
## Summary
|
|
11
11
|
|
|
12
|
-
This package helps a model escape loops in which it calls the same tool with identical arguments without making progress. At configured repeat counts, it asks the model to inspect the previous result and change approach or finish.
|
|
12
|
+
This package helps a model escape loops in which it calls the same tool with identical arguments without making progress. At configured repeat counts, it asks the model to inspect the previous result and change approach or finish. Reminders are advisory and never delay a call; an optional `blockThreshold` denies a further identical tracked call so the tool body does not run. Repeats are tracked separately for each agent and cleared by a new user message. The `dsh` base bundle enables the package with reminders at 3, 5, and 8 repeats.
|
|
13
13
|
|
|
14
14
|
## Table of Contents
|
|
15
15
|
|
|
@@ -29,7 +29,7 @@ Mount this plugin when the model should catch itself looping on identical tool c
|
|
|
29
29
|
|
|
30
30
|
### When to choose it
|
|
31
31
|
|
|
32
|
-
Choose it when the model works autonomously for long stretches and a stuck loop is the failure you want to break with advice
|
|
32
|
+
Choose it when the model works autonomously for long stretches and a stuck loop is the failure you want to break with advice, or with a deny once `blockThreshold` is set. Leave `blockThreshold` unset when identical repeats are legitimate and must run — a reminder is only a small extra message after the repeated call — and avoid the package when near-identical variants must be caught, because only exact repeats (same tool, same arguments regardless of property order) are detected.
|
|
33
33
|
|
|
34
34
|
### Setting the thresholds and scope
|
|
35
35
|
|
|
@@ -42,6 +42,8 @@ When you want to change when reminders fire or which tools they cover, mount the
|
|
|
42
42
|
include: [] # track every tool; list patterns to track only some
|
|
43
43
|
exclude: [todo_write] # never track these tools
|
|
44
44
|
argumentsPreviewChars: 500 # cap on arguments shown in the detailed reminder
|
|
45
|
+
blockThreshold: 12 # deny at this consecutive count; omit to stay advisory-only
|
|
46
|
+
blockProviders: [cursor] # routes that honor blockThreshold; default is the Cursor subscription route
|
|
45
47
|
```
|
|
46
48
|
|
|
47
49
|
| Field | Default | Meaning |
|
|
@@ -50,12 +52,14 @@ When you want to change when reminders fire or which tools they cover, mount the
|
|
|
50
52
|
| `include` | `[]` | Only these tools are tracked; empty means every tool |
|
|
51
53
|
| `exclude` | `[]` | These tools are never tracked; calls to them neither count nor reset |
|
|
52
54
|
| `argumentsPreviewChars` | `500` | How many characters of the repeated arguments the detailed reminder shows |
|
|
55
|
+
| `blockThreshold` | unset | Consecutive-repeat count at which an identical tracked call is denied before execute; omit to stay advisory-only |
|
|
56
|
+
| `blockProviders` | `['cursor']` | Provider routes that honor `blockThreshold`; empty denies no route. Reminders still run for every provider |
|
|
53
57
|
|
|
54
|
-
Invalid configuration fails at startup with a clear error — an empty `thresholds` list, a repeat count below 2,
|
|
58
|
+
Invalid configuration fails at startup with a clear error — an empty `thresholds` list, a repeat count below 2, a duplicate, or an invalid `blockThreshold` — never a silent change of behavior. The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-repeat-tool-reminder) documents every accepted value.
|
|
55
59
|
|
|
56
60
|
### What you get
|
|
57
61
|
|
|
58
|
-
With the defaults, a model that repeats the same call with identical arguments receives a short reminder on the third repeat — to analyze the previous result before calling again — and detailed reminders on the fifth and eighth, naming the tool and the repeated arguments so it can decide whether to change approach, gather more evidence, or finish. A new user message clears the count, so a fresh instruction is never treated as a loop. Reminders appear in the conversation after the repeated call's result, attributed to the plugin, so the model reads them like any other message.
|
|
62
|
+
With the defaults, a model that repeats the same call with identical arguments receives a short reminder on the third repeat — to analyze the previous result before calling again — and detailed reminders on the fifth and eighth, naming the tool and the repeated arguments so it can decide whether to change approach, gather more evidence, or finish. When `blockThreshold` is set, the call that would reach that count is denied before the tool body runs if the agent's current or selected provider is in `blockProviders` (default the Cursor subscription route `cursor`); the model sees the deny reason and the chain still counts the denied attempt. A DeepSeek or pi-ai catalog route is not denied. A new user message clears the count, so a fresh instruction is never treated as a loop. Reminders appear in the conversation after the repeated call's result, attributed to the plugin, so the model reads them like any other message.
|
|
59
63
|
|
|
60
64
|
-----
|
|
61
65
|
|
|
@@ -71,17 +75,18 @@ This section explains how the guard detects repeats and delivers reminders, and
|
|
|
71
75
|
|
|
72
76
|
The guard is built on four commitments:
|
|
73
77
|
|
|
74
|
-
- **Advisory
|
|
75
|
-
- **Count in post-execute.** Detection runs on `tools/post-execute`, which also fires for denied calls;
|
|
78
|
+
- **Advisory by default; optional deny.** Reminders enrich post-execute decisions with model context and never rewrite a call. When `blockThreshold` is set, `tools/pre-execute` denies an identical tracked call; `PostToolDecision` blocking stays a later listener's job.
|
|
79
|
+
- **Count in post-execute.** Detection still runs on `tools/post-execute`, which also fires for denied calls; pre-execute only peeks at the last key and count so a deny does not double-increment.
|
|
76
80
|
- **Exact-match canonicalization.** Arguments reach the guard as the loop's `JSON.parse` output (or its raw-string fallback), so JSON's value domain is the whole input domain and a deep key-sort plus `JSON.stringify` is a complete, deterministic identity — no bigint, cycle, or `undefined` handling exists because no input path can produce them.
|
|
77
|
-
- **Fail loud at load.** `thresholds` and `
|
|
81
|
+
- **Fail loud at load.** `thresholds`, `argumentsPreviewChars`, and `blockThreshold` validate in `apply` and throw, never falling back to defaults.
|
|
78
82
|
|
|
79
83
|
### Detection: the repeat chain
|
|
80
84
|
|
|
81
85
|
Each agent's chain is keyed by `(tool name, canonical arguments)` — two calls with the same tool and canonically identical arguments (property order ignored) count as consecutive, and a different tracked call resets the count to 1. The chain lives in a `WeakMap<Agent, Chain>`.
|
|
82
86
|
|
|
83
87
|
- **Untracked calls are transparent to the chain.** A call excluded by `include`/`exclude` neither increments nor resets the counter, so `grep X → todo_write → grep X` still counts as two consecutive `grep X` when `todo_write` is excluded — bookkeeping tools interleaved into a loop do not launder it.
|
|
84
|
-
- **Denied calls count.** Detection sits on `tools/post-execute`, which also runs for calls a `tools/pre-execute` listener denied; a model hammering a denied call is exactly the loop worth breaking.
|
|
88
|
+
- **Denied calls count.** Detection sits on `tools/post-execute`, which also runs for calls a `tools/pre-execute` listener denied — including this guard's own `blockThreshold` deny; a model hammering a denied call is exactly the loop worth breaking.
|
|
89
|
+
- **Blocking peeks, then post-execute counts.** When `blockThreshold` is set, `tools/pre-execute` denies if a matching chain's `count + 1` would reach that value; it does not increment. The denied attempt still flows through post-execute, which advances the count and may also attach a reminder.
|
|
85
90
|
- **Calls without an agent are ignored.** A direct `ctx.tools.execute()` caller has no model to remind and no live agent object to key on.
|
|
86
91
|
- **Per-agent keying, reset on user prompts.** One agent's repetition never trips another's reminder; a user prompt (`agent/pre-step`) deletes the submitting agent's chain, and object lifetime bounds the weak entry without a disposal listener.
|
|
87
92
|
- **In-memory only.** A session resumed from persistence starts with a fresh chain — the guard is a heuristic nudge, not a logged invariant, so reminders after a resume are the accepted cost.
|
|
@@ -95,7 +100,7 @@ Reminders ride the post-execute decision's `additionalContexts` (source `{kind:
|
|
|
95
100
|
| File | Role |
|
|
96
101
|
|---|---|
|
|
97
102
|
| [`src/index.ts`](src/index.ts) | Plugin entry: `Config` schema, fail-loud validation, chain listeners |
|
|
98
|
-
| — | No runtime invariant companion is published; the repeat chain is private to
|
|
103
|
+
| — | No runtime invariant companion is published; the repeat chain is private to this plugin's listeners and exposes no package-owned event or snapshot that an independent companion can observe. |
|
|
99
104
|
|
|
100
105
|
</details>
|
|
101
106
|
|
|
@@ -159,6 +164,26 @@ Each reminder is retained history; `argumentsPreviewChars` bounds its data-depen
|
|
|
159
164
|
|
|
160
165
|
Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
|
|
161
166
|
|
|
167
|
+
### Blocked identical-call result
|
|
168
|
+
|
|
169
|
+
#### What the model sees
|
|
170
|
+
|
|
171
|
+
When `blockThreshold` is set and the next identical tracked call would reach that count, the call is denied before the tool body runs. The deny reason starts with the sentence below; a second line names the tool.
|
|
172
|
+
|
|
173
|
+
##### Identical-call deny reason
|
|
174
|
+
|
|
175
|
+
```markdown
|
|
176
|
+
identical to your previous call; no state changed
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Token effect
|
|
180
|
+
|
|
181
|
+
The denied call still produces a tool-result error in history. Zero extra tokens when `blockThreshold` is unset or not yet reached.
|
|
182
|
+
|
|
183
|
+
#### KV Cache effect
|
|
184
|
+
|
|
185
|
+
Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
|
|
186
|
+
|
|
162
187
|
## Known Limitations and Deferred Work
|
|
163
188
|
|
|
164
189
|
<a id="known-limitations-and-deferred-work"></a>
|
|
@@ -168,9 +193,9 @@ These limits define when the guard is a poor fit. They are current package const
|
|
|
168
193
|
|
|
169
194
|
- **Exact-match detection only** — canonicalization is a deep key-sort, so near-identical variants (a tweaked path, extra whitespace inside a value) evade the chain; fuzzy matching is rejected pending evidence of need.
|
|
170
195
|
- **Compaction does not reset chains** — a chain spanning a compaction checkpoint keeps counting.
|
|
171
|
-
- **
|
|
196
|
+
- **Polling tools** — identical repeats that must run (status polls) should stay in `exclude` or leave `blockThreshold` unset; a set threshold denies those repeats once the count is reached.
|
|
172
197
|
- **No subagent chain-sharing** — chains stay isolated per agent; a parent and its subagent repeating the same call never combine.
|
|
173
|
-
- **Legitimate idempotent polling still draws nudges** past the thresholds — the
|
|
198
|
+
- **Legitimate idempotent polling still draws nudges** past the reminder thresholds — `thresholds`/`exclude` remain the reminder valves; `blockThreshold` is the deny valve.
|
|
174
199
|
- **Past the highest threshold a chain goes silent** — reminders fire only at exact configured counts, never beyond them.
|
|
175
200
|
|
|
176
201
|
<a id="dev-note"></a>
|
|
@@ -9,7 +9,7 @@ kind: "package-reference"
|
|
|
9
9
|
|
|
10
10
|
## 概述
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
本包帮助模型跳出以相同参数反复调用同一工具却没有进展的循环。达到配置的重复次数时,它会要求模型检查上一次结果并改变方法或结束任务。提醒只是建议,绝不会延迟调用;可选的 `blockThreshold` 会拒绝下一次相同的受跟踪调用,使工具本体不运行。每个 agent 的重复分别跟踪,新的用户消息会清除计数。`dsh` 基础组合包默认启用本包,并在重复 3、5、8 次时提醒。
|
|
13
13
|
|
|
14
14
|
## 目录
|
|
15
15
|
|
|
@@ -29,7 +29,7 @@ kind: "package-reference"
|
|
|
29
29
|
|
|
30
30
|
### 何时选择
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
当模型长时间自主工作、且卡住的循环是你想用建议、或在设置 `blockThreshold` 后用拒绝来打破的失败模式时,选择它。当相同的重复是合理且必须运行时,不要设置 `blockThreshold`——提醒只是重复调用之后的一条小消息——以及必须捕获近似变体时(因为只有精确重复——同一工具、同一参数且与属性顺序无关——才会被检测到),避免使用本包。
|
|
33
33
|
|
|
34
34
|
### 设置阈值与范围
|
|
35
35
|
|
|
@@ -42,6 +42,8 @@ kind: "package-reference"
|
|
|
42
42
|
include: [] # track every tool; list patterns to track only some
|
|
43
43
|
exclude: [todo_write] # never track these tools
|
|
44
44
|
argumentsPreviewChars: 500 # cap on arguments shown in the detailed reminder
|
|
45
|
+
blockThreshold: 12 # deny at this consecutive count; omit to stay advisory-only
|
|
46
|
+
blockProviders: [cursor] # routes that honor blockThreshold; default is the Cursor subscription route
|
|
45
47
|
```
|
|
46
48
|
|
|
47
49
|
| 字段 | 默认值 | 含义 |
|
|
@@ -50,12 +52,14 @@ kind: "package-reference"
|
|
|
50
52
|
| `include` | `[]` | 只跟踪这些工具;空表示所有工具 |
|
|
51
53
|
| `exclude` | `[]` | 绝不跟踪这些工具;对它们的调用既不计数也不重置 |
|
|
52
54
|
| `argumentsPreviewChars` | `500` | 详细提醒中显示多少字符的重复参数 |
|
|
55
|
+
| `blockThreshold` | 未设置 | 在该连续重复次数拒绝相同的受跟踪调用(执行前);省略则保持仅建议 |
|
|
56
|
+
| `blockProviders` | `['cursor']` | 遵守 `blockThreshold` 的提供方路由;空列表不拒绝任何路由。提醒仍对每个提供方生效 |
|
|
53
57
|
|
|
54
|
-
无效配置会在启动时以清晰错误失败——空的 `thresholds` 列表、小于 2
|
|
58
|
+
无效配置会在启动时以清晰错误失败——空的 `thresholds` 列表、小于 2 的重复次数、重复值或无效的 `blockThreshold`——绝不会静默改变行为。生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-repeat-tool-reminder)记录每个受支持的值。
|
|
55
59
|
|
|
56
60
|
### 你会得到什么
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
按默认值,以相同参数重复同一调用的模型会在第三次重复时收到简短提醒——先分析上一次结果再调用——并在第五次和第八次收到详细提醒,列出工具与重复参数,使其决定改变方法、收集更多证据还是结束任务。设置 `blockThreshold` 后,若智能体当前或所选提供方在 `blockProviders` 中(默认为 Cursor 订阅路由 `cursor`),将达到该次数的调用会在工具本体运行前被拒绝;模型看到拒绝原因,且链仍会计入这次被拒绝的尝试。DeepSeek 或 pi-ai 目录路由不会被拒绝。新的用户消息会清零计数,因此全新指令绝不会被当作循环。提醒出现在重复调用的结果之后、归属于插件,模型像阅读任何其他消息一样阅读它。
|
|
59
63
|
|
|
60
64
|
-----
|
|
61
65
|
|
|
@@ -71,17 +75,18 @@ kind: "package-reference"
|
|
|
71
75
|
|
|
72
76
|
guard 建立在四项承诺之上:
|
|
73
77
|
|
|
74
|
-
-
|
|
75
|
-
- **在 post-execute 中计数。**
|
|
78
|
+
- **默认仅建议;可选拒绝。** 提醒用模型上下文丰富 post-execute 决策,且从不改写调用。设置 `blockThreshold` 后,`tools/pre-execute` 会拒绝相同的受跟踪调用;`PostToolDecision` 阻止仍是后续监听器的事。
|
|
79
|
+
- **在 post-execute 中计数。** 检测仍运行在 `tools/post-execute` 上,被拒绝的调用同样会经过它;pre-execute 只查看上一次的键与计数,因此拒绝不会重复递增。
|
|
76
80
|
- **精确匹配规范化。** 参数以循环的 `JSON.parse` 输出(或畸形参数 JSON 的原始字符串回退)到达 guard,因此 JSON 的值域就是全部输入域,深度键排序加 `JSON.stringify` 是完整、确定性的同一性判定——不存在 bigint、循环引用或 `undefined` 处理,因为没有输入路径能产生它们。
|
|
77
|
-
- **加载时快速失败。** `thresholds` 与 `
|
|
81
|
+
- **加载时快速失败。** `thresholds`、`argumentsPreviewChars` 与 `blockThreshold` 在 `apply` 中校验并抛出错误,绝不回退到默认值。
|
|
78
82
|
|
|
79
83
|
### 检测:重复链
|
|
80
84
|
|
|
81
85
|
每个 agent 的链以「`(tool name, canonical arguments)`」为键——同一工具且规范化后参数相同(忽略属性顺序)的两次调用计为连续,换成另一条受跟踪调用则把计数重置为 1。链保存在 `WeakMap<Agent, Chain>` 中。
|
|
82
86
|
|
|
83
87
|
- **不受跟踪的调用对链透明。** 被 `include`/`exclude` 排除的调用既不递增也不重置计数器,因此 `grep X → todo_write → grep X` 在 `todo_write` 被排除时仍算作连续两次 `grep X`——穿插进循环的记录类工具不能掩盖循环。
|
|
84
|
-
- **被拒绝的调用也计数。** 检测位于 `tools/post-execute`,被 `tools/pre-execute`
|
|
88
|
+
- **被拒绝的调用也计数。** 检测位于 `tools/post-execute`,被 `tools/pre-execute` 监听器拒绝的调用同样会经过它——包括本 guard 自己的 `blockThreshold` 拒绝;模型反复尝试被拒绝的调用,恰恰是需要打破的循环。
|
|
89
|
+
- **阻止先查看,再在 post-execute 中计数。** 设置 `blockThreshold` 后,若匹配链的 `count + 1` 将达到该值,`tools/pre-execute` 会拒绝且不递增。被拒绝的尝试仍会经过 post-execute,后者推进计数,并可能同时附上提醒。
|
|
85
90
|
- **忽略没有 agent 的调用。** 直接调用 `ctx.tools.execute()` 的调用方没有需要提醒的模型,也没有可作为键的活跃 agent 对象。
|
|
86
91
|
- **按 agent 分键,用户提示词时重置。** 一个 agent 的重复绝不会触发另一个 agent 的提醒;用户提示词(`agent/pre-step`)会删除提交该提示词的 agent 链,对象生命周期限制弱引用条目的寿命,无需 dispose(资源释放)监听器。
|
|
87
92
|
- **仅驻留内存。** 从持久化恢复的会话以全新链开始——guard 是启发式提醒,而非记录在案的不变量,因此恢复后的提醒延后是可接受的代价。
|
|
@@ -95,7 +100,7 @@ guard 建立在四项承诺之上:
|
|
|
95
100
|
| 文件 | 职责 |
|
|
96
101
|
|---|---|
|
|
97
102
|
| [`src/index.ts`](src/index.ts) | 插件入口:`Config` schema、快速失败校验、链监听器 |
|
|
98
|
-
| — |
|
|
103
|
+
| — | 不发布运行时不变式配套组件;重复链私有于本插件的监听器,且不公开任何可供独立配套组件观察的包自有事件或快照。 |
|
|
99
104
|
|
|
100
105
|
</details>
|
|
101
106
|
|
|
@@ -159,6 +164,26 @@ The repeated calls are not making progress. Do not call this tool with these exa
|
|
|
159
164
|
|
|
160
165
|
仅追加;新出现的内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
|
|
161
166
|
|
|
167
|
+
### 被阻止的相同调用结果
|
|
168
|
+
|
|
169
|
+
#### 模型看到什么
|
|
170
|
+
|
|
171
|
+
设置 `blockThreshold` 且下一次相同的受跟踪调用将达到该次数时,调用会在工具本体运行前被拒绝。拒绝原因以下面的句子开头;第二行会给出工具名。
|
|
172
|
+
|
|
173
|
+
##### 相同调用的拒绝原因
|
|
174
|
+
|
|
175
|
+
```markdown
|
|
176
|
+
identical to your previous call; no state changed
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Token 影响
|
|
180
|
+
|
|
181
|
+
被拒绝的调用仍会在历史中产生一条 tool-result 错误。未设置或尚未达到 `blockThreshold` 时,不增加额外 token。
|
|
182
|
+
|
|
183
|
+
#### KV Cache 影响
|
|
184
|
+
|
|
185
|
+
仅追加;新出现的内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
|
|
186
|
+
|
|
162
187
|
## 已知限制与延期工作
|
|
163
188
|
|
|
164
189
|
<a id="known-limitations-and-deferred-work"></a>
|
|
@@ -168,9 +193,9 @@ The repeated calls are not making progress. Do not call this tool with these exa
|
|
|
168
193
|
|
|
169
194
|
- **仅精确匹配检测**——规范化是深度键排序,因此近似变体(稍作修改的路径、值内多余的空白)会绕过链;在没有需求证据前,不采用模糊匹配。
|
|
170
195
|
- **压缩(compaction)不会重置链**——跨越压缩检查点的链会继续计数。
|
|
171
|
-
-
|
|
196
|
+
- **轮询工具**——必须重复相同调用的工具(状态轮询)应留在 `exclude` 中,或不要设置 `blockThreshold`;一旦设置该阈值,达到次数后就会拒绝这些重复。
|
|
172
197
|
- **subagent 之间不共享链**——链始终按 agent 隔离;父 agent 与其 subagent 重复相同调用也绝不合并。
|
|
173
|
-
-
|
|
198
|
+
- **合理的幂等轮询超过提醒阈值后仍会收到提醒**——`thresholds`/`exclude` 仍是提醒阀门;`blockThreshold` 是拒绝阀门。
|
|
174
199
|
- **超过最高阈值后链不再提醒**——提醒只在精确达到所配置的次数时触发,超过后不会继续发送。
|
|
175
200
|
|
|
176
201
|
<a id="dev-note"></a>
|
|
@@ -1356,10 +1356,10 @@ function adapterFailureChunk(error, signal) {
|
|
|
1356
1356
|
//#endregion
|
|
1357
1357
|
//#region lib/types/index.js
|
|
1358
1358
|
/**
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
* repeat-tool-reminder Agent Note.
|
|
1359
|
+
* Per-agent repeat-call detector. It enriches post-execute decisions with
|
|
1360
|
+
* logged model context and, when `blockThreshold` is set, denies an identical
|
|
1361
|
+
* tracked call before execute. Configuration and chain semantics live in the
|
|
1362
|
+
* package README; rationale lives in the repeat-tool-reminder Agent Note.
|
|
1363
1363
|
* @module @deepseek-ai/dsh-repeat-tool-reminder
|
|
1364
1364
|
*/
|
|
1365
1365
|
const name = "repeat-tool-reminder";
|
|
@@ -1371,7 +1371,9 @@ const Config = z.object({
|
|
|
1371
1371
|
]),
|
|
1372
1372
|
include: z.array(z.string()).default([]),
|
|
1373
1373
|
exclude: z.array(z.string()).default([]),
|
|
1374
|
-
argumentsPreviewChars: z.number().default(500)
|
|
1374
|
+
argumentsPreviewChars: z.number().default(500),
|
|
1375
|
+
blockThreshold: z.number(),
|
|
1376
|
+
blockProviders: z.array(z.string()).default(["cursor"])
|
|
1375
1377
|
});
|
|
1376
1378
|
/**
|
|
1377
1379
|
* The `{kind:'plugin'}` source stamped on every reminder this guard injects —
|
|
@@ -1387,6 +1389,8 @@ const PLUGIN_SOURCE = {
|
|
|
1387
1389
|
* count, so a custom first threshold keeps the gentle-then-detailed escalation.
|
|
1388
1390
|
*/
|
|
1389
1391
|
const GENTLE_REMINDER = "You are repeating the exact same tool call with identical arguments. Carefully analyze the previous result before calling again: if the task is not complete, try a different approach or different arguments instead of repeating the call.";
|
|
1392
|
+
/** First line of the pre-execute deny reason; the tools runtime prefixes `Error: `. */
|
|
1393
|
+
const IDENTICAL_DENY_LINE = "identical to your previous call; no state changed";
|
|
1390
1394
|
/** The detailed later-threshold reminder naming the tool, the run length, and the canonical arguments. */
|
|
1391
1395
|
function detailedReminder(toolName, count, canonicalArguments) {
|
|
1392
1396
|
return `Repeated tool call detected:
|
|
@@ -1414,6 +1418,14 @@ function sortJsonValue(value) {
|
|
|
1414
1418
|
function canonicalize(argumentsValue) {
|
|
1415
1419
|
return JSON.stringify(sortJsonValue(argumentsValue));
|
|
1416
1420
|
}
|
|
1421
|
+
/** Chain identity for one call: tool name plus canonical arguments. */
|
|
1422
|
+
function identityKey(name, argumentsValue) {
|
|
1423
|
+
return JSON.stringify([name, canonicalize(argumentsValue)]);
|
|
1424
|
+
}
|
|
1425
|
+
/** Model-visible deny reason: stable first line, then the tool name. */
|
|
1426
|
+
function identicalDenyReason(toolName) {
|
|
1427
|
+
return `${IDENTICAL_DENY_LINE}\ntool: ${toolName}`;
|
|
1428
|
+
}
|
|
1417
1429
|
/** Compile one `*`-wildcard pattern to an anchored RegExp (every other regex metacharacter is matched literally). */
|
|
1418
1430
|
function wildcardToRegExp(pattern) {
|
|
1419
1431
|
const escaped = pattern.replace(/[|\\{}()[\]^$+?.]/g, String.raw`\$&`);
|
|
@@ -1440,6 +1452,19 @@ function validateThresholds(values) {
|
|
|
1440
1452
|
return [...values].sort((a, b) => a - b);
|
|
1441
1453
|
}
|
|
1442
1454
|
/**
|
|
1455
|
+
* Validate optional `blockThreshold` with the same fail-loud integer rule as
|
|
1456
|
+
* `thresholds`. Omitted keeps advisory-only behavior.
|
|
1457
|
+
*/
|
|
1458
|
+
function validateBlockThreshold(value) {
|
|
1459
|
+
if (value === void 0) return void 0;
|
|
1460
|
+
if (!Number.isInteger(value) || value < 2) throw new Error(`repeat-tool-reminder: invalid blockThreshold ${value} — must be an integer >= 2`);
|
|
1461
|
+
return value;
|
|
1462
|
+
}
|
|
1463
|
+
function validateBlockProviders(values) {
|
|
1464
|
+
for (const value of values) if (value.length === 0) throw new Error("repeat-tool-reminder: blockProviders entries must be non-empty");
|
|
1465
|
+
return values;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1443
1468
|
* Prepend the guard's reminder while preserving every downstream context's
|
|
1444
1469
|
* source and metadata.
|
|
1445
1470
|
*/
|
|
@@ -1449,7 +1474,7 @@ function prependContext(ours, theirs) {
|
|
|
1449
1474
|
/**
|
|
1450
1475
|
* Install the guard's listeners.
|
|
1451
1476
|
* @param ctx - plugin context; listeners are scoped to it and disposed with it.
|
|
1452
|
-
* @param config - validated {@link Config}; `thresholds`
|
|
1477
|
+
* @param config - validated {@link Config}; `thresholds` and `blockThreshold` are re-checked fail-loud here.
|
|
1453
1478
|
*/
|
|
1454
1479
|
function apply(ctx, config) {
|
|
1455
1480
|
const thresholds = validateThresholds(config.thresholds);
|
|
@@ -1457,6 +1482,8 @@ function apply(ctx, config) {
|
|
|
1457
1482
|
const includePatterns = config.include.map(wildcardToRegExp);
|
|
1458
1483
|
const excludePatterns = config.exclude.map(wildcardToRegExp);
|
|
1459
1484
|
const argumentsPreviewChars = config.argumentsPreviewChars;
|
|
1485
|
+
const blockThreshold = validateBlockThreshold(config.blockThreshold);
|
|
1486
|
+
const blockProviders = validateBlockProviders(config.blockProviders);
|
|
1460
1487
|
if (!Number.isInteger(argumentsPreviewChars) || argumentsPreviewChars < 1) throw new Error(`repeat-tool-reminder: invalid argumentsPreviewChars ${argumentsPreviewChars} — must be an integer >= 1`);
|
|
1461
1488
|
const chains = /* @__PURE__ */ new WeakMap();
|
|
1462
1489
|
/** Whether a tool participates in the chain (untracked calls are transparent: they neither count nor reset). */
|
|
@@ -1476,7 +1503,7 @@ function apply(ctx, config) {
|
|
|
1476
1503
|
if (!exec.agent) return void 0;
|
|
1477
1504
|
if (!tracked(exec.name)) return void 0;
|
|
1478
1505
|
const canonical = canonicalize(exec.arguments);
|
|
1479
|
-
const key =
|
|
1506
|
+
const key = identityKey(exec.name, exec.arguments);
|
|
1480
1507
|
const chain = chains.get(exec.agent);
|
|
1481
1508
|
const count = chain !== void 0 && chain.key === key ? chain.count + 1 : 1;
|
|
1482
1509
|
chains.set(exec.agent, {
|
|
@@ -1496,6 +1523,26 @@ function apply(ctx, config) {
|
|
|
1496
1523
|
}
|
|
1497
1524
|
});
|
|
1498
1525
|
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Peek at the last tracked key+count without advancing. Post-execute still
|
|
1528
|
+
* increments, including after this deny, so a reminder threshold can fire
|
|
1529
|
+
* on the same attempt.
|
|
1530
|
+
*/
|
|
1531
|
+
function wouldBlock(exec) {
|
|
1532
|
+
if (blockThreshold === void 0 || !exec.agent || !tracked(exec.name)) return false;
|
|
1533
|
+
const provider = exec.agent.session.requestHeader()?.config.provider ?? exec.agent.options.provider;
|
|
1534
|
+
if (provider === void 0 || !blockProviders.includes(provider)) return false;
|
|
1535
|
+
const chain = chains.get(exec.agent);
|
|
1536
|
+
if (chain === void 0) return false;
|
|
1537
|
+
return chain.key === identityKey(exec.name, exec.arguments) && chain.count + 1 >= blockThreshold;
|
|
1538
|
+
}
|
|
1539
|
+
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
1540
|
+
if (!wouldBlock(exec)) return next();
|
|
1541
|
+
return {
|
|
1542
|
+
kind: "deny",
|
|
1543
|
+
reason: identicalDenyReason(exec.name)
|
|
1544
|
+
};
|
|
1545
|
+
});
|
|
1499
1546
|
ctx.on("tools/post-execute", async (exec, _result, next) => {
|
|
1500
1547
|
const reminder = observe(exec);
|
|
1501
1548
|
const downstream = await next();
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/subagent/subagent/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 8098623ab93ac15a00bfba43326822e0fc8a13f0
|
|
6
|
+
README.zh.md: 8d055298658640502a8323679d2be04a7bfd95f9
|
|
@@ -143,11 +143,11 @@ Read these pages when the package-level contract is not enough. They move from t
|
|
|
143
143
|
|
|
144
144
|
#### What the model sees
|
|
145
145
|
|
|
146
|
-
One user-role parent message opening with the outcome — `Background subagent <child-id> finished and will do no further work unless you send it more.`, or the matching line for a child that was stopped, ran out of room, declined, or failed — followed by `Its closing message:` and the nonempty text blocks from the child's final assistant output, preserving their content and order. Reasoning and other nontext blocks are excluded; when no nonempty text remains, the notice says `It left no closing message.` This runtime-owned notice is distinct from model-authored parent/child messages, which use `sendMessage()` and `AgentMessageSource`; delegation schemas and model controls belong to the Consumer packages.
|
|
146
|
+
One user-role parent message opening with the outcome — `Background subagent <child-id> finished and will do no further work unless you send it more.`, or the matching line for a child that was stopped, ran out of room, declined, or failed — followed by `Its closing message:` and the nonempty text blocks from the child's final assistant output, preserving their content and order. A failed child opens with `Background subagent <child-id> failed before it finished: <reason>` when a sanitized reason exists, otherwise `Background subagent <child-id> failed before it finished.`, and after the closing-message block adds `Do the work directly or retry.` The reason is the child's diagnostic when present, else the teardown failure, limited to 4096 UTF-8 bytes and without tool inputs, file contents, credentials, or raw protocol payloads. Reasoning and other nontext blocks are excluded; when no nonempty text remains, the notice says `It left no closing message.` This runtime-owned notice is distinct from model-authored parent/child messages, which use `sendMessage()` and `AgentMessageSource`; delegation schemas and model controls belong to the Consumer packages.
|
|
147
147
|
|
|
148
148
|
#### Token effect
|
|
149
149
|
|
|
150
|
-
One notice per settled Activation in the parent's request, sized by the child's final text. A child that sends its own message and then settles costs the parent both.
|
|
150
|
+
One notice per settled Activation in the parent's request, sized by the child's final text and, on failure, a sanitized reason of at most 4096 UTF-8 bytes. A child that sends its own message and then settles costs the parent both.
|
|
151
151
|
|
|
152
152
|
#### KV Cache effect
|
|
153
153
|
|
|
@@ -143,11 +143,11 @@ kind: "package-reference"
|
|
|
143
143
|
|
|
144
144
|
#### 模型看到什么
|
|
145
145
|
|
|
146
|
-
一条用户角色的父级消息,开头是结果本身——`Background subagent <child-id> finished and will do no further work unless you send it more.`,或子级被停止、耗尽额度、拒绝任务或失败时的对应句子——随后是 `Its closing message:` 与子级最终 assistant
|
|
146
|
+
一条用户角色的父级消息,开头是结果本身——`Background subagent <child-id> finished and will do no further work unless you send it more.`,或子级被停止、耗尽额度、拒绝任务或失败时的对应句子——随后是 `Its closing message:` 与子级最终 assistant 输出中的非空文本块,保留原始内容与顺序。子级失败时,若有经过净化的原因,开头为 `Background subagent <child-id> failed before it finished: <reason>`,否则为 `Background subagent <child-id> failed before it finished.`,并在收尾消息块之后加上 `Do the work directly or retry.`。原因优先使用子级已记录的 diagnostic,否则使用 teardown 失败;长度不超过 4096 个 UTF-8 字节,且不含工具入参、文件内容、凭据或原始协议载荷。推理与其他非文本块不会进入通知;若没有剩余的非空文本,通知会写明 `It left no closing message.`。这条由运行时生成的通知与模型编写的父子消息相互独立;后者使用 `sendMessage()` 与 `AgentMessageSource`。委派 schema 与模型控制工具归消费方包所有。
|
|
147
147
|
|
|
148
148
|
#### Token 影响
|
|
149
149
|
|
|
150
|
-
父级请求中,每个已结算的 Activation
|
|
150
|
+
父级请求中,每个已结算的 Activation 一条通知,长度取决于子级的最终文本,失败时再加上至多 4096 个 UTF-8 字节的净化原因。如果子级先发送自己的消息再结算,父级请求会同时承担两者。
|
|
151
151
|
|
|
152
152
|
#### KV Cache 影响
|
|
153
153
|
|