dsh-thinking-lang 1.0.5 → 1.0.7

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/src/core.ts CHANGED
@@ -80,9 +80,24 @@ const FALLBACK_TAG = "zh-CN";
80
80
  /** Settings namespace owned by this plugin. / 本插件拥有的设置命名空间。 */
81
81
  export const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
82
82
 
83
- /** The one field this plugin stores. / 本插件唯一保存的字段。 */
83
+ /** The language field this plugin stores. / 本插件保存的语言字段。 */
84
84
  export const FIELD_LANGUAGE = "language";
85
85
 
86
+ /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
87
+ export const FIELD_REMINDER = "reminderMinutes";
88
+
89
+ /** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
90
+ export const REMINDER_OFF = -1;
91
+
92
+ /** Reminder value that injects on every turn. / 每轮都注入的取值。 */
93
+ export const REMINDER_EVERY_TURN = 0;
94
+
95
+ /** Reminder interval applied when the field is absent. / 字段缺失时的提醒间隔(分钟)。 */
96
+ export const DEFAULT_REMINDER_MINUTES = 30;
97
+
98
+ /** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
99
+ export const MAX_REMINDER_MINUTES = 1440;
100
+
86
101
  /** Every value the picker offers besides {@link AUTO}. / 选择器在 {@link AUTO} 之外提供的全部取值。 */
87
102
  export const SELECTABLE_TAGS: readonly string[] = CATALOGUE.map((language) => language.tag);
88
103
 
@@ -90,10 +105,17 @@ export const SELECTABLE_TAGS: readonly string[] = CATALOGUE.map((language) => la
90
105
  export interface ThinkingSettings {
91
106
  /** Selected language tag, or {@link AUTO}. / 所选语言标签,或 {@link AUTO}。 */
92
107
  language: string;
108
+ /**
109
+ * Minutes between reminders: {@link REMINDER_OFF} disables them,
110
+ * {@link REMINDER_EVERY_TURN} injects on every turn, and 1–1440 is a minimum gap.
111
+ * 提醒间隔(分钟):{@link REMINDER_OFF} 关闭,{@link REMINDER_EVERY_TURN} 每轮
112
+ * 注入,1–1440 为最小间隔。
113
+ */
114
+ reminderMinutes: number;
93
115
  }
94
116
 
95
- /** Configuration applied when the field is absent. / 字段缺失时采用的配置。 */
96
- export const DEFAULTS: ThinkingSettings = { language: AUTO };
117
+ /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
118
+ export const DEFAULTS: ThinkingSettings = { language: AUTO, reminderMinutes: DEFAULT_REMINDER_MINUTES };
97
119
 
98
120
  /** A minimal read handle over the host settings service. / 宿主设置服务的最小读取句柄。 */
99
121
  export interface Reader {
@@ -202,10 +224,35 @@ function tagForLocale(raw: unknown): string | undefined {
202
224
  * Coerce an untrusted settings section into a complete configuration.
203
225
  * 把不可信的设置段强制转换为完整配置。
204
226
  */
227
+ /** Clamp one untrusted reminder value into the accepted range; any negative value disables it. / 把不可信的提醒值收敛到允许范围;负数一律视为关闭。 */
228
+ function normalizeReminder(raw: unknown): number {
229
+ const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
230
+ if (!Number.isFinite(numeric)) return DEFAULT_REMINDER_MINUTES;
231
+ const rounded = Math.round(numeric);
232
+ if (rounded < 0) return REMINDER_OFF;
233
+ return rounded > MAX_REMINDER_MINUTES ? MAX_REMINDER_MINUTES : rounded;
234
+ }
235
+
236
+ /**
237
+ * Convert stored minutes into the minimum gap between reminders.
238
+ * 把存储的分钟数换算成两次提醒之间的最小间隔。
239
+ *
240
+ * Returns {@link REMINDER_OFF} when the reminder is disabled and `0` when it runs
241
+ * on every turn. / 关闭时返回 {@link REMINDER_OFF},每轮注入时返回 `0`。
242
+ */
243
+ export function reminderDelayMs(minutes: number): number {
244
+ if (minutes < 0) return REMINDER_OFF;
245
+ if (minutes === REMINDER_EVERY_TURN) return 0;
246
+ return minutes * 60_000;
247
+ }
248
+
205
249
  export function normalizeSettings(raw: unknown): ThinkingSettings {
206
- const isSection = raw !== null && typeof raw === "object" && !Array.isArray(raw);
207
- const stored = isSection ? (raw as Record<string, unknown>)[FIELD_LANGUAGE] : undefined;
208
- return { language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language };
250
+ const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? (raw as Record<string, unknown>) : undefined;
251
+ const stored = section?.[FIELD_LANGUAGE];
252
+ return {
253
+ language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
254
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
255
+ };
209
256
  }
210
257
 
211
258
  /**
package/src/index.ts CHANGED
@@ -6,10 +6,10 @@
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 (10 min apart)
9
+ * pre-step step 1 → a short reminder, at most once per turn (interval configurable, default 30 min)
10
10
  *
11
11
  * section order 1 → 权威规则,每会话组装一次
12
- * pre-step step 1 → 短提醒,每轮最多一次(间隔 10 分钟)
12
+ * pre-step step 1 → 短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
13
13
  *
14
14
  * The host context is described by a local structural interface rather than the
15
15
  * `@deepseek-ai/cordis` type, so this package carries no DSH type dependency.
@@ -20,7 +20,10 @@ import { randomUUID } from "node:crypto";
20
20
  import z from "@deepseek-ai/schemastery";
21
21
  import {
22
22
  AUTO,
23
+ DEFAULT_REMINDER_MINUTES,
23
24
  FIELD_LANGUAGE,
25
+ FIELD_REMINDER,
26
+ REMINDER_OFF,
24
27
  SELECTABLE_TAGS,
25
28
  SETTINGS_NAMESPACE,
26
29
  type Reader,
@@ -28,6 +31,7 @@ import {
28
31
  effectiveCode,
29
32
  nativeNameFor,
30
33
  normalizeSettings,
34
+ reminderDelayMs,
31
35
  reminderText,
32
36
  sectionText
33
37
  } from "./core.js";
@@ -47,9 +51,6 @@ export const inject: string[] = [];
47
51
  */
48
52
  const SECTION_ORDER = 1;
49
53
 
50
- /** Minimum milliseconds between two per-turn reminders in one session. / 同一会话中两次每轮提醒之间的最小毫秒数。 */
51
- const REMINDER_INTERVAL_MS = 600_000;
52
-
53
54
  /** Settings namespace holding the desktop UI locale. / 保存桌面 UI 语言的设置命名空间。 */
54
55
  const LOCALE_NAMESPACE = "locale";
55
56
 
@@ -118,7 +119,10 @@ function labelled<T>(node: z<T>, label: string | undefined): z<T> {
118
119
  */
119
120
  function buildSchema(): z<ThinkingSettings> {
120
121
  const choices = [AUTO, ...SELECTABLE_TAGS].map((value) => labelled(z.const(value), nativeNameFor(value)));
121
- return z.object({ [FIELD_LANGUAGE]: live(z.union(choices).default(AUTO)) });
122
+ return z.object({
123
+ [FIELD_LANGUAGE]: live(z.union(choices).default(AUTO)),
124
+ [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES))
125
+ });
122
126
  }
123
127
 
124
128
  /** Durable settings schema; the field defaults to {@link AUTO}. / 持久化设置 schema;字段默认为 {@link AUTO}。 */
@@ -261,13 +265,16 @@ function osLocale(): string | undefined {
261
265
  }
262
266
 
263
267
  /**
264
- * Resolve the effective language for one prompt build.
265
- * 为一次提示词构建解析出生效语言。
268
+ * Resolve the configuration in effect for one prompt build.
269
+ * 为一次提示词构建解析出当前生效的配置。
266
270
  */
267
- function currentLanguage(reader: Reader): string {
271
+ function currentSettings(reader: Reader): ThinkingSettings {
268
272
  const settings = normalizeSettings(sectionOf(reader, SETTINGS_NAMESPACE));
269
273
  const desktop = sectionOf(reader, LOCALE_NAMESPACE)?.[LOCALE_FIELD];
270
- return effectiveCode(settings, osLocale(), typeof desktop === "string" ? desktop : undefined);
274
+ return {
275
+ ...settings,
276
+ language: effectiveCode(settings, osLocale(), typeof desktop === "string" ? desktop : undefined)
277
+ };
271
278
  }
272
279
 
273
280
  /** One pre-step payload slice this entry reads. / 本入口读取的 pre-step 载荷切片。 */
@@ -332,7 +339,7 @@ export function apply(ctx: HostContext): void {
332
339
  promptCtx.systemPrompt.section({
333
340
  name: "app:tk-lang",
334
341
  order: SECTION_ORDER,
335
- text: () => sectionText(currentLanguage(reader()))
342
+ text: () => sectionText(currentSettings(reader()).language)
336
343
  });
337
344
 
338
345
  // The reminder runs before the other pre-step listeners, so its message is
@@ -341,10 +348,13 @@ export function apply(ctx: HostContext): void {
341
348
  promptCtx.on("agent/pre-step", async (payload, next) => {
342
349
  const decision = await next();
343
350
  if (decision.kind !== "enter" || payload.signal.aborted || payload.step !== 1) return decision;
351
+ const settings = currentSettings(reader());
352
+ const delay = reminderDelayMs(settings.reminderMinutes);
353
+ if (delay === REMINDER_OFF) return decision;
344
354
  const now = Date.now();
345
355
  const previous = lastReminderAt.get(payload.agent.session.id);
346
- if (previous !== undefined && now - previous < REMINDER_INTERVAL_MS) return decision;
347
- const text = reminderText(currentLanguage(reader()));
356
+ if (delay > 0 && previous !== undefined && now - previous < delay) return decision;
357
+ const text = reminderText(settings.language);
348
358
  if (text === "") return decision;
349
359
  lastReminderAt.set(payload.agent.session.id, now);
350
360
  return { ...decision, messages: [...decision.messages, reminderMessage(text)] };