@twinsearth/ai-prison-dsh-plugin 1.2.0 → 1.2.1
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 +19 -0
- package/lib/watchdog-runtime.js +23 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@twinsearth/ai-prison-dsh-plugin` are recorded here.
|
|
4
4
|
|
|
5
|
+
## [1.2.1] — 2026-11-18
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Watchdog row crashed before its sampler started**: `readCrashLogs()` ran during
|
|
10
|
+
setup and called `persist()` while `let lastFlush` was still in its temporal dead
|
|
11
|
+
zone, so the row threw a `ReferenceError` after recording crash history but before
|
|
12
|
+
registering the sampler, the operation listener and the status route. The value is now
|
|
13
|
+
declared before the first scan, `readCrashLogs` is wrapped defensively, and the
|
|
14
|
+
runtime exposes a `dispose()` used by tests.
|
|
15
|
+
- Watchdog state directory and crash-log directory are now injectable
|
|
16
|
+
(`config.dataDir` / `config.logsDir`) so runtime tests stay hermetic.
|
|
17
|
+
|
|
18
|
+
### Tests
|
|
19
|
+
|
|
20
|
+
- New `test/watchdog-runtime.test.mjs`: heap sampling, crash-fixture parsing and
|
|
21
|
+
persistence, plugin-operation counting/estimation, failed-operation and removal
|
|
22
|
+
handling, all against temporary directories.
|
|
23
|
+
|
|
5
24
|
## [1.2.0] — 2026-11-18
|
|
6
25
|
|
|
7
26
|
### Added — P0 memory watchdog (observe mode)
|
package/lib/watchdog-runtime.js
CHANGED
|
@@ -53,7 +53,8 @@ function readHead(file, bytes) {
|
|
|
53
53
|
/** Read-only watchdog runtime. It observes; it never enables or disables plugins. */
|
|
54
54
|
export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
55
55
|
const profileDir = resolveProfileDir()
|
|
56
|
-
const dataDir = path.join(profileDir, '.ai-prison-watchdog')
|
|
56
|
+
const dataDir = config.dataDir ? path.resolve(String(config.dataDir)) : path.join(profileDir, '.ai-prison-watchdog')
|
|
57
|
+
const logsDir = config.logsDir ? path.resolve(String(config.logsDir)) : resolveLogsDir()
|
|
57
58
|
const stateFile = path.join(dataDir, 'state.json')
|
|
58
59
|
const incidentsFile = path.join(dataDir, 'incidents.jsonl')
|
|
59
60
|
const log = {
|
|
@@ -72,6 +73,13 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
72
73
|
watchdogState.dataDir = dataDir
|
|
73
74
|
watchdogState.config = { sampleMs: SAMPLE_MS, ...config }
|
|
74
75
|
watchdogState.lastCrashScan = 0
|
|
76
|
+
let lastFlush = 0
|
|
77
|
+
const cleanups = []
|
|
78
|
+
const effect = (fn, label) => {
|
|
79
|
+
const disposer = ctx.effect(fn, label)
|
|
80
|
+
if (typeof disposer === 'function') cleanups.push(disposer)
|
|
81
|
+
return disposer
|
|
82
|
+
}
|
|
75
83
|
|
|
76
84
|
restoreState()
|
|
77
85
|
readCrashLogs()
|
|
@@ -107,7 +115,6 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
107
115
|
return record
|
|
108
116
|
}
|
|
109
117
|
|
|
110
|
-
let lastFlush = 0
|
|
111
118
|
function persist(force = false) {
|
|
112
119
|
const now = Date.now()
|
|
113
120
|
if (!force && now - lastFlush < FLUSH_MS) return
|
|
@@ -224,7 +231,6 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
224
231
|
}
|
|
225
232
|
|
|
226
233
|
function readCrashLogs() {
|
|
227
|
-
const logsDir = resolveLogsDir()
|
|
228
234
|
let entries
|
|
229
235
|
try {
|
|
230
236
|
entries = fs.readdirSync(logsDir, { withFileTypes: true })
|
|
@@ -264,9 +270,10 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
264
270
|
// Sampler (P0: observe only).
|
|
265
271
|
try {
|
|
266
272
|
if (typeof ctx.effect === 'function') {
|
|
267
|
-
|
|
273
|
+
effect(() => {
|
|
268
274
|
sample()
|
|
269
|
-
const
|
|
275
|
+
const interval = Number(config.sampleMs) > 0 ? Number(config.sampleMs) : SAMPLE_MS
|
|
276
|
+
const timer = setInterval(sample, interval)
|
|
270
277
|
return () => clearInterval(timer)
|
|
271
278
|
}, 'ai-prison-watchdog: sampler')
|
|
272
279
|
} else {
|
|
@@ -281,7 +288,7 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
281
288
|
try {
|
|
282
289
|
if (typeof ctx.on === 'function') {
|
|
283
290
|
if (typeof ctx.effect === 'function') {
|
|
284
|
-
|
|
291
|
+
effect(() => ctx.on('plugin-manager/operation', onOperation), 'ai-prison-watchdog: operations')
|
|
285
292
|
} else {
|
|
286
293
|
ctx.on('plugin-manager/operation', onOperation)
|
|
287
294
|
}
|
|
@@ -320,6 +327,16 @@ export function createWatchdog(ctx, config = {}, logger = {}) {
|
|
|
320
327
|
snapshot: watchdogSnapshot,
|
|
321
328
|
sample,
|
|
322
329
|
readCrashLogs,
|
|
330
|
+
dispose() {
|
|
331
|
+
while (cleanups.length > 0) {
|
|
332
|
+
const disposer = cleanups.pop()
|
|
333
|
+
try {
|
|
334
|
+
disposer()
|
|
335
|
+
} catch {
|
|
336
|
+
// ignore dispose races
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
},
|
|
323
340
|
}
|
|
324
341
|
}
|
|
325
342
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/ai-prison-dsh-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|