@goodandready/dsh-agent-loop-guard 0.2.18 → 0.2.25
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 +45 -0
- package/lib/assistant-output-state.js +25 -7
- package/lib/client.js +61 -57
- package/lib/guard-state.js +79 -3
- package/lib/index.js +8 -7
- package/lib/plugin-updater.js +151 -26
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.25] - 2026-10-19
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **Stop Command Detection & History Isolation (#120)**: Hardened `hasStopRequest` in `lib/guard-state.js` to inspect only the latest user message (`source.kind === 'user'` or `role === 'user'`), eliminating cross-turn leakage where a past stop command in turn 1 permanently locked tools in subsequent turns. Removed broad keywords `answer` and `回答` from default stop patterns, and introduced `isDefaultStopRequest` to require explicit standalone or imperative stop commands ("stop", "halt", "cancel", "abort", "terminate", "please stop", "停止", "暂停", "取消", "终止", "死循环"), eliminating false-positive blocks on regular user requests ("answer in Russian", "please answer using files", "stop the service and fix it").
|
|
7
|
+
- **Bounded Streaming Output Buffer (#121)**: Bounded `state.pending` buffer in `AssistantOutputGuardState.observeText` to `maxAssistantBlockChars` and parsed newlines incrementally via `indexOf('\n')` instead of `split(/\n/gu)`, preventing unbounded memory growth and O(N^2) CPU stalls during long streaming outputs without line breaks (such as minified JSON or base64 payloads).
|
|
8
|
+
- **Issue Label Deduplication (#122)**: Reassigned affected issues to canonical project labels and cleaned up duplicate labels in Gitea repository.
|
|
9
|
+
|
|
10
|
+
## [0.2.24] - 2026-10-15
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **Supply-Chain Guard Compliance (#116)**: Removed `--config.minimumReleaseAge=0` override in plugin updater (`lib/plugin-updater.js`), enforcing compliance with pnpm global supply-chain quarantine and release age delay policies across fleet environments.
|
|
14
|
+
- **Client Slots Cleanup (#116)**: Removed deprecated dead slot `settings.plugin.item` from `src/client/60-slots.js` and unified configuration card rendering across `plugins.row.config` and `plugins.item`, reducing bundle size and keeping `lib/client.js` at 582 lines (under the 600 line limit).
|
|
15
|
+
|
|
16
|
+
## [0.2.23] - 2026-10-11
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- **Desktop Updater Fallback (#113)**: Detected DSH Desktop profile via `isDesktopProfile` and located bundled desktop CLI binary via `findDesktopCliEntry`. Added `isDesktop` and `canAutoUpdate` flags to updater status endpoint. Added `shell: true` option when spawning Windows `.cmd` binaries in `installExact`. Replaced "Update Now" button in settings card with localized hint (`Update in Plugins page` / `请在插件页面更新`) when running in DSH Desktop or when automatic updates cannot be performed. Preserved standard "Update Now" flow in headless/web server profiles.
|
|
20
|
+
|
|
21
|
+
## [0.2.22] - 2026-10-09
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- **Telemetry Route Security Boundary (#102)**: Integrated `getConnection(ctx)` and delegated request verification to DSH core service `connection.requestRejection(request)`. Enforced loopback and mandatory `sec-fetch-site` (`same-origin` or `none`) fallback when connection service is absent. Enforced `x-dsh-loop-guard: '1'` header and origin/host verification on POST telemetry reset, preventing unauthorized access or state reset from loopback/LAN bridges.
|
|
25
|
+
- **Persistent Release Packaging & Clean Isolation (#101)**: Relocated production web profile tarball dependency to external persistent directory `/home/vadim/.dsh/artifacts/`. Replaced indiscriminate `rm -f *.tgz` in `clean` script with `scripts/clean-pack.mjs` to safeguard release tarballs from local repository cleanup. Added `scripts/pack-release.mjs` (`npm run pack:release`) to build, pack into persistent artifacts directory, and generate `.sha256` checksums.
|
|
26
|
+
|
|
27
|
+
## [0.2.21] - 2026-10-09
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
- **Canonical Design Tokens (#100)**: Replaced 38 occurrences of non-existent theme tokens (`--dsw-alias-accent-primary`, `status-success`, `status-danger`, `status-warning`, `bg-hover`, `bg-layer-hover`) in `src/client/10-styles.js` and `src/client/50-settings-card.js` with canonical DSH theme tokens (`brand-primary`, `state-success-primary`, `state-error-primary`, `state-warn-primary`, `interactive-bg-hover`), restoring native styling, status coloring, and updater button appearance across themes.
|
|
31
|
+
- **Theme Token Validation Guard (#104)**: Extended `test/theme-guard.test.js` to extract all `--dsw-alias-*` tokens from `lib/client.js` and assert adherence to the canonical 79-token design system of `@deepseek-ai/dsh-client-ui-theme`, preventing regression on unknown tokens.
|
|
32
|
+
|
|
33
|
+
## [0.2.20] - 2026-10-09
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- **Streamed Text Memory Cap (#97)**: Capped `streamedText` buffer in `AssistantOutputGuardState` to `maxAssistantBlockChars` to prevent unbounded memory growth during long streaming assistant turns.
|
|
37
|
+
- **Volatile Config Reload Subscription (#98)**: Subscribed to Cordis `loader/volatile-update` event alongside `app-boot/config-reload` and `internal/update` for instant volatile settings reload without requiring manual refresh.
|
|
38
|
+
- **Settings Loader Fallback Cleanup (#99)**: Removed dead `typeof sctx.settings.get === 'function'` fallback from live config reader.
|
|
39
|
+
- **Language Independence & Configurable Stop Patterns (#103)**: Removed Cyrillic regex in engine core `lib/guard-state.js`, added balanced standard `en` and `zh` default patterns, and added configurable `stopPatterns` in `Config` (with `.volatile()`) and `hasStopRequest()`.
|
|
40
|
+
|
|
41
|
+
## [0.2.19] - 2026-10-08
|
|
42
|
+
|
|
43
|
+
### Fixed
|
|
44
|
+
- **Settings Contract & Snapshot Reader (#90)**: Replaced non-existent with synchronous , unpacked settings values from ( contract) instead of , and bound reactive updates through .
|
|
45
|
+
- **Locale Resolution & Reactivity (#40)**: Read active locale identifier from in with fallback to and , ensuring settings card respects the host language selection over browser .
|
|
46
|
+
- **Volatile Schema Verification (#89)**: Verified and tested that all 13 user-facing schema fields carry (), ensuring live configuration registration under DSH 0.2.0.
|
|
47
|
+
|
|
3
48
|
## [0.2.18] - 2026-09-30
|
|
4
49
|
|
|
5
50
|
### Fixed
|
|
@@ -168,20 +168,38 @@ export class AssistantOutputGuardState {
|
|
|
168
168
|
state.blockHasher = createHash('sha256');
|
|
169
169
|
}
|
|
170
170
|
state.blockHasher.update(text);
|
|
171
|
-
state.streamedText += text;
|
|
172
171
|
if (state.blockText.length + text.length > this.maxAssistantBlockChars) {
|
|
173
172
|
state.blockOversized = true;
|
|
174
173
|
state.blockText = (state.blockText + text).slice(-this.maxAssistantBlockChars);
|
|
174
|
+
state.streamedText = (state.streamedText + text).slice(-this.maxAssistantBlockChars);
|
|
175
175
|
} else {
|
|
176
176
|
state.blockText += text;
|
|
177
|
+
state.streamedText += text;
|
|
177
178
|
}
|
|
178
179
|
state.streamedSkipAvailable = true;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
let nlIdx = text.indexOf('\n');
|
|
181
|
+
if (nlIdx === -1) {
|
|
182
|
+
state.pending += text;
|
|
183
|
+
if (state.pending.length > this.maxAssistantBlockChars) {
|
|
184
|
+
state.pending = state.pending.slice(-this.maxAssistantBlockChars);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
const firstLine = state.pending + text.slice(0, nlIdx);
|
|
188
|
+
state.pending = '';
|
|
189
|
+
const hit = this.observeLine(session, firstLine);
|
|
184
190
|
if (hit) return hit;
|
|
191
|
+
|
|
192
|
+
let start = nlIdx + 1;
|
|
193
|
+
while ((nlIdx = text.indexOf('\n', start)) !== -1) {
|
|
194
|
+
const line = text.slice(start, nlIdx);
|
|
195
|
+
const hit = this.observeLine(session, line);
|
|
196
|
+
if (hit) return hit;
|
|
197
|
+
start = nlIdx + 1;
|
|
198
|
+
}
|
|
199
|
+
state.pending = text.slice(start);
|
|
200
|
+
if (state.pending.length > this.maxAssistantBlockChars) {
|
|
201
|
+
state.pending = state.pending.slice(-this.maxAssistantBlockChars);
|
|
202
|
+
}
|
|
185
203
|
}
|
|
186
204
|
return undefined;
|
|
187
205
|
}
|
|
@@ -239,7 +257,7 @@ export class AssistantOutputGuardState {
|
|
|
239
257
|
}
|
|
240
258
|
const suffix = prior.length > 0 && prior !== text && text.startsWith(prior) ? text.slice(prior.length) : text;
|
|
241
259
|
const hit = this.observeText(session, { turn, step, index, text: suffix });
|
|
242
|
-
state.streamedText = text;
|
|
260
|
+
state.streamedText = text.length > this.maxAssistantBlockChars ? text.slice(-this.maxAssistantBlockChars) : text;
|
|
243
261
|
state.streamedSkipAvailable = false;
|
|
244
262
|
if (hit) return hit;
|
|
245
263
|
return this.finalizeBlock(session);
|
package/lib/client.js
CHANGED
|
@@ -33,7 +33,7 @@ window.__ModuleLoader__.load({
|
|
|
33
33
|
display: flex; align-items: center; gap: 12px; padding: 14px 16px;
|
|
34
34
|
transition: background 0.15s ease;
|
|
35
35
|
}
|
|
36
|
-
.alg-header-btn:hover { background: var(--dsw-alias-
|
|
36
|
+
.alg-header-btn:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
37
37
|
.alg-chevron {
|
|
38
38
|
margin-left: auto; color: var(--dsw-alias-label-tertiary);
|
|
39
39
|
display: flex; align-items: center; justify-content: center;
|
|
@@ -49,7 +49,7 @@ window.__ModuleLoader__.load({
|
|
|
49
49
|
border-radius: 8px; padding: 0 12px; font-size: 13px; outline: none;
|
|
50
50
|
transition: border-color 0.15s ease;
|
|
51
51
|
}
|
|
52
|
-
.alg-input:focus { border-color: var(--dsw-alias-
|
|
52
|
+
.alg-input:focus { border-color: var(--dsw-alias-brand-primary); }
|
|
53
53
|
.alg-checkbox-label {
|
|
54
54
|
display: flex; align-items: center; gap: 8px; font-size: 13px;
|
|
55
55
|
color: var(--dsw-alias-label-primary); cursor: pointer; padding: 6px 0;
|
|
@@ -57,7 +57,7 @@ window.__ModuleLoader__.load({
|
|
|
57
57
|
.alg-btn-primary {
|
|
58
58
|
appearance: none; font: inherit; cursor: pointer; border: 0; border-radius: 8px;
|
|
59
59
|
padding: 6px 16px; font-size: 13px; font-weight: 500;
|
|
60
|
-
background: var(--dsw-alias-
|
|
60
|
+
background: var(--dsw-alias-brand-primary); color: var(--dsw-alias-label-primary-inverted, var(--dsw-alias-bg-layer-3));
|
|
61
61
|
transition: opacity 0.15s ease;
|
|
62
62
|
}
|
|
63
63
|
.alg-btn-primary:hover:not(:disabled) { opacity: 0.9; }
|
|
@@ -65,7 +65,7 @@ window.__ModuleLoader__.load({
|
|
|
65
65
|
.alg-btn-updater {
|
|
66
66
|
appearance: none; font: inherit; cursor: pointer; border: 0; border-radius: 6px;
|
|
67
67
|
padding: 4px 10px; font-size: 12px; font-weight: 500;
|
|
68
|
-
background: var(--dsw-alias-
|
|
68
|
+
background: var(--dsw-alias-brand-primary); color: var(--dsw-alias-label-primary-inverted, var(--dsw-alias-bg-layer-3));
|
|
69
69
|
transition: opacity 0.15s ease;
|
|
70
70
|
}
|
|
71
71
|
.alg-btn-updater:hover:not(:disabled) { opacity: 0.9; }
|
|
@@ -99,6 +99,7 @@ window.__ModuleLoader__.load({
|
|
|
99
99
|
updateAvailable: 'Update available: v{v}',
|
|
100
100
|
upToDate: 'Up to date',
|
|
101
101
|
updateNow: 'Update Now',
|
|
102
|
+
updateViaPluginsPage: 'Update in Plugins page',
|
|
102
103
|
updating: 'Updating…',
|
|
103
104
|
updateSuccess: 'Updated to v{v}. Restart DSH service to apply changes.',
|
|
104
105
|
updateFailed: 'Update failed: {msg}',
|
|
@@ -136,6 +137,7 @@ window.__ModuleLoader__.load({
|
|
|
136
137
|
updateAvailable: '发现新版本: v{v}',
|
|
137
138
|
upToDate: '已是最新版本',
|
|
138
139
|
updateNow: '立即更新',
|
|
140
|
+
updateViaPluginsPage: '请在插件页面更新',
|
|
139
141
|
updating: '正在更新…',
|
|
140
142
|
updateSuccess: '已更新至 v{v}。请重启 DSH 服务以生效变更。',
|
|
141
143
|
updateFailed: '更新失败: {msg}',
|
|
@@ -171,9 +173,10 @@ window.__ModuleLoader__.load({
|
|
|
171
173
|
maxRepeatedAssistantBlocks: 5, maxAssistantBlockChars: 16384,
|
|
172
174
|
};
|
|
173
175
|
|
|
174
|
-
function PluginCard({ ctx: _ctx, t, bare }) {
|
|
176
|
+
function PluginCard({ ctx: _ctx, t, bare, ...props }) {
|
|
177
|
+
const isBare = Boolean(bare || props?.view === 'page');
|
|
175
178
|
const [expanded, setExpanded] = React.useState(false);
|
|
176
|
-
const isExpanded = Boolean(
|
|
179
|
+
const isExpanded = Boolean(isBare || expanded);
|
|
177
180
|
const [draft, setDraft] = React.useState({ ...DEFAULTS, progressToolNamesText: 'todo_write', strictToolsText: '' });
|
|
178
181
|
const [status, setStatus] = React.useState('loading');
|
|
179
182
|
const [saving, setSaving] = React.useState(false);
|
|
@@ -181,7 +184,7 @@ window.__ModuleLoader__.load({
|
|
|
181
184
|
|
|
182
185
|
const [updateState, setUpdateState] = React.useState({
|
|
183
186
|
checking: false, updateAvailable: false, currentVersion: '', latestVersion: '',
|
|
184
|
-
updating: false, notice: '', error: '',
|
|
187
|
+
updating: false, notice: '', error: '', canAutoUpdate: true, isDesktop: false,
|
|
185
188
|
});
|
|
186
189
|
|
|
187
190
|
const [telemetry, setTelemetry] = React.useState({ totalViolations: 0, byCode: {}, lastViolation: null });
|
|
@@ -203,7 +206,7 @@ window.__ModuleLoader__.load({
|
|
|
203
206
|
const snap = typeof _ctx?.locale?.getLocale === 'function'
|
|
204
207
|
? _ctx.locale.getLocale()
|
|
205
208
|
: (typeof _ctx?.locale?.getSnapshot === 'function' ? _ctx.locale.getSnapshot() : null);
|
|
206
|
-
const loc = typeof snap === 'string' ? snap : (snap?.locale || snap?.id);
|
|
209
|
+
const loc = typeof snap === 'string' ? snap : (snap?.active || snap?.locale || snap?.id);
|
|
207
210
|
if (loc) return loc;
|
|
208
211
|
return typeof navigator !== 'undefined' && navigator.language ? navigator.language : 'en';
|
|
209
212
|
};
|
|
@@ -222,30 +225,39 @@ window.__ModuleLoader__.load({
|
|
|
222
225
|
React.useEffect(() => {
|
|
223
226
|
if (!scope) { setStatus('unavailable'); return; }
|
|
224
227
|
let cancelled = false;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
if (snap
|
|
230
|
-
if (snap.status === 'loading') { setStatus('loading'); return; }
|
|
231
|
-
if (snap.status === 'unavailable') { setStatus('unavailable'); return; }
|
|
232
|
-
}
|
|
233
|
-
const vals = snap && snap.values ? snap.values : snap;
|
|
234
|
-
if (vals && typeof vals === 'object') {
|
|
235
|
-
const names = Array.isArray(vals.progressToolNames) ? vals.progressToolNames : DEFAULTS.progressToolNames;
|
|
236
|
-
const strict = Array.isArray(vals.strictTools) ? vals.strictTools : DEFAULTS.strictTools;
|
|
237
|
-
setDraft((d) => ({
|
|
238
|
-
...d, ...DEFAULTS, ...vals,
|
|
239
|
-
progressToolNamesText: names.join(', '),
|
|
240
|
-
strictToolsText: strict.join(', '),
|
|
241
|
-
}));
|
|
242
|
-
}
|
|
243
|
-
setStatus('ready');
|
|
244
|
-
} catch (e) {
|
|
245
|
-
if (!cancelled) setStatus('unavailable');
|
|
228
|
+
const syncFromSnapshot = (snap) => {
|
|
229
|
+
if (!snap || typeof snap !== 'object') return;
|
|
230
|
+
if ('status' in snap) {
|
|
231
|
+
if (snap.status === 'loading') { setStatus('loading'); return; }
|
|
232
|
+
if (snap.status === 'unavailable') { setStatus('unavailable'); return; }
|
|
246
233
|
}
|
|
247
|
-
|
|
248
|
-
|
|
234
|
+
const vals = snap.value !== undefined ? snap.value : (snap.values !== undefined ? snap.values : snap);
|
|
235
|
+
if (vals && typeof vals === 'object') {
|
|
236
|
+
const names = Array.isArray(vals.progressToolNames) ? vals.progressToolNames : DEFAULTS.progressToolNames;
|
|
237
|
+
const strict = Array.isArray(vals.strictTools) ? vals.strictTools : DEFAULTS.strictTools;
|
|
238
|
+
setDraft((d) => ({
|
|
239
|
+
...d, ...DEFAULTS, ...vals,
|
|
240
|
+
progressToolNamesText: names.join(', '),
|
|
241
|
+
strictToolsText: strict.join(', '),
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
setStatus('ready');
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
if (typeof scope.getSnapshot === 'function') syncFromSnapshot(scope.getSnapshot());
|
|
249
|
+
else if (typeof scope.get === 'function') Promise.resolve(scope.get()).then((s) => { if (!cancelled) syncFromSnapshot(s); }).catch(() => { if (!cancelled) setStatus('unavailable'); });
|
|
250
|
+
else setStatus('unavailable');
|
|
251
|
+
} catch (_) { if (!cancelled) setStatus('unavailable'); }
|
|
252
|
+
|
|
253
|
+
const unsub = typeof scope.subscribe === 'function' ? scope.subscribe(() => {
|
|
254
|
+
if (!cancelled && typeof scope.getSnapshot === 'function') { try { syncFromSnapshot(scope.getSnapshot()); } catch (_) {} }
|
|
255
|
+
}) : null;
|
|
256
|
+
|
|
257
|
+
return () => {
|
|
258
|
+
cancelled = true;
|
|
259
|
+
if (typeof unsub === 'function') unsub();
|
|
260
|
+
};
|
|
249
261
|
}, [scope]);
|
|
250
262
|
|
|
251
263
|
React.useEffect(() => {
|
|
@@ -262,6 +274,7 @@ window.__ModuleLoader__.load({
|
|
|
262
274
|
setUpdateState((s) => ({
|
|
263
275
|
...s, checking: false, currentVersion: data.currentVersion || '',
|
|
264
276
|
latestVersion: data.latestVersion || '', updateAvailable: !!data.updateAvailable,
|
|
277
|
+
canAutoUpdate: data.canAutoUpdate !== false, isDesktop: !!data.isDesktop,
|
|
265
278
|
}));
|
|
266
279
|
} catch (err) {
|
|
267
280
|
if (cancelled) return;
|
|
@@ -404,7 +417,7 @@ window.__ModuleLoader__.load({
|
|
|
404
417
|
React.createElement('span', { style: { display: 'flex', flexDirection: 'column' } },
|
|
405
418
|
React.createElement('span', { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 15, fontWeight: 600, display: 'flex', alignItems: 'center', gap: 8 } },
|
|
406
419
|
tt('title'),
|
|
407
|
-
React.createElement('span', { style: { fontSize: 11, fontWeight: 500, padding: '2px 6px', borderRadius: 6, background: 'color-mix(in srgb, var(--dsw-alias-
|
|
420
|
+
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 ? '…' : '—'))
|
|
408
421
|
),
|
|
409
422
|
React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 13 } }, tt('sub'))
|
|
410
423
|
),
|
|
@@ -423,19 +436,21 @@ window.__ModuleLoader__.load({
|
|
|
423
436
|
React.createElement('span', {
|
|
424
437
|
style: {
|
|
425
438
|
fontSize: 11, padding: '1px 6px', borderRadius: 4,
|
|
426
|
-
background: updateState.updateAvailable ? 'color-mix(in srgb, var(--dsw-alias-
|
|
427
|
-
color: updateState.updateAvailable ? 'var(--dsw-alias-
|
|
439
|
+
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)',
|
|
440
|
+
color: updateState.updateAvailable ? 'var(--dsw-alias-brand-primary)' : 'var(--dsw-alias-state-success-primary)',
|
|
428
441
|
}
|
|
429
442
|
}, updateState.checking ? tt('updateChecking') : (updateState.updateAvailable ? tt('updateAvailable', { v: updateState.latestVersion }) : (updateState.currentVersion ? tt('upToDate') : '—')))
|
|
430
443
|
),
|
|
431
|
-
updateState.error && React.createElement('span', { style: { color: 'var(--dsw-alias-
|
|
444
|
+
updateState.error && React.createElement('span', { style: { color: 'var(--dsw-alias-state-error-primary)', fontSize: 12 } }, updateState.error)
|
|
432
445
|
),
|
|
433
|
-
updateState.updateAvailable &&
|
|
434
|
-
|
|
435
|
-
|
|
446
|
+
updateState.updateAvailable && (
|
|
447
|
+
(updateState.isDesktop || !updateState.canAutoUpdate)
|
|
448
|
+
? React.createElement('span', { className: 'alg-updater-hint', style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, tt('updateViaPluginsPage'))
|
|
449
|
+
: React.createElement('button', { className: 'alg-btn-updater', onClick: onTriggerUpdate, disabled: updateState.updating }, updateState.updating ? tt('updating') : tt('updateNow'))
|
|
450
|
+
)
|
|
436
451
|
),
|
|
437
452
|
updateState.notice && React.createElement('div', {
|
|
438
|
-
style: { padding: '8px 12px', marginBottom: 12, background: 'color-mix(in srgb, var(--dsw-alias-
|
|
453
|
+
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)' }
|
|
439
454
|
}, updateState.notice),
|
|
440
455
|
|
|
441
456
|
React.createElement('div', {
|
|
@@ -449,10 +464,10 @@ window.__ModuleLoader__.load({
|
|
|
449
464
|
),
|
|
450
465
|
React.createElement('div', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } },
|
|
451
466
|
telemetry.error
|
|
452
|
-
? React.createElement('span', { style: { color: 'var(--dsw-alias-
|
|
467
|
+
? React.createElement('span', { style: { color: 'var(--dsw-alias-state-error-primary)' } }, telemetry.error)
|
|
453
468
|
: telemetry.totalViolations > 0
|
|
454
469
|
? 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-
|
|
470
|
+
React.createElement('div', null, tt('totalBlocked') + ': ', React.createElement('strong', { style: { color: 'var(--dsw-alias-state-warn-primary)' } }, telemetry.totalViolations)),
|
|
456
471
|
telemetry.lastViolation && React.createElement('div', { style: { color: 'var(--dsw-alias-label-tertiary)' } },
|
|
457
472
|
tt('lastViolation') + ': ' + telemetry.lastViolation.code + ' (' + telemetry.lastViolation.tool + ')'
|
|
458
473
|
)
|
|
@@ -480,11 +495,11 @@ window.__ModuleLoader__.load({
|
|
|
480
495
|
React.createElement('button', {
|
|
481
496
|
className: 'alg-btn-primary', onClick: onSave, disabled: saving || status !== 'ready',
|
|
482
497
|
}, saving ? tt('saving') : tt('ready')),
|
|
483
|
-
msg && React.createElement('span', { style: { fontSize: 13, color: msg === tt('saved') || msg === tt('statsResetDone') ? 'var(--dsw-alias-
|
|
498
|
+
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)
|
|
484
499
|
)
|
|
485
500
|
);
|
|
486
501
|
|
|
487
|
-
if (
|
|
502
|
+
if (isBare) {
|
|
488
503
|
return React.createElement('div', { className: 'alg-page' }, body);
|
|
489
504
|
}
|
|
490
505
|
return React.createElement('li', { className: 'alg-card' }, header, expanded && body);
|
|
@@ -496,7 +511,8 @@ window.__ModuleLoader__.load({
|
|
|
496
511
|
style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 13 }
|
|
497
512
|
}, en.sub);
|
|
498
513
|
}
|
|
499
|
-
|
|
514
|
+
const isBare = Boolean(props && (props.bare || props.view === 'page'));
|
|
515
|
+
return React.createElement(PluginCard, { ...props, bare: isBare });
|
|
500
516
|
}
|
|
501
517
|
exports.inject = ['slots', 'configForms', 'locale'];
|
|
502
518
|
exports.apply = function apply(ctx) {
|
|
@@ -556,22 +572,10 @@ window.__ModuleLoader__.load({
|
|
|
556
572
|
locale: NS,
|
|
557
573
|
inject: () => ({ ctx }),
|
|
558
574
|
},
|
|
559
|
-
(props) => React.createElement(PluginItem, { ...props, ctx: (props && props.ctx) || ctx })
|
|
560
|
-
)
|
|
561
|
-
);
|
|
562
|
-
|
|
563
|
-
registerSlotWhenReady('settings.plugin.item', () =>
|
|
564
|
-
ctx.slots.register(
|
|
565
|
-
{
|
|
566
|
-
name: 'settings.plugin.item',
|
|
567
|
-
key: NS,
|
|
568
|
-
order: 95,
|
|
569
|
-
locale: NS,
|
|
570
|
-
inject: () => ({ ctx }),
|
|
571
|
-
},
|
|
572
575
|
(props) => React.createElement(PluginCard, { ...props, ctx: (props && props.ctx) || ctx })
|
|
573
576
|
)
|
|
574
577
|
);
|
|
578
|
+
|
|
575
579
|
};
|
|
576
580
|
return module.exports;
|
|
577
581
|
},
|
package/lib/guard-state.js
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
const
|
|
2
|
+
export const DEFAULT_STOP_PATTERNS = {
|
|
3
|
+
en: /(?<![\p{L}\p{N}_-])(?:stop|halt|cancel|abort|terminate)(?![\p{L}\p{N}_-])/iu,
|
|
4
|
+
zh: /(?:停止|暂停|取消|终止|死循环)/u,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const EXPLICIT_STOP_EN = /^(?:please\s+)?(?:stop|halt|cancel|abort|terminate)(?:\s+(?:now|please|immediately|execution|calling\s+tools|and\s+answer|and\s+explain))?[.!?]*$/iu;
|
|
8
|
+
const EXPLICIT_STOP_ZH = /^(?:请|检测到)?(?:停止|暂停|取消|终止|死循环)(?:执行|操作|调用|一下|了)?[!。??!]*$/u;
|
|
9
|
+
|
|
10
|
+
export function isDefaultStopRequest(text) {
|
|
11
|
+
if (!text || typeof text !== 'string') return false;
|
|
12
|
+
const trimmed = text.trim();
|
|
13
|
+
if (!trimmed) return false;
|
|
14
|
+
|
|
15
|
+
// Direct single-command match
|
|
16
|
+
if (EXPLICIT_STOP_EN.test(trimmed) || EXPLICIT_STOP_ZH.test(trimmed)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Multi-sentence / multi-line message: check if any standalone segment/sentence is an explicit stop command
|
|
21
|
+
const segments = trimmed.split(/[\r\n.!?。!?]+/).map((s) => s.trim()).filter(Boolean);
|
|
22
|
+
for (const segment of segments) {
|
|
23
|
+
if (EXPLICIT_STOP_EN.test(segment) || EXPLICIT_STOP_ZH.test(segment)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function compileStopPatterns(customPatterns = []) {
|
|
32
|
+
if (!Array.isArray(customPatterns)) return [];
|
|
33
|
+
const compiled = [];
|
|
34
|
+
for (const item of customPatterns) {
|
|
35
|
+
if (item instanceof RegExp) {
|
|
36
|
+
compiled.push(item);
|
|
37
|
+
} else if (typeof item === 'string' && item.trim() !== '') {
|
|
38
|
+
const escaped = item.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
39
|
+
compiled.push(new RegExp(escaped, 'iu'));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return compiled;
|
|
43
|
+
}
|
|
44
|
+
|
|
3
45
|
const SECRET_KEY_PATTERN = /(?:token|secret|password|authorization|api[-_]?key|cookie)/iu;
|
|
4
46
|
|
|
5
47
|
function stableJson(value) {
|
|
@@ -51,9 +93,26 @@ export function nonNegativeInteger(value, fallback) {
|
|
|
51
93
|
return Number.isSafeInteger(value) && value >= 0 ? value : fallback;
|
|
52
94
|
}
|
|
53
95
|
|
|
54
|
-
export function hasStopRequest(messages) {
|
|
96
|
+
export function hasStopRequest(messages, customPatterns = []) {
|
|
55
97
|
if (!Array.isArray(messages)) return false;
|
|
56
|
-
|
|
98
|
+
const compiledCustom = compileStopPatterns(customPatterns);
|
|
99
|
+
let lastUserMessage = null;
|
|
100
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
101
|
+
const msg = messages[i];
|
|
102
|
+
if (msg && (msg.source?.kind === 'user' || msg.role === 'user')) {
|
|
103
|
+
lastUserMessage = msg;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!lastUserMessage) return false;
|
|
108
|
+
|
|
109
|
+
const text = textFrom(lastUserMessage.content);
|
|
110
|
+
if (!text) return false;
|
|
111
|
+
|
|
112
|
+
if (isDefaultStopRequest(text)) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return compiledCustom.some((regex) => regex.test(text));
|
|
57
116
|
}
|
|
58
117
|
|
|
59
118
|
export function callFingerprint(name, args) {
|
|
@@ -130,6 +189,11 @@ export class LoopGuardState {
|
|
|
130
189
|
.filter((name) => typeof name === 'string' && name.trim() !== '')
|
|
131
190
|
.map((name) => name.trim())
|
|
132
191
|
: [];
|
|
192
|
+
const stopPatterns = Array.isArray(config.stopPatterns)
|
|
193
|
+
? config.stopPatterns
|
|
194
|
+
.filter((name) => typeof name === 'string' && name.trim() !== '')
|
|
195
|
+
.map((name) => name.trim())
|
|
196
|
+
: [];
|
|
133
197
|
this.config = {
|
|
134
198
|
...config,
|
|
135
199
|
maxToolAttemptsPerTurn: nonNegativeInteger(config.maxToolAttemptsPerTurn, 64),
|
|
@@ -138,7 +202,9 @@ export class LoopGuardState {
|
|
|
138
202
|
strictToolLimit: positiveInteger(config.strictToolLimit, 3),
|
|
139
203
|
dryRunMode: Boolean(config.dryRunMode),
|
|
140
204
|
blockExactDuplicates: config.blockExactDuplicates !== undefined ? Boolean(config.blockExactDuplicates) : true,
|
|
205
|
+
stopPatterns,
|
|
141
206
|
};
|
|
207
|
+
this.stopPatterns = stopPatterns;
|
|
142
208
|
this.logger = config.logger;
|
|
143
209
|
this.onViolation = typeof config.onViolation === 'function' ? config.onViolation : undefined;
|
|
144
210
|
this.progressToolNames = new Set(progressToolNames);
|
|
@@ -182,11 +248,21 @@ export class LoopGuardState {
|
|
|
182
248
|
dryRunMode: config.dryRunMode !== undefined ? Boolean(config.dryRunMode) : Boolean(this.config.dryRunMode),
|
|
183
249
|
blockExactDuplicates: config.blockExactDuplicates !== undefined ? Boolean(config.blockExactDuplicates) : this.config.blockExactDuplicates,
|
|
184
250
|
};
|
|
251
|
+
if (Array.isArray(config.stopPatterns)) {
|
|
252
|
+
this.stopPatterns = config.stopPatterns
|
|
253
|
+
.filter((name) => typeof name === 'string' && name.trim() !== '')
|
|
254
|
+
.map((name) => name.trim());
|
|
255
|
+
this.config.stopPatterns = this.stopPatterns;
|
|
256
|
+
}
|
|
185
257
|
if (config.logger !== undefined) this.logger = config.logger;
|
|
186
258
|
this.progressToolNames = new Set(progressToolNames);
|
|
187
259
|
this.strictTools = new Set(strictTools);
|
|
188
260
|
}
|
|
189
261
|
|
|
262
|
+
hasStopRequest(messages) {
|
|
263
|
+
return hasStopRequest(messages, this.stopPatterns);
|
|
264
|
+
}
|
|
265
|
+
|
|
190
266
|
recordExternalViolation(code, detail, extra = {}) {
|
|
191
267
|
this.metrics.totalViolations += 1;
|
|
192
268
|
this.metrics.byCode[code] = (this.metrics.byCode[code] || 0) + 1;
|
package/lib/index.js
CHANGED
|
@@ -46,6 +46,7 @@ export const Config = Schema.object({
|
|
|
46
46
|
maxRepeatedAssistantLines: Schema.number().volatile().min(1).default(5),
|
|
47
47
|
maxRepeatedAssistantBlocks: Schema.number().volatile().min(1).default(5),
|
|
48
48
|
maxAssistantBlockChars: Schema.number().volatile().min(256).default(16_384),
|
|
49
|
+
stopPatterns: Schema.array(Schema.string()).volatile().default([]),
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
function callIdFromEvent(event) {
|
|
@@ -125,6 +126,9 @@ export function apply(ctx, config = {}) {
|
|
|
125
126
|
const strictTools = Array.isArray(raw.strictTools)
|
|
126
127
|
? raw.strictTools.filter((t) => typeof t === 'string' && t.trim() !== '').map((t) => t.trim())
|
|
127
128
|
: [];
|
|
129
|
+
const stopPatterns = Array.isArray(raw.stopPatterns)
|
|
130
|
+
? raw.stopPatterns.filter((t) => typeof t === 'string' && t.trim() !== '').map((t) => t.trim())
|
|
131
|
+
: [];
|
|
128
132
|
return {
|
|
129
133
|
...raw,
|
|
130
134
|
maxToolAttemptsPerTurn: nonNegativeInteger(raw.maxToolAttemptsPerTurn, 64),
|
|
@@ -138,6 +142,7 @@ export function apply(ctx, config = {}) {
|
|
|
138
142
|
maxRepeatedAssistantLines: positiveInteger(raw.maxRepeatedAssistantLines, 5),
|
|
139
143
|
maxRepeatedAssistantBlocks: positiveInteger(raw.maxRepeatedAssistantBlocks, 5),
|
|
140
144
|
maxAssistantBlockChars: positiveInteger(raw.maxAssistantBlockChars, 16_384),
|
|
145
|
+
stopPatterns,
|
|
141
146
|
};
|
|
142
147
|
};
|
|
143
148
|
|
|
@@ -160,6 +165,7 @@ export function apply(ctx, config = {}) {
|
|
|
160
165
|
};
|
|
161
166
|
|
|
162
167
|
if (typeof ctx.on === 'function') {
|
|
168
|
+
ctx.on('loader/volatile-update', () => applyLiveConfig());
|
|
163
169
|
ctx.on('app-boot/config-reload', () => applyLiveConfig());
|
|
164
170
|
ctx.on('internal/update', () => applyLiveConfig());
|
|
165
171
|
}
|
|
@@ -183,11 +189,6 @@ export function apply(ctx, config = {}) {
|
|
|
183
189
|
if (desc && desc.value && typeof desc.value === 'object') {
|
|
184
190
|
return resolveConfig(desc.value);
|
|
185
191
|
}
|
|
186
|
-
} else if (typeof sctx.settings.get === 'function') {
|
|
187
|
-
const val = sctx.settings.get(NS);
|
|
188
|
-
if (val && typeof val === 'object') {
|
|
189
|
-
return resolveConfig(val);
|
|
190
|
-
}
|
|
191
192
|
}
|
|
192
193
|
} catch (error) {
|
|
193
194
|
ctx.logger?.warn?.('dsh-agent-loop-guard: settings describe failed: ' + (error instanceof Error ? error.message : String(error)));
|
|
@@ -248,7 +249,7 @@ export function apply(ctx, config = {}) {
|
|
|
248
249
|
kind: 'exact',
|
|
249
250
|
path: '/api/@goodandready/dsh-agent-loop-guard/telemetry',
|
|
250
251
|
handler: async (request, response) => {
|
|
251
|
-
if (!isTrustedTelemetryRequest(request)) {
|
|
252
|
+
if (!isTrustedTelemetryRequest(request, wctx)) {
|
|
252
253
|
response.writeHead(403, {
|
|
253
254
|
'content-type': 'application/json; charset=utf-8',
|
|
254
255
|
'cache-control': 'no-store',
|
|
@@ -292,7 +293,7 @@ export function apply(ctx, config = {}) {
|
|
|
292
293
|
ctx.on('agent/pre-step', async ({ agent, turn, messages, signal }, next) => {
|
|
293
294
|
const decision = await next();
|
|
294
295
|
if (decision.kind === 'reject' || signal.aborted) return decision;
|
|
295
|
-
state.beginTurn(agent, turn, hasStopRequest(messages));
|
|
296
|
+
state.beginTurn(agent, turn, state.hasStopRequest(messages));
|
|
296
297
|
return decision;
|
|
297
298
|
});
|
|
298
299
|
|
package/lib/plugin-updater.js
CHANGED
|
@@ -33,11 +33,43 @@ export function isPrivateLan(value) {
|
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export function getConnection(ctx) {
|
|
37
|
+
try {
|
|
38
|
+
const fromCtx = ctx?.reflect?.get
|
|
39
|
+
? (ctx.reflect.get('connection') || ctx?.connection)
|
|
40
|
+
: (ctx?.get ? (ctx.get('connection') || ctx?.connection) : Reflect.get(ctx || {}, 'connection'));
|
|
41
|
+
if (fromCtx) return fromCtx;
|
|
42
|
+
if (ctx?.root) {
|
|
43
|
+
return getConnection(ctx.root);
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isTrustedTelemetryRequest(request, targetCtx = null) {
|
|
52
|
+
// 1. Core connection auth check
|
|
53
|
+
const conn = getConnection(targetCtx);
|
|
54
|
+
if (conn && typeof conn.requestRejection === 'function') {
|
|
55
|
+
let rejection;
|
|
56
|
+
try {
|
|
57
|
+
rejection = conn.requestRejection(request);
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (rejection !== undefined) return false;
|
|
62
|
+
} else {
|
|
63
|
+
// Fallback when connection service is absent (e.g. standalone tests):
|
|
64
|
+
// Remote must be loopback AND require sec-fetch-site (same-origin or none)
|
|
65
|
+
if (!isLoopback(request?.socket?.remoteAddress)) return false;
|
|
66
|
+
const site = header(request, 'sec-fetch-site');
|
|
67
|
+
if (site !== 'same-origin' && site !== 'none') return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 2. For POST (reset telemetry): require x-dsh-loop-guard: 1 and origin verification
|
|
71
|
+
if (request?.method === 'POST') {
|
|
72
|
+
if (header(request, 'x-dsh-loop-guard') !== '1') return false;
|
|
41
73
|
const origin = header(request, 'origin');
|
|
42
74
|
const host = header(request, 'host');
|
|
43
75
|
if (origin === undefined || host === undefined) return false;
|
|
@@ -49,12 +81,23 @@ export function isTrustedTelemetryRequest(request) {
|
|
|
49
81
|
return false;
|
|
50
82
|
}
|
|
51
83
|
}
|
|
84
|
+
|
|
52
85
|
return true;
|
|
53
86
|
}
|
|
54
87
|
|
|
55
|
-
export function isTrustedUpdateRequest(request) {
|
|
88
|
+
export function isTrustedUpdateRequest(request, targetCtx = null) {
|
|
56
89
|
if (header(request, UPDATE_HEADER) !== '1') return false;
|
|
57
|
-
|
|
90
|
+
const conn = getConnection(targetCtx);
|
|
91
|
+
if (conn && typeof conn.requestRejection === 'function') {
|
|
92
|
+
let rejection;
|
|
93
|
+
try {
|
|
94
|
+
rejection = conn.requestRejection(request);
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (rejection !== undefined) return false;
|
|
99
|
+
}
|
|
100
|
+
if (!isLoopback(request?.socket?.remoteAddress)) return false;
|
|
58
101
|
const site = header(request, 'sec-fetch-site');
|
|
59
102
|
if (site !== undefined && site !== 'same-origin') return false;
|
|
60
103
|
const origin = header(request, 'origin');
|
|
@@ -82,7 +125,65 @@ function profileNameFromArgv(argv) {
|
|
|
82
125
|
return argv[2] === 'web' ? 'web' : undefined;
|
|
83
126
|
}
|
|
84
127
|
|
|
85
|
-
function
|
|
128
|
+
export function isDesktopProfile(profileName, profileDir) {
|
|
129
|
+
if (process.env.DSH_PROFILE === 'desktop' || process.env.DSH_DESKTOP === '1' || process.env.DSH_DESKTOP === 'true') return true;
|
|
130
|
+
if (profileName === 'desktop') return true;
|
|
131
|
+
if (typeof profileName === 'string' && profileName.toLowerCase() === 'desktop') return true;
|
|
132
|
+
if (typeof profileDir === 'string' && basename(resolve(profileDir)).toLowerCase() === 'desktop') return true;
|
|
133
|
+
if (typeof process.versions?.electron === 'string') return true;
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function findDesktopCliEntry() {
|
|
138
|
+
if (process.env.DSH_DESKTOP_CLI && existsSync(process.env.DSH_DESKTOP_CLI)) {
|
|
139
|
+
return process.env.DSH_DESKTOP_CLI;
|
|
140
|
+
}
|
|
141
|
+
const isWin = process.platform === 'win32';
|
|
142
|
+
const cliName = isWin ? 'dsh.cmd' : 'dsh';
|
|
143
|
+
|
|
144
|
+
const pathEnv = process.env.PATH || '';
|
|
145
|
+
const pathDirs = pathEnv.split(isWin ? ';' : ':');
|
|
146
|
+
for (const dir of pathDirs) {
|
|
147
|
+
if (!dir) continue;
|
|
148
|
+
try {
|
|
149
|
+
const candidate = resolve(dir, cliName);
|
|
150
|
+
if (existsSync(candidate)) return candidate;
|
|
151
|
+
} catch {}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (typeof process.resourcesPath === 'string') {
|
|
155
|
+
try {
|
|
156
|
+
const candidate = resolve(process.resourcesPath, 'runtime', 'cli', 'bin', cliName);
|
|
157
|
+
if (existsSync(candidate)) return candidate;
|
|
158
|
+
} catch {}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const execDir = dirname(process.execPath);
|
|
163
|
+
const candidate = resolve(execDir, 'resources', 'runtime', 'cli', 'bin', cliName);
|
|
164
|
+
if (existsSync(candidate)) return candidate;
|
|
165
|
+
} catch {}
|
|
166
|
+
|
|
167
|
+
if (isWin && process.env.LOCALAPPDATA) {
|
|
168
|
+
try {
|
|
169
|
+
const candidate = resolve(
|
|
170
|
+
process.env.LOCALAPPDATA,
|
|
171
|
+
'Programs',
|
|
172
|
+
'DeepSeek Harness',
|
|
173
|
+
'resources',
|
|
174
|
+
'runtime',
|
|
175
|
+
'cli',
|
|
176
|
+
'bin',
|
|
177
|
+
'dsh.cmd'
|
|
178
|
+
);
|
|
179
|
+
if (existsSync(candidate)) return candidate;
|
|
180
|
+
} catch {}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function findDshCliEntry() {
|
|
86
187
|
const value = process.argv[1];
|
|
87
188
|
if (value === undefined || value === '') return undefined;
|
|
88
189
|
const entry = value.startsWith('file:') ? fileURLToPath(value) : resolve(process.cwd(), value);
|
|
@@ -108,15 +209,23 @@ function findDshCliEntry() {
|
|
|
108
209
|
}
|
|
109
210
|
}
|
|
110
211
|
|
|
111
|
-
function runtime() {
|
|
212
|
+
export function runtime() {
|
|
112
213
|
const profileDir = resolve(process.env.DSH_PROFILE_DIR
|
|
113
214
|
?? resolve(homedir(), '.dsh', 'profiles', 'web'));
|
|
114
|
-
const selected = profileNameFromArgv(process.argv);
|
|
215
|
+
const selected = profileNameFromArgv(process.argv) || process.env.DSH_PROFILE;
|
|
115
216
|
const profileName = validProfileName(selected)
|
|
116
217
|
? selected
|
|
117
218
|
: validProfileName(basename(profileDir)) ? basename(profileDir) : 'web';
|
|
118
|
-
const
|
|
119
|
-
|
|
219
|
+
const isDesktop = isDesktopProfile(profileName, profileDir);
|
|
220
|
+
const desktopCli = isDesktop ? findDesktopCliEntry() : undefined;
|
|
221
|
+
const cliEntry = isDesktop ? desktopCli : findDshCliEntry();
|
|
222
|
+
return {
|
|
223
|
+
profileName,
|
|
224
|
+
profileDir,
|
|
225
|
+
isDesktop,
|
|
226
|
+
...(desktopCli !== undefined ? { desktopCli } : {}),
|
|
227
|
+
...(cliEntry !== undefined ? { cliEntry } : {}),
|
|
228
|
+
};
|
|
120
229
|
}
|
|
121
230
|
|
|
122
231
|
function parseSemver(value) {
|
|
@@ -189,7 +298,7 @@ export async function currentVersion(manifestUrl) {
|
|
|
189
298
|
}
|
|
190
299
|
}
|
|
191
300
|
|
|
192
|
-
async function status(options, target) {
|
|
301
|
+
export async function status(options, target) {
|
|
193
302
|
let current = 'unknown';
|
|
194
303
|
try {
|
|
195
304
|
current = await currentVersion(options.manifestUrl);
|
|
@@ -198,6 +307,8 @@ async function status(options, target) {
|
|
|
198
307
|
}
|
|
199
308
|
const latest = await latestVersion(options.packageName, options.registry ?? 'https://registry.npmjs.org');
|
|
200
309
|
const validCurrent = current !== 'unknown';
|
|
310
|
+
const isDesktop = Boolean(target.isDesktop);
|
|
311
|
+
const canAutoUpdate = Boolean(target.cliEntry !== undefined && (!isDesktop || target.desktopCli !== undefined));
|
|
201
312
|
return {
|
|
202
313
|
packageName: options.packageName,
|
|
203
314
|
currentVersion: current,
|
|
@@ -205,23 +316,37 @@ async function status(options, target) {
|
|
|
205
316
|
latestCheckFailed: latest === undefined || !validCurrent,
|
|
206
317
|
updateAvailable: latest !== undefined && validCurrent && isNewerVersion(current, latest),
|
|
207
318
|
profileName: target.profileName,
|
|
208
|
-
|
|
319
|
+
isDesktop,
|
|
320
|
+
canAutoUpdate,
|
|
209
321
|
};
|
|
210
322
|
}
|
|
211
323
|
|
|
212
324
|
async function installExact(target, packageSpec, options) {
|
|
213
325
|
if (target.cliEntry === undefined) throw new Error('Automatic update is unavailable in this runtime.');
|
|
214
326
|
await new Promise((resolvePromise, reject) => {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
327
|
+
const isCmd = typeof target.cliEntry === 'string' && target.cliEntry.endsWith('.cmd');
|
|
328
|
+
const child = isCmd
|
|
329
|
+
? spawn(target.cliEntry, [
|
|
330
|
+
'plugin', '--profile', target.profileName, 'add',
|
|
331
|
+
packageSpec,
|
|
332
|
+
`--registry=${options.registry ?? 'https://registry.npmjs.org/'}`,
|
|
333
|
+
], {
|
|
334
|
+
cwd: target.profileDir,
|
|
335
|
+
windowsHide: true,
|
|
336
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
337
|
+
shell: true,
|
|
338
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
339
|
+
})
|
|
340
|
+
: spawn(process.execPath, [
|
|
341
|
+
target.cliEntry, 'plugin', '--profile', target.profileName, 'add',
|
|
342
|
+
packageSpec,
|
|
343
|
+
`--registry=${options.registry ?? 'https://registry.npmjs.org/'}`,
|
|
344
|
+
], {
|
|
345
|
+
cwd: target.profileDir,
|
|
346
|
+
windowsHide: true,
|
|
347
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
348
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
349
|
+
});
|
|
225
350
|
let detail = '';
|
|
226
351
|
child.stdout?.on('data', (chunk) => { detail = (detail + String(chunk)).slice(-4_000); });
|
|
227
352
|
child.stderr?.on('data', (chunk) => { detail = (detail + String(chunk)).slice(-4_000); });
|
|
@@ -272,7 +397,7 @@ export function registerPluginUpdater(ctx, options) {
|
|
|
272
397
|
response.end();
|
|
273
398
|
return;
|
|
274
399
|
}
|
|
275
|
-
if (!isTrustedUpdateRequest(request)) {
|
|
400
|
+
if (!isTrustedUpdateRequest(request, ctx)) {
|
|
276
401
|
json(response, 403, { error: 'Rejected non-local or cross-origin update request.' });
|
|
277
402
|
return;
|
|
278
403
|
}
|
|
@@ -306,4 +431,4 @@ export function registerPluginUpdater(ctx, options) {
|
|
|
306
431
|
}
|
|
307
432
|
},
|
|
308
433
|
});
|
|
309
|
-
}
|
|
434
|
+
}
|
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.25",
|
|
4
4
|
"description": "Fail-closed runtime tool-call loop guard for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
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
25
|
"build:client": "node scripts/build-client.mjs",
|
|
26
26
|
"pretest": "node scripts/build-client.mjs",
|
|
27
|
-
"clean": "
|
|
27
|
+
"clean": "node scripts/clean-pack.mjs",
|
|
28
|
+
"pack:release": "node scripts/pack-release.mjs"
|
|
28
29
|
},
|
|
29
30
|
"dsh": {
|
|
30
31
|
"bundle": {
|