@goodandready/dsh-agent-loop-guard 0.2.29 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +5 -1
- package/README.ru.md +5 -1
- package/README.zh.md +5 -1
- package/lib/client.js +462 -503
- package/lib/guard-helpers.js +380 -264
- package/lib/guard-state.js +94 -40
- package/lib/index.js +4 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -19,509 +19,468 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
} catch (err) {
|
|
20
20
|
console.warn?.('[dsh-agent-loop-guard] primitives unavailable, using SVG fallback:', err?.message || String(err));
|
|
21
21
|
}
|
|
22
|
-
const CSS_STYLES = `
|
|
23
|
-
.alg-page { width: 100%; min-width: 0; }
|
|
24
|
-
.alg-card {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
.alg-
|
|
30
|
-
.alg-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
.alg-
|
|
37
|
-
.alg-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
.alg-
|
|
43
|
-
.alg-
|
|
44
|
-
.alg-
|
|
45
|
-
.alg-
|
|
46
|
-
.alg-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
),
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
),
|
|
485
|
-
|
|
486
|
-
field('maxToolAttemptsPerTurn', num('maxToolAttemptsPerTurn')),
|
|
487
|
-
field('maxProgressToolCallsPerTurn', num('maxProgressToolCallsPerTurn')),
|
|
488
|
-
field('maxCallsPerRepeatGroup', num('maxCallsPerRepeatGroup')),
|
|
489
|
-
field('strictTools', str('strictToolsText')),
|
|
490
|
-
field('strictToolLimit', num('strictToolLimit')),
|
|
491
|
-
check('blockExactDuplicates'),
|
|
492
|
-
check('dryRunMode'),
|
|
493
|
-
check('assistantOutputGuard'),
|
|
494
|
-
field('maxRepeatedAssistantLines', num('maxRepeatedAssistantLines')),
|
|
495
|
-
field('maxRepeatedAssistantBlocks', num('maxRepeatedAssistantBlocks')),
|
|
496
|
-
field('maxAssistantBlockChars', num('maxAssistantBlockChars')),
|
|
497
|
-
field('progressToolNames', str('progressToolNamesText')),
|
|
498
|
-
field('pseudoToolCallThreshold', num('pseudoToolCallThreshold')),
|
|
499
|
-
check('oscillationDetection'),
|
|
500
|
-
field('maxOscillationRepeats', num('maxOscillationRepeats')),
|
|
501
|
-
check('payloadBloatGuard'),
|
|
502
|
-
field('maxToolResultChars', num('maxToolResultChars')),
|
|
503
|
-
|
|
504
|
-
React.createElement('div', {
|
|
505
|
-
style: { display: 'flex', alignItems: 'center', gap: 12, paddingTop: 14, borderTop: '1px solid var(--dsw-alias-border-l2)', marginTop: 10 }
|
|
506
|
-
},
|
|
507
|
-
React.createElement('button', {
|
|
508
|
-
className: 'alg-btn-primary', onClick: onSave, disabled: saving || status !== 'ready',
|
|
509
|
-
}, saving ? tt('saving') : tt('ready')),
|
|
510
|
-
msg && React.createElement('span', { style: { fontSize: 13, color: msg === tt('saved') || msg === tt('statsResetDone') ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)' } }, msg)
|
|
511
|
-
)
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
if (isBare) return React.createElement('div', { className: 'alg-page' }, body);
|
|
515
|
-
return React.createElement('li', { className: 'alg-card' }, header, expanded && body);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
function PluginItem(props) {
|
|
519
|
-
if (props && props.view === 'summary') {
|
|
520
|
-
return React.createElement('div', { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 13 } }, en.sub);
|
|
521
|
-
}
|
|
522
|
-
return React.createElement(PluginCard, { ...props, bare: Boolean(props && (props.bare || props.view === 'page')) });
|
|
523
|
-
}
|
|
524
|
-
|
|
22
|
+
const CSS_STYLES = `
|
|
23
|
+
.alg-page { width: 100%; min-width: 0; }
|
|
24
|
+
.alg-card { border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-3); border-radius: 12px; list-style: none; margin-bottom: 12px; overflow: hidden; transition: border-color 0.15s ease; }
|
|
25
|
+
.alg-card:hover { border-color: var(--dsw-alias-border-l1, var(--dsw-alias-border-l2)); }
|
|
26
|
+
.alg-header-btn { appearance: none; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; background: transparent; border: 0; border-radius: 12px; display: flex; align-items: center; gap: 12px; padding: 14px 16px; transition: background 0.15s ease; }
|
|
27
|
+
.alg-header-btn:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
28
|
+
.alg-chevron { margin-left: auto; color: var(--dsw-alias-label-tertiary); display: flex; align-items: center; justify-content: center; transition: transform 0.2s ease; }
|
|
29
|
+
.alg-chevron.expanded { transform: rotate(180deg); }
|
|
30
|
+
.alg-body { padding: 0 16px 16px; border-top: 1px solid var(--dsw-alias-border-l2); }
|
|
31
|
+
.alg-field { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; }
|
|
32
|
+
.alg-field label { font-size: 13px; color: var(--dsw-alias-label-secondary); cursor: pointer; }
|
|
33
|
+
.alg-input { height: 34px; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); border-radius: 8px; padding: 0 12px; font-size: 13px; outline: none; transition: border-color 0.15s ease; }
|
|
34
|
+
.alg-input:focus { border-color: var(--dsw-alias-brand-primary); }
|
|
35
|
+
.alg-checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dsw-alias-label-primary); cursor: pointer; padding: 5px 0; }
|
|
36
|
+
.alg-btn-primary { appearance: none; font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 6px 16px; font-size: 13px; font-weight: 500; background: var(--dsw-alias-brand-primary); color: var(--dsw-alias-label-primary-inverted, var(--dsw-alias-bg-layer-3)); transition: opacity 0.15s ease; }
|
|
37
|
+
.alg-btn-primary:hover:not(:disabled) { opacity: 0.9; }
|
|
38
|
+
.alg-btn-primary:disabled { opacity: 0.5; cursor: default; }
|
|
39
|
+
.alg-btn-updater { appearance: none; font: inherit; cursor: pointer; border: 0; border-radius: 6px; padding: 4px 10px; font-size: 12px; font-weight: 500; background: var(--dsw-alias-brand-primary); color: var(--dsw-alias-label-primary-inverted, var(--dsw-alias-bg-layer-3)); transition: opacity 0.15s ease; }
|
|
40
|
+
.alg-btn-updater:hover:not(:disabled) { opacity: 0.9; }
|
|
41
|
+
.alg-btn-updater:disabled { opacity: 0.6; cursor: default; }
|
|
42
|
+
.alg-btn-ghost { background: transparent; border: 1px solid var(--dsw-alias-border-l2); color: var(--dsw-alias-label-tertiary); border-radius: 4px; padding: 2px 8px; font-size: 11px; cursor: pointer; transition: color 0.15s ease, border-color 0.15s ease; }
|
|
43
|
+
.alg-btn-ghost:hover { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-label-secondary); }
|
|
44
|
+
.alg-presets { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--dsw-alias-border-l2); margin-bottom: 8px; flex-wrap: wrap; }
|
|
45
|
+
.alg-btn-preset { appearance: none; font: inherit; cursor: pointer; border: 1px solid var(--dsw-alias-border-l2); border-radius: 6px; padding: 3px 10px; font-size: 12px; background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-secondary); transition: all 0.15s ease; }
|
|
46
|
+
.alg-btn-preset:hover { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-label-primary); }
|
|
47
|
+
.alg-incident-row { display: flex; align-items: center; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid color-mix(in srgb, var(--dsw-alias-border-l2) 40%, transparent); font-size: 11px; }
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
if (typeof document !== 'undefined') {
|
|
51
|
+
const styleId = 'dsh-agent-loop-guard-styles';
|
|
52
|
+
if (!document.getElementById(styleId)) {
|
|
53
|
+
const style = document.createElement('style');
|
|
54
|
+
style.id = styleId;
|
|
55
|
+
style.setAttribute('data-dsh-plugin', '@goodandready/dsh-agent-loop-guard');
|
|
56
|
+
style.textContent = CSS_STYLES;
|
|
57
|
+
document.head.appendChild(style);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const en = {
|
|
61
|
+
title: 'Agent Loop Guard', sub: 'Fail-closed tool-call and assistant-output loop limits',
|
|
62
|
+
version: 'Version', updateChecking: 'Checking updates…', updateAvailable: 'Update available: v{v}',
|
|
63
|
+
upToDate: 'Up to date', updateNow: 'Update Now', updateViaPluginsPage: 'Update in Plugins page',
|
|
64
|
+
updating: 'Updating…', updateSuccess: 'Updated to v{v}. Restart DSH service to apply changes.',
|
|
65
|
+
updateFailed: 'Update failed: {msg}', checkUpdateFailed: 'Check failed',
|
|
66
|
+
telemetryTitle: 'Protection Telemetry', telemetryLoadFailed: 'Failed to load telemetry',
|
|
67
|
+
totalBlocked: 'Loops Prevented', steeredCount: 'Smart Steers', lastViolation: 'Last Incident',
|
|
68
|
+
noViolations: 'No loop violations detected in current runtime.', resetStats: 'Reset Stats',
|
|
69
|
+
statsResetDone: 'Stats reset', statsResetFailed: 'Failed to reset stats',
|
|
70
|
+
presetsTitle: 'Presets', presetStrict: 'Strict', presetBalanced: 'Balanced', presetAutonomous: 'Autonomous Coding',
|
|
71
|
+
presetApplied: 'Preset {name} applied to form', copyDump: 'Copy Diagnostic Dump', dumpCopied: 'Diagnostic dump copied to clipboard',
|
|
72
|
+
maxToolAttemptsPerTurn: 'Max tool attempts per turn (0 = disabled)', maxProgressToolCallsPerTurn: 'Max progress tool calls per turn',
|
|
73
|
+
maxCallsPerRepeatGroup: 'Max calls per repeat group', strictTools: 'Strict tools (comma-separated, lower limit)',
|
|
74
|
+
strictToolLimit: 'Strict tools limit', blockExactDuplicates: 'Block exact duplicate tool calls',
|
|
75
|
+
dryRunMode: 'Dry-run / Audit mode (log only, do not reject)', assistantOutputGuard: 'Assistant output guard',
|
|
76
|
+
maxRepeatedAssistantLines: 'Max repeated assistant lines', maxRepeatedAssistantBlocks: 'Max repeated assistant blocks',
|
|
77
|
+
maxAssistantBlockChars: 'Max assistant block chars', progressToolNames: 'Progress tool names (comma-separated)',
|
|
78
|
+
pseudoToolCallThreshold: 'Pseudo tool-call loop threshold (turns, 0 = disabled)', oscillationDetection: 'Oscillation loop guard (ping-pong cycles)',
|
|
79
|
+
maxOscillationRepeats: 'Max oscillation repeats (2-4 step cycles)', payloadBloatGuard: 'Payload bloat guard (truncate huge outputs)',
|
|
80
|
+
maxToolResultChars: 'Max tool result characters (0 = disabled)', errorThrashingGuard: 'Error thrashing guard (fail-loop detection)',
|
|
81
|
+
maxConsecutiveFailures: 'Max consecutive failures before thrashing block', adaptiveSteering: 'Smart steering (guide agent before hard cancel)',
|
|
82
|
+
saving: 'Saving…', ready: 'Save Settings', saved: 'Saved',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const zh = {
|
|
86
|
+
title: 'Agent Loop Guard', sub: '工具调用与助手输出防死循环熔断限制',
|
|
87
|
+
version: '版本', updateChecking: '正在检查更新…', updateAvailable: '发现新版本: v{v}',
|
|
88
|
+
upToDate: '已是最新版本', updateNow: '立即更新', updateViaPluginsPage: '请在插件页面更新',
|
|
89
|
+
updating: '正在更新…', updateSuccess: '已更新至 v{v}。请重启 DSH 服务以生效变更。',
|
|
90
|
+
updateFailed: '更新失败: {msg}', checkUpdateFailed: '检查更新失败',
|
|
91
|
+
telemetryTitle: '防护运行遥测', telemetryLoadFailed: '获取遥测数据失败',
|
|
92
|
+
totalBlocked: '已拦截死循环', steeredCount: '自纠正引导次数', lastViolation: '最近拦截事件',
|
|
93
|
+
noViolations: '当前运行时未检测到死循环违规。', resetStats: '重置统计',
|
|
94
|
+
statsResetDone: '统计已重置', statsResetFailed: '重置统计失败',
|
|
95
|
+
presetsTitle: '灵敏度预设', presetStrict: '严格', presetBalanced: '平衡', presetAutonomous: '自主编程',
|
|
96
|
+
presetApplied: '已应用预设: {name}', copyDump: '复制诊断数据', dumpCopied: '诊断数据已复制到剪贴板',
|
|
97
|
+
maxToolAttemptsPerTurn: '单回合最大工具尝试次数(0 表示禁用)', maxProgressToolCallsPerTurn: '单回合最大进度工具调用次数',
|
|
98
|
+
maxCallsPerRepeatGroup: '同组工具最大重复调用次数', strictTools: '严格限制工具(逗号分隔,触发更低阈值)',
|
|
99
|
+
strictToolLimit: '严格工具调用上限', blockExactDuplicates: '立即拦截完全相同的重复工具调用',
|
|
100
|
+
dryRunMode: '审计模拟模式(仅记录日志,不实际拦截)', assistantOutputGuard: '助手文本输出防循环守卫',
|
|
101
|
+
maxRepeatedAssistantLines: '最大单行重复次数', maxRepeatedAssistantBlocks: '最大段落重复次数',
|
|
102
|
+
maxAssistantBlockChars: '最大段落判定字符数', progressToolNames: '进度标记工具(逗号分隔)',
|
|
103
|
+
pseudoToolCallThreshold: '伪工具调用空转拦截阈值(连续回合数,0 表示禁用)', oscillationDetection: '交替循环拦截(乒乓震荡检测)',
|
|
104
|
+
maxOscillationRepeats: '最大交替循环重复次数(2-4 步序列)', payloadBloatGuard: '超大结果防膨胀拦截(截断巨大输出)',
|
|
105
|
+
maxToolResultChars: '工具结果字符上限(0 表示禁用)', errorThrashingGuard: '工具重复报错拦截(错误循环保护)',
|
|
106
|
+
maxConsecutiveFailures: '连续报错熔断阈值', adaptiveSteering: '智能自纠正(熔断前引导修正)',
|
|
107
|
+
saving: '正在保存…', ready: '保存配置', saved: '配置已保存',
|
|
108
|
+
};
|
|
109
|
+
const DEFAULTS = {
|
|
110
|
+
maxToolAttemptsPerTurn: 64, maxProgressToolCallsPerTurn: 16, progressToolNames: ['todo_write'],
|
|
111
|
+
maxCallsPerRepeatGroup: 5, strictTools: [], strictToolLimit: 3, blockExactDuplicates: true,
|
|
112
|
+
dryRunMode: false, assistantOutputGuard: true, maxRepeatedAssistantLines: 5,
|
|
113
|
+
maxRepeatedAssistantBlocks: 5, maxAssistantBlockChars: 16384, pseudoToolCallThreshold: 3,
|
|
114
|
+
oscillationDetection: true, maxOscillationRepeats: 3, payloadBloatGuard: true, maxToolResultChars: 65536,
|
|
115
|
+
errorThrashingGuard: true, maxConsecutiveFailures: 4, adaptiveSteering: true,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const CLIENT_PRESETS = {
|
|
119
|
+
strict: {
|
|
120
|
+
maxToolAttemptsPerTurn: 10, maxProgressToolCallsPerTurn: 3, maxCallsPerRepeatGroup: 2,
|
|
121
|
+
strictToolLimit: 1, blockExactDuplicates: true, oscillationDetection: true, maxOscillationRepeats: 2,
|
|
122
|
+
errorThrashingGuard: true, maxConsecutiveFailures: 3, payloadBloatGuard: true, maxToolResultChars: 32768,
|
|
123
|
+
pseudoToolCallThreshold: 2, adaptiveSteering: true,
|
|
124
|
+
},
|
|
125
|
+
balanced: {
|
|
126
|
+
maxToolAttemptsPerTurn: 16, maxProgressToolCallsPerTurn: 6, maxCallsPerRepeatGroup: 3,
|
|
127
|
+
strictToolLimit: 2, blockExactDuplicates: true, oscillationDetection: true, maxOscillationRepeats: 3,
|
|
128
|
+
errorThrashingGuard: true, maxConsecutiveFailures: 4, payloadBloatGuard: true, maxToolResultChars: 65536,
|
|
129
|
+
pseudoToolCallThreshold: 3, adaptiveSteering: true,
|
|
130
|
+
},
|
|
131
|
+
autonomous: {
|
|
132
|
+
maxToolAttemptsPerTurn: 32, maxProgressToolCallsPerTurn: 12, maxCallsPerRepeatGroup: 5,
|
|
133
|
+
strictToolLimit: 3, blockExactDuplicates: true, oscillationDetection: true, maxOscillationRepeats: 4,
|
|
134
|
+
errorThrashingGuard: true, maxConsecutiveFailures: 6, payloadBloatGuard: true, maxToolResultChars: 131072,
|
|
135
|
+
pseudoToolCallThreshold: 4, adaptiveSteering: true,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
function PluginCard({ ctx: _ctx, t, bare, ...props }) {
|
|
139
|
+
const isBare = Boolean(bare || props?.view === 'page');
|
|
140
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
141
|
+
const isExpanded = Boolean(isBare || expanded);
|
|
142
|
+
const [draft, setDraft] = React.useState({ ...DEFAULTS, progressToolNamesText: 'todo_write', strictToolsText: '' });
|
|
143
|
+
const [status, setStatus] = React.useState('loading');
|
|
144
|
+
const [saving, setSaving] = React.useState(false);
|
|
145
|
+
const [msg, setMsg] = React.useState('');
|
|
146
|
+
|
|
147
|
+
const [updateState, setUpdateState] = React.useState({
|
|
148
|
+
checking: false, updateAvailable: false, currentVersion: '', latestVersion: '',
|
|
149
|
+
updating: false, notice: '', error: '', canAutoUpdate: true, isDesktop: false,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const [telemetry, setTelemetry] = React.useState({ totalViolations: 0, steeredCount: 0, byCode: {}, lastViolation: null, incidents: [] });
|
|
153
|
+
|
|
154
|
+
const scopeRef = React.useRef(null);
|
|
155
|
+
if (!scopeRef.current && _ctx && _ctx.configForms) {
|
|
156
|
+
try { scopeRef.current = _ctx.configForms.get(NS); } catch (e) { scopeRef.current = null; }
|
|
157
|
+
}
|
|
158
|
+
const scope = scopeRef.current;
|
|
159
|
+
|
|
160
|
+
const [, setLocaleTick] = React.useState(0);
|
|
161
|
+
React.useEffect(() => {
|
|
162
|
+
if (typeof _ctx?.locale?.subscribe === 'function') return _ctx.locale.subscribe(() => setLocaleTick((c) => c + 1));
|
|
163
|
+
}, []);
|
|
164
|
+
|
|
165
|
+
const getActiveLocale = () => {
|
|
166
|
+
const snap = typeof _ctx?.locale?.getLocale === 'function' ? _ctx.locale.getLocale()
|
|
167
|
+
: (typeof _ctx?.locale?.getSnapshot === 'function' ? _ctx.locale.getSnapshot() : null);
|
|
168
|
+
const loc = typeof snap === 'string' ? snap : (snap?.active || snap?.locale || snap?.id);
|
|
169
|
+
return loc || (typeof navigator !== 'undefined' && navigator.language ? navigator.language : 'en');
|
|
170
|
+
};
|
|
171
|
+
const currentLang = String(getActiveLocale()).toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
172
|
+
const dict = currentLang === 'zh' ? zh : en;
|
|
173
|
+
const tt = (k, params) => {
|
|
174
|
+
let str = (typeof t === 'function' ? t(k) : null) || dict[k] || en[k] || k;
|
|
175
|
+
if (params && typeof params === 'object') {
|
|
176
|
+
for (const [pk, pv] of Object.entries(params)) {
|
|
177
|
+
str = str.replace(new RegExp('\\{' + pk + '\\}', 'g'), String(pv));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return str;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (!scope) { setStatus('unavailable'); return; }
|
|
185
|
+
let cancelled = false;
|
|
186
|
+
const syncFromSnapshot = (snap) => {
|
|
187
|
+
if (!snap || typeof snap !== 'object') return;
|
|
188
|
+
if ('status' in snap) {
|
|
189
|
+
if (snap.status === 'loading') { setStatus('loading'); return; }
|
|
190
|
+
if (snap.status === 'unavailable') { setStatus('unavailable'); return; }
|
|
191
|
+
}
|
|
192
|
+
const vals = snap.value !== undefined ? snap.value : (snap.values !== undefined ? snap.values : snap);
|
|
193
|
+
if (vals && typeof vals === 'object') {
|
|
194
|
+
const names = Array.isArray(vals.progressToolNames) ? vals.progressToolNames : DEFAULTS.progressToolNames;
|
|
195
|
+
const strict = Array.isArray(vals.strictTools) ? vals.strictTools : DEFAULTS.strictTools;
|
|
196
|
+
setDraft((d) => ({
|
|
197
|
+
...d, ...DEFAULTS, ...vals,
|
|
198
|
+
progressToolNamesText: names.join(', '),
|
|
199
|
+
strictToolsText: strict.join(', '),
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
setStatus('ready');
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
if (typeof scope.getSnapshot === 'function') syncFromSnapshot(scope.getSnapshot());
|
|
207
|
+
else if (typeof scope.get === 'function') Promise.resolve(scope.get()).then((s) => { if (!cancelled) syncFromSnapshot(s); }).catch(() => { if (!cancelled) setStatus('unavailable'); });
|
|
208
|
+
else setStatus('unavailable');
|
|
209
|
+
} catch (_) { if (!cancelled) setStatus('unavailable'); }
|
|
210
|
+
|
|
211
|
+
const unsub = typeof scope.subscribe === 'function' ? scope.subscribe(() => {
|
|
212
|
+
if (!cancelled && typeof scope.getSnapshot === 'function') { try { syncFromSnapshot(scope.getSnapshot()); } catch (err) { void err; } }
|
|
213
|
+
}) : null;
|
|
214
|
+
|
|
215
|
+
return () => { cancelled = true; if (typeof unsub === 'function') unsub(); };
|
|
216
|
+
}, [scope]);
|
|
217
|
+
|
|
218
|
+
React.useEffect(() => {
|
|
219
|
+
if (!isExpanded) return;
|
|
220
|
+
let cancelled = false;
|
|
221
|
+
|
|
222
|
+
(async () => {
|
|
223
|
+
try {
|
|
224
|
+
const res = await fetch('/api/@goodandready/dsh-agent-loop-guard/update');
|
|
225
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
226
|
+
const data = await res.json();
|
|
227
|
+
if (cancelled) return;
|
|
228
|
+
setUpdateState((s) => ({
|
|
229
|
+
...s, checking: false, updateAvailable: Boolean(data.updateAvailable),
|
|
230
|
+
currentVersion: data.currentVersion || '', latestVersion: data.latestVersion || '',
|
|
231
|
+
updating: false, notice: '', error: '',
|
|
232
|
+
canAutoUpdate: data.canAutoUpdate !== false, isDesktop: !!data.isDesktop,
|
|
233
|
+
}));
|
|
234
|
+
} catch (err) {
|
|
235
|
+
if (cancelled) return;
|
|
236
|
+
setUpdateState((s) => ({ ...s, checking: false, error: tt('checkUpdateFailed') }));
|
|
237
|
+
}
|
|
238
|
+
})();
|
|
239
|
+
|
|
240
|
+
(async () => {
|
|
241
|
+
try {
|
|
242
|
+
const res = await fetch('/api/@goodandready/dsh-agent-loop-guard/telemetry');
|
|
243
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
244
|
+
const data = await res.json();
|
|
245
|
+
if (cancelled) return;
|
|
246
|
+
setTelemetry({
|
|
247
|
+
totalViolations: Number(data.totalViolations) || 0,
|
|
248
|
+
steeredCount: Number(data.steeredCount) || 0,
|
|
249
|
+
byCode: data.byCode || {},
|
|
250
|
+
lastViolation: data.lastViolation || null,
|
|
251
|
+
incidents: Array.isArray(data.incidents) ? data.incidents : [],
|
|
252
|
+
error: null,
|
|
253
|
+
});
|
|
254
|
+
} catch (err) {
|
|
255
|
+
if (cancelled) return;
|
|
256
|
+
setTelemetry((t) => ({ ...t, error: tt('telemetryLoadFailed') }));
|
|
257
|
+
}
|
|
258
|
+
})();
|
|
259
|
+
|
|
260
|
+
return () => { cancelled = true; };
|
|
261
|
+
}, [isExpanded]);
|
|
262
|
+
|
|
263
|
+
async function onSave() {
|
|
264
|
+
if (!scope || saving) return;
|
|
265
|
+
setSaving(true);
|
|
266
|
+
setMsg('');
|
|
267
|
+
const names = draft.progressToolNamesText.split(',').map((s) => s.trim()).filter(Boolean);
|
|
268
|
+
const strictList = draft.strictToolsText.split(',').map((s) => s.trim()).filter(Boolean);
|
|
269
|
+
const payload = {
|
|
270
|
+
maxToolAttemptsPerTurn: Number(draft.maxToolAttemptsPerTurn) || 0, maxProgressToolCallsPerTurn: Number(draft.maxProgressToolCallsPerTurn) || 16,
|
|
271
|
+
maxCallsPerRepeatGroup: Number(draft.maxCallsPerRepeatGroup) || 5, strictTools: strictList, strictToolLimit: Number(draft.strictToolLimit) || 3,
|
|
272
|
+
blockExactDuplicates: draft.blockExactDuplicates !== false, dryRunMode: Boolean(draft.dryRunMode),
|
|
273
|
+
assistantOutputGuard: draft.assistantOutputGuard !== false, maxRepeatedAssistantLines: Number(draft.maxRepeatedAssistantLines) || 5,
|
|
274
|
+
maxRepeatedAssistantBlocks: Number(draft.maxRepeatedAssistantBlocks) || 5, maxAssistantBlockChars: Number(draft.maxAssistantBlockChars) || 16384,
|
|
275
|
+
pseudoToolCallThreshold: Number.isFinite(Number(draft.pseudoToolCallThreshold)) ? Number(draft.pseudoToolCallThreshold) : 3,
|
|
276
|
+
oscillationDetection: draft.oscillationDetection !== false, maxOscillationRepeats: Number(draft.maxOscillationRepeats) || 3,
|
|
277
|
+
payloadBloatGuard: draft.payloadBloatGuard !== false, progressToolNames: names.length ? names : ['todo_write'],
|
|
278
|
+
maxToolResultChars: Number.isFinite(Number(draft.maxToolResultChars)) && Number(draft.maxToolResultChars) >= 0 ? Number(draft.maxToolResultChars) : 65536,
|
|
279
|
+
errorThrashingGuard: draft.errorThrashingGuard !== false, maxConsecutiveFailures: Number(draft.maxConsecutiveFailures) || 4,
|
|
280
|
+
adaptiveSteering: draft.adaptiveSteering !== false,
|
|
281
|
+
};
|
|
282
|
+
const errs = [];
|
|
283
|
+
for (const [k, v] of Object.entries(payload)) {
|
|
284
|
+
try { await scope.set(k, v); } catch (e) { errs.push(k + ': ' + (e && e.message || String(e))); }
|
|
285
|
+
}
|
|
286
|
+
setSaving(false);
|
|
287
|
+
setMsg(errs.length ? errs.join('; ') : tt('saved'));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function applyPreset(name) {
|
|
291
|
+
if (!CLIENT_PRESETS[name]) return;
|
|
292
|
+
setDraft((d) => ({ ...d, ...CLIENT_PRESETS[name] }));
|
|
293
|
+
setMsg(tt('presetApplied', { name: tt('preset' + name.charAt(0).toUpperCase() + name.slice(1)) }));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function onCopyDump() {
|
|
297
|
+
try {
|
|
298
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) navigator.clipboard.writeText(JSON.stringify(telemetry, null, 2));
|
|
299
|
+
setMsg(tt('dumpCopied'));
|
|
300
|
+
} catch (e) { setMsg(String(e)); }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function onTriggerUpdate() {
|
|
304
|
+
if (updateState.updating) return;
|
|
305
|
+
setUpdateState((s) => ({ ...s, updating: true, error: '', notice: '' }));
|
|
306
|
+
try {
|
|
307
|
+
const res = await fetch('/api/@goodandready/dsh-agent-loop-guard/update', {
|
|
308
|
+
method: 'POST', headers: { 'x-dsh-plugin-update': '1' },
|
|
309
|
+
});
|
|
310
|
+
const data = await res.json();
|
|
311
|
+
if (!res.ok || data.error) throw new Error(data.error || 'HTTP ' + res.status);
|
|
312
|
+
setUpdateState((s) => ({
|
|
313
|
+
...s, updating: false, updateAvailable: false,
|
|
314
|
+
currentVersion: data.updatedVersion || s.latestVersion,
|
|
315
|
+
notice: tt('updateSuccess', { v: data.updatedVersion || s.latestVersion }),
|
|
316
|
+
}));
|
|
317
|
+
} catch (err) { setUpdateState((s) => ({ ...s, updating: false, error: tt('updateFailed', { msg: err.message || String(err) }) })); }
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async function onResetTelemetry() {
|
|
321
|
+
try {
|
|
322
|
+
const res = await fetch('/api/@goodandready/dsh-agent-loop-guard/telemetry', {
|
|
323
|
+
method: 'POST', headers: { 'x-dsh-loop-guard': '1' },
|
|
324
|
+
});
|
|
325
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
326
|
+
setTelemetry({ totalViolations: 0, steeredCount: 0, byCode: {}, lastViolation: null, incidents: [], error: null });
|
|
327
|
+
setMsg(tt('statsResetDone'));
|
|
328
|
+
} catch (err) { setMsg(tt('statsResetFailed')); }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const renderChevron = () => {
|
|
332
|
+
if (PrimitivesChevron) {
|
|
333
|
+
return React.createElement(PrimitivesChevron, {
|
|
334
|
+
className: 'alg-chevron' + (expanded ? ' expanded' : ''),
|
|
335
|
+
style: { width: 14, height: 14, color: 'inherit' }
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return React.createElement('svg', {
|
|
339
|
+
className: 'alg-chevron' + (expanded ? ' expanded' : ''),
|
|
340
|
+
width: 14, height: 14, viewBox: '0 0 24 24', fill: 'none',
|
|
341
|
+
stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
342
|
+
style: { flexShrink: 0 }
|
|
343
|
+
}, React.createElement('polyline', { points: '6 9 12 15 18 9' }));
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const field = (key, input) => {
|
|
347
|
+
const id = 'alg-' + key;
|
|
348
|
+
const linkedInput = React.isValidElement && React.isValidElement(input)
|
|
349
|
+
? React.cloneElement(input, { id }) : input;
|
|
350
|
+
return React.createElement('div', { key, className: 'alg-field' },
|
|
351
|
+
React.createElement('label', { htmlFor: id }, tt(key)),
|
|
352
|
+
linkedInput
|
|
353
|
+
);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const num = (k) => React.createElement('input', { type: 'number', className: 'alg-input', value: draft[k], onChange: (e) => setDraft((d) => ({ ...d, [k]: e.target.value })) });
|
|
357
|
+
const str = (k) => React.createElement('input', { type: 'text', className: 'alg-input', value: draft[k], onChange: (e) => setDraft((d) => ({ ...d, [k]: e.target.value })) });
|
|
358
|
+
const check = (k) => React.createElement('label', { key: k, className: 'alg-checkbox-label' }, React.createElement('input', { type: 'checkbox', checked: !!draft[k], onChange: (e) => setDraft((d) => ({ ...d, [k]: e.target.checked })) }), tt(k));
|
|
359
|
+
|
|
360
|
+
const header = React.createElement('button', {
|
|
361
|
+
className: 'alg-header-btn', onClick: () => setExpanded(!expanded), 'aria-expanded': expanded,
|
|
362
|
+
},
|
|
363
|
+
React.createElement('span', { style: { display: 'flex', flexDirection: 'column' } },
|
|
364
|
+
React.createElement('span', { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 15, fontWeight: 600, display: 'flex', alignItems: 'center', gap: 8 } },
|
|
365
|
+
tt('title'),
|
|
366
|
+
React.createElement('span', { style: { fontSize: 11, fontWeight: 500, padding: '2px 6px', borderRadius: 6, background: 'color-mix(in srgb, var(--dsw-alias-brand-primary) 15%, transparent)', color: 'var(--dsw-alias-brand-primary)' } }, updateState.currentVersion ? 'v' + updateState.currentVersion : (updateState.checking ? '…' : '—'))
|
|
367
|
+
),
|
|
368
|
+
React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 13 } }, tt('sub'))
|
|
369
|
+
),
|
|
370
|
+
renderChevron()
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const body = React.createElement('div', { className: 'alg-body' },
|
|
374
|
+
React.createElement('div', {
|
|
375
|
+
style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 0', borderBottom: '1px solid var(--dsw-alias-border-l2)' }
|
|
376
|
+
},
|
|
377
|
+
React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 2 } },
|
|
378
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
379
|
+
React.createElement('span', { style: { fontSize: 13, fontWeight: 500, color: 'var(--dsw-alias-label-primary)' } },
|
|
380
|
+
tt('version') + ': ' + (updateState.currentVersion ? 'v' + updateState.currentVersion : '—')
|
|
381
|
+
),
|
|
382
|
+
React.createElement('span', {
|
|
383
|
+
style: {
|
|
384
|
+
fontSize: 11, padding: '1px 6px', borderRadius: 4,
|
|
385
|
+
background: updateState.updateAvailable ? 'color-mix(in srgb, var(--dsw-alias-brand-primary) 15%, transparent)' : 'color-mix(in srgb, var(--dsw-alias-state-success-primary) 15%, transparent)',
|
|
386
|
+
color: updateState.updateAvailable ? 'var(--dsw-alias-brand-primary)' : 'var(--dsw-alias-state-success-primary)',
|
|
387
|
+
}
|
|
388
|
+
}, updateState.checking ? tt('updateChecking') : (updateState.updateAvailable ? tt('updateAvailable', { v: updateState.latestVersion }) : (updateState.currentVersion ? tt('upToDate') : '—')))
|
|
389
|
+
),
|
|
390
|
+
updateState.error && React.createElement('span', { style: { color: 'var(--dsw-alias-state-error-primary)', fontSize: 12 } }, updateState.error)
|
|
391
|
+
),
|
|
392
|
+
updateState.updateAvailable && (
|
|
393
|
+
(updateState.isDesktop || !updateState.canAutoUpdate)
|
|
394
|
+
? React.createElement('span', { className: 'alg-updater-hint', style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, tt('updateViaPluginsPage'))
|
|
395
|
+
: React.createElement('button', { className: 'alg-btn-updater', onClick: onTriggerUpdate, disabled: updateState.updating }, updateState.updating ? tt('updating') : tt('updateNow'))
|
|
396
|
+
)
|
|
397
|
+
),
|
|
398
|
+
updateState.notice && React.createElement('div', {
|
|
399
|
+
style: { padding: '8px 12px', marginBottom: 12, background: 'color-mix(in srgb, var(--dsw-alias-state-success-primary) 10%, transparent)', color: 'var(--dsw-alias-state-success-primary)', borderRadius: 6, fontSize: 12, border: '1px solid color-mix(in srgb, var(--dsw-alias-state-success-primary) 20%, transparent)' }
|
|
400
|
+
}, updateState.notice),
|
|
401
|
+
|
|
402
|
+
React.createElement('div', { className: 'alg-presets' },
|
|
403
|
+
React.createElement('span', { style: { fontSize: 12, fontWeight: 500, color: 'var(--dsw-alias-label-secondary)', marginRight: 4 } }, tt('presetsTitle') + ':'),
|
|
404
|
+
React.createElement('button', { type: 'button', className: 'alg-btn-preset', onClick: () => applyPreset('strict') }, tt('presetStrict')),
|
|
405
|
+
React.createElement('button', { type: 'button', className: 'alg-btn-preset', onClick: () => applyPreset('balanced') }, tt('presetBalanced')),
|
|
406
|
+
React.createElement('button', { type: 'button', className: 'alg-btn-preset', onClick: () => applyPreset('autonomous') }, tt('presetAutonomous'))
|
|
407
|
+
),
|
|
408
|
+
|
|
409
|
+
React.createElement('div', {
|
|
410
|
+
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)' }
|
|
411
|
+
},
|
|
412
|
+
React.createElement('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 } },
|
|
413
|
+
React.createElement('span', { style: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' } }, tt('telemetryTitle')),
|
|
414
|
+
React.createElement('div', { style: { display: 'flex', gap: 6 } },
|
|
415
|
+
telemetry.totalViolations > 0 && React.createElement('button', { className: 'alg-btn-ghost', onClick: onCopyDump }, tt('copyDump')),
|
|
416
|
+
(telemetry.totalViolations > 0 || (telemetry.incidents && telemetry.incidents.length > 0)) && React.createElement('button', { className: 'alg-btn-ghost', onClick: onResetTelemetry }, tt('resetStats'))
|
|
417
|
+
)
|
|
418
|
+
),
|
|
419
|
+
React.createElement('div', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } },
|
|
420
|
+
telemetry.error
|
|
421
|
+
? React.createElement('span', { style: { color: 'var(--dsw-alias-state-error-primary)' } }, telemetry.error)
|
|
422
|
+
: (telemetry.totalViolations > 0 || telemetry.steeredCount > 0)
|
|
423
|
+
? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
424
|
+
React.createElement('div', { style: { display: 'flex', gap: 16 } },
|
|
425
|
+
React.createElement('div', null, tt('totalBlocked') + ': ', React.createElement('strong', { style: { color: 'var(--dsw-alias-state-warn-primary)' } }, telemetry.totalViolations)),
|
|
426
|
+
React.createElement('div', null, tt('steeredCount') + ': ', React.createElement('strong', { style: { color: 'var(--dsw-alias-brand-primary)' } }, telemetry.steeredCount || 0))
|
|
427
|
+
),
|
|
428
|
+
telemetry.lastViolation && React.createElement('div', { style: { color: 'var(--dsw-alias-label-tertiary)' } },
|
|
429
|
+
tt('lastViolation') + ': ' + telemetry.lastViolation.code + ' (' + telemetry.lastViolation.tool + ')'
|
|
430
|
+
),
|
|
431
|
+
telemetry.incidents && telemetry.incidents.length > 0 && React.createElement('div', { style: { marginTop: 6, borderTop: '1px solid var(--dsw-alias-border-l2)', paddingTop: 6 } },
|
|
432
|
+
React.createElement('div', { style: { fontWeight: 500, marginBottom: 4 } }, tt('incidentsTitle')),
|
|
433
|
+
telemetry.incidents.slice(0, 4).map((inc, i) => React.createElement('div', { key: inc.id || i, className: 'alg-incident-row' },
|
|
434
|
+
React.createElement('span', { style: { fontWeight: 500, color: inc.code === 'LOOP_GUARD_STEER' ? 'var(--dsw-alias-brand-primary)' : 'var(--dsw-alias-state-error-primary)' } }, inc.code),
|
|
435
|
+
React.createElement('span', { style: { color: 'var(--dsw-alias-label-tertiary)' } }, inc.tool)
|
|
436
|
+
))
|
|
437
|
+
)
|
|
438
|
+
)
|
|
439
|
+
: React.createElement('span', { style: { color: 'var(--dsw-alias-label-tertiary)' } }, tt('noViolations'))
|
|
440
|
+
)
|
|
441
|
+
),
|
|
442
|
+
|
|
443
|
+
field('maxToolAttemptsPerTurn', num('maxToolAttemptsPerTurn')),
|
|
444
|
+
field('maxProgressToolCallsPerTurn', num('maxProgressToolCallsPerTurn')),
|
|
445
|
+
field('maxCallsPerRepeatGroup', num('maxCallsPerRepeatGroup')),
|
|
446
|
+
field('strictTools', str('strictToolsText')),
|
|
447
|
+
field('strictToolLimit', num('strictToolLimit')),
|
|
448
|
+
check('blockExactDuplicates'),
|
|
449
|
+
check('dryRunMode'),
|
|
450
|
+
check('assistantOutputGuard'),
|
|
451
|
+
field('maxRepeatedAssistantLines', num('maxRepeatedAssistantLines')),
|
|
452
|
+
field('maxRepeatedAssistantBlocks', num('maxRepeatedAssistantBlocks')),
|
|
453
|
+
field('maxAssistantBlockChars', num('maxAssistantBlockChars')),
|
|
454
|
+
field('progressToolNames', str('progressToolNamesText')),
|
|
455
|
+
field('pseudoToolCallThreshold', num('pseudoToolCallThreshold')),
|
|
456
|
+
check('oscillationDetection'),
|
|
457
|
+
field('maxOscillationRepeats', num('maxOscillationRepeats')),
|
|
458
|
+
check('payloadBloatGuard'),
|
|
459
|
+
field('maxToolResultChars', num('maxToolResultChars')),
|
|
460
|
+
check('errorThrashingGuard'),
|
|
461
|
+
field('maxConsecutiveFailures', num('maxConsecutiveFailures')),
|
|
462
|
+
check('adaptiveSteering'),
|
|
463
|
+
|
|
464
|
+
React.createElement('div', {
|
|
465
|
+
style: { display: 'flex', alignItems: 'center', gap: 12, paddingTop: 14, borderTop: '1px solid var(--dsw-alias-border-l2)', marginTop: 10 }
|
|
466
|
+
},
|
|
467
|
+
React.createElement('button', {
|
|
468
|
+
className: 'alg-btn-primary', onClick: onSave, disabled: saving || status !== 'ready',
|
|
469
|
+
}, saving ? tt('saving') : tt('ready')),
|
|
470
|
+
msg && React.createElement('span', { style: { fontSize: 13, color: msg.includes(';') ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-state-success-primary)' } }, msg)
|
|
471
|
+
)
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
if (isBare) return React.createElement('div', { className: 'alg-page' }, body);
|
|
475
|
+
return React.createElement('li', { className: 'alg-card' }, header, expanded && body);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function PluginItem(props) {
|
|
479
|
+
if (props && props.view === 'summary') {
|
|
480
|
+
return React.createElement('div', { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 13 } }, en.sub);
|
|
481
|
+
}
|
|
482
|
+
return React.createElement(PluginCard, { ...props, bare: Boolean(props && (props.bare || props.view === 'page')) });
|
|
483
|
+
}
|
|
525
484
|
exports.inject = ['slots', 'configForms', 'locale'];
|
|
526
485
|
exports.apply = function apply(ctx) {
|
|
527
486
|
if (typeof ctx.locale?.register === 'function') {
|