dsh-ai-subtitle 0.2.0 → 0.3.1

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/docs/DETAIL.md CHANGED
@@ -31,5 +31,5 @@ Agent 工具:
31
31
 
32
32
  - 仅支持 Windows;
33
33
  - 每条碎片只有起止时间(段级),没有逐词时间戳;
34
- - 不提供自动翻译与术语表:中文由会话中的模型校对后写回 `cues.json`;
34
+ - 翻译由插件调用 DSH 已配置的模型完成,凭证由 DSH 管理,插件不保存密钥;
35
35
  - 首次安装约 3 GB,需要稳定网络。
package/docs/PLAN.md CHANGED
@@ -28,13 +28,13 @@
28
28
  - [x] 行宽与时长上限:超长且中日句子数一致时按句子再切
29
29
  - [x] 双语 SRT 导出(BOM、CRLF),导出前校验
30
30
  - [x] 界面上合并 / 拆分 / 起止 ±0.1 秒 / 恢复自动时间
31
- - [ ] 把“LLM 校对”变成插件内置动作(目前依赖会话里的 agent)
31
+ - [x] 把“LLM 校对”变成插件内置动作(`subtitle_review translate` 与面板按钮)
32
32
  - [ ] 开场音乐等幻觉碎片的自动过滤
33
33
 
34
34
  ## P3 术语表与翻译
35
35
 
36
- - [ ] `glossary.yaml`:人名、作品名、固定译法;日文侧纠错 + 中文侧强制
37
- - [ ] 翻译走会话已有的模型(不额外存 key),带术语表与长度约束
36
+ - [x] 术语表:人名、作品名、固定译法;日文侧纠错 + 中文侧强制(`glossary.json`)
37
+ - [x] 翻译走 DSH 已有的模型(不额外存 key),带术语表、背景标签与长度约束
38
38
  - [ ] 命中报告:未命中 / 低置信度条目交给人确认
39
39
 
40
40
  ## P4 界面(已完成)
package/docs/REVIEW.md ADDED
@@ -0,0 +1,105 @@
1
+ # 校对工作流
2
+
3
+ `subtitle_review` 把“转写”和“成片中文字幕”之间的那一步固定下来:**插件切块,插件调用 DSH 已配置的模型,插件校验并合并**。模型凭证由 DSH 管理,插件不保存任何密钥。
4
+
5
+ ## 一次性准备
6
+
7
+ `asr.json` 由转写产生,`cues.json` 可以不存在。术语表放在项目目录下:
8
+
9
+ ```json
10
+ {
11
+ "version": 1,
12
+ "strict": false,
13
+ "terms": [
14
+ { "jp": "本多真梨子", "zh": "本多真梨子", "kind": "name" },
15
+ { "jp": "マスター", "zh": "老板", "kind": "term" }
16
+ ],
17
+ "corrections": [
18
+ { "from": "本田", "to": "本多", "reason": "ASR 误听" }
19
+ ]
20
+ }
21
+ ```
22
+
23
+ - `terms`:日文出现该词时,中文必须包含指定译法;
24
+ - `corrections`:导入时自动替换日文,避免误听写进字幕;
25
+ - `strict`:为 `true` 时,术语未命中直接拒绝该批次。
26
+
27
+ ## 术语表的导入导出
28
+
29
+ 术语表可以在表格软件里维护,插件只负责读写:
30
+
31
+ ```sh
32
+ subtitle_glossary { project: "…", action: "export" } # 写到 <project>/glossary.csv
33
+ subtitle_glossary { project: "…", action: "import", path: "D:\\glossary.csv" }
34
+ subtitle_glossary { project: "…", action: "import", from: "https://example.com/glossary.csv" }
35
+ ```
36
+
37
+ CSV 只有四列,第一行是表头:
38
+
39
+ ```csv
40
+ type,jp,zh,note
41
+ term,マスター,老板,称呼
42
+ correction,本田,本多,ASR 误听
43
+ ```
44
+
45
+ - `type` 为 `term` 时约束中文译法,为 `correction` 时替换日文;
46
+ - 导出带 UTF-8 BOM,Excel 直接双击不会乱码;
47
+ - 导入默认**合并**(同 `jp` 覆盖、其余保留),`merge: false` 则整体替换;
48
+ - `from` 支持 http(s) 链接,适合把表格发布成 CSV 后直接同步(上限 1 MB、超时 15 秒);
49
+ - 导入会返回新增/更新条数与跳过的行号,不会静默丢弃。
50
+
51
+ ## 工作流
52
+
53
+ 面板里的「校对」区块默认走**自动翻译**,不需要手工复制:
54
+
55
+ 1. **选模型**:下拉框列出 DSH 已配置的 provider 与模型,默认选账号登录的那一条;选择会记在项目的 `translate.json`。
56
+ 2. **自动翻译本批**:把当前批次发给模型,带上背景标签、术语表与已有意见,结果直接写回 `cues.json`。
57
+ 3. **自动翻译全部剩余**:后台任务(有进度、可取消),每完成一批就落盘。
58
+ 4. **校对日文**(可选):勾选「同时校正日文识别」,提示词会要求先修正同音字、漏字、重复与断句,再把校正后的日文写回,结果里报告改动了多少条。
59
+ 5. **看结果提意见**:批次里每条 cue 下有意见输入框,也可以写整批意见;点「保存意见并重译本批」,意见会随下一次翻译一起交给模型。
60
+ 6. **导出字幕**:全部批次完成后,由项目行或弹窗里的按钮导出。
61
+
62
+ Agent 侧对应 `subtitle_review` 的 `translate`(单批或 `all: true` 后台)与 `feedback`(写意见)两个动作。
63
+
64
+ 手动兜底:折叠项「手动:复制批次 / 粘贴模型结果」保留,模型不可用或想用外部工具时仍可走这条路。
65
+
66
+ ## 背景与标签
67
+
68
+ 项目目录下的 `hints.json` 保存翻译方向:
69
+
70
+ ```json
71
+ { "tags": ["声优节目", "广播"], "note": "称呼口语化,第三人称用「她」" }
72
+ ```
73
+
74
+ - 面板里通过「背景与术语」编辑,最多 20 个标签;
75
+ - 每次翻译都会把标签与说明放进提示词,适合写人名、作品名、节目风格;
76
+ - 遇到固定误听,写进 `corrections` 比依赖模型更稳。
77
+
78
+ ## 逐条删除
79
+
80
+ 编辑器里每条 cue 都有「删除」:它把这条标记为跳过段(`skip`),而不是真的从覆盖范围里拿掉。
81
+
82
+ - 好处是覆盖率仍然连续,导出校验不会因此失败;
83
+ - 被删除的条目不会出现在 SRT 里,标题会显示「已删除(不显示)」;
84
+ - 点「恢复」还原。
85
+
86
+ ## 导出命名
87
+
88
+ 导出的字幕与视频同名(`视频名.srt`),放在项目目录下;项目没有记录视频时退回用项目目录名。
89
+ 旧的 `subtitles.srt` 不会再被写入,可以手动删除。
90
+
91
+ ## 约定
92
+
93
+ - 行格式固定为 `from-to|jp|zh`;`zh` 可省略表示待翻译;`#` 开头的行是注释;
94
+ - 批次 id 是碎片区间(`61-120`),不会因编辑 cue 而变化;
95
+ - **纯音乐或音效片段**有两种处理:`allowEmpty: true` 生成一条中文为空的字幕,或者
96
+ 用 `from-to|<skip>` 标记整段跳过——跳过仍计入覆盖率,但不会出现在 SRT 里;
97
+ - 已有 `skip` 标记的区间在 `next` 里原样显示为 `<skip>`,不需要反复处理;
98
+ - 术语表缺省时不做任何术语约束,行为与之前一致。
99
+
100
+ ## 失败时
101
+
102
+ - **鉴权失败**(`Authentication Fails`):当前 provider 的 API key 无效,换下拉框里账号登录的那一项,或在 DSH 设置里修好该 provider;
103
+ - **区间不连续**:模型漏行或合并错了行,错误信息会指出哪一行开始偏离;
104
+ - **覆盖率失败**:说明这一批没有覆盖到批次两端,整批被拒绝,`cues.json` 不受影响;
105
+ - **术语 strict 失败**:把缺少的译法补进中文后重试,或把该词从 `terms` 移到 `corrections`。
package/index.js CHANGED
@@ -1,10 +1,33 @@
1
1
  import { defineTool } from '@deepseek-ai/dsh-tools'
2
- import { existsSync, readFileSync } from 'node:fs'
3
- import { join, resolve } from 'node:path'
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
3
+ import { basename, dirname, extname, join, resolve } from 'node:path'
4
4
  import { Runtime } from './src/runtime.js'
5
5
  import { registerApi } from './src/api.js'
6
- import { cancelAll, getJob, listJobs, waitJob, describeJob } from './src/jobs.js'
6
+ import { cancelAll, getJob, listJobs, waitJob, describeJob, startJob } from './src/jobs.js'
7
+ import { rememberMedia } from './src/recent.js'
8
+ import { loadHints } from './src/hints.js'
7
9
  import { buildRows, cueStats, loadCues, validateCues, writeSrt } from './src/cues.js'
10
+ import {
11
+ applyBatch,
12
+ formatApply,
13
+ formatReport,
14
+ formatStatus,
15
+ nextBatch,
16
+ planBatches,
17
+ renderBatch,
18
+ reviewReport,
19
+ reviewStatus,
20
+ loadProject,
21
+ } from './src/review.js'
22
+ import {
23
+ fetchGlossaryText,
24
+ fromCsv,
25
+ glossaryPath,
26
+ loadGlossary,
27
+ mergeGlossary,
28
+ saveGlossary,
29
+ toCsv,
30
+ } from './src/glossary.js'
8
31
 
9
32
  export const name = 'dsh-ai-subtitle'
10
33
  export const inject = ['tools']
@@ -27,10 +50,26 @@ export function apply(ctx, config = {}) {
27
50
  ctx.effect(() => () => cancelAll('插件已卸载,任务取消'))
28
51
  }
29
52
 
53
+ // The panel and the tools call the session's model through ctx.llm; a scoped
54
+ // context is the only way to reach it, so keep it for both entry points.
55
+ let llmCtx = null
56
+ ctx.inject(['llm'], (scoped) => {
57
+ scoped.effect(() => {
58
+ llmCtx = scoped
59
+ return () => {
60
+ llmCtx = null
61
+ }
62
+ })
63
+ })
64
+ const modelContext = () => {
65
+ if (!llmCtx) throw new Error('模型服务不可用:请先在 DSH 设置里配置模型')
66
+ return llmCtx
67
+ }
68
+
30
69
  // The sidebar panel talks to the Host over these local JSON routes. The
31
70
  // plugin still works without a web server (headless profiles just skip it).
32
71
  ctx.inject(['webServer'], (scoped) => {
33
- scoped.effect(() => registerApi(scoped, runtimeFor))
72
+ scoped.effect(() => registerApi(scoped, runtimeFor, modelContext))
34
73
  })
35
74
 
36
75
  ctx.tools.register(defineTool({
@@ -77,6 +116,7 @@ export function apply(ctx, config = {}) {
77
116
  output: { schema: { type: 'string' }, render: (_args, value) => text(value) },
78
117
  async execute(args) {
79
118
  const rt = runtimeFor(args.installDir)
119
+ rememberMedia(rt, resolve(args.media))
80
120
  const job = rt.transcribe({
81
121
  media: args.media,
82
122
  model: args.model,
@@ -124,9 +164,155 @@ export function apply(ctx, config = {}) {
124
164
  const check = validateCues(cues, asr.fragments.length)
125
165
  if (!check.ok) return ['cue coverage failed:', ...check.errors.map((line) => ' - ' + line)].join('\n')
126
166
  const rows = buildRows(asr.fragments, cues, { minDuration: 1.2, maxDuration: 9 })
127
- const outPath = args.out ? resolve(args.out) : join(asrPath, '..', 'subtitles.srt')
167
+ const projectDir = dirname(asrPath)
168
+ let srtName = 'subtitles.srt'
169
+ try {
170
+ const meta = JSON.parse(readFileSync(join(projectDir, 'meta.json'), 'utf8'))
171
+ if (meta && typeof meta.media === 'string' && meta.media) srtName = basename(meta.media, extname(meta.media)) + '.srt'
172
+ } catch {
173
+ // no meta.json: keep the legacy name
174
+ }
175
+ const outPath = args.out ? resolve(args.out) : join(projectDir, srtName)
128
176
  writeSrt(outPath, rows)
129
177
  return JSON.stringify({ out: outPath, ...cueStats(rows) }, null, 1)
130
178
  },
131
179
  }))
180
+
181
+ ctx.tools.register(defineTool({
182
+ name: 'subtitle_review',
183
+ description:
184
+ 'Batch workflow for bilingual cues. "translate" translates a batch (or every remaining batch as a background job) through the DSH model service, using glossary.json and the saved feedback notes; "status"/"next"/"report" inspect progress; "apply" writes manually produced lines back with coverage and glossary validation; "feedback" records notes that steer the next translation.',
185
+ parameters: {
186
+ project: { type: 'string', required: true, description: 'Absolute path of the project directory (contains asr.json and cues.json).' },
187
+ action: { type: 'string', required: true, description: 'One of "status", "next", "apply", "report", "translate", "feedback".' },
188
+ batch: { type: 'string', description: 'Batch id such as "61-120". Required for apply; optional for next to re-open a specific batch.' },
189
+ lines: { type: 'string', description: 'For apply: the returned lines, one per cue, formatted "from-to|jp|zh".' },
190
+ glossary: { type: 'string', description: 'Path to glossary.json; defaults to <project>/glossary.json.' },
191
+ allowEmpty: { type: 'boolean', description: 'Accept empty Chinese text, for music or sound effects.' },
192
+ all: { type: 'boolean', description: 'For translate: translate every remaining batch as a background job.' },
193
+ note: { type: 'string', description: 'For feedback: the note to attach to a batch or one cue.' },
194
+ range: { type: 'string', description: 'For feedback: a cue range such as "12-12"; omit for a batch-wide note.' },
195
+ provider: { type: 'string', description: 'Model provider route; defaults to the first configured one.' },
196
+ model: { type: 'string', description: 'Model id; defaults to the first model the provider lists.' },
197
+ proofread: { type: 'boolean', description: 'For translate: also correct Japanese ASR errors before translating.' },
198
+ },
199
+ output: { schema: { type: 'string' }, render: (_args, value) => text(value) },
200
+ async execute(args) {
201
+ const project = resolve(args.project)
202
+ if (!existsSync(project)) throw new Error(`project directory not found: ${project}`)
203
+ const options = { batch: args.batch, glossary: args.glossary, allowEmpty: Boolean(args.allowEmpty) }
204
+
205
+ if (args.action === 'status') return formatStatus(reviewStatus(project, options))
206
+ if (args.action === 'report') return formatReport(reviewReport(project, options))
207
+ if (args.action === 'next') {
208
+ const { cues, fragments } = loadProject(project)
209
+ const batches = planBatches(fragments, cues, options)
210
+ const batch = args.batch ? batches.find((item) => item.id === args.batch) : nextBatch(batches, cues)
211
+ if (!batch) return '(none) every batch is already translated'
212
+ const glossary = loadGlossary(args.glossary || glossaryPath(project))
213
+ return renderBatch(batch, fragments, cues, glossary, loadHints(project))
214
+ }
215
+ if (args.action === 'apply') {
216
+ if (!args.batch) throw new Error('apply needs a batch id, for example "61-120"')
217
+ if (!args.lines) throw new Error('apply needs the returned lines')
218
+ return formatApply(applyBatch(project, options))
219
+ }
220
+ if (args.action === 'translate') {
221
+ const routeOptions = { provider: args.provider, model: args.model }
222
+ if (args.all) {
223
+ const before = reviewStatus(project)
224
+ const job = startJob('translate', `翻译 ${args.project}`, async (current) => {
225
+ const result = await translateRemaining(modelContext(), project, {
226
+ ...routeOptions,
227
+ mode: args.proofread ? 'proofread' : 'translate',
228
+ signal: current.signal,
229
+ onProgress: (count, batch) => current.report(before.remaining ? (count / before.remaining) * 100 : 50, 'translate', `批次 ${batch}`),
230
+ })
231
+ return { batches: result.batches, route: result.route, remaining: reviewStatus(project).remaining }
232
+ }, { projectDir: project })
233
+ return `translate job started: ${job.id}\nremaining batches: ${before.remaining}\nPoll with subtitle_job { id: "${job.id}", waitSeconds: 60 }.`
234
+ }
235
+ const result = await translateBatch(modelContext(), project, { ...routeOptions, batch: args.batch, mode: args.proofread ? 'proofread' : 'translate' })
236
+ if (result.done) return result.message
237
+ return formatApply(result) + `\nmodel: ${result.route}`
238
+ }
239
+ if (args.action === 'feedback') {
240
+ if (args.note) {
241
+ if (!args.batch) throw new Error('feedback needs a batch id')
242
+ const entry = saveFeedback(project, { batch: args.batch, range: args.range, note: args.note })
243
+ return `saved feedback for batch ${entry.batch}${entry.range ? ' cue ' + entry.range : ''}: ${entry.note}`
244
+ }
245
+ const { cues, fragments } = loadProject(project)
246
+ const batches = planBatches(fragments, cues)
247
+ const batchId = args.batch || (batches[0] && batches[0].id)
248
+ const notes = batchId ? feedbackForBatch(project, batchId) : []
249
+ const all = loadFeedback(project).items
250
+ const lines = [`feedback items: ${all.length}`]
251
+ for (const item of all) lines.push(` ${item.batch}${item.range ? ' cue ' + item.range : ''}: ${item.note}`)
252
+ if (batchId) lines.push('', `batch ${batchId} notes:`, ...(notes.length ? notes.map((note) => ' ' + note) : [' (none)']))
253
+ return lines.join('\n')
254
+ }
255
+ throw new Error(`unknown action ${args.action}; use status, next, apply or report`)
256
+ },
257
+ }))
258
+
259
+ ctx.tools.register(defineTool({
260
+ name: 'subtitle_glossary',
261
+ description:
262
+ 'Read, export or import the project glossary. "show" lists the current entries, "export" writes a CSV table (type,jp,zh,note) that can be edited in a spreadsheet or an online document, and "import" reads that table back from a file or an http(s) URL and merges it into glossary.json.',
263
+ parameters: {
264
+ project: { type: 'string', required: true, description: 'Absolute path of the project directory.' },
265
+ action: { type: 'string', required: true, description: 'One of "show", "export", "import".' },
266
+ path: { type: 'string', description: 'CSV file to write (export) or read (import). Defaults to <project>/glossary.csv.' },
267
+ from: { type: 'string', description: 'For import: an http(s) URL of the published CSV, instead of a local file.' },
268
+ merge: { type: 'boolean', description: 'For import: merge into the current glossary (default) instead of replacing it.' },
269
+ glossary: { type: 'string', description: 'Path to glossary.json; defaults to <project>/glossary.json.' },
270
+ },
271
+ output: { schema: { type: 'string' }, render: (_args, value) => text(value) },
272
+ async execute(args) {
273
+ const project = resolve(args.project)
274
+ if (!existsSync(project)) throw new Error(`project directory not found: ${project}`)
275
+ const glossaryFile = args.glossary || glossaryPath(project)
276
+ const csvFile = args.path ? resolve(args.path) : join(project, 'glossary.csv')
277
+
278
+ if (args.action === 'show') {
279
+ const glossary = loadGlossary(glossaryFile)
280
+ if (!glossary.exists) return `no glossary.json at ${glossaryFile}; export or import a table to create one`
281
+ const lines = [
282
+ `glossary: ${glossaryFile}`,
283
+ `terms: ${glossary.terms.length} · corrections: ${glossary.corrections.length} · strict: ${glossary.strict}`,
284
+ ]
285
+ for (const term of glossary.terms.slice(0, 30)) lines.push(` ${term.jp} → ${term.zh}${term.kind ? ` (${term.kind})` : ''}`)
286
+ for (const rule of glossary.corrections.slice(0, 30)) lines.push(` ${rule.from} ⇒ ${rule.to}${rule.reason ? ` (${rule.reason})` : ''}`)
287
+ if (glossary.errors.length > 0) lines.push('errors: ' + glossary.errors.join('; '))
288
+ return lines.join('\n')
289
+ }
290
+
291
+ if (args.action === 'export') {
292
+ const glossary = loadGlossary(glossaryFile)
293
+ const csv = toCsv(glossary)
294
+ writeFileSync(csvFile, csv, 'utf8')
295
+ const rows = glossary.terms.length + glossary.corrections.length
296
+ return `wrote ${rows} row(s) to ${csvFile} (${glossary.terms.length} terms, ${glossary.corrections.length} corrections)`
297
+ }
298
+
299
+ if (args.action === 'import') {
300
+ const text = args.from
301
+ ? await fetchGlossaryText(args.from)
302
+ : readFileSync(args.path ? resolve(args.path) : csvFile, 'utf8')
303
+ const parsed = fromCsv(text)
304
+ const existing = loadGlossary(glossaryFile)
305
+ const merged = mergeGlossary(existing, parsed, { merge: args.merge !== false })
306
+ saveGlossary(glossaryFile, merged.glossary)
307
+ const lines = [
308
+ `imported ${parsed.terms.length} term(s) and ${parsed.corrections.length} correction(s) from ${args.from || args.path || csvFile}`,
309
+ `added ${merged.summary.added}, updated ${merged.summary.updated}, total ${merged.summary.total} (${merged.summary.merged ? 'merged' : 'replaced'})`,
310
+ ]
311
+ if (parsed.errors.length > 0) lines.push('skipped lines: ' + parsed.errors.slice(0, 10).join('; '))
312
+ return lines.join('\n')
313
+ }
314
+
315
+ throw new Error(`unknown action ${args.action}; use show, export or import`)
316
+ },
317
+ }))
132
318
  }
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Subtitle studio",
4
- "description": "Japanese video to bilingual subtitles: installs its own ffmpeg, Python and Whisper runtime, picks the fastest download source, then transcribes, edits cues and exports SRT.",
4
+ "description": "Japanese video to bilingual subtitles: installs its own ffmpeg, Python and Whisper runtime, translates batches through the configured model with glossary and background hints, then edits cues and exports a video-named SRT.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "字幕工作台",
4
- "description": "日语视频转中日双语字幕:自带 ffmpeg、Python、Whisper 运行时安装器,按速度选择下载源,转写后可断句、编辑时间轴并导出 SRT。",
4
+ "description": "日语视频转中日双语字幕:自带 ffmpeg、Python、Whisper 运行时安装器,按批调用已配置的模型翻译并带上术语表与背景标签,可逐条修改并导出与视频同名的 SRT。",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ai-subtitle",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Japanese video to bilingual JP/zh subtitles inside DeepSeek Harness: a self-installing ffmpeg, Python and Whisper runtime, cue editing and SRT export.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -25,6 +25,7 @@
25
25
  "scripts/client-symbols.json",
26
26
  "locale/*.json",
27
27
  "docs/DETAIL.md",
28
+ "docs/REVIEW.md",
28
29
  "docs/PLAN.md",
29
30
  "icon.svg",
30
31
  "README.md",
@@ -34,7 +35,8 @@
34
35
  "LICENSE"
35
36
  ],
36
37
  "scripts": {
37
- "check": "node scripts/check-client.mjs"
38
+ "check": "node scripts/check-client.mjs",
39
+ "test": "node --test tests/*.test.mjs"
38
40
  },
39
41
  "peerDependencies": {
40
42
  "@deepseek-ai/cordis": "*",
@@ -31,6 +31,23 @@ function declarations(text) {
31
31
  return [...names].sort()
32
32
  }
33
33
 
34
+ // The panel header shows BUILD; a client.js edit that keeps the old tag makes the
35
+ // running version impossible to identify, which already cost one debugging round.
36
+ const buildMatch = source.match(/const BUILD = '([^']+)'/)
37
+ if (buildMatch) {
38
+ const build = buildMatch[1]
39
+ const previous = spawnSync('git', ['show', 'HEAD:client.js'], { encoding: 'utf8' })
40
+ const changed = spawnSync('git', ['diff', '--name-only', 'HEAD', '--', 'client.js'], { encoding: 'utf8' })
41
+ if (previous.status === 0) {
42
+ const oldBuild = (previous.stdout.match(/const BUILD = '([^']+)'/) || [])[1]
43
+ const dirty = (changed.stdout || '').trim().length > 0
44
+ if (dirty && oldBuild === build) {
45
+ console.error(`BUILD must change when client.js changes: still \`${build}\``)
46
+ process.exitCode = 1
47
+ }
48
+ }
49
+ }
50
+
34
51
  const check = spawnSync(process.execPath, ['--check', clientPath], { encoding: 'utf8' })
35
52
  if (check.status !== 0) {
36
53
  console.error('client.js has a syntax error:\n' + (check.stderr || ''))