dsh-thinking-lang 1.0.7 → 1.0.8

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/DEVELOPMENT.md CHANGED
@@ -20,15 +20,15 @@
20
20
 
21
21
  文本由 [`src/core.ts`](src/core.ts) 的 `CATALOGUE` 提供,每种语言一份、**用该语言书写**:
22
22
 
23
- | 语言 | section(规则句) | reminder(每轮提醒) |
24
- |---|---|---|
25
- | 简体中文 | 推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。 | 继续用简体中文思考、推理与规划。 |
26
- | 繁體中文 | 推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。 | 繼續用繁體中文思考、推理與規劃。 |
27
- | English | Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use. | Keep thinking, reasoning, and planning in English. |
23
+ | 语言 | section(规则句) | reminder(批次开头) | tail(请求末尾) |
24
+ |---|---|---|---|
25
+ | 简体中文 | 推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。 | 注意:思考、推理与规划用简体中文,即使上文不是 | 下文请使用简体中文思考 |
26
+ | 繁體中文 | 推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。 | 注意:思考、推理與規劃用繁體中文,即使上文不是 | 下文請使用繁體中文思考 |
27
+ | English | Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use. | Note: think, reason, and plan in English, even if the text above is not | Think in English from here on |
28
28
 
29
29
  改文本改 `CATALOGUE`,再 `npm run build`。
30
30
 
31
- section 的 `order: 1` 紧跟 persona;提醒消息经 `prepend` 注册,落在请求最末(晚于 time-context 等注入)。
31
+ section 的 `order: 1` 紧跟 persona。提醒分两处:一条独立消息插在批次最前,另一条折进 `skill-catalog` 块的 `content` 首部。`agent/pre-step` 监听器在 `agent/created` 时重新 `prepend`,所以它排在监听链最外层,能看到其余注入追加完再动手。
32
32
 
33
33
  ### 提醒间隔
34
34
 
@@ -42,19 +42,38 @@ section 的 `order: 1` 紧跟 persona;提醒消息经 `prepend` 注册,落
42
42
 
43
43
  宿主端由 [`reminderDelayMs`](src/core.ts) 换算;客户端在插件详情页的配置卡片里修改,两处读写同一份设置文档。
44
44
 
45
+ ### 额外提醒注入
46
+
47
+ 存储字段是 `extraInjection`(布尔,默认 `true`)。开启时把 `skill-catalog` 块的 `content[0]` 换成「下文请使用简体中文思考」(按所选语言书写),模型因此在那段上下文里先读到规则、再读技能列表。
48
+
49
+ 它跟着提醒间隔联动:`reminderMinutes` 为负数时,整个 `agent/pre-step` 监听器提前返回,两处注入一起停;客户端对应地把这一行置灰。
50
+
45
51
  ---
46
52
 
47
53
  ## Token 开销(实测)
48
54
 
49
55
  用 DeepSeek V4 词表实测(不计特殊 token):
50
56
 
51
- | 语言 | section | reminder |
52
- |---|---|---|
53
- | 简体中文 | 21 | 10 |
54
- | 繁體中文 | 22 | 10 |
55
- | English | 23 | 10 |
57
+ | 语言 | section(每会话一次) | 前置提醒(每提醒轮次) | 额外提醒(每提醒轮次) |
58
+ |---|---|---|---|
59
+ | 简体中文 | 21 | 14 | 6 |
60
+ | 繁體中文 | 22 | 14 | 6 |
61
+ | English | 23 | 18 | 6 |
62
+
63
+ 前置提醒是一条独立的用户消息,额外提醒只改 `skill-catalog` 的 `content[0]`、不新增消息,所以后者便宜。按默认 30 分钟间隔、100 轮算,一个会话约 50 次提醒、合计约 1000–1300 token。**换语言对每轮开销几乎没有影响**。
64
+
65
+ 旧版只有一条 10 token 的提醒;现在为了压住英文正文拆成 14 + 6(简体中文)。
66
+
67
+ ### 效果数据
68
+
69
+ 2026-11-18 实测,prompt 固定为「英文开场 + 中文测试句结尾」:
70
+
71
+ | 做法 | 按所选语言思考 |
72
+ |---|---|
73
+ | 系统提示 + 前置提醒 | 约 30% |
74
+ | 再加额外提醒注入 | 约 70%(30 个样本 21 中) |
56
75
 
57
- section 每会话一次;reminder 每个轮次最多一条,按默认 30 分钟间隔计,一小时最多两条,100 轮约 1000 token。**换语言对每轮开销几乎没有影响**。
76
+ 样本:单注入 10 个(3 中);双注入 40 个(29 中)。同一配置重复跑波动在 7 个百分点以内。**注入提高概率,不保证结果**——用户消息首行就是所选语言时基本不受影响。
58
77
 
59
78
  ---
60
79
 
@@ -154,3 +173,5 @@ dsh plugin --profile desktop add "$PWD"
154
173
  - **没有聊天命令**:切换语言只走设置页。如需 `/thinking-language`,可参照 `dsh-thinking-language` 的命令实现补上。
155
174
  - **`auto` 依赖运行时能报出系统语言**:Linux/macOS 走环境变量,Windows 走 `Intl`。两者都拿不到时会静默落到界面语言,再不行才是 `zh-CN`。
156
175
  - **插件 id 与设置命名空间**:两者都是 `ay-dsh-tk-lang`,占的是一套自有命名;包名 `dsh-thinking-lang` 与 `dsh-thinking-language` 这类仍然相似,注意区分。功能重复的插件同时装上时,设置页会各插一行、各自注入提示词。
176
+ - **注入只提高概率,不保证结果**:用户消息首行不是所选语言(英文开场、纯图片或附件)时,实测约 30%(仅前置提醒)/ 70%(含额外注入)按所选语言思考。需要稳定拿到目标语言的思考内容,请改用官方思考过程翻译插件。
177
+ - **额外注入依赖 `skill-catalog` 块**:会话里没有技能目录时,规则改插在最后一条注入消息的 `content` 首部,位置与效果都可能不同。
package/README.md CHANGED
@@ -18,16 +18,30 @@
18
18
  |--------|------|------|
19
19
  | **思考语言** | 自动 / 简体中文 / 繁體中文 / English | 内部推理与规划所用的语言 |
20
20
  | **提醒间隔** | 关闭 / 每轮 / 10 / 30 / 60 分钟 / 自定义 1–1440 | 两次「用该语言思考」提醒之间的最小间隔,默认 **30 分钟** |
21
+ | **额外提醒注入** | 开启 / 关闭 | 开启时把提醒同时并入技能目录那段上下文;提醒间隔为「关闭」时此项一并停用。默认开启 |
21
22
 
22
- 「关闭」只停止每轮提醒,系统提示里的规则仍然生效;「每轮」是每个对话轮次的第一步都提醒一次。
23
+ 「关闭」停止全部注入,只保留系统提示里的规则;「每轮」是每个对话轮次的第一步都提醒一次。
23
24
 
24
25
  ![设置 → 通用中的「思考语言」行](assets/settings-general.png)
25
26
 
26
27
  *截图:设置 → 通用里的「思考语言」行,紧贴在宿主自己的界面语言下方。*
27
28
 
28
- ![插件详情页里的配置卡片:思考语言与提醒间隔](assets/plugin-config.png)
29
+ ![插件详情页里的配置卡片:思考语言、提醒间隔与额外提醒注入](assets/plugin-config.png)
29
30
 
30
- *截图:插件页 → 本插件详情里的同一份配置,含「提醒间隔」的预设与自定义输入。*
31
+ *截图:插件页 → 本插件详情里的同一份配置,含「提醒间隔」的预设与自定义输入,以及「额外提醒注入」开关。*
32
+
33
+ ### 效果与限制
34
+
35
+ 注入提高的是概率,不是保证。用户消息本身就用的所选语言时基本没问题;**用户消息首行不是所选语言**(英文开场、纯图片、只有附件)时实测:
36
+
37
+ | 做法 | 按所选语言思考的比例 |
38
+ |---|---|
39
+ | 系统提示 + 前置提醒(默认) | 约 **30%** |
40
+ | 再开启「额外提醒注入」 | 约 **70%** |
41
+
42
+ 额外注入本身多花约 6 token(简体中文),换来请求尾部一次强提醒。
43
+
44
+ **如果目标是稳定拿到目标语言的思考内容**,用官方的思考过程翻译插件更合适:它把思考内容翻译后显示,代价是每次都要多付一遍翻译的 token。本插件只在「直接改思考语言、并接受大多数时候是它」这个场景下更省。
31
45
 
32
46
  ### 「自动」怎么判定
33
47
 
Binary file
package/client/client.js CHANGED
@@ -23,19 +23,22 @@ window.__ModuleLoader__.load({
23
23
  tag: "zh-CN",
24
24
  nativeName: "简体中文",
25
25
  section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
26
- reminder: "继续用简体中文思考、推理与规划。"
26
+ reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
27
+ tail: "下文请使用简体中文思考"
27
28
  },
28
29
  {
29
30
  tag: "zh-TW",
30
31
  nativeName: "繁體中文",
31
32
  section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
32
- reminder: "繼續用繁體中文思考、推理與規劃。"
33
+ reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
34
+ tail: "下文請使用繁體中文思考"
33
35
  },
34
36
  {
35
37
  tag: "en",
36
38
  nativeName: "English",
37
39
  section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
38
- reminder: "Keep thinking, reasoning, and planning in English."
40
+ reminder: "Note: think, reason, and plan in English, even if the text above is not",
41
+ tail: "Think in English from here on"
39
42
  }
40
43
  ];
41
44
  /** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
@@ -46,13 +49,16 @@ window.__ModuleLoader__.load({
46
49
  const FIELD_LANGUAGE = "language";
47
50
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
48
51
  const FIELD_REMINDER = "reminderMinutes";
52
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
53
+ const FIELD_EXTRA = "extraInjection";
49
54
  /** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
50
55
  const MAX_REMINDER_MINUTES = 1440;
51
56
  CATALOGUE.map((language) => language.tag);
52
57
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
53
58
  const DEFAULTS = {
54
59
  language: AUTO,
55
- reminderMinutes: 30
60
+ reminderMinutes: 30,
61
+ extraInjection: true
56
62
  };
57
63
  /** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
58
64
  const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
@@ -83,12 +89,17 @@ window.__ModuleLoader__.load({
83
89
  if (rounded < 0) return -1;
84
90
  return rounded > 1440 ? MAX_REMINDER_MINUTES : rounded;
85
91
  }
92
+ /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
93
+ function normalizeExtra(raw) {
94
+ return raw !== false && raw !== "false";
95
+ }
86
96
  function normalizeSettings(raw) {
87
97
  const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
88
98
  const stored = section?.[FIELD_LANGUAGE];
89
99
  return {
90
100
  language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
91
- reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
101
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
102
+ extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
92
103
  };
93
104
  }
94
105
  /** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
@@ -103,7 +114,11 @@ window.__ModuleLoader__.load({
103
114
  reminderTurn: "每轮",
104
115
  reminderCustom: "自定义",
105
116
  reminderUnit: "分钟",
106
- reminderCustomHint: "1–1440 分钟"
117
+ reminderCustomHint: "1–1440 分钟",
118
+ extraHeading: "额外提醒注入",
119
+ extraDescription: "开启后把提醒同时并入技能目录;提醒间隔为「关闭」时,此项也一并关闭。",
120
+ extraOn: "开启",
121
+ extraOff: "关闭"
107
122
  },
108
123
  en: {
109
124
  heading: "Thinking language",
@@ -115,7 +130,11 @@ window.__ModuleLoader__.load({
115
130
  reminderTurn: "Every turn",
116
131
  reminderCustom: "Custom",
117
132
  reminderUnit: "min",
118
- reminderCustomHint: "1–1440 minutes"
133
+ reminderCustomHint: "1–1440 minutes",
134
+ extraHeading: "Extra reminder injection",
135
+ extraDescription: "Also folds the reminder into the skill catalogue. Switching the reminder interval off turns this off too.",
136
+ extraOn: "On",
137
+ extraOff: "Off"
119
138
  }
120
139
  };
121
140
  //#endregion
@@ -309,6 +328,52 @@ window.__ModuleLoader__.load({
309
328
  };
310
329
  }
311
330
  /**
331
+ * Build the extra-injection picker: on or off.
332
+ * 构建额外注入选择器:开启或关闭。
333
+ *
334
+ * It shares the host Menu with the other controls, so the three read as one column.
335
+ * 与另外两个控件共用宿主 Menu,三者在视觉上成一列。
336
+ */
337
+ function createExtraPicker(primitives) {
338
+ const Menu = primitives?.Menu;
339
+ const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
340
+ return function ExtraPicker(props) {
341
+ const { doc, t, settings, disabled = false } = props;
342
+ const [open, setOpen] = (0, react.useState)(false);
343
+ const items = [{
344
+ id: "on",
345
+ label: t("extraOn")
346
+ }, {
347
+ id: "off",
348
+ label: t("extraOff")
349
+ }];
350
+ const close = () => setOpen(false);
351
+ const choose = (id) => {
352
+ writeField(doc, FIELD_EXTRA, id === "on");
353
+ close();
354
+ };
355
+ const picker = (0, react.createElement)("button", {
356
+ type: "button",
357
+ className: "dsh_desk_lang_picker",
358
+ "aria-haspopup": "menu",
359
+ "aria-expanded": open,
360
+ disabled,
361
+ onClick: () => setOpen((value) => !value)
362
+ }, settings.extraInjection ? t("extraOn") : t("extraOff"), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
363
+ if (!Menu) return picker;
364
+ return (0, react.createElement)(Menu, {
365
+ open,
366
+ anchor: picker,
367
+ items,
368
+ selectedId: settings.extraInjection ? "on" : "off",
369
+ align: "end",
370
+ portal: true,
371
+ onClose: close,
372
+ onSelect: choose
373
+ });
374
+ };
375
+ }
376
+ /**
312
377
  * Build the General settings row: heading, description and the language picker.
313
378
  * 构建「通用」设置行:标题、说明与语言选择器。
314
379
  */
@@ -335,6 +400,7 @@ window.__ModuleLoader__.load({
335
400
  function createConfigCard(primitives) {
336
401
  const LanguagePicker = createLanguagePicker(primitives);
337
402
  const ReminderPicker = createReminderPicker(primitives);
403
+ const ExtraPicker = createExtraPicker(primitives);
338
404
  return function ThinkingLanguageCard(props) {
339
405
  const settings = useSettings(props.doc);
340
406
  if (props.view === "summary") return null;
@@ -343,11 +409,16 @@ window.__ModuleLoader__.load({
343
409
  t: props.t,
344
410
  settings
345
411
  };
346
- return (0, react.createElement)("div", null, (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("description"))), (0, react.createElement)(LanguagePicker, binding)), (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))), (0, react.createElement)(ReminderPicker, binding)));
412
+ const reminderOff = settings.reminderMinutes < 0;
413
+ return (0, react.createElement)("div", null, (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("description"))), (0, react.createElement)(LanguagePicker, binding)), (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))), (0, react.createElement)(ReminderPicker, binding)), (0, react.createElement)("div", { className: reminderOff ? "dsh_desk_lang_row dsh_desk_lang_row_disabled" : "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("extraHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("extraDescription"))), (0, react.createElement)(ExtraPicker, {
414
+ ...binding,
415
+ disabled: reminderOff
416
+ })));
347
417
  };
348
418
  }
349
419
  const rowCss = [
350
420
  ".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
421
+ ".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
351
422
  ".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
352
423
  ".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
353
424
  ".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
@@ -18,19 +18,22 @@ const CATALOGUE = [
18
18
  tag: "zh-CN",
19
19
  nativeName: "简体中文",
20
20
  section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
21
- reminder: "继续用简体中文思考、推理与规划。"
21
+ reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
22
+ tail: "下文请使用简体中文思考"
22
23
  },
23
24
  {
24
25
  tag: "zh-TW",
25
26
  nativeName: "繁體中文",
26
27
  section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
27
- reminder: "繼續用繁體中文思考、推理與規劃。"
28
+ reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
29
+ tail: "下文請使用繁體中文思考"
28
30
  },
29
31
  {
30
32
  tag: "en",
31
33
  nativeName: "English",
32
34
  section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
33
- reminder: "Keep thinking, reasoning, and planning in English."
35
+ reminder: "Note: think, reason, and plan in English, even if the text above is not",
36
+ tail: "Think in English from here on"
34
37
  }
35
38
  ];
36
39
  /** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
@@ -41,13 +44,16 @@ const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
41
44
  const FIELD_LANGUAGE = "language";
42
45
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
43
46
  const FIELD_REMINDER = "reminderMinutes";
47
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
48
+ const FIELD_EXTRA = "extraInjection";
44
49
  /** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
45
50
  const MAX_REMINDER_MINUTES = 1440;
46
51
  CATALOGUE.map((language) => language.tag);
47
52
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
48
53
  const DEFAULTS = {
49
54
  language: AUTO,
50
- reminderMinutes: 30
55
+ reminderMinutes: 30,
56
+ extraInjection: true
51
57
  };
52
58
  /** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
53
59
  const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
@@ -78,12 +84,17 @@ function normalizeReminder(raw) {
78
84
  if (rounded < 0) return -1;
79
85
  return rounded > 1440 ? MAX_REMINDER_MINUTES : rounded;
80
86
  }
87
+ /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
88
+ function normalizeExtra(raw) {
89
+ return raw !== false && raw !== "false";
90
+ }
81
91
  function normalizeSettings(raw) {
82
92
  const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
83
93
  const stored = section?.[FIELD_LANGUAGE];
84
94
  return {
85
95
  language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
86
- reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
96
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
97
+ extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
87
98
  };
88
99
  }
89
100
  /** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
@@ -98,7 +109,11 @@ const dictionaries = {
98
109
  reminderTurn: "每轮",
99
110
  reminderCustom: "自定义",
100
111
  reminderUnit: "分钟",
101
- reminderCustomHint: "1–1440 分钟"
112
+ reminderCustomHint: "1–1440 分钟",
113
+ extraHeading: "额外提醒注入",
114
+ extraDescription: "开启后把提醒同时并入技能目录;提醒间隔为「关闭」时,此项也一并关闭。",
115
+ extraOn: "开启",
116
+ extraOff: "关闭"
102
117
  },
103
118
  en: {
104
119
  heading: "Thinking language",
@@ -110,7 +125,11 @@ const dictionaries = {
110
125
  reminderTurn: "Every turn",
111
126
  reminderCustom: "Custom",
112
127
  reminderUnit: "min",
113
- reminderCustomHint: "1–1440 minutes"
128
+ reminderCustomHint: "1–1440 minutes",
129
+ extraHeading: "Extra reminder injection",
130
+ extraDescription: "Also folds the reminder into the skill catalogue. Switching the reminder interval off turns this off too.",
131
+ extraOn: "On",
132
+ extraOff: "Off"
114
133
  }
115
134
  };
116
135
  //#endregion
@@ -304,6 +323,52 @@ function createReminderPicker(primitives) {
304
323
  };
305
324
  }
306
325
  /**
326
+ * Build the extra-injection picker: on or off.
327
+ * 构建额外注入选择器:开启或关闭。
328
+ *
329
+ * It shares the host Menu with the other controls, so the three read as one column.
330
+ * 与另外两个控件共用宿主 Menu,三者在视觉上成一列。
331
+ */
332
+ function createExtraPicker(primitives) {
333
+ const Menu = primitives?.Menu;
334
+ const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
335
+ return function ExtraPicker(props) {
336
+ const { doc, t, settings, disabled = false } = props;
337
+ const [open, setOpen] = (0, react.useState)(false);
338
+ const items = [{
339
+ id: "on",
340
+ label: t("extraOn")
341
+ }, {
342
+ id: "off",
343
+ label: t("extraOff")
344
+ }];
345
+ const close = () => setOpen(false);
346
+ const choose = (id) => {
347
+ writeField(doc, FIELD_EXTRA, id === "on");
348
+ close();
349
+ };
350
+ const picker = (0, react.createElement)("button", {
351
+ type: "button",
352
+ className: "dsh_desk_lang_picker",
353
+ "aria-haspopup": "menu",
354
+ "aria-expanded": open,
355
+ disabled,
356
+ onClick: () => setOpen((value) => !value)
357
+ }, settings.extraInjection ? t("extraOn") : t("extraOff"), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
358
+ if (!Menu) return picker;
359
+ return (0, react.createElement)(Menu, {
360
+ open,
361
+ anchor: picker,
362
+ items,
363
+ selectedId: settings.extraInjection ? "on" : "off",
364
+ align: "end",
365
+ portal: true,
366
+ onClose: close,
367
+ onSelect: choose
368
+ });
369
+ };
370
+ }
371
+ /**
307
372
  * Build the General settings row: heading, description and the language picker.
308
373
  * 构建「通用」设置行:标题、说明与语言选择器。
309
374
  */
@@ -330,6 +395,7 @@ function createRow(primitives) {
330
395
  function createConfigCard(primitives) {
331
396
  const LanguagePicker = createLanguagePicker(primitives);
332
397
  const ReminderPicker = createReminderPicker(primitives);
398
+ const ExtraPicker = createExtraPicker(primitives);
333
399
  return function ThinkingLanguageCard(props) {
334
400
  const settings = useSettings(props.doc);
335
401
  if (props.view === "summary") return null;
@@ -338,11 +404,16 @@ function createConfigCard(primitives) {
338
404
  t: props.t,
339
405
  settings
340
406
  };
341
- return (0, react.createElement)("div", null, (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("description"))), (0, react.createElement)(LanguagePicker, binding)), (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))), (0, react.createElement)(ReminderPicker, binding)));
407
+ const reminderOff = settings.reminderMinutes < 0;
408
+ return (0, react.createElement)("div", null, (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("description"))), (0, react.createElement)(LanguagePicker, binding)), (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))), (0, react.createElement)(ReminderPicker, binding)), (0, react.createElement)("div", { className: reminderOff ? "dsh_desk_lang_row dsh_desk_lang_row_disabled" : "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("extraHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("extraDescription"))), (0, react.createElement)(ExtraPicker, {
409
+ ...binding,
410
+ disabled: reminderOff
411
+ })));
342
412
  };
343
413
  }
344
414
  const rowCss = [
345
415
  ".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
416
+ ".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
346
417
  ".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
347
418
  ".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
348
419
  ".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
package/lib/core.d.ts CHANGED
@@ -33,8 +33,10 @@ export interface Language {
33
33
  nativeName: string;
34
34
  /** The rule sentence written in this language. / 用本语言写成的规则句。 */
35
35
  section: string;
36
- /** The short per-turn reminder written in this language. / 用本语言写成的每轮短提醒。 */
36
+ /** The short reminder written in this language for the head of the batch. / 写在批次开头的短提醒。 */
37
37
  reminder: string;
38
+ /** The short reminder written for the last message of the request. / 写在请求末尾的短提醒。 */
39
+ tail: string;
38
40
  }
39
41
  /**
40
42
  * The catalogue, in picker order.
@@ -57,6 +59,8 @@ export declare const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
57
59
  export declare const FIELD_LANGUAGE = "language";
58
60
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
59
61
  export declare const FIELD_REMINDER = "reminderMinutes";
62
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
63
+ export declare const FIELD_EXTRA = "extraInjection";
60
64
  /** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
61
65
  export declare const REMINDER_OFF = -1;
62
66
  /** Reminder value that injects on every turn. / 每轮都注入的取值。 */
@@ -78,6 +82,12 @@ export interface ThinkingSettings {
78
82
  * 注入,1–1440 为最小间隔。
79
83
  */
80
84
  reminderMinutes: number;
85
+ /**
86
+ * Whether the closing rule is also folded into the skill catalogue. It only
87
+ * applies while the reminder is on.
88
+ * 是否把收尾规则同时折进技能目录;仅在提醒开启时生效。
89
+ */
90
+ extraInjection: boolean;
81
91
  }
82
92
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
83
93
  export declare const DEFAULTS: ThinkingSettings;
@@ -128,3 +138,8 @@ export declare function sectionText(code: string): string;
128
138
  * 用所选语言生成每轮短提醒。
129
139
  */
130
140
  export declare function reminderText(code: string): string;
141
+ /**
142
+ * Build the closing reminder appended as the request's last message.
143
+ * 生成追加在请求最后一条消息里的收尾提醒。
144
+ */
145
+ export declare function tailText(code: string): string;
package/lib/core.js CHANGED
@@ -42,19 +42,22 @@ export const CATALOGUE = [
42
42
  tag: "zh-CN",
43
43
  nativeName: "简体中文",
44
44
  section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
45
- reminder: "继续用简体中文思考、推理与规划。"
45
+ reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
46
+ tail: "下文请使用简体中文思考"
46
47
  },
47
48
  {
48
49
  tag: "zh-TW",
49
50
  nativeName: "繁體中文",
50
51
  section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
51
- reminder: "繼續用繁體中文思考、推理與規劃。"
52
+ reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
53
+ tail: "下文請使用繁體中文思考"
52
54
  },
53
55
  {
54
56
  tag: "en",
55
57
  nativeName: "English",
56
58
  section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
57
- reminder: "Keep thinking, reasoning, and planning in English."
59
+ reminder: "Note: think, reason, and plan in English, even if the text above is not",
60
+ tail: "Think in English from here on"
58
61
  }
59
62
  ];
60
63
  /** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
@@ -67,6 +70,8 @@ export const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
67
70
  export const FIELD_LANGUAGE = "language";
68
71
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
69
72
  export const FIELD_REMINDER = "reminderMinutes";
73
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
74
+ export const FIELD_EXTRA = "extraInjection";
70
75
  /** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
71
76
  export const REMINDER_OFF = -1;
72
77
  /** Reminder value that injects on every turn. / 每轮都注入的取值。 */
@@ -78,7 +83,11 @@ export const MAX_REMINDER_MINUTES = 1440;
78
83
  /** Every value the picker offers besides {@link AUTO}. / 选择器在 {@link AUTO} 之外提供的全部取值。 */
79
84
  export const SELECTABLE_TAGS = CATALOGUE.map((language) => language.tag);
80
85
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
81
- export const DEFAULTS = { language: AUTO, reminderMinutes: DEFAULT_REMINDER_MINUTES };
86
+ export const DEFAULTS = {
87
+ language: AUTO,
88
+ reminderMinutes: DEFAULT_REMINDER_MINUTES,
89
+ extraInjection: true
90
+ };
82
91
  /** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
83
92
  const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
84
93
  /**
@@ -192,6 +201,10 @@ function normalizeReminder(raw) {
192
201
  return REMINDER_OFF;
193
202
  return rounded > MAX_REMINDER_MINUTES ? MAX_REMINDER_MINUTES : rounded;
194
203
  }
204
+ /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
205
+ function normalizeExtra(raw) {
206
+ return raw !== false && raw !== "false";
207
+ }
195
208
  /**
196
209
  * Convert stored minutes into the minimum gap between reminders.
197
210
  * 把存储的分钟数换算成两次提醒之间的最小间隔。
@@ -211,7 +224,8 @@ export function normalizeSettings(raw) {
211
224
  const stored = section?.[FIELD_LANGUAGE];
212
225
  return {
213
226
  language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
214
- reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
227
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
228
+ extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
215
229
  };
216
230
  }
217
231
  /**
@@ -256,3 +270,10 @@ export function sectionText(code) {
256
270
  export function reminderText(code) {
257
271
  return languageOf(code)?.reminder ?? "";
258
272
  }
273
+ /**
274
+ * Build the closing reminder appended as the request's last message.
275
+ * 生成追加在请求最后一条消息里的收尾提醒。
276
+ */
277
+ export function tailText(code) {
278
+ return languageOf(code)?.tail ?? "";
279
+ }
package/lib/index.d.ts CHANGED
@@ -29,6 +29,7 @@ interface HostContext {
29
29
  on(event: "agent/pre-step", listener: (payload: PreStepPayload, next: () => Promise<PreStepDecision>) => Promise<PreStepDecision>, options?: {
30
30
  prepend?: boolean;
31
31
  }): unknown;
32
+ on(event: "agent/created", listener: (payload: unknown) => unknown): unknown;
32
33
  systemPrompt: {
33
34
  section(section: {
34
35
  name: string;
package/lib/index.js CHANGED
@@ -6,10 +6,14 @@
6
6
  * 注入形态(设计理由见 README):
7
7
  *
8
8
  * section order 1 → the authoritative rule, once per session
9
- * pre-step step 1 → a short reminder, at most once per turn (interval configurable, default 30 min)
9
+ * pre-step step 1 → a short reminder at the head of the batch, at most once per turn
10
+ * (interval configurable, default 30 min)
11
+ * pre-step step 1 → the closing rule, folded into the skill catalogue when the
12
+ * extra-injection setting is on
10
13
  *
11
14
  * section order 1 → 权威规则,每会话组装一次
12
- * pre-step step 1 → 短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
15
+ * pre-step step 1 → 批次开头的短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
16
+ * pre-step step 1 → 收尾规则,额外注入开启时折进技能目录
13
17
  *
14
18
  * The host context is described by a local structural interface rather than the
15
19
  * `@deepseek-ai/cordis` type, so this package carries no DSH type dependency.
@@ -18,7 +22,7 @@
18
22
  */
19
23
  import { randomUUID } from "node:crypto";
20
24
  import z from "@deepseek-ai/schemastery";
21
- import { AUTO, DEFAULT_REMINDER_MINUTES, FIELD_LANGUAGE, FIELD_REMINDER, REMINDER_OFF, SELECTABLE_TAGS, SETTINGS_NAMESPACE, effectiveCode, nativeNameFor, normalizeSettings, reminderDelayMs, reminderText, sectionText } from "./core.js";
25
+ import { AUTO, DEFAULT_REMINDER_MINUTES, DEFAULTS, FIELD_EXTRA, FIELD_LANGUAGE, FIELD_REMINDER, REMINDER_OFF, SELECTABLE_TAGS, SETTINGS_NAMESPACE, effectiveCode, nativeNameFor, normalizeSettings, reminderDelayMs, reminderText, tailText, sectionText } from "./core.js";
22
26
  /** Stable Cordis plugin name. / 稳定的 Cordis 插件名。 */
23
27
  export const name = "ay-dsh-tk-lang";
24
28
  /** Plugin-level service requirements; services are acquired per branch below. / 插件级服务声明;服务在下方逐分支获取。 */
@@ -91,7 +95,8 @@ function buildSchema() {
91
95
  const choices = [AUTO, ...SELECTABLE_TAGS].map((value) => labelled(z.const(value), nativeNameFor(value)));
92
96
  return z.object({
93
97
  [FIELD_LANGUAGE]: live(z.union(choices).default(AUTO)),
94
- [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES))
98
+ [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES)),
99
+ [FIELD_EXTRA]: live(z.boolean().default(DEFAULTS.extraInjection))
95
100
  });
96
101
  }
97
102
  /** Durable settings schema; the field defaults to {@link AUTO}. / 持久化设置 schema;字段默认为 {@link AUTO}。 */
@@ -247,6 +252,40 @@ function reminderMessage(text) {
247
252
  source: { kind: name, form: "snapshot", sections: [{ name, text }] }
248
253
  };
249
254
  }
255
+ /**
256
+ * Put the rule in front of the text a message already carries.
257
+ * 把规则放到消息已有文本的前面。
258
+ */
259
+ function prefixPrompt(message, text) {
260
+ const content = Array.isArray(message.content) ? message.content : [];
261
+ const head = content[0];
262
+ if (head && head.type === "text" && typeof head.text === "string" && head.text.startsWith(text))
263
+ return message;
264
+ return { ...message, content: [{ type: "text", text: `${text}\n` }, ...content] };
265
+ }
266
+ /**
267
+ * Rewrite the skill-catalog injection so the rule opens a block the model reads as
268
+ * instruction, not as the text it has to answer. Falls back to the last injected
269
+ * message when no skill catalogue is present. / 改写 skill-catalog 注入,让规则出现在
270
+ * 模型读作指令的块开头;没有技能目录时退回最后一条注入消息。
271
+ */
272
+ function prefixInjected(messages, text) {
273
+ let index = messages.findIndex((message) => message.source?.kind === "skill-catalog");
274
+ if (index < 0) {
275
+ for (let cursor = messages.length - 1; cursor >= 0; cursor -= 1) {
276
+ const source = messages[cursor].source;
277
+ if (messages[cursor].role === "user" && source?.kind !== name) {
278
+ index = cursor;
279
+ break;
280
+ }
281
+ }
282
+ }
283
+ if (index < 0)
284
+ return messages;
285
+ const next = [...messages];
286
+ next[index] = prefixPrompt(messages[index], text);
287
+ return next;
288
+ }
250
289
  /**
251
290
  * Register the settings consumer, the prompt section, and the per-turn reminder.
252
291
  * 注册设置消费方、提示词段,以及每轮一次的提醒。
@@ -264,10 +303,11 @@ export function apply(ctx) {
264
303
  order: SECTION_ORDER,
265
304
  text: () => sectionText(currentSettings(reader()).language)
266
305
  });
267
- // The reminder runs before the other pre-step listeners, so its message is
268
- // appended after theirs and stays closest to the end of the request.
269
- // 该提醒先于其它 pre-step 监听器执行,因此它的消息追加在它们之后,离请求末尾最近。
270
- promptCtx.on("agent/pre-step", async (payload, next) => {
306
+ /**
307
+ * Wrap the batch in two reminders: one before the prompt, one after every injection.
308
+ * 用两条提醒夹住批次:一条在提问之前,一条在全部注入之后。
309
+ */
310
+ const rewrite = async (payload, next) => {
271
311
  const decision = await next();
272
312
  if (decision.kind !== "enter" || payload.signal.aborted || payload.step !== 1)
273
313
  return decision;
@@ -279,11 +319,32 @@ export function apply(ctx) {
279
319
  const previous = lastReminderAt.get(payload.agent.session.id);
280
320
  if (delay > 0 && previous !== undefined && now - previous < delay)
281
321
  return decision;
282
- const text = reminderText(settings.language);
283
- if (text === "")
322
+ const head = reminderText(settings.language);
323
+ if (head === "")
284
324
  return decision;
285
325
  lastReminderAt.set(payload.agent.session.id, now);
286
- return { ...decision, messages: [...decision.messages, reminderMessage(text)] };
287
- }, { prepend: true });
326
+ // The closing rule rides on the same switch as the reminder: turning the
327
+ // reminder off skips this whole listener, so both injections stop together.
328
+ // 收尾规则与提醒共用一个开关:提醒关闭时本段不执行,两处注入一起停。
329
+ const tail = settings.extraInjection ? tailText(settings.language) : "";
330
+ const messages = tail === "" ? decision.messages : prefixInjected(decision.messages, tail);
331
+ return { ...decision, messages: [reminderMessage(head), ...messages] };
332
+ };
333
+ /**
334
+ * `prepend` unshifts, so the listener prepended last runs first and returns last:
335
+ * only it sees every message the other pre-step listeners appended, including the
336
+ * trailing `time-context` batch.
337
+ * `prepend` 是 unshift:最后 prepend 的监听器最先执行、最后返回,只有它能看见其它
338
+ * pre-step 监听器追加的全部消息,包括压在最后的 `time-context`。
339
+ */
340
+ let disposeStep;
341
+ const bindOutermost = () => {
342
+ disposeStep?.();
343
+ disposeStep = promptCtx.on("agent/pre-step", rewrite, { prepend: true });
344
+ };
345
+ bindOutermost();
346
+ promptCtx.on("agent/created", () => {
347
+ bindOutermost();
348
+ });
288
349
  });
289
350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-lang",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "DSH plugin: set the agent's reasoning language (Settings → General)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,6 +29,14 @@ export interface Dict {
29
29
  reminderUnit: string;
30
30
  /** Hint under the custom interval input. / 自定义间隔输入框的提示。 */
31
31
  reminderCustomHint: string;
32
+ /** Extra-injection row heading. / 额外注入行的标题。 */
33
+ extraHeading: string;
34
+ /** Extra-injection row description. / 额外注入行的说明。 */
35
+ extraDescription: string;
36
+ /** Label of the enabled option. / 开启选项的标签。 */
37
+ extraOn: string;
38
+ /** Label of the disabled option. / 关闭选项的标签。 */
39
+ extraOff: string;
32
40
  }
33
41
 
34
42
  /** Simplified Chinese copy. / 简体中文文案。 */
@@ -42,7 +50,11 @@ export const zh: Dict = {
42
50
  reminderTurn: "每轮",
43
51
  reminderCustom: "自定义",
44
52
  reminderUnit: "分钟",
45
- reminderCustomHint: "1–1440 分钟"
53
+ reminderCustomHint: "1–1440 分钟",
54
+ extraHeading: "额外提醒注入",
55
+ extraDescription: "开启后把提醒同时并入技能目录;提醒间隔为「关闭」时,此项也一并关闭。",
56
+ extraOn: "开启",
57
+ extraOff: "关闭"
46
58
  };
47
59
 
48
60
  /** English copy. / 英文文案。 */
@@ -57,7 +69,12 @@ export const en: Dict = {
57
69
  reminderTurn: "Every turn",
58
70
  reminderCustom: "Custom",
59
71
  reminderUnit: "min",
60
- reminderCustomHint: "1–1440 minutes"
72
+ reminderCustomHint: "1–1440 minutes",
73
+ extraHeading: "Extra reminder injection",
74
+ extraDescription:
75
+ "Also folds the reminder into the skill catalogue. Switching the reminder interval off turns this off too.",
76
+ extraOn: "On",
77
+ extraOff: "Off"
61
78
  };
62
79
 
63
80
  /** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
@@ -14,6 +14,7 @@ import {
14
14
  AUTO,
15
15
  CATALOGUE,
16
16
  DEFAULTS,
17
+ FIELD_EXTRA,
17
18
  FIELD_LANGUAGE,
18
19
  FIELD_REMINDER,
19
20
  MAX_REMINDER_MINUTES,
@@ -268,6 +269,59 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
268
269
  };
269
270
  }
270
271
 
272
+ /**
273
+ * Build the extra-injection picker: on or off.
274
+ * 构建额外注入选择器:开启或关闭。
275
+ *
276
+ * It shares the host Menu with the other controls, so the three read as one column.
277
+ * 与另外两个控件共用宿主 Menu,三者在视觉上成一列。
278
+ */
279
+ function createExtraPicker(primitives: UiPrimitives | undefined) {
280
+ const Menu = primitives?.Menu;
281
+ const Chevron =
282
+ primitives?.IconChevronDownOutlineRegular ??
283
+ primitives?.IconChevronDownOutline14 ??
284
+ primitives?.IconChevronDownOutlineMedium;
285
+
286
+ return function ExtraPicker(props: Binding & { settings: ThinkingSettings; disabled?: boolean }): unknown {
287
+ const { doc, t, settings, disabled = false } = props;
288
+ const [open, setOpen] = useState<boolean>(false);
289
+ const items = [
290
+ { id: "on", label: t("extraOn") },
291
+ { id: "off", label: t("extraOff") }
292
+ ];
293
+ const close = (): void => setOpen(false);
294
+ const choose = (id: string): void => {
295
+ writeField(doc, FIELD_EXTRA, id === "on");
296
+ close();
297
+ };
298
+ const picker = h(
299
+ "button",
300
+ {
301
+ type: "button",
302
+ className: "dsh_desk_lang_picker",
303
+ "aria-haspopup": "menu",
304
+ "aria-expanded": open,
305
+ disabled,
306
+ onClick: (): void => setOpen((value: boolean) => !value)
307
+ },
308
+ settings.extraInjection ? t("extraOn") : t("extraOff"),
309
+ Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
310
+ );
311
+ if (!Menu) return picker;
312
+ return h(Menu, {
313
+ open,
314
+ anchor: picker,
315
+ items,
316
+ selectedId: settings.extraInjection ? "on" : "off",
317
+ align: "end",
318
+ portal: true,
319
+ onClose: close,
320
+ onSelect: choose
321
+ });
322
+ };
323
+ }
324
+
271
325
  /**
272
326
  * Build the General settings row: heading, description and the language picker.
273
327
  * 构建「通用」设置行:标题、说明与语言选择器。
@@ -302,10 +356,15 @@ export function createRow(primitives: UiPrimitives | undefined): (props: Binding
302
356
  export function createConfigCard(primitives: UiPrimitives | undefined): (props: Binding & { view?: string }) => unknown {
303
357
  const LanguagePicker = createLanguagePicker(primitives);
304
358
  const ReminderPicker = createReminderPicker(primitives);
359
+ const ExtraPicker = createExtraPicker(primitives);
305
360
  return function ThinkingLanguageCard(props: Binding & { view?: string }): unknown {
306
361
  const settings = useSettings(props.doc);
307
362
  if (props.view === "summary") return null;
308
363
  const binding = { doc: props.doc, t: props.t, settings };
364
+ // Turning the reminder off stops both injections, so the extra-injection
365
+ // control greys out instead of accepting a value that cannot take effect.
366
+ // 提醒关闭时两处注入都会停,因此额外注入控件置灰,而不是让一个不生效的取值可选。
367
+ const reminderOff = settings.reminderMinutes < 0;
309
368
  return h(
310
369
  "div",
311
370
  null,
@@ -330,6 +389,17 @@ export function createConfigCard(primitives: UiPrimitives | undefined): (props:
330
389
  h("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))
331
390
  ),
332
391
  h(ReminderPicker, binding)
392
+ ),
393
+ h(
394
+ "div",
395
+ { className: reminderOff ? "dsh_desk_lang_row dsh_desk_lang_row_disabled" : "dsh_desk_lang_row" },
396
+ h(
397
+ "div",
398
+ { className: "dsh_desk_lang_text" },
399
+ h("div", { className: "dsh_desk_lang_title" }, props.t("extraHeading")),
400
+ h("div", { className: "dsh_desk_lang_desc" }, props.t("extraDescription"))
401
+ ),
402
+ h(ExtraPicker, { ...binding, disabled: reminderOff })
333
403
  )
334
404
  );
335
405
  };
@@ -344,6 +414,7 @@ export function createConfigCard(primitives: UiPrimitives | undefined): (props:
344
414
  // 选择器末尾多一个宿主不需要的 `flex:none`;除此之外逐字符一致。
345
415
  const rowCss = [
346
416
  ".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
417
+ ".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
347
418
  ".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
348
419
  ".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
349
420
  ".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
package/src/core.ts CHANGED
@@ -34,8 +34,10 @@ export interface Language {
34
34
  nativeName: string;
35
35
  /** The rule sentence written in this language. / 用本语言写成的规则句。 */
36
36
  section: string;
37
- /** The short per-turn reminder written in this language. / 用本语言写成的每轮短提醒。 */
37
+ /** The short reminder written in this language for the head of the batch. / 写在批次开头的短提醒。 */
38
38
  reminder: string;
39
+ /** The short reminder written for the last message of the request. / 写在请求末尾的短提醒。 */
40
+ tail: string;
39
41
  }
40
42
 
41
43
  /**
@@ -55,19 +57,22 @@ export const CATALOGUE: readonly Language[] = [
55
57
  tag: "zh-CN",
56
58
  nativeName: "简体中文",
57
59
  section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
58
- reminder: "继续用简体中文思考、推理与规划。"
60
+ reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
61
+ tail: "下文请使用简体中文思考"
59
62
  },
60
63
  {
61
64
  tag: "zh-TW",
62
65
  nativeName: "繁體中文",
63
66
  section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
64
- reminder: "繼續用繁體中文思考、推理與規劃。"
67
+ reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
68
+ tail: "下文請使用繁體中文思考"
65
69
  },
66
70
  {
67
71
  tag: "en",
68
72
  nativeName: "English",
69
73
  section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
70
- reminder: "Keep thinking, reasoning, and planning in English."
74
+ reminder: "Note: think, reason, and plan in English, even if the text above is not",
75
+ tail: "Think in English from here on"
71
76
  }
72
77
  ];
73
78
 
@@ -86,6 +91,9 @@ export const FIELD_LANGUAGE = "language";
86
91
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
87
92
  export const FIELD_REMINDER = "reminderMinutes";
88
93
 
94
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
95
+ export const FIELD_EXTRA = "extraInjection";
96
+
89
97
  /** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
90
98
  export const REMINDER_OFF = -1;
91
99
 
@@ -112,10 +120,20 @@ export interface ThinkingSettings {
112
120
  * 注入,1–1440 为最小间隔。
113
121
  */
114
122
  reminderMinutes: number;
123
+ /**
124
+ * Whether the closing rule is also folded into the skill catalogue. It only
125
+ * applies while the reminder is on.
126
+ * 是否把收尾规则同时折进技能目录;仅在提醒开启时生效。
127
+ */
128
+ extraInjection: boolean;
115
129
  }
116
130
 
117
131
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
118
- export const DEFAULTS: ThinkingSettings = { language: AUTO, reminderMinutes: DEFAULT_REMINDER_MINUTES };
132
+ export const DEFAULTS: ThinkingSettings = {
133
+ language: AUTO,
134
+ reminderMinutes: DEFAULT_REMINDER_MINUTES,
135
+ extraInjection: true
136
+ };
119
137
 
120
138
  /** A minimal read handle over the host settings service. / 宿主设置服务的最小读取句柄。 */
121
139
  export interface Reader {
@@ -233,6 +251,11 @@ function normalizeReminder(raw: unknown): number {
233
251
  return rounded > MAX_REMINDER_MINUTES ? MAX_REMINDER_MINUTES : rounded;
234
252
  }
235
253
 
254
+ /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
255
+ function normalizeExtra(raw: unknown): boolean {
256
+ return raw !== false && raw !== "false";
257
+ }
258
+
236
259
  /**
237
260
  * Convert stored minutes into the minimum gap between reminders.
238
261
  * 把存储的分钟数换算成两次提醒之间的最小间隔。
@@ -251,7 +274,8 @@ export function normalizeSettings(raw: unknown): ThinkingSettings {
251
274
  const stored = section?.[FIELD_LANGUAGE];
252
275
  return {
253
276
  language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
254
- reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
277
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
278
+ extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
255
279
  };
256
280
  }
257
281
 
@@ -297,3 +321,11 @@ export function sectionText(code: string): string {
297
321
  export function reminderText(code: string): string {
298
322
  return languageOf(code)?.reminder ?? "";
299
323
  }
324
+
325
+ /**
326
+ * Build the closing reminder appended as the request's last message.
327
+ * 生成追加在请求最后一条消息里的收尾提醒。
328
+ */
329
+ export function tailText(code: string): string {
330
+ return languageOf(code)?.tail ?? "";
331
+ }
package/src/index.ts CHANGED
@@ -6,10 +6,14 @@
6
6
  * 注入形态(设计理由见 README):
7
7
  *
8
8
  * section order 1 → the authoritative rule, once per session
9
- * pre-step step 1 → a short reminder, at most once per turn (interval configurable, default 30 min)
9
+ * pre-step step 1 → a short reminder at the head of the batch, at most once per turn
10
+ * (interval configurable, default 30 min)
11
+ * pre-step step 1 → the closing rule, folded into the skill catalogue when the
12
+ * extra-injection setting is on
10
13
  *
11
14
  * section order 1 → 权威规则,每会话组装一次
12
- * pre-step step 1 → 短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
15
+ * pre-step step 1 → 批次开头的短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
16
+ * pre-step step 1 → 收尾规则,额外注入开启时折进技能目录
13
17
  *
14
18
  * The host context is described by a local structural interface rather than the
15
19
  * `@deepseek-ai/cordis` type, so this package carries no DSH type dependency.
@@ -21,6 +25,8 @@ import z from "@deepseek-ai/schemastery";
21
25
  import {
22
26
  AUTO,
23
27
  DEFAULT_REMINDER_MINUTES,
28
+ DEFAULTS,
29
+ FIELD_EXTRA,
24
30
  FIELD_LANGUAGE,
25
31
  FIELD_REMINDER,
26
32
  REMINDER_OFF,
@@ -33,6 +39,7 @@ import {
33
39
  normalizeSettings,
34
40
  reminderDelayMs,
35
41
  reminderText,
42
+ tailText,
36
43
  sectionText
37
44
  } from "./core.js";
38
45
 
@@ -121,7 +128,8 @@ function buildSchema(): z<ThinkingSettings> {
121
128
  const choices = [AUTO, ...SELECTABLE_TAGS].map((value) => labelled(z.const(value), nativeNameFor(value)));
122
129
  return z.object({
123
130
  [FIELD_LANGUAGE]: live(z.union(choices).default(AUTO)),
124
- [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES))
131
+ [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES)),
132
+ [FIELD_EXTRA]: live(z.boolean().default(DEFAULTS.extraInjection))
125
133
  });
126
134
  }
127
135
 
@@ -300,6 +308,7 @@ interface HostContext {
300
308
  listener: (payload: PreStepPayload, next: () => Promise<PreStepDecision>) => Promise<PreStepDecision>,
301
309
  options?: { prepend?: boolean }
302
310
  ): unknown;
311
+ on(event: "agent/created", listener: (payload: unknown) => unknown): unknown;
303
312
  systemPrompt: {
304
313
  section(section: { name: string; order?: number; text: () => string }): unknown;
305
314
  };
@@ -322,6 +331,40 @@ function reminderMessage(text: string): Record<string, unknown> {
322
331
  };
323
332
  }
324
333
 
334
+ /**
335
+ * Put the rule in front of the text a message already carries.
336
+ * 把规则放到消息已有文本的前面。
337
+ */
338
+ function prefixPrompt(message: Record<string, unknown>, text: string): Record<string, unknown> {
339
+ const content = Array.isArray(message.content) ? (message.content as Array<Record<string, unknown>>) : [];
340
+ const head = content[0];
341
+ if (head && head.type === "text" && typeof head.text === "string" && head.text.startsWith(text)) return message;
342
+ return { ...message, content: [{ type: "text", text: `${text}\n` }, ...content] };
343
+ }
344
+
345
+ /**
346
+ * Rewrite the skill-catalog injection so the rule opens a block the model reads as
347
+ * instruction, not as the text it has to answer. Falls back to the last injected
348
+ * message when no skill catalogue is present. / 改写 skill-catalog 注入,让规则出现在
349
+ * 模型读作指令的块开头;没有技能目录时退回最后一条注入消息。
350
+ */
351
+ function prefixInjected(messages: Array<Record<string, unknown>>, text: string): Array<Record<string, unknown>> {
352
+ let index = messages.findIndex((message) => (message.source as { kind?: unknown } | undefined)?.kind === "skill-catalog");
353
+ if (index < 0) {
354
+ for (let cursor = messages.length - 1; cursor >= 0; cursor -= 1) {
355
+ const source = messages[cursor].source as { kind?: unknown } | undefined;
356
+ if (messages[cursor].role === "user" && source?.kind !== name) {
357
+ index = cursor;
358
+ break;
359
+ }
360
+ }
361
+ }
362
+ if (index < 0) return messages;
363
+ const next = [...messages];
364
+ next[index] = prefixPrompt(messages[index], text);
365
+ return next;
366
+ }
367
+
325
368
  /**
326
369
  * Register the settings consumer, the prompt section, and the per-turn reminder.
327
370
  * 注册设置消费方、提示词段,以及每轮一次的提醒。
@@ -342,10 +385,11 @@ export function apply(ctx: HostContext): void {
342
385
  text: () => sectionText(currentSettings(reader()).language)
343
386
  });
344
387
 
345
- // The reminder runs before the other pre-step listeners, so its message is
346
- // appended after theirs and stays closest to the end of the request.
347
- // 该提醒先于其它 pre-step 监听器执行,因此它的消息追加在它们之后,离请求末尾最近。
348
- promptCtx.on("agent/pre-step", async (payload, next) => {
388
+ /**
389
+ * Wrap the batch in two reminders: one before the prompt, one after every injection.
390
+ * 用两条提醒夹住批次:一条在提问之前,一条在全部注入之后。
391
+ */
392
+ const rewrite = async (payload: PreStepPayload, next: () => Promise<PreStepDecision>) => {
349
393
  const decision = await next();
350
394
  if (decision.kind !== "enter" || payload.signal.aborted || payload.step !== 1) return decision;
351
395
  const settings = currentSettings(reader());
@@ -354,10 +398,32 @@ export function apply(ctx: HostContext): void {
354
398
  const now = Date.now();
355
399
  const previous = lastReminderAt.get(payload.agent.session.id);
356
400
  if (delay > 0 && previous !== undefined && now - previous < delay) return decision;
357
- const text = reminderText(settings.language);
358
- if (text === "") return decision;
401
+ const head = reminderText(settings.language);
402
+ if (head === "") return decision;
359
403
  lastReminderAt.set(payload.agent.session.id, now);
360
- return { ...decision, messages: [...decision.messages, reminderMessage(text)] };
361
- }, { prepend: true });
404
+ // The closing rule rides on the same switch as the reminder: turning the
405
+ // reminder off skips this whole listener, so both injections stop together.
406
+ // 收尾规则与提醒共用一个开关:提醒关闭时本段不执行,两处注入一起停。
407
+ const tail = settings.extraInjection ? tailText(settings.language) : "";
408
+ const messages = tail === "" ? decision.messages : prefixInjected(decision.messages, tail);
409
+ return { ...decision, messages: [reminderMessage(head), ...messages] };
410
+ };
411
+
412
+ /**
413
+ * `prepend` unshifts, so the listener prepended last runs first and returns last:
414
+ * only it sees every message the other pre-step listeners appended, including the
415
+ * trailing `time-context` batch.
416
+ * `prepend` 是 unshift:最后 prepend 的监听器最先执行、最后返回,只有它能看见其它
417
+ * pre-step 监听器追加的全部消息,包括压在最后的 `time-context`。
418
+ */
419
+ let disposeStep: (() => void) | undefined;
420
+ const bindOutermost = (): void => {
421
+ disposeStep?.();
422
+ disposeStep = promptCtx.on("agent/pre-step", rewrite, { prepend: true }) as () => void;
423
+ };
424
+ bindOutermost();
425
+ promptCtx.on("agent/created", () => {
426
+ bindOutermost();
427
+ });
362
428
  });
363
429
  }