dsh-prompt-pocket 1.0.1 → 1.0.3
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 +50 -15
- package/README.zh.md +50 -15
- package/client.js +78 -0
- package/index.js +54 -0
- package/package.json +1 -1
- package/scripts/smoke.mjs +38 -0
package/README.md
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
# dsh-prompt-pocket
|
|
2
2
|
|
|
3
|
-
**A prompt pocket
|
|
3
|
+
**A prompt pocket for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness): one keystroke saves what you were typing, one click puts it back at the caret.** It lives as a 24px dot in the corner, so the layout never grows a sidebar, a chip row, or a panel that shifts the conversation.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Site: **[dshtoolbox.com/plugins/dsh-prompt-pocket](https://www.dshtoolbox.com/plugins/dsh-prompt-pocket/)** · 中文页: [dshtoolbox.com/zh/plugins/dsh-prompt-pocket](https://www.dshtoolbox.com/zh/plugins/dsh-prompt-pocket/) · npm: [dsh-prompt-pocket](https://www.npmjs.com/package/dsh-prompt-pocket)
|
|
8
|
+
|
|
9
|
+
## Why it exists
|
|
10
|
+
|
|
11
|
+
Prompt libraries ask for a title, tags, a folder and a panel before they will keep a sentence. By then you have forgotten the sentence. This one keeps the sentence.
|
|
12
|
+
|
|
13
|
+
## What it does that others do not
|
|
14
|
+
|
|
15
|
+
- **`Ctrl+Shift+S` saves without a dialog.** The selection if there is one, the whole draft otherwise. No title, no tags, no “where should this go”.
|
|
16
|
+
- **The confirmation appears beside the dot even when the panel is closed** — with a one-click move to the other drawer and a button to rewrite the prompt.
|
|
17
|
+
- **Insert is revision-guarded, not string concatenation.** A quote chip or attachment you already had stays where it is, the insert is one undo step, and focus returns to the composer.
|
|
18
|
+
- **Two drawers split by workspace, not by session.** Sessions get archived and forked; a prompt pinned to one session loses its home. A bare session falls back to General instead of showing an empty drawer.
|
|
19
|
+
- **✦ writes a DSH prompt, it does not paraphrase.** Variables, paths, URLs and code blocks are kept byte-for-byte, nothing is invented, and filler is forbidden by the instruction. A failed or empty result never replaces your text; accepting a rewrite keeps the old one in `prior`.
|
|
20
|
+
- **One click on an assistant reply keeps it verbatim** as source material, read from the session log — text blocks only, tool calls never leak in.
|
|
21
|
+
- **The agent shares the same pocket** through the `prompt_stash` tool, scoped to the drawers so one project's prompts do not show up in another's answer.
|
|
22
|
+
- **Export and import as one JSON file.** The panel exports every prompt and merges an import by id, keeping the newer copy; nothing local is deleted by an import. It is the first step toward syncing two machines through a private git repository.
|
|
23
|
+
- **500 prompts, least recently used dropped, one JSON file, atomic writes, no runtime dependencies, no account.** Nothing leaves the machine except the one model call you explicitly ask for.
|
|
24
|
+
|
|
25
|
+

|
|
6
26
|
|
|
7
27
|
## Install
|
|
8
28
|
|
|
@@ -10,27 +30,42 @@
|
|
|
10
30
|
dsh plugin --profile web add dsh-prompt-pocket
|
|
11
31
|
```
|
|
12
32
|
|
|
13
|
-
Restart the host once, then force-reload the page
|
|
33
|
+
Restart the host once so the route, the tool and the client bundle register, then force-reload the page with `Ctrl+Shift+R`. From a checkout instead:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/FindSomeSkills/dsh-prompt-pocket
|
|
37
|
+
cd dsh-prompt-pocket
|
|
38
|
+
dsh plugin --profile web add .
|
|
39
|
+
```
|
|
14
40
|
|
|
15
41
|
## Use
|
|
16
42
|
|
|
17
|
-
| Action |
|
|
43
|
+
| Action | How |
|
|
18
44
|
| --- | --- |
|
|
19
|
-
| Save selection
|
|
20
|
-
| Open the pocket | `Ctrl+Shift+P
|
|
21
|
-
|
|
|
22
|
-
|
|
|
45
|
+
| Save the selection or the draft | `Ctrl+Shift+S` |
|
|
46
|
+
| Open or close the pocket | `Ctrl+Shift+P`, or click the dot |
|
|
47
|
+
| Move the dot | Drag it; the position is remembered per browser |
|
|
48
|
+
| Insert a prompt at the caret | `Enter`, or click the row |
|
|
49
|
+
| Replace the whole draft | `Alt+Enter` while a row is selected |
|
|
50
|
+
| Walk the list | `↑` `↓` (wraps around), `Esc` closes |
|
|
51
|
+
| Move a prompt between drawers | `⇄` on the row |
|
|
52
|
+
| Delete | `×` on the row |
|
|
53
|
+
| Rewrite the prompt for DSH | `✦`, or the button on the save confirmation |
|
|
54
|
+
| Save an assistant reply | `⤓` in the reply action row |
|
|
23
55
|
|
|
24
|
-
|
|
56
|
+
## Where the data lives
|
|
25
57
|
|
|
26
|
-
|
|
58
|
+
`$DSH_HOME/dsh-prompt-stash/store.json`, by default `~/.dsh/dsh-prompt-stash/store.json`. One file for every profile and every browser pointed at this host; writes go through a temporary file and a rename, and a damaged file is renamed to `.corrupt-<timestamp>.bak` instead of blocking the panel.
|
|
27
59
|
|
|
28
|
-
##
|
|
60
|
+
## Requirements
|
|
29
61
|
|
|
30
|
-
|
|
62
|
+
DeepSeek Harness `>= 0.2.0-rc.1` and a Web profile — the pocket renders inside the composer. Windows, macOS and Linux run the same code; the interface language follows the DSH setting. The desktop client is untested.
|
|
31
63
|
|
|
32
|
-
|
|
64
|
+
## Links
|
|
33
65
|
|
|
34
|
-
|
|
66
|
+
- Product page: https://www.dshtoolbox.com/plugins/dsh-prompt-pocket/
|
|
67
|
+
- Chinese page: https://www.dshtoolbox.com/zh/plugins/dsh-prompt-pocket/
|
|
68
|
+
- npm: https://www.npmjs.com/package/dsh-prompt-pocket
|
|
69
|
+
- Manual: [docs/DETAIL.md](docs/DETAIL.md) (English) · [docs/DETAIL.zh.md](docs/DETAIL.zh.md) (中文)
|
|
35
70
|
|
|
36
|
-
MIT
|
|
71
|
+
MIT.
|
package/README.zh.md
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
# dsh-prompt-pocket
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 用的提示词口袋:一个快捷键存下你正在打的字,一次点击把它插回光标处。** 它就是角落里一枚 24px 的圆点,界面不会因此长出一条侧栏、一排胶囊,或者一个挤压对话的面板。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
站点:**[dshtoolbox.com/zh/plugins/dsh-prompt-pocket](https://www.dshtoolbox.com/zh/plugins/dsh-prompt-pocket/)** · English: [dshtoolbox.com/plugins/dsh-prompt-pocket](https://www.dshtoolbox.com/plugins/dsh-prompt-pocket/) · npm: [dsh-prompt-pocket](https://www.npmjs.com/package/dsh-prompt-pocket)
|
|
8
|
+
|
|
9
|
+
## 为什么做这个
|
|
10
|
+
|
|
11
|
+
提示词库要先让你起标题、打标签、建文件夹、开面板,然后才肯收下一句话。等你填完,那句话已经忘了。这个不填,直接收。
|
|
12
|
+
|
|
13
|
+
## 别处没有的几件事
|
|
14
|
+
|
|
15
|
+
- **`Ctrl+Shift+S` 存,不弹窗。** 有选中存选中,没选中存整段草稿。不起标题、不选标签、不问放哪。
|
|
16
|
+
- **面板关着也能看见存到哪了。** 圆点旁边出一条两秒的提示,带「改存另一档」和「写成 DSH 提示词」两个按钮。
|
|
17
|
+
- **插入走输入框的修订号保护,不是拼字符串。** 你已经插的引用 chip、挂的附件都留在原地,插入是一步撤销,插完焦点回到输入框。
|
|
18
|
+
- **两个抽屉按 workspace 分,不按会话分。** 会话会归档、会 fork,绑在会话上的提示词那天就没了家;没有 workspace 的裸会话退成通用,而不是给你一个空标签页。
|
|
19
|
+
- **✦ 写的是 DSH 提示词,不是同义改写。** `{{变量}}`、路径、URL、代码块原样保留,没说过的东西不编,套话在被禁之列。失败或空结果绝不覆盖原文;接受新版本时旧文本留在 `prior` 里,一键退回。
|
|
20
|
+
- **AI 回复一键存原文。** 从会话日志里只取 text 块,工具调用不会漏进提示词。
|
|
21
|
+
- **模型共用同一个口袋。** `prompt_stash` 工具读写同一份文件,且守分档,一个项目的提示词不会出现在另一个项目的回答里。
|
|
22
|
+
- **导出与导入就是一个 JSON 文件。** 面板能导出全部提示词;导入按 id 合并、保留较新的一份,且导入不会删掉本地任何东西。这是跨机器同步(私有 git 仓库)的第一步。
|
|
23
|
+
- **最多 500 条,满了淘汰最久没用的那条;一个 JSON 文件、原子写、没有运行时依赖、不需要账号。** 除了你主动点的那一次模型调用,什么都不出这台机器。
|
|
24
|
+
|
|
25
|
+

|
|
6
26
|
|
|
7
27
|
## 安装
|
|
8
28
|
|
|
@@ -10,27 +30,42 @@
|
|
|
10
30
|
dsh plugin --profile web add dsh-prompt-pocket
|
|
11
31
|
```
|
|
12
32
|
|
|
13
|
-
|
|
33
|
+
装完重启一次宿主,让路由、工具和客户端 bundle 注册;然后 `Ctrl+Shift+R` 强刷页面。要从源码装:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/FindSomeSkills/dsh-prompt-pocket
|
|
37
|
+
cd dsh-prompt-pocket
|
|
38
|
+
dsh plugin --profile web add .
|
|
39
|
+
```
|
|
14
40
|
|
|
15
41
|
## 用法
|
|
16
42
|
|
|
17
|
-
|
|
|
43
|
+
| 要做什么 | 怎么做 |
|
|
18
44
|
| --- | --- |
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
45
|
+
| 存选中内容或整段草稿 | `Ctrl+Shift+S` |
|
|
46
|
+
| 开 / 关面板 | `Ctrl+Shift+P`,或点圆点 |
|
|
47
|
+
| 挪圆点 | 按住拖;位置按浏览器记住 |
|
|
48
|
+
| 插到光标处 | `Enter`,或直接点那一行 |
|
|
49
|
+
| 整段替换 | 选中行后 `Alt+Enter` |
|
|
50
|
+
| 上下选 | `↑` `↓`(循环),`Esc` 关 |
|
|
51
|
+
| 在两个档之间挪 | 行尾 `⇄` |
|
|
52
|
+
| 删除 | 行尾 `×` |
|
|
53
|
+
| 写成 DSH 提示词 | 行尾 `✦`,或存完提示里的按钮 |
|
|
54
|
+
| 存一条 AI 回复 | 回复动作行的 `⤓` |
|
|
23
55
|
|
|
24
|
-
|
|
56
|
+
## 数据在哪
|
|
25
57
|
|
|
26
|
-
|
|
58
|
+
`$DSH_HOME/dsh-prompt-stash/store.json`,默认 `~/.dsh/dsh-prompt-stash/store.json`。一个文件,所有 profile、所有连到这台机器的浏览器共用;写入走临时文件 + rename,文件坏了会改名成 `.corrupt-<时间戳>.bak`,不会挡住面板。
|
|
27
59
|
|
|
28
|
-
##
|
|
60
|
+
## 运行要求
|
|
29
61
|
|
|
30
|
-
|
|
62
|
+
DeepSeek Harness `>= 0.2.0-rc.1`,Web profile——口袋渲染在输入框里。Windows、macOS、Linux 跑同一份代码;界面语言跟随 DSH 的设置。桌面客户端没验证过。
|
|
31
63
|
|
|
32
|
-
|
|
64
|
+
## 链接
|
|
33
65
|
|
|
34
|
-
|
|
66
|
+
- 产品页:https://www.dshtoolbox.com/zh/plugins/dsh-prompt-pocket/
|
|
67
|
+
- 英文页:https://www.dshtoolbox.com/plugins/dsh-prompt-pocket/
|
|
68
|
+
- npm:https://www.npmjs.com/package/dsh-prompt-pocket
|
|
69
|
+
- 使用手册:[docs/DETAIL.zh.md](docs/DETAIL.zh.md) · [docs/DETAIL.md](docs/DETAIL.md)
|
|
35
70
|
|
|
36
|
-
MIT
|
|
71
|
+
MIT。
|
package/client.js
CHANGED
|
@@ -42,6 +42,10 @@ window.__ModuleLoader__.load({
|
|
|
42
42
|
polishNoModel: '没有可用的模型,去设置里选一个',
|
|
43
43
|
polishSame: '原文已经是完整可执行的提示词,没有改',
|
|
44
44
|
countTotal: '共 {n} 条',
|
|
45
|
+
exportAll: '导出',
|
|
46
|
+
importAll: '导入',
|
|
47
|
+
importDone: '已合并:新增 {a},更新 {u}',
|
|
48
|
+
importFail: '导入失败,文件格式不对',
|
|
45
49
|
polishOriginal: '原文',
|
|
46
50
|
polishResult: 'DSH 提示词',
|
|
47
51
|
accept: '用这版',
|
|
@@ -80,6 +84,10 @@ window.__ModuleLoader__.load({
|
|
|
80
84
|
polishNoModel: 'No model is available; pick one in settings',
|
|
81
85
|
polishSame: 'The input is already an executable prompt; nothing changed',
|
|
82
86
|
countTotal: '{n} in total',
|
|
87
|
+
exportAll: 'Export',
|
|
88
|
+
importAll: 'Import',
|
|
89
|
+
importDone: 'Merged: {a} new, {u} updated',
|
|
90
|
+
importFail: 'Import failed: not a pocket file',
|
|
83
91
|
polishOriginal: 'Original',
|
|
84
92
|
polishResult: 'DSH prompt',
|
|
85
93
|
accept: 'Use this',
|
|
@@ -204,6 +212,7 @@ window.__ModuleLoader__.load({
|
|
|
204
212
|
const [active, setActive] = useState(0);
|
|
205
213
|
const searchRef = useRef(null);
|
|
206
214
|
const panelRef = useRef(null);
|
|
215
|
+
const fileRef = useRef(null);
|
|
207
216
|
const [lastId, setLastId] = useState(null);
|
|
208
217
|
const spanRef = useRef(null);
|
|
209
218
|
const dragRef = useRef(null);
|
|
@@ -325,6 +334,42 @@ window.__ModuleLoader__.load({
|
|
|
325
334
|
[workspaceId]
|
|
326
335
|
);
|
|
327
336
|
|
|
337
|
+
const doExport = useCallback(async () => {
|
|
338
|
+
const r = await fetch('/dsh-prompt-stash/export');
|
|
339
|
+
if (!r.ok) return;
|
|
340
|
+
const blob = await r.blob();
|
|
341
|
+
const a = document.createElement('a');
|
|
342
|
+
a.href = URL.createObjectURL(blob);
|
|
343
|
+
a.download = `dsh-prompt-pocket-${new Date().toISOString().slice(0, 10)}.json`;
|
|
344
|
+
a.click();
|
|
345
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
|
|
346
|
+
}, []);
|
|
347
|
+
|
|
348
|
+
const doImport = useCallback(
|
|
349
|
+
async (file) => {
|
|
350
|
+
try {
|
|
351
|
+
const parsed = JSON.parse(await file.text());
|
|
352
|
+
const entries = Array.isArray(parsed) ? parsed : parsed.entries;
|
|
353
|
+
if (!Array.isArray(entries)) throw new Error('entries');
|
|
354
|
+
const r = await fetch('/dsh-prompt-stash/import', {
|
|
355
|
+
method: 'POST',
|
|
356
|
+
headers: { 'content-type': 'application/json' },
|
|
357
|
+
body: JSON.stringify({ entries, workspaceId }),
|
|
358
|
+
});
|
|
359
|
+
const json = await r.json();
|
|
360
|
+
if (!r.ok) throw new Error(json && json.error);
|
|
361
|
+
if (json.entries) setData(json);
|
|
362
|
+
setFlash({
|
|
363
|
+
text: t('importDone').replace('{a}', String(json.merge ? json.merge.added : 0)).replace('{u}', String(json.merge ? json.merge.updated : 0)),
|
|
364
|
+
until: Date.now() + 6000,
|
|
365
|
+
});
|
|
366
|
+
} catch {
|
|
367
|
+
setFlash({ text: t('importFail'), until: Date.now() + 5000 });
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
[workspaceId, t]
|
|
371
|
+
);
|
|
372
|
+
|
|
328
373
|
const remove = useCallback(
|
|
329
374
|
async (id) => {
|
|
330
375
|
const r = await api('/mutate', {
|
|
@@ -836,6 +881,39 @@ window.__ModuleLoader__.load({
|
|
|
836
881
|
)
|
|
837
882
|
)
|
|
838
883
|
),
|
|
884
|
+
h(
|
|
885
|
+
'div',
|
|
886
|
+
{ style: { display: 'flex', gap: 12, padding: '2px 10px 6px', fontSize: 11 } },
|
|
887
|
+
h(
|
|
888
|
+
'button',
|
|
889
|
+
{
|
|
890
|
+
type: 'button',
|
|
891
|
+
onClick: doExport,
|
|
892
|
+
style: { background: 'transparent', border: 'none', padding: 0, color: 'var(--dsw-alias-brand-primary, #4aa3ff)', cursor: 'pointer', font: 'inherit' },
|
|
893
|
+
},
|
|
894
|
+
t('exportAll')
|
|
895
|
+
),
|
|
896
|
+
h(
|
|
897
|
+
'button',
|
|
898
|
+
{
|
|
899
|
+
type: 'button',
|
|
900
|
+
onClick: () => fileRef.current && fileRef.current.click(),
|
|
901
|
+
style: { background: 'transparent', border: 'none', padding: 0, color: 'var(--dsw-alias-brand-primary, #4aa3ff)', cursor: 'pointer', font: 'inherit' },
|
|
902
|
+
},
|
|
903
|
+
t('importAll')
|
|
904
|
+
),
|
|
905
|
+
h('input', {
|
|
906
|
+
ref: fileRef,
|
|
907
|
+
type: 'file',
|
|
908
|
+
accept: '.json,application/json',
|
|
909
|
+
style: { display: 'none' },
|
|
910
|
+
onChange: (ev) => {
|
|
911
|
+
const file = ev.target.files && ev.target.files[0];
|
|
912
|
+
if (file) doImport(file);
|
|
913
|
+
ev.target.value = '';
|
|
914
|
+
},
|
|
915
|
+
})
|
|
916
|
+
),
|
|
839
917
|
h(
|
|
840
918
|
'div',
|
|
841
919
|
{
|
package/index.js
CHANGED
|
@@ -171,6 +171,41 @@ async function mutate(body) {
|
|
|
171
171
|
return { ok: false, code: 'unknown-op' };
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
// Merge an exported file into the local store. Same id + newer usedAt wins;
|
|
175
|
+
// everything else is kept, so an import never deletes a local prompt.
|
|
176
|
+
async function importEntries(rawEntries) {
|
|
177
|
+
const store = await readStore();
|
|
178
|
+
const byId = new Map(store.entries.map((e) => [e.id, e]));
|
|
179
|
+
const incoming = normalize({ entries: Array.isArray(rawEntries) ? rawEntries : [] }).entries;
|
|
180
|
+
let added = 0;
|
|
181
|
+
let updated = 0;
|
|
182
|
+
let skipped = 0;
|
|
183
|
+
for (const entry of incoming) {
|
|
184
|
+
const current = byId.get(entry.id);
|
|
185
|
+
if (!current) {
|
|
186
|
+
byId.set(entry.id, entry);
|
|
187
|
+
added += 1;
|
|
188
|
+
} else if ((entry.usedAt || 0) > (current.usedAt || 0)) {
|
|
189
|
+
byId.set(entry.id, entry);
|
|
190
|
+
updated += 1;
|
|
191
|
+
} else {
|
|
192
|
+
skipped += 1;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const entries = evict([...byId.values()]);
|
|
196
|
+
await writeStore({ version: 1, entries });
|
|
197
|
+
return {
|
|
198
|
+
ok: true,
|
|
199
|
+
merge: {
|
|
200
|
+
received: Array.isArray(rawEntries) ? rawEntries.length : 0,
|
|
201
|
+
added,
|
|
202
|
+
updated,
|
|
203
|
+
skipped,
|
|
204
|
+
invalid: (Array.isArray(rawEntries) ? rawEntries.length : 0) - incoming.length,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
174
209
|
// The client action row only receives a message id; the text lives in the session log.
|
|
175
210
|
function replyText(sessions, sessionId, messageId) {
|
|
176
211
|
if (!sessions || !sessionId || !messageId) return null;
|
|
@@ -314,6 +349,25 @@ export function apply(ctx) {
|
|
|
314
349
|
return sendNode(res, 200, await snapshot(url.searchParams.get('workspace') || undefined));
|
|
315
350
|
}
|
|
316
351
|
|
|
352
|
+
if (url.pathname === '/dsh-prompt-stash/export') {
|
|
353
|
+
if (req.method !== 'GET') return sendNode(res, 405, { error: 'method not allowed' });
|
|
354
|
+
const store = await readStore();
|
|
355
|
+
return sendNode(res, 200, { version: 1, exportedAt: new Date().toISOString(), entries: store.entries });
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (url.pathname === '/dsh-prompt-stash/import') {
|
|
359
|
+
if (req.method !== 'POST') return sendNode(res, 405, { error: 'method not allowed' });
|
|
360
|
+
let body;
|
|
361
|
+
try {
|
|
362
|
+
body = JSON.parse(await readBody(req));
|
|
363
|
+
} catch {
|
|
364
|
+
return sendNode(res, 400, { error: 'malformed body' });
|
|
365
|
+
}
|
|
366
|
+
if (!Array.isArray(body && body.entries)) return sendNode(res, 400, { error: 'entries required' });
|
|
367
|
+
const result = await importEntries(body.entries);
|
|
368
|
+
return sendNode(res, 200, { ...result, ...(await snapshot(body.workspaceId)) });
|
|
369
|
+
}
|
|
370
|
+
|
|
317
371
|
if (url.pathname === '/dsh-prompt-stash/mutate') {
|
|
318
372
|
if (req.method !== 'POST') return sendNode(res, 405, { error: 'method not allowed' });
|
|
319
373
|
let body;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-prompt-pocket",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A prompt pocket that floats in the corner: save the draft or the selected text with Ctrl+Shift+S, click a saved prompt to drop it back at the caret.",
|
package/scripts/smoke.mjs
CHANGED
|
@@ -275,6 +275,44 @@ const pass = (n) => ok.push(n);
|
|
|
275
275
|
pass('有模型时把流式结果拼成润色文本');
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
// 18. export returns every entry
|
|
279
|
+
{
|
|
280
|
+
await post('/mutate', { op: 'save', text: 'exported prompt', scope: 'global' });
|
|
281
|
+
const r = await call('/dsh-prompt-stash/export');
|
|
282
|
+
assert.equal(r.status, 200);
|
|
283
|
+
assert.ok(Array.isArray(r.json.entries) && r.json.entries.length >= 1);
|
|
284
|
+
assert.equal(typeof r.json.exportedAt, 'string');
|
|
285
|
+
pass('导出的文件带上全部条目和时间');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 19. import merges by id: one new, one newer version, one invalid
|
|
289
|
+
{
|
|
290
|
+
const before = await call('/dsh-prompt-stash/state');
|
|
291
|
+
const local = before.json.entries[0];
|
|
292
|
+
const r = await post('/dsh-prompt-stash/import', {
|
|
293
|
+
entries: [
|
|
294
|
+
{ ...local, text: 'updated by import', usedAt: local.usedAt + 10000 },
|
|
295
|
+
{ id: 'imported-1', text: 'a prompt from another machine', scope: 'global', usedAt: Date.now() },
|
|
296
|
+
{ text: '' },
|
|
297
|
+
],
|
|
298
|
+
});
|
|
299
|
+
assert.equal(r.status, 200);
|
|
300
|
+
assert.equal(r.json.merge.added, 1);
|
|
301
|
+
assert.equal(r.json.merge.updated, 1);
|
|
302
|
+
assert.equal(r.json.merge.invalid, 1);
|
|
303
|
+
const after = await call('/dsh-prompt-stash/state');
|
|
304
|
+
assert.ok(after.json.entries.some((e) => e.text === 'updated by import'));
|
|
305
|
+
assert.ok(after.json.entries.some((e) => e.id === 'imported-1'));
|
|
306
|
+
pass('导入按 id 合并:新增、更新、无效各计一次');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// 20. import without an entries array is refused
|
|
310
|
+
{
|
|
311
|
+
const r = await post('/dsh-prompt-stash/import', { entries: 'nope' });
|
|
312
|
+
assert.equal(r.status, 400);
|
|
313
|
+
pass('导入缺数组时 400');
|
|
314
|
+
}
|
|
315
|
+
|
|
278
316
|
await fs.rm(tmp, { recursive: true, force: true });
|
|
279
317
|
if (process.env.DSH_HOME === tmp) delete process.env.DSH_HOME;
|
|
280
318
|
|