@twinsearth/ai-prison-dsh-plugin 1.4.7 → 1.5.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 +41 -0
- package/client.js +8 -1
- package/lib/notifier.js +80 -0
- package/lib/watchdog-policy.js +47 -0
- package/lib/watchdog-runtime.js +95 -23
- package/locale/en.json +4 -2
- package/locale/zh.json +4 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@twinsearth/ai-prison-dsh-plugin` are recorded here.
|
|
4
4
|
|
|
5
|
+
## [1.5.0] — 2026-11-18
|
|
6
|
+
|
|
7
|
+
### Changed — profile tamper monitor is dry-run (observe) by default
|
|
8
|
+
|
|
9
|
+
- `tamperPolicy` now accepts `observe` (default), `alert` and `restore`. In
|
|
10
|
+
`observe` the monitor still snapshots the five critical files, backs up the
|
|
11
|
+
drifted bytes to `tampered/` and records an L1 plan/incident, but **never
|
|
12
|
+
restores the file, never quarantines and never closes a plugin** — the
|
|
13
|
+
dry-run stage requested before turning the guard on.
|
|
14
|
+
- `alert` records only as well; only an explicit `tamperPolicy: "restore"`
|
|
15
|
+
restores the bytes and applies L1 enforcement.
|
|
16
|
+
- The panel line now shows the active policy, and the tool snapshot carries it.
|
|
17
|
+
|
|
18
|
+
### Added — Top5 v2 (child RSS, EWMA, stable order)
|
|
19
|
+
|
|
20
|
+
- Every 60 s the watchdog scans the process table (Windows) and attributes the
|
|
21
|
+
working set of processes whose command line references
|
|
22
|
+
`profiles/desktop/node_modules/<plugin>` to that plugin (`rssMB`).
|
|
23
|
+
- Top5 scores `module-load/operation estimate + child RSS`, smooths RSS with an
|
|
24
|
+
EWMA (alpha 0.35) and only reorders when a score moved more than 20 %, which
|
|
25
|
+
stops the list from jumping on every sample.
|
|
26
|
+
- The panel Top5 table gained a child-RSS column; the tool snapshot exposes
|
|
27
|
+
`rss` and `rssAt`.
|
|
28
|
+
- A pre-freeze heap snapshot is intentionally not taken: at 4.5 GB of a 6 GB
|
|
29
|
+
heap the snapshot's ~2x temporary cost would OOM the host, so freeze keeps
|
|
30
|
+
using the measured/estimate/RSS data.
|
|
31
|
+
|
|
32
|
+
### Added — optional desktop notifications
|
|
33
|
+
|
|
34
|
+
- `config: { notify: true }` turns on a Windows tray-balloon notification for
|
|
35
|
+
freeze, pause, quarantine, tamper, crash-enforcement and budget incidents
|
|
36
|
+
(rate limited per kind, 60 s; disabled by default). The watchdog does not
|
|
37
|
+
depend on it: failures are ignored.
|
|
38
|
+
|
|
39
|
+
### Notes
|
|
40
|
+
- The monitor stays a module inside the watchdog row rather than a separate
|
|
41
|
+
loader row: it runs in the same host process either way, and keeping it in
|
|
42
|
+
the row avoids a second loader entry whose failure would silently remove the
|
|
43
|
+
status API as well. It can already be disabled with `tamperMonitor: false`.
|
|
44
|
+
|
|
45
|
+
## [1.4.7] — 2026-11-18
|
|
5
46
|
## [1.4.7] — 2026-11-18
|
|
6
47
|
|
|
7
48
|
### Added — panel/remote operations roll back while paused or frozen
|
package/client.js
CHANGED
|
@@ -460,9 +460,16 @@ window.__ModuleLoader__.load({
|
|
|
460
460
|
topFive.length === 0 ? null : h('div', null,
|
|
461
461
|
h('div', { style: { ...C.key, marginBottom: 4 } }, t('watchdog.topFive', { n: topFive.length })),
|
|
462
462
|
h('table', { style: C.table },
|
|
463
|
+
h('thead', null, h('tr', null,
|
|
464
|
+
h('th', { style: C.th }, t('prison.plugin')),
|
|
465
|
+
h('th', { style: C.th }, t('prison.estimate')),
|
|
466
|
+
h('th', { style: C.th }, t('prison.rss')),
|
|
467
|
+
h('th', { style: C.th }, ''),
|
|
468
|
+
)),
|
|
463
469
|
h('tbody', null, topFive.map((row) => h('tr', { key: row.target },
|
|
464
470
|
h('td', { style: { ...C.td, ...C.mono, fontSize: 11.5, wordBreak: 'break-all' } }, row.target),
|
|
465
471
|
h('td', { style: C.td }, row.estimateMB + ' MB'),
|
|
472
|
+
h('td', { style: C.td }, (row.rssMB || 0) + ' MB'),
|
|
466
473
|
h('td', { style: C.td }, h('button', { style: button, onClick: () => act('close', row.target, '立即关闭 ' + row.target + ' ?') }, t('watchdog.close'))),
|
|
467
474
|
))),
|
|
468
475
|
),
|
|
@@ -473,7 +480,7 @@ window.__ModuleLoader__.load({
|
|
|
473
480
|
plan.at + ' · ' + plan.level + ' · ' + (plan.target || 'unattributed') + (plan.inFlight ? ' (in-flight)' : '') + (plan.crash ? ' · ' + (plan.crash.oom ? 'OOM' : 'exit ' + plan.crash.hostExitCode) : ''))),
|
|
474
481
|
),
|
|
475
482
|
watchdog.baseline ? h('p', { style: { ...C.muted, fontSize: 11.5, margin: '10px 0 0' } }, t('watchdog.baseline', { at: watchdog.baseline.at })) : null,
|
|
476
|
-
watchdog.tamper ? h('p', { style: { ...C.muted, fontSize: 11.5, margin: '6px 0 0' } }, t('watchdog.tamper', { n: (watchdog.tamper.files || []).length, at: watchdog.tamper.lastCheckAt || '—' })) : null,
|
|
483
|
+
watchdog.tamper ? h('p', { style: { ...C.muted, fontSize: 11.5, margin: '6px 0 0' } }, t('watchdog.tamper', { n: (watchdog.tamper.files || []).length, at: watchdog.tamper.lastCheckAt || '—', policy: watchdog.tamper.policy || '' })) : null,
|
|
477
484
|
h('div', { style: { marginTop: 10, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
478
485
|
h('button', { style: { ...button, padding: '5px 10px', opacity: frozen ? 0.5 : 1 }, disabled: frozen, title: frozen ? t('watchdog.measureBlocked') : undefined, onClick: () => { if (!frozen) act('probe') } }, t('watchdog.measure')),
|
|
479
486
|
watchdog.probeProgress ? h('span', { style: { ...C.mono, fontSize: 11.5 } }, `${watchdog.probeProgress.done || 0}/${watchdog.probeProgress.total || 0}`) : null,
|
package/lib/notifier.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Optional desktop notification for enforcement events. Uses the Windows tray
|
|
5
|
+
* balloon through PowerShell so no extra dependency is needed. Disabled by
|
|
6
|
+
* default; enable with `config: { notify: true }` on the watchdog row.
|
|
7
|
+
*/
|
|
8
|
+
const KIND_LABELS = {
|
|
9
|
+
freeze: '内存冻结',
|
|
10
|
+
pause: '内存暂停',
|
|
11
|
+
quarantine: '插件隔离',
|
|
12
|
+
tamper: '配置篡改',
|
|
13
|
+
'crash-enforced': '崩溃隔离',
|
|
14
|
+
budget: '内存超限',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let lastAt = 0
|
|
18
|
+
let lastKind = ''
|
|
19
|
+
|
|
20
|
+
export function shouldNotify(kind, now = Date.now(), cooldownMs = 60_000) {
|
|
21
|
+
if (!KIND_LABELS[kind]) return false
|
|
22
|
+
if (kind === lastKind && now - lastAt < cooldownMs) return false
|
|
23
|
+
lastKind = kind
|
|
24
|
+
lastAt = now
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function notificationFor(incident) {
|
|
29
|
+
const kind = incident && incident.kind
|
|
30
|
+
const label = KIND_LABELS[kind]
|
|
31
|
+
if (!label) return null
|
|
32
|
+
const target = incident.target ? ` ${incident.target}` : ''
|
|
33
|
+
const title = `AI Prison · ${label}`
|
|
34
|
+
const body = String(incident.detail || incident.evidence || target || '').slice(0, 180) || label
|
|
35
|
+
return { title, body }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function powershellScript(title, body) {
|
|
39
|
+
const safeTitle = String(title).replace(/'/g, "''")
|
|
40
|
+
const safeBody = String(body).replace(/'/g, "''")
|
|
41
|
+
return [
|
|
42
|
+
'Add-Type -AssemblyName System.Windows.Forms | Out-Null',
|
|
43
|
+
'Add-Type -AssemblyName System.Drawing | Out-Null',
|
|
44
|
+
'$n = New-Object System.Windows.Forms.NotifyIcon',
|
|
45
|
+
'$n.Icon = [System.Drawing.SystemIcons]::Warning',
|
|
46
|
+
'$n.Visible = $true',
|
|
47
|
+
`$n.ShowBalloonTip(8000, '${safeTitle}', '${safeBody}', [System.Windows.Forms.ToolTipIcon]::Warning)`,
|
|
48
|
+
'Start-Sleep -Seconds 9',
|
|
49
|
+
'$n.Visible = $false',
|
|
50
|
+
'$n.Dispose()',
|
|
51
|
+
].join('; ')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Fire one tray notification (best effort, detached). */
|
|
55
|
+
export function notify(incident, { cooldownMs = 60_000 } = {}) {
|
|
56
|
+
const message = notificationFor(incident)
|
|
57
|
+
if (!message) return { ok: false, reason: 'unsupported-kind' }
|
|
58
|
+
if (process.platform !== 'win32') return { ok: false, reason: 'platform' }
|
|
59
|
+
const now = Date.now()
|
|
60
|
+
if (!shouldNotify(incident.kind, now, cooldownMs)) return { ok: false, reason: 'rate-limited' }
|
|
61
|
+
lastAt = now
|
|
62
|
+
lastKind = incident.kind
|
|
63
|
+
try {
|
|
64
|
+
const child = spawn('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', powershellScript(message.title, message.body)], {
|
|
65
|
+
detached: true,
|
|
66
|
+
stdio: 'ignore',
|
|
67
|
+
windowsHide: true,
|
|
68
|
+
})
|
|
69
|
+
child.unref()
|
|
70
|
+
return { ok: true, title: message.title }
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return { ok: false, reason: String((error && error.message) || error) }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Test hook. */
|
|
77
|
+
export function resetNotifierState() {
|
|
78
|
+
lastAt = 0
|
|
79
|
+
lastKind = ''
|
|
80
|
+
}
|
package/lib/watchdog-policy.js
CHANGED
|
@@ -222,6 +222,53 @@ export function topOperations(operations, limit = 5) {
|
|
|
222
222
|
return rows.slice(0, Math.max(1, limit))
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Top5 v2: combine measured module-load MB, operation estimates and the RSS of
|
|
227
|
+
* child processes attributed to a plugin. The ranking is smoothed and stable:
|
|
228
|
+
* an item only changes rank when its score moved by more than 20%.
|
|
229
|
+
*/
|
|
230
|
+
export function rankTopPlugins({ operations = [], budgets = {}, rss = {}, previous = {}, alpha = 0.35, limit = 5 } = {}) {
|
|
231
|
+
const rows = new Map()
|
|
232
|
+
for (const row of operations) {
|
|
233
|
+
rows.set(row.target, { target: row.target, operationMB: Number(row.estimateMB) || 0, count: Number(row.count) || 0, version: row.version || null, source: row.source || 'estimate', measuredAt: row.measuredAt || null })
|
|
234
|
+
}
|
|
235
|
+
for (const [target, entry] of Object.entries(budgets)) {
|
|
236
|
+
if (!entry || entry.error || entry.moduleLoadMB === undefined) continue
|
|
237
|
+
const current = rows.get(target) || { target, operationMB: 0, count: 0, version: entry.version || null, source: 'measured', measuredAt: entry.measuredAt || null }
|
|
238
|
+
current.moduleLoadMB = Number(entry.moduleLoadMB) || 0
|
|
239
|
+
current.source = 'measured'
|
|
240
|
+
current.measuredAt = entry.measuredAt || current.measuredAt
|
|
241
|
+
current.version = entry.version || current.version
|
|
242
|
+
rows.set(target, current)
|
|
243
|
+
}
|
|
244
|
+
for (const [target, bytes] of Object.entries(rss)) {
|
|
245
|
+
const current = rows.get(target) || { target, operationMB: 0, count: 0, version: null, source: 'estimate', measuredAt: null }
|
|
246
|
+
const previousRss = Number(previous[target] && previous[target].rssMB) || 0
|
|
247
|
+
current.rssMB = previousRss > 0 ? Math.round(previousRss * (1 - alpha) + (Number(bytes) / (1024 * 1024)) * alpha) : Math.round((Number(bytes) || 0) / (1024 * 1024))
|
|
248
|
+
rows.set(target, current)
|
|
249
|
+
}
|
|
250
|
+
const ranked = [...rows.values()].map((row) => ({
|
|
251
|
+
...row,
|
|
252
|
+
rssMB: row.rssMB || 0,
|
|
253
|
+
score: Math.round((row.moduleLoadMB || row.operationMB || 0) + (row.rssMB || 0)),
|
|
254
|
+
}))
|
|
255
|
+
ranked.sort((a, b) => b.score - a.score)
|
|
256
|
+
const changed = ranked.some((row) => {
|
|
257
|
+
const before = previous[row.target]
|
|
258
|
+
if (!before || !Number.isFinite(before.score)) return true
|
|
259
|
+
const delta = Math.abs(row.score - before.score)
|
|
260
|
+
return delta / Math.max(1, before.score) > 0.2
|
|
261
|
+
})
|
|
262
|
+
const next = {}
|
|
263
|
+
for (const row of ranked) next[row.target] = { score: row.score, rssMB: row.rssMB }
|
|
264
|
+
if (!changed) {
|
|
265
|
+
// keep the last order while scores are stable
|
|
266
|
+
const order = Object.keys(previous)
|
|
267
|
+
ranked.sort((a, b) => order.indexOf(a.target) - order.indexOf(b.target))
|
|
268
|
+
}
|
|
269
|
+
return { rows: ranked.slice(0, Math.max(1, limit)), nextRanking: next }
|
|
270
|
+
}
|
|
271
|
+
|
|
225
272
|
/** Named byte formatting used by the panel/tool text. */
|
|
226
273
|
export function formatBytes(bytes) {
|
|
227
274
|
const value = Number(bytes)
|
package/lib/watchdog-runtime.js
CHANGED
|
@@ -3,10 +3,12 @@ import os from 'node:os'
|
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import v8 from 'node:v8'
|
|
5
5
|
import crypto from 'node:crypto'
|
|
6
|
+
import { spawn } from 'node:child_process'
|
|
6
7
|
import { watchdogState, MAX_SAMPLES, MAX_INCIDENTS } from './watchdog-state.js'
|
|
7
8
|
import { probeBudget } from './budget-probe.js'
|
|
8
9
|
import { createTamperMonitor } from './tamper-monitor.js'
|
|
9
10
|
import { remediationFor } from './remediation.js'
|
|
11
|
+
import { notify } from './notifier.js'
|
|
10
12
|
import {
|
|
11
13
|
attributeCrash,
|
|
12
14
|
classifyWaterline,
|
|
@@ -19,6 +21,7 @@ import {
|
|
|
19
21
|
operationWeight,
|
|
20
22
|
parseCrashLog,
|
|
21
23
|
thresholdsFor,
|
|
24
|
+
rankTopPlugins,
|
|
22
25
|
topOperations,
|
|
23
26
|
} from './watchdog-policy.js'
|
|
24
27
|
|
|
@@ -155,7 +158,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
155
158
|
tamper = createTamperMonitor({
|
|
156
159
|
profileDir,
|
|
157
160
|
dataDir,
|
|
158
|
-
policy: config.tamperPolicy === 'alert' ? 'alert' : '
|
|
161
|
+
policy: config.tamperPolicy === 'restore' ? 'restore' : config.tamperPolicy === 'alert' ? 'alert' : 'observe',
|
|
159
162
|
graceMs: Number(config.tamperGraceMs) >= 0 ? Number(config.tamperGraceMs) : 15_000,
|
|
160
163
|
intervalMs: Number(config.tamperIntervalMs) > 0 ? Number(config.tamperIntervalMs) : 30_000,
|
|
161
164
|
shouldIgnore: () => Date.now() < operationWindowUntil || Date.now() - lastOperationAt < 120000,
|
|
@@ -181,7 +184,8 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
181
184
|
function handleTamper(result) {
|
|
182
185
|
if (!result || !Array.isArray(result.diffs) || result.diffs.length === 0) return
|
|
183
186
|
const files = result.diffs.map((diff) => diff.file)
|
|
184
|
-
|
|
187
|
+
const policy = (watchdogState.tamper && watchdogState.tamper.policy) || 'observe'
|
|
188
|
+
appendIncident({ kind: 'tamper', files, policy, restored: result.restored, detail: '配置漂移:' + files.join(', ') + (policy === 'observe' ? '(observe:仅记录,不恢复不关闭)' : '') })
|
|
185
189
|
let target = null
|
|
186
190
|
let evidence = []
|
|
187
191
|
try {
|
|
@@ -195,7 +199,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
195
199
|
} catch {
|
|
196
200
|
target = null
|
|
197
201
|
}
|
|
198
|
-
const applied = Boolean(watchdogState.enforce && target)
|
|
202
|
+
const applied = Boolean(watchdogState.enforce && target && policy === 'restore')
|
|
199
203
|
const plan = { at: new Date().toISOString(), level: 'L1', crash: null, reason: 'tamper', remediation: remediationFor('tamper'), target, inFlight: false, evidence: { files: result.diffs, candidates: evidence }, applied }
|
|
200
204
|
watchdogState.plans.push(plan)
|
|
201
205
|
if (watchdogState.plans.length > 20) watchdogState.plans = watchdogState.plans.slice(-20)
|
|
@@ -208,6 +212,63 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
208
212
|
persist(true)
|
|
209
213
|
}
|
|
210
214
|
|
|
215
|
+
const RSS_INTERVAL_MS = 60_000
|
|
216
|
+
let rssTimer = null
|
|
217
|
+
let rssScanning = false
|
|
218
|
+
|
|
219
|
+
function scanChildRss() {
|
|
220
|
+
if (process.platform !== 'win32' || rssScanning) return
|
|
221
|
+
const manager = refs.manager
|
|
222
|
+
if (!manager || typeof manager.listBundles !== 'function') return
|
|
223
|
+
rssScanning = true
|
|
224
|
+
const profileLiteral = String(profileDir).replace(/'/g, "''")
|
|
225
|
+
const script = [
|
|
226
|
+
"$ErrorActionPreference='SilentlyContinue'",
|
|
227
|
+
"Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine -like '*node_modules*' -and $_.CommandLine -like '*" + profileLiteral + "*' } | ForEach-Object { ($_.ProcessId.ToString() + '|' + [string]$_.WorkingSetSize + '|' + $_.CommandLine) }",
|
|
228
|
+
].join('; ')
|
|
229
|
+
let output = ''
|
|
230
|
+
const child = spawn('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script], { windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] })
|
|
231
|
+
child.stdout.on('data', (chunk) => {
|
|
232
|
+
output += String(chunk)
|
|
233
|
+
})
|
|
234
|
+
child.on('error', () => {
|
|
235
|
+
rssScanning = false
|
|
236
|
+
})
|
|
237
|
+
child.on('exit', () => {
|
|
238
|
+
rssScanning = false
|
|
239
|
+
void manager
|
|
240
|
+
.listBundles()
|
|
241
|
+
.then((rows) => {
|
|
242
|
+
const enabled = rows.filter((row) => row.enabled && !EXEMPT_TARGETS.has(row.name)).map((row) => row.name)
|
|
243
|
+
const totals = new Map()
|
|
244
|
+
for (const line of output.split('\n')) {
|
|
245
|
+
const parts = line.trim().split('|')
|
|
246
|
+
if (parts.length < 3) continue
|
|
247
|
+
const bytes = Number(parts[1]) || 0
|
|
248
|
+
const commandLine = parts.slice(2).join('|')
|
|
249
|
+
for (const name of enabled) {
|
|
250
|
+
if (commandLine.includes('node_modules' + path.sep + name) || commandLine.includes('node_modules/' + name)) {
|
|
251
|
+
totals.set(name, (totals.get(name) || 0) + bytes)
|
|
252
|
+
break
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const rss = { ...(watchdogState.rss || {}) }
|
|
257
|
+
for (const [name, bytes] of totals) rss[name] = bytes
|
|
258
|
+
watchdogState.rss = rss
|
|
259
|
+
watchdogState.rssAt = new Date().toISOString()
|
|
260
|
+
})
|
|
261
|
+
.catch(() => {})
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function startRssScanner() {
|
|
266
|
+
if (rssTimer || process.platform !== 'win32') return
|
|
267
|
+
const timer = setTimeout(scanChildRss, 5000)
|
|
268
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
269
|
+
rssTimer = setInterval(scanChildRss, RSS_INTERVAL_MS)
|
|
270
|
+
if (typeof rssTimer.unref === 'function') rssTimer.unref()
|
|
271
|
+
}
|
|
211
272
|
function persist(force = false) {
|
|
212
273
|
const now = Date.now()
|
|
213
274
|
if (!force && now - lastFlush < FLUSH_MS) return
|
|
@@ -259,6 +320,13 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
259
320
|
|
|
260
321
|
function appendIncident(incident) {
|
|
261
322
|
const record = { at: new Date().toISOString(), mode: watchdogState.mode, ...incident }
|
|
323
|
+
if (watchdogState.config && watchdogState.config.notify === true && ['freeze', 'pause', 'quarantine', 'tamper', 'crash-enforced', 'budget'].includes(record.kind)) {
|
|
324
|
+
try {
|
|
325
|
+
notify(record)
|
|
326
|
+
} catch {
|
|
327
|
+
// notifications are best effort
|
|
328
|
+
}
|
|
329
|
+
}
|
|
262
330
|
watchdogState.incidents.push(record)
|
|
263
331
|
if (watchdogState.incidents.length > MAX_INCIDENTS) watchdogState.incidents = watchdogState.incidents.slice(-MAX_INCIDENTS)
|
|
264
332
|
try {
|
|
@@ -739,6 +807,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
739
807
|
refs.manager = child.pluginManager || (typeof child.get === 'function' ? child.get('pluginManager') : null)
|
|
740
808
|
if (refs.manager) {
|
|
741
809
|
void reapplyQuarantine()
|
|
810
|
+
startRssScanner()
|
|
742
811
|
const probeTimer = setTimeout(() => {
|
|
743
812
|
void scheduleProbe()
|
|
744
813
|
}, Number(config.probeDelayMs) > 0 ? Number(config.probeDelayMs) : 30_000)
|
|
@@ -873,6 +942,8 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
873
942
|
disableTarget,
|
|
874
943
|
releaseTarget,
|
|
875
944
|
dispose() {
|
|
945
|
+
if (rssTimer) clearInterval(rssTimer)
|
|
946
|
+
rssTimer = null
|
|
876
947
|
while (cleanups.length > 0) {
|
|
877
948
|
const disposer = cleanups.pop()
|
|
878
949
|
try {
|
|
@@ -885,29 +956,28 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
885
956
|
}
|
|
886
957
|
}
|
|
887
958
|
|
|
888
|
-
/**
|
|
959
|
+
/** Top5 v2: measured + estimate + child RSS with EWMA smoothing and rank hysteresis. */
|
|
889
960
|
function mergedTop(state, limit) {
|
|
890
961
|
const operations = topOperations(state.operations, 50)
|
|
891
|
-
const
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
962
|
+
const { rows, nextRanking } = rankTopPlugins({
|
|
963
|
+
operations,
|
|
964
|
+
budgets: state.budgets || {},
|
|
965
|
+
rss: state.rss || {},
|
|
966
|
+
previous: state.ranking || {},
|
|
967
|
+
limit,
|
|
968
|
+
})
|
|
969
|
+
state.ranking = nextRanking
|
|
970
|
+
return rows.map((row) => ({
|
|
971
|
+
target: row.target,
|
|
972
|
+
count: row.count || 0,
|
|
973
|
+
estimateMB: row.moduleLoadMB || row.operationMB || 0,
|
|
974
|
+
rssMB: row.rssMB || 0,
|
|
975
|
+
totalMB: row.score,
|
|
976
|
+
lastAt: row.measuredAt || null,
|
|
977
|
+
version: row.version || null,
|
|
978
|
+
source: row.source,
|
|
979
|
+
}))
|
|
909
980
|
}
|
|
910
|
-
|
|
911
981
|
/** Serialisable snapshot shared by the tool and the panel route. */
|
|
912
982
|
export function watchdogSnapshot() {
|
|
913
983
|
const s = watchdogState
|
|
@@ -941,6 +1011,8 @@ export function watchdogSnapshot() {
|
|
|
941
1011
|
baseline: s.baseline ? { at: s.baseline.at, runId: s.baseline.runId, bundles: s.baseline.bundles } : null,
|
|
942
1012
|
budgets: s.budgets,
|
|
943
1013
|
tamper: s.tamper || null,
|
|
1014
|
+
rss: s.rss || {},
|
|
1015
|
+
rssAt: s.rssAt || null,
|
|
944
1016
|
incidents: s.incidents.slice(-20),
|
|
945
1017
|
generatedAt: new Date().toISOString(),
|
|
946
1018
|
}
|
package/locale/en.json
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"watchdog.plans": "Crash plans (dry-run)",
|
|
18
18
|
"watchdog.noPlans": "No crash attribution plans.",
|
|
19
19
|
"watchdog.baseline": "Clean baseline: {at}",
|
|
20
|
-
"watchdog.tamper": "Profile watch: {n} critical file(s)
|
|
20
|
+
"watchdog.tamper": "Profile watch: {n} critical file(s) · policy {policy} · last check {at}",
|
|
21
21
|
"watchdog.measure": "Measure plugin budgets now",
|
|
22
|
-
"watchdog.measureBlocked": "Heap is frozen: measuring spawns child processes, so it stays disabled until the heap recovers."
|
|
22
|
+
"watchdog.measureBlocked": "Heap is frozen: measuring spawns child processes, so it stays disabled until the heap recovers.",
|
|
23
|
+
"prison.rss": "Child RSS",
|
|
24
|
+
"prison.plugin": "Plugin"
|
|
23
25
|
}
|
package/locale/zh.json
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"watchdog.plans": "崩溃降级计划(dry-run)",
|
|
18
18
|
"watchdog.noPlans": "暂无崩溃归因计划。",
|
|
19
19
|
"watchdog.baseline": "干净基线:{at}",
|
|
20
|
-
"watchdog.tamper": "配置监控:{n}
|
|
20
|
+
"watchdog.tamper": "配置监控:{n} 个关键文件 · 策略 {policy} · 最近检查 {at}",
|
|
21
21
|
"watchdog.measure": "立即测量插件预算",
|
|
22
|
-
"watchdog.measureBlocked": "堆已冻结:测量会启动子进程,恢复前暂停测量。"
|
|
22
|
+
"watchdog.measureBlocked": "堆已冻结:测量会启动子进程,恢复前暂停测量。",
|
|
23
|
+
"prison.rss": "子进程 RSS",
|
|
24
|
+
"prison.plugin": "插件"
|
|
23
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/ai-prison-dsh-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "AI Prison for DSH: six governance tools wrapping the aiprison CLI (levels, demo, drill, inspect, verify, repair-tail) plus a panel for the L0–L5 matrix and the audit-chain state. The CLI ships bundled for Windows, macOS and Linux; every capability-removal backend stays simulated.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|