@goodandready/dsh-agent-loop-guard 0.2.13 → 0.2.14
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 +23 -0
- package/lib/assistant-output-state.js +35 -7
- package/lib/client.js +136 -284
- package/lib/guard-state.js +61 -15
- package/lib/index.js +5 -2
- package/lib/plugin-updater.js +13 -2
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.14] - 2026-09-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Streaming Assistant Block Hashing**: Incremental SHA-256 hashing for assistant output blocks exceeding 16,384 characters, preventing false positive loop rejections caused by truncated suffixes (#79).
|
|
12
|
+
- **Large Payload Fingerprints**: SHA-256 fingerprint hashing for tool arguments and results larger than 256 bytes, drastically lowering memory usage and serialization overhead in long turns (#70, #66).
|
|
13
|
+
- **Client Modular Architecture**: Extracted monolithic client source into clean submodules under `src/client/` (`00-header.js`, `10-styles.js`, `20-locales.js`, `50-settings-card.js`, `60-slots.js`, `90-footer.js`) with automated build via `scripts/build-client.mjs`, reducing final client bundle below the 600-line preflight threshold (#74).
|
|
14
|
+
- **Repository Clean Script**: Added standard `clean` npm script (`rm -f *.tgz`) (#67).
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- **Immediate Duplicate Tool Call Blocking**: `blockExactDuplicates: true` now rejects identical duplicate tool calls immediately on the first recurrence (`exactCount >= 1`), while `blockExactDuplicates: false` allows iterations up to `maxCallsPerRepeatGroup` (#76).
|
|
18
|
+
- **Memory Leak in Session State**: `LoopGuardState.byAgent` now removes agent session entries when `session/disposed` fires, preventing memory growth in persistent daemon processes (#69, #65).
|
|
19
|
+
- **Group Counter Rollback**: Releasing uncommitted or canceled tool calls in `recordResult` properly decrements `repeatGroups` and `exactGroups` counters (#78).
|
|
20
|
+
- **Assistant Message Fallback Key**: Normalized message text is now used as fallback key when message ID is absent, replacing unreliable string length comparison (#77).
|
|
21
|
+
- **Telemetry Violation Accuracy**: Preserved primary violation code (`blockReason`) during `answerOnly` mode, eliminating false spikes of `LOOP_GUARD_STOP` in telemetry when agents attempt subsequent tools (#73).
|
|
22
|
+
- **LAN Origin Authorization**: Permitted same-origin update and telemetry requests from local network host headers matching the server socket address (#72).
|
|
23
|
+
- **Bare Mode UI Activation**: Enabled automatic telemetry polling and updater checks when rendering bare settings on `plugins.item` and `plugins.row.config` seats without manual header clicks (#64).
|
|
24
|
+
|
|
25
|
+
### Performance
|
|
26
|
+
- Replaced array-copy reversal (`[...calls].reverse().find`) with native `Array.prototype.findLast` in `findCall` (#71).
|
|
27
|
+
|
|
28
|
+
### Documentation
|
|
29
|
+
- Updated `docs/design/DESIGN.md` to document dual-seat integration (`plugins.row.config` and `plugins.item`), justify runtime functional Cyrillic stop word heuristics, and refresh npm packaging metrics (#68).
|
|
30
|
+
|
|
8
31
|
## 0.2.13
|
|
9
32
|
|
|
10
33
|
### Fixed
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
function sessionKey(session) {
|
|
2
3
|
if (typeof session === 'string' && session.length > 0) return session;
|
|
3
4
|
if (session !== null && typeof session === 'object') {
|
|
@@ -94,6 +95,9 @@ export class AssistantOutputGuardState {
|
|
|
94
95
|
state.streamedText = '';
|
|
95
96
|
state.streamedSkipAvailable = false;
|
|
96
97
|
state.blockText = '';
|
|
98
|
+
state.blockHasher = createHash('sha256');
|
|
99
|
+
state.blockFullHash = undefined;
|
|
100
|
+
state.blockOversized = false;
|
|
97
101
|
state.blockFinalized = false;
|
|
98
102
|
}
|
|
99
103
|
return state;
|
|
@@ -105,8 +109,12 @@ export class AssistantOutputGuardState {
|
|
|
105
109
|
state.streamedText = '';
|
|
106
110
|
state.streamedSkipAvailable = false;
|
|
107
111
|
state.blockText = '';
|
|
112
|
+
state.blockHasher = null;
|
|
113
|
+
state.blockFullHash = undefined;
|
|
114
|
+
state.blockOversized = false;
|
|
108
115
|
state.blockFinalized = false;
|
|
109
116
|
state.lastBlock = '';
|
|
117
|
+
state.lastBlockKey = '';
|
|
110
118
|
state.blockRepeatCount = 0;
|
|
111
119
|
state.lastLine = '';
|
|
112
120
|
state.repeatCount = 0;
|
|
@@ -118,8 +126,12 @@ export class AssistantOutputGuardState {
|
|
|
118
126
|
state.streamedText = '';
|
|
119
127
|
state.streamedSkipAvailable = false;
|
|
120
128
|
state.blockText = '';
|
|
129
|
+
state.blockHasher = null;
|
|
130
|
+
state.blockFullHash = undefined;
|
|
131
|
+
state.blockOversized = false;
|
|
121
132
|
state.blockFinalized = false;
|
|
122
133
|
state.lastBlock = '';
|
|
134
|
+
state.lastBlockKey = '';
|
|
123
135
|
state.blockRepeatCount = 0;
|
|
124
136
|
state.lastLine = '';
|
|
125
137
|
state.repeatCount = 0;
|
|
@@ -152,10 +164,16 @@ export class AssistantOutputGuardState {
|
|
|
152
164
|
if (typeof text !== 'string' || text.length === 0) return undefined;
|
|
153
165
|
const state = this.beginBlock(session, turn, step, index);
|
|
154
166
|
if (state.activeTools.size > 0 || state.triggered) return undefined;
|
|
167
|
+
if (!state.blockHasher) {
|
|
168
|
+
state.blockHasher = createHash('sha256');
|
|
169
|
+
}
|
|
170
|
+
state.blockHasher.update(text);
|
|
155
171
|
state.streamedText += text;
|
|
156
|
-
state.blockText
|
|
157
|
-
|
|
158
|
-
state.blockText = state.blockText.slice(-this.maxAssistantBlockChars);
|
|
172
|
+
if (state.blockText.length + text.length > this.maxAssistantBlockChars) {
|
|
173
|
+
state.blockOversized = true;
|
|
174
|
+
state.blockText = (state.blockText + text).slice(-this.maxAssistantBlockChars);
|
|
175
|
+
} else {
|
|
176
|
+
state.blockText += text;
|
|
159
177
|
}
|
|
160
178
|
state.streamedSkipAvailable = true;
|
|
161
179
|
state.pending += text;
|
|
@@ -168,13 +186,15 @@ export class AssistantOutputGuardState {
|
|
|
168
186
|
return undefined;
|
|
169
187
|
}
|
|
170
188
|
|
|
171
|
-
observeBlock(session, block) {
|
|
189
|
+
observeBlock(session, block, fullHash = undefined) {
|
|
172
190
|
const state = this.stateFor(session);
|
|
173
191
|
const normalized = normalizeAssistantBlock(block);
|
|
174
192
|
if (normalized === '' || !normalized.includes('\n') || state.activeTools.size > 0 || state.triggered) return undefined;
|
|
175
|
-
|
|
193
|
+
const key = fullHash ? 'hash:' + fullHash : normalized;
|
|
194
|
+
if (key === state.lastBlockKey) {
|
|
176
195
|
state.blockRepeatCount += 1;
|
|
177
196
|
} else {
|
|
197
|
+
state.lastBlockKey = key;
|
|
178
198
|
state.lastBlock = normalized;
|
|
179
199
|
state.blockRepeatCount = 1;
|
|
180
200
|
}
|
|
@@ -193,14 +213,22 @@ export class AssistantOutputGuardState {
|
|
|
193
213
|
const state = this.stateFor(session);
|
|
194
214
|
if (state.blockFinalized) return undefined;
|
|
195
215
|
state.blockFinalized = true;
|
|
196
|
-
|
|
216
|
+
if (state.blockOversized && state.blockHasher && !state.blockFullHash) {
|
|
217
|
+
try {
|
|
218
|
+
state.blockFullHash = state.blockHasher.digest('hex');
|
|
219
|
+
} catch {
|
|
220
|
+
// already digested
|
|
221
|
+
}
|
|
222
|
+
state.blockHasher = null;
|
|
223
|
+
}
|
|
224
|
+
return this.observeBlock(session, state.blockText, state.blockFullHash);
|
|
197
225
|
}
|
|
198
226
|
|
|
199
227
|
observeMessage(session, { id, turn, step, index = 0, text } = {}) {
|
|
200
228
|
if (typeof text !== 'string' || text.length === 0) return undefined;
|
|
201
229
|
const state = this.beginBlock(session, turn, step, index);
|
|
202
230
|
const key = id === undefined || id === null
|
|
203
|
-
? String(turn ?? 'u') + ':' + String(step ?? 's') + ':' +
|
|
231
|
+
? String(turn ?? 'u') + ':' + String(step ?? 's') + ':' + normalizeAssistantBlock(text)
|
|
204
232
|
: String(id);
|
|
205
233
|
if (state.seenMessages.has(key)) return undefined;
|
|
206
234
|
state.seenMessages.add(key);
|
package/lib/client.js
CHANGED
|
@@ -6,9 +6,6 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
7
|
const React = require('react');
|
|
8
8
|
const NS = '@goodandready/dsh-agent-loop-guard';
|
|
9
|
-
// Row seat on the Plugins page: the row's "configure" control opens this
|
|
10
|
-
// entry, keyed `<package name>#<row id>` exactly as cordis.patch.yml
|
|
11
|
-
// declares the row (kernel: rowConfigKey(bundle, rowId)).
|
|
12
9
|
const PKG = '@goodandready/dsh-agent-loop-guard';
|
|
13
10
|
const ROW_ID = '@goodandready/dsh-agent-loop-guard';
|
|
14
11
|
const ROW_CONFIG_KEY = PKG + '#' + ROW_ID;
|
|
@@ -20,135 +17,63 @@ window.__ModuleLoader__.load({
|
|
|
20
17
|
PrimitivesChevron = prim.IconChevronDownOutline14 || prim.IconChevronDown || prim.IconChevronDown16;
|
|
21
18
|
}
|
|
22
19
|
} catch (err) {
|
|
23
|
-
/* bestEffort */
|
|
24
20
|
console.warn?.('[dsh-agent-loop-guard] primitives unavailable, using SVG fallback:', err?.message || String(err));
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
const CSS_STYLES = `
|
|
28
|
-
|
|
29
|
-
.alg-page {
|
|
30
|
-
width: 100%;
|
|
31
|
-
min-width: 0;
|
|
32
|
-
}
|
|
23
|
+
.alg-page { width: 100%; min-width: 0; }
|
|
33
24
|
.alg-card {
|
|
34
|
-
border: 1px solid var(--dsw-alias-border-l2);
|
|
35
|
-
|
|
36
|
-
border-radius: 12px;
|
|
37
|
-
list-style: none;
|
|
38
|
-
margin-bottom: 12px;
|
|
39
|
-
overflow: hidden;
|
|
25
|
+
border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-3);
|
|
26
|
+
border-radius: 12px; list-style: none; margin-bottom: 12px; overflow: hidden;
|
|
40
27
|
transition: border-color 0.15s ease;
|
|
41
28
|
}
|
|
42
|
-
.alg-card:hover {
|
|
43
|
-
border-color: var(--dsw-alias-border-l1, var(--dsw-alias-border-l2));
|
|
44
|
-
}
|
|
29
|
+
.alg-card:hover { border-color: var(--dsw-alias-border-l1, var(--dsw-alias-border-l2)); }
|
|
45
30
|
.alg-header-btn {
|
|
46
|
-
appearance: none;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
color: inherit;
|
|
50
|
-
text-align: left;
|
|
51
|
-
cursor: pointer;
|
|
52
|
-
background: transparent;
|
|
53
|
-
border: 0;
|
|
54
|
-
border-radius: 12px;
|
|
55
|
-
display: flex;
|
|
56
|
-
align-items: center;
|
|
57
|
-
gap: 12px;
|
|
58
|
-
padding: 14px 16px;
|
|
31
|
+
appearance: none; width: 100%; font: inherit; color: inherit; text-align: left;
|
|
32
|
+
cursor: pointer; background: transparent; border: 0; border-radius: 12px;
|
|
33
|
+
display: flex; align-items: center; gap: 12px; padding: 14px 16px;
|
|
59
34
|
transition: background 0.15s ease;
|
|
60
35
|
}
|
|
61
|
-
.alg-header-btn:hover {
|
|
62
|
-
background: var(--dsw-alias-bg-hover, var(--dsw-alias-bg-layer-hover));
|
|
63
|
-
}
|
|
36
|
+
.alg-header-btn:hover { background: var(--dsw-alias-bg-hover, var(--dsw-alias-bg-layer-hover)); }
|
|
64
37
|
.alg-chevron {
|
|
65
|
-
margin-left: auto;
|
|
66
|
-
|
|
67
|
-
display: flex;
|
|
68
|
-
align-items: center;
|
|
69
|
-
justify-content: center;
|
|
38
|
+
margin-left: auto; color: var(--dsw-alias-label-tertiary);
|
|
39
|
+
display: flex; align-items: center; justify-content: center;
|
|
70
40
|
transition: transform 0.2s ease;
|
|
71
41
|
}
|
|
72
|
-
.alg-chevron.expanded {
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
.alg-
|
|
76
|
-
padding: 0 16px 16px;
|
|
77
|
-
border-top: 1px solid var(--dsw-alias-border-l2);
|
|
78
|
-
}
|
|
79
|
-
.alg-field {
|
|
80
|
-
display: flex;
|
|
81
|
-
flex-direction: column;
|
|
82
|
-
gap: 6px;
|
|
83
|
-
padding: 10px 0;
|
|
84
|
-
}
|
|
85
|
-
.alg-field label {
|
|
86
|
-
font-size: 13px;
|
|
87
|
-
color: var(--dsw-alias-label-secondary);
|
|
88
|
-
cursor: pointer;
|
|
89
|
-
}
|
|
42
|
+
.alg-chevron.expanded { transform: rotate(180deg); }
|
|
43
|
+
.alg-body { padding: 0 16px 16px; border-top: 1px solid var(--dsw-alias-border-l2); }
|
|
44
|
+
.alg-field { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; }
|
|
45
|
+
.alg-field label { font-size: 13px; color: var(--dsw-alias-label-secondary); cursor: pointer; }
|
|
90
46
|
.alg-input {
|
|
91
|
-
height: 34px;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
color: var(--dsw-alias-label-primary);
|
|
95
|
-
border-radius: 8px;
|
|
96
|
-
padding: 0 12px;
|
|
97
|
-
font-size: 13px;
|
|
98
|
-
outline: none;
|
|
47
|
+
height: 34px; border: 1px solid var(--dsw-alias-border-l2);
|
|
48
|
+
background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary);
|
|
49
|
+
border-radius: 8px; padding: 0 12px; font-size: 13px; outline: none;
|
|
99
50
|
transition: border-color 0.15s ease;
|
|
100
51
|
}
|
|
101
|
-
.alg-input:focus {
|
|
102
|
-
border-color: var(--dsw-alias-accent-primary);
|
|
103
|
-
}
|
|
52
|
+
.alg-input:focus { border-color: var(--dsw-alias-accent-primary); }
|
|
104
53
|
.alg-checkbox-label {
|
|
105
|
-
display: flex;
|
|
106
|
-
|
|
107
|
-
gap: 8px;
|
|
108
|
-
font-size: 13px;
|
|
109
|
-
color: var(--dsw-alias-label-primary);
|
|
110
|
-
cursor: pointer;
|
|
111
|
-
padding: 6px 0;
|
|
54
|
+
display: flex; align-items: center; gap: 8px; font-size: 13px;
|
|
55
|
+
color: var(--dsw-alias-label-primary); cursor: pointer; padding: 6px 0;
|
|
112
56
|
}
|
|
113
57
|
.alg-btn-primary {
|
|
114
|
-
|
|
115
|
-
padding:
|
|
116
|
-
|
|
117
|
-
border-radius: 8px;
|
|
118
|
-
background: var(--dsw-alias-accent-primary);
|
|
119
|
-
color: var(--dsw-alias-label-inverse);
|
|
120
|
-
font-size: 13px;
|
|
121
|
-
font-weight: 600;
|
|
122
|
-
cursor: pointer;
|
|
58
|
+
appearance: none; font: inherit; cursor: pointer; border: 0; border-radius: 8px;
|
|
59
|
+
padding: 6px 16px; font-size: 13px; font-weight: 500;
|
|
60
|
+
background: var(--dsw-alias-accent-primary); color: var(--dsw-alias-bg-layer-3);
|
|
123
61
|
transition: opacity 0.15s ease;
|
|
124
62
|
}
|
|
125
|
-
.alg-btn-primary:disabled {
|
|
126
|
-
|
|
127
|
-
cursor: default;
|
|
128
|
-
}
|
|
63
|
+
.alg-btn-primary:hover:not(:disabled) { opacity: 0.9; }
|
|
64
|
+
.alg-btn-primary:disabled { opacity: 0.5; cursor: default; }
|
|
129
65
|
.alg-btn-updater {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
background: var(--dsw-alias-accent-primary);
|
|
133
|
-
|
|
134
|
-
border: 0;
|
|
135
|
-
font-size: 12px;
|
|
136
|
-
font-weight: 600;
|
|
137
|
-
cursor: pointer;
|
|
138
|
-
}
|
|
139
|
-
.alg-btn-updater:disabled {
|
|
140
|
-
opacity: 0.6;
|
|
141
|
-
cursor: default;
|
|
66
|
+
appearance: none; font: inherit; cursor: pointer; border: 0; border-radius: 6px;
|
|
67
|
+
padding: 4px 10px; font-size: 12px; font-weight: 500;
|
|
68
|
+
background: var(--dsw-alias-accent-primary); color: var(--dsw-alias-bg-layer-3);
|
|
69
|
+
transition: opacity 0.15s ease;
|
|
142
70
|
}
|
|
71
|
+
.alg-btn-updater:hover:not(:disabled) { opacity: 0.9; }
|
|
72
|
+
.alg-btn-updater:disabled { opacity: 0.6; cursor: default; }
|
|
143
73
|
.alg-btn-ghost {
|
|
144
|
-
background: transparent;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
border-radius: 4px;
|
|
148
|
-
padding: 2px 8px;
|
|
149
|
-
font-size: 11px;
|
|
150
|
-
cursor: pointer;
|
|
151
|
-
transition: color 0.15s ease, border-color 0.15s ease;
|
|
74
|
+
background: transparent; border: 1px solid var(--dsw-alias-border-l2);
|
|
75
|
+
color: var(--dsw-alias-label-tertiary); border-radius: 4px; padding: 2px 8px;
|
|
76
|
+
font-size: 11px; cursor: pointer; transition: color 0.15s ease, border-color 0.15s ease;
|
|
152
77
|
}
|
|
153
78
|
.alg-btn-ghost:hover {
|
|
154
79
|
color: var(--dsw-alias-label-primary);
|
|
@@ -166,7 +91,6 @@ window.__ModuleLoader__.load({
|
|
|
166
91
|
document.head.appendChild(style);
|
|
167
92
|
}
|
|
168
93
|
}
|
|
169
|
-
|
|
170
94
|
const en = {
|
|
171
95
|
title: 'Agent Loop Guard',
|
|
172
96
|
sub: 'Fail-closed tool-call and assistant-output loop limits',
|
|
@@ -240,50 +164,27 @@ window.__ModuleLoader__.load({
|
|
|
240
164
|
ready: '保存配置',
|
|
241
165
|
saved: '配置已保存',
|
|
242
166
|
};
|
|
243
|
-
|
|
244
167
|
const DEFAULTS = {
|
|
245
|
-
maxToolAttemptsPerTurn: 64,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
strictTools: [],
|
|
250
|
-
strictToolLimit: 3,
|
|
251
|
-
blockExactDuplicates: true,
|
|
252
|
-
dryRunMode: false,
|
|
253
|
-
assistantOutputGuard: true,
|
|
254
|
-
maxRepeatedAssistantLines: 5,
|
|
255
|
-
maxRepeatedAssistantBlocks: 5,
|
|
256
|
-
maxAssistantBlockChars: 16384,
|
|
168
|
+
maxToolAttemptsPerTurn: 64, maxProgressToolCallsPerTurn: 16, progressToolNames: ['todo_write'],
|
|
169
|
+
maxCallsPerRepeatGroup: 5, strictTools: [], strictToolLimit: 3, blockExactDuplicates: true,
|
|
170
|
+
dryRunMode: false, assistantOutputGuard: true, maxRepeatedAssistantLines: 5,
|
|
171
|
+
maxRepeatedAssistantBlocks: 5, maxAssistantBlockChars: 16384,
|
|
257
172
|
};
|
|
258
173
|
|
|
259
174
|
function PluginCard({ ctx: _ctx, t, bare }) {
|
|
260
175
|
const [expanded, setExpanded] = React.useState(false);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
progressToolNamesText: 'todo_write',
|
|
264
|
-
strictToolsText: '',
|
|
265
|
-
});
|
|
176
|
+
const isExpanded = Boolean(bare || expanded);
|
|
177
|
+
const [draft, setDraft] = React.useState({ ...DEFAULTS, progressToolNamesText: 'todo_write', strictToolsText: '' });
|
|
266
178
|
const [status, setStatus] = React.useState('loading');
|
|
267
179
|
const [saving, setSaving] = React.useState(false);
|
|
268
180
|
const [msg, setMsg] = React.useState('');
|
|
269
181
|
|
|
270
|
-
// Updater state
|
|
271
182
|
const [updateState, setUpdateState] = React.useState({
|
|
272
|
-
checking: false,
|
|
273
|
-
|
|
274
|
-
currentVersion: '',
|
|
275
|
-
latestVersion: '',
|
|
276
|
-
updating: false,
|
|
277
|
-
notice: '',
|
|
278
|
-
error: '',
|
|
183
|
+
checking: false, updateAvailable: false, currentVersion: '', latestVersion: '',
|
|
184
|
+
updating: false, notice: '', error: '',
|
|
279
185
|
});
|
|
280
186
|
|
|
281
|
-
|
|
282
|
-
const [telemetry, setTelemetry] = React.useState({
|
|
283
|
-
totalViolations: 0,
|
|
284
|
-
byCode: {},
|
|
285
|
-
lastViolation: null,
|
|
286
|
-
});
|
|
187
|
+
const [telemetry, setTelemetry] = React.useState({ totalViolations: 0, byCode: {}, lastViolation: null });
|
|
287
188
|
|
|
288
189
|
const scopeRef = React.useRef(null);
|
|
289
190
|
if (!scopeRef.current && _ctx && _ctx.configForms) {
|
|
@@ -318,7 +219,6 @@ window.__ModuleLoader__.load({
|
|
|
318
219
|
return str;
|
|
319
220
|
};
|
|
320
221
|
|
|
321
|
-
// Load settings
|
|
322
222
|
React.useEffect(() => {
|
|
323
223
|
if (!scope) { setStatus('unavailable'); return; }
|
|
324
224
|
let cancelled = false;
|
|
@@ -335,9 +235,7 @@ window.__ModuleLoader__.load({
|
|
|
335
235
|
const names = Array.isArray(vals.progressToolNames) ? vals.progressToolNames : DEFAULTS.progressToolNames;
|
|
336
236
|
const strict = Array.isArray(vals.strictTools) ? vals.strictTools : DEFAULTS.strictTools;
|
|
337
237
|
setDraft((d) => ({
|
|
338
|
-
...d,
|
|
339
|
-
...DEFAULTS,
|
|
340
|
-
...vals,
|
|
238
|
+
...d, ...DEFAULTS, ...vals,
|
|
341
239
|
progressToolNamesText: names.join(', '),
|
|
342
240
|
strictToolsText: strict.join(', '),
|
|
343
241
|
}));
|
|
@@ -350,12 +248,10 @@ window.__ModuleLoader__.load({
|
|
|
350
248
|
return () => { cancelled = true; };
|
|
351
249
|
}, [scope]);
|
|
352
250
|
|
|
353
|
-
// Check updater and telemetry on expand
|
|
354
251
|
React.useEffect(() => {
|
|
355
|
-
if (!
|
|
252
|
+
if (!isExpanded) return;
|
|
356
253
|
let cancelled = false;
|
|
357
254
|
|
|
358
|
-
// Fetch update status
|
|
359
255
|
(async () => {
|
|
360
256
|
setUpdateState((s) => ({ ...s, checking: true, error: '', notice: '' }));
|
|
361
257
|
try {
|
|
@@ -364,11 +260,8 @@ window.__ModuleLoader__.load({
|
|
|
364
260
|
const data = await res.json();
|
|
365
261
|
if (cancelled) return;
|
|
366
262
|
setUpdateState((s) => ({
|
|
367
|
-
...s,
|
|
368
|
-
|
|
369
|
-
currentVersion: data.currentVersion || '',
|
|
370
|
-
latestVersion: data.latestVersion || '',
|
|
371
|
-
updateAvailable: !!data.updateAvailable,
|
|
263
|
+
...s, checking: false, currentVersion: data.currentVersion || '',
|
|
264
|
+
latestVersion: data.latestVersion || '', updateAvailable: !!data.updateAvailable,
|
|
372
265
|
}));
|
|
373
266
|
} catch (err) {
|
|
374
267
|
if (cancelled) return;
|
|
@@ -376,7 +269,6 @@ window.__ModuleLoader__.load({
|
|
|
376
269
|
}
|
|
377
270
|
})();
|
|
378
271
|
|
|
379
|
-
// Fetch telemetry
|
|
380
272
|
(async () => {
|
|
381
273
|
try {
|
|
382
274
|
const res = await fetch('/api/@goodandready/dsh-agent-loop-guard/telemetry');
|
|
@@ -396,19 +288,13 @@ window.__ModuleLoader__.load({
|
|
|
396
288
|
})();
|
|
397
289
|
|
|
398
290
|
return () => { cancelled = true; };
|
|
399
|
-
}, [
|
|
291
|
+
}, [isExpanded]);
|
|
400
292
|
|
|
401
293
|
async function onSave() {
|
|
402
294
|
if (!scope) { setMsg('Settings unavailable'); return; }
|
|
403
295
|
setSaving(true); setMsg('');
|
|
404
|
-
const names = String(draft.progressToolNamesText || '')
|
|
405
|
-
|
|
406
|
-
.map((s) => s.trim())
|
|
407
|
-
.filter(Boolean);
|
|
408
|
-
const strictNames = String(draft.strictToolsText || '')
|
|
409
|
-
.split(',')
|
|
410
|
-
.map((s) => s.trim())
|
|
411
|
-
.filter(Boolean);
|
|
296
|
+
const names = String(draft.progressToolNamesText || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
297
|
+
const strictNames = String(draft.strictToolsText || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
412
298
|
const maxToolAttempts = Number(draft.maxToolAttemptsPerTurn);
|
|
413
299
|
const payload = {
|
|
414
300
|
maxToolAttemptsPerTurn: Number.isFinite(maxToolAttempts) && maxToolAttempts >= 0 ? maxToolAttempts : 64,
|
|
@@ -441,22 +327,14 @@ window.__ModuleLoader__.load({
|
|
|
441
327
|
headers: { 'x-dsh-plugin-update': '1' },
|
|
442
328
|
});
|
|
443
329
|
const data = await res.json();
|
|
444
|
-
if (!res.ok || data.error)
|
|
445
|
-
throw new Error(data.error || 'Update failed with HTTP ' + res.status);
|
|
446
|
-
}
|
|
330
|
+
if (!res.ok || data.error) throw new Error(data.error || 'Update failed with HTTP ' + res.status);
|
|
447
331
|
setUpdateState((s) => ({
|
|
448
|
-
...s,
|
|
449
|
-
updating: false,
|
|
450
|
-
updateAvailable: false,
|
|
332
|
+
...s, updating: false, updateAvailable: false,
|
|
451
333
|
currentVersion: data.updatedVersion || s.latestVersion,
|
|
452
334
|
notice: tt('updateSuccess', { v: data.updatedVersion || s.latestVersion }),
|
|
453
335
|
}));
|
|
454
336
|
} catch (err) {
|
|
455
|
-
setUpdateState((s) => ({
|
|
456
|
-
...s,
|
|
457
|
-
updating: false,
|
|
458
|
-
error: tt('updateFailed', { msg: err.message || String(err) }),
|
|
459
|
-
}));
|
|
337
|
+
setUpdateState((s) => ({ ...s, updating: false, error: tt('updateFailed', { msg: err.message || String(err) }) }));
|
|
460
338
|
}
|
|
461
339
|
}
|
|
462
340
|
|
|
@@ -483,14 +361,8 @@ window.__ModuleLoader__.load({
|
|
|
483
361
|
}
|
|
484
362
|
return React.createElement('svg', {
|
|
485
363
|
className: 'alg-chevron' + (expanded ? ' expanded' : ''),
|
|
486
|
-
width: 14,
|
|
487
|
-
|
|
488
|
-
viewBox: '0 0 24 24',
|
|
489
|
-
fill: 'none',
|
|
490
|
-
stroke: 'currentColor',
|
|
491
|
-
strokeWidth: 2,
|
|
492
|
-
strokeLinecap: 'round',
|
|
493
|
-
strokeLinejoin: 'round',
|
|
364
|
+
width: 14, height: 14, viewBox: '0 0 24 24', fill: 'none',
|
|
365
|
+
stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
494
366
|
style: { flexShrink: 0 }
|
|
495
367
|
}, React.createElement('polyline', { points: '6 9 12 15 18 9' }));
|
|
496
368
|
};
|
|
@@ -507,16 +379,12 @@ window.__ModuleLoader__.load({
|
|
|
507
379
|
};
|
|
508
380
|
|
|
509
381
|
const num = (key) => React.createElement('input', {
|
|
510
|
-
type: 'number',
|
|
511
|
-
className: 'alg-input',
|
|
512
|
-
value: draft[key],
|
|
382
|
+
type: 'number', className: 'alg-input', value: draft[key],
|
|
513
383
|
onChange: (e) => setDraft((d) => ({ ...d, [key]: e.target.value })),
|
|
514
384
|
});
|
|
515
385
|
|
|
516
386
|
const str = (key) => React.createElement('input', {
|
|
517
|
-
type: 'text',
|
|
518
|
-
className: 'alg-input',
|
|
519
|
-
value: draft[key],
|
|
387
|
+
type: 'text', className: 'alg-input', value: draft[key],
|
|
520
388
|
onChange: (e) => setDraft((d) => ({ ...d, [key]: e.target.value })),
|
|
521
389
|
});
|
|
522
390
|
|
|
@@ -529,104 +397,99 @@ window.__ModuleLoader__.load({
|
|
|
529
397
|
);
|
|
530
398
|
|
|
531
399
|
const header = React.createElement('button', {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
400
|
+
className: 'alg-header-btn',
|
|
401
|
+
onClick: () => setExpanded(!expanded),
|
|
402
|
+
'aria-expanded': expanded,
|
|
403
|
+
},
|
|
404
|
+
React.createElement('span', { style: { display: 'flex', flexDirection: 'column' } },
|
|
405
|
+
React.createElement('span', { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 15, fontWeight: 600, display: 'flex', alignItems: 'center', gap: 8 } },
|
|
406
|
+
tt('title'),
|
|
407
|
+
React.createElement('span', { style: { fontSize: 11, fontWeight: 500, padding: '2px 6px', borderRadius: 6, background: 'color-mix(in srgb, var(--dsw-alias-accent-primary) 15%, transparent)', color: 'var(--dsw-alias-accent-primary)' } }, updateState.currentVersion ? 'v' + updateState.currentVersion : (updateState.checking ? '…' : '—'))
|
|
408
|
+
),
|
|
409
|
+
React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 13 } }, tt('sub'))
|
|
410
|
+
),
|
|
411
|
+
renderChevron()
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
const body = React.createElement('div', { className: 'alg-body' },
|
|
415
|
+
React.createElement('div', {
|
|
416
|
+
style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 0', borderBottom: '1px solid var(--dsw-alias-border-l2)' }
|
|
535
417
|
},
|
|
536
|
-
React.createElement('
|
|
537
|
-
React.createElement('
|
|
538
|
-
|
|
539
|
-
|
|
418
|
+
React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 2 } },
|
|
419
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
420
|
+
React.createElement('span', { style: { fontSize: 13, fontWeight: 500, color: 'var(--dsw-alias-label-primary)' } },
|
|
421
|
+
tt('version') + ': ' + (updateState.currentVersion ? 'v' + updateState.currentVersion : '—')
|
|
422
|
+
),
|
|
423
|
+
React.createElement('span', {
|
|
424
|
+
style: {
|
|
425
|
+
fontSize: 11, padding: '1px 6px', borderRadius: 4,
|
|
426
|
+
background: updateState.updateAvailable ? 'color-mix(in srgb, var(--dsw-alias-accent-primary) 15%, transparent)' : 'color-mix(in srgb, var(--dsw-alias-status-success) 15%, transparent)',
|
|
427
|
+
color: updateState.updateAvailable ? 'var(--dsw-alias-accent-primary)' : 'var(--dsw-alias-status-success)',
|
|
428
|
+
}
|
|
429
|
+
}, updateState.checking ? tt('updateChecking') : (updateState.updateAvailable ? tt('updateAvailable', { v: updateState.latestVersion }) : (updateState.currentVersion ? tt('upToDate') : '—')))
|
|
540
430
|
),
|
|
541
|
-
React.createElement('span', { style: { color: 'var(--dsw-alias-
|
|
431
|
+
updateState.error && React.createElement('span', { style: { color: 'var(--dsw-alias-status-danger)', fontSize: 12 } }, updateState.error)
|
|
542
432
|
),
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
433
|
+
updateState.updateAvailable && React.createElement('button', {
|
|
434
|
+
className: 'alg-btn-updater', onClick: onTriggerUpdate, disabled: updateState.updating,
|
|
435
|
+
}, updateState.updating ? tt('updating') : tt('updateNow'))
|
|
436
|
+
),
|
|
437
|
+
updateState.notice && React.createElement('div', {
|
|
438
|
+
style: { padding: '8px 12px', marginBottom: 12, background: 'color-mix(in srgb, var(--dsw-alias-status-success) 10%, transparent)', color: 'var(--dsw-alias-status-success)', borderRadius: 6, fontSize: 12, border: '1px solid color-mix(in srgb, var(--dsw-alias-status-success) 20%, transparent)' }
|
|
439
|
+
}, updateState.notice),
|
|
440
|
+
|
|
441
|
+
React.createElement('div', {
|
|
442
|
+
style: { padding: '12px 14px', margin: '14px 0', background: 'color-mix(in srgb, var(--dsw-alias-label-primary) 2%, transparent)', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l2)' }
|
|
547
443
|
},
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary)' } }, tt('version') + ': ' + (updateState.currentVersion || (updateState.checking ? '…' : '—'))),
|
|
554
|
-
updateState.checking && React.createElement('span', { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 } }, tt('updateChecking')),
|
|
555
|
-
!updateState.checking && updateState.updateAvailable && React.createElement('span', { style: { color: 'var(--dsw-alias-status-warning)', fontWeight: 600, fontSize: 12 } }, tt('updateAvailable', { v: updateState.latestVersion })),
|
|
556
|
-
!updateState.checking && !updateState.updateAvailable && !updateState.error && React.createElement('span', { style: { color: 'var(--dsw-alias-status-success)', fontSize: 12 } }, '✓ ' + tt('upToDate')),
|
|
557
|
-
updateState.error && React.createElement('span', { style: { color: 'var(--dsw-alias-status-danger)', fontSize: 12 } }, updateState.error)
|
|
558
|
-
),
|
|
559
|
-
updateState.updateAvailable && React.createElement('button', {
|
|
560
|
-
className: 'alg-btn-updater',
|
|
561
|
-
onClick: onTriggerUpdate,
|
|
562
|
-
disabled: updateState.updating,
|
|
563
|
-
}, updateState.updating ? tt('updating') : tt('updateNow'))
|
|
444
|
+
React.createElement('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 } },
|
|
445
|
+
React.createElement('span', { style: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' } }, tt('telemetryTitle')),
|
|
446
|
+
telemetry.totalViolations > 0 && React.createElement('button', {
|
|
447
|
+
className: 'alg-btn-ghost', onClick: onResetTelemetry,
|
|
448
|
+
}, tt('resetStats'))
|
|
564
449
|
),
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
React.createElement('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 } },
|
|
574
|
-
React.createElement('span', { style: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' } }, tt('telemetryTitle')),
|
|
575
|
-
telemetry.totalViolations > 0 && React.createElement('button', {
|
|
576
|
-
className: 'alg-btn-ghost',
|
|
577
|
-
onClick: onResetTelemetry,
|
|
578
|
-
}, tt('resetStats'))
|
|
579
|
-
),
|
|
580
|
-
React.createElement('div', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } },
|
|
581
|
-
telemetry.error
|
|
582
|
-
? React.createElement('span', { style: { color: 'var(--dsw-alias-status-danger)' } }, telemetry.error)
|
|
583
|
-
: telemetry.totalViolations > 0
|
|
584
|
-
? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
585
|
-
React.createElement('div', null, tt('totalBlocked') + ': ', React.createElement('strong', { style: { color: 'var(--dsw-alias-status-warning)' } }, telemetry.totalViolations)),
|
|
586
|
-
telemetry.lastViolation && React.createElement('div', { style: { color: 'var(--dsw-alias-label-tertiary)' } },
|
|
587
|
-
tt('lastViolation') + ': ' + telemetry.lastViolation.code + ' (' + telemetry.lastViolation.tool + ')'
|
|
588
|
-
)
|
|
450
|
+
React.createElement('div', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } },
|
|
451
|
+
telemetry.error
|
|
452
|
+
? React.createElement('span', { style: { color: 'var(--dsw-alias-status-danger)' } }, telemetry.error)
|
|
453
|
+
: telemetry.totalViolations > 0
|
|
454
|
+
? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
455
|
+
React.createElement('div', null, tt('totalBlocked') + ': ', React.createElement('strong', { style: { color: 'var(--dsw-alias-status-warning)' } }, telemetry.totalViolations)),
|
|
456
|
+
telemetry.lastViolation && React.createElement('div', { style: { color: 'var(--dsw-alias-label-tertiary)' } },
|
|
457
|
+
tt('lastViolation') + ': ' + telemetry.lastViolation.code + ' (' + telemetry.lastViolation.tool + ')'
|
|
589
458
|
)
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
),
|
|
593
|
-
|
|
594
|
-
// Form fields
|
|
595
|
-
field('maxToolAttemptsPerTurn', num('maxToolAttemptsPerTurn')),
|
|
596
|
-
field('maxProgressToolCallsPerTurn', num('maxProgressToolCallsPerTurn')),
|
|
597
|
-
field('maxCallsPerRepeatGroup', num('maxCallsPerRepeatGroup')),
|
|
598
|
-
field('strictTools', str('strictToolsText')),
|
|
599
|
-
field('strictToolLimit', num('strictToolLimit')),
|
|
600
|
-
check('blockExactDuplicates'),
|
|
601
|
-
check('dryRunMode'),
|
|
602
|
-
check('assistantOutputGuard'),
|
|
603
|
-
field('maxRepeatedAssistantLines', num('maxRepeatedAssistantLines')),
|
|
604
|
-
field('maxRepeatedAssistantBlocks', num('maxRepeatedAssistantBlocks')),
|
|
605
|
-
field('maxAssistantBlockChars', num('maxAssistantBlockChars')),
|
|
606
|
-
field('progressToolNames', str('progressToolNamesText')),
|
|
607
|
-
|
|
608
|
-
// Save button and status
|
|
609
|
-
React.createElement('div', {
|
|
610
|
-
style: { display: 'flex', alignItems: 'center', gap: 12, paddingTop: 14, borderTop: '1px solid var(--dsw-alias-border-l2)', marginTop: 10 }
|
|
611
|
-
},
|
|
612
|
-
React.createElement('button', {
|
|
613
|
-
className: 'alg-btn-primary',
|
|
614
|
-
onClick: onSave,
|
|
615
|
-
disabled: saving || status !== 'ready',
|
|
616
|
-
}, saving ? tt('saving') : tt('ready')),
|
|
617
|
-
msg && React.createElement('span', { style: { fontSize: 13, color: msg === tt('saved') || msg === tt('statsResetDone') ? 'var(--dsw-alias-status-success)' : 'var(--dsw-alias-status-danger)' } }, msg)
|
|
459
|
+
)
|
|
460
|
+
: React.createElement('span', { style: { color: 'var(--dsw-alias-label-tertiary)' } }, tt('noViolations'))
|
|
618
461
|
)
|
|
619
|
-
)
|
|
462
|
+
),
|
|
463
|
+
|
|
464
|
+
field('maxToolAttemptsPerTurn', num('maxToolAttemptsPerTurn')),
|
|
465
|
+
field('maxProgressToolCallsPerTurn', num('maxProgressToolCallsPerTurn')),
|
|
466
|
+
field('maxCallsPerRepeatGroup', num('maxCallsPerRepeatGroup')),
|
|
467
|
+
field('strictTools', str('strictToolsText')),
|
|
468
|
+
field('strictToolLimit', num('strictToolLimit')),
|
|
469
|
+
check('blockExactDuplicates'),
|
|
470
|
+
check('dryRunMode'),
|
|
471
|
+
check('assistantOutputGuard'),
|
|
472
|
+
field('maxRepeatedAssistantLines', num('maxRepeatedAssistantLines')),
|
|
473
|
+
field('maxRepeatedAssistantBlocks', num('maxRepeatedAssistantBlocks')),
|
|
474
|
+
field('maxAssistantBlockChars', num('maxAssistantBlockChars')),
|
|
475
|
+
field('progressToolNames', str('progressToolNamesText')),
|
|
476
|
+
|
|
477
|
+
React.createElement('div', {
|
|
478
|
+
style: { display: 'flex', alignItems: 'center', gap: 12, paddingTop: 14, borderTop: '1px solid var(--dsw-alias-border-l2)', marginTop: 10 }
|
|
479
|
+
},
|
|
480
|
+
React.createElement('button', {
|
|
481
|
+
className: 'alg-btn-primary', onClick: onSave, disabled: saving || status !== 'ready',
|
|
482
|
+
}, saving ? tt('saving') : tt('ready')),
|
|
483
|
+
msg && React.createElement('span', { style: { fontSize: 13, color: msg === tt('saved') || msg === tt('statsResetDone') ? 'var(--dsw-alias-status-success)' : 'var(--dsw-alias-status-danger)' } }, msg)
|
|
484
|
+
)
|
|
485
|
+
);
|
|
620
486
|
|
|
621
|
-
// The Plugins page renders this entry bare: it draws the title, the icon
|
|
622
|
-
// and the crumb itself, so the row seat must not add a second card frame.
|
|
623
487
|
if (bare) {
|
|
624
488
|
return React.createElement('div', { className: 'alg-page' }, body);
|
|
625
489
|
}
|
|
626
490
|
return React.createElement('li', { className: 'alg-card' }, header, expanded && body);
|
|
627
491
|
}
|
|
628
492
|
|
|
629
|
-
// Row seat component: summary one-liner plus the bare form on the page.
|
|
630
493
|
function PluginItem(props) {
|
|
631
494
|
if (props && props.view === 'summary') {
|
|
632
495
|
return React.createElement('div', {
|
|
@@ -635,7 +498,6 @@ window.__ModuleLoader__.load({
|
|
|
635
498
|
}
|
|
636
499
|
return React.createElement(PluginCard, { ...props, bare: true });
|
|
637
500
|
}
|
|
638
|
-
|
|
639
501
|
exports.inject = ['slots', 'configForms', 'locale'];
|
|
640
502
|
exports.apply = function apply(ctx) {
|
|
641
503
|
if (typeof ctx.locale?.register === 'function') {
|
|
@@ -671,9 +533,6 @@ window.__ModuleLoader__.load({
|
|
|
671
533
|
}
|
|
672
534
|
}
|
|
673
535
|
|
|
674
|
-
// Row seat first: the current core renders the Plugins page and opens
|
|
675
|
-
// this entry from the row's configure control. The older seats stay as
|
|
676
|
-
// fallbacks for hosts that only declare them.
|
|
677
536
|
registerSlotWhenReady('plugins.row.config', () =>
|
|
678
537
|
ctx.slots.register(
|
|
679
538
|
{
|
|
@@ -687,12 +546,6 @@ window.__ModuleLoader__.load({
|
|
|
687
546
|
)
|
|
688
547
|
);
|
|
689
548
|
|
|
690
|
-
// List seat (plugins.item): the seat the Plugins page really renders as the
|
|
691
|
-
// plugin's own page with its configuration — the page draws the title, icon
|
|
692
|
-
// and crumb and asks for view 'summary' (the card's one-liner) or view 'page'
|
|
693
|
-
// (the form), both served by PluginItem. The label is a static string on
|
|
694
|
-
// purpose: it is resolved while the page renders, and a locale lookup there
|
|
695
|
-
// would take the whole client batch down with it.
|
|
696
549
|
registerSlotWhenReady('plugins.item', () =>
|
|
697
550
|
ctx.slots.register(
|
|
698
551
|
{
|
|
@@ -720,7 +573,6 @@ window.__ModuleLoader__.load({
|
|
|
720
573
|
)
|
|
721
574
|
);
|
|
722
575
|
};
|
|
723
|
-
|
|
724
576
|
return module.exports;
|
|
725
577
|
},
|
|
726
578
|
});
|
package/lib/guard-state.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
const STOP_REQUEST_PATTERN = /(?:\b(?:stop|halt|cancel|answer(?:\s+now)?)\b|(?<![\p{L}\p{N}_-])стоп(?![\p{L}\p{N}_-])|останов(?:ись|ить)|прекрати|хватит|ответь|петл[яиюе])/iu;
|
|
2
3
|
const SECRET_KEY_PATTERN = /(?:token|secret|password|authorization|api[-_]?key|cookie)/iu;
|
|
3
4
|
|
|
@@ -56,18 +57,32 @@ export function hasStopRequest(messages) {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
export function callFingerprint(name, args) {
|
|
59
|
-
try {
|
|
60
|
-
|
|
60
|
+
try {
|
|
61
|
+
const raw = stableJson(args);
|
|
62
|
+
const body = raw.length > 256 ? 'sha256:' + createHash('sha256').update(raw).digest('hex') : raw;
|
|
63
|
+
return String(name) + ':' + body;
|
|
64
|
+
} catch {
|
|
65
|
+
return String(name) + ':<unserializable>';
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
export function callRepeatFingerprint(name, args) {
|
|
64
|
-
try {
|
|
65
|
-
|
|
70
|
+
try {
|
|
71
|
+
const raw = normalizedJson(args);
|
|
72
|
+
const body = raw.length > 256 ? 'sha256:' + createHash('sha256').update(raw).digest('hex') : raw;
|
|
73
|
+
return String(name) + ':' + body;
|
|
74
|
+
} catch {
|
|
75
|
+
return String(name) + ':<unserializable>';
|
|
76
|
+
}
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
export function resultFingerprint(value) {
|
|
69
|
-
try {
|
|
70
|
-
|
|
80
|
+
try {
|
|
81
|
+
const raw = stableJson(value);
|
|
82
|
+
return raw.length > 256 ? 'sha256:' + createHash('sha256').update(raw).digest('hex') : raw;
|
|
83
|
+
} catch {
|
|
84
|
+
return '<unserializable-result>';
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
export function safeCallSummary(name, args) {
|
|
@@ -200,6 +215,14 @@ export class LoopGuardState {
|
|
|
200
215
|
this.metrics.lastViolation = null;
|
|
201
216
|
}
|
|
202
217
|
|
|
218
|
+
disposeSession(sessionId) {
|
|
219
|
+
if (sessionId === undefined || sessionId === null) return;
|
|
220
|
+
const id = typeof sessionId === 'object' ? (sessionId.id ?? sessionId) : sessionId;
|
|
221
|
+
const str = String(id);
|
|
222
|
+
this.byAgent.delete('session:' + str);
|
|
223
|
+
this.byAgent.delete(str);
|
|
224
|
+
}
|
|
225
|
+
|
|
203
226
|
agentKey(agent) {
|
|
204
227
|
if (agent !== null && typeof agent === 'object') {
|
|
205
228
|
const sessionId = agent.session?.id ?? agent.session?.header?.id ?? agent.id;
|
|
@@ -224,6 +247,7 @@ export class LoopGuardState {
|
|
|
224
247
|
stopRequested: false,
|
|
225
248
|
answerOnly: false,
|
|
226
249
|
stopReason: '',
|
|
250
|
+
blockReason: undefined,
|
|
227
251
|
progressEpoch: 0,
|
|
228
252
|
repeatGroups: new Map(),
|
|
229
253
|
exactGroups: new Map(),
|
|
@@ -239,10 +263,14 @@ export class LoopGuardState {
|
|
|
239
263
|
if (prior === undefined || prior.turn !== turn) {
|
|
240
264
|
const next = this.emptyState(turn);
|
|
241
265
|
next.stopRequested = Boolean(stopRequested);
|
|
266
|
+
if (stopRequested) next.blockReason = 'LOOP_GUARD_STOP';
|
|
242
267
|
this.byAgent.set(key, next);
|
|
243
268
|
return;
|
|
244
269
|
}
|
|
245
|
-
if (stopRequested)
|
|
270
|
+
if (stopRequested) {
|
|
271
|
+
prior.stopRequested = true;
|
|
272
|
+
prior.blockReason = 'LOOP_GUARD_STOP';
|
|
273
|
+
}
|
|
246
274
|
}
|
|
247
275
|
|
|
248
276
|
stateFor(agent) {
|
|
@@ -257,16 +285,28 @@ export class LoopGuardState {
|
|
|
257
285
|
|
|
258
286
|
findCall(state, callId) {
|
|
259
287
|
if (typeof callId === 'string' && callId.length > 0) {
|
|
260
|
-
const exact =
|
|
288
|
+
const exact = state.calls.findLast((call) => call.id === callId && !call.released);
|
|
261
289
|
if (exact !== undefined) return exact;
|
|
262
290
|
}
|
|
263
|
-
return
|
|
291
|
+
return state.calls.findLast((call) => !call.released && !call.resultSeen);
|
|
264
292
|
}
|
|
265
293
|
|
|
266
294
|
decrementReservations(state, call) {
|
|
267
295
|
if (!call || !call.counted || call.committed) return;
|
|
268
296
|
state.attemptsSinceProgress = Math.max(0, state.attemptsSinceProgress - 1);
|
|
269
297
|
if (call.isProgressTool) state.progressAttemptsSinceProgress = Math.max(0, state.progressAttemptsSinceProgress - 1);
|
|
298
|
+
if (call.repeatFingerprint) {
|
|
299
|
+
const group = state.repeatGroups.get(call.repeatFingerprint);
|
|
300
|
+
if (group && group.progressEpoch === state.progressEpoch && group.count > 0) {
|
|
301
|
+
group.count = Math.max(0, group.count - 1);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (call.fingerprint) {
|
|
305
|
+
const exact = state.exactGroups.get(call.fingerprint);
|
|
306
|
+
if (exact && exact.progressEpoch === state.progressEpoch && exact.count > 0) {
|
|
307
|
+
exact.count = Math.max(0, exact.count - 1);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
270
310
|
}
|
|
271
311
|
|
|
272
312
|
violation(state, agent, name, args, callId, code, detail) {
|
|
@@ -305,6 +345,9 @@ export class LoopGuardState {
|
|
|
305
345
|
|
|
306
346
|
state.answerOnly = true;
|
|
307
347
|
state.stopReason = code + ': ' + detail;
|
|
348
|
+
if (!state.blockReason) {
|
|
349
|
+
state.blockReason = code;
|
|
350
|
+
}
|
|
308
351
|
|
|
309
352
|
let guidance = 'ACTION REQUIRED: ';
|
|
310
353
|
if (code === 'LOOP_GUARD_STOP') {
|
|
@@ -330,7 +373,8 @@ export class LoopGuardState {
|
|
|
330
373
|
return this.violation(state, agent, name, args, callId, 'LOOP_GUARD_STOP', 'user requested stop; tools are disabled for this turn');
|
|
331
374
|
}
|
|
332
375
|
if (state.answerOnly) {
|
|
333
|
-
|
|
376
|
+
const code = state.blockReason || 'LOOP_GUARD_STOP';
|
|
377
|
+
return this.violation(state, agent, name, args, callId, code, state.stopReason || 'previous guard violation requires a text answer');
|
|
334
378
|
}
|
|
335
379
|
const fingerprint = callFingerprint(name, args);
|
|
336
380
|
const repeatFingerprint = callRepeatFingerprint(name, args);
|
|
@@ -342,11 +386,13 @@ export class LoopGuardState {
|
|
|
342
386
|
const isStrictTool = this.strictTools.has(String(name));
|
|
343
387
|
const maxRepeats = isStrictTool ? this.config.strictToolLimit : this.config.maxCallsPerRepeatGroup;
|
|
344
388
|
|
|
389
|
+
if (this.config.blockExactDuplicates && exactCount >= 1) {
|
|
390
|
+
return this.violation(state, agent, name, args, callId, 'LOOP_GUARD_DUPLICATE', 'identical tool call repeated without a new result or state change after ' + exactCount + ' attempts');
|
|
391
|
+
}
|
|
392
|
+
|
|
345
393
|
if (repeatCount >= maxRepeats) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
return this.violation(state, agent, name, args, callId, 'LOOP_GUARD_REPEAT', 'near-identical tool call repeated without a new result or state change after ' + repeatCount + ' attempts');
|
|
394
|
+
const code = (this.config.blockExactDuplicates && exactCount >= maxRepeats) ? 'LOOP_GUARD_DUPLICATE' : 'LOOP_GUARD_REPEAT';
|
|
395
|
+
return this.violation(state, agent, name, args, callId, code, 'near-identical tool call repeated without a new result or state change after ' + repeatCount + ' attempts');
|
|
350
396
|
}
|
|
351
397
|
const isProgressTool = this.progressToolNames.has(String(name));
|
|
352
398
|
if (isProgressTool) {
|
|
@@ -436,4 +482,4 @@ export class LoopGuardState {
|
|
|
436
482
|
}
|
|
437
483
|
return { known: outcome.known, productive };
|
|
438
484
|
}
|
|
439
|
-
}
|
|
485
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -283,7 +283,10 @@ export function apply(ctx, config = {}) {
|
|
|
283
283
|
return;
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
|
-
ctx.on('session/disposed', (session) =>
|
|
286
|
+
ctx.on('session/disposed', (session) => {
|
|
287
|
+
assistantState.dispose(session.id);
|
|
288
|
+
state.disposeSession(session.id);
|
|
289
|
+
});
|
|
287
290
|
|
|
288
291
|
return ctx.tools.guard((execution) => state.denyReason(execution.agent, execution.name, execution.arguments, execution.callId));
|
|
289
|
-
}
|
|
292
|
+
}
|
package/lib/plugin-updater.js
CHANGED
|
@@ -22,6 +22,17 @@ export function isLoopback(value) {
|
|
|
22
22
|
|| address?.startsWith('::ffff:127.') === true;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
export function isPrivateLan(value) {
|
|
26
|
+
const address = value?.toLowerCase().replace(/^\[|\]$/g, '');
|
|
27
|
+
if (!address) return false;
|
|
28
|
+
const ipv4 = address.startsWith('::ffff:') ? address.slice(7) : address;
|
|
29
|
+
return (
|
|
30
|
+
ipv4.startsWith('192.168.') ||
|
|
31
|
+
ipv4.startsWith('10.') ||
|
|
32
|
+
/^172\.(1[6-9]|2[0-9]|3[0-1])\./.test(ipv4)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
25
36
|
export function isTrustedTelemetryRequest(request) {
|
|
26
37
|
if (!isLoopback(request.socket?.remoteAddress)) return false;
|
|
27
38
|
const site = header(request, 'sec-fetch-site');
|
|
@@ -33,7 +44,7 @@ export function isTrustedTelemetryRequest(request) {
|
|
|
33
44
|
try {
|
|
34
45
|
const url = new URL(origin);
|
|
35
46
|
return (url.protocol === 'http:' || url.protocol === 'https:')
|
|
36
|
-
&& isLoopback(url.hostname) && url.host === host;
|
|
47
|
+
&& (isLoopback(url.hostname) || isPrivateLan(url.hostname)) && url.host === host;
|
|
37
48
|
} catch {
|
|
38
49
|
return false;
|
|
39
50
|
}
|
|
@@ -52,7 +63,7 @@ export function isTrustedUpdateRequest(request) {
|
|
|
52
63
|
try {
|
|
53
64
|
const url = new URL(origin);
|
|
54
65
|
return (url.protocol === 'http:' || url.protocol === 'https:')
|
|
55
|
-
&& isLoopback(url.hostname) && url.host === host;
|
|
66
|
+
&& (isLoopback(url.hostname) || isPrivateLan(url.hostname)) && url.host === host;
|
|
56
67
|
} catch {
|
|
57
68
|
return false;
|
|
58
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-agent-loop-guard",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Fail-closed runtime tool-call loop guard for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "node --test",
|
|
24
|
-
"check": "node --check lib/index.js && node --check lib/guard-state.js && node --check lib/assistant-output-state.js && node --check lib/plugin-updater.js && node --check lib/client.js"
|
|
24
|
+
"check": "node --check lib/index.js && node --check lib/guard-state.js && node --check lib/assistant-output-state.js && node --check lib/plugin-updater.js && node --check lib/client.js",
|
|
25
|
+
"build:client": "node scripts/build-client.mjs",
|
|
26
|
+
"pretest": "node scripts/build-client.mjs",
|
|
27
|
+
"clean": "rm -f *.tgz"
|
|
25
28
|
},
|
|
26
29
|
"dsh": {
|
|
27
30
|
"bundle": {
|