dsh-workspace-scratch 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,221 @@
1
- # Temporary Holding Version
1
+ # dsh-workspace-scratch
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
+ 一个 DeepSeek Harness(DSH)插件:让 **每次会话都在工作区根目录创建 `.dsh` 目录**,把临时文件和记忆文件都收进去,工作区本身不再被污染。
4
+
5
+ ## 功能
6
+
7
+ 会话开始(插件加载时已有的 agent、以及之后每个 `agent/created`)时,在工作区根目录建立:
8
+
9
+ ```
10
+ <workspace>/.dsh/
11
+ ├── .gitignore # 内容为 `*`,保证 .dsh 里的东西不进版本库
12
+ ├── tmp/
13
+ │ └── <session-id>/ # 本次会话的临时文件(脚本、中间产物、下载、日志、截图)
14
+ └── memory/ # 跨会话保留的记忆条目
15
+ ├── MEMORY.md # 自动维护的记忆索引
16
+ └── *.md # 每条记忆一个 markdown 文件
17
+ ```
18
+
19
+ 另外:
20
+
21
+ - 若工作区是 git 仓库,自动往 `.git/info/exclude` 追加 `/.dsh/`(不改动被跟踪的 `.gitignore`)。
22
+ - `tmp/<session-id>/` 超过 `retentionDays` 天未变动会在会话启动时自动清理(当前会话目录永远保留)。
23
+ - 注册 `scratch` 与 `memory` 两个模型工具,路径被强制限制在对应目录内,`../../` 之类越界路径直接报错。
24
+ - 注入一段系统提示词说明 + 一行运行时上下文(当前会话的 scratch / memory 绝对路径),让模型知道该往哪里写。
25
+
26
+ ## 安装(已发布到 npm)
27
+
28
+ **插件已发布**:`dsh-workspace-scratch@0.2.1` → https://www.npmjs.com/package/dsh-workspace-scratch
29
+
30
+ ### 通过官方 Discover 安装
31
+
32
+ 在 DSH 里 **Plugins → Discover** 添加这个索引地址:
33
+
34
+ ```
35
+ https://unpkg.com/dsh-workspace-scratch@0.2.1/plugin-index.json
36
+ ```
37
+
38
+ 然后搜索 `工作区` / `workspace` / `scratch`,点安装。
39
+
40
+ > 该地址已实测返回 200 且无重定向(Discover 拒绝重定向),索引也通过官方
41
+ > `@deepseek-ai/dsh-plugin-market-index` 校验。带版本号意味着**每次发新版要换 URL**;
42
+ > 建好 GitHub 仓库后可改用 `raw.githubusercontent.com` 的稳定地址。
43
+
44
+ ### 直接安装
45
+
46
+ ```bash
47
+ dsh plugin --profile <profile> install dsh-workspace-scratch@0.2.1
48
+ ```
49
+
50
+ 或在对话里:
51
+
52
+ ```text
53
+ plugin_manager install_bundle target: "dsh-workspace-scratch@0.2.1"
54
+ ```
55
+
56
+ ## 本地开发安装
57
+
58
+ ```bash
59
+ # 1. 装进当前 profile(desktop)。也可以直接用 GUI 的插件页安装/启用。
60
+ dsh plugin --profile desktop install ~/.dsh/plugins/dsh-workspace-scratch
61
+
62
+ # 2. 重启该 profile 生效
63
+ ```
64
+
65
+ 离线自测(不需要启动 DSH):
66
+
67
+ ```bash
68
+ cd ~/.dsh/plugins/dsh-workspace-scratch
69
+ node --test "test/**/*.test.mjs"
70
+ ```
71
+
72
+ ## 配置
73
+
74
+ 下面这些字段可以直接写在 profile 的 `cordis.patch.yml`(行配置层)里;设置页写入的覆盖值优先级更高。
75
+ 未写的字段取默认值:
76
+
77
+ ```yaml
78
+ - id: workspace-scratch
79
+ name: dsh-workspace-scratch
80
+ config:
81
+ dirName: .dsh # 隐藏目录名,默认 .dsh
82
+ tmpDirName: tmp # 临时文件子目录,默认 tmp
83
+ memoryDirName: memory # 记忆子目录,默认 memory
84
+ retentionDays: 7 # 会话临时目录保留天数,0 表示不清理
85
+ writeGitIgnore: true # 写 .dsh/.gitignore(内容 `*`)
86
+ gitExclude: true # 往 .git/info/exclude 追加 /.dsh/
87
+ promptGuidance: true # 注入系统提示词与运行时上下文
88
+ tools: true # 注册 scratch / memory 工具
89
+ scratchTool: true # 单独开关 scratch 工具
90
+ memoryTool: true # 单独开关 memory 工具
91
+ ```
92
+
93
+ 非法配置(如 `retentionDays: -1`、`dirName: "../x"`、非布尔开关)在加载期直接抛错,不会带病运行。
94
+
95
+ ## 设置页(Settings → 工作区)
96
+
97
+ 插件在设置面板注册一页「工作区」,可直接改这些字段,**保存后下一条消息即生效,无需重启**:
98
+
99
+ | 字段 | 作用 |
100
+ |---|---|
101
+ | `dirName` | 隐藏目录名(默认 `.dsh`) |
102
+ | `retentionDays` | 会话临时目录保留天数,`0` 表示永不清理 |
103
+ | `writeGitIgnore` | 是否写 `.dsh/.gitignore`(内容 `*`) |
104
+ | `gitExclude` | 是否往 `.git/info/exclude` 追加 `/.dsh/` |
105
+ | `tools` | `scratch` / `memory` 工具总开关 |
106
+ | `scratchTool` / `memoryTool` | 分别开关两个工具 |
107
+ | `promptGuidance` | 是否注入系统提示词与运行时上下文 |
108
+
109
+ 配置是三层的浅合并,后者覆盖前者:
110
+
111
+ ```
112
+ 默认值 < profile 里的行配置(config:) < 设置页写入的覆盖值
113
+ ```
114
+
115
+ 设置页的覆盖值存在 **`$DSH_HOME/workspace-scratch/settings.json`**(默认 `~/.dsh/...`,权限 600),
116
+ 不写进工作区。「恢复默认」会删除该文件,让字段回落到行配置与内置默认值。
117
+
118
+ 界面上的按钮语义:
119
+
120
+ - **保存** —— 只提交改动过的字段,合并进已有覆盖值
121
+ - **恢复默认** —— 删除整个覆盖文件
122
+ - 页面顶部会显示设置文件路径、当前生效目录,以及是否有字段被界面覆盖
123
+
124
+ 非法值(如负数天数、带 `/` 的目录名)由 host 校验后拒绝,错误原文显示在页面上,草稿不会丢失。
125
+
126
+ ### 设置页 API
127
+
128
+ 设置页通过插件自己的路由读写,**复用 GUI 的认证闸门**(`connection.requestRejection`),
129
+ 与官方 `/api/*` 一样要求浏览器会话:
130
+
131
+ | 方法 | 路径 | 说明 |
132
+ |---|---|---|
133
+ | `GET` | `/workspace-scratch/api/state` | 返回三层配置、字段清单、设置文件路径与警告 |
134
+ | `POST` | `/workspace-scratch/api/config` | 合并保存覆盖值并热应用 |
135
+ | `POST` | `/workspace-scratch/api/reset` | 清空覆盖值;可传 `{keys:[...]}` 只清指定字段 |
136
+
137
+ 未认证请求返回 401,跨源请求返回 403。
138
+
139
+ ## 发新版(维护者)
140
+
141
+ 包已发布,日常只需发新版本:
142
+
143
+ ```bash
144
+ # 1. 改 package.json 的 version
145
+ # 2. 发布(prepublishOnly 会自动重建索引 + 跑全部测试)
146
+ npm publish
147
+ # 3. 更新索引 URL 里的版本号(README「安装」章节,以及告诉用户)
148
+ ```
149
+
150
+ `prepublishOnly` 的顺序是 `build:index && test`,所以带过期索引或测试失败的包不会发出去。
151
+
152
+ 发布需要 npm token 具备 **Bypass 2FA**;首包发布时 Packages 必须选 `All packages`
153
+ (包尚不存在时无法单独授权)。本机全局 registry 是 npmmirror 只读镜像,
154
+ 所以 `publishConfig.registry` 已固定为 `registry.npmjs.org`。
155
+
156
+ ### 索引与版本号
157
+
158
+ 索引里的 `publishTimestamp` 每次重建都会更新,`version` 取自 `package.json`,
159
+ `engines.dsh` 取自 manifest。**索引 URL 目前带版本号**,发新版必须换 URL;
160
+ 把 `plugin-index.json` 放进 GitHub 仓库并改用
161
+ `https://raw.githubusercontent.com/<你>/<repo>/main/plugin-index.json` 即可永久稳定。
162
+
163
+ ### 免 npm 的替代路径:git 源
164
+
165
+ 没有 npm 账号也能分发——索引支持 git 源,安装时固定到具体 commit:
166
+
167
+ ```bash
168
+ node scripts/build-index.mjs --source git \
169
+ --git-url https://github.com/<你>/dsh-workspace-scratch \
170
+ --commit <40 位 commit SHA>
171
+ ```
172
+
173
+ 对应安装参数是 `git+https://github.com/...git#<commit>`。git 源的包必须在仓库根,
174
+ 或在索引里用 `path` 指明子目录。
175
+
176
+ ## 工具
177
+
178
+ ### `scratch`
179
+
180
+ 会话私有临时目录(`.dsh/tmp/<session>/`),`path` 相对该目录:
181
+
182
+ | action | 说明 |
183
+ |---|---|
184
+ | `write` | 写文件(自动建父目录);`append: true` 追加 |
185
+ | `read` | 读文件,超过 64 KiB 截断并提示 |
186
+ | `list` | 递归列出临时目录,最多 200 项 |
187
+ | `delete` | 删除文件或子目录(拒绝删除会话目录本身) |
188
+
189
+ ### `memory`
190
+
191
+ 跨会话记忆(`.dsh/memory/`),每次保存后自动重建 `MEMORY.md` 索引:
192
+
193
+ | action | 说明 |
194
+ |---|---|
195
+ | `save` | 保存笔记,`name` 会规范成 `*.md` 文件名;`append: true` 追加 |
196
+ | `read` | 读某条笔记 |
197
+ | `list` | 输出记忆索引 |
198
+ | `search` | 在全部笔记里做大小写不敏感的行级搜索 |
199
+ | `delete` | 删除笔记并更新索引 |
200
+
201
+ ## 模型体验
202
+
203
+ - **系统提示词段**:一段固定文字(`order` 1750),说明临时文件与记忆文件必须写进 `.dsh`,并给出目录约定。
204
+ - **运行时上下文行**:`Session scratch directory: "<...>". Workspace memory directory: "<...>".`(`order` 130)。路径随会话走,不写死在系统提示词里,因此不会破坏 prompt 前缀缓存。
205
+
206
+ ## 安全性
207
+
208
+ - 所有路径先 `resolve` 再校验前缀,绝对路径和 `..` 越界都被拒绝。
209
+ - 会话根目录是文件系统根(如 `/`)时拒绝管理,避免把 `.dsh` 建到 `/` 下。
210
+ - 工作区根取会话记录的 `cwd`(原始项目目录),模型中途 `cd` 不会把 `.dsh` 挪到别处。
211
+ - 不做任何删除工作区文件的操作;`prune` 只清理 `.dsh/tmp/` 下过期的会话目录。
212
+
213
+ ## 卸载
214
+
215
+ 在 GUI 插件页停用/移除,或:
216
+
217
+ ```bash
218
+ dsh plugin --profile desktop remove dsh-workspace-scratch
219
+ ```
220
+
221
+ 插件停用后 `.dsh` 目录仍留在工作区(数据是用户的),需要时手动删除即可。
package/client.js ADDED
@@ -0,0 +1,382 @@
1
+ /**
2
+ * dsh-workspace-scratch client half — the Settings page.
3
+ *
4
+ * Authored directly in the DSH client module format
5
+ * (`window.__ModuleLoader__.load({ id, factory })`), the same delivery shape as
6
+ * the official UI bundles: the host serves this file at
7
+ * /plugins/dsh-workspace-scratch/client.js and the browser kernel loads it.
8
+ * It talks to its own host half over /workspace-scratch/api/*, so it imports
9
+ * nothing from `@deepseek-ai/*` beyond the baseline `react` module.
10
+ *
11
+ * Layout: a status line naming the effective settings file, then two groups —
12
+ * 目录与清理 (where files go, how long they live) and 工具与提示词 (what the
13
+ * model can use) — followed by Save / Reset. The page never decides validity
14
+ * on its own: the host validates and returns the authoritative state, and its
15
+ * error message is rendered verbatim.
16
+ */
17
+ window.__ModuleLoader__.load({
18
+ id: 'dsh-workspace-scratch',
19
+ factory(require) {
20
+ const React = require('react')
21
+ const h = React.createElement
22
+
23
+ /** Browser-only set of group ids the user collapsed. */
24
+ const OPEN_KEY = 'dsh-workspace-scratch/settings-open'
25
+
26
+ const css = `
27
+ .wss_page{display:flex;flex-direction:column;gap:16px;padding:0 4px 24px;font-size:13px}
28
+ .wss_head{display:flex;flex-direction:column;gap:4px}
29
+ .wss_title{font-weight:600;font-size:14px}
30
+ .wss_meta{font-size:12px;color:var(--dsw-alias-label-secondary,#888);word-break:break-all}
31
+ .wss_card{border:1px solid rgba(128,128,128,.3);border-radius:12px;overflow:hidden}
32
+ .wss_card_head{display:flex;align-items:center;gap:8px;width:100%;padding:10px 14px;background:transparent;border:0;color:inherit;font:inherit;cursor:pointer;text-align:left}
33
+ .wss_card_head:hover{background:rgba(128,128,128,.08)}
34
+ .wss_card_title{font-weight:600}
35
+ .wss_summary{margin-left:auto;font-size:12px;color:var(--dsw-alias-label-secondary,#888)}
36
+ .wss_chevron{display:inline-block;width:12px;transition:transform .12s ease;color:var(--dsw-alias-label-secondary,#888)}
37
+ .wss_chevron.open{transform:rotate(90deg)}
38
+ .wss_body{display:flex;flex-direction:column;gap:14px;padding:4px 14px 16px}
39
+ .wss_row{display:flex;align-items:flex-start;gap:12px;justify-content:space-between}
40
+ .wss_row_text{display:flex;flex-direction:column;gap:2px;min-width:0}
41
+ .wss_label{font-weight:500}
42
+ .wss_hint{font-size:12px;color:var(--dsw-alias-label-secondary,#888);line-height:1.45}
43
+ .wss_key{font-size:11px;padding:0 4px;border-radius:4px;background:rgba(128,128,128,.16);color:var(--dsw-alias-label-secondary,#888);margin-left:6px}
44
+ .wss_control{flex:0 0 auto;display:flex;align-items:center;gap:6px}
45
+ .wss_input{font:inherit;font-size:13px;padding:5px 8px;border-radius:8px;border:1px solid rgba(128,128,128,.4);background:transparent;color:inherit;width:110px;box-sizing:border-box}
46
+ .wss_input.wide{width:150px}
47
+ .wss_input.invalid{border-color:#c62828}
48
+ .wss_switch{position:relative;display:inline-flex;align-items:center;cursor:pointer}
49
+ .wss_switch input{position:absolute;opacity:0;width:0;height:0}
50
+ .wss_track{width:36px;height:20px;border-radius:10px;background:rgba(128,128,128,.45);transition:background .12s ease;display:inline-block;position:relative}
51
+ .wss_track::after{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:transform .12s ease}
52
+ .wss_switch input:checked + .wss_track{background:#1976d2}
53
+ .wss_switch input:checked + .wss_track::after{transform:translateX(16px)}
54
+ .wss_switch input:focus-visible + .wss_track{outline:2px solid #1976d2;outline-offset:2px}
55
+ .wss_switch input:disabled + .wss_track{opacity:.5}
56
+ .wss_footer{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding-top:4px}
57
+ .wss_btn{cursor:pointer;font:inherit;font-size:12px;padding:6px 14px;border-radius:8px;border:1px solid rgba(128,128,128,.5);background:transparent;color:inherit}
58
+ .wss_btn:hover:not(:disabled){background:rgba(128,128,128,.12)}
59
+ .wss_btn:disabled{opacity:.5;cursor:default}
60
+ .wss_btn.primary{border-color:transparent;background:#1976d2;color:#fff}
61
+ .wss_btn.primary:hover:not(:disabled){background:#1565c0}
62
+ .wss_dirty{font-size:12px;color:#ed6c02}
63
+ .wss_ok{font-size:12px;color:#2e7d32}
64
+ .wss_err{font-size:12px;color:#c62828;line-height:1.45}
65
+ .wss_warn{font-size:12px;color:#ed6c02;line-height:1.45;border:1px solid rgba(237,108,2,.4);border-radius:8px;padding:8px 10px}
66
+ .wss_note{font-size:12px;color:var(--dsw-alias-label-secondary,#888)}
67
+ `
68
+
69
+ /** Fetch JSON from the plugin's own host API. */
70
+ async function api(path, body) {
71
+ const init = body === undefined
72
+ ? { method: 'GET' }
73
+ : { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }
74
+ const resp = await fetch(`/workspace-scratch/api/${path}`, init)
75
+ const json = await resp.json().catch(() => ({ ok: false, message: `HTTP ${resp.status}` }))
76
+ return { ok: resp.ok && json.ok !== false, status: resp.status, body: json }
77
+ }
78
+
79
+ /** Read the collapsed-group set, tolerating unavailable storage. */
80
+ function readOpen() {
81
+ try {
82
+ const raw = window.localStorage.getItem(OPEN_KEY)
83
+ if (raw === null) return null
84
+ const parsed = JSON.parse(raw)
85
+ return Array.isArray(parsed) ? parsed : null
86
+ } catch {
87
+ return null
88
+ }
89
+ }
90
+
91
+ /** Persist the collapsed-group set. */
92
+ function writeOpen(ids) {
93
+ try {
94
+ window.localStorage.setItem(OPEN_KEY, JSON.stringify(ids))
95
+ } catch {
96
+ /* private mode: collapse state simply does not persist */
97
+ }
98
+ }
99
+
100
+ /** One labelled row with a control on the right. */
101
+ function Row(props) {
102
+ return h('div', { className: 'wss_row' },
103
+ h('div', { className: 'wss_row_text' },
104
+ h('span', { className: 'wss_label' },
105
+ props.label,
106
+ props.field === undefined ? null : h('code', { className: 'wss_key' }, props.field)),
107
+ props.hint === undefined ? null : h('span', { className: 'wss_hint' }, props.hint)),
108
+ h('div', { className: 'wss_control' }, props.children))
109
+ }
110
+
111
+ /** Theme-inheriting switch. */
112
+ function Switch(props) {
113
+ return h('label', { className: 'wss_switch' },
114
+ h('input', { type: 'checkbox', checked: props.checked, disabled: props.disabled, onChange: (event) => props.onChange(event.target.checked) }),
115
+ h('span', { className: 'wss_track', 'aria-hidden': 'true' }))
116
+ }
117
+
118
+ /** Collapsible card, one per group. */
119
+ function Card(props) {
120
+ return h('div', { className: 'wss_card' },
121
+ h('button', {
122
+ type: 'button',
123
+ className: 'wss_card_head',
124
+ onClick: props.onToggle,
125
+ 'aria-expanded': props.open,
126
+ },
127
+ h('span', { className: 'wss_chevron' + (props.open ? ' open' : ''), 'aria-hidden': 'true' }, '›'),
128
+ h('span', { className: 'wss_card_title' }, props.title),
129
+ h('span', { className: 'wss_summary' }, props.open ? '' : props.summary)),
130
+ props.open ? h('div', { className: 'wss_body' }, props.children) : null)
131
+ }
132
+
133
+ /** Form value per field, derived from one effective-config snapshot. */
134
+ function formOf(cfg) {
135
+ return {
136
+ dirName: cfg.dirName,
137
+ retentionDays: String(cfg.retentionDays),
138
+ writeGitIgnore: cfg.writeGitIgnore,
139
+ gitExclude: cfg.gitExclude,
140
+ promptGuidance: cfg.promptGuidance,
141
+ tools: cfg.tools,
142
+ scratchTool: cfg.scratchTool,
143
+ memoryTool: cfg.memoryTool,
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Exactly what Save posts. Kept as one function of `form` so the dirty
149
+ * marker compares like-for-like with the request, and a field can never be
150
+ * silently omitted from the payload while the panel reports success.
151
+ */
152
+ function payloadOf(form) {
153
+ const days = form.retentionDays.trim()
154
+ return {
155
+ dirName: form.dirName,
156
+ // A blank box leaves the stored value alone instead of sending 0,
157
+ // which is a meaningful value for retentionDays.
158
+ retentionDays: days === '' ? undefined : Number(days),
159
+ writeGitIgnore: !!form.writeGitIgnore,
160
+ gitExclude: !!form.gitExclude,
161
+ promptGuidance: !!form.promptGuidance,
162
+ tools: !!form.tools,
163
+ scratchTool: !!form.scratchTool,
164
+ memoryTool: !!form.memoryTool,
165
+ }
166
+ }
167
+
168
+ /** Stable comparison form of a payload, so ordering cannot fake a change. */
169
+ function canonical(payload) {
170
+ const entries = Object.entries(payload).filter(([, value]) => value !== undefined)
171
+ entries.sort((left, right) => (left[0] < right[0] ? -1 : 1))
172
+ return JSON.stringify(entries)
173
+ }
174
+
175
+ /** The Settings page. */
176
+ function WorkspaceScratchSection() {
177
+ const [state, setState] = React.useState(null)
178
+ const [form, setForm] = React.useState(null)
179
+ const [saved, setSaved] = React.useState(null)
180
+ const [busy, setBusy] = React.useState('')
181
+ const [message, setMessage] = React.useState(null)
182
+ const [loadError, setLoadError] = React.useState(null)
183
+ const [open, setOpen] = React.useState(() => {
184
+ const stored = readOpen()
185
+ return Array.isArray(stored) && stored.length > 0 ? stored : ['paths', 'capabilities']
186
+ })
187
+
188
+ const accept = React.useCallback((body) => {
189
+ setState(body)
190
+ const next = formOf(body.effective)
191
+ setForm(next)
192
+ setSaved(next)
193
+ }, [])
194
+
195
+ React.useEffect(() => {
196
+ let alive = true
197
+ api('state').then((result) => {
198
+ if (!alive) return
199
+ if (result.ok) accept(result.body)
200
+ else setLoadError(result.body?.message ?? `HTTP ${result.status}`)
201
+ }).catch((error) => {
202
+ if (alive) setLoadError(String(error))
203
+ })
204
+ return () => {
205
+ alive = false
206
+ }
207
+ }, [accept])
208
+
209
+ React.useEffect(() => {
210
+ const style = document.createElement('style')
211
+ style.setAttribute('data-workspace-scratch', '')
212
+ style.textContent = css
213
+ document.head.appendChild(style)
214
+ return () => style.remove()
215
+ }, [])
216
+
217
+ const toggleGroup = (id) => {
218
+ const next = open.includes(id) ? open.filter((entry) => entry !== id) : [...open, id]
219
+ setOpen(next)
220
+ writeOpen(next)
221
+ }
222
+
223
+ if (loadError !== null) {
224
+ return h('div', { className: 'wss_page' },
225
+ h('div', { className: 'wss_head' },
226
+ h('span', { className: 'wss_title' }, '工作区临时文件与记忆'),
227
+ h('span', { className: 'wss_meta' }, '读取配置失败,插件可能未激活。')),
228
+ h('div', { className: 'wss_err' }, loadError))
229
+ }
230
+ if (form === null) return h('div', { className: 'wss_page' }, h('span', { className: 'wss_meta' }, '加载中…'))
231
+
232
+ const set = (key) => (event) => setForm({ ...form, [key]: event.target.value })
233
+ const setBool = (key) => (value) => setForm({ ...form, [key]: value })
234
+ const dirty = saved !== null && canonical(payloadOf(form)) !== canonical(payloadOf(saved))
235
+ const toolCount = [form.scratchTool, form.memoryTool].filter(Boolean).length
236
+
237
+ const save = async () => {
238
+ setBusy('save')
239
+ setMessage(null)
240
+ const result = await api('config', payloadOf(form))
241
+ setBusy('')
242
+ if (result.ok) {
243
+ accept(result.body)
244
+ setMessage({ kind: 'ok', text: '已保存,下一条消息即按新设置生效。' })
245
+ } else {
246
+ // Keep the draft so nothing typed is lost; the host still holds the old value.
247
+ setMessage({ kind: 'err', text: result.body?.message ?? `保存失败(HTTP ${result.status})` })
248
+ }
249
+ }
250
+
251
+ const reset = async () => {
252
+ setBusy('reset')
253
+ setMessage(null)
254
+ const result = await api('reset', {})
255
+ setBusy('')
256
+ if (result.ok) {
257
+ accept(result.body)
258
+ setMessage({ kind: 'ok', text: '已恢复为默认/插件配置。' })
259
+ } else {
260
+ setMessage({ kind: 'err', text: result.body?.message ?? `重置失败(HTTP ${result.status})` })
261
+ }
262
+ }
263
+
264
+ const overridden = state === null ? [] : Object.keys(state.stored ?? {})
265
+ const daysInvalid = form.retentionDays.trim() !== '' && !/^\d+$/.test(form.retentionDays.trim())
266
+
267
+ return h('div', { className: 'wss_page' },
268
+ h('div', { className: 'wss_head' },
269
+ h('span', { className: 'wss_title' }, '工作区临时文件与记忆'),
270
+ h('span', { className: 'wss_hint' }, '每次会话在工作区根目录建立隐藏目录,临时文件与记忆都放进去,工作区本身保持干净。'),
271
+ h('span', { className: 'wss_meta' }, '设置文件:' + state.settingsFile),
272
+ h('span', { className: 'wss_meta' }, '当前目录:' + state.effective.dirName + '/{' + state.effective.tmpDirName + '/<会话>, ' + state.effective.memoryDirName + '}')),
273
+
274
+ (state.warnings ?? []).map((text, index) =>
275
+ h('div', { className: 'wss_warn', key: 'warn' + index }, text)),
276
+
277
+ h('div', { className: 'wss_note' },
278
+ overridden.length === 0
279
+ ? '全部字段来自插件配置(无界面覆盖)。'
280
+ : `已覆盖:${overridden.join('、')}`),
281
+
282
+ h(Card, {
283
+ title: '目录与清理',
284
+ summary: `保留 ${form.retentionDays || '?'} 天 · ${form.dirName}`,
285
+ open: open.includes('paths'),
286
+ onToggle: () => toggleGroup('paths'),
287
+ },
288
+ h(Row, {
289
+ label: '隐藏目录名',
290
+ field: 'dirName',
291
+ hint: '会话在哪个子目录下工作;改名只影响之后新建的会话。',
292
+ },
293
+ h('input', { className: 'wss_input wide', value: form.dirName, spellCheck: false, onChange: set('dirName') })),
294
+
295
+ h(Row, {
296
+ label: '临时文件保留天数',
297
+ field: 'retentionDays',
298
+ hint: '超期未改动的会话临时目录会在下次会话启动时清理;0 表示永不清理。',
299
+ },
300
+ h('input', {
301
+ className: 'wss_input' + (daysInvalid ? ' invalid' : ''),
302
+ value: form.retentionDays,
303
+ inputMode: 'numeric',
304
+ onChange: set('retentionDays'),
305
+ 'aria-invalid': daysInvalid,
306
+ })),
307
+
308
+ h(Row, {
309
+ label: '写 .gitignore',
310
+ field: 'writeGitIgnore',
311
+ hint: '在隐藏目录里放一个内容为 * 的 .gitignore,保证里面的文件不进版本库。',
312
+ },
313
+ h(Switch, { checked: form.writeGitIgnore, onChange: setBool('writeGitIgnore') })),
314
+
315
+ h(Row, {
316
+ label: '加入 .git/info/exclude',
317
+ field: 'gitExclude',
318
+ hint: 'git 仓库里额外把该目录加入本地排除清单,不改动被跟踪的 .gitignore。',
319
+ },
320
+ h(Switch, { checked: form.gitExclude, onChange: setBool('gitExclude') }))),
321
+
322
+ h(Card, {
323
+ title: '工具与提示词',
324
+ summary: form.tools ? `${toolCount} 个工具${form.promptGuidance ? ' · 提示词开启' : ''}` : '工具已关闭',
325
+ open: open.includes('capabilities'),
326
+ onToggle: () => toggleGroup('capabilities'),
327
+ },
328
+ h(Row, {
329
+ label: '注册 scratch / memory 工具',
330
+ field: 'tools',
331
+ hint: '总开关。关闭后模型无法直接读写这两个目录,但仍会创建目录。',
332
+ },
333
+ h(Switch, { checked: form.tools, onChange: setBool('tools') })),
334
+
335
+ h(Row, {
336
+ label: 'scratch 工具',
337
+ field: 'scratchTool',
338
+ hint: '按会话读写的临时文件目录(脚本、中间产物、日志、截图)。',
339
+ },
340
+ h(Switch, { checked: form.scratchTool, disabled: !form.tools, onChange: setBool('scratchTool') })),
341
+
342
+ h(Row, {
343
+ label: 'memory 工具',
344
+ field: 'memoryTool',
345
+ hint: '跨会话保留的记忆条目,自动维护 MEMORY.md 索引。',
346
+ },
347
+ h(Switch, { checked: form.memoryTool, disabled: !form.tools, onChange: setBool('memoryTool') })),
348
+
349
+ h(Row, {
350
+ label: '注入提示词指引',
351
+ field: 'promptGuidance',
352
+ hint: '告诉模型临时文件与记忆该往哪写,并在运行时上下文里给出本会话的绝对路径。',
353
+ },
354
+ h(Switch, { checked: form.promptGuidance, onChange: setBool('promptGuidance') }))),
355
+
356
+ h('div', { className: 'wss_footer' },
357
+ h('button', { className: 'wss_btn primary', onClick: save, disabled: busy !== '' || !dirty }, busy === 'save' ? '保存中…' : '保存'),
358
+ h('button', { className: 'wss_btn', onClick: reset, disabled: busy !== '' }, busy === 'reset' ? '重置中…' : '恢复默认'),
359
+ dirty ? h('span', { className: 'wss_dirty' }, '● 有未保存的修改') : null,
360
+ message === null ? null : h('span', { className: message.kind === 'ok' ? 'wss_ok' : 'wss_err' }, message.text)),
361
+
362
+ h('div', { className: 'wss_note' },
363
+ '目录名与保留天数改动只影响之后新建的会话;已有的隐藏目录不会自动迁移或删除。'))
364
+ }
365
+
366
+ return {
367
+ inject: ['slots'],
368
+ apply(ctx) {
369
+ // Park the registration on the plugin's fiber so unloading the plugin
370
+ // removes the page instead of leaving a stale entry behind.
371
+ const register = () => ctx.slots.inject('settings.section', () => ctx.slots.register({
372
+ name: 'settings.section',
373
+ id: 'workspace-scratch',
374
+ order: 55,
375
+ label: '工作区',
376
+ }, WorkspaceScratchSection))
377
+ if (ctx.effect) ctx.effect(register)
378
+ else register()
379
+ },
380
+ }
381
+ },
382
+ })
@@ -0,0 +1,6 @@
1
+ # Bundle patch layer: mount the workspace-scratch plugin (index.js via the
2
+ # package root export). The profile's own cordis.patch.yml stays the user's
3
+ # patch layer; this file ships with the package and is applied as a bundle.
4
+ - insert:
5
+ - id: workspace-scratch
6
+ name: 'dsh-workspace-scratch'
package/icon.svg ADDED
@@ -0,0 +1,12 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-label="Work area scratch and memory">
2
+ <title>Work area scratch and memory</title>
3
+ <!-- Color: DeepSeek brand blue #4176e6, the token DSH uses for alias-link
4
+ and state-business-primary. 4.23:1 on white and 4.31:1 on the dark
5
+ surface, so one literal color reads on both themes.
6
+ Shape: a compact directory taking ~80% of the box, so the icon carries
7
+ the same visual weight as its neighbours. -->
8
+ <g fill="none" stroke="#4176e6" stroke-linecap="round" stroke-linejoin="round">
9
+ <path d="M3.4 6.4a2.4 2.4 0 0 1 2.4-2.4h3.9l2.4 2.8h6.1a2.4 2.4 0 0 1 2.4 2.4v8.4a2.4 2.4 0 0 1-2.4 2.4H5.8a2.4 2.4 0 0 1-2.4-2.4z" stroke-width="2"/>
10
+ <circle cx="12.4" cy="13.6" r="2.5" fill="#4176e6" stroke="none"/>
11
+ </g>
12
+ </svg>