@goodandready/dsh-agent-loop-guard 0.2.17 → 0.2.24
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 +49 -0
- package/lib/assistant-output-state.js +3 -2
- package/lib/client.js +61 -57
- package/lib/guard-state.js +47 -3
- package/lib/index.js +27 -14
- package/lib/plugin-updater.js +151 -26
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.24] - 2026-10-15
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **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.
|
|
7
|
+
- **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).
|
|
8
|
+
|
|
9
|
+
## [0.2.23] - 2026-10-11
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **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.
|
|
13
|
+
|
|
14
|
+
## [0.2.22] - 2026-10-09
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- **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.
|
|
18
|
+
- **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.
|
|
19
|
+
|
|
20
|
+
## [0.2.21] - 2026-10-09
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- **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.
|
|
24
|
+
- **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.
|
|
25
|
+
|
|
26
|
+
## [0.2.20] - 2026-10-09
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- **Streamed Text Memory Cap (#97)**: Capped `streamedText` buffer in `AssistantOutputGuardState` to `maxAssistantBlockChars` to prevent unbounded memory growth during long streaming assistant turns.
|
|
30
|
+
- **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.
|
|
31
|
+
- **Settings Loader Fallback Cleanup (#99)**: Removed dead `typeof sctx.settings.get === 'function'` fallback from live config reader.
|
|
32
|
+
- **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()`.
|
|
33
|
+
|
|
34
|
+
## [0.2.19] - 2026-10-08
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
- **Settings Contract & Snapshot Reader (#90)**: Replaced non-existent with synchronous , unpacked settings values from ( contract) instead of , and bound reactive updates through .
|
|
38
|
+
- **Locale Resolution & Reactivity (#40)**: Read active locale identifier from in with fallback to and , ensuring settings card respects the host language selection over browser .
|
|
39
|
+
- **Volatile Schema Verification (#89)**: Verified and tested that all 13 user-facing schema fields carry (), ensuring live configuration registration under DSH 0.2.0.
|
|
40
|
+
|
|
41
|
+
## [0.2.18] - 2026-09-30
|
|
42
|
+
|
|
43
|
+
### Fixed
|
|
44
|
+
- **Cordis Volatile Unwrapping (#93)**: Unwrapped Volatile settings references recursively via `plainConfig()` and `resolveConfig()` before and after Schemastery `Config(...)` validation, preventing `ValidationError: $.maxToolAttemptsPerTurn expected number but got [object Object]` during plugin activation under DSH 0.2.0-rc.2.
|
|
45
|
+
- **Strict Validation Integrity**: Preserved strict error throwing on invalid user types (e.g. non-numeric volatile values or arbitrary non-volatile objects) without silent coercion.
|
|
46
|
+
|
|
47
|
+
## [0.2.17] - 2026-09-29
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
- **Settings Form ID Binding (#92)**: Keyed form presentation under the entry ID for DSH 0.1.7-rc.2 and 0.2.0 hosts.
|
|
51
|
+
|
|
3
52
|
## 0.2.16
|
|
4
53
|
|
|
5
54
|
### Fixed
|
|
@@ -168,12 +168,13 @@ 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
|
state.pending += text;
|
|
@@ -239,7 +240,7 @@ export class AssistantOutputGuardState {
|
|
|
239
240
|
}
|
|
240
241
|
const suffix = prior.length > 0 && prior !== text && text.startsWith(prior) ? text.slice(prior.length) : text;
|
|
241
242
|
const hit = this.observeText(session, { turn, step, index, text: suffix });
|
|
242
|
-
state.streamedText = text;
|
|
243
|
+
state.streamedText = text.length > this.maxAssistantBlockChars ? text.slice(-this.maxAssistantBlockChars) : text;
|
|
243
244
|
state.streamedSkipAvailable = false;
|
|
244
245
|
if (hit) return hit;
|
|
245
246
|
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,23 @@
|
|
|
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|answer(?:\s+now)?)(?![\p{L}\p{N}_-])/iu,
|
|
4
|
+
zh: /(?:停止|暂停|取消|终止|回答|死循环)/u,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function compileStopPatterns(customPatterns = []) {
|
|
8
|
+
if (!Array.isArray(customPatterns)) return [];
|
|
9
|
+
const compiled = [];
|
|
10
|
+
for (const item of customPatterns) {
|
|
11
|
+
if (item instanceof RegExp) {
|
|
12
|
+
compiled.push(item);
|
|
13
|
+
} else if (typeof item === 'string' && item.trim() !== '') {
|
|
14
|
+
const escaped = item.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
15
|
+
compiled.push(new RegExp(escaped, 'iu'));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return compiled;
|
|
19
|
+
}
|
|
20
|
+
|
|
3
21
|
const SECRET_KEY_PATTERN = /(?:token|secret|password|authorization|api[-_]?key|cookie)/iu;
|
|
4
22
|
|
|
5
23
|
function stableJson(value) {
|
|
@@ -51,9 +69,18 @@ export function nonNegativeInteger(value, fallback) {
|
|
|
51
69
|
return Number.isSafeInteger(value) && value >= 0 ? value : fallback;
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
export function hasStopRequest(messages) {
|
|
72
|
+
export function hasStopRequest(messages, customPatterns = []) {
|
|
55
73
|
if (!Array.isArray(messages)) return false;
|
|
56
|
-
|
|
74
|
+
const compiledCustom = compileStopPatterns(customPatterns);
|
|
75
|
+
return messages.some((message) => {
|
|
76
|
+
if (message?.source?.kind !== 'user') return false;
|
|
77
|
+
const text = textFrom(message.content);
|
|
78
|
+
if (!text) return false;
|
|
79
|
+
if (DEFAULT_STOP_PATTERNS.en.test(text) || DEFAULT_STOP_PATTERNS.zh.test(text)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return compiledCustom.some((regex) => regex.test(text));
|
|
83
|
+
});
|
|
57
84
|
}
|
|
58
85
|
|
|
59
86
|
export function callFingerprint(name, args) {
|
|
@@ -130,6 +157,11 @@ export class LoopGuardState {
|
|
|
130
157
|
.filter((name) => typeof name === 'string' && name.trim() !== '')
|
|
131
158
|
.map((name) => name.trim())
|
|
132
159
|
: [];
|
|
160
|
+
const stopPatterns = Array.isArray(config.stopPatterns)
|
|
161
|
+
? config.stopPatterns
|
|
162
|
+
.filter((name) => typeof name === 'string' && name.trim() !== '')
|
|
163
|
+
.map((name) => name.trim())
|
|
164
|
+
: [];
|
|
133
165
|
this.config = {
|
|
134
166
|
...config,
|
|
135
167
|
maxToolAttemptsPerTurn: nonNegativeInteger(config.maxToolAttemptsPerTurn, 64),
|
|
@@ -138,7 +170,9 @@ export class LoopGuardState {
|
|
|
138
170
|
strictToolLimit: positiveInteger(config.strictToolLimit, 3),
|
|
139
171
|
dryRunMode: Boolean(config.dryRunMode),
|
|
140
172
|
blockExactDuplicates: config.blockExactDuplicates !== undefined ? Boolean(config.blockExactDuplicates) : true,
|
|
173
|
+
stopPatterns,
|
|
141
174
|
};
|
|
175
|
+
this.stopPatterns = stopPatterns;
|
|
142
176
|
this.logger = config.logger;
|
|
143
177
|
this.onViolation = typeof config.onViolation === 'function' ? config.onViolation : undefined;
|
|
144
178
|
this.progressToolNames = new Set(progressToolNames);
|
|
@@ -182,11 +216,21 @@ export class LoopGuardState {
|
|
|
182
216
|
dryRunMode: config.dryRunMode !== undefined ? Boolean(config.dryRunMode) : Boolean(this.config.dryRunMode),
|
|
183
217
|
blockExactDuplicates: config.blockExactDuplicates !== undefined ? Boolean(config.blockExactDuplicates) : this.config.blockExactDuplicates,
|
|
184
218
|
};
|
|
219
|
+
if (Array.isArray(config.stopPatterns)) {
|
|
220
|
+
this.stopPatterns = config.stopPatterns
|
|
221
|
+
.filter((name) => typeof name === 'string' && name.trim() !== '')
|
|
222
|
+
.map((name) => name.trim());
|
|
223
|
+
this.config.stopPatterns = this.stopPatterns;
|
|
224
|
+
}
|
|
185
225
|
if (config.logger !== undefined) this.logger = config.logger;
|
|
186
226
|
this.progressToolNames = new Set(progressToolNames);
|
|
187
227
|
this.strictTools = new Set(strictTools);
|
|
188
228
|
}
|
|
189
229
|
|
|
230
|
+
hasStopRequest(messages) {
|
|
231
|
+
return hasStopRequest(messages, this.stopPatterns);
|
|
232
|
+
}
|
|
233
|
+
|
|
190
234
|
recordExternalViolation(code, detail, extra = {}) {
|
|
191
235
|
this.metrics.totalViolations += 1;
|
|
192
236
|
this.metrics.byCode[code] = (this.metrics.byCode[code] || 0) + 1;
|
package/lib/index.js
CHANGED
|
@@ -11,13 +11,25 @@ import { registerPluginUpdater, isTrustedTelemetryRequest } from './plugin-updat
|
|
|
11
11
|
export const name = '@goodandready/dsh-agent-loop-guard';
|
|
12
12
|
export const inject = ['tools', 'agents', 'sessions'];
|
|
13
13
|
|
|
14
|
+
export function isVolatileRef(value) {
|
|
15
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) && typeof value.get === 'function';
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
// Unwrap Volatile boxes before any caller reads a value. A volatile field holds a box
|
|
15
19
|
// rather than its value, and the Loader mutates those boxes in place.
|
|
16
20
|
export function plainConfig(value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
while (typeof value === 'function') {
|
|
22
|
+
value = value();
|
|
23
|
+
}
|
|
24
|
+
if (isVolatileRef(value)) return plainConfig(value.get());
|
|
25
|
+
if (value === null || typeof value !== 'object') return value;
|
|
26
|
+
if (Array.isArray(value)) return value.map(plainConfig);
|
|
27
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, plainConfig(v)]));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function resolveConfig(raw) {
|
|
31
|
+
const unwrapped = plainConfig(raw);
|
|
32
|
+
return plainConfig(Config(unwrapped));
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
export const Config = Schema.object({
|
|
@@ -34,6 +46,7 @@ export const Config = Schema.object({
|
|
|
34
46
|
maxRepeatedAssistantLines: Schema.number().volatile().min(1).default(5),
|
|
35
47
|
maxRepeatedAssistantBlocks: Schema.number().volatile().min(1).default(5),
|
|
36
48
|
maxAssistantBlockChars: Schema.number().volatile().min(256).default(16_384),
|
|
49
|
+
stopPatterns: Schema.array(Schema.string()).volatile().default([]),
|
|
37
50
|
});
|
|
38
51
|
|
|
39
52
|
function callIdFromEvent(event) {
|
|
@@ -106,13 +119,16 @@ function logGuardViolation(ctx, event) {
|
|
|
106
119
|
|
|
107
120
|
export function apply(ctx, config = {}) {
|
|
108
121
|
const NS = name;
|
|
109
|
-
let getConfig = () =>
|
|
122
|
+
let getConfig = () => resolveConfig(ctx.fiber?.config ?? config) ?? {};
|
|
110
123
|
|
|
111
124
|
const syncFrom = (raw) => {
|
|
112
125
|
const maxCallsPerRepeatGroup = positiveInteger(raw.maxCallsPerRepeatGroup ?? raw.maxCallsPerToolPerTurn, 5);
|
|
113
126
|
const strictTools = Array.isArray(raw.strictTools)
|
|
114
127
|
? raw.strictTools.filter((t) => typeof t === 'string' && t.trim() !== '').map((t) => t.trim())
|
|
115
128
|
: [];
|
|
129
|
+
const stopPatterns = Array.isArray(raw.stopPatterns)
|
|
130
|
+
? raw.stopPatterns.filter((t) => typeof t === 'string' && t.trim() !== '').map((t) => t.trim())
|
|
131
|
+
: [];
|
|
116
132
|
return {
|
|
117
133
|
...raw,
|
|
118
134
|
maxToolAttemptsPerTurn: nonNegativeInteger(raw.maxToolAttemptsPerTurn, 64),
|
|
@@ -126,6 +142,7 @@ export function apply(ctx, config = {}) {
|
|
|
126
142
|
maxRepeatedAssistantLines: positiveInteger(raw.maxRepeatedAssistantLines, 5),
|
|
127
143
|
maxRepeatedAssistantBlocks: positiveInteger(raw.maxRepeatedAssistantBlocks, 5),
|
|
128
144
|
maxAssistantBlockChars: positiveInteger(raw.maxAssistantBlockChars, 16_384),
|
|
145
|
+
stopPatterns,
|
|
129
146
|
};
|
|
130
147
|
};
|
|
131
148
|
|
|
@@ -148,6 +165,7 @@ export function apply(ctx, config = {}) {
|
|
|
148
165
|
};
|
|
149
166
|
|
|
150
167
|
if (typeof ctx.on === 'function') {
|
|
168
|
+
ctx.on('loader/volatile-update', () => applyLiveConfig());
|
|
151
169
|
ctx.on('app-boot/config-reload', () => applyLiveConfig());
|
|
152
170
|
ctx.on('internal/update', () => applyLiveConfig());
|
|
153
171
|
}
|
|
@@ -169,12 +187,7 @@ export function apply(ctx, config = {}) {
|
|
|
169
187
|
if (typeof sctx.settings.describe === 'function') {
|
|
170
188
|
const desc = sctx.settings.describe().find((row) => row.ns === NS);
|
|
171
189
|
if (desc && desc.value && typeof desc.value === 'object') {
|
|
172
|
-
return
|
|
173
|
-
}
|
|
174
|
-
} else if (typeof sctx.settings.get === 'function') {
|
|
175
|
-
const val = sctx.settings.get(NS);
|
|
176
|
-
if (val && typeof val === 'object') {
|
|
177
|
-
return Config(val);
|
|
190
|
+
return resolveConfig(desc.value);
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
193
|
} catch (error) {
|
|
@@ -183,7 +196,7 @@ export function apply(ctx, config = {}) {
|
|
|
183
196
|
return null;
|
|
184
197
|
};
|
|
185
198
|
|
|
186
|
-
getConfig = () => readLiveSettings() ??
|
|
199
|
+
getConfig = () => readLiveSettings() ?? resolveConfig(ctx.fiber?.config ?? config) ?? {};
|
|
187
200
|
applyLiveConfig();
|
|
188
201
|
|
|
189
202
|
const disposeDocUpdated = typeof sctx.on === 'function'
|
|
@@ -236,7 +249,7 @@ export function apply(ctx, config = {}) {
|
|
|
236
249
|
kind: 'exact',
|
|
237
250
|
path: '/api/@goodandready/dsh-agent-loop-guard/telemetry',
|
|
238
251
|
handler: async (request, response) => {
|
|
239
|
-
if (!isTrustedTelemetryRequest(request)) {
|
|
252
|
+
if (!isTrustedTelemetryRequest(request, wctx)) {
|
|
240
253
|
response.writeHead(403, {
|
|
241
254
|
'content-type': 'application/json; charset=utf-8',
|
|
242
255
|
'cache-control': 'no-store',
|
|
@@ -280,7 +293,7 @@ export function apply(ctx, config = {}) {
|
|
|
280
293
|
ctx.on('agent/pre-step', async ({ agent, turn, messages, signal }, next) => {
|
|
281
294
|
const decision = await next();
|
|
282
295
|
if (decision.kind === 'reject' || signal.aborted) return decision;
|
|
283
|
-
state.beginTurn(agent, turn, hasStopRequest(messages));
|
|
296
|
+
state.beginTurn(agent, turn, state.hasStopRequest(messages));
|
|
284
297
|
return decision;
|
|
285
298
|
});
|
|
286
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.24",
|
|
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": {
|