dsh-session-guard 4.2.12 → 4.3.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/locale/pt.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Comporta automática de sessão em horas de pico",
4
+ "description": "Pausar automaticamente as sessões ativas durante as horas de pico. Nos horários de pico, somente as fontes oficiais do DeepSeek são bloqueadas; provedores locais/de terceiros continuam funcionando"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-guard",
3
- "version": "4.2.12",
3
+ "version": "4.3.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "tag": "latest"
@@ -46,6 +46,7 @@
46
46
  "README.it.md",
47
47
  "README.ru.md",
48
48
  "README.es.md",
49
+ "README.pt.md",
49
50
  "INSTALL.md",
50
51
  "INSTALL.zh.md",
51
52
  "INSTALL.ja.md",
@@ -55,6 +56,7 @@
55
56
  "INSTALL.it.md",
56
57
  "INSTALL.ru.md",
57
58
  "INSTALL.es.md",
59
+ "INSTALL.pt.md",
58
60
  "CHANGELOG.md",
59
61
  "CHANGELOG.ja.md",
60
62
  "CHANGELOG.ko.md",
@@ -63,6 +65,7 @@
63
65
  "CHANGELOG.it.md",
64
66
  "CHANGELOG.ru.md",
65
67
  "CHANGELOG.es.md",
68
+ "CHANGELOG.pt.md",
66
69
  "locale",
67
70
  "LICENSE"
68
71
  ],
@@ -92,10 +95,10 @@
92
95
  },
93
96
  "peerDependencies": {
94
97
  "@deepseek-ai/cordis": "^4.0.4",
95
- "@deepseek-ai/dsh-client-locale": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
96
- "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
97
- "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
98
- "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1"
98
+ "@deepseek-ai/dsh-client-locale": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1 || 0.2.2-rc.2 || 0.2.2-rc.3 || 0.2.2-rc.4 || 0.2.2-rc.5",
99
+ "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1 || 0.2.2-rc.2 || 0.2.2-rc.3 || 0.2.2-rc.4 || 0.2.2-rc.5",
100
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1 || 0.2.2-rc.2 || 0.2.2-rc.3 || 0.2.2-rc.4 || 0.2.2-rc.5",
101
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1 || 0.2.2-rc.2 || 0.2.2-rc.3 || 0.2.2-rc.4 || 0.2.2-rc.5"
99
102
  },
100
103
  "peerDependenciesMeta": {
101
104
  "@deepseek-ai/cordis": {
@@ -173,7 +173,7 @@ function mountConfigCards(ctx: ClientCtx): void {
173
173
  }
174
174
 
175
175
  export function apply(ctx: ClientCtx) {
176
- // 注册全部 9 种语言字典(zh/en/ja/ko/fr/de/it/ru/es)。
176
+ // 注册全部 10 种语言字典(zh/en/ja/ko/fr/de/it/ru/es/pt)。
177
177
  // 本插件此前 locales.ts 未被任何模块 import → 字典从未进入 bundle、从未注册(死代码)。
178
178
  // guarded:register 抛错不得带走下面的席位注册;effect 缺席时直接调一次(同语义)。
179
179
  safe('locale/dictionaries', () => {
@@ -1,4 +1,4 @@
1
- /** `session-guard` client dictionaries (zh / en / ja / ko / fr / de / it / ru / es). */
1
+ /** `session-guard` client dictionaries (zh / en / ja / ko / fr / de / it / ru / es / pt). */
2
2
 
3
3
  /** Dictionary namespace owned by this plugin. */
4
4
  export const NS = 'session-guard'
@@ -354,8 +354,47 @@ export const es: Record<keyof typeof zh, string> = {
354
354
  'status.peak_all': 'Pico · todo pausado',
355
355
  }
356
356
 
357
+ /** Brazilian Portuguese dictionary (keys mirror zh). */
358
+ export const pt: Record<keyof typeof zh, string> = {
359
+ 'badge.normal': 'Normal',
360
+ 'badge.paused': 'Pausada (pico)',
361
+ 'badge_paused_peak': 'Pausa por pico ativa',
362
+ 'settings.enabled': 'Pausa automática no pico',
363
+ 'settings.enabled.desc': 'Pausar automaticamente as sessões ativas durante as horas de pico',
364
+ 'settings.offPeakAutoResume': 'Retomada automática fora do pico',
365
+ 'settings.offPeakAutoResume.desc': 'Retomar automaticamente as sessões pausadas durante as horas de vale',
366
+ 'settings.weekendMode': 'Modo fim de semana',
367
+ 'settings.weekendMode.desc': 'Detectar fins de semana → sem pausa automática no fim de semana',
368
+ 'settings.queueFallback': 'Fila de espera com lock como reserva',
369
+ 'settings.queueFallback.desc': 'Recorrer à fila de espera com lock quando a porta de sessão própria não estiver disponível (fail-open)',
370
+ 'settings.retryEnabled': 'Nova tentativa automática',
371
+ 'settings.retryEnabled.desc': 'Retomar automaticamente após falhas transitórias (desativado por padrão, conservador)',
372
+ 'settings.timezone': 'Fuso horário',
373
+ 'settings.peakWindows': 'Janelas de horário de pico',
374
+ 'settings.providerGuard': 'Veredito bidimensional de fonte oficial',
375
+ 'settings.providerGuard.desc': 'No pico, bloquear somente as fontes oficiais do DeepSeek; provedores locais/de terceiros continuam rodando',
376
+ 'settings.officialProviders': 'IDs de provedor oficiais adicionais',
377
+ 'settings.officialProviders.desc': 'Correspondência exata, prioridade máxima (separados por vírgula)',
378
+ 'settings.officialBaseURLs': 'Hosts de endpoints oficiais',
379
+ 'settings.officialBaseURLs.desc': 'Hosts após a normalização da baseURL (separados por vírgula)',
380
+ 'settings.deferredMode': 'Modo de interceptação',
381
+ 'settings.deferredMode.desc': 'Reter sem erro; ou gerar erro e enfileirar como adiado',
382
+ 'settings.deferredResume': 'Continuação automática após o pico',
383
+ 'settings.deferredResume.desc': 'Desativado, requisições/sessões adiadas não retomam sozinhas; exigem /resume manual',
384
+ 'settings.deferredResumeText': 'Mensagem de retomada',
385
+ 'settings.deferredResumeText.desc': 'Conteúdo da mensagem enviada na retomada pós-pico no modo error',
386
+ 'settings.guardSubagents': 'Incluir requisições de subagentes',
387
+ 'settings.guardSubagents.desc': 'Requisições de subagentes também são cobradas; interceptadas por padrão',
388
+ 'settings.officialHint': 'Cadeia do veredito: lista explícita de ids → endpoint da baseURL → endpoint padrão do catálogo → id embutido. Para investigar um veredito equivocado, abra /session-guard/provider?provider=<id> e veja matchedBy.',
389
+ 'settings.unavailable': 'Configurações indisponíveis: confirme que o dsh-session-guard foi montado neste profile.',
390
+ 'status.normal': 'Operação normal',
391
+ 'status.paused_peak': 'Pausa por pico ativa',
392
+ 'status.peak_official': 'Pico · só oficiais',
393
+ 'status.peak_all': 'Pico · todas pausadas',
394
+ }
395
+
357
396
  /** Dictionary key union. */
358
397
  export type SessionGuardKey = keyof typeof zh
359
398
 
360
- /** Combined dictionary map — all 9 languages, for one-call registration. */
361
- export const dictionaries: Record<string, Record<string, string>> = { zh, en, ja, ko, fr, de, it, ru, es }
399
+ /** Combined dictionary map — all 10 languages, for one-call registration. */
400
+ export const dictionaries: Record<string, Record<string, string>> = { zh, en, ja, ko, fr, de, it, ru, es, pt }
package/src/holidays.js CHANGED
@@ -1,159 +1,215 @@
1
- /**
2
- * dsh-session-guard — 法定节假日 / 调休修正表(纯逻辑,零 IO,可单测)。
3
- *
4
- * 数据源:holiday-cn(NateScarlet/holiday-cn,每日自动解析国务院公告),
5
- * 全年 JSON:`{ year, papers: [...], days: [{ name, date, isOffDay }] }`。
6
- * `isOffDay: true` = 放假(含落在周末的假日);`false` = 调休补班日
7
- * (本来是周六日但要上班)。表外日期回退自然周末判定。
8
- *
9
- * 内置快照只覆盖已定稿年份(2026,39 条 = 33 放假日 + 6 调休补班日);
10
- * 未覆盖年份由 holiday-store.js 按年自动抓取,抓不到即退化为纯自然周末
11
- * (fail-open,与插件一贯风格一致)。
12
- */
13
- import { createHash } from 'node:crypto'
14
-
15
- /** 'YYYY-MM-DD' 严格形态(月/日补零),也是 Map 键与指纹序列化的唯一形态。 */
16
- const DATE_RE = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
17
-
18
- /**
19
- * 2026 年国务院放假安排(公告 content_7047091,经 holiday-cn 机读)。
20
- * 只保留判定需要的 date / isOffDay 两键;name 仅注释性内嵌于分组注释。
21
- */
22
- export const BUILTIN_2026 = Object.freeze({
23
- year: 2026,
24
- paper: 'https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm',
25
- days: Object.freeze([
26
- // 元旦:1/1(四)-1/3(六) 放假,1/4(日) 补班
27
- { date: '2026-01-01', isOffDay: true },
28
- { date: '2026-01-02', isOffDay: true },
29
- { date: '2026-01-03', isOffDay: true },
30
- { date: '2026-01-04', isOffDay: false },
31
- // 春节:2/15-2/23 放假,2/14(六)、2/28(六) 补班
32
- { date: '2026-02-14', isOffDay: false },
33
- { date: '2026-02-15', isOffDay: true },
34
- { date: '2026-02-16', isOffDay: true },
35
- { date: '2026-02-17', isOffDay: true },
36
- { date: '2026-02-18', isOffDay: true },
37
- { date: '2026-02-19', isOffDay: true },
38
- { date: '2026-02-20', isOffDay: true },
39
- { date: '2026-02-21', isOffDay: true },
40
- { date: '2026-02-22', isOffDay: true },
41
- { date: '2026-02-23', isOffDay: true },
42
- { date: '2026-02-28', isOffDay: false },
43
- // 清明:4/4-4/6 放假,无补班
44
- { date: '2026-04-04', isOffDay: true },
45
- { date: '2026-04-05', isOffDay: true },
46
- { date: '2026-04-06', isOffDay: true },
47
- // 劳动节:5/1-5/5 放假,5/9(六) 补班
48
- { date: '2026-05-01', isOffDay: true },
49
- { date: '2026-05-02', isOffDay: true },
50
- { date: '2026-05-03', isOffDay: true },
51
- { date: '2026-05-04', isOffDay: true },
52
- { date: '2026-05-05', isOffDay: true },
53
- { date: '2026-05-09', isOffDay: false },
54
- // 端午:6/19-6/21 放假,无补班
55
- { date: '2026-06-19', isOffDay: true },
56
- { date: '2026-06-20', isOffDay: true },
57
- { date: '2026-06-21', isOffDay: true },
58
- // 中秋:9/25-9/27 放假,9/20(日) 补班
59
- { date: '2026-09-20', isOffDay: false },
60
- { date: '2026-09-25', isOffDay: true },
61
- { date: '2026-09-26', isOffDay: true },
62
- { date: '2026-09-27', isOffDay: true },
63
- // 国庆:10/1-10/7 放假,10/10(六) 补班
64
- { date: '2026-10-01', isOffDay: true },
65
- { date: '2026-10-02', isOffDay: true },
66
- { date: '2026-10-03', isOffDay: true },
67
- { date: '2026-10-04', isOffDay: true },
68
- { date: '2026-10-05', isOffDay: true },
69
- { date: '2026-10-06', isOffDay: true },
70
- { date: '2026-10-07', isOffDay: true },
71
- { date: '2026-10-10', isOffDay: false },
72
- ]),
73
- })
74
-
75
- /** 内置快照数组(新定稿年份在此追加)。 */
76
- export const BUILTIN_TABLES = Object.freeze([BUILTIN_2026])
77
-
78
- /**
79
- * 校验并归一化 holiday-cn `days` 数组。
80
- * 逐条要求 `date` 为补零 'YYYY-MM-DD' 且 `isOffDay` 为布尔;
81
- * 排序去重(同日重复以末条为准,与上游「后公告覆盖前公告」一致)。
82
- * @param {unknown} raw days 原始数组
83
- * @returns {{date:string, isOffDay:boolean}[]} 归一化条目(新数组)
84
- * @throws {Error} 非数组 / 空条目 / 形态非法
85
- */
86
- export function normalizeDays(raw) {
87
- if (!Array.isArray(raw)) throw new Error('holiday days: not an array')
88
- const byDate = new Map()
89
- for (const item of raw) {
90
- const date = item && typeof item === 'object' ? item.date : undefined
91
- if (typeof date !== 'string' || !DATE_RE.test(date)) {
92
- throw new Error(`holiday days: bad date ${JSON.stringify(date)}`)
93
- }
94
- if (typeof item.isOffDay !== 'boolean') {
95
- throw new Error(`holiday days: bad isOffDay for ${date}`)
96
- }
97
- byDate.set(date, { date, isOffDay: item.isOffDay })
98
- }
99
- return [...byDate.values()].sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0))
100
- }
101
-
102
- /**
103
- * 解析 holiday-cn 全年 JSON(远端响应 / 缓存文件通吃)。
104
- * @param {unknown} json 已 parse 的对象
105
- * @returns {{year:number, days:{date:string, isOffDay:boolean}[]}}
106
- * @throws {Error} 形态不合 schema(year 与条目日期必须一致)
107
- */
108
- export function parseHolidayCn(json) {
109
- if (json === null || typeof json !== 'object') throw new Error('holiday json: not an object')
110
- const year = Number(json.year)
111
- if (!Number.isInteger(year) || year < 2000 || year > 2100) throw new Error('holiday json: bad year')
112
- const days = normalizeDays(json.days)
113
- for (const d of days) {
114
- if (Number(d.date.slice(0, 4)) !== year) throw new Error(`holiday json: day ${d.date} outside ${year}`)
115
- }
116
- return { year, days }
117
- }
118
-
119
- /**
120
- * 修正表指纹:对归一化(排序去重)后的 `date=isOffDay` 序列做 sha256。
121
- * 只哈希判定语义相关字段——name / papers / 抓取时间不参与,
122
- * 上游改文案不会引起伪变化。
123
- * @param {{date:string, isOffDay:boolean}[]} days normalizeDays / parseHolidayCn 产物
124
- * @returns {string} 'sha256:<hex>'
125
- */
126
- export function fingerprint(days) {
127
- const canon = days.map((d) => `${d.date}=${d.isOffDay ? 1 : 0}`).join(';')
128
- return `sha256:${createHash('sha256').update(canon).digest('hex')}`
129
- }
130
-
131
- /**
132
- * 归一化 days → 查表 Map:'YYYY-MM-DD' → 是否放假日。
133
- * @param {{date:string, isOffDay:boolean}[]} days
134
- * @returns {Map<string, boolean>}
135
- */
136
- export function buildMap(days) {
137
- const m = new Map()
138
- for (const d of days) m.set(d.date, d.isOffDay)
139
- return m
140
- }
141
-
142
- /** wallClock 分量 → 补零 'YYYY-MM-DD'。 */
143
- export function ymdOf(wc) {
144
- return `${wc.year}-${String(wc.month).padStart(2, '0')}-${String(wc.day).padStart(2, '0')}`
145
- }
146
-
147
- /**
148
- * 修正表感知的「当天是否休息日」:
149
- * - 表内条目:`isOffDay` 直接定乾坤(true 放假 / false 调休补班——周末也算上班);
150
- * - 表外 / 无表(map 为 null 或空):回退自然周末(0=周日、6=周六)。
151
- * @param {Map<string, boolean>|null|undefined} map buildMap 产物
152
- * @param {string} ymd 补零日期串
153
- * @param {number} weekday 该日期在用户时区的星期(0-6,同 wallClock 约定)
154
- * @returns {boolean}
155
- */
156
- export function isRestDay(map, ymd, weekday) {
157
- if (map instanceof Map && map.has(ymd)) return map.get(ymd) === true
158
- return weekday === 0 || weekday === 6
159
- }
1
+ /**
2
+ * dsh-session-guard — 法定节假日 / 调休修正表(纯逻辑,零 IO,可单测)。
3
+ *
4
+ * 数据源:holiday-cn(NateScarlet/holiday-cn,每日自动解析国务院公告),
5
+ * 全年 JSON:`{ year, papers: [...], days: [{ name, date, isOffDay }] }`。
6
+ * `isOffDay: true` = 放假(含落在周末的假日);`false` = 调休补班日
7
+ * (本来是周六日但要上班)。表外日期回退自然周末判定。
8
+ *
9
+ * 内置快照只覆盖已定稿年份(2026:39 条 = 33 放假日 + 6 调休补班日;
10
+ * 2027:34 条 = 29 放假日 + 5 调休补班日);未覆盖年份由 holiday-store.js
11
+ * 按年自动抓取,抓不到即退化为纯自然周末(fail-open,与插件一贯风格一致)。
12
+ *
13
+ * 内置表让离线部署也有正确的放假/补班判定;联网时仍以远端指纹为准,
14
+ * 上游若有修订会在 24h 预算内覆盖内置表。
15
+ */
16
+ import { createHash } from 'node:crypto'
17
+
18
+ /** 'YYYY-MM-DD' 严格形态(月/日补零),也是 Map 键与指纹序列化的唯一形态。 */
19
+ const DATE_RE = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
20
+
21
+ /**
22
+ * 2026 年国务院放假安排(公告 content_7047091,经 holiday-cn 机读)。
23
+ * 只保留判定需要的 date / isOffDay 两键;name 仅注释性内嵌于分组注释。
24
+ */
25
+ export const BUILTIN_2026 = Object.freeze({
26
+ year: 2026,
27
+ paper: 'https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm',
28
+ days: Object.freeze([
29
+ // 元旦:1/1(四)-1/3(六) 放假,1/4(日) 补班
30
+ { date: '2026-01-01', isOffDay: true },
31
+ { date: '2026-01-02', isOffDay: true },
32
+ { date: '2026-01-03', isOffDay: true },
33
+ { date: '2026-01-04', isOffDay: false },
34
+ // 春节:2/15-2/23 放假,2/14(六)、2/28(六) 补班
35
+ { date: '2026-02-14', isOffDay: false },
36
+ { date: '2026-02-15', isOffDay: true },
37
+ { date: '2026-02-16', isOffDay: true },
38
+ { date: '2026-02-17', isOffDay: true },
39
+ { date: '2026-02-18', isOffDay: true },
40
+ { date: '2026-02-19', isOffDay: true },
41
+ { date: '2026-02-20', isOffDay: true },
42
+ { date: '2026-02-21', isOffDay: true },
43
+ { date: '2026-02-22', isOffDay: true },
44
+ { date: '2026-02-23', isOffDay: true },
45
+ { date: '2026-02-28', isOffDay: false },
46
+ // 清明:4/4-4/6 放假,无补班
47
+ { date: '2026-04-04', isOffDay: true },
48
+ { date: '2026-04-05', isOffDay: true },
49
+ { date: '2026-04-06', isOffDay: true },
50
+ // 劳动节:5/1-5/5 放假,5/9(六) 补班
51
+ { date: '2026-05-01', isOffDay: true },
52
+ { date: '2026-05-02', isOffDay: true },
53
+ { date: '2026-05-03', isOffDay: true },
54
+ { date: '2026-05-04', isOffDay: true },
55
+ { date: '2026-05-05', isOffDay: true },
56
+ { date: '2026-05-09', isOffDay: false },
57
+ // 端午:6/19-6/21 放假,无补班
58
+ { date: '2026-06-19', isOffDay: true },
59
+ { date: '2026-06-20', isOffDay: true },
60
+ { date: '2026-06-21', isOffDay: true },
61
+ // 中秋:9/25-9/27 放假,9/20(日) 补班
62
+ { date: '2026-09-20', isOffDay: false },
63
+ { date: '2026-09-25', isOffDay: true },
64
+ { date: '2026-09-26', isOffDay: true },
65
+ { date: '2026-09-27', isOffDay: true },
66
+ // 国庆:10/1-10/7 放假,10/10(六) 补班
67
+ { date: '2026-10-01', isOffDay: true },
68
+ { date: '2026-10-02', isOffDay: true },
69
+ { date: '2026-10-03', isOffDay: true },
70
+ { date: '2026-10-04', isOffDay: true },
71
+ { date: '2026-10-05', isOffDay: true },
72
+ { date: '2026-10-06', isOffDay: true },
73
+ { date: '2026-10-07', isOffDay: true },
74
+ { date: '2026-10-10', isOffDay: false },
75
+ ]),
76
+ })
77
+
78
+ /**
79
+ * 2027 年国务院放假安排(公告 content_7085102,经 holiday-cn 机读;
80
+ * 快照指纹 sha256:8f999d47…9780331af,取表时点 2026-11)。
81
+ * 同样只保留 date / isOffDay。
82
+ */
83
+ export const BUILTIN_2027 = Object.freeze({
84
+ year: 2027,
85
+ paper: 'https://www.gov.cn/zhengce/zhengceku/202611/content_7085102.htm',
86
+ days: Object.freeze([
87
+ // 元旦:1/1(五)-1/3(日) 放假,无补班
88
+ { date: '2027-01-01', isOffDay: true },
89
+ { date: '2027-01-02', isOffDay: true },
90
+ { date: '2027-01-03', isOffDay: true },
91
+ // 春节:2/5(五)-2/13(六) 放假,1/31(日)、2/14(日) 补班
92
+ { date: '2027-01-31', isOffDay: false },
93
+ { date: '2027-02-05', isOffDay: true },
94
+ { date: '2027-02-06', isOffDay: true },
95
+ { date: '2027-02-07', isOffDay: true },
96
+ { date: '2027-02-08', isOffDay: true },
97
+ { date: '2027-02-09', isOffDay: true },
98
+ { date: '2027-02-10', isOffDay: true },
99
+ { date: '2027-02-11', isOffDay: true },
100
+ { date: '2027-02-12', isOffDay: true },
101
+ { date: '2027-02-13', isOffDay: true },
102
+ { date: '2027-02-14', isOffDay: false },
103
+ // 清明:4/3(六)-4/5(一) 放假,无补班
104
+ { date: '2027-04-03', isOffDay: true },
105
+ { date: '2027-04-04', isOffDay: true },
106
+ { date: '2027-04-05', isOffDay: true },
107
+ // 劳动节:5/1(六)-5/5(三) 放假,5/8(六) 补班
108
+ { date: '2027-05-01', isOffDay: true },
109
+ { date: '2027-05-02', isOffDay: true },
110
+ { date: '2027-05-03', isOffDay: true },
111
+ { date: '2027-05-04', isOffDay: true },
112
+ { date: '2027-05-05', isOffDay: true },
113
+ { date: '2027-05-08', isOffDay: false },
114
+ // 端午:6/9(三) 放假一天,无补班
115
+ { date: '2027-06-09', isOffDay: true },
116
+ // 中秋:9/15(三) 放假一天,无补班
117
+ { date: '2027-09-15', isOffDay: true },
118
+ // 国庆:10/1(五)-10/7(四) 放假,9/26(日)、10/9(六) 补班
119
+ { date: '2027-09-26', isOffDay: false },
120
+ { date: '2027-10-01', isOffDay: true },
121
+ { date: '2027-10-02', isOffDay: true },
122
+ { date: '2027-10-03', isOffDay: true },
123
+ { date: '2027-10-04', isOffDay: true },
124
+ { date: '2027-10-05', isOffDay: true },
125
+ { date: '2027-10-06', isOffDay: true },
126
+ { date: '2027-10-07', isOffDay: true },
127
+ { date: '2027-10-09', isOffDay: false },
128
+ ]),
129
+ })
130
+
131
+ /** 内置快照数组(新定稿年份在此追加)。 */
132
+ export const BUILTIN_TABLES = Object.freeze([BUILTIN_2026, BUILTIN_2027])
133
+
134
+ /**
135
+ * 校验并归一化 holiday-cn `days` 数组。
136
+ * 逐条要求 `date` 为补零 'YYYY-MM-DD' 且 `isOffDay` 为布尔;
137
+ * 排序去重(同日重复以末条为准,与上游「后公告覆盖前公告」一致)。
138
+ * @param {unknown} raw days 原始数组
139
+ * @returns {{date:string, isOffDay:boolean}[]} 归一化条目(新数组)
140
+ * @throws {Error} 非数组 / 空条目 / 形态非法
141
+ */
142
+ export function normalizeDays(raw) {
143
+ if (!Array.isArray(raw)) throw new Error('holiday days: not an array')
144
+ const byDate = new Map()
145
+ for (const item of raw) {
146
+ const date = item && typeof item === 'object' ? item.date : undefined
147
+ if (typeof date !== 'string' || !DATE_RE.test(date)) {
148
+ throw new Error(`holiday days: bad date ${JSON.stringify(date)}`)
149
+ }
150
+ if (typeof item.isOffDay !== 'boolean') {
151
+ throw new Error(`holiday days: bad isOffDay for ${date}`)
152
+ }
153
+ byDate.set(date, { date, isOffDay: item.isOffDay })
154
+ }
155
+ return [...byDate.values()].sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0))
156
+ }
157
+
158
+ /**
159
+ * 解析 holiday-cn 全年 JSON(远端响应 / 缓存文件通吃)。
160
+ * @param {unknown} json 已 parse 的对象
161
+ * @returns {{year:number, days:{date:string, isOffDay:boolean}[]}}
162
+ * @throws {Error} 形态不合 schema(year 与条目日期必须一致)
163
+ */
164
+ export function parseHolidayCn(json) {
165
+ if (json === null || typeof json !== 'object') throw new Error('holiday json: not an object')
166
+ const year = Number(json.year)
167
+ if (!Number.isInteger(year) || year < 2000 || year > 2100) throw new Error('holiday json: bad year')
168
+ const days = normalizeDays(json.days)
169
+ for (const d of days) {
170
+ if (Number(d.date.slice(0, 4)) !== year) throw new Error(`holiday json: day ${d.date} outside ${year}`)
171
+ }
172
+ return { year, days }
173
+ }
174
+
175
+ /**
176
+ * 修正表指纹:对归一化(排序去重)后的 `date=isOffDay` 序列做 sha256。
177
+ * 只哈希判定语义相关字段——name / papers / 抓取时间不参与,
178
+ * 上游改文案不会引起伪变化。
179
+ * @param {{date:string, isOffDay:boolean}[]} days normalizeDays / parseHolidayCn 产物
180
+ * @returns {string} 'sha256:<hex>'
181
+ */
182
+ export function fingerprint(days) {
183
+ const canon = days.map((d) => `${d.date}=${d.isOffDay ? 1 : 0}`).join(';')
184
+ return `sha256:${createHash('sha256').update(canon).digest('hex')}`
185
+ }
186
+
187
+ /**
188
+ * 归一化 days → 查表 Map:'YYYY-MM-DD' → 是否放假日。
189
+ * @param {{date:string, isOffDay:boolean}[]} days
190
+ * @returns {Map<string, boolean>}
191
+ */
192
+ export function buildMap(days) {
193
+ const m = new Map()
194
+ for (const d of days) m.set(d.date, d.isOffDay)
195
+ return m
196
+ }
197
+
198
+ /** wallClock 分量 → 补零 'YYYY-MM-DD'。 */
199
+ export function ymdOf(wc) {
200
+ return `${wc.year}-${String(wc.month).padStart(2, '0')}-${String(wc.day).padStart(2, '0')}`
201
+ }
202
+
203
+ /**
204
+ * 修正表感知的「当天是否休息日」:
205
+ * - 表内条目:`isOffDay` 直接定乾坤(true 放假 / false 调休补班——周末也算上班);
206
+ * - 表外 / 无表(map 为 null 或空):回退自然周末(0=周日、6=周六)。
207
+ * @param {Map<string, boolean>|null|undefined} map buildMap 产物
208
+ * @param {string} ymd 补零日期串
209
+ * @param {number} weekday 该日期在用户时区的星期(0-6,同 wallClock 约定)
210
+ * @returns {boolean}
211
+ */
212
+ export function isRestDay(map, ymd, weekday) {
213
+ if (map instanceof Map && map.has(ymd)) return map.get(ymd) === true
214
+ return weekday === 0 || weekday === 6
215
+ }