@deepseek-ai/dsh-repeat-tool-reminder 0.2.3-alpha.1 → 0.2.3-alpha.3
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.i18n.yaml +8 -8
- package/README.md +6 -2
- package/README.zh.md +6 -2
- package/lib/index.js +179 -159
- package/lib/types/index.d.ts +8 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/package.json +15 -15
- package/src/index.ts +18 -5
package/README.i18n.yaml
CHANGED
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
en: c6b47c1f0034c021
|
|
22
22
|
zh: 5a2097425754d8b0
|
|
23
23
|
/deepseek-ai-dsh-repeat-tool-reminder/use-this-package/setting-the-thresholds-and-scope:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: 7607aba97759fabd
|
|
25
|
+
zh: 890f055255699beb
|
|
26
26
|
/deepseek-ai-dsh-repeat-tool-reminder/use-this-package/what-you-get:
|
|
27
|
-
en:
|
|
28
|
-
zh:
|
|
27
|
+
en: fbae1e5d16a701ec
|
|
28
|
+
zh: 3a82a7b204cd503e
|
|
29
29
|
/deepseek-ai-dsh-repeat-tool-reminder/understand-the-implementation:
|
|
30
30
|
en: dd6d7a1571af5a9a
|
|
31
31
|
zh: eba00095dfc1c92a
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
en: 7bca56e3cba01338
|
|
34
34
|
zh: 530fda764d226f39
|
|
35
35
|
/deepseek-ai-dsh-repeat-tool-reminder/understand-the-implementation/detection-the-repeat-chain:
|
|
36
|
-
en:
|
|
37
|
-
zh:
|
|
36
|
+
en: fb766150c393345e
|
|
37
|
+
zh: 973e5ba9d49fbfc9
|
|
38
38
|
/deepseek-ai-dsh-repeat-tool-reminder/understand-the-implementation/reminder-delivery:
|
|
39
39
|
en: e11bb31ae82954cd
|
|
40
40
|
zh: 14f9c32ca93e7096
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
en: f5d5f97a153f7c70
|
|
79
79
|
zh: 51155536aab03002
|
|
80
80
|
/deepseek-ai-dsh-repeat-tool-reminder/known-limitations-and-deferred-work:
|
|
81
|
-
en:
|
|
82
|
-
zh:
|
|
81
|
+
en: 7c2b26d3e9e22ba4
|
|
82
|
+
zh: 0c540e6f07cc1c41
|
|
83
83
|
/deepseek-ai-dsh-repeat-tool-reminder/known-limitations-and-deferred-work/dev-note:
|
|
84
84
|
en: ef308dcf213685c7
|
|
85
85
|
zh: 5830b6bbeea9863f
|
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ When you want to change when reminders fire or which tools they cover, mount the
|
|
|
41
41
|
thresholds: [3, 5, 8] # remind at 3, 5, and 8 consecutive repeats
|
|
42
42
|
include: [] # track every tool; list patterns to track only some
|
|
43
43
|
exclude: [todo_write] # never track these tools
|
|
44
|
+
restartCountAfter: [wait_agent] # these calls restart the count without counting
|
|
44
45
|
argumentsPreviewChars: 500 # cap on arguments shown in the detailed reminder
|
|
45
46
|
```
|
|
46
47
|
|
|
@@ -49,13 +50,14 @@ When you want to change when reminders fire or which tools they cover, mount the
|
|
|
49
50
|
| `thresholds` | `[3, 5, 8]` | Repeat counts that trigger a reminder |
|
|
50
51
|
| `include` | `[]` | Only these tools are tracked; empty means every tool |
|
|
51
52
|
| `exclude` | `[]` | These tools are never tracked; calls to them neither count nor reset |
|
|
53
|
+
| `restartCountAfter` | `[]` | Successful calls to these tools end the count without counting, while failed calls count as usual; the `dsh` base bundle lists `wait_agent`, `job_output`, and `ask_user_question`, so waiting for a subagent, a background job, or a user answer draws no reminder |
|
|
52
54
|
| `argumentsPreviewChars` | `500` | How many characters of the repeated arguments the detailed reminder shows |
|
|
53
55
|
|
|
54
56
|
Invalid configuration fails at startup with a clear error — an empty `thresholds` list, a repeat count below 2, or a duplicate — never a silent change of behavior. The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-repeat-tool-reminder) documents every accepted value.
|
|
55
57
|
|
|
56
58
|
### What you get
|
|
57
59
|
|
|
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. Only model-direct calls count, including `run_code`; calls inside a PTC program neither increment nor reset the count. 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.
|
|
60
|
+
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. Only model-direct calls count, including `run_code`; calls inside a PTC program neither increment nor reset the count. A new user message clears the count, so a fresh instruction is never treated as a loop. The `dsh` base bundle also lists `wait_agent`, `job_output`, and `ask_user_question` in `restartCountAfter`, so waiting repeatedly for a subagent, a background job, or a user answer draws no reminder, and lists `todo_write`, `team_task_update`, and `update_goal` in `exclude`, so these updates between repeated calls do not hide 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
61
|
|
|
60
62
|
-----
|
|
61
63
|
|
|
@@ -80,6 +82,7 @@ The guard is built on four commitments:
|
|
|
80
82
|
|
|
81
83
|
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
84
|
|
|
85
|
+
- **`restartCountAfter` calls end the chain.** A successful call matching `restartCountAfter` deletes the agent's chain before `include`/`exclude` apply and never counts, so `list_agents → wait_agent → list_agents` starts a new count after each wait. A failed or denied call goes through the normal chain, so hammering an unknown job id still draws reminders.
|
|
83
86
|
- **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
87
|
- **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.
|
|
85
88
|
- **Nested calls and calls without an agent are ignored.** Calls with `exec.parent` neither increment nor reset the chain; calls without an agent have no model to remind or live agent object to key on.
|
|
@@ -169,7 +172,8 @@ These limits define when the guard is a poor fit. They are current package const
|
|
|
169
172
|
- **Compaction does not reset chains** — a chain spanning a compaction checkpoint keeps counting.
|
|
170
173
|
- **Advisory only** — escalating to a blocking form at a high threshold is not implemented, though `PostToolDecision` already supports blocking.
|
|
171
174
|
- **No subagent chain-sharing** — chains stay isolated per agent; a parent and its subagent repeating the same call never combine.
|
|
172
|
-
- **Legitimate idempotent polling still draws nudges** past the thresholds — the pressure valves are the `thresholds`/`exclude` config.
|
|
175
|
+
- **Legitimate idempotent polling still draws nudges** past the thresholds unless its tool is listed in `restartCountAfter` — the pressure valves are the `thresholds`/`exclude`/`restartCountAfter` config.
|
|
176
|
+
- **`restartCountAfter` matches tool names only** — listing `job_output` also stops reminders for repeated non-blocking reads (`wait` unset), which the jobs prompt already discourages.
|
|
173
177
|
- **Past the highest threshold a chain goes silent** — reminders fire only at exact configured counts, never beyond them.
|
|
174
178
|
|
|
175
179
|
<a id="dev-note"></a>
|
package/README.zh.md
CHANGED
|
@@ -41,6 +41,7 @@ kind: "package-reference"
|
|
|
41
41
|
thresholds: [3, 5, 8] # remind at 3, 5, and 8 consecutive repeats
|
|
42
42
|
include: [] # track every tool; list patterns to track only some
|
|
43
43
|
exclude: [todo_write] # never track these tools
|
|
44
|
+
restartCountAfter: [wait_agent] # these calls restart the count without counting
|
|
44
45
|
argumentsPreviewChars: 500 # cap on arguments shown in the detailed reminder
|
|
45
46
|
```
|
|
46
47
|
|
|
@@ -49,13 +50,14 @@ kind: "package-reference"
|
|
|
49
50
|
| `thresholds` | `[3, 5, 8]` | 触发提醒的重复次数 |
|
|
50
51
|
| `include` | `[]` | 只跟踪这些工具;空表示所有工具 |
|
|
51
52
|
| `exclude` | `[]` | 绝不跟踪这些工具;对它们的调用既不计数也不重置 |
|
|
53
|
+
| `restartCountAfter` | `[]` | 对这些工具的成功调用会结束当前计数且自身不计数,失败的调用照常计数;`dsh` 基础组合包列出 `wait_agent`、`job_output` 和 `ask_user_question`,因此等待 subagent、后台任务或用户回答不会收到提醒 |
|
|
52
54
|
| `argumentsPreviewChars` | `500` | 详细提醒中显示多少字符的重复参数 |
|
|
53
55
|
|
|
54
56
|
无效配置会在启动时以清晰错误失败——空的 `thresholds` 列表、小于 2 的重复次数或重复值——绝不会静默改变行为。生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-repeat-tool-reminder)记录每个受支持的值。
|
|
55
57
|
|
|
56
58
|
### 你会得到什么
|
|
57
59
|
|
|
58
|
-
按默认值,以相同参数重复同一调用的模型会在第三次重复时收到简短提醒——先分析上一次结果再调用——并在第五次和第八次收到详细提醒,列出工具与重复参数,使其决定改变方法、收集更多证据还是结束任务。只统计模型直接发起的调用,包括 `run_code`;PTC
|
|
60
|
+
按默认值,以相同参数重复同一调用的模型会在第三次重复时收到简短提醒——先分析上一次结果再调用——并在第五次和第八次收到详细提醒,列出工具与重复参数,使其决定改变方法、收集更多证据还是结束任务。只统计模型直接发起的调用,包括 `run_code`;PTC 程序内部的调用既不递增也不重置计数。新的用户消息会清零计数,因此全新指令绝不会被当作循环。`dsh` 基础组合包还把 `wait_agent`、`job_output` 和 `ask_user_question` 列入 `restartCountAfter`,因此反复等待 subagent、后台任务或用户回答不会收到提醒;并把 `todo_write`、`team_task_update` 和 `update_goal` 列入 `exclude`,因此穿插在重复调用之间的这些更新不会掩盖循环。提醒出现在重复调用的结果之后、归属于插件,模型像阅读任何其他消息一样阅读它。
|
|
59
61
|
|
|
60
62
|
-----
|
|
61
63
|
|
|
@@ -80,6 +82,7 @@ guard 建立在四项承诺之上:
|
|
|
80
82
|
|
|
81
83
|
每个 agent 的链以「`(tool name, canonical arguments)`」为键——同一工具且规范化后参数相同(忽略属性顺序)的两次调用计为连续,换成另一条受跟踪调用则把计数重置为 1。链保存在 `WeakMap<Agent, Chain>` 中。
|
|
82
84
|
|
|
85
|
+
- **`restartCountAfter` 调用会结束链。** 匹配 `restartCountAfter` 的成功调用会在 `include`/`exclude` 生效前删除该 agent 的链,且自身从不计数,因此 `list_agents → wait_agent → list_agents` 在每次等待后重新计数。失败或被拒绝的调用照常进入链,因此反复读取不存在的 job id 仍会收到提醒。
|
|
83
86
|
- **不受跟踪的调用对链透明。** 被 `include`/`exclude` 排除的调用既不递增也不重置计数器,因此 `grep X → todo_write → grep X` 在 `todo_write` 被排除时仍算作连续两次 `grep X`——穿插进循环的记录类工具不能掩盖循环。
|
|
84
87
|
- **被拒绝的调用也计数。** 检测位于 `tools/post-execute`,被 `tools/pre-execute` 监听器拒绝的调用同样会经过它;模型反复尝试被拒绝的调用,恰恰是需要打破的循环。
|
|
85
88
|
- **忽略内部子调用和没有 agent 的调用。** 带有 `exec.parent` 的调用既不递增也不重置链;没有 agent 的调用没有需要提醒的模型,也没有可作为键的活跃 agent 对象。
|
|
@@ -169,7 +172,8 @@ The repeated calls are not making progress. Do not call this tool with these exa
|
|
|
169
172
|
- **压缩(compaction)不会重置链**——跨越压缩检查点的链会继续计数。
|
|
170
173
|
- **仅提供建议**——尚未实现高阈值时升级为阻止形式,但 `PostToolDecision` 已支持阻止。
|
|
171
174
|
- **subagent 之间不共享链**——链始终按 agent 隔离;父 agent 与其 subagent 重复相同调用也绝不合并。
|
|
172
|
-
-
|
|
175
|
+
- **合理的幂等轮询超过阈值后仍会收到提醒**,除非其工具列在 `restartCountAfter` 中——可通过 `thresholds`/`exclude`/`restartCountAfter` 配置释放压力。
|
|
176
|
+
- **`restartCountAfter` 只匹配工具名**——列出 `job_output` 也会停止对重复非阻塞读取(未设置 `wait`)的提醒,jobs 提示词已劝阻这种用法。
|
|
173
177
|
- **超过最高阈值后链不再提醒**——提醒只在精确达到所配置的次数时触发,超过后不会继续发送。
|
|
174
178
|
|
|
175
179
|
<a id="dev-note"></a>
|
package/lib/index.js
CHANGED
|
@@ -52,162 +52,6 @@ var RemoteError = class extends HarnessError {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
//#endregion
|
|
55
|
-
//#region ../../typert/protocol/src/index.ts
|
|
56
|
-
/**
|
|
57
|
-
* Remote decorators and explicit Gateway bindings backed by versioned
|
|
58
|
-
* descriptors carried on decorated class prototypes. Strict reflection
|
|
59
|
-
* remains a Typert compiler responsibility.
|
|
60
|
-
* @module @deepseek-ai/dsh-typert-protocol
|
|
61
|
-
*/
|
|
62
|
-
const TYPERT_REMOTE_SEGMENT_PATTERN = /^[A-Za-z0-9_$.-]+$/;
|
|
63
|
-
/**
|
|
64
|
-
* Test one generated Remote name against the Connection endpoint grammar.
|
|
65
|
-
* @param value - namespace, method, lookup, or Context segment.
|
|
66
|
-
* @returns whether the value can cross the shared RPC carrier unchanged.
|
|
67
|
-
*/
|
|
68
|
-
function isTypertRemoteSegment(value) {
|
|
69
|
-
return value !== "." && value !== ".." && TYPERT_REMOTE_SEGMENT_PATTERN.test(value);
|
|
70
|
-
}
|
|
71
|
-
const REMOTE_METHOD_DESCRIPTOR = "@deepseek-ai/dsh-typert-protocol/remote-methods";
|
|
72
|
-
/**
|
|
73
|
-
* Bind one visible Service field to a Cordis key and Remote namespace. A
|
|
74
|
-
* service that owns a Cordis Context also gives its tree `ctx.invocation`,
|
|
75
|
-
* `undefined` outside a Remote call, so no `TypertRemoteService` is needed for
|
|
76
|
-
* a Host composition to read it.
|
|
77
|
-
* @param service - owning Service instance, normally `this`.
|
|
78
|
-
* @param serviceKey - exact Cordis service key.
|
|
79
|
-
* @param options - optional wire namespace.
|
|
80
|
-
* @returns a frozen, inspectable binding with no compiler-injected metadata.
|
|
81
|
-
*/
|
|
82
|
-
function bindTypertRemote(service, serviceKey, options = {}) {
|
|
83
|
-
validateName("service key", serviceKey);
|
|
84
|
-
const namespace = options.namespace ?? serviceKey;
|
|
85
|
-
validateName("namespace", namespace);
|
|
86
|
-
const ctx = Reflect.get(service, "ctx");
|
|
87
|
-
if (Context.is(ctx)) provideInvocationAccessor(ctx);
|
|
88
|
-
return Object.freeze({
|
|
89
|
-
service,
|
|
90
|
-
serviceKey,
|
|
91
|
-
namespace
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/** Cordis Service base that exposes its registered name through Typert Gateway. */
|
|
95
|
-
var TypertRemoteService = class extends Service {
|
|
96
|
-
/** Visible binding consumed by the Gateway's source-mode discovery. */
|
|
97
|
-
typertRemote;
|
|
98
|
-
/**
|
|
99
|
-
* Register the Service and bind the same key to Typert Gateway.
|
|
100
|
-
* @param ctx - owning Cordis Context.
|
|
101
|
-
* @param serviceKey - exact Cordis service key and default wire namespace.
|
|
102
|
-
* @param options - optional wire namespace.
|
|
103
|
-
*/
|
|
104
|
-
constructor(ctx, serviceKey, options = {}) {
|
|
105
|
-
super(ctx, serviceKey);
|
|
106
|
-
this.typertRemote = bindTypertRemote(this, this.name, options);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Make `ctx.invocation` read as `undefined` outside a Remote call instead of the
|
|
111
|
-
* reflect service's "cannot get property" error; a call-derived Context shadows
|
|
112
|
-
* the accessor with its own property. The first Remote Service constructed in a
|
|
113
|
-
* tree registers it on the root, where it outlives any one Service.
|
|
114
|
-
*/
|
|
115
|
-
function provideInvocationAccessor(ctx) {
|
|
116
|
-
if (Object.hasOwn(ctx[Context.root].reflect.props, "invocation")) return;
|
|
117
|
-
ctx[Context.root].accessor("invocation", { get: () => void 0 });
|
|
118
|
-
}
|
|
119
|
-
function Remote(methodExportOrOptions, context) {
|
|
120
|
-
if (typeof methodExportOrOptions === "string") {
|
|
121
|
-
validateName("Remote export name", methodExportOrOptions);
|
|
122
|
-
return remoteDecorator({ kind: "direct" }, { exportName: methodExportOrOptions });
|
|
123
|
-
}
|
|
124
|
-
if (typeof methodExportOrOptions === "object") return remoteDecorator({ kind: "direct" }, markerOptions(methodExportOrOptions, REMOTE_OPTION_KEYS, "Remote options require name, mode: \"stream\", or resources"));
|
|
125
|
-
if (context === void 0) throw new TypeError("typert-protocol: Remote decorator context is missing");
|
|
126
|
-
addMarkerInitializer(context, { kind: "direct" });
|
|
127
|
-
}
|
|
128
|
-
const REMOTE_OPTION_KEYS = new Set([
|
|
129
|
-
"name",
|
|
130
|
-
"mode",
|
|
131
|
-
"resources"
|
|
132
|
-
]);
|
|
133
|
-
/** Validate one decorator options object against its accepted keys and select the marker fields. */
|
|
134
|
-
function markerOptions(options, accepted, requirement) {
|
|
135
|
-
const keys = Reflect.ownKeys(options);
|
|
136
|
-
if (keys.length === 0 || keys.some((key) => typeof key !== "string" || !accepted.has(key)) || Object.hasOwn(options, "mode") && options.mode !== "stream") throw new TypeError(`typert-protocol: ${requirement}`);
|
|
137
|
-
const { mode, name, resources } = options;
|
|
138
|
-
if (name !== void 0) validateName("Remote export name", name);
|
|
139
|
-
return {
|
|
140
|
-
...mode === void 0 ? {} : { mode },
|
|
141
|
-
...name === void 0 ? {} : { exportName: name },
|
|
142
|
-
...resources === void 0 ? {} : { resources: resourceReaders(resources) }
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/** Freeze declared readers into the marker record; a misdeclared reader fails at decoration. */
|
|
146
|
-
function resourceReaders(resources) {
|
|
147
|
-
const readers = {};
|
|
148
|
-
for (const [kind, reader] of Object.entries(resources)) {
|
|
149
|
-
if (typeof reader !== "function") throw new TypeError(`typert-protocol: Remote resource reader "${kind}" must be a function`);
|
|
150
|
-
readers[kind] = reader;
|
|
151
|
-
}
|
|
152
|
-
if (Object.keys(readers).length === 0) throw new TypeError("typert-protocol: Remote resources require at least one reader");
|
|
153
|
-
return Object.freeze(readers);
|
|
154
|
-
}
|
|
155
|
-
function remoteDecorator(invocation, options = {}) {
|
|
156
|
-
return function(_method, context) {
|
|
157
|
-
addMarkerInitializer(context, invocation, options);
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function readRemoteMethodDescriptor(prototype) {
|
|
161
|
-
const property = Object.getOwnPropertyDescriptor(prototype, REMOTE_METHOD_DESCRIPTOR);
|
|
162
|
-
if (property === void 0) return void 0;
|
|
163
|
-
const descriptor = property.value;
|
|
164
|
-
if (descriptor === null || typeof descriptor !== "object") throw new TypeError("typert-protocol: Remote method descriptor must be an object");
|
|
165
|
-
const version = Reflect.get(descriptor, "version");
|
|
166
|
-
if (version !== 1) throw new TypeError(`typert-protocol: unsupported Remote method descriptor version ${String(version)}`);
|
|
167
|
-
const methods = Reflect.get(descriptor, "methods");
|
|
168
|
-
if (!Array.isArray(methods)) throw new TypeError("typert-protocol: Remote method descriptor methods must be an array");
|
|
169
|
-
return descriptor;
|
|
170
|
-
}
|
|
171
|
-
function addMarkerInitializer(context, invocation, options = {}) {
|
|
172
|
-
if (context.private || context.static || typeof context.name !== "string") throw new TypeError("typert-protocol: Remote decorators require a public instance method with a string name");
|
|
173
|
-
const method = context.name;
|
|
174
|
-
context.addInitializer(function() {
|
|
175
|
-
const prototype = Object.getPrototypeOf(this);
|
|
176
|
-
if (prototype === null) throw new TypeError(`typert-protocol: cannot mark Remote method "${method}" on an object without a prototype`);
|
|
177
|
-
mark(prototype, method, invocation, options);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
function mark(prototype, method, invocation, { mode, exportName, resources }) {
|
|
181
|
-
const descriptor = readRemoteMethodDescriptor(prototype);
|
|
182
|
-
const marker = Object.freeze({
|
|
183
|
-
method,
|
|
184
|
-
...exportName === void 0 || exportName === method ? {} : { exportName },
|
|
185
|
-
...mode === void 0 ? {} : { mode },
|
|
186
|
-
invocation: Object.freeze(invocation),
|
|
187
|
-
...resources === void 0 ? {} : { resources }
|
|
188
|
-
});
|
|
189
|
-
const current = descriptor?.methods.find((candidate) => candidate.method === method);
|
|
190
|
-
if (current !== void 0) {
|
|
191
|
-
if (current.exportName === marker.exportName && current.mode === marker.mode && current.resources === marker.resources && sameInvocation(current.invocation, invocation)) return;
|
|
192
|
-
throw new Error(`typert-protocol: Remote method "${method}" has conflicting invocation markers`);
|
|
193
|
-
}
|
|
194
|
-
Object.defineProperty(prototype, REMOTE_METHOD_DESCRIPTOR, {
|
|
195
|
-
configurable: true,
|
|
196
|
-
value: Object.freeze({
|
|
197
|
-
version: 1,
|
|
198
|
-
methods: Object.freeze([...descriptor?.methods ?? [], marker])
|
|
199
|
-
})
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function sameInvocation(left, right) {
|
|
203
|
-
if (left.kind === "direct") return right.kind === "direct";
|
|
204
|
-
if (right.kind === "direct") return false;
|
|
205
|
-
return left.context === right.context;
|
|
206
|
-
}
|
|
207
|
-
function validateName(subject, value) {
|
|
208
|
-
if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
|
|
209
|
-
}
|
|
210
|
-
//#endregion
|
|
211
55
|
//#region ../../util/values/src/partial-json.ts
|
|
212
56
|
/**
|
|
213
57
|
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
@@ -886,6 +730,162 @@ function deepFreeze(value) {
|
|
|
886
730
|
return value;
|
|
887
731
|
}
|
|
888
732
|
//#endregion
|
|
733
|
+
//#region ../../typert/protocol/src/index.ts
|
|
734
|
+
/**
|
|
735
|
+
* Remote decorators and explicit Gateway bindings backed by versioned
|
|
736
|
+
* descriptors carried on decorated class prototypes. Strict reflection
|
|
737
|
+
* remains a Typert compiler responsibility.
|
|
738
|
+
* @module @deepseek-ai/dsh-typert-protocol
|
|
739
|
+
*/
|
|
740
|
+
const TYPERT_REMOTE_SEGMENT_PATTERN = /^[A-Za-z0-9_$.-]+$/;
|
|
741
|
+
/**
|
|
742
|
+
* Test one generated Remote name against the Connection endpoint grammar.
|
|
743
|
+
* @param value - namespace, method, lookup, or Context segment.
|
|
744
|
+
* @returns whether the value can cross the shared RPC carrier unchanged.
|
|
745
|
+
*/
|
|
746
|
+
function isTypertRemoteSegment(value) {
|
|
747
|
+
return value !== "." && value !== ".." && TYPERT_REMOTE_SEGMENT_PATTERN.test(value);
|
|
748
|
+
}
|
|
749
|
+
const REMOTE_METHOD_DESCRIPTOR = "@deepseek-ai/dsh-typert-protocol/remote-methods";
|
|
750
|
+
/**
|
|
751
|
+
* Bind one visible Service field to a Cordis key and Remote namespace. A
|
|
752
|
+
* service that owns a Cordis Context also gives its tree `ctx.invocation`,
|
|
753
|
+
* `undefined` outside a Remote call, so no `TypertRemoteService` is needed for
|
|
754
|
+
* a Host composition to read it.
|
|
755
|
+
* @param service - owning Service instance, normally `this`.
|
|
756
|
+
* @param serviceKey - exact Cordis service key.
|
|
757
|
+
* @param options - optional wire namespace.
|
|
758
|
+
* @returns a frozen, inspectable binding with no compiler-injected metadata.
|
|
759
|
+
*/
|
|
760
|
+
function bindTypertRemote(service, serviceKey, options = {}) {
|
|
761
|
+
validateName("service key", serviceKey);
|
|
762
|
+
const namespace = options.namespace ?? serviceKey;
|
|
763
|
+
validateName("namespace", namespace);
|
|
764
|
+
const ctx = Reflect.get(service, "ctx");
|
|
765
|
+
if (Context.is(ctx)) provideInvocationAccessor(ctx);
|
|
766
|
+
return Object.freeze({
|
|
767
|
+
service,
|
|
768
|
+
serviceKey,
|
|
769
|
+
namespace
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
/** Cordis Service base that exposes its registered name through Typert Gateway. */
|
|
773
|
+
var TypertRemoteService = class extends Service {
|
|
774
|
+
/** Visible binding consumed by the Gateway's source-mode discovery. */
|
|
775
|
+
typertRemote;
|
|
776
|
+
/**
|
|
777
|
+
* Register the Service and bind the same key to Typert Gateway.
|
|
778
|
+
* @param ctx - owning Cordis Context.
|
|
779
|
+
* @param serviceKey - exact Cordis service key and default wire namespace.
|
|
780
|
+
* @param options - optional wire namespace.
|
|
781
|
+
*/
|
|
782
|
+
constructor(ctx, serviceKey, options = {}) {
|
|
783
|
+
super(ctx, serviceKey);
|
|
784
|
+
this.typertRemote = bindTypertRemote(this, this.name, options);
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
/**
|
|
788
|
+
* Make `ctx.invocation` read as `undefined` outside a Remote call instead of the
|
|
789
|
+
* reflect service's "cannot get property" error; a call-derived Context shadows
|
|
790
|
+
* the accessor with its own property. The first Remote Service constructed in a
|
|
791
|
+
* tree registers it on the root, where it outlives any one Service.
|
|
792
|
+
*/
|
|
793
|
+
function provideInvocationAccessor(ctx) {
|
|
794
|
+
if (Object.hasOwn(ctx[Context.root].reflect.props, "invocation")) return;
|
|
795
|
+
ctx[Context.root].accessor("invocation", { get: () => void 0 });
|
|
796
|
+
}
|
|
797
|
+
function Remote(methodExportOrOptions, context) {
|
|
798
|
+
if (typeof methodExportOrOptions === "string") {
|
|
799
|
+
validateName("Remote export name", methodExportOrOptions);
|
|
800
|
+
return remoteDecorator({ kind: "direct" }, { exportName: methodExportOrOptions });
|
|
801
|
+
}
|
|
802
|
+
if (typeof methodExportOrOptions === "object") return remoteDecorator({ kind: "direct" }, markerOptions(methodExportOrOptions, REMOTE_OPTION_KEYS, "Remote options require name, mode: \"stream\", or resources"));
|
|
803
|
+
if (context === void 0) throw new TypeError("typert-protocol: Remote decorator context is missing");
|
|
804
|
+
addMarkerInitializer(context, { kind: "direct" });
|
|
805
|
+
}
|
|
806
|
+
const REMOTE_OPTION_KEYS = new Set([
|
|
807
|
+
"name",
|
|
808
|
+
"mode",
|
|
809
|
+
"resources"
|
|
810
|
+
]);
|
|
811
|
+
/** Validate one decorator options object against its accepted keys and select the marker fields. */
|
|
812
|
+
function markerOptions(options, accepted, requirement) {
|
|
813
|
+
const keys = Reflect.ownKeys(options);
|
|
814
|
+
if (keys.length === 0 || keys.some((key) => typeof key !== "string" || !accepted.has(key)) || Object.hasOwn(options, "mode") && options.mode !== "stream") throw new TypeError(`typert-protocol: ${requirement}`);
|
|
815
|
+
const { mode, name, resources } = options;
|
|
816
|
+
if (name !== void 0) validateName("Remote export name", name);
|
|
817
|
+
return {
|
|
818
|
+
...mode === void 0 ? {} : { mode },
|
|
819
|
+
...name === void 0 ? {} : { exportName: name },
|
|
820
|
+
...resources === void 0 ? {} : { resources: resourceReaders(resources) }
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
/** Freeze declared readers into the marker record; a misdeclared reader fails at decoration. */
|
|
824
|
+
function resourceReaders(resources) {
|
|
825
|
+
const readers = {};
|
|
826
|
+
for (const [kind, reader] of Object.entries(resources)) {
|
|
827
|
+
if (typeof reader !== "function") throw new TypeError(`typert-protocol: Remote resource reader "${kind}" must be a function`);
|
|
828
|
+
readers[kind] = reader;
|
|
829
|
+
}
|
|
830
|
+
if (Object.keys(readers).length === 0) throw new TypeError("typert-protocol: Remote resources require at least one reader");
|
|
831
|
+
return Object.freeze(readers);
|
|
832
|
+
}
|
|
833
|
+
function remoteDecorator(invocation, options = {}) {
|
|
834
|
+
return function(_method, context) {
|
|
835
|
+
addMarkerInitializer(context, invocation, options);
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
function readRemoteMethodDescriptor(prototype) {
|
|
839
|
+
const property = Object.getOwnPropertyDescriptor(prototype, REMOTE_METHOD_DESCRIPTOR);
|
|
840
|
+
if (property === void 0) return void 0;
|
|
841
|
+
const descriptor = property.value;
|
|
842
|
+
if (descriptor === null || typeof descriptor !== "object") throw new TypeError("typert-protocol: Remote method descriptor must be an object");
|
|
843
|
+
const version = Reflect.get(descriptor, "version");
|
|
844
|
+
if (version !== 1) throw new TypeError(`typert-protocol: unsupported Remote method descriptor version ${String(version)}`);
|
|
845
|
+
const methods = Reflect.get(descriptor, "methods");
|
|
846
|
+
if (!Array.isArray(methods)) throw new TypeError("typert-protocol: Remote method descriptor methods must be an array");
|
|
847
|
+
return descriptor;
|
|
848
|
+
}
|
|
849
|
+
function addMarkerInitializer(context, invocation, options = {}) {
|
|
850
|
+
if (context.private || context.static || typeof context.name !== "string") throw new TypeError("typert-protocol: Remote decorators require a public instance method with a string name");
|
|
851
|
+
const method = context.name;
|
|
852
|
+
context.addInitializer(function() {
|
|
853
|
+
const prototype = Object.getPrototypeOf(this);
|
|
854
|
+
if (prototype === null) throw new TypeError(`typert-protocol: cannot mark Remote method "${method}" on an object without a prototype`);
|
|
855
|
+
mark(prototype, method, invocation, options);
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
function mark(prototype, method, invocation, { mode, exportName, resources }) {
|
|
859
|
+
const descriptor = readRemoteMethodDescriptor(prototype);
|
|
860
|
+
const marker = Object.freeze({
|
|
861
|
+
method,
|
|
862
|
+
...exportName === void 0 || exportName === method ? {} : { exportName },
|
|
863
|
+
...mode === void 0 ? {} : { mode },
|
|
864
|
+
invocation: Object.freeze(invocation),
|
|
865
|
+
...resources === void 0 ? {} : { resources }
|
|
866
|
+
});
|
|
867
|
+
const current = descriptor?.methods.find((candidate) => candidate.method === method);
|
|
868
|
+
if (current !== void 0) {
|
|
869
|
+
if (current.exportName === marker.exportName && current.mode === marker.mode && current.resources === marker.resources && sameInvocation(current.invocation, invocation)) return;
|
|
870
|
+
throw new Error(`typert-protocol: Remote method "${method}" has conflicting invocation markers`);
|
|
871
|
+
}
|
|
872
|
+
Object.defineProperty(prototype, REMOTE_METHOD_DESCRIPTOR, {
|
|
873
|
+
configurable: true,
|
|
874
|
+
value: Object.freeze({
|
|
875
|
+
version: 1,
|
|
876
|
+
methods: Object.freeze([...descriptor?.methods ?? [], marker])
|
|
877
|
+
})
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
function sameInvocation(left, right) {
|
|
881
|
+
if (left.kind === "direct") return right.kind === "direct";
|
|
882
|
+
if (right.kind === "direct") return false;
|
|
883
|
+
return left.context === right.context;
|
|
884
|
+
}
|
|
885
|
+
function validateName(subject, value) {
|
|
886
|
+
if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
|
|
887
|
+
}
|
|
888
|
+
//#endregion
|
|
889
889
|
//#region ../../util/crypto/src/index.ts
|
|
890
890
|
/**
|
|
891
891
|
* Random v4 UUID, minted from `crypto.getRandomValues`.
|
|
@@ -952,6 +952,7 @@ const LLM_FAILURE_CODES = {
|
|
|
952
952
|
INVALID_REPLAY_STATE: {},
|
|
953
953
|
INVALID_REQUEST: {},
|
|
954
954
|
INVALID_RESPONSE: {},
|
|
955
|
+
INVALID_TOOL_ARGUMENTS: { retryChoice: true },
|
|
955
956
|
MALFORMED_RESPONSE: { retryChoice: true },
|
|
956
957
|
MISSING_CREDENTIAL: {},
|
|
957
958
|
MODEL_SWITCH_COMPACTION_FAILED: {},
|
|
@@ -1044,6 +1045,7 @@ const DEFAULT_MAX_DELAY_MS = 1e4;
|
|
|
1044
1045
|
const DEFAULT_JITTER_RATIO = .1;
|
|
1045
1046
|
const DEFAULT_RETRYABLE_CODES = Object.freeze([
|
|
1046
1047
|
EMPTY_RESPONSE_CODE,
|
|
1048
|
+
"INVALID_TOOL_ARGUMENTS",
|
|
1047
1049
|
"RATE_LIMIT",
|
|
1048
1050
|
"SERVER",
|
|
1049
1051
|
"TIMEOUT",
|
|
@@ -1895,6 +1897,18 @@ var LlmError = class LlmError extends HarnessError {
|
|
|
1895
1897
|
});
|
|
1896
1898
|
}
|
|
1897
1899
|
/**
|
|
1900
|
+
* Report whether a registered provider advertises a model in its current
|
|
1901
|
+
* catalog. Catalog-driven entry points use it to accept only listed models.
|
|
1902
|
+
* @param provider - provider route to inspect.
|
|
1903
|
+
* @param model - provider-owned model id.
|
|
1904
|
+
* @returns false when the provider is unregistered or its catalog omits the model.
|
|
1905
|
+
* @throws the provider's catalog failure, unchanged.
|
|
1906
|
+
*/
|
|
1907
|
+
async isModelInCatalog(provider, model) {
|
|
1908
|
+
if (!this.adapters.has(provider)) return false;
|
|
1909
|
+
return (await this.listModels(provider)).some((entry) => entry.id === model);
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1898
1912
|
* Resolve and validate all metadata from the adapter that owns one exact
|
|
1899
1913
|
* route. The result is detached from adapter-owned objects; catalog
|
|
1900
1914
|
* membership remains advisory and does not control request routing.
|
|
@@ -2238,6 +2252,7 @@ const Config = z.object({
|
|
|
2238
2252
|
]),
|
|
2239
2253
|
include: z.array(z.string()).default([]),
|
|
2240
2254
|
exclude: z.array(z.string()).default([]),
|
|
2255
|
+
restartCountAfter: z.array(z.string()).default([]),
|
|
2241
2256
|
argumentsPreviewChars: z.number().default(500)
|
|
2242
2257
|
});
|
|
2243
2258
|
/**
|
|
@@ -2320,6 +2335,7 @@ function apply(ctx, config) {
|
|
|
2320
2335
|
const thresholdSet = new Set(thresholds);
|
|
2321
2336
|
const includePatterns = config.include.map(wildcardToRegExp);
|
|
2322
2337
|
const excludePatterns = config.exclude.map(wildcardToRegExp);
|
|
2338
|
+
const restartPatterns = config.restartCountAfter.map(wildcardToRegExp);
|
|
2323
2339
|
const argumentsPreviewChars = config.argumentsPreviewChars;
|
|
2324
2340
|
if (!Number.isInteger(argumentsPreviewChars) || argumentsPreviewChars < 1) throw new Error(`repeat-tool-reminder: invalid argumentsPreviewChars ${argumentsPreviewChars} — must be an integer >= 1`);
|
|
2325
2341
|
const chains = /* @__PURE__ */ new WeakMap();
|
|
@@ -2336,8 +2352,12 @@ function apply(ctx, config) {
|
|
|
2336
2352
|
* same pipeline), and a model hammering a denied call is exactly the loop
|
|
2337
2353
|
* worth breaking.
|
|
2338
2354
|
*/
|
|
2339
|
-
function observe(exec) {
|
|
2355
|
+
function observe(exec, result) {
|
|
2340
2356
|
if (!exec.agent || exec.parent !== void 0) return void 0;
|
|
2357
|
+
if (!result.isError && restartPatterns.some((pattern) => pattern.test(exec.name))) {
|
|
2358
|
+
chains.delete(exec.agent);
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2341
2361
|
if (!tracked(exec.name)) return void 0;
|
|
2342
2362
|
const canonical = canonicalize(exec.arguments);
|
|
2343
2363
|
const key = JSON.stringify([exec.name, canonical]);
|
|
@@ -2360,8 +2380,8 @@ function apply(ctx, config) {
|
|
|
2360
2380
|
}
|
|
2361
2381
|
});
|
|
2362
2382
|
}
|
|
2363
|
-
ctx.on("tools/post-execute", async (exec,
|
|
2364
|
-
const reminder = observe(exec);
|
|
2383
|
+
ctx.on("tools/post-execute", async (exec, result, next) => {
|
|
2384
|
+
const reminder = observe(exec, result);
|
|
2365
2385
|
const downstream = await next();
|
|
2366
2386
|
if (!reminder) return downstream;
|
|
2367
2387
|
return {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const name = "repeat-tool-reminder";
|
|
|
20
20
|
* Plugin config, validated by the same-named schemastery schema plus the
|
|
21
21
|
* load-time checks in `apply` (misconfiguration fails loud: an empty
|
|
22
22
|
* `thresholds` list, a non-integer, a value below 2, or a duplicate throws at
|
|
23
|
-
* plugin load, never a silent fall-back). `include`/`exclude` entries are
|
|
23
|
+
* plugin load, never a silent fall-back). `include`/`exclude`/`restartCountAfter` entries are
|
|
24
24
|
* `*`-wildcard predicates over tool names at call time, not references to
|
|
25
25
|
* registry entries — a pattern matching no currently registered tool is valid
|
|
26
26
|
* (`exclude: [mcp_*]` must stay legal in a deployment that loads no MCP tools).
|
|
@@ -32,6 +32,13 @@ export interface Config {
|
|
|
32
32
|
include?: string[];
|
|
33
33
|
/** Tool-name patterns transparent to the chain (neither count nor reset). */
|
|
34
34
|
exclude?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Tool-name patterns whose successful calls end the chain without counting,
|
|
37
|
+
* such as waits and job reads that observe changing state, so repeating them
|
|
38
|
+
* or repeating a call between them is not reported. Matched before
|
|
39
|
+
* `include`/`exclude`; a failed call is counted like any other call.
|
|
40
|
+
*/
|
|
41
|
+
restartCountAfter?: string[];
|
|
35
42
|
/**
|
|
36
43
|
* Maximum characters of canonical arguments quoted in the DETAILED reminder
|
|
37
44
|
* (default 500). Large payloads (a `write` body, a long command) would
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAGxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,gBAAgB;QACxB,sBAAsB,EAAE;YAAE,IAAI,EAAE,sBAAsB,CAAA;SAAE,GAAG,aAAa,CAAA;KACzE;CACF;AAMD,eAAO,MAAM,IAAI,yBAAyB,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM;IACrB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAGxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,gBAAgB;QACxB,sBAAsB,EAAE;YAAE,IAAI,EAAE,sBAAsB,CAAA;SAAE,GAAG,aAAa,CAAA;KACzE;CACF;AAMD,eAAO,MAAM,IAAI,yBAAyB,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM;IACrB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAM3B,CAAA;AA2GF;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAoExD"}
|
package/lib/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAYxD,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAYxD,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAA;AAmC1C,MAAM,CAAC,MAAM,MAAM,GAAc,CAAC,CAAC,MAAM,CAAC;IACxC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAClD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IACxC,OAA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,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-repeat-tool-reminder",
|
|
3
3
|
"description": "Repeat-tool-call guard plugin: advisory reminders when an agent loops on identical tool calls",
|
|
4
|
-
"version": "0.2.3-alpha.
|
|
4
|
+
"version": "0.2.3-alpha.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
],
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@deepseek-ai/schemastery": "~3.
|
|
35
|
+
"@deepseek-ai/schemastery": "~3.20.0-alpha.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@deepseek-ai/dsh-agent": "0.2.3-alpha.
|
|
39
|
-
"@deepseek-ai/dsh-tools": "0.2.3-alpha.
|
|
40
|
-
"@deepseek-ai/cordis": "~4.
|
|
38
|
+
"@deepseek-ai/dsh-agent": "0.2.3-alpha.3",
|
|
39
|
+
"@deepseek-ai/dsh-tools": "0.2.3-alpha.3",
|
|
40
|
+
"@deepseek-ai/cordis": "~4.2.0-alpha.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@deepseek-ai/dsh-brand": "0.2.3-alpha.
|
|
44
|
-
"@deepseek-ai/dsh-agent": "0.2.3-alpha.
|
|
45
|
-
"@deepseek-ai/dsh-agent-loop": "0.2.3-alpha.
|
|
46
|
-
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.3-alpha.
|
|
47
|
-
"@deepseek-ai/dsh-llm": "0.2.3-alpha.
|
|
48
|
-
"@deepseek-ai/dsh-session": "0.2.3-alpha.
|
|
49
|
-
"@deepseek-ai/dsh-tool-testkit": "0.2.3-alpha.
|
|
50
|
-
"@deepseek-ai/dsh-tools": "0.2.3-alpha.
|
|
51
|
-
"@deepseek-ai/cordis": "~4.
|
|
52
|
-
"@deepseek-ai/dsh-session-projection": "0.2.3-alpha.
|
|
43
|
+
"@deepseek-ai/dsh-brand": "0.2.3-alpha.3",
|
|
44
|
+
"@deepseek-ai/dsh-agent": "0.2.3-alpha.3",
|
|
45
|
+
"@deepseek-ai/dsh-agent-loop": "0.2.3-alpha.3",
|
|
46
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.3-alpha.3",
|
|
47
|
+
"@deepseek-ai/dsh-llm": "0.2.3-alpha.3",
|
|
48
|
+
"@deepseek-ai/dsh-session": "0.2.3-alpha.3",
|
|
49
|
+
"@deepseek-ai/dsh-tool-testkit": "0.2.3-alpha.3",
|
|
50
|
+
"@deepseek-ai/dsh-tools": "0.2.3-alpha.3",
|
|
51
|
+
"@deepseek-ai/cordis": "~4.2.0-alpha.2",
|
|
52
|
+
"@deepseek-ai/dsh-session-projection": "0.2.3-alpha.3"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare module '@deepseek-ai/dsh-llm' {
|
|
|
19
19
|
|
|
20
20
|
import type { MessageSource } from '@deepseek-ai/dsh-llm'
|
|
21
21
|
import type { UserMessage } from '@deepseek-ai/dsh-session'
|
|
22
|
-
import type { PostToolDecision, ToolExecution } from '@deepseek-ai/dsh-tools'
|
|
22
|
+
import type { PostToolDecision, ToolExecution, ToolExecutionResult } from '@deepseek-ai/dsh-tools'
|
|
23
23
|
|
|
24
24
|
export const name = 'repeat-tool-reminder'
|
|
25
25
|
|
|
@@ -27,7 +27,7 @@ export const name = 'repeat-tool-reminder'
|
|
|
27
27
|
* Plugin config, validated by the same-named schemastery schema plus the
|
|
28
28
|
* load-time checks in `apply` (misconfiguration fails loud: an empty
|
|
29
29
|
* `thresholds` list, a non-integer, a value below 2, or a duplicate throws at
|
|
30
|
-
* plugin load, never a silent fall-back). `include`/`exclude` entries are
|
|
30
|
+
* plugin load, never a silent fall-back). `include`/`exclude`/`restartCountAfter` entries are
|
|
31
31
|
* `*`-wildcard predicates over tool names at call time, not references to
|
|
32
32
|
* registry entries — a pattern matching no currently registered tool is valid
|
|
33
33
|
* (`exclude: [mcp_*]` must stay legal in a deployment that loads no MCP tools).
|
|
@@ -39,6 +39,13 @@ export interface Config {
|
|
|
39
39
|
include?: string[]
|
|
40
40
|
/** Tool-name patterns transparent to the chain (neither count nor reset). */
|
|
41
41
|
exclude?: string[]
|
|
42
|
+
/**
|
|
43
|
+
* Tool-name patterns whose successful calls end the chain without counting,
|
|
44
|
+
* such as waits and job reads that observe changing state, so repeating them
|
|
45
|
+
* or repeating a call between them is not reported. Matched before
|
|
46
|
+
* `include`/`exclude`; a failed call is counted like any other call.
|
|
47
|
+
*/
|
|
48
|
+
restartCountAfter?: string[]
|
|
42
49
|
/**
|
|
43
50
|
* Maximum characters of canonical arguments quoted in the DETAILED reminder
|
|
44
51
|
* (default 500). Large payloads (a `write` body, a long command) would
|
|
@@ -53,6 +60,7 @@ export const Config: z<Config> = z.object({
|
|
|
53
60
|
thresholds: z.array(z.number()).default([3, 5, 8]),
|
|
54
61
|
include: z.array(z.string()).default([]),
|
|
55
62
|
exclude: z.array(z.string()).default([]),
|
|
63
|
+
restartCountAfter: z.array(z.string()).default([]),
|
|
56
64
|
argumentsPreviewChars: z.number().default(500),
|
|
57
65
|
})
|
|
58
66
|
|
|
@@ -172,6 +180,7 @@ export function apply(ctx: Context, config: Config): void {
|
|
|
172
180
|
const thresholdSet = new Set(thresholds)
|
|
173
181
|
const includePatterns = (config.include as string[]).map(wildcardToRegExp)
|
|
174
182
|
const excludePatterns = (config.exclude as string[]).map(wildcardToRegExp)
|
|
183
|
+
const restartPatterns = (config.restartCountAfter as string[]).map(wildcardToRegExp)
|
|
175
184
|
const argumentsPreviewChars = config.argumentsPreviewChars as number
|
|
176
185
|
if (!Number.isInteger(argumentsPreviewChars) || argumentsPreviewChars < 1) {
|
|
177
186
|
throw new Error(`repeat-tool-reminder: invalid argumentsPreviewChars ${argumentsPreviewChars} — must be an integer >= 1`)
|
|
@@ -193,8 +202,12 @@ export function apply(ctx: Context, config: Config): void {
|
|
|
193
202
|
* same pipeline), and a model hammering a denied call is exactly the loop
|
|
194
203
|
* worth breaking.
|
|
195
204
|
*/
|
|
196
|
-
function observe(exec: ToolExecution): UserMessage | undefined {
|
|
205
|
+
function observe(exec: ToolExecution, result: Readonly<ToolExecutionResult>): UserMessage | undefined {
|
|
197
206
|
if (!exec.agent || exec.parent !== undefined) return undefined
|
|
207
|
+
if (!result.isError && restartPatterns.some(pattern => pattern.test(exec.name))) {
|
|
208
|
+
chains.delete(exec.agent)
|
|
209
|
+
return undefined
|
|
210
|
+
}
|
|
198
211
|
if (!tracked(exec.name)) return undefined
|
|
199
212
|
const canonical = canonicalize(exec.arguments)
|
|
200
213
|
const key = JSON.stringify([exec.name, canonical])
|
|
@@ -215,8 +228,8 @@ export function apply(ctx: Context, config: Config): void {
|
|
|
215
228
|
// the downstream outcome), DELEGATE so a later listener can still block or
|
|
216
229
|
// replace, then fold the reminder onto whatever came back — additionalContexts
|
|
217
230
|
// rides both decision variants, so a blocked call still gets the nudge.
|
|
218
|
-
ctx.on('tools/post-execute', async (exec,
|
|
219
|
-
const reminder = observe(exec)
|
|
231
|
+
ctx.on('tools/post-execute', async (exec, result, next): Promise<PostToolDecision> => {
|
|
232
|
+
const reminder = observe(exec, result)
|
|
220
233
|
const downstream = await next()
|
|
221
234
|
if (!reminder) return downstream
|
|
222
235
|
return { ...downstream, additionalContexts: prependContext(reminder, downstream.additionalContexts) }
|