@twinsearth/ai-prison-dsh-plugin 0.0.0-stage → 1.1.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 ADDED
@@ -0,0 +1,54 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@twinsearth/ai-prison-dsh-plugin` are recorded here.
4
+
5
+ ## [1.1.1] — 2026-11-18
6
+
7
+ ### Added
8
+
9
+ - **Panel actions**: the audit-chain card now has **Run demo (create ledger)** and
10
+ **Run recovery drill** buttons plus a last-action line. They call the new
11
+ `POST /api/ai-prison/run` Host route (authenticated through
12
+ `ctx.connection.fetch`), which runs the bundled CLI with the resolved ledger
13
+ directory; the panel itself still never writes on its own.
14
+
15
+ ### Fixed
16
+
17
+ - **Panel ledger directory**: the status route resolved `process.cwd()` (the
18
+ profile directory, e.g. `…/.dsh/profiles/desktop/.ai-prison`) because a Fetch
19
+ route carries no Agent. It now resolves the most recent live Session's
20
+ effective directory through `ctx.sessions` + `ctx.workingDirectory`, so the
21
+ panel and its action buttons use the session workspace by default.
22
+
23
+ ## [1.1.0] — 2026-11-17
24
+
25
+ First release: the AI Prison governance prototype as a DeepSeek Harness bundle.
26
+
27
+ ### Added
28
+
29
+ - **Seven model-facing tools**: `ai_prison_levels`, `ai_prison_status`,
30
+ `ai_prison_demo`, `ai_prison_drill`, `ai_prison_inspect`, `ai_prison_verify`,
31
+ `ai_prison_repair_tail`. Each call runs the bundled `aiprison` CLI and returns
32
+ `{ ok, command, dataDir, exitCode, timedOut, stdout, stderr }` with bounded
33
+ output, so a failing call reports instead of ending the turn.
34
+ - **Sidebar panel** (id `ai-prison`, order 2, shield icon): the L0–L5 grading
35
+ matrix, the ledger directory, integrity pill (`INTEGRITY OK` / `Check failed` /
36
+ `Not initialized`), record and file counts, CLI version/source, refresh button
37
+ and a 20-second auto refresh. Read-only.
38
+ - **Read-only status API** `GET /api/ai-prison/status` registered through
39
+ `ctx.connection.fetch`, the same authenticated channel the Web UI uses.
40
+ - **Bundled CLI**: six cross-compiled `aiprison` builds
41
+ (`windows`/`macos`/`linux` × `amd64`/`arm64`), plus `cliPath` /
42
+ `AIPRISON_BIN` / `PATH` fallbacks.
43
+ - **Bilingual display metadata** (`locale/en.json`, `locale/zh.json`) with a
44
+ single-image detail document, original icon and preview illustration.
45
+ - **Release machinery**: `scripts/build-binaries.mjs`,
46
+ `scripts/release-check.mjs`, npm tarball checks, market index
47
+ (`market/index.json`), and a `dsh-plugin-v*` GitHub Actions release workflow.
48
+
49
+ ### Known limits
50
+
51
+ - GRAM, TLM, hardware binding, MicroVM isolation and revocation distribution are
52
+ simulated; the tools demonstrate and audit governance, they do not enforce
53
+ real capability removal.
54
+ - 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,100 @@
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. Below the audit-chain card sit two explicit buttons — **Run demo
38
+ (create ledger)** and **Run recovery drill** — which call `POST
39
+ /api/ai-prison/run` and therefore write the ledger only when pressed; the panel
40
+ never writes on its own.
41
+
42
+ ## Ledger directory
43
+
44
+ Default for tools: `<session working directory>/.ai-prison`, so the audit trail
45
+ stays next to the project it governs. The panel resolves the most recent live
46
+ Session's effective directory for the same reason (a Fetch route carries no
47
+ Agent of its own). Override with a tool argument (`data_dir`) or with the plugin
48
+ config:
49
+
50
+ ```yaml
51
+ - id: ai-prison
52
+ config:
53
+ cliPath: '' # absolute path to a specific aiprison binary
54
+ dataDir: '' # durable ledger directory
55
+ timeoutMs: 120000 # per-call CLI timeout
56
+ ```
57
+
58
+ Resolution order for the CLI: `config.cliPath` → `AIPRISON_BIN` → the bundled
59
+ build for this platform → `aiprison` on `PATH`.
60
+
61
+ ## Bundled CLIs
62
+
63
+ `bin/<platform>-<arch>/aiprison` ships six cross-compiled builds: `windows`,
64
+ `macos`, `linux` × `amd64`, `arm64`. They are built from the Go sources in this
65
+ repository with `node dsh-plugin/scripts/build-binaries.mjs` (pure standard
66
+ library, `CGO_ENABLED=0`, no module downloads) and are not committed to git.
67
+
68
+ On a platform without a bundled build, point `cliPath` / `AIPRISON_BIN` at a
69
+ binary built from `cmd/aiprison`.
70
+
71
+ ## Development
72
+
73
+ ```bash
74
+ node dsh-plugin/scripts/build-binaries.mjs # from the repository root
75
+ cd dsh-plugin
76
+ node --test test/*.test.mjs # unit + integration tests
77
+ node scripts/release-check.mjs # version, files, binaries, secrets
78
+ node scripts/update-market-index.mjs # regenerate market/index.json
79
+ ```
80
+
81
+ A release is a `dsh-plugin-v*` tag: CI rebuilds the binaries, runs the tests and
82
+ the release check, packs the npm tarball and publishes the GitHub Release assets.
83
+
84
+ ## Limitations
85
+
86
+ - Backends are simulations: no real isolation, revocation distribution,
87
+ hardware binding or capability removal happens.
88
+ - The plugin never writes the ledger from status calls; only the two explicit
89
+ panel buttons and the `demo`, `drill` and `repair-tail` tools mutate it.
90
+ - A wrong `data_dir` reveals that directory's integrity state only; the plugin
91
+ reads and checks, it does not repair anything except the torn tail the CLI
92
+ itself accepts.
93
+ - On Windows, the aiprison binaries are unsigned; an enabled Controlled Folder
94
+ Access policy can deny their writes outside allowed locations. Keep the ledger
95
+ inside the working directory (the default) or allow the binary in Windows
96
+ Security.
97
+
98
+ ## License
99
+
100
+ 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,447 @@
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
+ const RUN_URL = 'api/ai-prison/run'
14
+
15
+ const DICTS = {
16
+ en: {
17
+ 'panel.label': 'AI Prison',
18
+ 'page.title': 'AI Prison',
19
+ 'page.subtitle': 'Graduated capability deprivation for agents. Every backend is simulated.',
20
+ 'matrix.title': 'L0–L5 grading matrix',
21
+ 'matrix.code': 'Level',
22
+ 'matrix.name': 'Name',
23
+ 'matrix.duration': 'Duration',
24
+ 'matrix.deprivations': 'Deprived capabilities',
25
+ 'matrix.empty': 'The CLI is not ready, so the matrix cannot be read.',
26
+ 'ledger.title': 'Audit chain',
27
+ 'ledger.dir': 'Ledger directory',
28
+ 'ledger.records': 'Records',
29
+ 'ledger.integrity': 'Integrity',
30
+ 'ledger.files': 'Files',
31
+ 'ledger.detail': 'Detail',
32
+ 'ledger.empty': 'No ledger yet: run the demo or the drill to create one.',
33
+ 'integrity.ok': 'INTEGRITY OK',
34
+ 'integrity.failed': 'Check failed',
35
+ 'integrity.none': 'Not initialized',
36
+ 'cli.found': 'aiprison {version}',
37
+ 'cli.missing': 'CLI not found',
38
+ 'cli.source': 'Source',
39
+ 'action.refresh': 'Refresh',
40
+ 'action.loading': 'Reading…',
41
+ 'action.runDemo': 'Run demo (create ledger)',
42
+ 'action.runDrill': 'Run recovery drill',
43
+ 'action.running': 'Running…',
44
+ 'ledger.actions': 'Explicit actions',
45
+ 'ledger.actionsHint': 'These buttons run the bundled CLI and write the ledger; the panel never writes on its own.',
46
+ 'ledger.lastAction': 'Last action',
47
+ 'meta.updated': 'Updated {time}',
48
+ 'meta.readonly': 'Read-only view: the panel never writes by itself; only the buttons above do.',
49
+ 'error.title': 'Cannot read the status',
50
+ 'error.hint': 'Check that the bundle is enabled and the aiprison CLI resolves for this platform.',
51
+ },
52
+ zh: {
53
+ 'panel.label': 'AI Prison',
54
+ 'page.title': 'AI Prison · AI 监狱',
55
+ 'page.subtitle': '面向 AI Agent 的分级能力剥夺与行为矫正;所有后端均为内存模拟。',
56
+ 'matrix.title': 'L0–L5 分级矩阵',
57
+ 'matrix.code': '级别',
58
+ 'matrix.name': '名称',
59
+ 'matrix.duration': '期限',
60
+ 'matrix.deprivations': '被剥夺的能力',
61
+ 'matrix.empty': 'CLI 未就绪,暂时无法读取矩阵。',
62
+ 'ledger.title': '审计链状态',
63
+ 'ledger.dir': '数据目录',
64
+ 'ledger.records': '记录数',
65
+ 'ledger.integrity': '完整性',
66
+ 'ledger.files': '文件数',
67
+ 'ledger.detail': '详情',
68
+ 'ledger.empty': '账本尚未初始化:运行 demo 或 drill 即可创建。',
69
+ 'integrity.ok': 'INTEGRITY OK',
70
+ 'integrity.failed': '校验失败',
71
+ 'integrity.none': '未初始化',
72
+ 'cli.found': 'aiprison {version}',
73
+ 'cli.missing': 'CLI 未找到',
74
+ 'cli.source': '来源',
75
+ 'action.refresh': '刷新',
76
+ 'action.loading': '读取中…',
77
+ 'action.runDemo': '运行 demo(创建账本)',
78
+ 'action.runDrill': '运行恢复演练',
79
+ 'action.running': '运行中…',
80
+ 'ledger.actions': '显式操作',
81
+ 'ledger.actionsHint': '这些按钮会运行内置 CLI 并写入账本;面板本身不会自动写入。',
82
+ 'ledger.lastAction': '最近操作',
83
+ 'meta.updated': '更新于 {time}',
84
+ 'meta.readonly': '只读视图:面板不会自行写入账本,只有上方按钮会写入。',
85
+ 'error.title': '无法读取状态',
86
+ 'error.hint': '请确认插件已启用,且本平台能解析到 aiprison CLI。',
87
+ },
88
+ }
89
+
90
+ const fallbackDict = String(navigator.language || '').toLowerCase().startsWith('zh') ? DICTS.zh : DICTS.en
91
+ let translate
92
+
93
+ function t(key, vars) {
94
+ let text = (typeof translate === 'function' ? translate(key) : undefined) || fallbackDict[key] || key
95
+ if (vars) {
96
+ for (const [name, value] of Object.entries(vars)) text = text.split(`{${name}}`).join(String(value))
97
+ }
98
+ return text
99
+ }
100
+
101
+ const C = {
102
+ page: { maxWidth: 980, margin: '0 auto', padding: '20px 24px 16px', color: 'var(--dsw-alias-label-primary, #0f1115)' },
103
+ header: { display: 'flex', alignItems: 'center', gap: 12, marginBottom: 14 },
104
+ title: { fontSize: 18, fontWeight: 600, margin: 0 },
105
+ sub: { fontSize: 12, color: 'var(--dsw-alias-label-secondary, #61666b)', margin: '3px 0 0' },
106
+ pill: {
107
+ marginLeft: 'auto',
108
+ display: 'inline-flex',
109
+ alignItems: 'center',
110
+ gap: 6,
111
+ fontSize: 12,
112
+ fontWeight: 500,
113
+ padding: '4px 10px',
114
+ borderRadius: 999,
115
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
116
+ whiteSpace: 'nowrap',
117
+ },
118
+ dot: { width: 8, height: 8, borderRadius: 999, display: 'inline-block' },
119
+ card: {
120
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
121
+ borderRadius: 12,
122
+ padding: 12,
123
+ marginBottom: 12,
124
+ background: 'var(--dsw-alias-bg-layer-1, transparent)',
125
+ },
126
+ cardHead: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8, fontSize: 13, fontWeight: 600 },
127
+ table: { width: '100%', borderCollapse: 'collapse', fontSize: 12.5 },
128
+ th: {
129
+ textAlign: 'left',
130
+ fontWeight: 500,
131
+ color: 'var(--dsw-alias-label-secondary, #61666b)',
132
+ padding: '6px 8px',
133
+ borderBottom: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
134
+ whiteSpace: 'nowrap',
135
+ },
136
+ td: {
137
+ padding: '7px 8px',
138
+ borderBottom: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,.06))',
139
+ verticalAlign: 'top',
140
+ },
141
+ mono: { fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 12 },
142
+ code: { fontWeight: 600, fontFamily: 'ui-monospace, Consolas, monospace' },
143
+ chips: { display: 'flex', flexWrap: 'wrap', gap: 4 },
144
+ chip: {
145
+ fontSize: 11.5,
146
+ padding: '1px 7px',
147
+ borderRadius: 999,
148
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.12))',
149
+ color: 'var(--dsw-alias-label-secondary, #61666b)',
150
+ whiteSpace: 'nowrap',
151
+ },
152
+ grid: { display: 'grid', gridTemplateColumns: 'minmax(110px, max-content) minmax(0, 1fr)', gap: '6px 14px', fontSize: 12.5 },
153
+ key: { color: 'var(--dsw-alias-label-secondary, #61666b)' },
154
+ muted: { color: 'var(--dsw-alias-label-secondary, #61666b)' },
155
+ btn: {
156
+ padding: '5px 10px',
157
+ borderRadius: 7,
158
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.16))',
159
+ background: 'transparent',
160
+ color: 'inherit',
161
+ cursor: 'pointer',
162
+ fontSize: 12,
163
+ marginLeft: 8,
164
+ },
165
+ error: { color: '#c81e1e' },
166
+ ok: { color: '#15803d' },
167
+ actionBtn: {
168
+ padding: '5px 12px',
169
+ borderRadius: 7,
170
+ border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.16))',
171
+ background: 'transparent',
172
+ color: 'inherit',
173
+ cursor: 'pointer',
174
+ fontSize: 12,
175
+ },
176
+ }
177
+
178
+ function PrisonIcon({ size = 36, active = true }) {
179
+ return h(
180
+ 'svg',
181
+ {
182
+ width: size,
183
+ height: size,
184
+ viewBox: '0 0 36 36',
185
+ role: 'img',
186
+ 'aria-hidden': true,
187
+ style: { display: 'block', opacity: active ? 1 : 0.75, flex: 'none' },
188
+ },
189
+ h('path', {
190
+ 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',
191
+ fill: 'none',
192
+ stroke: '#334155',
193
+ strokeWidth: 2.2,
194
+ strokeLinejoin: 'round',
195
+ }),
196
+ h('path', { d: 'M14 12.6v11.2M18 11.4v13.4M22 12.6v11.2', stroke: '#334155', strokeWidth: 2.2, strokeLinecap: 'round' }),
197
+ )
198
+ }
199
+
200
+ function Pill({ tone, text }) {
201
+ const color = tone === 'ok' ? C.ok.color : tone === 'error' ? C.error.color : C.muted.color
202
+ return h('span', { style: C.pill }, h('span', { style: { ...C.dot, background: color } }), h('span', null, text))
203
+ }
204
+
205
+ function fetchStatus() {
206
+ return fetch(new URL(STATUS_URL, document.baseURI), {
207
+ credentials: 'same-origin',
208
+ headers: { accept: 'application/json' },
209
+ }).then((response) => {
210
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
211
+ return response.json()
212
+ })
213
+ }
214
+
215
+ /** Run one explicit ledger action through the Host half. */
216
+ function postRun(action) {
217
+ return fetch(new URL(RUN_URL, document.baseURI), {
218
+ method: 'POST',
219
+ credentials: 'same-origin',
220
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
221
+ body: JSON.stringify({ action }),
222
+ }).then(async (response) => {
223
+ const payload = await response.json().catch(() => ({}))
224
+ if (!response.ok || payload.ok !== true) {
225
+ throw new Error(payload.error || payload.summary || `HTTP ${response.status}`)
226
+ }
227
+ return payload
228
+ })
229
+ }
230
+
231
+ function MatrixCard({ levels }) {
232
+ if (!Array.isArray(levels) || levels.length === 0) {
233
+ 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')))
234
+ }
235
+ return h(
236
+ 'section',
237
+ { style: C.card },
238
+ h('div', { style: C.cardHead }, t('matrix.title')),
239
+ h(
240
+ 'table',
241
+ { style: C.table },
242
+ 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')))),
243
+ h(
244
+ 'tbody',
245
+ null,
246
+ levels.map((level) =>
247
+ h(
248
+ 'tr',
249
+ { key: level.code },
250
+ h('td', { style: C.td }, h('span', { style: C.code }, level.code)),
251
+ h('td', { style: C.td }, level.name),
252
+ h('td', { style: C.td }, h('span', { title: level.durationHint || '' }, level.durationClass || '—')),
253
+ h(
254
+ 'td',
255
+ { style: C.td },
256
+ h('div', { style: C.chips }, (level.deprivations || []).map((item) => h('span', { key: item, style: C.chip }, item))),
257
+ ),
258
+ ),
259
+ ),
260
+ ),
261
+ ),
262
+ )
263
+ }
264
+
265
+ function LedgerCard({ ledger, cliFound, busy, onAction, lastResult }) {
266
+ const exists = Boolean(ledger && ledger.exists)
267
+ const integrityTone = !exists ? 'none' : ledger.integrity === 'ok' ? 'ok' : 'error'
268
+ const integrityText = !exists ? t('integrity.none') : ledger.integrity === 'ok' ? t('integrity.ok') : t('integrity.failed')
269
+ const entries = [
270
+ { key: 'dir', label: t('ledger.dir'), value: h('span', { style: { ...C.mono, wordBreak: 'break-all' } }, ledger?.dir || '—') },
271
+ { key: 'integrity', label: t('ledger.integrity'), value: h(Pill, { tone: integrityTone, text: integrityText }) },
272
+ ]
273
+ if (exists) {
274
+ entries.push({ key: 'records', label: t('ledger.records'), value: h('span', { style: C.mono }, String(ledger.records ?? '—')) })
275
+ entries.push({ key: 'files', label: t('ledger.files'), value: h('span', { style: C.mono }, String(ledger.files ?? '—')) })
276
+ }
277
+ if (exists && ledger.detail) {
278
+ entries.push({ key: 'detail', label: t('ledger.detail'), value: h('span', { style: { ...C.mono, wordBreak: 'break-word' } }, ledger.detail) })
279
+ }
280
+ const disabled = Boolean(busy) || !cliFound
281
+ return h(
282
+ 'section',
283
+ { style: C.card },
284
+ h('div', { style: C.cardHead }, t('ledger.title')),
285
+ h(
286
+ 'div',
287
+ { style: C.grid },
288
+ entries.flatMap((entry) => [
289
+ h('div', { key: `k-${entry.key}`, style: C.key }, entry.label),
290
+ h('div', { key: `v-${entry.key}` }, entry.value),
291
+ ]),
292
+ ),
293
+ !exists ? h('p', { style: { ...C.muted, fontSize: 12, margin: '8px 0 0' } }, t('ledger.empty')) : null,
294
+ h(
295
+ 'div',
296
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap', marginTop: 10 } },
297
+ h(
298
+ 'button',
299
+ { type: 'button', style: C.actionBtn, disabled, onClick: () => onAction('demo') },
300
+ busy === 'demo' ? t('action.running') : t('action.runDemo'),
301
+ ),
302
+ h(
303
+ 'button',
304
+ { type: 'button', style: C.actionBtn, disabled, onClick: () => onAction('drill') },
305
+ busy === 'drill' ? t('action.running') : t('action.runDrill'),
306
+ ),
307
+ h('span', { style: { ...C.muted, fontSize: 11.5 } }, t('ledger.actionsHint')),
308
+ ),
309
+ lastResult
310
+ ? h(
311
+ 'p',
312
+ {
313
+ style: {
314
+ ...C.mono,
315
+ fontSize: 11.5,
316
+ margin: '8px 0 0',
317
+ color: lastResult.ok ? C.ok.color : C.error.color,
318
+ wordBreak: 'break-word',
319
+ },
320
+ },
321
+ `${t('ledger.lastAction')}: ${lastResult.action} — ${lastResult.summary}`,
322
+ )
323
+ : null,
324
+ )
325
+ }
326
+
327
+ function PrisonPage() {
328
+ const [data, setData] = React.useState(null)
329
+ const [error, setError] = React.useState(null)
330
+ const [loading, setLoading] = React.useState(true)
331
+ const [updated, setUpdated] = React.useState(null)
332
+ const [busy, setBusy] = React.useState(null)
333
+ const [lastResult, setLastResult] = React.useState(null)
334
+
335
+ const load = React.useCallback(() => {
336
+ setLoading(true)
337
+ setError(null)
338
+ fetchStatus()
339
+ .then((payload) => {
340
+ setData(payload)
341
+ setUpdated(new Date())
342
+ setLoading(false)
343
+ })
344
+ .catch((cause) => {
345
+ setError(String((cause && cause.message) || cause))
346
+ setLoading(false)
347
+ })
348
+ }, [])
349
+
350
+ React.useEffect(() => {
351
+ load()
352
+ const timer = setInterval(load, 20000)
353
+ return () => clearInterval(timer)
354
+ }, [load])
355
+
356
+ const runAction = React.useCallback(
357
+ (action) => {
358
+ setBusy(action)
359
+ setLastResult(null)
360
+ postRun(action)
361
+ .then((payload) => {
362
+ setLastResult({ action, ok: true, summary: payload.summary || '' })
363
+ setBusy(null)
364
+ load()
365
+ })
366
+ .catch((cause) => {
367
+ setLastResult({ action, ok: false, summary: String((cause && cause.message) || cause) })
368
+ setBusy(null)
369
+ })
370
+ },
371
+ [load],
372
+ )
373
+
374
+ const cli = data?.cli
375
+ const cliText = cli && cli.found ? t('cli.found', { version: cli.version || '?' }) : t('cli.missing')
376
+ const timeText = updated ? updated.toLocaleTimeString() : ''
377
+
378
+ return h(
379
+ 'div',
380
+ { style: C.page },
381
+ h(
382
+ 'div',
383
+ { style: C.header },
384
+ h('span', { style: { display: 'inline-flex' } }, h(PrisonIcon, { size: 26, active: true })),
385
+ h('div', { style: { minWidth: 0 } }, h('h1', { style: C.title }, t('page.title')), h('p', { style: C.sub }, t('page.subtitle'))),
386
+ h(Pill, { tone: cli && cli.found ? 'ok' : 'error', text: cliText }),
387
+ h('button', { type: 'button', style: C.btn, onClick: load, disabled: loading }, loading ? t('action.loading') : t('action.refresh')),
388
+ ),
389
+ error
390
+ ? h(
391
+ 'section',
392
+ { style: C.card },
393
+ h('div', { style: { ...C.cardHead, ...C.error } }, t('error.title')),
394
+ h('p', { style: { ...C.mono, margin: 0 } }, error),
395
+ h('p', { style: { ...C.muted, fontSize: 12, margin: '8px 0 0' } }, t('error.hint')),
396
+ )
397
+ : null,
398
+ h(MatrixCard, { levels: data?.levels }),
399
+ h(LedgerCard, {
400
+ ledger: data?.ledger,
401
+ cliFound: Boolean(cli && cli.found),
402
+ busy,
403
+ onAction: runAction,
404
+ lastResult,
405
+ }),
406
+ h(
407
+ 'p',
408
+ { style: { ...C.muted, fontSize: 12, margin: '2px 0 0', display: 'flex', gap: 12, flexWrap: 'wrap' } },
409
+ h('span', null, t('meta.readonly')),
410
+ cli && cli.path ? h('span', { style: C.mono }, `${t('cli.source')}: ${cli.source} · ${cli.path}`) : null,
411
+ timeText ? h('span', null, t('meta.updated', { time: timeText })) : null,
412
+ ),
413
+ )
414
+ }
415
+
416
+ function apply(ctx) {
417
+ try {
418
+ if (ctx.locale) {
419
+ ctx.locale.register(NS, 'en', DICTS.en)
420
+ ctx.locale.register(NS, 'zh', DICTS.zh)
421
+ translate = ctx.locale.bind(NS)
422
+ } else if (typeof ctx.inject === 'function') {
423
+ ctx.inject(['locale'], (child) => {
424
+ child.locale.register(NS, 'en', DICTS.en)
425
+ child.locale.register(NS, 'zh', DICTS.zh)
426
+ translate = child.locale.bind(NS)
427
+ })
428
+ }
429
+ } catch (cause) {
430
+ console.warn('[ai-prison] locale registration failed', cause)
431
+ }
432
+ ctx.effect(
433
+ () =>
434
+ ctx.slots.inject('sidebar.panellist', () =>
435
+ ctx.slots.register({ name: 'sidebar.panellist', id: PANEL_ID, order: 2, label: () => t('panel.label') }, PrisonIcon),
436
+ ),
437
+ 'ai-prison: sidebar entry',
438
+ )
439
+ ctx.effect(
440
+ () => ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, PrisonPage)),
441
+ 'ai-prison: main panel',
442
+ )
443
+ }
444
+
445
+ return { inject: ['slots'], apply, PANEL_ID, NS }
446
+ },
447
+ })
@@ -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)