@twinsearth/ai-prison-dsh-plugin 1.4.5 → 1.4.6

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 CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  All notable changes to `@twinsearth/ai-prison-dsh-plugin` are recorded here.
4
4
 
5
+ ## [1.4.6] — 2026-11-18
6
+
7
+ ### Added — structured reason / impact / steps / release text
8
+
9
+ - New `lib/remediation.js` explains every enforcement action in four fixed
10
+ sections: why it happened, what it affects, what to do (numbered steps) and how
11
+ the plugin leaves the prison.
12
+ - Freeze, pause and every quarantine reason (hot-ops, crash, budget, tamper) now
13
+ carry a `remediation` object in the incident, the quarantine entry and the
14
+ crash/tamper plan.
15
+ - The panel "Plugin prison" renders it under each jailed plugin (title, why,
16
+ impact, numbered steps, release path); the agent tool returns the same object.
17
+ - Tests cover every remediation reason and the quarantine payload.
18
+
19
+ ### Notes
20
+ - This completes the three follow-ups requested for the probe work: the probe
21
+ publish fix and the full background probe queue shipped in 1.4.3/1.4.4; this
22
+ release adds the operator-facing explanation.
23
+
24
+ ## [1.4.5] — 2026-11-18
5
25
  ## [1.4.5] — 2026-11-18
6
26
 
7
27
  ### Fixed — tamper monitor false positives (important)
package/client.js CHANGED
@@ -443,9 +443,18 @@ window.__ModuleLoader__.load({
443
443
  h('div', { style: { ...C.key, marginBottom: 4 } }, t('watchdog.quarantine')),
444
444
  quarantine.length === 0
445
445
  ? h('p', { style: { ...C.muted, fontSize: 12, margin: '0 0 10px' } }, t('watchdog.noQuarantine'))
446
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, marginBottom: 10 } },
447
- quarantine.map((entry) => h('div', { key: entry.target, style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
448
- h('span', { style: { ...C.mono, fontSize: 12, wordBreak: 'break-all' } }, entry.target + ' · ' + entry.reason + ' · ' + entry.level),
446
+ : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8, marginBottom: 10 } },
447
+ quarantine.map((entry) => h('div', { key: entry.target, style: { display: 'flex', alignItems: 'flex-start', gap: 8, flexWrap: 'wrap' } },
448
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2, flex: '1 1 260px', minWidth: 0 } },
449
+ h('span', { style: { ...C.mono, fontSize: 12, wordBreak: 'break-all' } }, entry.target + ' · ' + entry.reason + ' · ' + entry.level),
450
+ entry.remediation ? h('div', { style: { fontSize: 11.5, color: 'var(--dsw-alias-label-secondary, #61666b)', lineHeight: 1.5 } },
451
+ h('div', { style: { fontWeight: 600 } }, entry.remediation.title),
452
+ h('div', null, entry.remediation.why),
453
+ h('div', null, entry.remediation.impact),
454
+ entry.remediation.steps.map((step, index) => h('div', { key: index }, (index + 1) + '. ' + step)),
455
+ h('div', null, '解除:' + entry.remediation.release),
456
+ ) : null,
457
+ ),
449
458
  h('button', { style: button, onClick: () => act('release', entry.target, '假释 ' + entry.target + ' ?') }, t('watchdog.release')),
450
459
  ))),
451
460
  topFive.length === 0 ? null : h('div', null,
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Human-readable remediation for every AI Prison enforcement action.
3
+ *
4
+ * Each entry answers four questions in fixed order so the panel and the agent
5
+ * say the same thing: why it happened, what it affects, what to do, and how the
6
+ * plugin gets out of prison.
7
+ */
8
+ const REMEDIATION = {
9
+ 'hot-ops': {
10
+ title: '插件热操作过频',
11
+ why: '同一插件在本次运行中被反复安装、启用或热切换(超过 5 次),插件图被反复重组,是内存暴涨与崩溃的高风险来源。',
12
+ impact: '该插件已被自动关闭并隔离;本次运行内不再加载。',
13
+ steps: [
14
+ '确认你确实需要反复开关它;安装/升级完成一次即可,不要连续点击。',
15
+ '重启 DSH(或在本面板点"假释")后重新启用一次。',
16
+ '如果它每次启动都反复启用自己,向插件作者反馈"启动期重复 enable"。',
17
+ ],
18
+ release: '重启 DSH 会自动释放;也可以在面板"插件监狱"里点"假释"手动释放。',
19
+ },
20
+ crash: {
21
+ title: '该插件被归因为崩溃来源',
22
+ why: 'DSH 宿主进程崩溃(如爆内存),崩溃日志里的 hostRunId 与本插件最后一次安装/启用记录匹配。',
23
+ impact: '该插件已被隔离并关闭,隔离在重启后仍生效,避免崩溃循环。',
24
+ steps: [
25
+ '先重启 DSH,确认在没有该插件时环境稳定。',
26
+ '检查插件版本是否有修复(升级到最新版),或查看其 README 的已知崩溃问题。',
27
+ '确需继续使用时,在面板"插件监狱"点"假释",一次只放行一个插件并观察内存。',
28
+ ],
29
+ release: '仅手动释放(面板"假释");重启不会自动解除,防止崩溃循环。',
30
+ },
31
+ budget: {
32
+ title: '启动内存超过硬阈值',
33
+ why: '隔离探针实测该插件模块加载的 retained 内存超过 500 MB 硬阈值(或该项目历史上留下超限记录)。',
34
+ impact: '该插件已被关闭并隔离,且写入 pending-boot.json,下次启动前会被外部 guard 直接剔除。',
35
+ steps: [
36
+ '升级到该插件的修复版本;若仍超限,联系作者或换用轻量替代。',
37
+ '如果确认是误报(插件版本已变化),在面板"插件监狱"点"假释"后重新测量预算。',
38
+ '临时需要使用时,只放行一次并在面板观察内存 Top5。',
39
+ ],
40
+ release: '手动释放(面板"假释");释放后再测一次预算确认。',
41
+ },
42
+ tamper: {
43
+ title: '关键配置文件被非插件管理器修改',
44
+ why: 'profile 的 package.json / cordis.patch.yml / pnpm-workspace.yaml / pnpm-lock.yaml 在插件管理器操作窗口之外发生了变化(被修改或删除)。',
45
+ impact: '已把被改动内容备份到 .ai-prison-watchdog/tampered/,默认恢复原文件;归因到的最后安装/启用插件已被隔离。',
46
+ steps: [
47
+ '检查 .ai-prison-watchdog/tampered/ 下的备份,确认改动来自哪里(手工编辑、脚本、其他工具)。',
48
+ '不要在 DSH 运行中手工改 profile 配置;确需修改时先退出 DSH。',
49
+ '确认无插件行为异常后,在面板"插件监狱"点"假释"恢复该插件。',
50
+ ],
51
+ release: '手动释放(面板"假释");恢复前先核对 tampered/ 备份。',
52
+ },
53
+ freeze: {
54
+ title: '内存水位达到冻结线',
55
+ why: '宿主堆内存超过 5 GB 冻结阈值(6 GB host;4 GB host 按比例折算),继续加载/重组插件会直接导致 OOM 崩溃。',
56
+ impact: '所有增内存的插件操作被禁止(安装、启用、热切换、重载、卸载等),Agent 的 plugin_manager 也已被拒绝。',
57
+ steps: [
58
+ '在面板"内存看护 → Top5"里立即关闭占用最大的插件。',
59
+ '关闭后等待 1 分钟让堆回落,或直接重启 DSH。',
60
+ '排查是谁在持续吃内存:优先怀疑最近开启/升级的插件。',
61
+ ],
62
+ release: '堆回落到冻结线以下并持续 60 秒会自动解除;或重启 DSH。',
63
+ },
64
+ pause: {
65
+ title: '内存水位达到暂停线,需要二次确认',
66
+ why: '宿主堆内存超过 3.9 GB 暂停阈值,插件操作已暂停,防止继续推高水位。',
67
+ impact: '所有增内存的插件操作被临时拦截;本次操作需要你明确确认。',
68
+ steps: [
69
+ '先在"内存看护 → Top5"里关闭一个不需要的插件。',
70
+ '确认要继续时,点面板的"我已知晓:允许插件操作 10 分钟"。',
71
+ '宽限期内若水位继续上涨到 5 GB,会自动升级为冻结。',
72
+ ],
73
+ release: '点"二次确认"给 10 分钟宽限;堆回落到 3.6 GB 以下会自动解除。',
74
+ },
75
+ }
76
+
77
+ /** Look up the remediation for one enforcement reason. */
78
+ export function remediationFor(reason, extra = {}) {
79
+ const code = REMEDIATION[reason] ? reason : 'hot-ops'
80
+ const base = REMEDIATION[code]
81
+ return {
82
+ code,
83
+ title: base.title,
84
+ why: base.why,
85
+ impact: base.impact,
86
+ steps: [...base.steps],
87
+ release: base.release,
88
+ ...(extra.count !== undefined ? { detail: `本次运行计数 ${extra.count}` } : {}),
89
+ }
90
+ }
91
+
92
+ /** Reasons this module knows about (used by tests and the panel). */
93
+ export const REMEDIATION_REASONS = Object.keys(REMEDIATION)
@@ -6,6 +6,7 @@ import crypto from 'node:crypto'
6
6
  import { watchdogState, MAX_SAMPLES, MAX_INCIDENTS } from './watchdog-state.js'
7
7
  import { probeBudget } from './budget-probe.js'
8
8
  import { createTamperMonitor } from './tamper-monitor.js'
9
+ import { remediationFor } from './remediation.js'
9
10
  import {
10
11
  attributeCrash,
11
12
  classifyWaterline,
@@ -194,11 +195,11 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
194
195
  target = null
195
196
  }
196
197
  const applied = Boolean(watchdogState.enforce && target)
197
- const plan = { at: new Date().toISOString(), level: 'L1', crash: null, reason: 'tamper', target, inFlight: false, evidence: { files: result.diffs, candidates: evidence }, applied }
198
+ 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 }
198
199
  watchdogState.plans.push(plan)
199
200
  if (watchdogState.plans.length > 20) watchdogState.plans = watchdogState.plans.slice(-20)
200
201
  if (applied) {
201
- watchdogState.quarantine.set(target, { reason: 'tamper', level: 'L1', at: plan.at, release: 'manual', evidence: '配置漂移:' + files.join(', ') })
202
+ watchdogState.quarantine.set(target, { reason: 'tamper', level: 'L1', at: plan.at, release: 'manual', evidence: '配置漂移:' + files.join(', '), remediation: remediationFor('tamper') })
202
203
  void disableTarget(target, 'tamper')
203
204
  writePendingBoot({ level: 'L1', reason: 'tamper', disable: [target], keep: [] })
204
205
  appendIncident({ kind: 'tamper-enforced', target, files, detail: '配置漂移后已隔离 ' + target })
@@ -310,6 +311,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
310
311
  heapUsed,
311
312
  heapLimit,
312
313
  detail: `heap ${formatBytes(heapUsed)} ≥ block ${formatBytes(thresholds.totalBlock)}:冻结插件操作`,
314
+ remediation: remediationFor('freeze'),
313
315
  })
314
316
  log.warn(`[ai-prison-watchdog] ${incident.detail}`)
315
317
  persist(true)
@@ -321,6 +323,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
321
323
  heapUsed,
322
324
  heapLimit,
323
325
  detail: `heap ${formatBytes(heapUsed)} ≥ pause ${formatBytes(thresholds.totalPause)}:插件操作需二次确认`,
326
+ remediation: remediationFor('pause'),
324
327
  })
325
328
  persist(true)
326
329
  } else if (waterline === 'warn' && previous !== 'warn' && previous === 'ok') {
@@ -430,6 +433,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
430
433
  at: new Date().toISOString(),
431
434
  release: 'restart',
432
435
  evidence: `本次运行内热操作计数 ${entry.count} > 5(安装/启用/热切换)`,
436
+ remediation: remediationFor('hot-ops', { count: entry.count }),
433
437
  })
434
438
  appendIncident({ kind: 'quarantine', target, level: 'L2', reason: 'hot-ops', detail: `热操作 ${entry.count} 次 > 5,自动关闭` })
435
439
  persist(true)
@@ -490,7 +494,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
490
494
  const unique = [...new Set(targets)].filter((target) => target && !EXEMPT_TARGETS.has(target) && !watchdogState.quarantine.has(target))
491
495
  const disabled = []
492
496
  for (const target of unique) {
493
- watchdogState.quarantine.set(target, { reason, level: 'crash', at: new Date().toISOString(), release: 'manual', evidence: reason })
497
+ watchdogState.quarantine.set(target, { reason, level: 'crash', at: new Date().toISOString(), release: 'manual', evidence: reason, remediation: remediationFor(reason) })
494
498
  if (await disableTarget(target, reason)) disabled.push(target)
495
499
  await new Promise((resolve) => setTimeout(resolve, 300))
496
500
  }
@@ -500,7 +504,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
500
504
  async function enforceCrashPlan(plan) {
501
505
  if (!plan || !plan.target || watchdogState.crashFallback !== 'enforce') return
502
506
  try {
503
- watchdogState.quarantine.set(plan.target, { reason: 'crash', level: plan.level, at: new Date().toISOString(), release: 'manual', evidence: plan.reason })
507
+ watchdogState.quarantine.set(plan.target, { reason: 'crash', level: plan.level, at: new Date().toISOString(), release: 'manual', evidence: plan.reason, remediation: remediationFor('crash') })
504
508
  const disabled = [plan.target].filter((target) => !EXEMPT_TARGETS.has(target))
505
509
  await disableTarget(plan.target, 'crash-' + plan.level)
506
510
  let targets = [plan.target]
@@ -584,7 +588,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
584
588
  if (thresholds && mb >= Math.round(thresholds.singleBlock / (1024 * 1024))) {
585
589
  appendIncident({ kind: 'plugin-budget', target: name, level: 'block', detail: '启动实测 ' + mb + ' MB > 500 MB,禁止该插件' })
586
590
  if (watchdogState.enforce) {
587
- watchdogState.quarantine.set(name, { reason: 'budget', level: 'L1', at: new Date().toISOString(), release: 'manual', evidence: mb + ' MB > 500 MB' })
591
+ watchdogState.quarantine.set(name, { reason: 'budget', level: 'L1', at: new Date().toISOString(), release: 'manual', evidence: mb + ' MB > 500 MB', remediation: remediationFor('budget') })
588
592
  void disableTarget(name, 'budget-over-500MB')
589
593
  writePendingBoot({ level: 'L1', reason: 'budget', disable: [name], keep: [] })
590
594
  }
@@ -674,6 +678,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
674
678
  const plan = {
675
679
  at: new Date().toISOString(),
676
680
  level,
681
+ remediation: remediationFor('crash'),
677
682
  crash: { file: crash.file, time: crash.parsed.time, phase: crash.parsed.phase, oom: crash.parsed.oom, hostExitCode: crash.parsed.hostExitCode },
678
683
  hostRunId: crash.parsed.hostRunId,
679
684
  target: attribution.picked ? attribution.picked.target : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/ai-prison-dsh-plugin",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
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",