@nelsonlongxiang/dsh-prompt-templates 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/README_zh.md +11 -4
- package/cordis.patch.yml +6 -0
- package/docs/evolution-default.md +5 -3
- package/docs/self-check.md +1 -1
- package/docs/spec-event-inject.md +21 -0
- package/docs/test-plan-phase-c.md +15 -0
- package/lib/cli/database.js +3 -3
- package/lib/client/Library.js +21 -4
- package/lib/client/api.js +17 -0
- package/lib/client/locales.js +6 -0
- package/lib/client.js +63 -2
- package/lib/client.js.map +1 -1
- package/lib/event-inject.js +38 -8
- package/lib/event-store.js +58 -0
- package/lib/index.js +51 -8
- package/lib/inject.js +4 -1
- package/lib/lessons.js +453 -0
- package/lib/self-check.js +12 -12
- package/lib/store.js +25 -5
- package/lib/tool-registry.js +40 -0
- package/lib/types/client/api.d.ts +9 -0
- package/lib/types/client/locales.d.ts +6 -0
- package/lib/types/event-inject.d.ts +7 -0
- package/lib/types/event-store.d.ts +32 -0
- package/lib/types/index.d.ts +7 -2
- package/lib/types/inject.d.ts +2 -0
- package/lib/types/lessons.d.ts +192 -0
- package/lib/types/self-check.d.ts +1 -1
- package/lib/types/store.d.ts +9 -4
- package/lib/types/tool-registry.d.ts +41 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,9 @@ No Python toolchain required — since 0.3.0 the host half persists templates th
|
|
|
29
29
|
- **Search & scroll** — filter the list as you type, reliable scrolling for long collections
|
|
30
30
|
- **Drag to reposition, double-click to reset** — the panel remembers where you put it
|
|
31
31
|
- **Durable by design** — templates persist in SQLite through a pure-TS store (`node:sqlite`) owned by the host plugin and closed with its lifecycle
|
|
32
|
+
- **Card library and intervention log** (0.16) — templates carry an effective version; version packs (`packs/`) import as stored versions without switching what is live; every time template content enters a session a durable record keeps id, version, text hash, session, turn and step, never the bodies. See [library packs](docs/library-packs.md)
|
|
33
|
+
- **Wrap-up self-check and card casting** (0.17) — the self-check adds one step before a working session would end its turn; it is on by default since the owner decision of 2026-11-21 (on master, not yet in a published package — the 0.17.0/0.18.0 packages ship it off); opt out with `selfCheck.enabled: false`. `cast.enabled` (off by default) lets named plugins cast one card into a session. See [the self-check contract](docs/self-check.md)
|
|
34
|
+
- **Lessons and handoff notice** (0.18) — lessons are on by default since the same 2026-11-21 decision (master only; the 0.18.0 package ships them off; opt out with `lessons.enabled: false`) and let a session write one- or two-sentence lessons (its own session templates under the 体会 category) that are recalled in matching situations; the handoff notice follows the event-reminder switches (off by default): once an episode exhausts its reminders and repeats, one notice asks the session to stop self-correcting and hand over. Details: `docs/spec-lesson-inject.md` and `docs/release-notes-0.18.0.md` in the source repository
|
|
32
35
|
|
|
33
36
|
## Sharing (cross-instance copy)
|
|
34
37
|
|
|
@@ -45,10 +48,10 @@ Each template (global or session-scoped) carries its own **switch + interval N**
|
|
|
45
48
|
|
|
46
49
|
- The injected content arrives as one durable `<system-reminder>` user message recorded in the session log (source kind `prompt-template-schedule`), so replays and audits reconstruct exactly what the model saw
|
|
47
50
|
- A boundary round is never injected twice, even across restarts or step retries
|
|
48
|
-
- Config persists in the plugin's SQLite database (schema
|
|
51
|
+
- Config persists in the plugin's SQLite database (database schema v11 as of 0.18.0, including evolution enrollment; the gate is `SCHEMA_VERSION` in `src/store.ts`); `injectEnabled: false` in the patch config silences **scheduled injection only** — event reminders (below) have their own independent master switch `eventInject.enabled`
|
|
49
52
|
- Each template picks a delivery mode: **silent** (default, model context only) or **visible in chat** (rendered as a normal user message with a ⚙️ scheduled-injection header)
|
|
50
53
|
|
|
51
|
-
## Atelier evolution checkpoint (
|
|
54
|
+
## Atelier evolution checkpoint (since 0.15.0)
|
|
52
55
|
|
|
53
56
|
A session-scoped `工坊·演化自评估` template is provisioned once by default and scheduled every 100 user turns. Existing same-name global/session templates and user edits, disabling and deletion are preserved. This is a reminder, not migration execution or authorization. Set `evolutionAssessmentEnabled: false` to opt out. See [the lifecycle, counting and rollback contract](docs/evolution-default.md).
|
|
54
57
|
|
|
@@ -78,7 +81,7 @@ Placeholders `{{date}}` `{{time}}` `{{datetime}}` `{{weekday}}` `{{session}}` `{
|
|
|
78
81
|
```text
|
|
79
82
|
src/ TypeScript plugin (host half + browser half)
|
|
80
83
|
index.ts Host: owns the TS store, exposes the HTTP routes
|
|
81
|
-
store.ts Pure-TS store over node:sqlite (database schema
|
|
84
|
+
store.ts Pure-TS store over node:sqlite (database schema v11)
|
|
82
85
|
inject.ts Host: scheduled auto-injection on the pre-step waterfall
|
|
83
86
|
invariant.ts Host: registers the package's invariant companion
|
|
84
87
|
cli/ The sync CLI (export/diff/merge/import) shipped as bin
|
|
@@ -93,7 +96,7 @@ The store is pure TS inside the host half; no child process is spawned.
|
|
|
93
96
|
|
|
94
97
|
## Security
|
|
95
98
|
|
|
96
|
-
- Template **content** reaches a model request in exactly two ways: as ordinary user text the user chose to insert, or through scheduled auto-injection. User templates follow their saved switches; the
|
|
99
|
+
- Template **content** reaches a model request in exactly two ways: as ordinary user text the user chose to insert, or through scheduled auto-injection. User templates follow their saved switches; the Atelier evolution default (shipped since 0.15.0) is enabled at once-per-session creation unless the deployment opts out, and remains editable/disableable/deletable by the user. Each delivered injection is a durable session event. The wrap-up self-check (`selfCheck.enabled`) and lessons (`lessons.enabled`) are further injection paths, on by default on master since 2026-11-21 and turned off with `false` in deployment config; card casting (`cast.enabled`) stays off by default. Event reminders are a separate channel: they carry no template content, and their switch is independent of scheduled injection
|
|
97
100
|
- The panel talks to the host store over the Host's plugin routes only; no extra listener, no outbound network
|
|
98
101
|
|
|
99
102
|
## Database sync CLI
|
|
@@ -145,6 +148,8 @@ pnpm verify:release # alias of pnpm verify
|
|
|
145
148
|
|
|
146
149
|
`pnpm verify` is the gate to run before pushing. It does not boot a DeepSeek Harness process. In order:
|
|
147
150
|
|
|
151
|
+
> **Windows: run it from Git Bash.** Under a PowerShell/cmd parent shell `bash` resolves to WSL first, which strips Windows env vars; the offline release-script suite (`tests/release-script.test.ts`) then skips itself with one explanatory line (`RELEASE_FIXTURE_STUBS` arrives empty, #31). From Git Bash all 40 run.
|
|
152
|
+
|
|
148
153
|
1. **typecheck** — `tsc --noEmit` for the host project and the client project
|
|
149
154
|
2. **test:cli** — `node:test` over `tests/*.test.ts`: CLI sync, store rules, schema migration, inject helpers, client filters, and an in-process host check. That check mounts `apply()` on Cordis with a stand-in web server, drives the `/plugins/dsh-prompt-templates` routes (including inject-status), and runs the `agent/pre-step` listener against a fake session log
|
|
150
155
|
3. **build** — host `tsc`, client `tsc`, and the tsdown browser bundle
|
|
@@ -175,6 +180,8 @@ Pull-back verification uses ignored `tmp/release/run-*/` owned by this invocatio
|
|
|
175
180
|
|
|
176
181
|
- **Session templates need a current session** — with no session open, only global templates are reachable
|
|
177
182
|
- **Injections don't render in the chat transcript** — the DSH chat view omits injected context rows by design (they carry a non-`user` message source); see them in the trajectory tab. Templates with delivery mode **visible** are the exception: they render as ordinary user messages
|
|
183
|
+
- **Self-check, casting, lessons and handoff are not yet verified on a real host** — model behavior is NOT_RUN; since self-check and lessons now default on, validate in a separate `DSH_HOME` before upgrading a live host ([test plan](docs/test-plan-phase-c.md) §7)
|
|
184
|
+
- **Panel-sent cards record no turn or step** — intervention records from the panel's insert / send / interject keep `turn` and `step` null by design. Insert only places text in the composer and may never be sent, so it has no turn. For send and interject, the turn and step are known only once the host processes that message; the host exposes them only inside its pre-step event and has no per-session "current turn" lookup, so the record does not guess. Scheduled, event, cast and self-check records carry real turns
|
|
178
185
|
- **Use the published npm build for normal installation** — Git/source installations run a `prepare` build and require the development toolchain and dependencies. The documented verification gate uses public `@deepseek-ai/*` packages and requires no harness source checkout; direct Git-URL installation is not verified by that gate. Use `dsh plugin --profile <name> add @nelsonlongxiang/dsh-prompt-templates` for a prebuilt package.
|
|
179
186
|
|
|
180
187
|
## License
|
package/README_zh.md
CHANGED
|
@@ -29,6 +29,9 @@ dsh plugin --profile web add @nelsonlongxiang/dsh-prompt-templates
|
|
|
29
29
|
- **搜索与滚动**——边输入边过滤,长列表滚动可靠
|
|
30
30
|
- **拖拽定位、双击复位**——面板记住你放的位置
|
|
31
31
|
- **设计即持久**——模板经纯 TS 存储(`node:sqlite`)落 SQLite,由 host 插件持有并随其生命周期关闭
|
|
32
|
+
- **卡库与介入记录**(0.16)——模板带生效版本;版本包(`packs/`)导入只存为新版本,不切换正在用的版本;模板内容每次进入会话都留一条持久记录(标识、版本、文字哈希、会话、轮、步),不记正文。见[卡库导入](docs/library-packs.md)
|
|
33
|
+
- **收尾自查与投卡**(0.17)——收尾自查让有活的会话在本来结束的一轮多走一步;属主 2026-11-21 裁定改为默认开(已在 master,尚未随包发布,0.17.0/0.18.0 包里仍默认关),写 `selfCheck.enabled: false` 关闭。`cast.enabled`(默认关)让点名的插件向会话投一张卡。见[收尾自查合同](docs/self-check.md)
|
|
34
|
+
- **体会与交接通知**(0.18)——体会按同一裁定改为默认开(仅 master,0.18.0 包里默认关;写 `lessons.enabled: false` 关闭),让会话写下一两句体会(存为它自己的会话模板,归「体会」分类),同类情境下带回;交接通知跟随事件提醒的开关(默认关):提醒次数用完后同一问题再重复,发一次通知,请会话停止自行反复修正、交给属主。细节见源码仓的 `docs/spec-lesson-inject.md` 与 `docs/release-notes-0.18.0.md`
|
|
32
35
|
|
|
33
36
|
## 分享(跨实例复制)
|
|
34
37
|
|
|
@@ -45,10 +48,10 @@ dsh plugin --profile web add @nelsonlongxiang/dsh-prompt-templates
|
|
|
45
48
|
|
|
46
49
|
- 注入内容是一条持久的 `<system-reminder>` 用户消息,记入会话日志(source kind `prompt-template-schedule`),重放与审计可精确还原模型所见
|
|
47
50
|
- 同一边界轮绝不重复注入——跨重启、跨步骤重试都不例外
|
|
48
|
-
- 配置持久化在插件 SQLite 库(schema
|
|
51
|
+
- 配置持久化在插件 SQLite 库(0.18.0 起数据库 schema v11,含演化模板登记;以 `src/store.ts` 的 `SCHEMA_VERSION` 为准);patch 配置里的 `injectEnabled: false` 只关**定时注入**——事件提醒(见下)有独立总开关 `eventInject.enabled`,互不控制
|
|
49
52
|
- 每条模板可选交付模式:**静默**(默认,只进模型上下文)或**对话流可见**(以普通用户消息渲染,带 ⚙️ 定时注入标记)
|
|
50
53
|
|
|
51
|
-
## Atelier
|
|
54
|
+
## Atelier 演化自评估(0.15.0 起)
|
|
52
55
|
|
|
53
56
|
默认按会话补充 `工坊·演化自评估`,每100用户轮次调用 Agent Atelier 指引;已有同名模板、编辑、关闭和删除不被覆盖。仅提醒,不执行迁移或授予权限。可用 `evolutionAssessmentEnabled: false` 停用。首次历史边界不追补、升级/退出/回滚详见 [演化自评估合同](docs/evolution-default.md)。
|
|
54
57
|
|
|
@@ -78,7 +81,7 @@ dsh plugin --profile web add @nelsonlongxiang/dsh-prompt-templates
|
|
|
78
81
|
```text
|
|
79
82
|
src/ TypeScript 插件(host 面 + 浏览器面)
|
|
80
83
|
index.ts Host:持有 TS 存储,暴露 HTTP 路由
|
|
81
|
-
store.ts 纯 TS 存储(node:sqlite,数据库 schema
|
|
84
|
+
store.ts 纯 TS 存储(node:sqlite,数据库 schema v11)
|
|
82
85
|
inject.ts Host:挂在 pre-step waterfall 上的定时注入
|
|
83
86
|
invariant.ts Host:注册本包的 invariant 伴生插件
|
|
84
87
|
cli/ 随 bin 发布的同步 CLI(export/diff/merge/import)
|
|
@@ -92,7 +95,7 @@ cordis.patch.yml Bundle patch:挂插件行
|
|
|
92
95
|
|
|
93
96
|
## 安全
|
|
94
97
|
|
|
95
|
-
-
|
|
98
|
+
- 模板**内容**进入模型请求只有两条路:用户主动插入的普通用户文本,或经定时注入通道。用户模板按已保存的开关执行;0.15.0 起发布的 Atelier 演化默认项在每会话首次创建时启用,可由部署退出,用户仍可编辑、关闭或删除。每次实际投递均记为持久会话事件。收尾自查(`selfCheck.enabled`)与体会(`lessons.enabled`)是另外两条注入路径,master 上自 2026-11-21 起默认开,部署配置写 `false` 关闭;投卡(`cast.enabled`)仍默认关。事件提醒是独立通道:不携带模板内容,开关也与定时注入互不控制
|
|
96
99
|
- 面板仅经 Host 的插件路由访问 host 存储;无额外监听、无外联网络
|
|
97
100
|
|
|
98
101
|
## 数据同步 CLI
|
|
@@ -144,6 +147,8 @@ pnpm verify:release # pnpm verify 的别名
|
|
|
144
147
|
|
|
145
148
|
推送前跑 `pnpm verify`。它不启动 DeepSeek Harness 进程,顺序为:
|
|
146
149
|
|
|
150
|
+
> **Windows:从 Git Bash 运行。** 若父 shell 是 PowerShell/cmd,`bash` 会先解析到 WSL——WSL 剥掉 Windows 环境变量,release-script 离线套件(`tests/release-script.test.ts`)的夹具会因 `RELEASE_FIXTURE_STUBS` 为空而整套跳过并提示原因(#31);从 Git Bash 运行则 40 项全跑。
|
|
151
|
+
|
|
147
152
|
1. **typecheck** — host 与 client 两个工程的 `tsc --noEmit`
|
|
148
153
|
2. **test:cli** — `node:test` 跑 `tests/*.test.ts`:CLI 同步、store 规则、schema 迁移、注入纯函数、client 过滤,以及进程内 host 检查。该检查把 `apply()` 挂到 Cordis 上,用替身 web server 驱动 `/plugins/dsh-prompt-templates` 路由(含 inject-status),并对一份假会话日志跑 `agent/pre-step` 监听器
|
|
149
154
|
3. **build** — host `tsc`、client `tsc`、tsdown 浏览器 bundle
|
|
@@ -174,6 +179,8 @@ GitHub Actions(`.github/workflows/verify.yml`)在指向 `master` 的 push /
|
|
|
174
179
|
|
|
175
180
|
- **会话模板需要当前会话**——无会话打开时只能用全局模板
|
|
176
181
|
- **注入不在对话流中渲染**——DSH 对话视图按设计省略注入的 context 行(消息 source 非 `user`);可在轨迹 tab 查看。交付模式为"对话流可见"的模板是例外:以普通用户消息渲染
|
|
182
|
+
- **自查、投卡、体会与交接通知尚未在真实宿主上验证**——模型行为 NOT_RUN;自查与体会已改为默认开,升级在用的宿主前先在独立 `DSH_HOME` 验证([测试计划](docs/test-plan-phase-c.md) §7)
|
|
183
|
+
- **面板手动发卡的记录没有轮和步**——面板的插入、直发、插话所写的介入记录,`turn`、`step` 按设计为空。插入只是把文字放进输入框,可能根本不发,本来就没有所属轮次;直发与插话落在哪一轮、哪一步,要等宿主处理到那条消息才知道,而宿主只在每一步开始前的事件里给出轮与步,没有按会话查当前轮的接口,所以记录不去猜。按轮次、按事件、投卡与收尾自查的记录都带真实轮次
|
|
177
184
|
- **正式使用优先安装 npm 发布构建**——Git/源码安装会执行 `prepare` 构建,需要开发工具链和依赖。本仓所述验证门禁使用公网 `@deepseek-ai/*` 包,不需要 harness 源码检出;该门禁没有验证直接 Git-URL 安装。使用预构建包请运行 `dsh plugin --profile <name> add @nelsonlongxiang/dsh-prompt-templates`。
|
|
178
185
|
|
|
179
186
|
## 许可证
|
package/cordis.patch.yml
CHANGED
|
@@ -35,3 +35,9 @@
|
|
|
35
35
|
# maxAttempts: 3 — delivery attempts before a reminder is marked failed
|
|
36
36
|
# observationWindow: 200 — redacted observations kept per session
|
|
37
37
|
# ignoreTools: [] — tool names never observed
|
|
38
|
+
# Wrap-up self-check and lessons (ON by default since the 2026-11-21
|
|
39
|
+
# owner decision; write false to turn one off):
|
|
40
|
+
# selfCheck:
|
|
41
|
+
# enabled: true — selfcheck_write / selfcheck_conclude and the wrap-up check
|
|
42
|
+
# lessons:
|
|
43
|
+
# enabled: true — lesson_write, digest prompts and situational recall
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Atelier 演化自评估:默认会话模板 v2
|
|
1
|
+
# Atelier 演化自评估:默认会话模板 v2(0.15.0 起随插件发布)
|
|
2
2
|
|
|
3
3
|
## 合同
|
|
4
4
|
|
|
@@ -31,7 +31,7 @@ schema v6 新增 `evolution_defaults(session_id, template_id, source, version, e
|
|
|
31
31
|
|
|
32
32
|
- 本版本功能回滚:设置 `evolutionAssessmentEnabled:false`,仅停本功能补充/自动来源注入;不删模板,不改事件提醒。全部定时注入关闭用 `injectEnabled:false`。
|
|
33
33
|
- 单会话关闭:面板关闭或删除生成模板,不会再补。
|
|
34
|
-
- 包降级至仅支持 v5 的版本前,需停止写入并使用升级前的一致 SQLite 备份恢复;不得仅改 `user_version` 或删除表冒充回滚。模板 JSON
|
|
34
|
+
- 包降级至仅支持 v5 的版本前,需停止写入并使用升级前的一致 SQLite 备份恢复;不得仅改 `user_version` 或删除表冒充回滚。模板 JSON 不是完整运行态备份。回滚/部署均需单独授权,本说明不执行也不授权。
|
|
35
35
|
- 新宿主/全新数据库有独立登记。CLI JSON 只带模板/类目并保留其中的启用配置;经显式 dry-run/确认后,它能重建已删除模板(含原 ID),但不重置旧库登记,也不把登记复制到新库。在原库恢复相同 ID 后仍受自动来源总开关约束;在新库导入的行是显式用户配置,不因 description 文本变成受管理默认项。它不等于完整回退,也不能据此声称删除意图随 JSON 搬迁。
|
|
36
36
|
- 剪贴板分享导入是另一入口:新增项默认关闭,同名覆盖保留目标开关。不要把它与保留配置的 CLI 快照导入混为一谈。跨机迁移需另核启用策略及授权。
|
|
37
37
|
|
|
@@ -43,4 +43,6 @@ schema v6 新增 `evolution_defaults(session_id, template_id, source, version, e
|
|
|
43
43
|
|
|
44
44
|
本轮这些 store/CLI 与进程内宿主集成回归可运行;类型检查、完整构建及包门的精确候选结果在 PR #15 按提交记录。主干同步时包内链接门曾因缺少本说明 FAIL,补白名单后 PASS;本说明现在显式进入 npm 包并有安装内容校验。历史草稿的缺依赖状态不再描述当前工程环境。
|
|
45
45
|
|
|
46
|
-
真实 DSH profile 的持久送达、实际技能加载、模型执行/采纳、真实迁移/恢复、收益、macOS现场与当前头独立OPS:**NOT_RUN/未覆盖**。不能由测试、静态参考存在、注入消息或作者自述推出这些状态为 PASS
|
|
46
|
+
真实 DSH profile 的持久送达、实际技能加载、模型执行/采纳、真实迁移/恢复、收益、macOS现场与当前头独立OPS:**NOT_RUN/未覆盖**。不能由测试、静态参考存在、注入消息或作者自述推出这些状态为 PASS。
|
|
47
|
+
|
|
48
|
+
(2026-11-21 注:本文起草于 PR #15,原句「保持 Draft,不合并、发布、部署或启用生产模板」描述的是当时的 PR 状态;该功能已随 0.15.0 发布并默认开启。上面的 NOT_RUN 项仍然成立;在生产宿主上部署或回滚仍需单独授权。)
|
package/docs/self-check.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 收尾自查(第 2 期,PT-4)
|
|
2
2
|
|
|
3
|
-
依据 workbench-market 第 18 篇「自查模板」一节(属主裁定 R103~R106)。部署配置 `selfCheck.enabled`
|
|
3
|
+
依据 workbench-market 第 18 篇「自查模板」一节(属主裁定 R103~R106)。部署配置 `selfCheck.enabled` **默认开**(属主 2026-11-21 裁定:初始化配置对所有安装者默认启用,取代此前「默认关,启用需另外批准」);部署方写 `selfCheck.enabled: false` 关闭。
|
|
4
4
|
|
|
5
5
|
## 什么时候触发
|
|
6
6
|
|
|
@@ -140,6 +140,7 @@ src/
|
|
|
140
140
|
- 提醒之后,下一次相关调用的稳定指纹变了 → `signal: changed`
|
|
141
141
|
- 提醒之后同一模式又出现 → `signal: repeated`,修订号加 1
|
|
142
142
|
- 0.16(schema v8):同时 `repeated_after_reminder` 加 1,即「提醒后仍在重复」的次数。`signal` 在下一次提醒时清空,这个计数不清空,留给以后的观察者读;在 `GET …/event-episodes` 和面板的问题台账里都能看到。
|
|
143
|
+
- 交接(未发布,见 9.4):每问题的提醒次数用完、上次提醒后同一模式又出现、而且仍停在 `notified`(没人处置)时,插件不再沉默,而是发**一次**交接通知,说明已提醒几次、提醒后又重复几次,请把试过的做法和结果交给属主或评审。交接通知不算又一次提醒,不改问题的状态和计数。
|
|
143
144
|
- `applied` / `verified` / `ineffective` / `reverted` / `rejected` / `deferred` / `awaiting_authorization` 只通过审计接口设置,并且必须附证据引用(call id 或会话事件序号)。Agent 的口头自述不是证据。
|
|
144
145
|
- 宿主不能证明模型“读到”了提醒,所以不设 `consumed`;需要时在报告里写 UNKNOWN。
|
|
145
146
|
|
|
@@ -315,3 +316,23 @@ eventInject:
|
|
|
315
316
|
- `src/event-inject.ts`:`tools/result` 观察器与 pre-step 消费者
|
|
316
317
|
- `src/store.ts`:v4 → v5 迁移;`src/index.ts`:配置与审计路由
|
|
317
318
|
- 测试:`tests/event-features.test.ts`、`tests/event-store.test.ts`、`tests/event-host.test.ts`,以及 `tests/dsh-contract.test.ts` 的两条护栏
|
|
319
|
+
|
|
320
|
+
### 9.4 交接通知(未发布,分支 `feat/event-handoff`)
|
|
321
|
+
|
|
322
|
+
**为什么。** 原来每问题最多提醒 `max_per_episode` 次(默认 2)。提醒用完后同一模式再出现,插件只把 `repeated_after_reminder` 加一,然后不再出声:Agent 被告知过「查过仍解不开就交出去」,但属主那边没有任何信号,问题就悬着。依据是 agent-atelier 的设计草案(`docs/design/rsi-transformation-policy.md` 的 T2:自修两次仍复发就停止,交给属主或评审;该草案在分支 `docs/experience-theory-design` 上,尚未合并,不是现行规则)。
|
|
323
|
+
|
|
324
|
+
**什么时候发。** 同时满足:规则启用;问题仍是 `notified`(没被人工处置);`notify_count` 已达 `max_per_episode`;上次提醒之后又有新证据(`evidence_revision > notified_revision`);冷却已过;这个问题从没排过交接。
|
|
325
|
+
|
|
326
|
+
**发什么。** 一条「【工坊·交接|规则 …|证据修订 …】」:已提醒几次、提醒后仍重复几次、示例与证据引用,「插件不再就此提醒」,「请停止就此自行反复修正,把试过的做法和结果交给属主或评审」,以及不授权声明。与提醒同一套措辞约束:不出现 a2a 工具名,赋值不进提示词。按规则配置的模式投递(默认可见,属主在对话里看得到)。
|
|
327
|
+
|
|
328
|
+
**怎么记。**
|
|
329
|
+
|
|
330
|
+
- 走同一个待发记录与对账机制,计入每轮条数和字符预算。去重键是 `<会话>|<问题>|<规则@版本>|handoff`,不带证据修订号:同一问题、同一规则版本只发一次。
|
|
331
|
+
- 未送达时用同一个键重试,达到 `maxAttempts` 标 `failed`;**新证据不会把它标成 `superseded`**,因为后来的重复正是它要报告的事。
|
|
332
|
+
- 交接不调用 `prepare`:问题的 `notify_count`、`notified_revision`、`signal`、冷却和状态都不变。
|
|
333
|
+
- 审计路由 `GET …/event-episodes` 的每个问题多一个 `handoff` 字段:`none` / `due` / `pending` / `sent` / `failed`。`due` 只描述条件已满足;规则关着时不会发。
|
|
334
|
+
- 介入记录里交接单独记成 `event:<规则>:handoff`,和这条规则的普通提醒分开,便于区分「提醒过」和「交接过」。
|
|
335
|
+
|
|
336
|
+
**不做什么。** 不改问题终态(仍只由审计接口加证据设置),不自动起决策卡,不调用其他插件,不改模板;跟随事件提醒总开关和规则开关,默认关。面板问题台账暂不显示这个字段,留给后续。
|
|
337
|
+
|
|
338
|
+
测试:`tests/event-store.test.ts` 的 M04(最后一步从「什么都不发」改为「只发交接,不是第三次提醒」)与两个 T2 用例;`tests/event-host.test.ts` 断言路由带 `handoff`。
|
|
@@ -181,3 +181,18 @@ M04/M05 验的是**原状态续接**:锁定数据库、session_id、会话日
|
|
|
181
181
|
3. 如需代码降版,先核对旧代码的 schema 支持范围,在独立副本验证;降版不等于数据库降级,不删事件表强行兼容,不覆盖唯一证据。
|
|
182
182
|
4. 核对生产宿主、权限、配置与库均未修改。清理限已授权且无唯一证据的本轮临时物,不自动删历史保全或他人现场。
|
|
183
183
|
5. Phase D(受控试用)仍由属主依报告裁定;本流程不含试用、发布或生产部署。
|
|
184
|
+
|
|
185
|
+
## 7. 交接通知与体会(0.18.0 起)
|
|
186
|
+
|
|
187
|
+
0.18.0 发布的两项功能不在上面的 M/B 用例里,在同一测试宿主上按下面补测。边界、证据(§1.5)与收尾(§6)同上;每项用 §1.2 的新实验单元。交接通知跟随事件提醒的开关,默认关;体会在 0.18.0 包里默认关,属主 2026-11-21 裁定(#40)后 master 上默认开,测哪个版本就按哪个版本的默认值。真实宿主与模型行为在取得证据前一律 NOT_RUN。依据:[spec-event-inject.md](spec-event-inject.md) §9.4、仓库中的 `docs/spec-lesson-inject.md` §11–§14 与 `docs/release-notes-0.18.0.md`(这两份不随 npm 包发布)。
|
|
188
|
+
|
|
189
|
+
| ID | 操作 | 通过判据 | 失败或无法执行时 |
|
|
190
|
+
|---|---|---|---|
|
|
191
|
+
| H01 | 开事件提醒总开关与 `repeated-failure`;按 M02 的夹具让同一失败模式反复出现,直到该问题的提醒次数用完,过冷却后再出现一次 | 只发**一次**「【工坊·交接|…】」通知;`GET …/event-episodes` 中该问题的 `handoff` 依次经 `due`、`pending` 到 `sent`;之后不再就此出声;问题的提醒计数、冷却与状态不因交接改变 | 记 FAIL,附日志 |
|
|
192
|
+
| H02 | 同 H01,但在交接通知写入日志前停止宿主,再启动续接 | 重启后用同一个键重试并只送达一次;不重复发送 | 停机时机掌握不住记 NOT_RUN |
|
|
193
|
+
| L01 | 测 0.18.0 包时在测试 profile 设 `lessons.enabled: true`(含 #40 的版本不写这一项即为开);让同一目标先失败后成功 | 下一步出现消化提示;Agent 用 `lesson_write` 写下的「体会·N」出现在面板「体会」分类下,可见、可改、可删;不写也被允许 | 记 FAIL |
|
|
194
|
+
| L02 | 接 L01,制造同一工具、同样准备或同一目标的情境 | 下一次模型决策前带回那条体会;冷却内不重复唤起;不命中时不注入 | 记 FAIL |
|
|
195
|
+
| L03 | 用 `PATCH /plugins/dsh-prompt-templates/lessons/<template_id>`(`{"pinned": true}`)标常驻,再分别触发会话恢复与上下文压缩;最后用户主动清空上下文 | 恢复、压缩后各装载一次常驻体会(合计 ≤400 字、条数 ≤ `maxPinned`);清空上下文时不装载。本项同时核实宿主压缩后是否真的发出 `agent/created`(`source: compact`),目前只有类型声明为据 | 宿主不发该事件时记 FAIL 并附证据,这会改变 `lessons.enabled` 的启用前提;没有压缩入口记 NOT_RUN |
|
|
196
|
+
| D01 | 新单元,所有开关保持默认 | 交接通知零写入、零注入;0.18.0 包上体会也零写入、零注入(含 #40 的版本体会默认开,不在此判) | 记 FAIL |
|
|
197
|
+
| D02 | 新单元,部署配置写 `lessons.enabled: false` 与 `selfCheck.enabled: false` | 体会与自查的表、日志零写入、零注入;如 Agent 仍能看到并调用 `lesson_write`、`selfcheck_write`、`selfcheck_conclude`,调用也不产生写入(记下工具是否可见) | 记 FAIL |
|
|
198
|
+
|
package/lib/cli/database.js
CHANGED
|
@@ -9,7 +9,7 @@ import { createSnapshot, diffSnapshots } from "./model.js";
|
|
|
9
9
|
* v5 event tables, v6 the stored master switch / evolution enrollment, and
|
|
10
10
|
* v7 the combined migration all hold runtime state that is never exported.
|
|
11
11
|
*/
|
|
12
|
-
const SUPPORTED_DB_VERSIONS = [4, 5, 6, 7, 8, 9, 10];
|
|
12
|
+
const SUPPORTED_DB_VERSIONS = [4, 5, 6, 7, 8, 9, 10, 11];
|
|
13
13
|
/** A valid operation blocked by a safety/business gate (CLI exit 1). */
|
|
14
14
|
export class ImportBlockedError extends Error {
|
|
15
15
|
constructor(message) { super(message); this.name = 'ImportBlockedError'; }
|
|
@@ -21,7 +21,7 @@ export function exportDatabase(dbPath, filters = {}) {
|
|
|
21
21
|
db.exec('PRAGMA query_only=ON');
|
|
22
22
|
const version = Number(db.prepare('PRAGMA user_version').get().user_version);
|
|
23
23
|
if (!SUPPORTED_DB_VERSIONS.includes(version))
|
|
24
|
-
throw new Error(`${path} has schema version ${version}, expected 4 to
|
|
24
|
+
throw new Error(`${path} has schema version ${version}, expected 4 to 11`);
|
|
25
25
|
const clauses = [];
|
|
26
26
|
const args = [];
|
|
27
27
|
if (filters.scope !== undefined) {
|
|
@@ -116,7 +116,7 @@ export async function importDatabase(dbPath, incoming, options) {
|
|
|
116
116
|
db.exec(`PRAGMA busy_timeout=${options.busyTimeoutMs ?? 5000}`);
|
|
117
117
|
const version = Number(db.prepare('PRAGMA user_version').get().user_version);
|
|
118
118
|
if (!SUPPORTED_DB_VERSIONS.includes(version))
|
|
119
|
-
throw new Error(`${path} has schema version ${version}, expected 4 to
|
|
119
|
+
throw new Error(`${path} has schema version ${version}, expected 4 to 11`);
|
|
120
120
|
backupPath = resolve(options.backupOut ?? `${path}.${timestampName()}.bak`);
|
|
121
121
|
mkdirSync(dirname(backupPath), { recursive: true });
|
|
122
122
|
await backup(db, backupPath);
|
package/lib/client/Library.js
CHANGED
|
@@ -10,13 +10,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
10
10
|
*/
|
|
11
11
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
12
12
|
import { IconCopyOutlineRegular, IconDownloadOutlineRegular, IconEditOutlineRegular, IconGlobeOutlineRegular, IconPlusOutlineRegular, IconQueueOutlineRegular, IconSendOutlineRegular, IconTrashOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
13
|
-
import { recordManualIntervention } from "./api.js";
|
|
13
|
+
import { listLessonPins, recordManualIntervention, setLessonPinned } from "./api.js";
|
|
14
14
|
import { filterTemplateRows, searchableTemplateRows } from "./filter.js";
|
|
15
15
|
import { buildSharePayload, parseSharePayload, planShareImport } from "./share.js";
|
|
16
16
|
import { copyShareText } from "./clipboard.js";
|
|
17
17
|
import { GITHUB_REPOSITORY_URL, PLUGIN_VERSION, templateCountLabel } from "./meta.js";
|
|
18
18
|
import css from './Panel.module.css';
|
|
19
|
-
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onShare, onMakeGlobal, onToggleInject, sortable, onDragStart, onDropOn, t }) {
|
|
19
|
+
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onShare, onMakeGlobal, pin, onToggleInject, sortable, onDragStart, onDropOn, t }) {
|
|
20
20
|
const injectTitle = template.inject_enabled && template.inject_every !== null
|
|
21
21
|
? `${t('panel.inject')} · ${template.inject_every}${template.mode === 'visible' ? ' · ' + t('panel.modeVisible') : ''}`
|
|
22
22
|
: t('panel.inject');
|
|
@@ -26,7 +26,7 @@ function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete
|
|
|
26
26
|
e.preventDefault();
|
|
27
27
|
e.stopPropagation();
|
|
28
28
|
onDropOn(template.id);
|
|
29
|
-
} }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template); }, title: t('panel.insert'), children: [_jsx("span", { className: css.name, children: template.name }), _jsx("span", { className: css.preview, children: template.content })] }), _jsxs("button", { type: "button", className: template.inject_enabled ? css.injectBtnActive : css.injectBtn, onClick: () => { onToggleInject(template); }, "aria-label": t('panel.inject'), "aria-pressed": template.inject_enabled, title: injectTitle, children: ["\u27F3", template.inject_enabled && template.inject_every !== null ? template.inject_every : ''] }), _jsx("button", { type: "button", className: css.interjectBtn, onClick: () => { onInterject(template); }, "aria-label": t('panel.interject'), title: t('panel.interject'), children: _jsx(IconQueueOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.sendBtn, onClick: () => { onSend(template); }, "aria-label": t('panel.sendNow'), title: t('panel.sendNow'), children: _jsx(IconSendOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.shareBtn, onClick: (event) => { onShare(template, event.currentTarget); }, "aria-label": t('panel.share'), title: t('panel.share'), children: _jsx(IconCopyOutlineRegular, { size: 12 }) }), onMakeGlobal !== undefined && (_jsx("button", { type: "button", className: css.globalBtn, onClick: () => { onMakeGlobal(template.id); }, "aria-label": t('panel.makeGlobal'), title: t('panel.makeGlobal'), children: _jsx(IconGlobeOutlineRegular, { size: 12 }) })), _jsx("button", { type: "button", className: css.editBtn, onClick: () => { onEdit(template.id); }, "aria-label": t('panel.edit'), title: t('panel.edit'), children: _jsx(IconEditOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.deleteBtn, onClick: () => { onDelete(template.id); }, "aria-label": t('panel.delete'), children: _jsx(IconTrashOutlineRegular, { size: 12 }) })] }));
|
|
29
|
+
} }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template); }, title: t('panel.insert'), children: [_jsx("span", { className: css.name, children: template.name }), _jsx("span", { className: css.preview, children: template.content })] }), _jsxs("button", { type: "button", className: template.inject_enabled ? css.injectBtnActive : css.injectBtn, onClick: () => { onToggleInject(template); }, "aria-label": t('panel.inject'), "aria-pressed": template.inject_enabled, title: injectTitle, children: ["\u27F3", template.inject_enabled && template.inject_every !== null ? template.inject_every : ''] }), _jsx("button", { type: "button", className: css.interjectBtn, onClick: () => { onInterject(template); }, "aria-label": t('panel.interject'), title: t('panel.interject'), children: _jsx(IconQueueOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.sendBtn, onClick: () => { onSend(template); }, "aria-label": t('panel.sendNow'), title: t('panel.sendNow'), children: _jsx(IconSendOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.shareBtn, onClick: (event) => { onShare(template, event.currentTarget); }, "aria-label": t('panel.share'), title: t('panel.share'), children: _jsx(IconCopyOutlineRegular, { size: 12 }) }), onMakeGlobal !== undefined && (_jsx("button", { type: "button", className: css.globalBtn, onClick: () => { onMakeGlobal(template.id); }, "aria-label": t('panel.makeGlobal'), title: t('panel.makeGlobal'), children: _jsx(IconGlobeOutlineRegular, { size: 12 }) })), pin !== undefined && (_jsx("button", { type: "button", className: pin.pinned ? css.injectBtnActive : css.injectBtn, onClick: () => { pin.onToggle(); }, "aria-label": pin.pinned ? t('panel.unpin') : t('panel.pin'), "aria-pressed": pin.pinned, title: pin.pinned ? t('panel.unpin') : t('panel.pin'), children: "\uD83D\uDCCC" })), _jsx("button", { type: "button", className: css.editBtn, onClick: () => { onEdit(template.id); }, "aria-label": t('panel.edit'), title: t('panel.edit'), children: _jsx(IconEditOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.deleteBtn, onClick: () => { onDelete(template.id); }, "aria-label": t('panel.delete'), children: _jsx(IconTrashOutlineRegular, { size: 12 }) })] }));
|
|
30
30
|
}
|
|
31
31
|
/** The template inline form: creation (with scope + category pickers) and in-place edit. */
|
|
32
32
|
function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
|
|
@@ -247,6 +247,23 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
247
247
|
setManualShare(null);
|
|
248
248
|
return () => { shareRequest.current += 1; };
|
|
249
249
|
}, [sessionId]);
|
|
250
|
+
// 体会 pins (phase 2): only the session's own lessons get the toggle; the host enforces the quota.
|
|
251
|
+
const [lessonPins, setLessonPins] = useState(new Map());
|
|
252
|
+
const loadLessonPins = useCallback(async () => {
|
|
253
|
+
if (sessionId === null) {
|
|
254
|
+
setLessonPins(new Map());
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const items = await listLessonPins(sessionId);
|
|
258
|
+
setLessonPins(new Map(items.map(item => [item.id, item.pinned])));
|
|
259
|
+
}, [sessionId]);
|
|
260
|
+
useEffect(() => { void loadLessonPins(); }, [loadLessonPins, templates]);
|
|
261
|
+
const handleTogglePin = useCallback(async (id) => {
|
|
262
|
+
const result = await setLessonPinned(id, lessonPins.get(id) !== true);
|
|
263
|
+
if (!result.ok)
|
|
264
|
+
setNotice(result.error.code === 'pinned-full' ? t('panel.pinFull') : result.error.message);
|
|
265
|
+
await loadLessonPins();
|
|
266
|
+
}, [lessonPins, loadLessonPins, t]);
|
|
250
267
|
useEffect(() => {
|
|
251
268
|
if (notice === null)
|
|
252
269
|
return;
|
|
@@ -455,7 +472,7 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
455
472
|
});
|
|
456
473
|
return result.ok;
|
|
457
474
|
}, onDone: () => { setEditingId(null); void load(); }, onCancel: () => { setEditingId(null); } }, row.id))
|
|
458
|
-
: (_jsx(TemplateRow, { template: row, onInsert: (c) => { handleInsert(c); }, onSend: (c) => { handleSend(c); }, onInterject: (c) => { handleInterject(c); }, onEdit: (id) => { setEditingId(id); }, onDelete: (id) => { void handleRemove(id); }, onShare: (tpl, trigger) => { void handleShareTemplate(tpl, trigger); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, onToggleInject: (tpl) => { void handleToggleInject(tpl); }, sortable: needle === '', onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
|
|
475
|
+
: (_jsx(TemplateRow, { template: row, onInsert: (c) => { handleInsert(c); }, onSend: (c) => { handleSend(c); }, onInterject: (c) => { handleInterject(c); }, onEdit: (id) => { setEditingId(id); }, onDelete: (id) => { void handleRemove(id); }, onShare: (tpl, trigger) => { void handleShareTemplate(tpl, trigger); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, pin: lessonPins.has(row.id) ? { pinned: lessonPins.get(row.id) === true, onToggle: () => { void handleTogglePin(row.id); } } : undefined, onToggleInject: (tpl) => { void handleToggleInject(tpl); }, sortable: needle === '', onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
|
|
459
476
|
return (_jsxs("div", { className: css.library, "data-prompt-library": true, children: [_jsxs("div", { className: header !== undefined ? `${css.toolbar} ${css.toolbarDraggable}` : css.toolbar, title: header?.hint, onPointerDown: header?.onPointerDown, onPointerMove: header?.onPointerMove, onPointerUp: header?.onPointerUp, onDoubleClick: header?.onDoubleClick, children: [_jsxs("span", { className: css.titleGroup, children: [_jsx("span", { className: css.title, children: t('panel.title') }), _jsx("span", { className: css.countBadge, "data-template-count": true, title: needle !== '' ? t('panel.searchCount') : t('panel.tabCount'), children: countLabel }), injected !== null && (_jsxs("button", { type: "button", className: `${css.injectBadge} ${css.injectBadgeButton}`, "data-prompt-injected": true, title: `${t('panel.injectedAt')} ${injected.turn} · ${new Date(injected.at).toLocaleTimeString()} · ${injected.templates.join(', ')}`, "aria-label": t('panel.historyTitle'), "aria-expanded": historyOpen, onClick: () => { setHistoryOpen(open => !open); }, children: ["\u27F3", injected.turn] })), _jsx("button", { type: "button", className: css.importBtn, onClick: () => { setShowImport(v => !v); }, "aria-label": t('panel.import'), "aria-expanded": showImport, title: t('panel.import'), children: _jsx(IconDownloadOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.importBtn, "data-prompt-events-toggle": true, onClick: () => { setEventsOpen(open => !open); }, "aria-label": t('panel.eventsTitle'), "aria-expanded": eventsOpen, title: t('panel.eventsTitle'), children: "\u2699" })] }), headerExtra] }), notice !== null && _jsx("div", { className: css.notice, role: "status", children: notice }), manualShare !== null && (_jsxs("section", { className: css.importForm, "data-prompt-share-manual": true, "aria-label": t('panel.shareManualTitle'), children: [_jsxs("div", { role: "status", children: [t(manualShare.failure.kind === 'unavailable' ? 'panel.copyUnavailable'
|
|
460
477
|
: manualShare.failure.kind === 'unfocused' ? 'panel.copyUnfocused'
|
|
461
478
|
: manualShare.failure.kind === 'denied' ? 'panel.copyDenied'
|
package/lib/client/api.js
CHANGED
|
@@ -98,6 +98,23 @@ export async function eventEpisodes(sessionId) {
|
|
|
98
98
|
const body = await response.json();
|
|
99
99
|
return [...body.items ?? []];
|
|
100
100
|
}
|
|
101
|
+
/** Load a session's lessons with their pin state (empty when none, unavailable, or the host predates lessons). */
|
|
102
|
+
export async function listLessonPins(sessionId) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(`${BASE}/lessons?session_id=${encodeURIComponent(sessionId)}`, { cache: 'no-store' });
|
|
105
|
+
if (!response.ok)
|
|
106
|
+
return [];
|
|
107
|
+
const body = await response.json();
|
|
108
|
+
return (body.items ?? []).filter(item => typeof item.id === 'string').map(item => ({ id: item.id, pinned: item.pinned === true }));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** The owner pins or unpins one lesson; a full pin quota settles as error code `pinned-full`. */
|
|
115
|
+
export function setLessonPinned(templateId, pinned) {
|
|
116
|
+
return mutate('PATCH', `/lessons/${encodeURIComponent(templateId)}`, { pinned });
|
|
117
|
+
}
|
|
101
118
|
/** Run one mutating request and settle it into the action envelope. */
|
|
102
119
|
async function mutate(method, path, body) {
|
|
103
120
|
try {
|
package/lib/client/locales.js
CHANGED
|
@@ -32,6 +32,9 @@ export const zh = {
|
|
|
32
32
|
'panel.delete': '删除',
|
|
33
33
|
'panel.edit': '编辑',
|
|
34
34
|
'panel.makeGlobal': '设为全局',
|
|
35
|
+
'panel.pin': '设为常驻体会(会话开始、恢复和压缩后装载)',
|
|
36
|
+
'panel.unpin': '取消常驻',
|
|
37
|
+
'panel.pinFull': '常驻体会已达上限,先取消一条再设',
|
|
35
38
|
'panel.inject': '定时注入',
|
|
36
39
|
'panel.injectEvery': '注入间隔(轮)',
|
|
37
40
|
'panel.variablesHint': '支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)',
|
|
@@ -110,6 +113,9 @@ export const en = {
|
|
|
110
113
|
'panel.delete': 'Delete',
|
|
111
114
|
'panel.edit': 'Edit',
|
|
112
115
|
'panel.makeGlobal': 'Make global',
|
|
116
|
+
'panel.pin': 'Pin this lesson (loaded at session start, resume and after compaction)',
|
|
117
|
+
'panel.unpin': 'Unpin',
|
|
118
|
+
'panel.pinFull': 'Pinned lessons are at the limit; unpin one first',
|
|
113
119
|
'panel.inject': 'Auto-inject',
|
|
114
120
|
'panel.injectEvery': 'Every (rounds)',
|
|
115
121
|
'panel.variablesHint': 'Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)',
|
package/lib/client.js
CHANGED
|
@@ -107,6 +107,23 @@ window.__ModuleLoader__.load({
|
|
|
107
107
|
if (!response.ok) return [];
|
|
108
108
|
return [...(await response.json()).items ?? []];
|
|
109
109
|
}
|
|
110
|
+
/** Load a session's lessons with their pin state (empty when none, unavailable, or the host predates lessons). */
|
|
111
|
+
async function listLessonPins(sessionId) {
|
|
112
|
+
try {
|
|
113
|
+
const response = await fetch(`${BASE}/lessons?session_id=${encodeURIComponent(sessionId)}`, { cache: "no-store" });
|
|
114
|
+
if (!response.ok) return [];
|
|
115
|
+
return ((await response.json()).items ?? []).filter((item) => typeof item.id === "string").map((item) => ({
|
|
116
|
+
id: item.id,
|
|
117
|
+
pinned: item.pinned === true
|
|
118
|
+
}));
|
|
119
|
+
} catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** The owner pins or unpins one lesson; a full pin quota settles as error code `pinned-full`. */
|
|
124
|
+
function setLessonPinned(templateId, pinned) {
|
|
125
|
+
return mutate("PATCH", `/lessons/${encodeURIComponent(templateId)}`, { pinned });
|
|
126
|
+
}
|
|
110
127
|
/** Run one mutating request and settle it into the action envelope. */
|
|
111
128
|
async function mutate(method, path, body) {
|
|
112
129
|
try {
|
|
@@ -346,7 +363,7 @@ window.__ModuleLoader__.load({
|
|
|
346
363
|
/** Canonical public source repository for the panel's metadata link. */
|
|
347
364
|
const GITHUB_REPOSITORY_URL = "https://github.com/NelsonLongXiang/dsh-prompt-templates";
|
|
348
365
|
/** Build-injected package version; `dev` only exists in unbundled unit tests. */
|
|
349
|
-
const PLUGIN_VERSION = "0.
|
|
366
|
+
const PLUGIN_VERSION = "0.19.0";
|
|
350
367
|
/** Header count: current-tab size when idle, matched/searchable when searching. */
|
|
351
368
|
function templateCountLabel(matched, searchable, searching) {
|
|
352
369
|
return searching ? `${matched}/${searchable}` : String(matched);
|
|
@@ -453,7 +470,7 @@ window.__ModuleLoader__.load({
|
|
|
453
470
|
* passed in as `sessionId` (the overlay reads it from its composer-entry
|
|
454
471
|
* attachment; the sidebar tab reads it straight from its standard props).
|
|
455
472
|
*/
|
|
456
|
-
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onShare, onMakeGlobal, onToggleInject, sortable, onDragStart, onDropOn, t }) {
|
|
473
|
+
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onShare, onMakeGlobal, pin, onToggleInject, sortable, onDragStart, onDropOn, t }) {
|
|
457
474
|
const injectTitle = template.inject_enabled && template.inject_every !== null ? `${t("panel.inject")} · ${template.inject_every}${template.mode === "visible" ? " · " + t("panel.modeVisible") : ""}` : t("panel.inject");
|
|
458
475
|
return (0, react_jsx_runtime.jsxs)("div", {
|
|
459
476
|
className: Panel_module_css_default.row,
|
|
@@ -542,6 +559,17 @@ window.__ModuleLoader__.load({
|
|
|
542
559
|
title: t("panel.makeGlobal"),
|
|
543
560
|
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconGlobeOutlineRegular, { size: 12 })
|
|
544
561
|
}),
|
|
562
|
+
pin !== void 0 && (0, react_jsx_runtime.jsx)("button", {
|
|
563
|
+
type: "button",
|
|
564
|
+
className: pin.pinned ? Panel_module_css_default.injectBtnActive : Panel_module_css_default.injectBtn,
|
|
565
|
+
onClick: () => {
|
|
566
|
+
pin.onToggle();
|
|
567
|
+
},
|
|
568
|
+
"aria-label": pin.pinned ? t("panel.unpin") : t("panel.pin"),
|
|
569
|
+
"aria-pressed": pin.pinned,
|
|
570
|
+
title: pin.pinned ? t("panel.unpin") : t("panel.pin"),
|
|
571
|
+
children: "📌"
|
|
572
|
+
}),
|
|
545
573
|
(0, react_jsx_runtime.jsx)("button", {
|
|
546
574
|
type: "button",
|
|
547
575
|
className: Panel_module_css_default.editBtn,
|
|
@@ -964,6 +992,27 @@ window.__ModuleLoader__.load({
|
|
|
964
992
|
shareRequest.current += 1;
|
|
965
993
|
};
|
|
966
994
|
}, [sessionId]);
|
|
995
|
+
const [lessonPins, setLessonPins] = (0, react.useState)(/* @__PURE__ */ new Map());
|
|
996
|
+
const loadLessonPins = (0, react.useCallback)(async () => {
|
|
997
|
+
if (sessionId === null) {
|
|
998
|
+
setLessonPins(/* @__PURE__ */ new Map());
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const items = await listLessonPins(sessionId);
|
|
1002
|
+
setLessonPins(new Map(items.map((item) => [item.id, item.pinned])));
|
|
1003
|
+
}, [sessionId]);
|
|
1004
|
+
(0, react.useEffect)(() => {
|
|
1005
|
+
loadLessonPins();
|
|
1006
|
+
}, [loadLessonPins, templates]);
|
|
1007
|
+
const handleTogglePin = (0, react.useCallback)(async (id) => {
|
|
1008
|
+
const result = await setLessonPinned(id, lessonPins.get(id) !== true);
|
|
1009
|
+
if (!result.ok) setNotice(result.error.code === "pinned-full" ? t("panel.pinFull") : result.error.message);
|
|
1010
|
+
await loadLessonPins();
|
|
1011
|
+
}, [
|
|
1012
|
+
lessonPins,
|
|
1013
|
+
loadLessonPins,
|
|
1014
|
+
t
|
|
1015
|
+
]);
|
|
967
1016
|
(0, react.useEffect)(() => {
|
|
968
1017
|
if (notice === null) return;
|
|
969
1018
|
const timer = setTimeout(() => {
|
|
@@ -1189,6 +1238,12 @@ window.__ModuleLoader__.load({
|
|
|
1189
1238
|
onMakeGlobal: row.scope === "session" ? (id) => {
|
|
1190
1239
|
handleMakeGlobal(id);
|
|
1191
1240
|
} : void 0,
|
|
1241
|
+
pin: lessonPins.has(row.id) ? {
|
|
1242
|
+
pinned: lessonPins.get(row.id) === true,
|
|
1243
|
+
onToggle: () => {
|
|
1244
|
+
handleTogglePin(row.id);
|
|
1245
|
+
}
|
|
1246
|
+
} : void 0,
|
|
1192
1247
|
onToggleInject: (tpl) => {
|
|
1193
1248
|
handleToggleInject(tpl);
|
|
1194
1249
|
},
|
|
@@ -2169,6 +2224,9 @@ window.__ModuleLoader__.load({
|
|
|
2169
2224
|
"panel.delete": "删除",
|
|
2170
2225
|
"panel.edit": "编辑",
|
|
2171
2226
|
"panel.makeGlobal": "设为全局",
|
|
2227
|
+
"panel.pin": "设为常驻体会(会话开始、恢复和压缩后装载)",
|
|
2228
|
+
"panel.unpin": "取消常驻",
|
|
2229
|
+
"panel.pinFull": "常驻体会已达上限,先取消一条再设",
|
|
2172
2230
|
"panel.inject": "定时注入",
|
|
2173
2231
|
"panel.injectEvery": "注入间隔(轮)",
|
|
2174
2232
|
"panel.variablesHint": "支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)",
|
|
@@ -2247,6 +2305,9 @@ window.__ModuleLoader__.load({
|
|
|
2247
2305
|
"panel.delete": "Delete",
|
|
2248
2306
|
"panel.edit": "Edit",
|
|
2249
2307
|
"panel.makeGlobal": "Make global",
|
|
2308
|
+
"panel.pin": "Pin this lesson (loaded at session start, resume and after compaction)",
|
|
2309
|
+
"panel.unpin": "Unpin",
|
|
2310
|
+
"panel.pinFull": "Pinned lessons are at the limit; unpin one first",
|
|
2250
2311
|
"panel.inject": "Auto-inject",
|
|
2251
2312
|
"panel.injectEvery": "Every (rounds)",
|
|
2252
2313
|
"panel.variablesHint": "Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)",
|