@shellraining/dsh-effort-picker 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shellRaining
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # dsh-effort-picker
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
+ 用键盘切换思考强度。
4
+
5
+ ## 使用
6
+
7
+ - 在输入框键入 `/effort`(或搜「思考强度」),弹出当前模型公布的强度列表,当前值打勾。`↑`/`↓` 移动,Enter 或 Tab 选定,Escape 关闭。
8
+ - 在本页面把会话切到另一个模型后,不管是用 `/model` 还是输入框的模型菜单,都会立即弹出同一个列表,接着选强度即可。新模型只有一档或没有强度时不弹。其他窗口或宿主改动造成的模型变化不会弹出。
9
+ - 只改强度、模型不变时不弹。按 Escape 关掉列表,强度保持切换模型时选择器带上的值(`/model` 用新模型的默认强度)。
10
+ - 子代理会话没有这个命令,和 `/model` 一致。
11
+
12
+ 配合 [dsh-vim-menu-keys](../vim-menu-keys) 可以用 `Ctrl-n`/`Ctrl-p` 移动。
13
+
14
+ ## 安装
15
+
16
+ ```sh
17
+ dsh plugin --profile web add @shellraining/dsh-effort-picker
18
+ ```
19
+
20
+ `desktop` profile 使用应用内插件管理器,或退出桌面应用后使用随应用分发的 Desktop CLI。
21
+
22
+ ## 本地开发
23
+
24
+ ```sh
25
+ pnpm --filter @shellraining/dsh-effort-picker build
26
+ ```
27
+
28
+ 需要即时预览时,按仓库 [质量与验证](../../docs/quality.md) 中“本地链接与即时预览”一节把 profile 链接到本目录。
29
+
30
+ ## 实现与兼容性
31
+
32
+ 依据 DSH `0.2.3-alpha.2` 的源码实现,宿主接口集中在 [src/host.ts](src/host.ts):
33
+
34
+ | 依赖 | 用途 |
35
+ | --- | --- |
36
+ | `ctx.commandUi.register` | 注册 `/effort` 选择框。 |
37
+ | `ctx.commandUi.popupFor(scope).open` | 换模型后主动打开选择框。`popupFor` 在公开契约里返回 `unknown`,这里按实现中的控制器结构调用,上游改动时最可能在这里失效。 |
38
+ | `ctx.modelDirectories.directoryFor` | 读取模型目录与当前选择,提交 `select`。`pending` 字段用来区分本页面发起的选择。 |
39
+ | `ctx.sessions.list` 的 `retainedBy.mainView` | 找到主视图中的会话,与上游各插件的做法相同。 |
40
+
41
+ 只跟随主视图会话;右栏侧边会话里的模型切换不会弹出列表。
42
+
43
+ 人工验收:分别用 `/model` 和输入框模型菜单切换到有多档强度的模型,确认弹出列表、当前值打勾、选定后输入框模型位显示新强度;切到只有一档的模型确认不弹;用 `/effort` 单独改强度确认不会再次弹出;停用插件后确认 `/effort` 消失。
44
+
45
+ ## 许可
46
+
47
+ MIT
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: effort-picker
3
+ name: '@shellraining/dsh-effort-picker'
package/lib/client.js ADDED
@@ -0,0 +1,168 @@
1
+ // Generated by `pnpm run build`; edit src/, not this file.
2
+ window.__ModuleLoader__.load({
3
+ id: "@shellraining/dsh-effort-picker",
4
+ factory: (require) => {
5
+ var module = { exports: {} };
6
+ var exports = module.exports;
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
+ // src/client.ts
10
+ var name = "effort-picker";
11
+ var inject = ["locale"];
12
+ var NS = "dsh-effort-picker";
13
+ var COMMAND = "effort";
14
+ var ZH = {
15
+ label: "思考强度",
16
+ description: "切换当前模型的思考强度",
17
+ search: "搜索思考强度",
18
+ empty: "当前模型没有可选的思考强度",
19
+ noResults: "没有匹配的思考强度",
20
+ noModel: "还没有选择模型",
21
+ sessionInUse: "会话正被其他正在运行的 DSH 占用,退出后重试"
22
+ };
23
+ var EN = {
24
+ label: "Reasoning effort",
25
+ description: "Change the reasoning effort of the current model",
26
+ search: "Search efforts",
27
+ empty: "The current model has no reasoning efforts",
28
+ noResults: "No matching effort",
29
+ noModel: "No model is selected",
30
+ sessionInUse: "Another running DSH holds this session; quit it and try again"
31
+ };
32
+ function sameRoute(a, b) {
33
+ return a !== null && b !== null && a.provider === b.provider && a.model === b.model;
34
+ }
35
+ function reasoningOf(state, route) {
36
+ return state.groups.find((group) => group.id === route.provider)?.models.find((model) => model.id === route.model)?.reasoning;
37
+ }
38
+ function effortOptions(state) {
39
+ const current = state.current;
40
+ if (current === null) return [];
41
+ const reasoning = reasoningOf(state, current);
42
+ const active = current.reasoningEffort ?? reasoning?.defaultEffort;
43
+ return (reasoning?.efforts ?? []).map((effort) => ({
44
+ id: effort.id,
45
+ label: effort.name,
46
+ ...effort.description === void 0 ? {} : { detail: effort.description },
47
+ ...effort.id === active ? { active: true } : {}
48
+ }));
49
+ }
50
+ function mainSessionId(sessions) {
51
+ return Object.values(sessions.list.getSnapshot().byId).find((row) => (row.retainedBy["mainView"] ?? 0) > 0)?.id;
52
+ }
53
+ /** 跟随主视图会话,对当前会话调用 attach,切换或卸载时释放。 */
54
+ function followMainSession(sessions, attach) {
55
+ let id;
56
+ let release = () => {};
57
+ const sync = () => {
58
+ const next = mainSessionId(sessions);
59
+ if (next === id) return;
60
+ release();
61
+ release = () => {};
62
+ id = next;
63
+ if (next !== void 0) release = attach(next);
64
+ };
65
+ const unsubscribe = sessions.list.subscribe(sync);
66
+ sync();
67
+ return () => {
68
+ unsubscribe();
69
+ release();
70
+ };
71
+ }
72
+ /**
73
+ * 本页面的一次选择成功且换了模型时调用 onSwitch。
74
+ * `pending` 只记录本页面发起的选择,其他窗口或宿主改动不会触发。
75
+ */
76
+ function watchModelSwitch(directories, sessionId, onSwitch) {
77
+ const store = directories.directoryFor(sessionId).store;
78
+ let previous = store.getSnapshot();
79
+ let base = previous.current;
80
+ return store.subscribe(() => {
81
+ const next = store.getSnapshot();
82
+ const picked = previous.pending;
83
+ if (picked === null && next.pending !== null) base = next.current;
84
+ previous = next;
85
+ if (picked === null || next.pending !== null || next.status !== "ready" || sameRoute(base, picked)) return;
86
+ if ((reasoningOf(next, picked)?.efforts.length ?? 0) > 1) onSwitch();
87
+ });
88
+ }
89
+ function apply(ctx) {
90
+ ctx.effect(() => {
91
+ const disposeZh = ctx.locale.register(NS, "zh", ZH);
92
+ const disposeEn = ctx.locale.register(NS, "en", EN);
93
+ return () => {
94
+ disposeEn();
95
+ disposeZh();
96
+ };
97
+ }, `${name}: copy`);
98
+ const t = ctx.locale.bind(NS);
99
+ ctx.inject([
100
+ "commandUi",
101
+ "modelDirectories",
102
+ "sessions"
103
+ ], (scope) => {
104
+ const commandUi = scope.commandUi;
105
+ const models = scope.modelDirectories;
106
+ const sessions = scope.sessions;
107
+ const usable = (sessionId) => sessions.subagentAddress(sessionId) === void 0;
108
+ const spec = {
109
+ kind: "popupSelect",
110
+ searchLabels: () => ({
111
+ placeholder: t("search"),
112
+ empty: t("empty"),
113
+ noResults: t("noResults")
114
+ }),
115
+ options: async (session) => effortOptions(await models.directoryFor(session.sessionId).load()),
116
+ onSelect: async (option, session) => {
117
+ const directory = models.directoryFor(session.sessionId);
118
+ const current = directory.store.getSnapshot().current;
119
+ if (current === null) throw new Error(t("noModel"));
120
+ const result = await directory.select({
121
+ provider: current.provider,
122
+ model: current.model,
123
+ reasoningEffort: option.id
124
+ });
125
+ if (!result.ok) throw new Error(result.error.code === "session/writer-held" ? t("sessionInUse") : result.error.message);
126
+ }
127
+ };
128
+ scope.effect(() => commandUi.register({
129
+ name: COMMAND,
130
+ label: () => t("label"),
131
+ description: () => t("description"),
132
+ icon: _deepseek_ai_dsh_client_ui_primitives.IconThinkOutlineRegular,
133
+ available: (session) => usable(session.sessionId),
134
+ ui: spec
135
+ }), `${name}: /${COMMAND}`);
136
+ const openPicker = (sessionId) => {
137
+ const sessionScope = sessions.scope(sessionId);
138
+ if (sessionScope === void 0) return;
139
+ const popup = commandUi.popupFor(sessionScope);
140
+ if (popup.state.getSnapshot().open) return;
141
+ popup.open(COMMAND, spec, { sessionId }, {
142
+ via: "enter",
143
+ token: `/${COMMAND}`
144
+ });
145
+ };
146
+ scope.effect(() => followMainSession(sessions, (sessionId) => {
147
+ if (!usable(sessionId) || sessions.scope(sessionId) === void 0) return () => {};
148
+ let timer;
149
+ const stop = watchModelSwitch(models, sessionId, () => {
150
+ clearTimeout(timer);
151
+ timer = setTimeout(() => {
152
+ openPicker(sessionId);
153
+ }, 0);
154
+ });
155
+ return () => {
156
+ clearTimeout(timer);
157
+ stop();
158
+ };
159
+ }), `${name}: ask after model switch`);
160
+ });
161
+ }
162
+ exports.apply = apply;
163
+ exports.inject = inject;
164
+ exports.name = name;
165
+
166
+ return module.exports;
167
+ },
168
+ });
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Generated by `pnpm run build`; edit src/, not this file.
2
+ // src/index.ts
3
+ var name = "effort-picker";
4
+ function apply() {}
5
+ export { apply, name };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@shellraining/dsh-effort-picker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "用 /effort 选择思考强度,切换模型后立即弹出强度选择,全程键盘操作",
6
+ "main": "./lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./client": "./lib/client.js",
10
+ "./package.json": "./package.json",
11
+ "./cordis.patch.yml": "./cordis.patch.yml"
12
+ },
13
+ "files": [
14
+ "lib",
15
+ "cordis.patch.yml",
16
+ "LICENSE",
17
+ "README.md"
18
+ ],
19
+ "engines": {
20
+ "node": ">=24.9.0",
21
+ "dsh": ">=0.2.3-alpha.2 <0.3.0"
22
+ },
23
+ "devDependencies": {
24
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
25
+ "@types/react": "18.3.31",
26
+ "typescript": "7.0.2"
27
+ },
28
+ "dsh": {
29
+ "bundle": {
30
+ "patch": "./cordis.patch.yml"
31
+ },
32
+ "client": {
33
+ "platform": "web",
34
+ "inject": [
35
+ "@deepseek-ai/dsh-client-locale",
36
+ "@deepseek-ai/dsh-client-ui-commands",
37
+ "@deepseek-ai/dsh-client-ui-model-selection"
38
+ ]
39
+ }
40
+ },
41
+ "license": "MIT",
42
+ "author": "shellRaining",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/shellRaining/dsh-plugins.git",
46
+ "directory": "plugins/effort-picker"
47
+ },
48
+ "keywords": [
49
+ "deepseek-harness",
50
+ "dsh",
51
+ "dsh-plugin",
52
+ "model",
53
+ "reasoning"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "pnpm run typecheck && node build.ts",
60
+ "typecheck": "tsc -p tsconfig.json"
61
+ }
6
62
  }