@twinsearth/ai-prison-dsh-plugin 1.4.3 → 1.4.4
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 +21 -0
- package/client.js +4 -0
- package/lib/watchdog-runtime.js +94 -20
- package/locale/en.json +2 -1
- package/locale/zh.json +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@twinsearth/ai-prison-dsh-plugin` are recorded here.
|
|
4
4
|
|
|
5
|
+
## [1.4.4] — 2026-11-18
|
|
6
|
+
|
|
7
|
+
### Fixed — per-plugin budget probe actually works end to end
|
|
8
|
+
|
|
9
|
+
- The probe now covers **every enabled, non-exempt bundle without a current
|
|
10
|
+
measurement** (not only plugins installed/enabled in the last 30 minutes),
|
|
11
|
+
scheduled after boot (max 5 per run) and retried after failures (error entries
|
|
12
|
+
older than 10 minutes, up to 5 attempts).
|
|
13
|
+
- Budgets are version-aware: an entry measured for another version, without a
|
|
14
|
+
version, older than 7 days, or failed is treated as stale and re-measured.
|
|
15
|
+
- A manual "Measure plugin budgets now" button in the Enforcement card and a
|
|
16
|
+
`probe` action on the watchdog route run the queue immediately (up to 15
|
|
17
|
+
targets) and report `probeProgress`.
|
|
18
|
+
- The measured module-load MB **wins over operation estimates in Top5** and is
|
|
19
|
+
labelled `source: "measured"`; operation-derived rows stay `estimate`.
|
|
20
|
+
- >500 MB still quarantines, closes and queues the plugin in
|
|
21
|
+
`pending-boot.json`; 300–500 MB records a warning only.
|
|
22
|
+
- Tests: `test/watchdog-budget.test.mjs` covers the 600 MB quarantine path,
|
|
23
|
+
the 420 MB warning path with measured Top5, and failed-probe retry counting.
|
|
24
|
+
|
|
25
|
+
## [1.4.3] — 2026-11-18
|
|
5
26
|
## [1.4.3] — 2026-11-18
|
|
6
27
|
|
|
7
28
|
### Added — profile tamper monitor (requirement 3, the missing half)
|
package/client.js
CHANGED
|
@@ -465,6 +465,10 @@ window.__ModuleLoader__.load({
|
|
|
465
465
|
),
|
|
466
466
|
watchdog.baseline ? h('p', { style: { ...C.muted, fontSize: 11.5, margin: '10px 0 0' } }, t('watchdog.baseline', { at: watchdog.baseline.at })) : null,
|
|
467
467
|
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,
|
|
468
|
+
h('div', { style: { marginTop: 10, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
469
|
+
h('button', { style: { ...button, padding: '5px 10px' }, onClick: () => act('probe') }, t('watchdog.measure')),
|
|
470
|
+
watchdog.probeProgress ? h('span', { style: { ...C.mono, fontSize: 11.5 } }, `${watchdog.probeProgress.done || 0}/${watchdog.probeProgress.total || 0}`) : null,
|
|
471
|
+
),
|
|
468
472
|
)
|
|
469
473
|
}
|
|
470
474
|
|
package/lib/watchdog-runtime.js
CHANGED
|
@@ -515,18 +515,52 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
518
|
+
const probeFn = typeof config.probe === 'function' ? config.probe : probeBudget
|
|
519
|
+
const probeMax = Number(config.probeMax) > 0 ? Number(config.probeMax) : 5
|
|
520
|
+
const probeRetryMs = Number(config.probeRetryMs) > 0 ? Number(config.probeRetryMs) : 10 * 60 * 1000
|
|
521
|
+
const probeMaxAgeMs = 7 * 24 * 3600 * 1000
|
|
522
|
+
|
|
523
|
+
function budgetState(name, version) {
|
|
524
|
+
const entry = watchdogState.budgets[name]
|
|
525
|
+
if (!entry) return 'missing'
|
|
526
|
+
if (entry.error) {
|
|
527
|
+
const age = Date.now() - Date.parse(entry.measuredAt || 0)
|
|
528
|
+
return age > probeRetryMs && (Number(entry.attempts) || 0) < 5 ? 'retry' : 'error'
|
|
529
|
+
}
|
|
530
|
+
if (entry.moduleLoadMB === undefined) return 'stale'
|
|
531
|
+
if (!entry.version || (version && entry.version !== version)) return 'stale'
|
|
532
|
+
if (Date.now() - Date.parse(entry.measuredAt || 0) > probeMaxAgeMs) return 'stale'
|
|
533
|
+
return 'ok'
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
async function probeOne(name, version) {
|
|
537
|
+
const previous = watchdogState.budgets[name] || {}
|
|
538
|
+
watchdogState.probeProgress = { ...(watchdogState.probeProgress || { done: 0, total: 0 }), current: name }
|
|
539
|
+
const result = await probeFn({ profileDir, packageName: name })
|
|
540
|
+
if (!result || !result.ok) {
|
|
541
|
+
watchdogState.budgets[name] = {
|
|
542
|
+
error: String((result && result.error) || 'probe-failed').slice(0, 300),
|
|
543
|
+
measuredAt: new Date().toISOString(),
|
|
544
|
+
version: version || previous.version || null,
|
|
545
|
+
attempts: (Number(previous.attempts) || 0) + 1,
|
|
546
|
+
source: 'module-load-probe',
|
|
547
|
+
}
|
|
522
548
|
persist(true)
|
|
523
|
-
return
|
|
549
|
+
return { ok: false }
|
|
550
|
+
}
|
|
551
|
+
watchdogState.budgets[name] = {
|
|
552
|
+
moduleLoadMB: result.moduleLoadMB,
|
|
553
|
+
rssMB: result.rssMB,
|
|
554
|
+
ms: result.ms,
|
|
555
|
+
measuredAt: new Date().toISOString(),
|
|
556
|
+
version: version || null,
|
|
557
|
+
attempts: (Number(previous.attempts) || 0) + 1,
|
|
558
|
+
source: 'module-load-probe',
|
|
524
559
|
}
|
|
525
|
-
watchdogState.budgets[name] = { moduleLoadMB: result.moduleLoadMB, rssMB: result.rssMB, ms: result.ms, measuredAt: new Date().toISOString(), source: 'module-load-probe' }
|
|
526
560
|
const thresholds = watchdogState.thresholds
|
|
527
561
|
const mb = result.moduleLoadMB
|
|
528
562
|
if (thresholds && mb >= Math.round(thresholds.singleBlock / (1024 * 1024))) {
|
|
529
|
-
appendIncident({ kind: 'plugin-budget', target: name, level: 'block', detail: '启动实测 ' + mb + ' MB > 500 MB
|
|
563
|
+
appendIncident({ kind: 'plugin-budget', target: name, level: 'block', detail: '启动实测 ' + mb + ' MB > 500 MB,禁止该插件' })
|
|
530
564
|
if (watchdogState.enforce) {
|
|
531
565
|
watchdogState.quarantine.set(name, { reason: 'budget', level: 'L1', at: new Date().toISOString(), release: 'manual', evidence: mb + ' MB > 500 MB' })
|
|
532
566
|
void disableTarget(name, 'budget-over-500MB')
|
|
@@ -536,18 +570,18 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
536
570
|
appendIncident({ kind: 'plugin-budget', target: name, level: 'warn', detail: '启动实测 ' + mb + ' MB > 300 MB,仅提醒' })
|
|
537
571
|
}
|
|
538
572
|
persist(true)
|
|
573
|
+
return { ok: true }
|
|
539
574
|
}
|
|
540
575
|
|
|
541
|
-
async function scheduleProbe() {
|
|
542
|
-
if (watchdogState.
|
|
543
|
-
watchdogState.probeStarted = true
|
|
576
|
+
async function scheduleProbe({ force = false } = {}) {
|
|
577
|
+
if (watchdogState.probeRunning) return watchdogState.probeProgress
|
|
544
578
|
const manager = refs.manager
|
|
545
|
-
if (!manager || typeof manager.listBundles !== 'function') return
|
|
579
|
+
if (!manager || typeof manager.listBundles !== 'function') return null
|
|
546
580
|
let rows
|
|
547
581
|
try {
|
|
548
582
|
rows = await manager.listBundles()
|
|
549
583
|
} catch {
|
|
550
|
-
return
|
|
584
|
+
return null
|
|
551
585
|
}
|
|
552
586
|
const recent = new Set()
|
|
553
587
|
const cutoff = Date.now() - 30 * 60 * 1000
|
|
@@ -558,14 +592,25 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
558
592
|
if (Date.parse(operation.time || 0) < cutoff) continue
|
|
559
593
|
recent.add(operation.target)
|
|
560
594
|
}
|
|
561
|
-
const
|
|
562
|
-
.filter((row) => row.enabled && !EXEMPT_TARGETS.has(row.name)
|
|
563
|
-
.map((row) => row.name)
|
|
564
|
-
.
|
|
565
|
-
|
|
595
|
+
const candidates = rows
|
|
596
|
+
.filter((row) => row.enabled && !EXEMPT_TARGETS.has(row.name))
|
|
597
|
+
.map((row) => ({ name: row.name, version: row.version ? String(row.version) : '', state: budgetState(row.name, row.version ? String(row.version) : '') }))
|
|
598
|
+
.filter((candidate) => candidate.state !== 'ok')
|
|
599
|
+
.sort((a, b) => (recent.has(b.name) ? 1 : 0) - (recent.has(a.name) ? 1 : 0))
|
|
600
|
+
.slice(0, force ? Math.max(probeMax, Number(config.probeMaxForce) > 0 ? Number(config.probeMaxForce) : 15) : probeMax)
|
|
601
|
+
watchdogState.probeProgress = { done: 0, total: candidates.length, current: null, finishedAt: null }
|
|
602
|
+
if (candidates.length === 0) return watchdogState.probeProgress
|
|
603
|
+
watchdogState.probeRunning = true
|
|
604
|
+
for (const candidate of candidates) {
|
|
566
605
|
if (watchdogState.waterline !== 'ok') break
|
|
567
|
-
await probeOne(name)
|
|
606
|
+
const outcome = await probeOne(candidate.name, candidate.version)
|
|
607
|
+
watchdogState.probeProgress = { ...watchdogState.probeProgress, done: watchdogState.probeProgress.done + 1, current: candidate.name, lastOk: Boolean(outcome && outcome.ok) }
|
|
608
|
+
if (candidates.length > 1) await new Promise((resolve) => setTimeout(resolve, Number(config.probeGapMs) >= 0 ? Number(config.probeGapMs) : 1500))
|
|
568
609
|
}
|
|
610
|
+
watchdogState.probeProgress = { ...watchdogState.probeProgress, current: null, finishedAt: new Date().toISOString() }
|
|
611
|
+
watchdogState.probeRunning = false
|
|
612
|
+
persist(true)
|
|
613
|
+
return watchdogState.probeProgress
|
|
569
614
|
}
|
|
570
615
|
|
|
571
616
|
// ---- crash attribution and dry-run plans (requirements 3 & 4) -----------
|
|
@@ -737,6 +782,10 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
737
782
|
}
|
|
738
783
|
const action = typeof body.action === 'string' ? body.action : ''
|
|
739
784
|
const target = typeof body.target === 'string' ? body.target : ''
|
|
785
|
+
if (action === 'probe') {
|
|
786
|
+
const progress = await scheduleProbe({ force: true })
|
|
787
|
+
return Response.json({ ok: true, progress })
|
|
788
|
+
}
|
|
740
789
|
if (action === 'confirm-pause') {
|
|
741
790
|
watchdogState.graceUntil = Date.now() + PAUSE_GRACE_MS
|
|
742
791
|
appendIncident({ kind: 'pause-confirmed', detail: `用户二次确认继续插件操作(宽限 10 分钟)` })
|
|
@@ -766,6 +815,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
766
815
|
snapshot: watchdogSnapshot,
|
|
767
816
|
sample,
|
|
768
817
|
readCrashLogs,
|
|
818
|
+
probeNow: (options) => scheduleProbe(options),
|
|
769
819
|
tamperCheck: (options) => {
|
|
770
820
|
if (!tamper) return null
|
|
771
821
|
const result = tamper.checkNow(options)
|
|
@@ -787,6 +837,29 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
787
837
|
}
|
|
788
838
|
}
|
|
789
839
|
|
|
840
|
+
/** Merge live operation estimates with measured module-load budgets (measured wins). */
|
|
841
|
+
function mergedTop(state, limit) {
|
|
842
|
+
const operations = topOperations(state.operations, 50)
|
|
843
|
+
const measured = []
|
|
844
|
+
for (const [target, entry] of Object.entries(state.budgets || {})) {
|
|
845
|
+
if (!entry || entry.error || entry.moduleLoadMB === undefined) continue
|
|
846
|
+
const existing = operations.find((row) => row.target === target)
|
|
847
|
+
measured.push({
|
|
848
|
+
target,
|
|
849
|
+
count: existing ? existing.count : 0,
|
|
850
|
+
estimateMB: entry.moduleLoadMB,
|
|
851
|
+
lastAt: entry.measuredAt || (existing ? existing.lastAt : null),
|
|
852
|
+
version: entry.version || (existing ? existing.version : null),
|
|
853
|
+
source: 'measured',
|
|
854
|
+
measuredAt: entry.measuredAt || null,
|
|
855
|
+
})
|
|
856
|
+
}
|
|
857
|
+
const others = operations
|
|
858
|
+
.filter((row) => !measured.some((entry) => entry.target === row.target))
|
|
859
|
+
.map((row) => ({ ...row, source: 'estimate' }))
|
|
860
|
+
return [...measured, ...others].sort((a, b) => b.estimateMB - a.estimateMB || b.count - a.count).slice(0, Math.max(1, limit))
|
|
861
|
+
}
|
|
862
|
+
|
|
790
863
|
/** Serialisable snapshot shared by the tool and the panel route. */
|
|
791
864
|
export function watchdogSnapshot() {
|
|
792
865
|
const s = watchdogState
|
|
@@ -810,8 +883,9 @@ export function watchdogSnapshot() {
|
|
|
810
883
|
graceUntil: s.graceUntil,
|
|
811
884
|
frozenAt: s.frozenAt,
|
|
812
885
|
samples: s.samples.slice(-30),
|
|
813
|
-
operations:
|
|
814
|
-
topFive:
|
|
886
|
+
operations: mergedTop(s, 10),
|
|
887
|
+
topFive: mergedTop(s, 5),
|
|
888
|
+
probeProgress: s.probeProgress || null,
|
|
815
889
|
quarantine,
|
|
816
890
|
plans: s.plans.slice(-5),
|
|
817
891
|
escalation: { level: s.escalation.level, crashes: s.escalation.crashes.slice(-10) },
|
package/locale/en.json
CHANGED
|
@@ -17,5 +17,6 @@
|
|
|
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), last check {at}"
|
|
20
|
+
"watchdog.tamper": "Profile watch: {n} critical file(s), last check {at}",
|
|
21
|
+
"watchdog.measure": "Measure plugin budgets now"
|
|
21
22
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/ai-prison-dsh-plugin",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
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",
|