gatelight 0.19.3 → 0.40.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.
Files changed (62) hide show
  1. package/.antigravity-plugin/plugin.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/README.md +2 -2
  5. package/package.json +1 -1
  6. package/skills/merge/SKILL.md +1 -1
  7. package/skills/modular/SKILL.md +6 -6
  8. package/skills/setup/SKILL.md +2 -2
  9. package/skills/setup-codekeep/SKILL.md +61 -17
  10. package/skills/setup-codekeep/frontend.eslint.mjs +287 -0
  11. package/skills/setup-modwall/SKILL.md +10 -11
  12. package/skills/setup-testcraft/SKILL.md +9 -3
  13. package/skills/setup-testcraft/checklist/dev-login.md +3 -3
  14. package/skills/setup-testcraft/checklist/same-number.md +26 -0
  15. package/skills/write-tests/SKILL.md +12 -12
  16. package/src/base/baseline.ts +2 -2
  17. package/src/base/commands.ts +2 -40
  18. package/src/base/execute.ts +1 -11
  19. package/src/base/exit.ts +1 -1
  20. package/src/base/full.ts +7 -10
  21. package/src/base/git.ts +34 -3
  22. package/src/base/hook.ts +71 -17
  23. package/src/base/hookformat.ts +16 -6
  24. package/src/base/layermap.ts +6 -3
  25. package/src/base/module.ts +8 -8
  26. package/src/base/repo.ts +8 -34
  27. package/src/base/sessions.ts +45 -13
  28. package/src/base/shell.ts +18 -10
  29. package/src/base/stop.ts +20 -6
  30. package/src/base/store.ts +15 -30
  31. package/src/cli.ts +3 -16
  32. package/src/craft/commands.ts +7 -1
  33. package/src/craft/defaults.ts +59 -0
  34. package/src/craft/session.ts +8 -4
  35. package/src/keep/check.ts +107 -40
  36. package/src/keep/config.ts +56 -26
  37. package/src/keep/eslint.ts +144 -6
  38. package/src/keep/loosen.ts +11 -61
  39. package/src/keep/session.ts +19 -5
  40. package/src/keep/styles.ts +72 -0
  41. package/src/pace/commands.ts +9 -3
  42. package/src/pace/full.ts +14 -25
  43. package/src/pace/index.ts +3 -0
  44. package/src/pace/record.ts +12 -6
  45. package/src/pace/results.ts +43 -2
  46. package/src/pace/run/playwright-reporter.mjs +5 -4
  47. package/src/pace/run/runner.ts +13 -7
  48. package/src/pace/run/targets.ts +3 -2
  49. package/src/pace/session.ts +3 -3
  50. package/src/pace/unfinished.ts +87 -0
  51. package/src/pace/unmerged.ts +87 -0
  52. package/src/pace/verify.ts +2 -2
  53. package/src/wall/commands.ts +92 -26
  54. package/src/wall/database.ts +12 -1
  55. package/src/wall/dbcheck.ts +2 -2
  56. package/src/wall/dbrules.ts +60 -19
  57. package/src/wall/literals.ts +162 -0
  58. package/src/wall/migrate.ts +248 -0
  59. package/src/wall/project.ts +29 -9
  60. package/src/wall/receipt.ts +2 -1
  61. package/src/wall/session.ts +5 -5
  62. package/src/wall/store.ts +3 -1
@@ -2,11 +2,12 @@
2
2
  // 算它实际用的规则,分叉点那一版和现在比(eslint 的配置是代码,读文件读不出规则)。路径都传绝对路径:相对路径会被当成忽略。
3
3
  // 每个文件都算,不挑代表文件:按目录加的覆盖、忽略,挑代表文件会漏。实测 1500 个文件 0.3 秒。
4
4
  // 算放松的:规则没了、关了、error 降成 warn;上限类规则(行数、复杂度、嵌套、参数)数字调大;别的规则改了参数(判断不了方向);
5
- // 文件变成不被 lint(被忽略、配置不再覆盖它);reportUnusedDisableDirectives 降级或关掉。新加规则、调严的不算。
5
+ // 文件变成不被 lint(被忽略、配置不再覆盖它);reportUnusedDisableDirectives 降级或关掉;noInlineConfig 关掉(代码里的注释又能就地关规则)。
6
+ // 新加规则、调严的不算。
6
7
  // 只比两边都有的文件:这次新加的文件没有"原来"。
7
8
 
8
9
  import { createRequire } from 'node:module'
9
- import { dirname, join } from 'node:path'
10
+ import { dirname, join, relative } from 'node:path'
10
11
  import { pathToFileURL } from 'node:url'
11
12
  import type { ConfirmItem } from '../base/confirm.ts'
12
13
 
@@ -16,6 +17,8 @@ export interface Effective {
16
17
  rules: Record<string, unknown[]>
17
18
  /** 没用的 eslint-disable 注释报不报:0 关、1 警告、2 报错。 */
18
19
  unusedDirectives: number
20
+ /** 代码里就地关规则、改配置的注释(eslint-disable 和 eslint 规则: off 这类)不起作用。 */
21
+ noInlineConfig: boolean
19
22
  }
20
23
 
21
24
  /** 文件(相对仓库根目录)→ 生效的规则。 */
@@ -24,9 +27,23 @@ export type FileRules = Map<string, Effective | undefined>
24
27
  /** eslint 查的代码文件。 */
25
28
  export const isCode = (path: string): boolean => /\.[cm]?[jt]sx?$/.test(path)
26
29
 
30
+ interface LintMessage {
31
+ severity: number
32
+ line?: number
33
+ message: string
34
+ ruleId: string | null
35
+ }
36
+ interface LintResult {
37
+ filePath: string
38
+ errorCount: number
39
+ warningCount: number
40
+ messages: LintMessage[]
41
+ }
27
42
  interface EslintInstance {
28
43
  isPathIgnored(path: string): Promise<boolean>
29
- calculateConfigForFile(path: string): Promise<{ rules?: Record<string, unknown>; linterOptions?: { reportUnusedDisableDirectives?: unknown } } | undefined>
44
+ lintFiles(paths: string[]): Promise<LintResult[]>
45
+ loadFormatter(name: string): Promise<{ format(results: LintResult[]): string | Promise<string> }>
46
+ calculateConfigForFile(path: string): Promise<{ rules?: Record<string, unknown>; linterOptions?: { reportUnusedDisableDirectives?: unknown; noInlineConfig?: unknown } } | undefined>
30
47
  }
31
48
  type EslintClass = new (options: { cwd: string; overrideConfigFile: string }) => EslintInstance
32
49
 
@@ -72,11 +89,45 @@ export async function fileRules(eslint: EslintClass, tree: string, config: strin
72
89
  const [severity, ...options] = Array.isArray(setting) ? setting : [setting]
73
90
  rules[name] = [level(severity), ...options]
74
91
  }
75
- result.set(file, { rules, unusedDirectives: level(computed.linterOptions?.reportUnusedDisableDirectives) })
92
+ const options = computed.linterOptions
93
+ result.set(file, { rules, unusedDirectives: level(options?.reportUnusedDisableDirectives), noInlineConfig: options?.noInlineConfig === true })
76
94
  }
77
95
  return result
78
96
  }
79
97
 
98
+ /** 一条警告:file 相对 root。 */
99
+ export interface Warning {
100
+ file: string
101
+ line: number
102
+ message: string
103
+ }
104
+
105
+ /** lint 的结果:错误几条,有错误时是只列错误的报告;警告逐条给出,由调用方挑这次改到的行。 */
106
+ export interface Linted {
107
+ errors: number
108
+ warnings: Warning[]
109
+ report: string
110
+ }
111
+
112
+ /**
113
+ * 用项目自己的 eslint 程序接口跑一遍 lint,查 files(相对 root、被 lint 的代码文件)。程序接口不读批量豁免文件
114
+ * (eslint-suppressions.json 只在 eslint 命令行里起作用),所以豁免文件放在哪、叫什么都不影响结果。跑不起来时抛错。
115
+ */
116
+ export async function lint(eslint: EslintClass, root: string, config: string, files: string[]): Promise<Linted> {
117
+ const instance = new eslint({ cwd: root, overrideConfigFile: join(root, config) })
118
+ const results = await instance.lintFiles(files.map(file => join(root, file)))
119
+ const errors = results.reduce((sum, result) => sum + result.errorCount, 0)
120
+ const warnings = results.flatMap(result =>
121
+ result.messages.filter(message => message.severity === 1).map(message => ({ file: relative(root, result.filePath), line: message.line ?? 0, message: message.message })),
122
+ )
123
+ if (errors === 0) return { errors, warnings, report: '' }
124
+ const onlyErrors = results
125
+ .filter(result => result.errorCount > 0)
126
+ .map(result => ({ ...result, warningCount: 0, fixableWarningCount: 0, messages: result.messages.filter(message => message.severity === 2) }))
127
+ const formatter = await instance.loadFormatter('stylish')
128
+ return { errors, warnings, report: await formatter.format(onlyErrors) }
129
+ }
130
+
80
131
  /** 键按字母排的 JSON:参数一样、写的顺序不同算一样。 */
81
132
  export function stable(value: unknown): string {
82
133
  return JSON.stringify(value, (_key, item: unknown) =>
@@ -113,7 +164,7 @@ const RULE_PLAIN: Record<string, string> = {
113
164
  }
114
165
 
115
166
  /** 规则在弹窗里的叫法:白话(规则名),没有白话的只写规则名。 */
116
- export function ruleName(rule: string): string {
167
+ function ruleName(rule: string): string {
117
168
  const plain = RULE_PLAIN[rule] ?? LIMITS[rule]?.what
118
169
  return plain ? `${plain}(${rule})` : rule
119
170
  }
@@ -176,11 +227,98 @@ function changesOf(before: Effective, now: Effective): Change[] {
176
227
  text: `没用了的"这里不查"注释(eslint-disable)从${LEVEL_NAMES[before.unusedDirectives]}改成${LEVEL_NAMES[now.unusedDirectives]}(reportUnusedDisableDirectives):以后用不上的这类注释可以留在代码里`,
177
228
  })
178
229
  }
230
+ if (before.noInlineConfig && !now.noInlineConfig) {
231
+ changes.push({
232
+ before: stable(['noInlineConfig', true]),
233
+ after: stable(['noInlineConfig', false]),
234
+ text: '代码里就地关规则的注释(eslint-disable、/* eslint 规则: off */)从不起作用改成起作用(关掉了 noInlineConfig):以后在代码里写一句注释就能关掉规则,不用改配置',
235
+ })
236
+ }
179
237
  return changes
180
238
  }
181
239
 
240
+ /** 参数整段列出来的长度上限:再长的只列改了的几处,整段列出来人看不出改了什么。 */
241
+ const WHOLE = 300
242
+ /** 改了的地方前后各带几个字。 */
243
+ const AROUND = 30
244
+
245
+ /** 两段只差一部分的文字:从第一处不同到最后一处不同,前后各带几个字。按字算,不切坏 emoji。 */
246
+ function around(was: string, is: string): [string, string] {
247
+ const [a, b] = [[...was], [...is]]
248
+ let start = 0
249
+ while (start < a.length && start < b.length && a[start] === b[start]) start++
250
+ let end = 0
251
+ while (end < a.length - start && end < b.length - start && a[a.length - 1 - end] === b[b.length - 1 - end]) end++
252
+ const cut = (chars: string[]): string => {
253
+ const from = Math.max(0, start - AROUND)
254
+ const to = Math.min(chars.length, chars.length - end + AROUND)
255
+ return `${from > 0 ? '…' : ''}${chars.slice(from, to).join('')}${to < chars.length ? '…' : ''}`
256
+ }
257
+ return [cut(a), cut(b)]
258
+ }
259
+
260
+ /** 两串逐项对齐(最长公共子序列):没变的项对上,剩下的是删掉的和加上的。 */
261
+ function align(was: string[], is: string[]): { kind: 'same' | 'gone' | 'new'; text: string; at: number }[] {
262
+ const longest = was.map(() => new Array<number>(is.length + 1).fill(0))
263
+ longest.push(new Array<number>(is.length + 1).fill(0))
264
+ for (let i = was.length - 1; i >= 0; i--) {
265
+ for (let j = is.length - 1; j >= 0; j--) {
266
+ longest[i]![j] = was[i] === is[j] ? longest[i + 1]![j + 1]! + 1 : Math.max(longest[i + 1]![j]!, longest[i]![j + 1]!)
267
+ }
268
+ }
269
+ const steps: { kind: 'same' | 'gone' | 'new'; text: string; at: number }[] = []
270
+ let [i, j] = [0, 0]
271
+ while (i < was.length || j < is.length) {
272
+ if (i < was.length && j < is.length && was[i] === is[j]) {
273
+ steps.push({ kind: 'same', text: was[i]!, at: j })
274
+ i++
275
+ j++
276
+ } else if (j < is.length && (i === was.length || longest[i + 1]![j]! < longest[i]![j + 1]!)) {
277
+ steps.push({ kind: 'new', text: is[j]!, at: j })
278
+ j++
279
+ } else {
280
+ steps.push({ kind: 'gone', text: was[i]!, at: i })
281
+ i++
282
+ }
283
+ }
284
+ return steps
285
+ }
286
+
287
+ /**
288
+ * 参数很长(比如一长串选择器)时只列改了的地方,一处不漏:两版逐项对齐,没变的不列;
289
+ * 同一段里删一项、加一项的配成"改了",只列改了的那段,前后带几个字;多出来的整项列出来。
290
+ */
291
+ function placesChanged(was: unknown[], is: unknown[]): string[] {
292
+ const lines: string[] = []
293
+ const steps = align(was.map(item => stable(item)), is.map(item => stable(item)))
294
+ let index = 0
295
+ while (index < steps.length) {
296
+ if (steps[index]!.kind === 'same') {
297
+ index++
298
+ continue
299
+ }
300
+ const gone: { text: string; at: number }[] = []
301
+ const added: { text: string; at: number }[] = []
302
+ while (index < steps.length && steps[index]!.kind !== 'same') {
303
+ const step = steps[index++]!
304
+ ;(step.kind === 'gone' ? gone : added).push(step)
305
+ }
306
+ const pairs = Math.min(gone.length, added.length)
307
+ for (let k = 0; k < pairs; k++) {
308
+ const [shortBefore, shortAfter] = around(gone[k]!.text, added[k]!.text)
309
+ lines.push(`第 ${added[k]!.at + 1} 项 原来:${shortBefore}`, `第 ${added[k]!.at + 1} 项 现在:${shortAfter}`)
310
+ }
311
+ for (const item of gone.slice(pairs)) lines.push(`少了原来的第 ${item.at + 1} 项:${item.text}`)
312
+ for (const item of added.slice(pairs)) lines.push(`多了现在的第 ${item.at + 1} 项:${item.text}`)
313
+ }
314
+ return lines
315
+ }
316
+
182
317
  function changedText(rule: string, was: unknown[], is: unknown[]): string {
183
- return [`lint 规则 ${ruleName(rule)} 的参数改了,程序看不出是改松还是改紧`, `原来:${stable(was)}`, `现在:${stable(is)}`].join('\n')
318
+ const title = `lint 规则 ${ruleName(rule)} 的参数改了,程序看不出是改松还是改紧`
319
+ const [before, after] = [stable(was), stable(is)]
320
+ if (before.length + after.length <= WHOLE) return [title, `原来:${before}`, `现在:${after}`].join('\n')
321
+ return [title, ...placesChanged(was, is)].join('\n')
184
322
  }
185
323
 
186
324
  /** 列出来的文件最多几个。 */
@@ -1,5 +1,5 @@
1
- // 读文件就能比的放松:.codekeep/config.json、eslint 的批量豁免文件、gitleaks 的忽略文件和配置、biome 的配置。和分叉点那一版比,
2
- // 放松的列成条目交给底座的用户确认(base/confirm.ts);收紧的(加检查、豁免变少)不问。
1
+ // 读文件就能比的放松:.codekeep/config.json、gitleaks 的忽略文件和配置、biome 的配置。和分叉点那一版比,
2
+ // 放松的列成条目交给底座的用户确认(base/confirm.ts);收紧的(加检查)不问。
3
3
  // eslint、tsconfig 生效的配置要跑工具才算得出来,见 eslint.ts、tsconfig.ts。
4
4
  //
5
5
  // 每一项的改之前、改成什么写成能区分同一项改动的内容:同一条检查的同一次改命令在哪个分支上都是同一项,共用一次同意;
@@ -9,7 +9,7 @@ import type { ConfirmItem } from '../base/confirm.ts'
9
9
  import type { Judging } from '../base/judging.ts'
10
10
  import { hash } from '../base/records.ts'
11
11
  import { CONFIG_PATH, type Config, KEEP_DIR } from './config.ts'
12
- import { ruleName, stable } from './eslint.ts'
12
+ import { stable } from './eslint.ts'
13
13
 
14
14
  /** gitleaks 的忽略文件和配置(仓库根目录;gitleaks 在仓库根目录跑时用的就是这两个)。 */
15
15
  export const GITLEAKS_IGNORE = '.gitleaksignore'
@@ -58,13 +58,6 @@ export function configItems(before: Config, now: Config): ConfirmItem[] {
58
58
  text: `拿来比规则的 eslint 配置文件从 ${before.eslint.config} 换成了 ${now.eslint.config}:程序看不出两份是不是一回事,lint 实际用的可能不是这一份`,
59
59
  })
60
60
  }
61
- if (now.eslint.suppressions !== before.eslint.suppressions) {
62
- items.push({
63
- before: stable(['eslint.suppressions', before.eslint.suppressions]),
64
- after: stable(['eslint.suppressions', now.eslint.suppressions]),
65
- text: `eslint 的批量豁免文件从 ${before.eslint.suppressions} 换成了 ${now.eslint.suppressions}:换过去的那份里豁免了什么没和原来的比`,
66
- })
67
- }
68
61
  }
69
62
  }
70
63
  for (const tsconfig of before.tsconfig.filter(path => !now.tsconfig.includes(path))) {
@@ -74,59 +67,13 @@ export function configItems(before: Config, now: Config): ConfirmItem[] {
74
67
  items.push({ before: stable(['prettier', true]), after: stable(['prettier', false]), text: '不再比格式检查查哪些文件(关掉了 prettier 一项):以后往忽略文件里加路径、躲开格式检查,程序看不出来' })
75
68
  }
76
69
  if (before.secrets && !now.secrets) items.push({ before: stable(['secrets', true]), after: stable(['secrets', false]), text: '关掉了密钥扫描(secrets):以后提交里带了密钥、密码,整组不再拦' })
77
- return items
78
- }
79
-
80
- /** 批量豁免文件:文件 → 规则 → 豁免了几处。读不出来时是 undefined。 */
81
- type Suppressions = Map<string, number>
82
-
83
- function suppressionsOf(text: string): Suppressions | undefined {
84
- try {
85
- const raw = JSON.parse(text) as unknown
86
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return undefined
87
- const counts: Suppressions = new Map()
88
- for (const [file, rules] of Object.entries(raw as Record<string, unknown>)) {
89
- if (typeof rules !== 'object' || rules === null) return undefined
90
- for (const [rule, entry] of Object.entries(rules as Record<string, unknown>)) {
91
- const count = (entry as { count?: unknown } | null)?.count
92
- if (typeof count !== 'number') return undefined
93
- counts.set(`${file}\0${rule}`, count)
94
- }
95
- }
96
- return counts
97
- } catch {
98
- return undefined
70
+ for (const path of before.styles?.theme.filter(item => !now.styles?.theme.includes(item)) ?? []) {
71
+ items.push({ before: stable(['styles.theme', path]), after: '', text: `不再管主题文件 ${path}(从 styles 里去掉了):以后改它不再问你` })
99
72
  }
100
- }
101
-
102
- /** 列出来的最多几处。 */
103
- const SHOWN = 20
104
-
105
- /** eslint 的批量豁免文件里,哪条规则、哪个文件豁免的数量变多了:合成一项。 */
106
- export function suppressionsItem(path: string, judging: Judging): ConfirmItem | undefined {
107
- if (judging.now === undefined) return undefined
108
- const now = suppressionsOf(judging.now)
109
- const before = judging.before === undefined ? new Map<string, number>() : suppressionsOf(judging.before)
110
- if (!now || !before) {
111
- if (judging.before === judging.now) return undefined
112
- return {
113
- before: hash(judging.before),
114
- after: hash(judging.now),
115
- text: `eslint 的批量豁免文件 ${path} 改了,${!now ? '现在这一版' : '分叉点那一版'}读不出来,程序看不出是不是多豁免了`,
116
- }
117
- }
118
- const more = [...now].filter(([key, count]) => count > (before.get(key) ?? 0)).sort(([a], [b]) => (a < b ? -1 : 1))
119
- if (more.length === 0) return undefined
120
- const lines = more.slice(0, SHOWN).map(([key, count]) => {
121
- const [file, rule] = key.split('\0')
122
- return `${file}:${ruleName(rule ?? '')} 从 ${before.get(key) ?? 0} 处变成 ${count} 处`
123
- })
124
- if (more.length > SHOWN) lines.push(`……还有 ${more.length - SHOWN} 处`)
125
- return {
126
- before: stable(more.map(([key]) => [key, before.get(key) ?? 0])),
127
- after: stable(more),
128
- text: [`eslint 的批量豁免文件 ${path} 多豁免了 ${more.length} 处:这些地方违反了规则也照样通过`, ...lines].join('\n'),
73
+ for (const dir of before.styles?.ui.filter(item => !now.styles?.ui.includes(item)) ?? []) {
74
+ items.push({ before: stable(['styles.ui', dir]), after: '', text: `不再管组件层目录 ${dir} 里的样式文件(从 styles 里去掉了):以后改这些样式不再问你` })
129
75
  }
76
+ return items
130
77
  }
131
78
 
132
79
  /** .gitleaksignore 的条目(每行一条,# 开头的是注释)。 */
@@ -136,6 +83,9 @@ const entries = (text: string | undefined): string[] =>
136
83
  .map(line => line.trim())
137
84
  .filter(line => line !== '' && !line.startsWith('#'))
138
85
 
86
+ /** 列出来的最多几条。 */
87
+ const SHOWN = 20
88
+
139
89
  /** gitleaks 的忽略文件多了条目、配置改了(配置是 TOML,程序看不出方向,改了就问)。 */
140
90
  export function gitleaksItems(ignore: Judging, config: Judging): ConfirmItem[] {
141
91
  const items: ConfirmItem[] = []
@@ -1,22 +1,36 @@
1
1
  // "代码规范"说给 agent 的话,经底座的钩子送出去(base/module.ts 的 brief):会话开始时说几句规范的约定。
2
+ // 配置里写了 styles(配了前端规则)的,多说一条前端的约定。
2
3
  // 没有改文件前的拦截和停止门:lint 自己会报,规范检查在落地前的整组里跑(见 full.ts)。
3
4
 
4
5
  import { existsSync } from 'node:fs'
5
6
  import { join } from 'node:path'
6
7
  import type { Repo } from '../base/repo.ts'
7
- import { CONFIG_PATH, KEEP_DIR } from './config.ts'
8
+ import { fileNow } from '../base/git.ts'
9
+ import { CONFIG_PATH, KEEP_DIR, parseConfig, type StylesConfig } from './config.ts'
8
10
 
9
- export function guide(label = '这个仓库'): string[] {
11
+ export function guide(label = '这个仓库', styles?: StylesConfig): string[] {
10
12
  return [
11
13
  `${label}用 codekeep 管代码规范(${KEEP_DIR}/):`,
12
- `1. 类型检查、lint、格式检查由 codekeep 在整组(testpace full)里跑,命令和要比的配置写在 ${CONFIG_PATH}。`,
13
- '2. 不改松规范:不关规则、不把 error 降成 warn、不调高长度和复杂度上限、不加忽略的路径、不关严格类型选项、不往批量豁免文件里加条目。确实要改,整组会要用户确认:先在对话里用白话讲清改了哪条、为什么只能这样。',
14
+ `1. 类型检查、lint、格式检查由 codekeep 在整组(testpace full)里跑:lint 由它用项目的 eslint 直接查,别的命令和要比的配置写在 ${CONFIG_PATH}。`,
15
+ '2. 不改松规范:不关规则、不把 error 降成 warn、不调高长度和复杂度上限、不加忽略的路径、不关严格类型选项;eslint 的批量豁免(eslint-suppressions.json)在整组里不起作用,超标的改代码。确实要改,整组会要用户确认:先在对话里用白话讲清改了哪条、为什么只能这样。',
14
16
  '3. 代码里"这里不查"的注释(eslint-disable、@ts-expect-error 这类)必须写理由,比如 // eslint-disable-next-line 规则名 -- 理由;能改代码就改代码,不加这种注释。',
15
17
  '4. 提交里不放密钥、密码;测试用的假值写得一眼能看出是假的(比如 test-password-not-real)。',
18
+ ...(styles ? [frontend(styles)] : []),
16
19
  ]
17
20
  }
18
21
 
22
+ function frontend(styles: StylesConfig): string {
23
+ const places = [...styles.theme.map(path => `主题 ${path}`), ...styles.ui.map(dir => `组件层 ${dir} 里的样式文件`)].join('、')
24
+ return [
25
+ '5. 前端:组件不合适时不写样式、不写具体的值去补,告诉用户。页面上不加说明文字:lint 的文字警告只是提示,放的是数据、单位、问句、要照录的不用改,不为消掉警告删掉原因、办法和数据。',
26
+ `具体的颜色、尺寸只写在${places};要改先在对话里讲清楚改什么、为什么,整组会要用户确认。`,
27
+ '前端文件里"这里不查"的注释不起作用,lint 报了就改代码。',
28
+ ].join('')
29
+ }
30
+
19
31
  /** 会话说明:接入了"代码规范"的仓库(工作区里有 .codekeep/)才说。 */
20
32
  export function brief(label: string, repo?: Repo): string[] {
21
- return repo && existsSync(join(repo.root, KEEP_DIR)) ? guide(label) : []
33
+ if (!repo || !existsSync(join(repo.root, KEEP_DIR))) return []
34
+ const text = fileNow(repo.root, CONFIG_PATH)
35
+ return guide(label, text === undefined ? undefined : parseConfig(text).config?.styles)
22
36
  }
@@ -0,0 +1,72 @@
1
+ // 前端具体的外观只准写在主题文件和组件层目录的样式文件里,这两处改了要用户同意。
2
+ // 读文件就能比:和分叉点那一版比,主题文件、组件层目录里的样式文件(.css、.less、.scss 这类)新加、删掉、改了内容的,
3
+ // 一个文件列一项,按行列出原来和现在。只是空白、空行变了的不问。组件层目录里别的文件(组件代码、取数)不管。
4
+ // 只比两边配置里都写着的路径:这次新写进配置的(首次接入、新加的目录)不比。
5
+
6
+ import type { ConfirmItem } from '../base/confirm.ts'
7
+ import { type Judging, judgingDir, judgingFile } from '../base/judging.ts'
8
+ import { hash } from '../base/records.ts'
9
+ import type { StylesConfig } from './config.ts'
10
+ import { stable } from './eslint.ts'
11
+
12
+ /** 组件层目录里算样式文件的。 */
13
+ export const isStyle = (path: string): boolean => /\.(css|less|s[ac]ss|styl)$/.test(path)
14
+
15
+ /** 一项里最多列几行。 */
16
+ const SHOWN = 10
17
+
18
+ const linesOf = (text: string | undefined): string[] =>
19
+ (text ?? '')
20
+ .split('\n')
21
+ .map(line => line.trim())
22
+ .filter(line => line !== '')
23
+
24
+ /** a 里有、b 里没有的行,按 a 的顺序;同样的行按次数算。 */
25
+ function minus(a: string[], b: string[]): string[] {
26
+ const left = new Map<string, number>()
27
+ for (const line of b) left.set(line, (left.get(line) ?? 0) + 1)
28
+ return a.filter(line => {
29
+ const count = left.get(line) ?? 0
30
+ if (count > 0) left.set(line, count - 1)
31
+ return count === 0
32
+ })
33
+ }
34
+
35
+ /** 一个文件两版之间的一项:只是空白、空行变了的没有。what 是这个文件在弹窗里的叫法,then 是改了以后会怎样。 */
36
+ function fileItem(path: string, judging: Judging, what: string, then: string): ConfirmItem | undefined {
37
+ const before = linesOf(judging.before)
38
+ const now = linesOf(judging.now)
39
+ const removed = minus(before, now)
40
+ const added = minus(now, before)
41
+ if (removed.length === 0 && added.length === 0 && (judging.before === undefined) === (judging.now === undefined)) return undefined
42
+ const head =
43
+ judging.before === undefined
44
+ ? `新加了${what} ${path}(${now.length} 行):${then}`
45
+ : judging.now === undefined
46
+ ? `删掉了${what} ${path}:${then}`
47
+ : `${what} ${path} 改了(删掉 ${removed.length} 行、新加 ${added.length} 行):${then}`
48
+ const lines = [...removed.map(line => `原来:${line}`), ...added.map(line => `现在:${line}`)]
49
+ const shown = judging.now === undefined ? [] : lines.slice(0, SHOWN)
50
+ if (judging.now !== undefined && lines.length > SHOWN) shown.push(`……还有 ${lines.length - SHOWN} 行`)
51
+ return { before: stable(['style', path, hash(judging.before)]), after: stable(['style', path, hash(judging.now)]), text: [head, ...shown].join('\n') }
52
+ }
53
+
54
+ /** 主题文件、组件层的样式文件改了的:一个文件一项。 */
55
+ export function stylesItems(root: string, fork: string, before: StylesConfig, now: StylesConfig): ConfirmItem[] {
56
+ const items: ConfirmItem[] = []
57
+ const themes = before.theme.filter(path => now.theme.includes(path))
58
+ for (const path of themes) {
59
+ const item = fileItem(path, judgingFile(root, fork, path), '主题文件', '页面上用到这些颜色、尺寸的地方都会跟着变')
60
+ if (item) items.push(item)
61
+ }
62
+ const seen = new Set(themes)
63
+ for (const dir of before.ui.filter(path => now.ui.includes(path))) {
64
+ for (const [path, judging] of judgingDir(root, fork, dir)) {
65
+ if (!isStyle(path) || seen.has(path)) continue
66
+ seen.add(path)
67
+ const item = fileItem(path, judging, '组件层的样式文件', '用到它的组件在页面上的样子会变,要到页面上看')
68
+ if (item) items.push(item)
69
+ }
70
+ }
71
+ return items
72
+ }
@@ -11,7 +11,7 @@ import { currentBranch, defaultBranch, forkPoint, landings, workTreeId } from '.
11
11
  import { busyText, failureText, ignoredBy } from '../base/repo.ts'
12
12
  import { commandExists, COMMAND_KEYS, loadConfig } from './config.ts'
13
13
  import { askLayermap, BRANCH_CAP, fullReasons, INDIRECT_RANK, LAYERMAP_HINT, NEARBY_RANK, outsideNote } from './focused.ts'
14
- import { paceRuns, runRecorded } from './record.ts'
14
+ import { paceRuns, type Recorded, runRecorded } from './record.ts'
15
15
  import { renderReport } from './report.ts'
16
16
  import { PROVE_RUNS, provenFixed, type TestResult } from './results.ts'
17
17
  import { nodeTest } from './run/node-test.ts'
@@ -78,7 +78,7 @@ export async function focused(args: string[], usage: string): Promise<number> {
78
78
  }
79
79
  if (related.execution.interrupted) return EXIT.interrupted
80
80
  if (related.record.result === 'fail') {
81
- console.log([...lines, failureText('相关测试失败', related.record.log, related.execution), ...related.notes].join('\n'))
81
+ console.log([...lines, failedText('相关测试', related), ...related.notes].join('\n'))
82
82
  return EXIT.fail
83
83
  }
84
84
  lines.push(`相关测试通过 · 用时 ${duration(related.execution.durationMs)}`, ...related.notes)
@@ -96,6 +96,12 @@ export async function focused(args: string[], usage: string): Promise<number> {
96
96
  return code
97
97
  }
98
98
 
99
+ /** files 没过的说法。命令自己通过、只是跑完核对出有文件没跑到的(notes 里点名),不贴输出节选。 */
100
+ function failedText(what: string, run: Recorded): string {
101
+ if (run.execution.exitCode !== 0) return failureText(`${what}失败`, run.record.log, run.execution)
102
+ return `${what}没通过:命令通过了,跑完核对出有测试文件没跑到(见下)· 用时 ${duration(run.execution.durationMs)}\n完整日志:${run.record.log}`
103
+ }
104
+
99
105
  export async function files(argv: string[], usage: string): Promise<number> {
100
106
  // --repeat N:连跑 N 次,没过就停。造出时好时坏的测试的失败,或证明修好了(见 results.ts 的 PROVE_RUNS)
101
107
  let times = 1
@@ -157,7 +163,7 @@ export async function files(argv: string[], usage: string): Promise<number> {
157
163
  took += run.execution.durationMs
158
164
  if (run.record.result === 'fail') {
159
165
  const which = times > 1 ? `连跑第 ${index} 次(共 ${times} 次)` : ''
160
- console.log([failureText(`${what}${which}失败`, run.record.log, run.execution), ...notes].join('\n'))
166
+ console.log([failedText(`${what}${which}`, run), ...notes].join('\n'))
161
167
  return EXIT.fail
162
168
  }
163
169
  passes.push(run.results)
package/src/pace/full.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // 整组里"跑测试"的部分(base/module.ts 的 fullPart):测试以外的检查(full),再把 tests 规则找到的全部测试文件交给 files。
2
- // 测试由这里按规则找出来,不靠谁记得把新测试加进整组。跑完读回每个测试的结果:记下没过的,认时好时坏和几轮没过的。
2
+ // 测试由这里按规则找出来,不靠谁记得把新测试加进整组。跑完读回每个测试的结果:记下没过的,认时好时坏和几轮没过的;
3
+ // 交给 files 的文件有没交回结果的(results.ts 的 unreported),各段都过了的整组算没过,全部测试那一段没过的照样点名。
3
4
 
4
5
  import type { FullPart } from '../base/module.ts'
5
6
  import type { Repo } from '../base/repo.ts'
@@ -7,7 +8,7 @@ import { loadConfig } from './config.ts'
7
8
  import { unconfirmedChanges } from './consent.ts'
8
9
  import type { PaceRun } from './record.ts'
9
10
  import { FULL_STEP, TESTS_STEP } from './report.ts'
10
- import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile, type TestResult } from './results.ts'
11
+ import { failedTests, noteResults, reached, readResults, RESULTS_ENV, resultsFile, unreported, unreportedText } from './results.ts'
11
12
  import { findTests } from './tests.ts'
12
13
 
13
14
  export function fullPart(repo: Repo): FullPart | { problem: string } {
@@ -27,33 +28,21 @@ export function fullPart(repo: Repo): FullPart | { problem: string } {
27
28
  ],
28
29
  summary: `${tests.length} 个测试文件`,
29
30
  env: { [RESULTS_ENV]: resultsAt.path },
30
- finish() {
31
+ finish(failedStep) {
31
32
  const results = readResults(resultsAt.path, repo.root)
33
+ // 全部测试那一段跑了(过了,或它自己没过)才核对;前面的段没过,测试没跑,核对不出什么
34
+ const ran = failedStep === undefined || failedStep === TESTS_STEP
35
+ const silent = ran ? unreported(tests, results) : []
36
+ const text = unreportedText(files, silent, reached(results).length, failedStep !== undefined)
32
37
  return {
33
- fields: { tests: tests.length, ...(results.length > 0 ? { failed: failedTests(results) } : {}) },
34
- problems: silentFiles(tests, results, files),
35
- notes: (record, before) => noteResults(repo, { record: record as PaceRun, results, before: before as PaceRun[], whole: tests }),
38
+ fields: { tests: tests.length, ...(results.length > 0 ? { failed: failedTests(results) } : {}), ...(silent.length > 0 ? { notRun: silent } : {}) },
39
+ problems: failedStep === undefined && text ? [text] : [],
40
+ notes: (record, before) => [
41
+ ...(failedStep !== undefined && text ? [text] : []),
42
+ ...noteResults(repo, { record: record as PaceRun, results, before: before as PaceRun[], whole: tests }),
43
+ ],
36
44
  }
37
45
  },
38
46
  dispose: () => resultsAt.dispose(),
39
47
  }
40
48
  }
41
-
42
- /** 一次最多点名几个没交回结果的文件。 */
43
- const NAMED = 10
44
-
45
- /**
46
- * 交给 files 的每个测试文件都要交回至少一条结果(过、没过、跳过都算)。不读脚本:脚本漏跑了哪一类测试,结果里就少了那些文件。
47
- * 一条结果都没交回的,是 files 整个没经 testpace run 跑、也没自己写结果。
48
- */
49
- export function silentFiles(tests: readonly string[], results: readonly TestResult[], files: string): string[] {
50
- const reported = new Set(results.map(test => test.file))
51
- const silent = tests.filter(file => !reported.has(file))
52
- if (silent.length === 0) return []
53
- const how = `node:test、Vitest、Playwright 的测试经 testpace run 跑(它会交回结果);别的跑法自己往环境变量 ${RESULTS_ENV} 给的文件里,每个测试追加一行 JSON:{"file":"文件的绝对路径","name":"测试名","status":"passed、failed 或 skipped"}`
54
- if (results.length === 0) return [`files 命令(${files})跑完,一个测试结果都没交回,整组核对不了跑到了哪些测试。${how}。`]
55
- const named = silent.slice(0, NAMED).join('、') + (silent.length > NAMED ? ` 等 ${silent.length} 个` : '')
56
- return [
57
- `交给 files 命令(${files})的测试文件里,这些一条结果都没交回:${named}。可能是 files 的脚本没把它们交给测试框架、被框架的配置排除了,或跑它们的那一路没交结果。${how}。`,
58
- ]
59
- }
package/src/pace/index.ts CHANGED
@@ -4,6 +4,7 @@ import type { Module } from '../base/module.ts'
4
4
  import { contractProblems, FIELDS } from './config.ts'
5
5
  import { fullPart } from './full.ts'
6
6
  import { alerts, fullCommandHint, rhythm } from './session.ts'
7
+ import { onSession, unfinished } from './unfinished.ts'
7
8
 
8
9
  export const pace: Module = {
9
10
  name: 'pace',
@@ -12,5 +13,7 @@ export const pace: Module = {
12
13
  brief: rhythm,
13
14
  alerts,
14
15
  beforeCommand: fullCommandHint,
16
+ onSession,
17
+ unfinished,
15
18
  fullPart,
16
19
  }
@@ -3,9 +3,9 @@
3
3
  import { type Repo, runClaimed, runner } from '../base/repo.ts'
4
4
  import type { Execution } from '../base/execute.ts'
5
5
  import { currentBranch, headCommit, workTreeId } from '../base/git.ts'
6
- import type { RunningMarker, RunRecord, Store } from '../base/store.ts'
6
+ import type { RunMarker, RunRecord, Store } from '../base/store.ts'
7
7
  import type { CommandKey } from './config.ts'
8
- import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile, type TestResult, wholeFiles } from './results.ts'
8
+ import { failedTests, noteResults, reached, readResults, RESULTS_ENV, resultsFile, type TestResult, unreported, unreportedText, wholeFiles } from './results.ts'
9
9
  import type { TestId } from './testlist.ts'
10
10
 
11
11
  /** 这个模块跑的命令的记录:fast、files,和整组(full,底座跑的,带着这个模块加的字段)。 */
@@ -17,6 +17,8 @@ export interface PaceRun extends RunRecord {
17
17
  tests?: number
18
18
  /** 没过的测试(经 testpace run 跑、交回了每个测试结果的才有)。 */
19
19
  failed?: TestId[]
20
+ /** 交给 files 的测试文件里一条结果都没交回的(没跑到),见 results.ts 的 unreported。 */
21
+ notRun?: string[]
20
22
  /** testpace files --repeat 连跑的第几次(从 1 起)、共几次。 */
21
23
  repeat?: { index: number; of: number }
22
24
  }
@@ -32,12 +34,13 @@ export interface Recorded {
32
34
  execution: Execution
33
35
  /** 命令里的 testpace run 交回的每个测试的结果;没经 testpace run 跑的为空。 */
34
36
  results: TestResult[]
35
- /** 看这些结果要说给 agent 的话:时好时坏、几轮没过(见 results.ts)。 */
37
+ /** 看这些结果要说给 agent 的话:没跑到的、时好时坏、几轮没过(见 results.ts)。 */
36
38
  notes: string[]
37
39
  }
38
40
 
39
41
  /**
40
42
  * 跑 fast 或 files 并记一条记录(见 runClaimed),收回每个测试的结果、看有没有时好时坏和几轮没过的(见 results.ts)。
43
+ * files 还核对交给它的每个测试文件都交回了结果:命令通过、却有没跑到的,这次算没过;命令没过的,照样点名没跑到的。
41
44
  * 跑完重算一次代码(treeAtEnd):认时好时坏要"同一份代码",跑的过程中代码改过的不算。通过记录只认 full。
42
45
  */
43
46
  export async function runRecorded(
@@ -47,7 +50,7 @@ export async function runRecorded(
47
50
  args: string[],
48
51
  tree: string,
49
52
  options: { repeat?: PaceRun['repeat']; passedEarlier?: Map<string, string> } = {},
50
- ): Promise<Recorded | { busy: RunningMarker }> {
53
+ ): Promise<Recorded | { busy: RunMarker }> {
51
54
  const file = resultsFile()
52
55
  try {
53
56
  const run = await runClaimed(repo, kind, command, args, tree, { [RESULTS_ENV]: file.path })
@@ -55,6 +58,8 @@ export async function runRecorded(
55
58
  const { id, startedAt, log, execution } = run
56
59
  const results = execution.interrupted ? [] : readResults(file.path, repo.root)
57
60
  const failed = failedTests(results)
61
+ const silent = kind === 'files' && !execution.interrupted ? unreported(args, results) : []
62
+ const unreached = unreportedText(command, silent, reached(results).length, execution.exitCode !== 0)
58
63
  const record: PaceRun = {
59
64
  id,
60
65
  kind,
@@ -66,9 +71,10 @@ export async function runRecorded(
66
71
  startedAt,
67
72
  durationMs: execution.durationMs,
68
73
  exitCode: execution.exitCode,
69
- result: execution.exitCode === 0 ? 'pass' : 'fail',
74
+ result: execution.exitCode === 0 && !unreached ? 'pass' : 'fail',
70
75
  ...(kind === 'files' ? { files: args } : {}),
71
76
  ...(results.length > 0 ? { failed } : {}),
77
+ ...(silent.length > 0 ? { notRun: silent } : {}),
72
78
  ...(options.repeat ? { repeat: options.repeat } : {}),
73
79
  ...runner(),
74
80
  log,
@@ -76,7 +82,7 @@ export async function runRecorded(
76
82
  if (execution.interrupted) return { record, execution, results, notes: [] }
77
83
  const before = paceRuns(repo.store)
78
84
  repo.store.appendRun(record)
79
- const notes = noteResults(repo, { record, results, before, whole: wholeFiles(args), ...(options.passedEarlier ? { passedEarlier: options.passedEarlier } : {}) })
85
+ const notes = [...(unreached ? [unreached] : []), ...noteResults(repo, { record, results, before, whole: wholeFiles(args), ...(options.passedEarlier ? { passedEarlier: options.passedEarlier } : {}) })]
80
86
  return { record, execution, results, notes }
81
87
  } finally {
82
88
  file.dispose()