dsh-unslop 0.6.5 → 0.6.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 +58 -0
- package/README.md +31 -14
- package/README.zh-CN.md +31 -14
- package/client.js +17 -8
- package/dsh.plugin.json +2 -2
- package/host/index.js +161 -75
- package/host/session-state.js +117 -0
- package/package.json +3 -1
- package/tests/adversarial.mjs +22 -6
- package/tests/hosttest.mjs +77 -15
- package/tests/routetest.mjs +50 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project. Versions follow semver; the plugin ships as an npm bundle and as
|
|
4
|
+
a GitHub release, and both carry the same tag.
|
|
5
|
+
|
|
6
|
+
## [0.6.6] — 2026-12-06
|
|
7
|
+
|
|
8
|
+
### Changed — **behavioural, read before upgrading**
|
|
9
|
+
|
|
10
|
+
- **The design tier is per session.** It used to live in one global `design.json`, so switching it in
|
|
11
|
+
one conversation moved every other conversation with it. The tier is now stored per session in
|
|
12
|
+
`plugins-data/unslop/sessions.json`, and **the default is `off`**: a conversation that never switched
|
|
13
|
+
unslop on resolves to an empty tool set — neither `mcp__unslop__*` nor the six host tools enter its
|
|
14
|
+
schema, and a call fails as an unknown tool.
|
|
15
|
+
- **After upgrading, open the composer chip once per conversation** and pick 原版 unslop or MD3E.
|
|
16
|
+
Nothing breaks if you do not; the session simply has no unslop tools. This is the one migration
|
|
17
|
+
step, and it is deliberate: a global default would have kept leaking unslop into unrelated work.
|
|
18
|
+
- `unslop_mode {mode:"off"}` no longer takes the global tool surface down with it. The surface
|
|
19
|
+
(`all` / `core` / `off`) is a context-budget switch and stays global; whether a tool exists at all is
|
|
20
|
+
now decided per session.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- `host/session-state.js` — the per-session tier store. `off` is stored as the absence of a record, so
|
|
25
|
+
a profile that never used the feature has no file and the default cannot be ambiguous. Reads always
|
|
26
|
+
hit disk: the gate runs at every step admission, and a cache would delay a switch to the next process
|
|
27
|
+
event.
|
|
28
|
+
- Every tool registration carries a `when` gate (`ctx.tools.register(def, { when })`), so admission is
|
|
29
|
+
re-resolved per step without re-registering anything — a tier switch cannot race a running step.
|
|
30
|
+
- The skill preamble now starts with **STEP 0**: if the unslop tools are absent from the session's tool
|
|
31
|
+
list, the session is off — do not read references, do not plan design work, ask the user to switch
|
|
32
|
+
the tier on. `MODE.md` says it is a hint, not authority.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- README facts now match the code: the "bold but systemless" fixture scores **24**, not 4;
|
|
37
|
+
`story-path.mjs` is **26** lines, not 27; md3e chapters run **70–950 tokens**, not 50–270; the
|
|
38
|
+
compatibility table lists the running **0.2.2-rc.5**; `sessions.json` is documented with its full
|
|
39
|
+
path; the install section says the package has to land in the **profile's** `node_modules`, and that
|
|
40
|
+
the tier has to be switched on before asking for work.
|
|
41
|
+
- The English and Chinese READMEs are back in step (the English tier row was missing "per session").
|
|
42
|
+
|
|
43
|
+
### Tests
|
|
44
|
+
|
|
45
|
+
`npm test` — **227 assertions, 0 failures** (was 196). The 31 new ones cover: a fresh session admits
|
|
46
|
+
nothing, enabling session A leaves session B off, switching A off leaves B alone, the surface tiers
|
|
47
|
+
still filter `admitted` globally, and the installed skill carries the STEP 0 guard.
|
|
48
|
+
|
|
49
|
+
## Earlier releases
|
|
50
|
+
|
|
51
|
+
| Tag | Date | Summary |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| v0.6.5 | 2026-12-03 | Keep unslop on the remediation side of the line |
|
|
54
|
+
| v0.6.4 | 2026-12-01 | Make the expressiveness checks a ceiling, not a checklist |
|
|
55
|
+
| v0.6.3 | 2026-11-30 | Stop hardcoding the reported version |
|
|
56
|
+
| v0.6.2 | 2026-11-30 | Give the shape library a real vocabulary |
|
|
57
|
+
| v0.6.1 | 2026-11-30 | Surface the seed tint that makes a compliant palette glare |
|
|
58
|
+
| v0.6.0 | 2026-11-30 | Distinguish M3E from compliant-but-quiet M3 |
|
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
**English** · [简体中文](README.zh-CN.md)
|
|
6
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/dsh-unslop) [](./LICENSE)
|
|
8
|
+
|
|
7
9
|
Brings [heydamir/unslop](https://github.com/heydamir/unslop) into DeepSeek Harness, and adds Google's **Material 3 Expressive** alongside it. unslop is a skill that turns a "vibecoded, obviously AI" interface into a designed one: it audits the slop (purple gradients, glows, emoji labels, "New ✨" badges, arbitrary spacing), derives a direction from the product itself, then fixes it layer by layer in nine passes. This project packages it as a **standalone, host-agnostic MCP server** with a thin dsh plugin bridging it in.
|
|
8
10
|
|
|
9
11
|
## What it solves
|
|
@@ -28,10 +30,21 @@ The plugin gives an agent two things:
|
|
|
28
30
|
| Capture a live page | `unslop_snapshot` saves a self-contained HTML copy plus a screenshot, so a bare URL is enough |
|
|
29
31
|
| Render-level check | `render:true` measures overflow, contrast, font size and tap targets |
|
|
30
32
|
| Story video | `unslop_story` renders a 10-second "interface unslopping itself" video with ffmpeg |
|
|
31
|
-
| Three tiers | Off / original unslop / MD3E, switched from the composer chip, applied immediately |
|
|
33
|
+
| Three tiers | Off / original unslop / MD3E, **per session**: switched from the composer chip, applied immediately |
|
|
32
34
|
|
|
33
35
|
## Install
|
|
34
36
|
|
|
37
|
+
The bundle row is resolved from the **profile's** `node_modules`, so install into the profile (or let the plugin manager do it) — a copy sitting in some unrelated project never loads:
|
|
38
|
+
|
|
39
|
+
```powershell
|
|
40
|
+
cd $env:USERPROFILE\.dsh\profiles\<profile>
|
|
41
|
+
npm install dsh-unslop
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then add `dsh-unslop` to `dsh.profile.bundles` in that profile's `package.json` and restart the Harness.
|
|
45
|
+
|
|
46
|
+
From a checkout instead:
|
|
47
|
+
|
|
35
48
|
```powershell
|
|
36
49
|
pwsh -File .\install.ps1 -DryRun # see which files would change
|
|
37
50
|
pwsh -File .\install.ps1 # copy into the profile, register the bundle
|
|
@@ -43,7 +56,9 @@ Or by hand:
|
|
|
43
56
|
2. Add `dsh-unslop` to `dsh.profile.bundles` in that profile's `package.json`;
|
|
44
57
|
3. Restart the Harness.
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
No separate runtime: it runs on the Node the Harness already uses (verified on Node 24).
|
|
60
|
+
|
|
61
|
+
Then **turn the tier on** — click the chip left of the composer and pick 原版 unslop or MD3E. A session starts with every unslop tool gated off, so nothing appears until you do that in that conversation. Then ask:
|
|
47
62
|
|
|
48
63
|
```
|
|
49
64
|
unslop this page for me
|
|
@@ -54,17 +69,17 @@ unslop this page for me
|
|
|
54
69
|
- `unslop_snapshot` needs Playwright + Chromium; `unslop_story` needs ffmpeg.
|
|
55
70
|
- The core audit workflow **works without either**. `unslop_status` reports what is missing, and `unslop_deps {install:true}` runs `npm install -D playwright` and `npx playwright install chromium`.
|
|
56
71
|
|
|
57
|
-
## Design tiers: Off / unslop / MD3E
|
|
72
|
+
## Design tiers: Off / unslop / MD3E — per session
|
|
58
73
|
|
|
59
|
-
A chip to the left of the composer (`● unslop MD3E 4/4 ▾`) switches the **design language**.
|
|
74
|
+
A chip to the left of the composer (`● unslop MD3E 4/4 ▾`) switches the **design language of the conversation you are in**. Inside a session you can also call `unslop_mode {mode:"md3e"}` directly.
|
|
60
75
|
|
|
61
76
|
| Tier | Behaviour |
|
|
62
77
|
|---|---|
|
|
63
|
-
| **Off** | No design guidance, and
|
|
64
|
-
| **Original unslop**
|
|
78
|
+
| **Off** (default) | No design guidance, and this session sees no unslop tool at all |
|
|
79
|
+
| **Original unslop** | The original method: audit → direction → nine passes |
|
|
65
80
|
| **MD3E** | **Material 3 Expressive**: all nine md3e references |
|
|
66
81
|
|
|
67
|
-
Switching takes effect **immediately, no restart
|
|
82
|
+
**The tier belongs to one session.** A session that never switched unslop on resolves to an empty tool set: neither `mcp__unslop__*` nor the six host tools enter its schema, and a call fails as an unknown tool. Nothing leaks into another conversation's tool list or context. Because every tool is gated, a session that is off has nothing left to call — the chip is the way in. Switching takes effect **immediately, no restart**: the tier is written to `<DSH_HOME>/plugins-data/unslop/sessions.json`, the skill's `MODE.md` records the most recent activation, and the tool set is re-resolved on the next step.
|
|
68
83
|
|
|
69
84
|
> The `4/4` on the chip is the **tool** count (list references / read / snapshot / video). The MD3E material does not occupy tool slots — it is markdown on disk, loaded on demand by `unslop_read`. Four tools, unbounded content.
|
|
70
85
|
|
|
@@ -72,7 +87,7 @@ Switching takes effect **immediately, no restart** — it writes `design.json` a
|
|
|
72
87
|
|
|
73
88
|
`md3e-overview` (the token-system idea and the expressive-vs-slop line), `md3e-color` (13 tones, roles, light/dark mapping), `md3e-typography` (15 roles plus emphasized variants), `md3e-shape` (radius scale and morphing), `md3e-motion` (spring tokens and CSS fallbacks), `md3e-components` (buttons, FAB, cards, chips, navigation, lists, dialogs), `md3e-layout` (window size classes, grid, elevation, dark theme), `md3e-audit` (the pass/fail checklist), `md3e-new` (the build order, kept as a reference).
|
|
74
89
|
|
|
75
|
-
**Chapter-level reading.** The nine documents total roughly 12.6k tokens, which is too much to read whole. List the outline, then read only the chapter you need
|
|
90
|
+
**Chapter-level reading.** The nine documents total roughly 12.6k tokens, which is too much to read whole. List the outline, then read only the chapter you need — most chapters land between 70 and 370 tokens; the two big outliers are `08-new-work`'s at ~950 and the audit's G section at ~750:
|
|
76
91
|
|
|
77
92
|
```
|
|
78
93
|
unslop_read {"name":"md3e-typography","outline":true} # chapters and their cost
|
|
@@ -91,7 +106,7 @@ unslop_read {"name":"md3e-typography","section":"15 roles"} # just that chapt
|
|
|
91
106
|
| Banned tells | Hue-to-hue gradients, coloured glows, ALL CAPS labels, emoji as icons, full-radius cards |
|
|
92
107
|
| Expressiveness (section G) | At least one accent doing a named job, spring motion on state change, every non-rectangular shape naming what it replaced, accent area kept tiny — a **compliant M3 page is not M3E**, but G is a ceiling, not a checklist: one accent and no stagger are complete answers |
|
|
93
108
|
|
|
94
|
-
Measured discrimination: **a page actually built on M3E scores 100; one that merely looks bold (gradients, glows, 900 weights, a screenful of pills, no system behind it) scores
|
|
109
|
+
Measured discrimination, on the fixtures the test suite ships: **a page actually built on M3E scores 100; one that merely looks bold (gradients, glows, 900 weights, a screenful of pills, no system behind it) scores 24.**
|
|
95
110
|
|
|
96
111
|
## Theme generation `unslop_theme`
|
|
97
112
|
|
|
@@ -139,13 +154,14 @@ Targets the DSH **0.2.2 series** (`engines.dsh: >=0.2.2-rc.1`):
|
|
|
139
154
|
|---|---|---|
|
|
140
155
|
| `0.2.2-rc.1` | Windows | ✅ Tested on this machine (host + MCP + skill + chip) |
|
|
141
156
|
| `0.2.2-rc.3` | Windows | ✅ End-to-end (host + MCP + skill + chip) |
|
|
157
|
+
| `0.2.2-rc.5` | Windows | ✅ Current: host + MCP + skill + chip, per-session tiers |
|
|
142
158
|
|
|
143
159
|
After a DSH upgrade, run `npm test` first, then `unslop_status`.
|
|
144
160
|
|
|
145
161
|
## Tests
|
|
146
162
|
|
|
147
163
|
```powershell
|
|
148
|
-
npm test # no Harness needed: runs against a stub ctx (
|
|
164
|
+
npm test # no Harness needed: runs against a stub ctx (227 assertions)
|
|
149
165
|
```
|
|
150
166
|
|
|
151
167
|
## Security
|
|
@@ -172,14 +188,15 @@ dsh-unslop/
|
|
|
172
188
|
├─ dsh.plugin.json plugin manifest (contributes.tools / mcp / skills)
|
|
173
189
|
├─ package.json exports host/client/mcp; bundle → cordis.patch.yml
|
|
174
190
|
├─ cordis.patch.yml inserts one host row (id: unslop-host)
|
|
175
|
-
├─ client.js composer design-tier chip (Off / unslop / MD3E)
|
|
191
|
+
├─ client.js composer design-tier chip (Off / unslop / MD3E, per session)
|
|
176
192
|
├─ host/
|
|
177
193
|
│ ├─ index.js apply(ctx,config): MCP client, tool surface, tiers, /unslop/api routes
|
|
178
194
|
│ ├─ mcp-client.js zero-dependency stdio MCP client
|
|
179
|
-
│
|
|
195
|
+
│ ├─ http-util.js Bearer + loopback fence
|
|
196
|
+
│ └─ session-state.js per-session tier store (sessions.json, off by default)
|
|
180
197
|
├─ mcp/
|
|
181
198
|
│ ├─ server.mjs ★ standalone MCP server (any MCP host can connect)
|
|
182
|
-
│ ├─ detect.mjs offline deterministic slop detector (
|
|
199
|
+
│ ├─ detect.mjs offline deterministic slop detector (26 rules + saturating score)
|
|
183
200
|
│ ├─ theme.mjs seed colour → M3/M3E palette (pure module, portable)
|
|
184
201
|
│ └─ render-check.mjs Playwright render-level QA
|
|
185
202
|
├─ vendor/ vendored Google colour algorithms (Apache-2.0)
|
|
@@ -226,7 +243,7 @@ The plugin relies on DSH internals: `ctx.tools.register`, `ctx.inject(['webServe
|
|
|
226
243
|
|
|
227
244
|
**`scripts/story-path.mjs` — the only path funnel**
|
|
228
245
|
|
|
229
|
-
|
|
246
|
+
26 lines, and **none of it is simplifiable**:
|
|
230
247
|
|
|
231
248
|
- After `normalize(join(root, path))`, **both root and target must be `realpathSync`'d** before the `relative` check.
|
|
232
249
|
- A bare `startsWith(root)` has two holes: `/a/site-private` passes a `/a/site` prefix test, and a symlink inside root can point outside.
|
package/README.zh-CN.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[English](README.md) · **简体中文**
|
|
6
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/dsh-unslop) [](./LICENSE)
|
|
8
|
+
|
|
7
9
|
把 [heydamir/unslop](https://github.com/heydamir/unslop) 接进 DeepSeek Harness,并额外并入 Google 的 **Material 3 Expressive**。unslop 是一个把「vibecoded、一眼 AI 味」的界面改造成有设计感的界面的技能:先审计 slop(紫色渐变、发光、emoji 标签、"New ✨" 徽章、乱间距),再从产品本身定方向,按九个 pass 逐层重排。本项目把它做成一个**独立、与宿主无关的 MCP server**,再用一层很薄的 dsh 插件把它桥进来。
|
|
8
10
|
|
|
9
11
|
## 它解决什么问题
|
|
@@ -28,10 +30,21 @@ AI 生成的界面有固定的一批毛病:紫→蓝渐变、彩色发光、em
|
|
|
28
30
|
| 抓取线上页面 | `unslop_snapshot` 用 Playwright 存自包含 HTML + 截图(只有链接也能改) |
|
|
29
31
|
| 渲染级验收 | `render:true` 实测溢出/对比度/字号/触控目标 |
|
|
30
32
|
| 故事视频 | `unslop_story` 用 ffmpeg 生成"界面自己变好看"的 10 秒视频 |
|
|
31
|
-
| 三种档位 | 关闭 / 原版 unslop / MD3E
|
|
33
|
+
| 三种档位 | 关闭 / 原版 unslop / MD3E,按会话生效:chip 一键切,只影响当前会话 |
|
|
32
34
|
|
|
33
35
|
## 安装
|
|
34
36
|
|
|
37
|
+
bundle 行是从 **profile 的** `node_modules` 解析的,所以要装进 profile(或直接用插件管理器)——装到别的项目目录里永远不会被加载:
|
|
38
|
+
|
|
39
|
+
```powershell
|
|
40
|
+
cd $env:USERPROFILE\.dsh\profiles\<profile>
|
|
41
|
+
npm install dsh-unslop
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
再把 `dsh-unslop` 加进该 profile 的 `dsh.profile.bundles`,重启 Harness。
|
|
45
|
+
|
|
46
|
+
从仓库检出安装:
|
|
47
|
+
|
|
35
48
|
```powershell
|
|
36
49
|
pwsh -File .\install.ps1 -DryRun # 先看会改哪些文件
|
|
37
50
|
pwsh -File .\install.ps1 # 复制进 profile、登记 bundle
|
|
@@ -43,7 +56,9 @@ pwsh -File .\install.ps1 # 复制进 profile、登记 bundle
|
|
|
43
56
|
2. 在 profile 的 `package.json` 里把 `dsh-unslop` 加进 `dsh.profile.bundles`;
|
|
44
57
|
3. 重启 Harness。
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
不需要单独装运行时:它跑在 Harness 自带的 Node 上(本机 Node 24 实测)。
|
|
60
|
+
|
|
61
|
+
然后**先开档位**——点输入框左侧的 chip,选「原版」或「MD3E」。新会话默认所有 unslop 工具都被门禁挡着,不在那个会话里切一次就什么都看不到。然后再对 agent 说:
|
|
47
62
|
|
|
48
63
|
```
|
|
49
64
|
帮我把这个页面 unslop 一下
|
|
@@ -54,17 +69,17 @@ pwsh -File .\install.ps1 # 复制进 profile、登记 bundle
|
|
|
54
69
|
- `unslop_snapshot` 需要 Playwright + Chromium;`unslop_story` 需要 ffmpeg。
|
|
55
70
|
- 两者**不装也能用**核心审计流程;缺时 `unslop_status` 会标出来,`unslop_deps {install:true}` 会跑 `npm install -D playwright` + `npx playwright install chromium`。
|
|
56
71
|
|
|
57
|
-
## 设计档位:关闭 / 原版 unslop / MD3E
|
|
72
|
+
## 设计档位:关闭 / 原版 unslop / MD3E(按会话)
|
|
58
73
|
|
|
59
|
-
输入框左侧有一个 chip(`● unslop MD3E 4/4
|
|
74
|
+
输入框左侧有一个 chip(`● unslop MD3E 4/4 ▾`),点开切换**当前这个会话**的设计语言。会话内也可以直接调 `unslop_mode {mode:"md3e"}`。
|
|
60
75
|
|
|
61
76
|
| 档位 | 行为 |
|
|
62
77
|
|---|---|
|
|
63
|
-
|
|
|
64
|
-
| **原版 unslop
|
|
78
|
+
| **关闭**(默认) | 不套用任何设计语言,且本会话根本看不到 unslop 工具 |
|
|
79
|
+
| **原版 unslop** | 原始 unslop 方法:审计 → 定方向 → 九个 pass |
|
|
65
80
|
| **MD3E** | **Material 3 Expressive**:完整的 9 篇 md3e 参考 |
|
|
66
81
|
|
|
67
|
-
|
|
82
|
+
**档位属于单个会话。** 没开启过的会话解析出来是空工具集:`mcp__unslop__*` 与六个 host 工具都不进它的 schema,调用会按未知工具失败,也不会污染别的会话的工具列表和上下文。因为每个工具都带会话门禁,关闭态的会话里没有任何 unslop 工具可调——入口只有 chip。切换**立即生效、无需重启**:档位写进 `<DSH_HOME>/plugins-data/unslop/sessions.json`,skill 的 `MODE.md` 只记录最近一次激活,工具集在下一步重新解析。
|
|
68
83
|
|
|
69
84
|
> chip 上的 `4/4` 是**工具**数量(查参考 / 读文档 / 截图 / 视频)。MD3E 的细则不占工具位——它们是磁盘上的 markdown,由 `unslop_read` 按需加载,所以工具只有 4 个,内容可以无限扩。
|
|
70
85
|
|
|
@@ -72,7 +87,7 @@ pwsh -File .\install.ps1 # 复制进 profile、登记 bundle
|
|
|
72
87
|
|
|
73
88
|
`md3e-overview`(总览与"表达 vs slop"边界)、`md3e-color`(13 音阶 / 语义色 / 明暗映射)、`md3e-typography`(15 个字号档位 + 强调变体)、`md3e-shape`(圆角尺度 + 形变)、`md3e-motion`(弹性动效 + CSS 回退)、`md3e-components`(按钮/FAB/卡片/chip/导航/列表/对话框等)、`md3e-layout`(窗口尺寸类 / 网格 / 层级 / 深色)、`md3e-audit`(逐 pass 检查表 + 表达-vs-slop 三问)、`md3e-new`(从零新建的七步工序,仅作参考)。
|
|
74
89
|
|
|
75
|
-
**按章读取**:9 篇合计约 12.6k tokens
|
|
90
|
+
**按章读取**:9 篇合计约 12.6k tokens,全读太贵。先看目录再只读需要的那一章(多数章节 70–370 tok;最大的两处是 `08-new-work` 的约 950 与审计 G 组的约 750):
|
|
76
91
|
|
|
77
92
|
```
|
|
78
93
|
unslop_read {"name":"md3e-typography","outline":true} # 列出章节 + 每章 token 估算
|
|
@@ -91,7 +106,7 @@ unslop_read {"name":"md3e-typography","section":"15 roles"} # 只读这一章
|
|
|
91
106
|
| 禁用项 | 跨色相渐变、彩色发光、全大写标签、emoji 当图标、卡片误用全圆 |
|
|
92
107
|
| 表达力(G 组) | 一个强调色承担点得出的职责、动效发生在状态变化、每个非矩形轮廓都答得出它替掉了什么、强调色面积要小——**合规的 M3 不等于 M3E**;但 G 组是上限不是清单:只用一族强调、不做错峰,都是完整答案 |
|
|
93
108
|
|
|
94
|
-
|
|
109
|
+
实测鉴别力(用的是测试套件里那对 fixture):**真按 M3E 做的页面 100 分;只是"看起来大胆"(渐变+发光+900 字重+满屏胶囊,但没有体系)24 分。**
|
|
95
110
|
|
|
96
111
|
## 主题生成 `unslop_theme`
|
|
97
112
|
|
|
@@ -139,13 +154,14 @@ unslop_detect {path:".", action:"compare"} # 出 Δ 分(例如 +44)
|
|
|
139
154
|
|---|---|---|
|
|
140
155
|
| `0.2.2-rc.1` | Windows | ✅ 本机实测(Host + MCP + skill + chip) |
|
|
141
156
|
| `0.2.2-rc.3` | Windows | ✅ 端到端验证(Host + MCP + skill + chip) |
|
|
157
|
+
| `0.2.2-rc.5` | Windows | ✅ 当前版本:Host + MCP + skill + chip,按会话档位 |
|
|
142
158
|
|
|
143
159
|
DSH 升级后先跑 `npm test`,再看 `unslop_status`。
|
|
144
160
|
|
|
145
161
|
## 测试
|
|
146
162
|
|
|
147
163
|
```powershell
|
|
148
|
-
npm test # 不装 Harness,用桩 ctx 跑全套(
|
|
164
|
+
npm test # 不装 Harness,用桩 ctx 跑全套(227 断言)
|
|
149
165
|
```
|
|
150
166
|
|
|
151
167
|
## 安全
|
|
@@ -172,14 +188,15 @@ dsh-unslop/
|
|
|
172
188
|
├─ dsh.plugin.json 插件清单(contributes.tools / mcp / skills)
|
|
173
189
|
├─ package.json exports host/client/mcp;bundle→cordis.patch.yml
|
|
174
190
|
├─ cordis.patch.yml 插入一行 host 半(id: unslop-host)
|
|
175
|
-
├─ client.js 输入框设计档位 chip(关闭 / 原版 / MD3E
|
|
191
|
+
├─ client.js 输入框设计档位 chip(关闭 / 原版 / MD3E,按会话)
|
|
176
192
|
├─ host/
|
|
177
193
|
│ ├─ index.js apply(ctx,config):MCP client、工具面、设计档位、/unslop/api 路由
|
|
178
194
|
│ ├─ mcp-client.js 零依赖 stdio MCP 客户端
|
|
179
|
-
│
|
|
195
|
+
│ ├─ http-util.js Bearer + loopback 围栏
|
|
196
|
+
│ └─ session-state.js 按会话的档位存储(sessions.json,缺省 off)
|
|
180
197
|
├─ mcp/
|
|
181
198
|
│ ├─ server.mjs ★ 独立 MCP server(任何 MCP 宿主都能直连)
|
|
182
|
-
│ ├─ detect.mjs 离线确定性 slop
|
|
199
|
+
│ ├─ detect.mjs 离线确定性 slop 检测(26 条规则 + 饱和评分)
|
|
183
200
|
│ ├─ theme.mjs 种子色 → M3/M3E 色板(纯模块,可独立搬走)
|
|
184
201
|
│ └─ render-check.mjs Playwright 渲染级 QA
|
|
185
202
|
├─ vendor/ vendored 的 Google 官方色彩算法(Apache-2.0)
|
|
@@ -226,7 +243,7 @@ dsh-unslop/
|
|
|
226
243
|
|
|
227
244
|
**`scripts/story-path.mjs` — 路径收敛(唯一安全入口)**
|
|
228
245
|
|
|
229
|
-
|
|
246
|
+
26 行,但**不能简化**:
|
|
230
247
|
|
|
231
248
|
- `normalize(join(root, path))` 之后,必须对 **root 和 target 都 `realpathSync`** 再 `relative` 校验。
|
|
232
249
|
- 裸 `startsWith(root)` 有两个洞:`/a/site-private` 会被 `/a/site` 前缀骗过;root 内的符号链接可以指向外部。
|
package/client.js
CHANGED
|
@@ -18,6 +18,12 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
const TOKEN_ROUTE = '/unslop/api/token'
|
|
19
19
|
const MODE_ROUTE = '/unslop/api/mode'
|
|
20
20
|
|
|
21
|
+
// The tier belongs to one session, so every call names it. The slot hands the chip a `sessionId`
|
|
22
|
+
// standard prop; without one there is nothing to read or switch.
|
|
23
|
+
const withSession = (pathname, sessionId) => (
|
|
24
|
+
sessionId ? `${pathname}?sessionId=${encodeURIComponent(String(sessionId))}` : pathname
|
|
25
|
+
)
|
|
26
|
+
|
|
21
27
|
let tokenPromise = null
|
|
22
28
|
function fetchToken() {
|
|
23
29
|
if (!tokenPromise) {
|
|
@@ -58,34 +64,37 @@ window.__ModuleLoader__.load({
|
|
|
58
64
|
md3e: 'MD3E:Material 3 Expressive(色板角色 / 15 个字体角色 / 形状尺度 / 弹簧动效 / 组件 / 布局)',
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
function Chip() {
|
|
62
|
-
try { return ChipInner() } catch (error) {
|
|
67
|
+
function Chip(props) {
|
|
68
|
+
try { return ChipInner(props || {}) } catch (error) {
|
|
63
69
|
return h('span', { style: { fontSize: '11px', color: '#e06060' } }, 'unslop: ' + String(error && error.message ? error.message : error))
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
function ChipInner() {
|
|
73
|
+
function ChipInner({ sessionId }) {
|
|
68
74
|
const [state, setState] = React.useState(null)
|
|
69
75
|
const [open, setOpen] = React.useState(false)
|
|
70
76
|
const load = React.useCallback(() => {
|
|
71
|
-
getJson(MODE_ROUTE).then(setState).catch(() => setState({ mode: 'unknown' }))
|
|
72
|
-
}, [])
|
|
77
|
+
getJson(withSession(MODE_ROUTE, sessionId)).then(setState).catch(() => setState({ mode: 'unknown' }))
|
|
78
|
+
}, [sessionId])
|
|
73
79
|
React.useEffect(() => {
|
|
74
80
|
load()
|
|
75
81
|
const timer = setInterval(load, 20_000)
|
|
76
82
|
return () => clearInterval(timer)
|
|
77
83
|
}, [load])
|
|
78
|
-
const mode = state && state.mode ? state.mode : '
|
|
84
|
+
const mode = state && state.mode ? state.mode : 'off'
|
|
79
85
|
const tools = state && (state.mcpTools || state.mcp) ? (state.mcpTools || state.mcp) : null
|
|
80
86
|
const pick = (tier) => {
|
|
81
87
|
setOpen(false)
|
|
82
|
-
postJson(MODE_ROUTE, { mode: tier }).then(setState).catch(() => {
|
|
88
|
+
postJson(MODE_ROUTE, { mode: tier, sessionId }).then(setState).catch(() => {
|
|
89
|
+
// A switch without a session cannot persist; show the truth instead of pretending.
|
|
90
|
+
load()
|
|
91
|
+
})
|
|
83
92
|
}
|
|
84
93
|
return h('div', { className: 'dsh-us-chip-wrap' },
|
|
85
94
|
h('button', {
|
|
86
95
|
type: 'button',
|
|
87
96
|
className: `dsh-us-chip${mode === 'off' ? ' is-off' : mode === 'md3e' ? ' is-md3e' : ' is-on'}${open ? ' is-open' : ''}`,
|
|
88
|
-
title: TITLES[mode] || 'unslop
|
|
97
|
+
title: TITLES[mode] || 'unslop 设计档位(按会话)',
|
|
89
98
|
onClick: () => setOpen((value) => !value),
|
|
90
99
|
},
|
|
91
100
|
h('span', { className: 'dsh-us-dot', 'aria-hidden': 'true' }),
|
package/dsh.plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-unslop",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"description": "unslop (github.com/heydamir/unslop) for DeepSeek Harness: a standalone MCP server that turns vibecoded, AI-looking UI into a designed interface. Exposes unslop_references / unslop_read / unslop_snapshot / unslop_story as mcp__unslop__* tools, plus unslop_status / unslop_deps, and installs the unslop workflow skill. Vendored under CC BY 4.0 with credit to Damir Sokolovsky (@heydamir).",
|
|
3
|
+
"version": "0.6.6",
|
|
4
|
+
"description": "unslop (github.com/heydamir/unslop) for DeepSeek Harness: a standalone MCP server that turns vibecoded, AI-looking UI into a designed interface. Exposes unslop_references / unslop_read / unslop_snapshot / unslop_story as mcp__unslop__* tools, plus unslop_status / unslop_deps, and installs the unslop workflow skill. The design tier is per session: a conversation that never switched it on sees no unslop tool at all. Vendored under CC BY 4.0 with credit to Damir Sokolovsky (@heydamir).",
|
|
5
5
|
"engines": {
|
|
6
6
|
"dsh": ">=0.2.2-rc.1"
|
|
7
7
|
},
|
package/host/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import os from 'node:os'
|
|
|
23
23
|
import path from 'node:path'
|
|
24
24
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
25
25
|
import { createUnslopClient } from './mcp-client.js'
|
|
26
|
+
import { createSessionStore, MODES as SESSION_MODES } from './session-state.js'
|
|
26
27
|
import { createHttpAuth, guarded, readJsonBody, sendJson } from './http-util.js'
|
|
27
28
|
import { scanPath, normalizeImpeccable, scoreItems } from '../mcp/detect.mjs'
|
|
28
29
|
|
|
@@ -42,40 +43,65 @@ const INSTALL_ROOT = path.join(DSH_HOME, 'plugins-data', 'unslop')
|
|
|
42
43
|
const BRIDGE_FILE = path.join(INSTALL_ROOT, 'bridge.json')
|
|
43
44
|
const TOKEN_FILE = path.join(INSTALL_ROOT, 'http.token')
|
|
44
45
|
const BASELINE_FILE = path.join(INSTALL_ROOT, 'detect-baseline.json')
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
// Per-session tiers live here. design.json from 0.6.x is deliberately ignored: it encoded a global
|
|
47
|
+
// tier, and honouring it would re-enable unslop in every conversation at once.
|
|
48
|
+
const SESSIONS_FILE = path.join(INSTALL_ROOT, 'sessions.json')
|
|
49
|
+
const sessions = createSessionStore(SESSIONS_FILE)
|
|
50
|
+
|
|
51
|
+
// Design language tiers, per session. `off` means the session sees no unslop tool at all; `unslop`
|
|
52
|
+
// and `md3e` admit every tool and only change which reference set the skill follows.
|
|
53
|
+
export const DESIGN_MODES = SESSION_MODES
|
|
50
54
|
const DESIGN_LABEL = { off: '关闭', unslop: '原版 unslop', md3e: 'Material 3 Expressive' }
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
// The session id an execution belongs to. Tools resolve it from the calling agent; HTTP routes take
|
|
57
|
+
// it from the query string or the body, because a route has no agent.
|
|
58
|
+
export function sessionIdOf(exec) {
|
|
59
|
+
const direct = exec && exec.agent && typeof exec.agent.id === 'string' ? exec.agent.id : null
|
|
60
|
+
if (direct) return direct
|
|
61
|
+
const nested = exec && exec.agent && exec.agent.session && typeof exec.agent.session.id === 'string' ? exec.agent.session.id : null
|
|
62
|
+
return nested
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
function readDesignMode(sessionId) {
|
|
66
|
+
const record = sessions.describe(sessionId)
|
|
67
|
+
return {
|
|
68
|
+
sessionId: record.sessionId,
|
|
69
|
+
mode: record.mode,
|
|
70
|
+
label: DESIGN_LABEL[record.mode],
|
|
71
|
+
enabled: record.enabled,
|
|
72
|
+
updatedAt: record.updatedAt,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function writeDesignMode(mode, sessionId) {
|
|
77
|
+
const record = sessions.set(sessionId, mode)
|
|
78
|
+
return {
|
|
79
|
+
sessionId: record.sessionId,
|
|
80
|
+
mode: record.mode,
|
|
81
|
+
label: DESIGN_LABEL[record.mode],
|
|
82
|
+
enabled: record.enabled,
|
|
83
|
+
updatedAt: record.updatedAt,
|
|
84
|
+
}
|
|
64
85
|
}
|
|
65
86
|
|
|
87
|
+
// The gate every tool registration carries. A session that never enabled unslop resolves to an empty
|
|
88
|
+
// tool set for that step, which is what "registered only in the sessions that turned it on" means.
|
|
89
|
+
const designGate = (sessionId) => sessions.isEnabled(sessionId)
|
|
90
|
+
|
|
66
91
|
// The skill is static text, so the active language is materialised next to it as MODE.md. The SKILL.md
|
|
67
92
|
// preamble tells the model to read it first, which makes a mode switch a one-file rewrite (no reinstall).
|
|
68
93
|
function writeSkillMode(mode) {
|
|
69
94
|
const body = [
|
|
70
|
-
`#
|
|
95
|
+
`# Design language (last activated in this profile): ${mode} (${DESIGN_LABEL[mode]})`,
|
|
71
96
|
'',
|
|
97
|
+
'This file is a hint, not authority: the tier belongs to one session. If the unslop tools are absent from your tool list, this session is off — ignore this file and stop.',
|
|
72
98
|
mode === 'md3e'
|
|
73
99
|
? 'This session runs **Material 3 Expressive**. Before any design work, call `unslop_read {name:"md3e-overview"}`, then read the sections you will touch (`md3e-color`, `md3e-typography`, `md3e-shape`, `md3e-motion`, `md3e-components`, `md3e-layout`) and audit with `md3e-audit`. Every value must come from a token in those docs. The generic `signs.md` / `tokens.md` are **not** the target language here. **Scope: unslop changes design, not the product** — building a new interface belongs to `dsh-m3e-mcp` (component catalogue) plus `m3e-studio` (brief). For colours, prefer the official `<m3e-theme>`; `unslop_theme` is an independent approximation and a same-named scheme can give a different result.'
|
|
74
100
|
: mode === 'unslop'
|
|
75
101
|
? 'This session runs the **original unslop** method: audit with `signs.md`, get values from `tokens.md`, and apply the nine passes in the classic order.'
|
|
76
102
|
: 'Design language is **off**: do not apply unslop or M3E guidance. The user has switched design assistance off for this session.',
|
|
77
103
|
'',
|
|
78
|
-
`Switch with \`unslop_mode {mode:"off|unslop|md3e"}\` (or the composer chip). Current: **${mode}**.`,
|
|
104
|
+
`Switch with \`unslop_mode {mode:"off|unslop|md3e"}\` (or the composer chip). The tier is per session: this file records the last activation in this profile, while \`unslop_status\` reports the tier of the session you are in. Current file value: **${mode}**.`,
|
|
79
105
|
].join('\n')
|
|
80
106
|
try {
|
|
81
107
|
fs.mkdirSync(SKILL_ROOT, { recursive: true })
|
|
@@ -164,8 +190,14 @@ function run(command, args, options = {}) {
|
|
|
164
190
|
|
|
165
191
|
// ---- skill install: copy the whole skills/unslop tree, compose a dsh preamble into SKILL.md --
|
|
166
192
|
const SKILL_PREAMBLE = `<!-- dsh-unslop: this copy is installed and kept in sync by the DSH plugin. In DeepSeek
|
|
167
|
-
Harness the tools appear as mcp__unslop__
|
|
168
|
-
|
|
193
|
+
Harness the tools appear as mcp__unslop__*.
|
|
194
|
+
STEP 0 — check whether you actually have them. If unslop_status and the mcp__unslop__* tools are
|
|
195
|
+
absent from this session's tool list, unslop is switched off here: do not read reference files and
|
|
196
|
+
do not plan design work. Say so, ask the user to turn the design tier on with the composer chip
|
|
197
|
+
(or unslop_mode), then stop.
|
|
198
|
+
If they are present, call unslop_status first: it reports this session's tier and whether
|
|
199
|
+
Playwright/ffmpeg are available (needed only by snapshot and story), and unslop_deps says how to
|
|
200
|
+
install them.
|
|
169
201
|
FIRST read MODE.md in this skill folder: it names the active design language (off / unslop / md3e).
|
|
170
202
|
- mode=unslop -> the original method: audit with signs.md, values from tokens.md, nine passes.
|
|
171
203
|
- mode=md3e -> Material 3 Expressive: read md3e-overview, then read ONLY the chapters you need with unslop_read {name, outline:true} + {name, section:'...'} (the set is ~12.6k tokens; do not read it whole), audit with md3e-audit.
|
|
@@ -202,7 +234,7 @@ function installSkill(report = []) {
|
|
|
202
234
|
copyDir(SKILL_SRC, SKILL_ROOT)
|
|
203
235
|
const installed = path.join(SKILL_ROOT, 'SKILL.md')
|
|
204
236
|
fs.writeFileSync(installed, composeSkill(fs.readFileSync(installed, 'utf8')))
|
|
205
|
-
writeSkillMode(
|
|
237
|
+
writeSkillMode(sessions.lastActivated())
|
|
206
238
|
report.push(`wrote ${SKILL_ROOT}`)
|
|
207
239
|
return { ok: true, dir: SKILL_ROOT, report }
|
|
208
240
|
} catch (error) {
|
|
@@ -285,7 +317,7 @@ function statusTool(settings, hooks) {
|
|
|
285
317
|
render: (_a, v) => {
|
|
286
318
|
const lines = [
|
|
287
319
|
`unslop: MCP ${v.mcp.running ? 'running' : 'NOT RUNNING'} — ${v.mcp.visible}/${v.mcp.total} tools on surface "${v.surface}"${v.mcp.serverVersion ? ` (server ${v.mcp.serverVersion})` : ''}`,
|
|
288
|
-
` design: ${v.design ? v.design.mode : '
|
|
320
|
+
` design: ${v.design ? v.design.mode : 'off'}${v.design ? ` (${DESIGN_LABEL[v.design.mode]})` : ''}${v.design && v.design.sessionId ? ` for session ${String(v.design.sessionId).slice(0, 8)}…` : ' — no session context, so no tool is admitted'}`,
|
|
289
321
|
` node: ${v.node}`,
|
|
290
322
|
` skill: ${v.skill.installed ? v.skill.dir : 'NOT INSTALLED'}`,
|
|
291
323
|
` playwright (snapshot): ${v.playwright ? 'found' : 'missing'}${v.ffmpeg ? ' ffmpeg (story): found' : ' ffmpeg (story): missing'}`,
|
|
@@ -295,7 +327,7 @@ function statusTool(settings, hooks) {
|
|
|
295
327
|
return [{ type: 'text', text: lines.join('\n') }]
|
|
296
328
|
},
|
|
297
329
|
},
|
|
298
|
-
async execute() { return hooks.statusReport() },
|
|
330
|
+
async execute(_args, exec) { return hooks.statusReport(sessionIdOf(exec)) },
|
|
299
331
|
}
|
|
300
332
|
}
|
|
301
333
|
|
|
@@ -364,7 +396,8 @@ function surfaceTool(settings, hooks) {
|
|
|
364
396
|
return [{ type: 'text', text: `unslop tool surface: ${v.surface}${v.allow.length ? ` = ${v.allow.join(', ')}` : ' (every tool)'}${counts}` }]
|
|
365
397
|
},
|
|
366
398
|
},
|
|
367
|
-
async execute(args) {
|
|
399
|
+
async execute(args, exec) {
|
|
400
|
+
const sessionId = sessionIdOf(exec)
|
|
368
401
|
let patch = null
|
|
369
402
|
if (args && typeof args.surface === 'string') {
|
|
370
403
|
const tier = Object.prototype.hasOwnProperty.call(SURFACES, args.surface) ? SURFACES[args.surface] : null
|
|
@@ -376,8 +409,8 @@ function surfaceTool(settings, hooks) {
|
|
|
376
409
|
patch = SURFACES.off
|
|
377
410
|
}
|
|
378
411
|
if (patch) writeSurface(patch)
|
|
379
|
-
const applied = hooks.applySurface()
|
|
380
|
-
return { ...readSurface(), mcp: applied, mcpTools: hooks.registryCounts() }
|
|
412
|
+
const applied = hooks.applySurface(sessionId)
|
|
413
|
+
return { ...readSurface(), ...(sessionId ? { sessionId } : {}), mcp: applied, mcpTools: hooks.registryCounts(sessionId) }
|
|
381
414
|
},
|
|
382
415
|
}
|
|
383
416
|
}
|
|
@@ -387,11 +420,12 @@ function modeTool(settings, hooks) {
|
|
|
387
420
|
return {
|
|
388
421
|
name: 'unslop_mode',
|
|
389
422
|
description:
|
|
390
|
-
'Read or switch the design language tier. "off" (关闭): no design guidance and
|
|
423
|
+
'Read or switch the design language tier of THIS session. "off" (关闭): no design guidance and no unslop tool admitted to this session at all; "unslop" (原版 unslop): the original unslop method — audit with signs.md, values from tokens.md, nine passes; "md3e": Material 3 Expressive — the full md3e reference set (color roles/tonal palettes, 15 type roles, shape scale, spring motion, components, layout, audit checklist). The tier is per session: switching it here never changes another conversation, and a session that is off cannot call this or any other unslop tool — turn it on from the composer chip. Switching writes this session\'s record plus the global MODE.md hint; the tool set is re-resolved on the next step — no restart.',
|
|
391
424
|
parameters: {
|
|
392
425
|
type: 'object',
|
|
393
426
|
properties: {
|
|
394
427
|
mode: { type: 'string', enum: DESIGN_MODES, description: 'Tier to switch to. Leave out to read the current one.' },
|
|
428
|
+
sessionId: { type: 'string', description: 'Target session id when calling outside a session; ignored when the call comes from an agent.' },
|
|
395
429
|
},
|
|
396
430
|
},
|
|
397
431
|
output: {
|
|
@@ -402,16 +436,16 @@ function modeTool(settings, hooks) {
|
|
|
402
436
|
return [{ type: 'text', text: `unslop 设计档位:${DESIGN_LABEL[v.mode]} (${mods})${counts}` }]
|
|
403
437
|
},
|
|
404
438
|
},
|
|
405
|
-
async execute(args) {
|
|
439
|
+
async execute(args, exec) {
|
|
440
|
+
const sessionId = sessionIdOf(exec) || (args && typeof args.sessionId === 'string' ? args.sessionId.trim() : null)
|
|
406
441
|
if (args && typeof args.mode === 'string') {
|
|
407
|
-
|
|
442
|
+
if (!sessionId) throw new Error('unslop_mode needs a session: the tier is per session. Call it from an agent, or pass sessionId.')
|
|
443
|
+
const next = writeDesignMode(args.mode, sessionId)
|
|
408
444
|
writeSkillMode(next.mode)
|
|
409
|
-
|
|
410
|
-
writeSurface(next.mode === 'off' ? SURFACES.off : SURFACES.all)
|
|
411
|
-
hooks.applySurface()
|
|
445
|
+
hooks.applySurface(sessionId)
|
|
412
446
|
}
|
|
413
|
-
const current = readDesignMode()
|
|
414
|
-
return { ...current, modes: DESIGN_MODES, labels: DESIGN_LABEL, mcp: hooks.registryCounts() }
|
|
447
|
+
const current = readDesignMode(sessionId)
|
|
448
|
+
return { ...current, modes: DESIGN_MODES, labels: DESIGN_LABEL, mcp: hooks.registryCounts(sessionId) }
|
|
415
449
|
},
|
|
416
450
|
}
|
|
417
451
|
}
|
|
@@ -611,44 +645,63 @@ function tokenRouteHandler(auth) {
|
|
|
611
645
|
return (req, res) => sendJson(res, 200, { ok: true, token: auth.token })
|
|
612
646
|
}
|
|
613
647
|
|
|
648
|
+
// A route has no agent, so the session comes from the caller: `?sessionId=` on a GET, `sessionId` in
|
|
649
|
+
// a POST body. Without one there is no tier to read or write, and the answer says so instead of
|
|
650
|
+
// silently falling back to a global default.
|
|
651
|
+
function sessionOfRequest(req, body) {
|
|
652
|
+
const fromBody = body && typeof body.sessionId === 'string' ? body.sessionId.trim() : ''
|
|
653
|
+
if (fromBody) return fromBody
|
|
654
|
+
try {
|
|
655
|
+
const url = new URL(String((req && req.url) || ''), 'http://localhost')
|
|
656
|
+
const query = url.searchParams.get('sessionId')
|
|
657
|
+
if (query && query.trim()) return query.trim()
|
|
658
|
+
} catch { /* no parsable url */ }
|
|
659
|
+
return null
|
|
660
|
+
}
|
|
661
|
+
|
|
614
662
|
function surfaceRouteHandler(hooks) {
|
|
615
663
|
return async (req, res) => {
|
|
616
664
|
if ((req.method || 'GET').toUpperCase() === 'POST') {
|
|
617
665
|
const body = await readJsonBody(req)
|
|
666
|
+
const sessionId = sessionOfRequest(req, body)
|
|
618
667
|
let patch = null
|
|
619
668
|
if (typeof body.surface === 'string' && Object.prototype.hasOwnProperty.call(SURFACES, body.surface)) patch = SURFACES[body.surface]
|
|
620
669
|
else if (Array.isArray(body.allow)) patch = { enabled: body.enabled !== false, allow: body.allow.map(String) }
|
|
621
670
|
if (!patch) return sendJson(res, 400, { ok: false, error: 'body must be {"surface":"off|core|all"} or {"allow":[...]}' })
|
|
622
671
|
writeSurface(patch)
|
|
623
|
-
const applied = hooks.applySurface()
|
|
624
|
-
return sendJson(res, 200, { ok: true, ...readSurface(), mcp: applied, mcpTools: hooks.registryCounts() })
|
|
672
|
+
const applied = hooks.applySurface(sessionId)
|
|
673
|
+
return sendJson(res, 200, { ok: true, ...readSurface(), sessionId, mcp: applied, mcpTools: hooks.registryCounts(sessionId) })
|
|
625
674
|
}
|
|
626
675
|
// GET is read-only: the chip polls this, so it must never re-register tools on a poll.
|
|
676
|
+
const sessionId = sessionOfRequest(req)
|
|
627
677
|
const surface = readSurface()
|
|
628
|
-
const counts = hooks.registryCounts()
|
|
629
|
-
sendJson(res, 200, { ok: true, ...surface, mcp: { ...counts, surface: surface.surface, allow: surface.allow }, mcpTools: counts })
|
|
678
|
+
const counts = hooks.registryCounts(sessionId)
|
|
679
|
+
sendJson(res, 200, { ok: true, ...surface, sessionId, mcp: { ...counts, surface: surface.surface, allow: surface.allow }, mcpTools: counts })
|
|
630
680
|
}
|
|
631
681
|
}
|
|
632
682
|
|
|
633
683
|
function statusRouteHandler(hooks) {
|
|
634
|
-
return async (req, res) => sendJson(res, 200, { ok: true, ...(await hooks.statusReport()) })
|
|
684
|
+
return async (req, res) => sendJson(res, 200, { ok: true, ...(await hooks.statusReport(sessionOfRequest(req))) })
|
|
635
685
|
}
|
|
636
686
|
|
|
637
|
-
// GET reads
|
|
687
|
+
// GET reads this session's tier; POST switches it (same effect as the unslop_mode tool).
|
|
638
688
|
function modeRouteHandler(hooks) {
|
|
639
689
|
return async (req, res) => {
|
|
640
690
|
if ((req.method || 'GET').toUpperCase() === 'POST') {
|
|
641
691
|
const body = await readJsonBody(req)
|
|
692
|
+
const sessionId = sessionOfRequest(req, body)
|
|
642
693
|
if (typeof body.mode !== 'string' || !DESIGN_MODES.includes(body.mode)) {
|
|
643
|
-
return sendJson(res, 400, { ok: false, error: `body must be {"mode":"${DESIGN_MODES.join('|')}"}` })
|
|
694
|
+
return sendJson(res, 400, { ok: false, error: `body must be {"mode":"${DESIGN_MODES.join('|')}","sessionId":"..."}` })
|
|
644
695
|
}
|
|
645
|
-
|
|
696
|
+
if (!sessionId) return sendJson(res, 400, { ok: false, error: 'sessionId is required: the design tier is per session' })
|
|
697
|
+
const next = writeDesignMode(body.mode, sessionId)
|
|
646
698
|
writeSkillMode(next.mode)
|
|
647
|
-
|
|
648
|
-
hooks.
|
|
699
|
+
hooks.applySurface(sessionId)
|
|
700
|
+
return sendJson(res, 200, { ok: true, ...next, modes: DESIGN_MODES, labels: DESIGN_LABEL, mcp: hooks.registryCounts(sessionId), mcpTools: hooks.registryCounts(sessionId) })
|
|
649
701
|
}
|
|
650
|
-
const
|
|
651
|
-
|
|
702
|
+
const sessionId = sessionOfRequest(req)
|
|
703
|
+
const current = readDesignMode(sessionId)
|
|
704
|
+
sendJson(res, 200, { ok: true, ...current, needsSession: !sessionId, modes: DESIGN_MODES, labels: DESIGN_LABEL, mcp: hooks.registryCounts(sessionId), mcpTools: hooks.registryCounts(sessionId) })
|
|
652
705
|
}
|
|
653
706
|
}
|
|
654
707
|
|
|
@@ -708,42 +761,71 @@ export function apply(ctx, config) {
|
|
|
708
761
|
}
|
|
709
762
|
}
|
|
710
763
|
|
|
711
|
-
|
|
764
|
+
// Counts are per session: `total` is what the server serves, `admitted` what the global surface
|
|
765
|
+
// allows, and `visible` what this session actually sees (zero while its tier is off).
|
|
766
|
+
const registryCounts = (sessionId) => {
|
|
767
|
+
const allowed = allowedNames(readSurface())
|
|
768
|
+
const admitted = runtime.tools.filter((tool) => allowed(tool.name)).length
|
|
769
|
+
return {
|
|
770
|
+
total: runtime.tools.length,
|
|
771
|
+
admitted,
|
|
772
|
+
visible: designGate(sessionId) ? admitted : 0,
|
|
773
|
+
running: Boolean(runtime.client),
|
|
774
|
+
}
|
|
775
|
+
}
|
|
712
776
|
|
|
713
|
-
|
|
777
|
+
// Register once, gate per step. A tier switch therefore needs no re-registration and cannot race a
|
|
778
|
+
// running step; bridge.json is read inside the gate, so a surface change lands on the next step too.
|
|
779
|
+
const registerMcpTools = () => {
|
|
714
780
|
disposeMcpTools()
|
|
715
|
-
|
|
716
|
-
const allowed = allowedNames(surface)
|
|
717
|
-
let visible = 0
|
|
781
|
+
let registered = 0
|
|
718
782
|
for (const tool of runtime.tools) {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
783
|
+
try {
|
|
784
|
+
runtime.disposers.set(tool.name, ctx.tools.register(mcpDefinition(tool), {
|
|
785
|
+
when: ({ agent }) => {
|
|
786
|
+
if (!agent || typeof agent.id !== 'string' || !agent.id) return false
|
|
787
|
+
if (!designGate(agent.id)) return false
|
|
788
|
+
return allowedNames(readSurface())(tool.name)
|
|
789
|
+
},
|
|
790
|
+
}))
|
|
791
|
+
registered += 1
|
|
792
|
+
} catch (error) {
|
|
793
|
+
console.error(`[dsh-unslop] cannot register ${TOOL_PREFIX}${tool.name}: ${String(error?.message || error)}`)
|
|
794
|
+
}
|
|
722
795
|
}
|
|
723
|
-
runtime.visible = visible
|
|
724
796
|
runtime.total = runtime.tools.length
|
|
725
|
-
return
|
|
797
|
+
return registered
|
|
726
798
|
}
|
|
727
799
|
|
|
728
|
-
const
|
|
729
|
-
node: process.version,
|
|
730
|
-
playwright: hasPlaywright(),
|
|
731
|
-
ffmpeg: Boolean(which('ffmpeg')),
|
|
732
|
-
skill: { dir: SKILL_ROOT, installed: fs.existsSync(path.join(SKILL_ROOT, 'SKILL.md')) },
|
|
733
|
-
references: runtime.references,
|
|
800
|
+
const applySurface = (sessionId) => ({
|
|
734
801
|
surface: readSurface().surface,
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
serverName: SERVER_NAME,
|
|
738
|
-
toolPrefix: TOOL_PREFIX,
|
|
739
|
-
running: Boolean(runtime.client),
|
|
740
|
-
visible: runtime.visible,
|
|
741
|
-
total: runtime.total,
|
|
742
|
-
serverVersion: runtime.serverVersion,
|
|
743
|
-
lastError: runtime.lastError,
|
|
744
|
-
},
|
|
802
|
+
allow: readSurface().allow,
|
|
803
|
+
...registryCounts(sessionId),
|
|
745
804
|
})
|
|
746
805
|
|
|
806
|
+
const statusReport = async (sessionId) => {
|
|
807
|
+
const counts = registryCounts(sessionId)
|
|
808
|
+
return {
|
|
809
|
+
node: process.version,
|
|
810
|
+
playwright: hasPlaywright(),
|
|
811
|
+
ffmpeg: Boolean(which('ffmpeg')),
|
|
812
|
+
skill: { dir: SKILL_ROOT, installed: fs.existsSync(path.join(SKILL_ROOT, 'SKILL.md')) },
|
|
813
|
+
references: runtime.references,
|
|
814
|
+
surface: readSurface().surface,
|
|
815
|
+
design: readDesignMode(sessionId),
|
|
816
|
+
mcp: {
|
|
817
|
+
serverName: SERVER_NAME,
|
|
818
|
+
toolPrefix: TOOL_PREFIX,
|
|
819
|
+
running: Boolean(runtime.client),
|
|
820
|
+
visible: counts.visible,
|
|
821
|
+
admitted: counts.admitted,
|
|
822
|
+
total: counts.total,
|
|
823
|
+
serverVersion: runtime.serverVersion,
|
|
824
|
+
lastError: runtime.lastError,
|
|
825
|
+
},
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
747
829
|
const hooks = { statusReport, applySurface, registryCounts }
|
|
748
830
|
|
|
749
831
|
const stopClient = () => {
|
|
@@ -765,7 +847,7 @@ export function apply(ctx, config) {
|
|
|
765
847
|
env: { ELECTRON_RUN_AS_NODE: '1', UNSLOP_PLAYWRIGHT_HOME: path.join(INSTALL_ROOT, 'node_modules') },
|
|
766
848
|
})
|
|
767
849
|
client.onListChanged(() => {
|
|
768
|
-
client.listTools().then((tools) => { runtime.tools = tools;
|
|
850
|
+
client.listTools().then((tools) => { runtime.tools = tools; registerMcpTools() }).catch((e) => { runtime.lastError = String(e?.message || e) })
|
|
769
851
|
})
|
|
770
852
|
client.onDown((reason) => { runtime.lastError = reason })
|
|
771
853
|
await client.start()
|
|
@@ -774,20 +856,24 @@ export function apply(ctx, config) {
|
|
|
774
856
|
runtime.tools = await client.listTools()
|
|
775
857
|
try { runtime.references = (await client.listResources()).length } catch { runtime.references = 0 }
|
|
776
858
|
runtime.lastError = null
|
|
777
|
-
|
|
859
|
+
registerMcpTools()
|
|
778
860
|
console.error(`[dsh-unslop] MCP server up: ${SERVER} (${runtime.total} tools, ${runtime.references} references)`)
|
|
779
|
-
return statusReport()
|
|
861
|
+
return statusReport(null)
|
|
780
862
|
}
|
|
781
863
|
|
|
782
864
|
ctx.inject(['workingDirectory'], (wdCtx) => {
|
|
783
865
|
workingDirectoryService = wdCtx.workingDirectory || null
|
|
784
866
|
})
|
|
785
867
|
|
|
868
|
+
// Every definition — host tool and bridged MCP tool alike — is admitted only into a session whose
|
|
869
|
+
// tier is on. `ctx.tools.register` is called once globally; the `when` gate is what makes the
|
|
870
|
+
// registration per session, evaluated against the calling agent on each step.
|
|
871
|
+
const hostGate = ({ agent }) => Boolean(agent && typeof agent.id === 'string' && agent.id) && designGate(agent.id)
|
|
786
872
|
const definitions = [statusTool(settings, hooks), depsTool(settings, hooks), surfaceTool(settings, hooks), modeTool(settings, hooks), themeTool(settings), detectTool(settings, hooks)]
|
|
787
873
|
ctx.effect(() => {
|
|
788
874
|
const disposers = []
|
|
789
875
|
try {
|
|
790
|
-
for (const definition of definitions) disposers.push(ctx.tools.register(definition))
|
|
876
|
+
for (const definition of definitions) disposers.push(ctx.tools.register(definition, { when: hostGate }))
|
|
791
877
|
return () => { while (disposers.length > 0) { try { disposers.pop()?.() } catch { /* ignore */ } } }
|
|
792
878
|
} catch (error) {
|
|
793
879
|
while (disposers.length > 0) { try { disposers.pop()?.() } catch { /* ignore */ } }
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// dsh-unslop — per-session design-language state.
|
|
2
|
+
//
|
|
3
|
+
// The tier used to live in one global design.json, so switching it in one conversation moved every
|
|
4
|
+
// other conversation with it. A session now carries its own tier: no record means "off", and the
|
|
5
|
+
// tools are gated per agent through ctx.tools.register(def, { when }) — a session that never enabled
|
|
6
|
+
// unslop never sees a single mcp__unslop__* schema and cannot call one.
|
|
7
|
+
//
|
|
8
|
+
// Dependency-free and synchronous on purpose: the gate runs at every step admission, and the file is
|
|
9
|
+
// a few hundred bytes.
|
|
10
|
+
//
|
|
11
|
+
// File shape (plugins-data/unslop/sessions.json):
|
|
12
|
+
// { "version": 1, "sessions": { "<sessionId>": { "mode": "unslop" | "md3e", "updatedAt": "ISO" } } }
|
|
13
|
+
//
|
|
14
|
+
// "off" is stored as the absence of a record, not as a third value, so a profile that never used the
|
|
15
|
+
// feature has no file at all and the default stays unambiguous.
|
|
16
|
+
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
|
|
20
|
+
export const MODES = ['off', 'unslop', 'md3e']
|
|
21
|
+
export const DEFAULT_MODE = 'off'
|
|
22
|
+
|
|
23
|
+
const emptyState = () => ({ version: 1, sessions: {} })
|
|
24
|
+
const keyOf = (sessionId) => (typeof sessionId === 'string' ? sessionId.trim() : '')
|
|
25
|
+
|
|
26
|
+
export function normalizeMode(value) {
|
|
27
|
+
return MODES.includes(value) ? value : DEFAULT_MODE
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createSessionStore(file) {
|
|
31
|
+
const readState = () => {
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''))
|
|
34
|
+
const sessions = parsed && typeof parsed.sessions === 'object' && parsed.sessions ? parsed.sessions : {}
|
|
35
|
+
return { version: 1, sessions }
|
|
36
|
+
} catch {
|
|
37
|
+
return emptyState()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const writeState = (state) => {
|
|
42
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
43
|
+
fs.writeFileSync(file, `${JSON.stringify({ version: 1, sessions: state.sessions }, null, 2)}\n`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const recordOf = (sessionId) => {
|
|
47
|
+
const key = keyOf(sessionId)
|
|
48
|
+
if (!key) return null
|
|
49
|
+
const record = readState().sessions[key]
|
|
50
|
+
if (!record || typeof record !== 'object') return null
|
|
51
|
+
return {
|
|
52
|
+
mode: normalizeMode(record.mode),
|
|
53
|
+
updatedAt: typeof record.updatedAt === 'string' ? record.updatedAt : null,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
modes: MODES,
|
|
59
|
+
file,
|
|
60
|
+
|
|
61
|
+
modeOf(sessionId) {
|
|
62
|
+
const record = recordOf(sessionId)
|
|
63
|
+
return record ? record.mode : DEFAULT_MODE
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
isEnabled(sessionId) {
|
|
67
|
+
const record = recordOf(sessionId)
|
|
68
|
+
return Boolean(record && record.mode !== 'off')
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
// One shape for every reader: a tool result, a route body and the chip all show the same fields.
|
|
72
|
+
describe(sessionId) {
|
|
73
|
+
const record = recordOf(sessionId)
|
|
74
|
+
const mode = record ? record.mode : DEFAULT_MODE
|
|
75
|
+
return {
|
|
76
|
+
sessionId: keyOf(sessionId) || null,
|
|
77
|
+
mode,
|
|
78
|
+
enabled: mode !== 'off',
|
|
79
|
+
updatedAt: record ? record.updatedAt : null,
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
set(sessionId, mode) {
|
|
84
|
+
const key = keyOf(sessionId)
|
|
85
|
+
if (!key) throw new Error('a session id is required: the design tier is per session, not global')
|
|
86
|
+
if (!MODES.includes(mode)) throw new Error(`unknown design mode "${mode}"; use one of ${MODES.join(', ')}`)
|
|
87
|
+
const state = readState()
|
|
88
|
+
if (mode === 'off') delete state.sessions[key]
|
|
89
|
+
else state.sessions[key] = { mode, updatedAt: new Date().toISOString() }
|
|
90
|
+
writeState(state)
|
|
91
|
+
return this.describe(key)
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
clear(sessionId) {
|
|
95
|
+
const key = keyOf(sessionId)
|
|
96
|
+
if (!key) return false
|
|
97
|
+
const state = readState()
|
|
98
|
+
if (!(key in state.sessions)) return false
|
|
99
|
+
delete state.sessions[key]
|
|
100
|
+
writeState(state)
|
|
101
|
+
return true
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
// The skill is a global document and cannot carry a per-session tier, so MODE.md only records
|
|
105
|
+
// the most recent activation as a hint. unslop_status is the authority inside a session.
|
|
106
|
+
lastActivated() {
|
|
107
|
+
const entries = Object.entries(readState().sessions)
|
|
108
|
+
if (entries.length === 0) return DEFAULT_MODE
|
|
109
|
+
entries.sort((a, b) => String(b[1]?.updatedAt || '').localeCompare(String(a[1]?.updatedAt || '')))
|
|
110
|
+
return normalizeMode(entries[0][1]?.mode)
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
snapshot() {
|
|
114
|
+
return readState().sessions
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-unslop",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "unslop for DeepSeek Harness: a standalone MCP server that turns vibecoded, AI-looking UI into a designed interface, bridged into dsh as mcp__unslop__* tools plus a workflow skill. Vendored under CC BY 4.0.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"host/index.js",
|
|
34
34
|
"host/mcp-client.js",
|
|
35
35
|
"host/http-util.js",
|
|
36
|
+
"host/session-state.js",
|
|
36
37
|
"client.js",
|
|
37
38
|
"mcp/server.mjs",
|
|
38
39
|
"mcp/detect.mjs",
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"install.ps1",
|
|
56
57
|
"docs/banner-*.png",
|
|
57
58
|
"README.md",
|
|
59
|
+
"CHANGELOG.md",
|
|
58
60
|
"LICENSE",
|
|
59
61
|
"LICENSE-unslop-CC-BY-4.0.txt",
|
|
60
62
|
"THIRD-PARTY-NOTICES.md"
|
package/tests/adversarial.mjs
CHANGED
|
@@ -212,13 +212,17 @@ async function hostSuite() {
|
|
|
212
212
|
try { await tools.get('unslop_surface').execute({ surface: 'bogus' }, { agent: null }) } catch { threw = true }
|
|
213
213
|
ok('unslop_surface invalid tier throws', threw)
|
|
214
214
|
|
|
215
|
-
// surface glob allow list: unslop_* should keep all 4
|
|
215
|
+
// surface glob allow list: unslop_* should keep all 4 — for a session that enabled the tier
|
|
216
|
+
const advAgent = { agent: { id: 'adv-session', session: null } }
|
|
217
|
+
const modeTool = tools.get('unslop_mode')
|
|
218
|
+
ok('fresh session starts off', (await modeTool.execute({}, advAgent)).mode === 'off')
|
|
219
|
+
await modeTool.execute({ mode: 'unslop' }, advAgent)
|
|
216
220
|
const surf = tools.get('unslop_surface')
|
|
217
|
-
const g = await surf.execute({ allow: ['unslop_*'] },
|
|
221
|
+
const g = await surf.execute({ allow: ['unslop_*'] }, advAgent)
|
|
218
222
|
ok('allow ["unslop_*"] keeps 4 mcp tools', g.mcp.visible === 4, JSON.stringify(g.mcp))
|
|
219
|
-
const off = await surf.execute({ enabled: false },
|
|
223
|
+
const off = await surf.execute({ enabled: false }, advAgent)
|
|
220
224
|
ok('enabled:false hides all mcp tools', off.mcp.visible === 0)
|
|
221
|
-
const back = await surf.execute({ surface: 'all' },
|
|
225
|
+
const back = await surf.execute({ surface: 'all' }, advAgent)
|
|
222
226
|
ok('surface all restores 4', back.mcp.visible === 4)
|
|
223
227
|
|
|
224
228
|
// deps probe (no install) does not throw
|
|
@@ -227,8 +231,8 @@ async function hostSuite() {
|
|
|
227
231
|
|
|
228
232
|
// ===================== C. routes =====================
|
|
229
233
|
console.log('\n== C. HTTP routes / auth ==')
|
|
230
|
-
const call = (handler, { method = 'GET', headers = {}, body, socket } = {}) => new Promise((resolve) => {
|
|
231
|
-
const req = new EventEmitter(); req.method = method; req.headers = headers; if (socket) req.socket = socket
|
|
234
|
+
const call = (handler, { method = 'GET', headers = {}, body, socket, url = '/' } = {}) => new Promise((resolve) => {
|
|
235
|
+
const req = new EventEmitter(); req.method = method; req.headers = headers; req.url = url; if (socket) req.socket = socket
|
|
232
236
|
const res = { _s: 200, _b: '', writeHead(s) { this._s = s }, end(chunk) { this._b += chunk || ''; let j = null; try { j = JSON.parse(this._b) } catch {} resolve({ status: this._s, json: j }) } }
|
|
233
237
|
handler(req, res)
|
|
234
238
|
if (body !== undefined) { req.emit('data', typeof body === 'string' ? body : JSON.stringify(body)); req.emit('end') } else req.emit('end')
|
|
@@ -253,6 +257,18 @@ async function hostSuite() {
|
|
|
253
257
|
ok('surface: loopback peer -> 200', (await call(routes.get('/unslop/api/surface'), { headers: auth, socket: { remoteAddress: '127.0.0.1' } })).status === 200)
|
|
254
258
|
ok('surface POST "__proto__" -> 400', (await call(routes.get('/unslop/api/surface'), { method: 'POST', headers: auth, body: { surface: '__proto__' } })).status === 400)
|
|
255
259
|
|
|
260
|
+
// the tier must not leak across sessions through the route either
|
|
261
|
+
const routeUrl = (sid) => `/unslop/api/mode?sessionId=${encodeURIComponent(sid)}`
|
|
262
|
+
const enableA = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'md3e', sessionId: 'adv-a' } })
|
|
263
|
+
ok('route: session A enabled', enableA.json.mode === 'md3e', JSON.stringify(enableA.json))
|
|
264
|
+
const readA = await call(routes.get('/unslop/api/mode'), { headers: auth, url: routeUrl('adv-a') })
|
|
265
|
+
const readB = await call(routes.get('/unslop/api/mode'), { headers: auth, url: routeUrl('adv-b') })
|
|
266
|
+
ok('route: A reads back md3e', readA.json.mode === 'md3e', JSON.stringify(readA.json))
|
|
267
|
+
ok('route: B is still off', readB.json.mode === 'off' && readB.json.mcp.visible === 0, JSON.stringify(readB.json))
|
|
268
|
+
const offA = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'off', sessionId: 'adv-a' } })
|
|
269
|
+
ok('route: A can switch itself off', offA.json.mode === 'off' && offA.json.mcp.visible === 0)
|
|
270
|
+
ok('route: B unaffected by A going off', (await call(routes.get('/unslop/api/mode'), { headers: auth, url: routeUrl('adv-b') })).json.mode === 'off')
|
|
271
|
+
|
|
256
272
|
try { fs.rmSync(tmpHome, { recursive: true, force: true }) } catch {}
|
|
257
273
|
}
|
|
258
274
|
|
package/tests/hosttest.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// dsh-unslop — host-half test with a stub ctx (no DeepSeek Harness). Verifies that apply()
|
|
2
|
-
// registers the
|
|
3
|
-
// that
|
|
2
|
+
// registers the six host tools plus the four bridged MCP tools, that every registration carries a
|
|
3
|
+
// per-session `when` gate, that the gate stays closed until that session enables a tier, and that a
|
|
4
|
+
// bridged call (unslop_read) round-trips through the real server.
|
|
4
5
|
//
|
|
5
6
|
// node tests/hosttest.mjs
|
|
6
7
|
|
|
@@ -28,7 +29,16 @@ const registered = new Map()
|
|
|
28
29
|
const disposers = []
|
|
29
30
|
const effects = []
|
|
30
31
|
const ctx = {
|
|
31
|
-
|
|
32
|
+
// Capture the registration options: the per-session gate is the whole point of this suite.
|
|
33
|
+
tools: {
|
|
34
|
+
register(def, options) {
|
|
35
|
+
const entry = { ...def, when: options && options.when }
|
|
36
|
+
registered.set(def.name, entry)
|
|
37
|
+
const dispose = () => registered.delete(def.name)
|
|
38
|
+
disposers.push(dispose)
|
|
39
|
+
return dispose
|
|
40
|
+
},
|
|
41
|
+
},
|
|
32
42
|
inject(_names, cb) { /* workingDirectory absent — base dir falls back to cwd */ },
|
|
33
43
|
effect(fn, _label) { const cleanup = fn(); effects.push(cleanup) },
|
|
34
44
|
}
|
|
@@ -39,6 +49,13 @@ apply(ctx, { installSkillOnBoot: true })
|
|
|
39
49
|
const deadline = Date.now() + 15_000
|
|
40
50
|
while (Date.now() < deadline && registered.size < 10) await new Promise((r) => setTimeout(r, 100))
|
|
41
51
|
|
|
52
|
+
const agentOf = (id) => ({ agent: { id, session: null } })
|
|
53
|
+
const gateOf = (name) => registered.get(name) && registered.get(name).when
|
|
54
|
+
const admits = (name, sessionId) => {
|
|
55
|
+
const gate = gateOf(name)
|
|
56
|
+
return typeof gate === 'function' ? gate(agentOf(sessionId)) : null
|
|
57
|
+
}
|
|
58
|
+
|
|
42
59
|
ok('host tool unslop_status registered', registered.has('unslop_status'))
|
|
43
60
|
ok('host tool unslop_deps registered', registered.has('unslop_deps'))
|
|
44
61
|
ok('host tool unslop_surface registered', registered.has('unslop_surface'))
|
|
@@ -47,15 +64,43 @@ ok('host tool unslop_theme registered', registered.has('unslop_theme'))
|
|
|
47
64
|
ok('host tool unslop_mode registered', registered.has('unslop_mode'))
|
|
48
65
|
ok('mcp tool unslop_read registered', registered.has('mcp__unslop__unslop_read'), [...registered.keys()].join(','))
|
|
49
66
|
ok('all ten tools registered', registered.size === 10, String(registered.size))
|
|
67
|
+
ok('every registration carries a when gate', [...registered.values()].every((d) => typeof d.when === 'function'), [...registered.keys()].join(','))
|
|
50
68
|
ok('skill installed to DSH_HOME', fs.existsSync(path.join(tmpHome, 'skills', 'unslop', 'SKILL.md')))
|
|
51
69
|
ok('skill keeps the CC BY credit', (() => {
|
|
52
70
|
try { return /@heydamir/.test(fs.readFileSync(path.join(tmpHome, 'skills', 'unslop', 'SKILL.md'), 'utf8')) } catch { return false }
|
|
53
71
|
})())
|
|
72
|
+
ok('skill tells the model that absent tools mean the session is off', (() => {
|
|
73
|
+
try { return /absent from this session's tool list/.test(fs.readFileSync(path.join(tmpHome, 'skills', 'unslop', 'SKILL.md'), 'utf8')) } catch { return false }
|
|
74
|
+
})())
|
|
75
|
+
ok('MODE.md calls itself a hint, not authority', (() => {
|
|
76
|
+
try { return /hint, not authority/.test(fs.readFileSync(path.join(tmpHome, 'skills', 'unslop', 'MODE.md'), 'utf8')) } catch { return false }
|
|
77
|
+
})())
|
|
78
|
+
|
|
79
|
+
// ---- per-session admission ---------------------------------------------------------------
|
|
80
|
+
ok('fresh session admits no unslop tool', ['unslop_status', 'mcp__unslop__unslop_read'].every((n) => admits(n, 'sess-a') === false))
|
|
81
|
+
ok('no agent at all admits nothing', gateOf('unslop_status')({}) === false)
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const mode = await registered.get('unslop_mode').execute({ mode: 'unslop' }, agentOf('sess-a'))
|
|
85
|
+
ok('unslop_mode switches the calling session', mode.mode === 'unslop' && mode.sessionId === 'sess-a', JSON.stringify(mode))
|
|
86
|
+
ok('enabled session admits the host tools', admits('unslop_status', 'sess-a') === true)
|
|
87
|
+
ok('enabled session admits the bridged tools', admits('mcp__unslop__unslop_read', 'sess-a') === true)
|
|
88
|
+
ok('a different session stays off', admits('unslop_status', 'sess-b') === false)
|
|
89
|
+
ok('a different session stays off (bridged)', admits('mcp__unslop__unslop_read', 'sess-b') === false)
|
|
90
|
+
|
|
91
|
+
const readA = await registered.get('unslop_mode').execute({}, agentOf('sess-a'))
|
|
92
|
+
const readB = await registered.get('unslop_mode').execute({}, agentOf('sess-b'))
|
|
93
|
+
ok('reading reports per-session tiers', readA.mode === 'unslop' && readB.mode === 'off', `${readA.mode} vs ${readB.mode}`)
|
|
94
|
+
ok('counts are per session', readA.mcp.visible === 4 && readB.mcp.visible === 0, JSON.stringify({ a: readA.mcp, b: readB.mcp }))
|
|
95
|
+
} catch (error) {
|
|
96
|
+
failed += 1
|
|
97
|
+
console.error(` FAIL per-session switch: ${error.message}`)
|
|
98
|
+
}
|
|
54
99
|
|
|
55
|
-
//
|
|
100
|
+
// ---- bridged round-trip ------------------------------------------------------------------
|
|
56
101
|
try {
|
|
57
102
|
const def = registered.get('mcp__unslop__unslop_read')
|
|
58
|
-
const result = await def.execute({ name: 'tokens' },
|
|
103
|
+
const result = await def.execute({ name: 'tokens' }, agentOf('sess-a'))
|
|
59
104
|
const text = (result.content || []).map((b) => b.text).join('\n')
|
|
60
105
|
ok('bridged unslop_read returns tokens', result.ok !== false && text.length > 500, `${text.length} chars`)
|
|
61
106
|
const rendered = def.output.render({ name: 'tokens' }, result)
|
|
@@ -65,31 +110,48 @@ try {
|
|
|
65
110
|
console.error(` FAIL bridged call: ${error.message}`)
|
|
66
111
|
}
|
|
67
112
|
|
|
68
|
-
//
|
|
113
|
+
// ---- status tool shape -------------------------------------------------------------------
|
|
69
114
|
try {
|
|
70
|
-
const status = await registered.get('unslop_status').execute({},
|
|
115
|
+
const status = await registered.get('unslop_status').execute({}, agentOf('sess-a'))
|
|
71
116
|
ok('status reports references count = 15', status.references === 15, String(status.references))
|
|
72
117
|
ok('status reports mcp running', status.mcp.running === true)
|
|
118
|
+
ok('status reports this session tier', status.design.mode === 'unslop' && status.design.sessionId === 'sess-a', JSON.stringify(status.design))
|
|
119
|
+
ok('status reports this session visibility', status.mcp.visible === 4 && status.mcp.total === 4, JSON.stringify(status.mcp))
|
|
120
|
+
const idle = await registered.get('unslop_status').execute({}, agentOf('sess-b'))
|
|
121
|
+
ok('status of an off session shows zero tools', idle.design.mode === 'off' && idle.mcp.visible === 0, JSON.stringify(idle.mcp))
|
|
73
122
|
} catch (error) {
|
|
74
123
|
failed += 1
|
|
75
124
|
console.error(` FAIL status tool: ${error.message}`)
|
|
76
125
|
}
|
|
77
126
|
|
|
78
|
-
//
|
|
127
|
+
// ---- surface tiers stay global, admission stays per session ------------------------------
|
|
79
128
|
try {
|
|
80
129
|
const surf = registered.get('unslop_surface')
|
|
81
|
-
const core = await surf.execute({ surface: 'core' },
|
|
82
|
-
ok('surface core -> 2/4
|
|
83
|
-
ok('core keeps unslop_read',
|
|
84
|
-
ok('core drops unslop_snapshot',
|
|
85
|
-
const all = await surf.execute({ surface: 'all' },
|
|
86
|
-
ok('surface all -> 4
|
|
87
|
-
ok('all restores unslop_snapshot',
|
|
130
|
+
const core = await surf.execute({ surface: 'core' }, agentOf('sess-a'))
|
|
131
|
+
ok('surface core -> 2/4 admitted', core.mcp.admitted === 2 && core.mcp.total === 4, JSON.stringify(core.mcp))
|
|
132
|
+
ok('core keeps unslop_read', admits('mcp__unslop__unslop_read', 'sess-a') === true)
|
|
133
|
+
ok('core drops unslop_snapshot', admits('mcp__unslop__unslop_snapshot', 'sess-a') === false)
|
|
134
|
+
const all = await surf.execute({ surface: 'all' }, agentOf('sess-a'))
|
|
135
|
+
ok('surface all -> 4 admitted', all.mcp.admitted === 4, JSON.stringify(all.mcp))
|
|
136
|
+
ok('all restores unslop_snapshot', admits('mcp__unslop__unslop_snapshot', 'sess-a') === true)
|
|
88
137
|
} catch (error) {
|
|
89
138
|
failed += 1
|
|
90
139
|
console.error(` FAIL surface switch: ${error.message}`)
|
|
91
140
|
}
|
|
92
141
|
|
|
142
|
+
// ---- switching one session off leaves the other alone -----------------------------------
|
|
143
|
+
try {
|
|
144
|
+
const offA = await registered.get('unslop_mode').execute({ mode: 'off' }, agentOf('sess-a'))
|
|
145
|
+
ok('mode off clears the session', offA.mode === 'off' && offA.enabled === false, JSON.stringify(offA))
|
|
146
|
+
ok('off session admits nothing again', admits('unslop_status', 'sess-a') === false)
|
|
147
|
+
const mode3 = await registered.get('unslop_mode').execute({ mode: 'md3e' }, agentOf('sess-b'))
|
|
148
|
+
ok('the other session switches independently', mode3.mode === 'md3e' && admits('mcp__unslop__unslop_read', 'sess-b') === true)
|
|
149
|
+
ok('the first session stays off', admits('unslop_status', 'sess-a') === false)
|
|
150
|
+
} catch (error) {
|
|
151
|
+
failed += 1
|
|
152
|
+
console.error(` FAIL isolation: ${error.message}`)
|
|
153
|
+
}
|
|
154
|
+
|
|
93
155
|
for (const cleanup of effects) { try { cleanup?.() } catch { /* ignore */ } }
|
|
94
156
|
try { fs.rmSync(tmpHome, { recursive: true, force: true }) } catch { /* ignore */ }
|
|
95
157
|
|
package/tests/routetest.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// dsh-unslop — HTTP route test with a stub ctx + fake req/res. Verifies the
|
|
2
|
-
//
|
|
1
|
+
// dsh-unslop — HTTP route test with a stub ctx + fake req/res. Verifies the routes the composer chip
|
|
2
|
+
// depends on: token bootstrap, per-session design tier, and the surface read/switch, including bearer
|
|
3
|
+
// auth and the loopback fence.
|
|
3
4
|
//
|
|
4
5
|
// node tests/routetest.mjs
|
|
5
6
|
|
|
@@ -35,11 +36,12 @@ while (Date.now() < deadline && (routes.size < 4 || tools.size < 10)) await new
|
|
|
35
36
|
ok('routes registered', routes.has('/unslop/api/token') && routes.has('/unslop/api/surface'), [...routes.keys()].join(','))
|
|
36
37
|
ok('mcp tools registered before surface checks', tools.size === 10, String(tools.size))
|
|
37
38
|
|
|
38
|
-
function call(handler, { method = 'GET', headers = {}, body } = {}) {
|
|
39
|
+
function call(handler, { method = 'GET', headers = {}, body, url = '/' } = {}) {
|
|
39
40
|
return new Promise((resolve) => {
|
|
40
41
|
const req = new EventEmitter()
|
|
41
42
|
req.method = method
|
|
42
43
|
req.headers = headers
|
|
44
|
+
req.url = url
|
|
43
45
|
const res = {
|
|
44
46
|
_status: 200, _body: '',
|
|
45
47
|
writeHead(status) { this._status = status },
|
|
@@ -52,6 +54,8 @@ function call(handler, { method = 'GET', headers = {}, body } = {}) {
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const loopback = { host: '127.0.0.1:11648' }
|
|
57
|
+
const S1 = 'session-one'
|
|
58
|
+
const S2 = 'session-two'
|
|
55
59
|
try {
|
|
56
60
|
const tok = await call(routes.get('/unslop/api/token'), { headers: loopback })
|
|
57
61
|
ok('token route 200 + token', tok.status === 200 && typeof tok.json.token === 'string' && tok.json.token.length > 20)
|
|
@@ -60,33 +64,58 @@ try {
|
|
|
60
64
|
ok('surface without bearer -> 401', noAuth.status === 401)
|
|
61
65
|
|
|
62
66
|
const auth = { ...loopback, authorization: `Bearer ${tok.json.token}` }
|
|
63
|
-
|
|
67
|
+
|
|
68
|
+
// ---- the tier is per session, and off is the default -------------------------------
|
|
69
|
+
const anonymousMode = await call(routes.get('/unslop/api/mode'), { headers: auth })
|
|
70
|
+
ok('mode GET without a session answers off + needsSession', anonymousMode.status === 200 && anonymousMode.json.mode === 'off' && anonymousMode.json.needsSession === true, JSON.stringify(anonymousMode.json))
|
|
71
|
+
ok('mode GET reports the three tiers', Array.isArray(anonymousMode.json.modes) && anonymousMode.json.modes.length === 3)
|
|
72
|
+
|
|
73
|
+
const anonymousPost = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'unslop' } })
|
|
74
|
+
ok('mode POST without a session -> 400', anonymousPost.status === 400 && /sessionId is required/.test(anonymousPost.json.error), JSON.stringify(anonymousPost.json))
|
|
75
|
+
|
|
76
|
+
const modeUrl = (sid) => (sid ? `/unslop/api/mode?sessionId=${encodeURIComponent(sid)}` : '/unslop/api/mode')
|
|
77
|
+
const surfaceUrl = (sid) => (sid ? `/unslop/api/surface?sessionId=${encodeURIComponent(sid)}` : '/unslop/api/surface')
|
|
78
|
+
const modeGet = (sid) => call(routes.get('/unslop/api/mode'), { headers: auth, url: modeUrl(sid) })
|
|
79
|
+
|
|
80
|
+
const offByDefault = await modeGet(S1)
|
|
81
|
+
ok('a session that never enabled is off', offByDefault.json.mode === 'off' && offByDefault.json.mcp.visible === 0, JSON.stringify(offByDefault.json.mcp))
|
|
82
|
+
|
|
83
|
+
const enable = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'unslop', sessionId: S1 } })
|
|
84
|
+
ok('mode POST enables that session', enable.status === 200 && enable.json.mode === 'unslop' && enable.json.sessionId === S1, JSON.stringify(enable.json))
|
|
85
|
+
ok('enabled session sees 4 tools', enable.json.mcp.visible === 4, JSON.stringify(enable.json.mcp))
|
|
86
|
+
|
|
87
|
+
const stillOff = await modeGet(S2)
|
|
88
|
+
ok('the other session stays off', stillOff.json.mode === 'off' && stillOff.json.mcp.visible === 0, JSON.stringify(stillOff.json))
|
|
89
|
+
|
|
90
|
+
const backS1 = await modeGet(S1)
|
|
91
|
+
ok('mode persists for the session', backS1.json.mode === 'unslop')
|
|
92
|
+
|
|
93
|
+
// ---- surface tiers stay global ------------------------------------------------------
|
|
94
|
+
const get1 = await call(routes.get('/unslop/api/surface'), { headers: auth, url: surfaceUrl(S1) })
|
|
64
95
|
ok('surface GET -> 200', get1.status === 200 && get1.json.ok === true)
|
|
65
|
-
ok('surface GET reports
|
|
96
|
+
ok('surface GET reports the server tool count', get1.json.mcp.total === 4, JSON.stringify(get1.json.mcp))
|
|
66
97
|
|
|
67
|
-
const setCore = await call(routes.get('/unslop/api/surface'), { method: 'POST', headers: auth, body: { surface: 'core' } })
|
|
68
|
-
ok('surface POST core ->
|
|
98
|
+
const setCore = await call(routes.get('/unslop/api/surface'), { method: 'POST', headers: auth, url: surfaceUrl(S1), body: { surface: 'core' } })
|
|
99
|
+
ok('surface POST core -> 2 admitted, 2 visible', setCore.json.mcp.admitted === 2 && setCore.json.mcp.visible === 2, JSON.stringify(setCore.json.mcp))
|
|
69
100
|
ok('surface POST core persists name', setCore.json.surface === 'core')
|
|
70
101
|
|
|
71
|
-
const setAll = await call(routes.get('/unslop/api/surface'), { method: 'POST', headers: auth, body: { surface: 'all' } })
|
|
72
|
-
ok('surface POST all -> visible
|
|
73
|
-
|
|
74
|
-
// design mode: three tiers, and "off" also takes the MCP tools down
|
|
75
|
-
const modeGet = await call(routes.get('/unslop/api/mode'), { headers: auth })
|
|
76
|
-
ok('mode GET -> 200', modeGet.status === 200 && Array.isArray(modeGet.json.modes) && modeGet.json.modes.length === 3, JSON.stringify(modeGet.json.modes))
|
|
77
|
-
ok('mode default is unslop', modeGet.json.mode === 'unslop', String(modeGet.json.mode))
|
|
102
|
+
const setAll = await call(routes.get('/unslop/api/surface'), { method: 'POST', headers: auth, url: surfaceUrl(S1), body: { surface: 'all' } })
|
|
103
|
+
ok('surface POST all -> 4 visible', setAll.json.mcp.visible === 4)
|
|
78
104
|
|
|
79
|
-
const toMd3e = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'md3e' } })
|
|
105
|
+
const toMd3e = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'md3e', sessionId: S1 } })
|
|
80
106
|
ok('mode POST md3e -> 200', toMd3e.status === 200 && toMd3e.json.mode === 'md3e')
|
|
81
107
|
ok('md3e keeps tools visible', toMd3e.json.mcp.visible === 4, JSON.stringify(toMd3e.json.mcp))
|
|
82
|
-
const modeFile = await call(routes.get('/unslop/api/mode'), { headers: auth })
|
|
83
|
-
ok('mode persists md3e', modeFile.json.mode === 'md3e')
|
|
84
108
|
|
|
85
|
-
const toOff = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'off' } })
|
|
86
|
-
ok('mode off ->
|
|
87
|
-
|
|
109
|
+
const toOff = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'off', sessionId: S1 } })
|
|
110
|
+
ok('mode off -> that session sees nothing', toOff.json.mcp.visible === 0, JSON.stringify(toOff.json.mcp))
|
|
111
|
+
|
|
112
|
+
const badMode = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'nope', sessionId: S1 } })
|
|
88
113
|
ok('mode POST invalid -> 400', badMode.status === 400)
|
|
89
|
-
|
|
114
|
+
|
|
115
|
+
const badSession = await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'unslop', sessionId: ' ' } })
|
|
116
|
+
ok('mode POST blank session -> 400', badSession.status === 400)
|
|
117
|
+
|
|
118
|
+
await call(routes.get('/unslop/api/mode'), { method: 'POST', headers: auth, body: { mode: 'unslop', sessionId: S1 } })
|
|
90
119
|
|
|
91
120
|
const badHost = await call(routes.get('/unslop/api/surface'), { headers: { host: 'evil.example.com', authorization: `Bearer ${tok.json.token}` } })
|
|
92
121
|
ok('non-loopback host -> 403', badHost.status === 403)
|