@huanlin/dsh-plugin-preface-context 0.1.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.
Files changed (38) hide show
  1. package/README.md +113 -0
  2. package/cordis.patch.yml +11 -0
  3. package/lib/client.js +794 -0
  4. package/lib/client.js.map +1 -0
  5. package/lib/index.js +127 -0
  6. package/lib/types/client/bind-snapshot-selector.d.ts +7 -0
  7. package/lib/types/client/bind-snapshot-selector.js +19 -0
  8. package/lib/types/client/client/bind-snapshot-selector.d.ts +7 -0
  9. package/lib/types/client/client/bind-snapshot-selector.js +19 -0
  10. package/lib/types/client/client/index.d.ts +39 -0
  11. package/lib/types/client/client/index.js +50 -0
  12. package/lib/types/client/client/locales.d.ts +7 -0
  13. package/lib/types/client/client/locales.js +41 -0
  14. package/lib/types/client/client/preface-card-controller.d.ts +94 -0
  15. package/lib/types/client/client/preface-card-controller.js +181 -0
  16. package/lib/types/client/client/preface-card.css.d.ts +53 -0
  17. package/lib/types/client/client/preface-card.css.js +327 -0
  18. package/lib/types/client/client/preface-card.d.ts +27 -0
  19. package/lib/types/client/client/preface-card.js +41 -0
  20. package/lib/types/client/config.d.ts +41 -0
  21. package/lib/types/client/config.js +42 -0
  22. package/lib/types/client/index.d.ts +39 -0
  23. package/lib/types/client/index.js +50 -0
  24. package/lib/types/client/locales.d.ts +7 -0
  25. package/lib/types/client/locales.js +41 -0
  26. package/lib/types/client/preface-card-controller.d.ts +94 -0
  27. package/lib/types/client/preface-card-controller.js +181 -0
  28. package/lib/types/client/preface-card.css.d.ts +53 -0
  29. package/lib/types/client/preface-card.css.js +327 -0
  30. package/lib/types/client/preface-card.d.ts +27 -0
  31. package/lib/types/client/preface-card.js +41 -0
  32. package/lib/types/config.d.ts +40 -0
  33. package/lib/types/config.js +42 -0
  34. package/lib/types/index.d.ts +46 -0
  35. package/lib/types/index.js +64 -0
  36. package/lib/types/settings.d.ts +50 -0
  37. package/lib/types/settings.js +85 -0
  38. package/package.json +130 -0
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ <p align="center">
2
+ <a href="https://dshfind.com/zh/plugins/huanlinoto/dsh-plugin-preface-context"><img src="https://dshfind.com/api/card/huanlinoto/dsh-plugin-preface-context?lang=zh" alt="dsh-plugin-preface-context card"></a>
3
+ </p>
4
+
5
+ # dsh-plugin-preface-context
6
+
7
+ 在每次会话开头固定注入一段用户配置的文本上下文(设置页输入框可编辑),作为模型可见的 instructions 注入第一轮请求。
8
+
9
+ > Injects a user-configured text block as model-visible instructions context at the start of every DSH session (editable from the settings page).
10
+
11
+ ## 功能
12
+
13
+ - **会话开始注入**:监听 `agent/session-start` 事件,在每次新建/恢复会话时,通过 `agent.inject()` 把用户配置的文本作为一条 `source.kind: 'plugin'`、`form: 'instructions'` 的 `user/message` 注入会话收件箱。该消息被第一轮 `agent/pre-step` 领取后送入模型请求,作为指令上下文最贴近模型的首个回答。
14
+ - **设置页可编辑**:在「插件配置」设置页注册一张卡片(与内置 `bash` / `agent-loop` / `web-search` 卡同列),包含:
15
+ - **启用开关**(boolean toggle)
16
+ - **上下文文本**(multiline textarea,保留换行和缩进)
17
+ - **实时生效**:设置页保存后,下一次会话开始即使用新文本,无需重启。
18
+
19
+ ## 开发
20
+
21
+ ### 仓库结构
22
+
23
+ ```
24
+ src/
25
+ ├── index.ts # host 入口: name/inject/Config/apply + agent/session-start hook
26
+ ├── config.ts # Config schema (Schemastery) + resolvePrefaceConfig
27
+ ├── settings.ts # installPrefaceSettings (settings namespace + live source bridge)
28
+ └── client/
29
+ ├── index.ts # client 入口: 挂 settings.plugin.item 槽
30
+ ├── preface-card.tsx # 设置卡组件
31
+ ├── preface-card-controller.ts # CardForm 桥接 (staged edit / save / discard)
32
+ ├── bind-snapshot-selector.ts # 内联 uSES bridge (上游不再从包根导出)
33
+ ├── preface-card.css.ts # 卡片样式 + <style data-plugin-css> 注入
34
+ └── locales.ts # zh/en 字典
35
+ tests/
36
+ ├── config.test.ts # Config schema 校验
37
+ ├── settings.test.ts # settings bridge source/onChange/fallback
38
+ ├── index.test.ts # buildPrefaceMessage 注入决策
39
+ ├── preface-card-controller.test.ts # controller stage/save/discard
40
+ └── preface-card.spec.tsx # 卡片渲染 + 交互 (jsdom)
41
+ ```
42
+
43
+ ### 前置依赖
44
+
45
+ - Node.js >= 22
46
+ - pnpm
47
+ - 本机 `~/.dsh/source/current` 指向 DSH 源码 checkout(tsconfig paths 解析 `@deepseek-ai/*` 类型)
48
+
49
+ ### 三件套
50
+
51
+ ```sh
52
+ pnpm install
53
+ pnpm run typecheck # tsc --noEmit (host + client)
54
+ pnpm test # vitest run
55
+ pnpm run build # tsdown 双 bundle (host ESM + client __ModuleLoader__ CJS) + tsc 类型产物
56
+ ```
57
+
58
+ ### 构建策略
59
+
60
+ **预构建 `lib/` 入库**(不含 `prepare` 脚本)。client 半部依赖 `@deepseek-ai/dsh-client-*` private peer deps,pnpm 在 git install 的 `prepare` 阶段会在临时目录拉不到这些包,所以 `lib/` 必须预构建并提交。改源码后需 `pnpm run build` + commit `lib/`。
61
+
62
+ ## 运行
63
+
64
+ ### 安装到 profile
65
+
66
+ ```sh
67
+ # 本地开发(热更新)
68
+ dsh plugin --profile web add "link:D:/Projects/deepseek-harness/dsh-plugin-preface-context"
69
+
70
+ # 从 GitHub 安装
71
+ dsh plugin --profile web add "github:huanlinoto/dsh-plugin-preface-context"
72
+ ```
73
+
74
+ 安装后重启 `dsh web`,浏览器硬刷新(`Ctrl+Shift+R`)。在设置页 → 插件配置 中可见「前言上下文」卡片。
75
+
76
+ ### 配置
77
+
78
+ 设置页卡片中:
79
+ - **启用**:开关关闭时不注入任何文本。
80
+ - **上下文文本**:输入要注入的文本(支持多行)。文本为空时不注入。
81
+
82
+ 也可通过 `cordis.patch.yml` 的 plugin-row `config` 块提供 composition base(默认 `enabled: true, contextText: ''`)。
83
+
84
+ ## 检查
85
+
86
+ ```sh
87
+ pnpm run typecheck # 类型门禁
88
+ pnpm test # 42 个单元/组件测试
89
+ pnpm run build # 产物: lib/index.js, lib/client.js (+ types)
90
+ ```
91
+
92
+ ### 为何不发布 `./invariant`
93
+
94
+ 本插件没有独立可分歧的观察:`agent/session-start` 监听器是 cordis effect,随插件 fiber 自动 dispose;settings 命名空间注册挂在自己的 conditional inject child 上,disposal 由 settings 服务契约保证。按上游 v0.1.2-rc.1 收紧的 invariant 规则(空 installer 与「检查服务/元数据存在」式 invariant 无效),不发布 `./invariant` 子路径导出。
95
+
96
+ ### 合规自检
97
+
98
+ - [x] 零源码 patch:未修改 DSH checkout 任何文件
99
+ - [x] B1: `package.json` 声明 `dsh.bundle.patch`
100
+ - [x] B2: 自带 `cordis.patch.yml`(insert 行 id/name/config 齐全)
101
+ - [x] B3: patch 行 `name` 用包名
102
+ - [x] F1: `files` 含 `lib/` + `cordis.patch.yml`
103
+ - [x] F2: `peerDependencies` 含 cordis + `@deepseek-ai/*`(全部 optional)
104
+ - [x] F3: typecheck/test/build 三 script 齐全
105
+ - [x] A4: Config 用 Schemastery `z.object`
106
+ - [x] A6: 不导出 default
107
+ - [x] 预构建策略:`lib/` 不在 `.gitignore`,无 `prepare` 脚本
108
+ - [x] UI1: `settings.plugin.item` keyed 槽位
109
+ - [x] G: Unit + Component 测试分层
110
+
111
+ ## License
112
+
113
+ AGPL-3.0
@@ -0,0 +1,11 @@
1
+ # Insert dsh-plugin-preface-context: injects a user-configured text block as
2
+ # model-visible instructions context at the start of every session (agent/
3
+ # session-start → agent.inject). The text and an enable switch are editable
4
+ # on the "插件配置" settings page via a settings.plugin.item card bound to
5
+ # the `preface-context` settings namespace.
6
+ - insert:
7
+ - id: dsh-plugin-preface-context
8
+ name: '@huanlin/dsh-plugin-preface-context'
9
+ config:
10
+ enabled: true
11
+ contextText: ''