@twinsearth/ai-prison-dsh-plugin 0.0.0-stage → 1.1.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 ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@twinsearth/ai-prison-dsh-plugin` are recorded here.
4
+
5
+ ## [1.1.0] — 2026-11-17
6
+
7
+ First release: the AI Prison governance prototype as a DeepSeek Harness bundle.
8
+
9
+ ### Added
10
+
11
+ - **Seven model-facing tools**: `ai_prison_levels`, `ai_prison_status`,
12
+ `ai_prison_demo`, `ai_prison_drill`, `ai_prison_inspect`, `ai_prison_verify`,
13
+ `ai_prison_repair_tail`. Each call runs the bundled `aiprison` CLI and returns
14
+ `{ ok, command, dataDir, exitCode, timedOut, stdout, stderr }` with bounded
15
+ output, so a failing call reports instead of ending the turn.
16
+ - **Sidebar panel** (id `ai-prison`, order 2, shield icon): the L0–L5 grading
17
+ matrix, the ledger directory, integrity pill (`INTEGRITY OK` / `Check failed` /
18
+ `Not initialized`), record and file counts, CLI version/source, refresh button
19
+ and a 20-second auto refresh. Read-only.
20
+ - **Read-only status API** `GET /api/ai-prison/status` registered through
21
+ `ctx.connection.fetch`, the same authenticated channel the Web UI uses.
22
+ - **Bundled CLI**: six cross-compiled `aiprison` builds
23
+ (`windows`/`macos`/`linux` × `amd64`/`arm64`), plus `cliPath` /
24
+ `AIPRISON_BIN` / `PATH` fallbacks.
25
+ - **Bilingual display metadata** (`locale/en.json`, `locale/zh.json`) with a
26
+ single-image detail document, original icon and preview illustration.
27
+ - **Release machinery**: `scripts/build-binaries.mjs`,
28
+ `scripts/release-check.mjs`, npm tarball checks, market index
29
+ (`market/index.json`), and a `dsh-plugin-v*` GitHub Actions release workflow.
30
+
31
+ ### Known limits
32
+
33
+ - GRAM, TLM, hardware binding, MicroVM isolation and revocation distribution are
34
+ simulated; the tools demonstrate and audit governance, they do not enforce
35
+ real capability removal.
36
+ - Ledger writes remain limited to `demo`, `drill` and `repair-tail`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AI Prison Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # @twinsearth/ai-prison-dsh-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ AI Prison for DSH — the defensive agent-governance prototype of
4
+ [Ai-PRISON](https://github.com/TwinsEarth/Ai-PRISON), exposed as a DeepSeek
5
+ Harness bundle: six `ai_prison_*` tools plus a sidebar panel that renders the
6
+ L0–L5 grading matrix and the durable ledger's audit-chain state.
7
+
8
+ Everything here is **defensive**: detection, graduated capability deprivation,
9
+ hash-chained audit, appeal and rehabilitation. GRAM, TLM, hardware binding and
10
+ MicroVM isolation are **simulated backends**, not shipped controls.
11
+
12
+ ## Install
13
+
14
+ - **Plugin Manager** → **Add plugin** → install this directory or the npm package.
15
+ - **npm**: `@twinsearth/ai-prison-dsh-plugin` (bundled `aiprison` CLI for
16
+ Windows, macOS and Linux, amd64 and arm64).
17
+ - **CLI**: `dsh plugin install @twinsearth/ai-prison-dsh-plugin` (or pass the
18
+ absolute package directory to the plugin manager).
19
+
20
+ After enabling the bundle, a shield entry appears in the sidebar. Open it for the
21
+ panel; the six tools become visible to the Agent on the next session step.
22
+
23
+ ## Tools
24
+
25
+ | Tool | Effect | What it does |
26
+ |---|---|---|
27
+ | `ai_prison_levels` | read-only | Print the L0–L5 matrix (codes, names, duration class, deprived capabilities). |
28
+ | `ai_prison_status` | read-only | CLI path/source/version, the matrix, and the ledger's integrity + record count. Same data as the panel. |
29
+ | `ai_prison_demo` | writes ledger | End-to-end governance demo: detect → seven-stage adjudication → layered enforcement → audit → appeal/rehabilitation → recovery. |
30
+ | `ai_prison_drill` | writes ledger | v1.0.0 recovery drill over the reversibility matrix with per-assertion PASS/FAIL and an overall verdict. |
31
+ | `ai_prison_inspect` | read-only | Replay the ledger: hash chain, agents, sentences, revocations, receipts, sealed snapshots. |
32
+ | `ai_prison_verify` | read-only | Verify every per-record hash link; `INTEGRITY OK` + exit 0, or locate the tamper/torn tail and exit 1. |
33
+ | `ai_prison_repair_tail` | mutates | Remove only a genuine torn tail line; refuses hard tampering. Run `ai_prison_verify` first. |
34
+
35
+ The panel shows the matrix from `ai_prison_levels` data plus the ledger
36
+ directory, integrity pill, record and file counts; it refreshes every 20 seconds
37
+ and on demand. It is strictly read-only.
38
+
39
+ ## Ledger directory
40
+
41
+ Default: `<session working directory>/.ai-prison`, so the audit trail stays next
42
+ to the project it governs. Override with a tool argument (`data_dir`) or with the
43
+ plugin config:
44
+
45
+ ```yaml
46
+ - id: ai-prison
47
+ config:
48
+ cliPath: '' # absolute path to a specific aiprison binary
49
+ dataDir: '' # durable ledger directory
50
+ timeoutMs: 120000 # per-call CLI timeout
51
+ ```
52
+
53
+ Resolution order for the CLI: `config.cliPath` → `AIPRISON_BIN` → the bundled
54
+ build for this platform → `aiprison` on `PATH`.
55
+
56
+ ## Bundled CLIs
57
+
58
+ `bin/<platform>-<arch>/aiprison` ships six cross-compiled builds: `windows`,
59
+ `macos`, `linux` × `amd64`, `arm64`. They are built from the Go sources in this
60
+ repository with `node dsh-plugin/scripts/build-binaries.mjs` (pure standard
61
+ library, `CGO_ENABLED=0`, no module downloads) and are not committed to git.
62
+
63
+ On a platform without a bundled build, point `cliPath` / `AIPRISON_BIN` at a
64
+ binary built from `cmd/aiprison`.
65
+
66
+ ## Development
67
+
68
+ ```bash
69
+ node dsh-plugin/scripts/build-binaries.mjs # from the repository root
70
+ cd dsh-plugin
71
+ node --test test/*.test.mjs # unit + integration tests
72
+ node scripts/release-check.mjs # version, files, binaries, secrets
73
+ node scripts/update-market-index.mjs # regenerate market/index.json
74
+ ```
75
+
76
+ A release is a `dsh-plugin-v*` tag: CI rebuilds the binaries, runs the tests and
77
+ the release check, packs the npm tarball and publishes the GitHub Release assets.
78
+
79
+ ## Limitations
80
+
81
+ - Backends are simulations: no real isolation, revocation distribution,
82
+ hardware binding or capability removal happens.
83
+ - The plugin never writes the ledger from the panel or from status calls; only
84
+ `demo`, `drill` and `repair-tail` mutate it.
85
+ - A wrong `data_dir` reveals that directory's integrity state only; the plugin
86
+ reads and checks, it does not repair anything except the torn tail the CLI
87
+ itself accepts.
88
+ - On Windows, the aiprison binaries are unsigned; an enabled Controlled Folder
89
+ Access policy can deny their writes outside allowed locations. Keep the ledger
90
+ inside the working directory (the default) or allow the binary in Windows
91
+ Security.
92
+
93
+ ## License
94
+
95
+ MIT — same as the AI Prison prototype in this repository.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/client.js ADDED
@@ -0,0 +1,352 @@
1
+ // Client half of @twinsearth/ai-prison-dsh-plugin: a sidebar entry plus the
2
+ // panel that renders the L0–L5 matrix and the durable ledger's audit-chain
3
+ // state. Data comes from GET /api/ai-prison/status (read-only).
4
+ window.__ModuleLoader__.load({
5
+ id: '@twinsearth/ai-prison-dsh-plugin',
6
+ factory: (require) => {
7
+ const React = require('react')
8
+ const h = React.createElement
9
+
10
+ const PANEL_ID = 'ai-prison'
11
+ const NS = 'ai-prison'
12
+ const STATUS_URL = 'api/ai-prison/status'
13
+
14
+ const DICTS = {
15
+ en: {
16
+ 'panel.label': 'AI Prison',
17
+ 'page.title': 'AI Prison',
18
+ 'page.subtitle': 'Graduated capability deprivation for agents. Every backend is simulated.',
19
+ 'matrix.title': 'L0–L5 grading matrix',
20
+ 'matrix.code': 'Level',
21
+ 'matrix.name': 'Name',
22
+ 'matrix.duration': 'Duration',
23
+ 'matrix.deprivations': 'Deprived capabilities',
24
+ 'matrix.empty': 'The CLI is not ready, so the matrix cannot be read.',
25
+ 'ledger.title': 'Audit chain',
26
+ 'ledger.dir': 'Ledger directory',
27
+ 'ledger.records': 'Records',
28
+ 'ledger.integrity': 'Integrity',
29
+ 'ledger.files': 'Files',
30
+ 'ledger.detail': 'Detail',
31
+ 'ledger.empty': 'No ledger yet: run the demo or the drill to create one.',
32
+ 'integrity.ok': 'INTEGRITY OK',
33
+ 'integrity.failed': 'Check failed',
34
+ 'integrity.none': 'Not initialized',
35
+ 'cli.found': 'aiprison {version}',
36
+ 'cli.missing': 'CLI not found',
37
+ 'cli.source': 'Source',
38
+ 'action.refresh': 'Refresh',
39
+ 'action.loading': 'Reading…',
40
+ 'meta.updated': 'Updated {time}',
41
+ 'meta.readonly': 'Read-only view: this panel never writes to the ledger.',
42
+ 'error.title': 'Cannot read the status',
43
+ 'error.hint': 'Check that the bundle is enabled and the aiprison CLI resolves for this platform.',
44
+ },
45
+ zh: {
46
+ 'panel.label': 'AI Prison',
47
+ 'page.title': 'AI Prison · AI 监狱',
48
+ 'page.subtitle': '面向 AI Agent 的分级能力剥夺与行为矫正;所有后端均为内存模拟。',
49
+ 'matrix.title': 'L0–L5 分级矩阵',
50
+ 'matrix.code': '级别',
51
+ 'matrix.name': '名称',
52
+ 'matrix.duration': '期限',
53
+ 'matrix.deprivations': '被剥夺的能力',
54
+ 'matrix.empty': 'CLI 未就绪,暂时无法读取矩阵。',
55
+ 'ledger.title': '审计链状态',
56
+ 'ledger.dir': '数据目录',
57
+ 'ledger.records': '记录数',
58
+ 'ledger.integrity': '完整性',
59
+ 'ledger.files': '文件数',
60
+ 'ledger.detail': '详情',
61
+ 'ledger.empty': '账本尚未初始化:运行 demo 或 drill 即可创建。',
62
+ 'integrity.ok': 'INTEGRITY OK',
63
+ 'integrity.failed': '校验失败',
64
+ 'integrity.none': '未初始化',
65
+ 'cli.found': 'aiprison {version}',
66
+ 'cli.missing': 'CLI 未找到',
67
+ 'cli.source': '来源',
68
+ 'action.refresh': '刷新',
69
+ 'action.loading': '读取中…',
70
+ 'meta.updated': '更新于 {time}',
71
+ 'meta.readonly': '只读视图:本面板不会写入数据目录。',
72
+ 'error.title': '无法读取状态',
73
+ 'error.hint': '请确认插件已启用,且本平台能解析到 aiprison CLI。',
74
+ },
75
+ }
76
+
77
+ const fallbackDict = String(navigator.language || '').toLowerCase().startsWith('zh') ? DICTS.zh : DICTS.en
78
+ let translate
79
+
80
+ function t(key, vars) {
81
+ let text = (typeof translate === 'function' ? translate(key) : undefined) || fallbackDict[key] || key
82
+ if (vars) {
83
+ for (const [name, value] of Object.entries(vars)) text = text.split(`{${name}}`).join(String(value))
84
+ }
85
+ return text
86
+ }
87
+
88
+ const C = {
89
+ page: { maxWidth: 980, margin: '0 auto', padding: '20px 24px 16px', color: 'var(--dsw-alias-label-primary, #0f1115)' },
90
+ header: { display: 'flex', alignItems: 'center', gap: 12, marginBottom: 14 },
91
+ title: { fontSize: 18, fontWeight: 600, margin: 0 },
92
+ sub: { fontSize: 12, color: 'var(--dsw-alias-label-secondary, #61666b)', margin: '3px 0 0' },
93
+ pill: {
94
+ marginLeft: 'auto',
95
+ display: 'inline-flex',
96
+ alignItems: 'center',
97
+ gap: 6,
98
+ fontSize: 12,
99
+ fontWeight: 500,
100
+ padding: '4px 10px',
101
+ borderRadius: 999,
102
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
103
+ whiteSpace: 'nowrap',
104
+ },
105
+ dot: { width: 8, height: 8, borderRadius: 999, display: 'inline-block' },
106
+ card: {
107
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
108
+ borderRadius: 12,
109
+ padding: 12,
110
+ marginBottom: 12,
111
+ background: 'var(--dsw-alias-bg-layer-1, transparent)',
112
+ },
113
+ cardHead: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8, fontSize: 13, fontWeight: 600 },
114
+ table: { width: '100%', borderCollapse: 'collapse', fontSize: 12.5 },
115
+ th: {
116
+ textAlign: 'left',
117
+ fontWeight: 500,
118
+ color: 'var(--dsw-alias-label-secondary, #61666b)',
119
+ padding: '6px 8px',
120
+ borderBottom: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
121
+ whiteSpace: 'nowrap',
122
+ },
123
+ td: {
124
+ padding: '7px 8px',
125
+ borderBottom: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,.06))',
126
+ verticalAlign: 'top',
127
+ },
128
+ mono: { fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 12 },
129
+ code: { fontWeight: 600, fontFamily: 'ui-monospace, Consolas, monospace' },
130
+ chips: { display: 'flex', flexWrap: 'wrap', gap: 4 },
131
+ chip: {
132
+ fontSize: 11.5,
133
+ padding: '1px 7px',
134
+ borderRadius: 999,
135
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
136
+ color: 'var(--dsw-alias-label-secondary, #61666b)',
137
+ whiteSpace: 'nowrap',
138
+ },
139
+ grid: { display: 'grid', gridTemplateColumns: 'minmax(110px, max-content) minmax(0, 1fr)', gap: '6px 14px', fontSize: 12.5 },
140
+ key: { color: 'var(--dsw-alias-label-secondary, #61666b)' },
141
+ muted: { color: 'var(--dsw-alias-label-secondary, #61666b)' },
142
+ btn: {
143
+ padding: '5px 10px',
144
+ borderRadius: 7,
145
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.16))',
146
+ background: 'transparent',
147
+ color: 'inherit',
148
+ cursor: 'pointer',
149
+ fontSize: 12,
150
+ marginLeft: 8,
151
+ },
152
+ error: { color: '#c81e1e' },
153
+ ok: { color: '#15803d' },
154
+ }
155
+
156
+ function PrisonIcon({ size = 36, active = true }) {
157
+ return h(
158
+ 'svg',
159
+ {
160
+ width: size,
161
+ height: size,
162
+ viewBox: '0 0 36 36',
163
+ role: 'img',
164
+ 'aria-hidden': true,
165
+ style: { display: 'block', opacity: active ? 1 : 0.75, flex: 'none' },
166
+ },
167
+ h('path', {
168
+ d: 'M18 4.4 29.4 9v9.1c0 6.7-11.4 13.2-11.4 13.2S6.6 24.7 6.6 18.1V9z',
169
+ fill: 'none',
170
+ stroke: '#334155',
171
+ strokeWidth: 2.2,
172
+ strokeLinejoin: 'round',
173
+ }),
174
+ h('path', { d: 'M14 12.6v11.2M18 11.4v13.4M22 12.6v11.2', stroke: '#334155', strokeWidth: 2.2, strokeLinecap: 'round' }),
175
+ )
176
+ }
177
+
178
+ function Pill({ tone, text }) {
179
+ const color = tone === 'ok' ? C.ok.color : tone === 'error' ? C.error.color : C.muted.color
180
+ return h('span', { style: C.pill }, h('span', { style: { ...C.dot, background: color } }), h('span', null, text))
181
+ }
182
+
183
+ function fetchStatus() {
184
+ return fetch(new URL(STATUS_URL, document.baseURI), {
185
+ credentials: 'same-origin',
186
+ headers: { accept: 'application/json' },
187
+ }).then((response) => {
188
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
189
+ return response.json()
190
+ })
191
+ }
192
+
193
+ function MatrixCard({ levels }) {
194
+ if (!Array.isArray(levels) || levels.length === 0) {
195
+ return h('section', { style: C.card }, h('div', { style: C.cardHead }, t('matrix.title')), h('p', { style: { ...C.muted, margin: 0, fontSize: 12 } }, t('matrix.empty')))
196
+ }
197
+ return h(
198
+ 'section',
199
+ { style: C.card },
200
+ h('div', { style: C.cardHead }, t('matrix.title')),
201
+ h(
202
+ 'table',
203
+ { style: C.table },
204
+ h('thead', null, h('tr', null, h('th', { style: C.th }, t('matrix.code')), h('th', { style: C.th }, t('matrix.name')), h('th', { style: C.th }, t('matrix.duration')), h('th', { style: C.th }, t('matrix.deprivations')))),
205
+ h(
206
+ 'tbody',
207
+ null,
208
+ levels.map((level) =>
209
+ h(
210
+ 'tr',
211
+ { key: level.code },
212
+ h('td', { style: C.td }, h('span', { style: C.code }, level.code)),
213
+ h('td', { style: C.td }, level.name),
214
+ h('td', { style: C.td }, h('span', { title: level.durationHint || '' }, level.durationClass || '—')),
215
+ h(
216
+ 'td',
217
+ { style: C.td },
218
+ h('div', { style: C.chips }, (level.deprivations || []).map((item) => h('span', { key: item, style: C.chip }, item))),
219
+ ),
220
+ ),
221
+ ),
222
+ ),
223
+ ),
224
+ )
225
+ }
226
+
227
+ function LedgerCard({ ledger }) {
228
+ const exists = Boolean(ledger && ledger.exists)
229
+ const integrityTone = !exists ? 'none' : ledger.integrity === 'ok' ? 'ok' : 'error'
230
+ const integrityText = !exists ? t('integrity.none') : ledger.integrity === 'ok' ? t('integrity.ok') : t('integrity.failed')
231
+ const entries = [
232
+ { key: 'dir', label: t('ledger.dir'), value: h('span', { style: { ...C.mono, wordBreak: 'break-all' } }, ledger?.dir || '—') },
233
+ { key: 'integrity', label: t('ledger.integrity'), value: h(Pill, { tone: integrityTone, text: integrityText }) },
234
+ ]
235
+ if (exists) {
236
+ entries.push({ key: 'records', label: t('ledger.records'), value: h('span', { style: C.mono }, String(ledger.records ?? '—')) })
237
+ entries.push({ key: 'files', label: t('ledger.files'), value: h('span', { style: C.mono }, String(ledger.files ?? '—')) })
238
+ }
239
+ if (exists && ledger.detail) {
240
+ entries.push({ key: 'detail', label: t('ledger.detail'), value: h('span', { style: { ...C.mono, wordBreak: 'break-word' } }, ledger.detail) })
241
+ }
242
+ return h(
243
+ 'section',
244
+ { style: C.card },
245
+ h('div', { style: C.cardHead }, t('ledger.title')),
246
+ h(
247
+ 'div',
248
+ { style: C.grid },
249
+ entries.flatMap((entry) => [
250
+ h('div', { key: `k-${entry.key}`, style: C.key }, entry.label),
251
+ h('div', { key: `v-${entry.key}` }, entry.value),
252
+ ]),
253
+ ),
254
+ !exists ? h('p', { style: { ...C.muted, fontSize: 12, margin: '8px 0 0' } }, t('ledger.empty')) : null,
255
+ )
256
+ }
257
+
258
+ function PrisonPage() {
259
+ const [data, setData] = React.useState(null)
260
+ const [error, setError] = React.useState(null)
261
+ const [loading, setLoading] = React.useState(true)
262
+ const [updated, setUpdated] = React.useState(null)
263
+
264
+ const load = React.useCallback(() => {
265
+ setLoading(true)
266
+ setError(null)
267
+ fetchStatus()
268
+ .then((payload) => {
269
+ setData(payload)
270
+ setUpdated(new Date())
271
+ setLoading(false)
272
+ })
273
+ .catch((cause) => {
274
+ setError(String((cause && cause.message) || cause))
275
+ setLoading(false)
276
+ })
277
+ }, [])
278
+
279
+ React.useEffect(() => {
280
+ load()
281
+ const timer = setInterval(load, 20000)
282
+ return () => clearInterval(timer)
283
+ }, [load])
284
+
285
+ const cli = data?.cli
286
+ const cliText = cli && cli.found ? t('cli.found', { version: cli.version || '?' }) : t('cli.missing')
287
+ const timeText = updated ? updated.toLocaleTimeString() : ''
288
+
289
+ return h(
290
+ 'div',
291
+ { style: C.page },
292
+ h(
293
+ 'div',
294
+ { style: C.header },
295
+ h('span', { style: { display: 'inline-flex' } }, h(PrisonIcon, { size: 26, active: true })),
296
+ h('div', { style: { minWidth: 0 } }, h('h1', { style: C.title }, t('page.title')), h('p', { style: C.sub }, t('page.subtitle'))),
297
+ h(Pill, { tone: cli && cli.found ? 'ok' : 'error', text: cliText }),
298
+ h('button', { type: 'button', style: C.btn, onClick: load, disabled: loading }, loading ? t('action.loading') : t('action.refresh')),
299
+ ),
300
+ error
301
+ ? h(
302
+ 'section',
303
+ { style: C.card },
304
+ h('div', { style: { ...C.cardHead, ...C.error } }, t('error.title')),
305
+ h('p', { style: { ...C.mono, margin: 0 } }, error),
306
+ h('p', { style: { ...C.muted, fontSize: 12, margin: '8px 0 0' } }, t('error.hint')),
307
+ )
308
+ : null,
309
+ h(MatrixCard, { levels: data?.levels }),
310
+ h(LedgerCard, { ledger: data?.ledger }),
311
+ h(
312
+ 'p',
313
+ { style: { ...C.muted, fontSize: 12, margin: '2px 0 0', display: 'flex', gap: 12, flexWrap: 'wrap' } },
314
+ h('span', null, t('meta.readonly')),
315
+ cli && cli.path ? h('span', { style: C.mono }, `${t('cli.source')}: ${cli.source} · ${cli.path}`) : null,
316
+ timeText ? h('span', null, t('meta.updated', { time: timeText })) : null,
317
+ ),
318
+ )
319
+ }
320
+
321
+ function apply(ctx) {
322
+ try {
323
+ if (ctx.locale) {
324
+ ctx.locale.register(NS, 'en', DICTS.en)
325
+ ctx.locale.register(NS, 'zh', DICTS.zh)
326
+ translate = ctx.locale.bind(NS)
327
+ } else if (typeof ctx.inject === 'function') {
328
+ ctx.inject(['locale'], (child) => {
329
+ child.locale.register(NS, 'en', DICTS.en)
330
+ child.locale.register(NS, 'zh', DICTS.zh)
331
+ translate = child.locale.bind(NS)
332
+ })
333
+ }
334
+ } catch (cause) {
335
+ console.warn('[ai-prison] locale registration failed', cause)
336
+ }
337
+ ctx.effect(
338
+ () =>
339
+ ctx.slots.inject('sidebar.panellist', () =>
340
+ ctx.slots.register({ name: 'sidebar.panellist', id: PANEL_ID, order: 2, label: () => t('panel.label') }, PrisonIcon),
341
+ ),
342
+ 'ai-prison: sidebar entry',
343
+ )
344
+ ctx.effect(
345
+ () => ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, PrisonPage)),
346
+ 'ai-prison: main panel',
347
+ )
348
+ }
349
+
350
+ return { inject: ['slots'], apply, PANEL_ID, NS }
351
+ },
352
+ })
@@ -0,0 +1,21 @@
1
+ # ai-prison-dsh-plugin: the AI Prison governance bundle.
2
+ #
3
+ # One row carries both halves: the Host half registers the six aiprison_* tools
4
+ # and the read-only status API behind the panel, the Client half registers the
5
+ # sidebar panel that renders the L0–L5 matrix and the audit-chain state.
6
+ #
7
+ # Optional config (a profile-level patch replaces this block wholesale, so
8
+ # restate every field you want to keep):
9
+ #
10
+ # config:
11
+ # # Absolute path to an aiprison binary. Default: the bundled build for
12
+ # # this platform, else `aiprison` on PATH.
13
+ # cliPath: ''
14
+ # # Durable ledger directory. Default: <session working directory>/.ai-prison
15
+ # dataDir: ''
16
+ # # Per-call timeout for the bundled CLI, milliseconds.
17
+ # timeoutMs: 120000
18
+ - insert:
19
+ - id: ai-prison
20
+ name: '@twinsearth/ai-prison-dsh-plugin'
21
+ config: {}
package/docs/DETAIL.md ADDED
@@ -0,0 +1 @@
1
+ ![AI Prison panel: the L0–L5 grading matrix beside the audit-chain integrity and record count of the ledger](preview.svg)
@@ -0,0 +1 @@
1
+ ![AI Prison 面板:左侧 L0–L5 分级矩阵,右侧审计链完整性与记录数](preview.svg)
@@ -0,0 +1,30 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300" fill="none">
2
+ <rect x="24" y="24" width="592" height="252" rx="16" fill="#f8fafc"/>
3
+ <rect x="24" y="24" width="592" height="252" rx="16" stroke="#e2e8f0" stroke-width="2"/>
4
+ <path d="M132 58 214 91v58c0 44-82 86-82 86S50 193 50 149V91z" stroke="#334155" stroke-width="6" stroke-linejoin="round"/>
5
+ <path d="M104 116v64M132 108v80M160 116v64" stroke="#334155" stroke-width="6" stroke-linecap="round"/>
6
+ <circle cx="132" cy="228" r="10" fill="#334155"/>
7
+ <rect x="268" y="62" width="52" height="22" rx="11" fill="#334155"/>
8
+ <rect x="336" y="62" width="196" height="22" rx="11" fill="#cbd5e1"/>
9
+ <rect x="268" y="100" width="52" height="22" rx="11" fill="#475569"/>
10
+ <rect x="336" y="100" width="164" height="22" rx="11" fill="#cbd5e1"/>
11
+ <rect x="268" y="138" width="52" height="22" rx="11" fill="#64748b"/>
12
+ <rect x="336" y="138" width="132" height="22" rx="11" fill="#cbd5e1"/>
13
+ <rect x="268" y="176" width="52" height="22" rx="11" fill="#94a3b8"/>
14
+ <rect x="336" y="176" width="100" height="22" rx="11" fill="#cbd5e1"/>
15
+ <rect x="268" y="214" width="52" height="22" rx="11" fill="#2563eb"/>
16
+ <rect x="336" y="214" width="68" height="22" rx="11" fill="#bfdbfe"/>
17
+ <g stroke="#2563eb" stroke-width="3" fill="none">
18
+ <rect x="464" y="88" width="44" height="26" rx="13"/>
19
+ <rect x="520" y="88" width="44" height="26" rx="13"/>
20
+ <rect x="464" y="150" width="44" height="26" rx="13"/>
21
+ <rect x="520" y="150" width="44" height="26" rx="13"/>
22
+ <rect x="464" y="212" width="44" height="26" rx="13"/>
23
+ <rect x="520" y="212" width="44" height="26" rx="13"/>
24
+ </g>
25
+ <path d="M508 101h12M508 163h12M508 225h12" stroke="#2563eb" stroke-width="3"/>
26
+ <path d="M452 101h8M452 163h8M452 225h8" stroke="#94a3b8" stroke-width="3"/>
27
+ <circle cx="576" cy="101" r="7" fill="#16a34a"/>
28
+ <circle cx="576" cy="163" r="7" fill="#16a34a"/>
29
+ <circle cx="576" cy="225" r="7" fill="#16a34a"/>
30
+ </svg>
package/icon.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" fill="none">
2
+ <path d="M18 4.4 29.4 9v9.1c0 6.7-11.4 13.2-11.4 13.2S6.6 24.7 6.6 18.1V9z" stroke="#334155" stroke-width="2.2" stroke-linejoin="round"/>
3
+ <path d="M14 12.6v11.2M18 11.4v13.4M22 12.6v11.2" stroke="#334155" stroke-width="2.2" stroke-linecap="round"/>
4
+ <circle cx="18" cy="27.4" r="2.1" fill="#334155"/>
5
+ </svg>
package/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { registerApi } from './lib/api.js'
2
+ import { installTools } from './lib/tools.js'
3
+
4
+ function loggerOf(ctx) {
5
+ const logger = ctx && typeof ctx === 'object' ? ctx.logger : undefined
6
+ return {
7
+ info: (...args) => (typeof logger?.info === 'function' ? logger.info(...args) : console.log('[ai-prison]', ...args)),
8
+ warn: (...args) => (typeof logger?.warn === 'function' ? logger.warn(...args) : console.warn('[ai-prison]', ...args)),
9
+ }
10
+ }
11
+
12
+ /**
13
+ * Host half of the bundle. It registers the aiprison_* tools and the read-only
14
+ * status API; the Client half (client.js) owns the sidebar panel. Both halves
15
+ * are optional services: a profile without `connection` keeps the tools, and a
16
+ * harness whose tools module cannot be resolved keeps the panel.
17
+ */
18
+ export function apply(ctx, config = {}) {
19
+ const logger = loggerOf(ctx)
20
+ const pluginConfig = config && typeof config === 'object' ? config : {}
21
+
22
+ const apiInstalled = registerApi({ ctx, config: pluginConfig, logger })
23
+ if (!apiInstalled) logger.info('ctx.inject 不可用:状态 API 未注册')
24
+
25
+ installTools({ ctx, config: pluginConfig, logger }).catch((error) => {
26
+ logger.warn(`aiprison_* 工具注册失败:${String((error && error.message) || error)}`)
27
+ })
28
+
29
+ ctx.effect(() => () => logger.info('AI Prison 插件已卸载'), 'ai-prison: lifecycle')
30
+ }
package/lib/api.js ADDED
@@ -0,0 +1,40 @@
1
+ import { buildStatus } from './status.js'
2
+
3
+ /**
4
+ * Read-only status API behind the sidebar panel. It registers through
5
+ * `ctx.connection.fetch`, so the route is authenticated exactly like the rest of
6
+ * the Web UI and needs no separate web server.
7
+ */
8
+ export function registerApi({ ctx, config = {}, logger } = {}) {
9
+ if (!ctx || typeof ctx.inject !== 'function') return false
10
+ ctx.inject(['connection'], (child) => {
11
+ try {
12
+ child.effect(
13
+ () =>
14
+ child.connection.fetch.register({
15
+ path: '/api/ai-prison/status',
16
+ methods: ['GET'],
17
+ requestBody: 'buffered',
18
+ fetch: async (request) => {
19
+ try {
20
+ const url = new URL(request.url)
21
+ const requested = url.searchParams.get('data_dir')
22
+ const statusConfig = requested ? { ...config, dataDir: requested } : config
23
+ const status = await buildStatus({ config: statusConfig })
24
+ return Response.json(status, { headers: { 'cache-control': 'no-store' } })
25
+ } catch (error) {
26
+ return Response.json(
27
+ { ok: false, error: String((error && error.message) || error) },
28
+ { status: 500 },
29
+ )
30
+ }
31
+ },
32
+ }),
33
+ 'ai-prison: status api',
34
+ )
35
+ } catch (error) {
36
+ logger?.warn?.(`注册 /api/ai-prison/status 失败:${String(error && error.message)}`)
37
+ }
38
+ })
39
+ return true
40
+ }