gatelight 0.0.0-stage → 0.17.9
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/.antigravity-plugin/plugin.json +9 -0
- package/.claude-plugin/plugin.json +11 -0
- package/.codex-plugin/plugin.json +18 -0
- package/.mcp.json +8 -0
- package/bin/modwall +8 -0
- package/bin/node.sh +14 -0
- package/bin/testcraft +8 -0
- package/bin/testpace +8 -0
- package/entry/command +44 -0
- package/hooks/antigravity.sh +24 -0
- package/hooks/codex.json +50 -0
- package/hooks/codex.sh +7 -0
- package/hooks/hooks.json +43 -0
- package/hooks/testpace.ts +25 -0
- package/hooks.json +16 -0
- package/mcp_config.json +8 -0
- package/package.json +21 -4
- package/setup.mjs +99 -0
- package/skills/merge/SKILL.md +42 -0
- package/skills/modular/SKILL.md +75 -0
- package/skills/setup/SKILL.md +101 -0
- package/skills/setup-modwall/SKILL.md +112 -0
- package/skills/setup-testcraft/SKILL.md +23 -0
- package/skills/setup-testcraft/checklist/dev-login.md +20 -0
- package/skills/write-tests/SKILL.md +153 -0
- package/src/base/agent.ts +100 -0
- package/src/base/baseline.ts +54 -0
- package/src/base/commandline.ts +40 -0
- package/src/base/commands.ts +94 -0
- package/src/base/confirm.ts +161 -0
- package/src/base/contract.ts +94 -0
- package/src/base/coverage.ts +46 -0
- package/src/base/entry.ts +90 -0
- package/src/base/excerpt.ts +46 -0
- package/src/base/execute.ts +70 -0
- package/src/base/exit.ts +6 -0
- package/src/base/format.ts +27 -0
- package/src/base/full.ts +160 -0
- package/src/base/gate.ts +251 -0
- package/src/base/git.ts +361 -0
- package/src/base/glob.ts +38 -0
- package/src/base/hook.ts +297 -0
- package/src/base/hookformat.ts +257 -0
- package/src/base/judging.ts +27 -0
- package/src/base/layermap.ts +69 -0
- package/src/base/module.ts +88 -0
- package/src/base/process-group.ts +101 -0
- package/src/base/records.ts +66 -0
- package/src/base/repo.ts +155 -0
- package/src/base/sessions.ts +55 -0
- package/src/base/shell.ts +176 -0
- package/src/base/stop.ts +100 -0
- package/src/base/store.ts +348 -0
- package/src/base/version.ts +24 -0
- package/src/cli.ts +186 -0
- package/src/craft/change.ts +24 -0
- package/src/craft/checklist.ts +157 -0
- package/src/craft/commands.ts +111 -0
- package/src/craft/config.ts +15 -0
- package/src/craft/full.ts +30 -0
- package/src/craft/index.ts +12 -0
- package/src/craft/session.ts +21 -0
- package/src/mcp.ts +79 -0
- package/src/modules.ts +10 -0
- package/src/modwall.ts +8 -0
- package/src/pace/commands.ts +281 -0
- package/src/pace/config.ts +103 -0
- package/src/pace/consent.ts +81 -0
- package/src/pace/focused.ts +208 -0
- package/src/pace/full.ts +38 -0
- package/src/pace/index.ts +16 -0
- package/src/pace/record.ts +84 -0
- package/src/pace/report.ts +335 -0
- package/src/pace/results.ts +243 -0
- package/src/pace/run/node-test-reporter.mjs +34 -0
- package/src/pace/run/node-test.ts +26 -0
- package/src/pace/run/playwright-reporter.mjs +48 -0
- package/src/pace/run/playwright.ts +34 -0
- package/src/pace/run/runner.ts +157 -0
- package/src/pace/run/targets.ts +130 -0
- package/src/pace/run/vitest-launcher.mjs +101 -0
- package/src/pace/run/vitest.ts +22 -0
- package/src/pace/session.ts +35 -0
- package/src/pace/testlist.ts +91 -0
- package/src/pace/tests.ts +22 -0
- package/src/pace/verify.ts +95 -0
- package/src/testcraft.ts +9 -0
- package/src/wall/check.ts +258 -0
- package/src/wall/commands.ts +279 -0
- package/src/wall/config.ts +394 -0
- package/src/wall/database.ts +136 -0
- package/src/wall/dbcheck.ts +389 -0
- package/src/wall/dbrules.ts +213 -0
- package/src/wall/edit.ts +64 -0
- package/src/wall/files.ts +35 -0
- package/src/wall/full.ts +30 -0
- package/src/wall/index.ts +15 -0
- package/src/wall/init.ts +149 -0
- package/src/wall/layermap.ts +124 -0
- package/src/wall/layout.ts +231 -0
- package/src/wall/loosen.ts +157 -0
- package/src/wall/miniprogram.ts +80 -0
- package/src/wall/project.ts +88 -0
- package/src/wall/rules.ts +400 -0
- package/src/wall/session.ts +198 -0
- package/src/wall/sql.ts +510 -0
- package/src/wall/store.ts +39 -0
- package/README.md +0 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// 这次改动的全貌:分叉点、改了哪些文件。清单按它挑命中的条目。
|
|
2
|
+
|
|
3
|
+
import { type Change, changesSince, forkPoint } from '../base/git.ts'
|
|
4
|
+
import { joined } from './config.ts'
|
|
5
|
+
|
|
6
|
+
export interface Snapshot {
|
|
7
|
+
root: string
|
|
8
|
+
base: string
|
|
9
|
+
branch: string
|
|
10
|
+
changes: Change[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type Opened = { snapshot: Snapshot } | { problem: string; code: 'notJoined' | 'usage' }
|
|
14
|
+
|
|
15
|
+
export function open(root: string): Opened {
|
|
16
|
+
const base = forkPoint(root)
|
|
17
|
+
if ('problem' in base) {
|
|
18
|
+
// 找不到分叉点时只看工作区:没有 .testcraft/ 就是没接入
|
|
19
|
+
if (!joined(root)) return { problem: '这个仓库没有接入 testcraft(没有 .testcraft/ 目录)', code: 'notJoined' }
|
|
20
|
+
return { problem: base.problem, code: 'usage' }
|
|
21
|
+
}
|
|
22
|
+
if (!joined(root, base.commit)) return { problem: '这个仓库没有接入 testcraft(没有 .testcraft/ 目录)', code: 'notJoined' }
|
|
23
|
+
return { snapshot: { root, base: base.commit, branch: base.branch, changes: changesSince(root, base.commit) } }
|
|
24
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// 按改动触发的清单:.testcraft/checklist/<编号>.md,一条一个文件,每条记一个写不成测试、又能从改动看出来的坑。
|
|
2
|
+
// # 标题:要守的事
|
|
3
|
+
// ## 触发:每行一条,行首反引号写路径规则(几个用、隔开);后面可以加 改到 `文字`(正则):这些文件增删的行里有这段文字才算。
|
|
4
|
+
// ## 怎么查:命中时要做的检查。
|
|
5
|
+
// ## 来由:哪次出的事(分支、提交、事故),说明为什么有这条。
|
|
6
|
+
// 从分叉点那一版读清单:分支里新加的条目合并后才生效,删了、改了的这次照旧按原来的提醒。
|
|
7
|
+
// 按这次改了的文件挑出命中的条目,提醒 agent 按"怎么查"查一遍。只是提醒:不要求写下怎么查的,也没有人核对查没查。
|
|
8
|
+
|
|
9
|
+
import { basename } from 'node:path'
|
|
10
|
+
import type { Snapshot } from './change.ts'
|
|
11
|
+
import { CHECKLIST_DIR, TESTCRAFT_DIR } from './config.ts'
|
|
12
|
+
import { matchesAny } from '../base/glob.ts'
|
|
13
|
+
import { type Change, diffLines, fileAt, fileNow, filesAt } from '../base/git.ts'
|
|
14
|
+
|
|
15
|
+
/** 行首的文件:一个或几个反引号括起来的路径,用、或逗号隔开。 */
|
|
16
|
+
const LEADING_FILES = /^`[^`]+`(?:\s*[、,,]\s*`[^`]+`)*/
|
|
17
|
+
|
|
18
|
+
/** 清单的条目:清单目录下一层的 .md 文件,一个文件一条。改名成别的扩展名、挪进子目录,就不再是条目。 */
|
|
19
|
+
export function isChecklistItem(path: string): boolean {
|
|
20
|
+
return path.startsWith(`${CHECKLIST_DIR}/`) && /^[^/]+\.md$/.test(path.slice(CHECKLIST_DIR.length + 1))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Trigger {
|
|
24
|
+
paths: string[]
|
|
25
|
+
/** 这些文件增删的行里要有的文字(正则);不写就是改到这些文件就算。 */
|
|
26
|
+
text?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Item {
|
|
30
|
+
id: string
|
|
31
|
+
file: string
|
|
32
|
+
title: string
|
|
33
|
+
triggers: Trigger[]
|
|
34
|
+
check: string
|
|
35
|
+
origin: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Parsed {
|
|
39
|
+
items: Item[]
|
|
40
|
+
problems: string[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const TEXT_AFTER = /^\s*改到\s*`([^`]+)`\s*$/
|
|
44
|
+
|
|
45
|
+
export function parseItem(file: string, text: string): { item: Item } | { problems: string[] } {
|
|
46
|
+
const problems: string[] = []
|
|
47
|
+
const title = /^#\s+(.+?)\s*$/m.exec(text)?.[1] ?? ''
|
|
48
|
+
if (!title) problems.push(`${file} 没有标题(# 后面写要守的事)`)
|
|
49
|
+
const sections = new Map<string, string[]>()
|
|
50
|
+
let section = ''
|
|
51
|
+
for (const line of text.split('\n')) {
|
|
52
|
+
const heading = /^#{2,}\s*(.+?)\s*$/.exec(line)
|
|
53
|
+
if (heading) {
|
|
54
|
+
section = heading[1] as string
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
const name = ['触发', '怎么查', '来由'].find(key => section.includes(key))
|
|
58
|
+
if (name) sections.set(name, [...(sections.get(name) ?? []), line])
|
|
59
|
+
}
|
|
60
|
+
const triggers: Trigger[] = []
|
|
61
|
+
for (const line of sections.get('触发') ?? []) {
|
|
62
|
+
const bullet = /^\s*[-*]\s+(.*)$/.exec(line)
|
|
63
|
+
if (!bullet) continue
|
|
64
|
+
const body = bullet[1] as string
|
|
65
|
+
const leading = LEADING_FILES.exec(body)
|
|
66
|
+
if (!leading) {
|
|
67
|
+
problems.push(`${file} 的触发条件"${body}"没写路径(行首用反引号括起来)`)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
const paths = [...leading[0].matchAll(/`([^`]+)`/g)].map(match => match[1] as string)
|
|
71
|
+
const rest = body.slice(leading[0].length)
|
|
72
|
+
if (rest.trim() === '') {
|
|
73
|
+
triggers.push({ paths })
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
const after = TEXT_AFTER.exec(rest)
|
|
77
|
+
if (!after) {
|
|
78
|
+
problems.push(`${file} 的触发条件"${body}"看不懂:路径后面只能写 改到 \`文字\``)
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
new RegExp(after[1] as string)
|
|
83
|
+
triggers.push({ paths, text: after[1] as string })
|
|
84
|
+
} catch (error) {
|
|
85
|
+
problems.push(`${file} 的触发条件里 \`${after[1]}\` 不是合法的正则:${(error as Error).message}`)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (triggers.length === 0 && !problems.some(problem => problem.includes('触发条件'))) problems.push(`${file} 没写触发条件("## 触发"下每行一条)`)
|
|
89
|
+
const prose = (name: string): string =>
|
|
90
|
+
(sections.get(name) ?? [])
|
|
91
|
+
.map(line => line.trim())
|
|
92
|
+
.filter(Boolean)
|
|
93
|
+
.join('\n')
|
|
94
|
+
const check = prose('怎么查')
|
|
95
|
+
const origin = prose('来由')
|
|
96
|
+
if (check.length < 4) problems.push(`${file} 没写怎么查("## 怎么查")`)
|
|
97
|
+
if (origin.length < 4) problems.push(`${file} 没写来由("## 来由":哪次出的事)`)
|
|
98
|
+
if (problems.length) return { problems }
|
|
99
|
+
return { item: { id: basename(file, '.md'), file, title, triggers, check, origin } }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseAll(files: Array<{ file: string; text: string | undefined }>): Parsed {
|
|
103
|
+
const parsed: Parsed = { items: [], problems: [] }
|
|
104
|
+
for (const { file, text } of files) {
|
|
105
|
+
if (text === undefined) continue
|
|
106
|
+
const result = parseItem(file, text)
|
|
107
|
+
if ('item' in result) parsed.items.push(result.item)
|
|
108
|
+
else parsed.problems.push(...result.problems)
|
|
109
|
+
}
|
|
110
|
+
return parsed
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 分叉点上的清单:这次改动按它提醒(分支上加的、删改的条目合并后才生效)。 */
|
|
114
|
+
export function baseChecklist(s: Snapshot): Parsed {
|
|
115
|
+
const files = filesAt(s.root, s.base, CHECKLIST_DIR).filter(isChecklistItem)
|
|
116
|
+
return parseAll(files.map(file => ({ file, text: fileAt(s.root, s.base, file) })))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 这次改动加的、改的条目:要写得对,合并后才用得上。分叉点上原有、这次没动的不在这里查。 */
|
|
120
|
+
export function changedChecklist(s: Snapshot): Parsed {
|
|
121
|
+
const files = s.changes.filter(change => change.status !== 'D' && isChecklistItem(change.path)).map(change => change.path)
|
|
122
|
+
return parseAll(files.map(file => ({ file, text: fileNow(s.root, file) })))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface Hit {
|
|
126
|
+
item: Item
|
|
127
|
+
/** 这次改了的、触发了它的文件。 */
|
|
128
|
+
paths: string[]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 这次改了的文件里,命中各条目触发条件的。testcraft 自己的文件(记录、清单、配置)不算;从别处改名挪进 .testcraft/ 的照旧按原来的路径算。 */
|
|
132
|
+
export function hitsOf(s: Snapshot, items: Item[]): Hit[] {
|
|
133
|
+
const ours = (path: string | undefined): boolean => path === undefined || path.startsWith(`${TESTCRAFT_DIR}/`)
|
|
134
|
+
const changes = s.changes.filter(change => !(ours(change.path) && ours(change.oldPath)))
|
|
135
|
+
const lines = new Map<string, string[]>()
|
|
136
|
+
const changedLines = (change: Change): string[] => {
|
|
137
|
+
let cached = lines.get(change.path)
|
|
138
|
+
if (!cached) {
|
|
139
|
+
const diff = diffLines(s.root, s.base, change)
|
|
140
|
+
cached = [...diff.added.map(line => line.text), ...diff.removed]
|
|
141
|
+
lines.set(change.path, cached)
|
|
142
|
+
}
|
|
143
|
+
return cached
|
|
144
|
+
}
|
|
145
|
+
const fires = (trigger: Trigger, change: Change): boolean => {
|
|
146
|
+
if (!matchesAny(change.path, trigger.paths) && !(change.oldPath !== undefined && matchesAny(change.oldPath, trigger.paths))) return false
|
|
147
|
+
if (trigger.text === undefined) return true
|
|
148
|
+
const pattern = new RegExp(trigger.text)
|
|
149
|
+
return changedLines(change).some(line => pattern.test(line))
|
|
150
|
+
}
|
|
151
|
+
const hits: Hit[] = []
|
|
152
|
+
for (const item of items) {
|
|
153
|
+
const paths = changes.filter(change => item.triggers.some(trigger => fires(trigger, change))).map(change => change.path)
|
|
154
|
+
if (paths.length) hits.push({ item, paths })
|
|
155
|
+
}
|
|
156
|
+
return hits
|
|
157
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// testcraft 的命令:checklist、status。命令入口(src/testcraft.ts)分发到这里。
|
|
2
|
+
// checklist 也是整组里的一段(见 full.ts):落地前把这次命中的条目再说一遍,这次加、改的条目写坏了的不让过。
|
|
3
|
+
|
|
4
|
+
import { readdirSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { EXIT } from '../base/exit.ts'
|
|
7
|
+
import { openRepo } from '../base/repo.ts'
|
|
8
|
+
import { open, type Snapshot } from './change.ts'
|
|
9
|
+
import { baseChecklist, changedChecklist, hitsOf } from './checklist.ts'
|
|
10
|
+
import { CHECKLIST_DIR, RULES_DIR } from './config.ts'
|
|
11
|
+
|
|
12
|
+
const USAGE = `用法:
|
|
13
|
+
testcraft checklist 清单(.testcraft/checklist/)里这次改动命中的条目和各条怎么查:按条目查一遍。
|
|
14
|
+
这次加、改的条目写得不对的会指出来,没改对不算通过(testpace full 里的一段,接入了的仓库自动跑)
|
|
15
|
+
testcraft status 这次改动命中的清单条目、暂定的规则`
|
|
16
|
+
|
|
17
|
+
/** 退出码用底座的:0 通过;1 没通过;2 用法、配置或环境问题。 */
|
|
18
|
+
|
|
19
|
+
function snapshot(): Snapshot | number {
|
|
20
|
+
const repo = openRepo(process.cwd())
|
|
21
|
+
if (!repo) {
|
|
22
|
+
console.error('testcraft 要在 git 仓库里运行。')
|
|
23
|
+
return EXIT.usage
|
|
24
|
+
}
|
|
25
|
+
const opened = open(repo.root)
|
|
26
|
+
if ('problem' in opened) {
|
|
27
|
+
if (opened.code === 'notJoined') {
|
|
28
|
+
console.log(`${opened.problem},不检查。`)
|
|
29
|
+
return EXIT.ok
|
|
30
|
+
}
|
|
31
|
+
console.error(`没法检查:${opened.problem}`)
|
|
32
|
+
return EXIT.usage
|
|
33
|
+
}
|
|
34
|
+
return opened.snapshot
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 清单:列出这次命中的条目和各条怎么查,返回退出码。只是提醒,命中了不算没通过。
|
|
39
|
+
* 这次加、改的条目写坏了的,没通过(合并后要用得上)。分叉点上原有、写坏了的条目只提醒:不是这次改动的事,不拦。
|
|
40
|
+
*/
|
|
41
|
+
function checklist(s: Snapshot): number {
|
|
42
|
+
const base = baseChecklist(s)
|
|
43
|
+
const changed = changedChecklist(s)
|
|
44
|
+
const hits = hitsOf(s, base.items)
|
|
45
|
+
const lines: string[] = []
|
|
46
|
+
if (base.items.length === 0) lines.push(base.problems.length ? '清单:分叉点上的条目都写得不对,这次没法按它们提醒。' : `清单:分叉点上没有条目(${CHECKLIST_DIR}/)。`)
|
|
47
|
+
else if (hits.length === 0) lines.push(`清单:${base.items.length} 条,这次改动一条也没命中。`)
|
|
48
|
+
else {
|
|
49
|
+
lines.push(`清单:这次改动命中 ${hits.length} 条,按"怎么查"逐条查一遍,查出问题就改好:`)
|
|
50
|
+
for (const hit of hits) {
|
|
51
|
+
lines.push(
|
|
52
|
+
` · ${hit.item.id}:${hit.item.title}`,
|
|
53
|
+
` 改到了:${hit.paths.slice(0, 5).join('、')}${hit.paths.length > 5 ? ` 等 ${hit.paths.length} 个` : ''}`,
|
|
54
|
+
...hit.item.check.split('\n').map((line, index) => ` ${index === 0 ? '怎么查:' : ' '}${line}`),
|
|
55
|
+
` 来由:${hit.item.origin.split('\n').join(' ')}`,
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (base.problems.length) lines.push('', '分叉点上这几条写得不对,这次没按它们提醒(不拦这次改动,另找时间修好):', ...base.problems.map(problem => ` · ${problem}`))
|
|
60
|
+
if (changed.problems.length) lines.push('', '这次加、改的条目写得不对(合并后要用得上):', ...changed.problems.map(problem => ` ✗ ${problem}`))
|
|
61
|
+
console.log(lines.join('\n'))
|
|
62
|
+
return changed.problems.length ? EXIT.fail : EXIT.ok
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function status(s: Snapshot): number {
|
|
66
|
+
const lines: string[] = [`和 ${s.branch} 的分叉点 ${s.base.slice(0, 8)} 比,这次改了 ${s.changes.length} 个文件。`]
|
|
67
|
+
const base = baseChecklist(s)
|
|
68
|
+
if (base.items.length) {
|
|
69
|
+
const hits = hitsOf(s, base.items)
|
|
70
|
+
lines.push(`清单(${CHECKLIST_DIR}/):${base.items.length} 条,这次命中 ${hits.length} 条${hits.length ? `:${hits.map(hit => hit.item.id).join('、')}(testcraft checklist 列出怎么查)` : ''}`)
|
|
71
|
+
} else lines.push('清单:没有条目')
|
|
72
|
+
const rules = listRules(s.root)
|
|
73
|
+
lines.push(rules.length ? `暂定的规则和记过的 bug(${RULES_DIR}/):\n${rules.map(rule => ` - ${rule}`).join('\n')}` : '暂定的规则和记过的 bug:没有')
|
|
74
|
+
console.log(lines.join('\n'))
|
|
75
|
+
return EXIT.ok
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function listRules(root: string): string[] {
|
|
79
|
+
try {
|
|
80
|
+
return readdirSync(join(root, RULES_DIR))
|
|
81
|
+
.filter(name => name.endsWith('.md'))
|
|
82
|
+
.sort()
|
|
83
|
+
.map(name => {
|
|
84
|
+
const text = readFileSync(join(root, RULES_DIR, name), 'utf8')
|
|
85
|
+
const title = /^#\s+(.+)$/m.exec(text)?.[1] ?? name
|
|
86
|
+
return `${name.replace(/\.md$/, '')}:${title}`
|
|
87
|
+
})
|
|
88
|
+
} catch {
|
|
89
|
+
return []
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function main(argv: string[]): number {
|
|
94
|
+
switch (argv[0]) {
|
|
95
|
+
case 'checklist':
|
|
96
|
+
case 'status': {
|
|
97
|
+
const s = snapshot()
|
|
98
|
+
if (typeof s === 'number') return s
|
|
99
|
+
return argv[0] === 'checklist' ? checklist(s) : status(s)
|
|
100
|
+
}
|
|
101
|
+
case undefined:
|
|
102
|
+
case '-h':
|
|
103
|
+
case '--help':
|
|
104
|
+
case 'help':
|
|
105
|
+
console.log(USAGE)
|
|
106
|
+
return argv[0] === undefined ? EXIT.usage : EXIT.ok
|
|
107
|
+
default:
|
|
108
|
+
console.error(`不认识的命令:${argv[0]}\n${USAGE}`)
|
|
109
|
+
return EXIT.usage
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// "测试写法"在项目里的东西:.testcraft/ 目录下的清单(checklist/)和暂定的规则(rules/)。没有这个目录的仓库没接入。
|
|
2
|
+
// 它不检查测试写得好不好,也不让 agent 写任何证明:写测试的约定在 write-tests 技能里,这里只管清单的提醒。
|
|
3
|
+
|
|
4
|
+
import { existsSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { hasFile } from '../base/git.ts'
|
|
7
|
+
|
|
8
|
+
export const TESTCRAFT_DIR = '.testcraft'
|
|
9
|
+
export const RULES_DIR = `${TESTCRAFT_DIR}/rules`
|
|
10
|
+
export const CHECKLIST_DIR = `${TESTCRAFT_DIR}/checklist`
|
|
11
|
+
|
|
12
|
+
/** 接入了:分叉点或工作区里有 .testcraft/。 */
|
|
13
|
+
export function joined(root: string, fork?: string): boolean {
|
|
14
|
+
return existsSync(join(root, TESTCRAFT_DIR)) || (fork !== undefined && hasFile(root, fork, TESTCRAFT_DIR))
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// 整组里"测试写法"的部分(base/module.ts 的 fullPart):接入了的仓库在测试之前跑一次 testcraft checklist,
|
|
2
|
+
// 落地前把这次命中的清单条目再说一遍;这次加、改的条目写坏了的不让过。不跑测试,只读文件。
|
|
3
|
+
// 它随插件一起装,不用在本机另外登记;没接入的仓库没有这一段。
|
|
4
|
+
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { quoted } from '../base/execute.ts'
|
|
7
|
+
import { forkPoint } from '../base/git.ts'
|
|
8
|
+
import type { FullPart } from '../base/module.ts'
|
|
9
|
+
import type { Repo } from '../base/repo.ts'
|
|
10
|
+
import { joined } from './config.ts'
|
|
11
|
+
|
|
12
|
+
/** 这个插件里的 testcraft 命令:用完整路径,不靠 PATH 上碰巧有哪一版。 */
|
|
13
|
+
const BIN = fileURLToPath(new URL('../../bin/testcraft', import.meta.url))
|
|
14
|
+
|
|
15
|
+
export function fullPart(repo: Repo): FullPart {
|
|
16
|
+
// 按分叉点也算接入:这次删掉 .testcraft/ 的,照旧按原来的清单提醒
|
|
17
|
+
if (!joined(repo.root, forkPoint(repo.root).commit)) return { steps: [] }
|
|
18
|
+
return {
|
|
19
|
+
steps: [
|
|
20
|
+
{
|
|
21
|
+
kind: 'craft',
|
|
22
|
+
name: '清单(testcraft checklist)',
|
|
23
|
+
title: '清单(testcraft checklist)',
|
|
24
|
+
header: '清单:testcraft checklist',
|
|
25
|
+
command: `${quoted(BIN)} checklist`,
|
|
26
|
+
args: [],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// "测试写法"这个模块交给底座的入口(见 base/module.ts):底座只通过这里知道它。
|
|
2
|
+
// 它在项目里的配置是 .testcraft/ 目录,没有这个目录的仓库里它不出声、不加检查。
|
|
3
|
+
|
|
4
|
+
import type { Module } from '../base/module.ts'
|
|
5
|
+
import { fullPart } from './full.ts'
|
|
6
|
+
import { brief } from './session.ts'
|
|
7
|
+
|
|
8
|
+
export const craft: Module = {
|
|
9
|
+
name: 'craft',
|
|
10
|
+
brief,
|
|
11
|
+
fullPart,
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// "测试写法"说给 agent 的话,经底座的钩子送出去(base/module.ts 的 brief):会话开始时说几句写测试的约定。
|
|
2
|
+
// 没有停止门:加测试、删测试、改到清单条目,收尾时都不拦。清单在落地前的整组里提醒(见 full.ts),平时用 testcraft checklist 看。
|
|
3
|
+
// 这里没有"证明测试管用""复查测试"这类检查:测试写得好不好靠写测试的约定,不靠再起一轮核对。
|
|
4
|
+
|
|
5
|
+
import type { Repo } from '../base/repo.ts'
|
|
6
|
+
import { joined } from './config.ts'
|
|
7
|
+
|
|
8
|
+
export function guide(label = '这个仓库'): string[] {
|
|
9
|
+
return [
|
|
10
|
+
`${label}用 testcraft 管测试的写法(.testcraft/):`,
|
|
11
|
+
'1. 什么时候写:分支上开发时不写新测试、不改已有的测试(需求还在试),做完告诉用户做完了、测试还没写。用户说要合并这个分支时才写:把这次定下来的规则用白话一条条列出来,交给一个子代理照 gatelight:write-tests 技能写新测试、改掉因为需求变了而不过的旧测试(没有起子代理的工具就自己写),跑通、提交,再合。例外,当场做:修已合进默认分支的规则的 bug,先写能重现它的测试再修。',
|
|
12
|
+
'2. 写哪些:小改动(文字、样式、注释、显示用的配置)不写。必跑层:钱、权限、状态与数据(什么状态下能做、数据会不会错)写在接口层、测透,每个功能留主流程的页面测试。细节层:界面细节、样式、提示文字这类人容易漏看的,也值得写。修过的 bug 留一条能重现它的测试。在页面上重复验证接口层守着的规则不写。',
|
|
13
|
+
'3. 已定的业务规则(合进默认分支的)以测试名为准。要改已定的业务规则(包括为此删测试、让测试不跑、改期望值),先用白话问用户,用户同意了再改;用户这次自己提出要改的不用再问。测试上别的调整(跟着代码改接法、换写法、挪位置、删重复的)自己定,不问用户,也不用写说明。',
|
|
14
|
+
'4. 改动命中 .testcraft/checklist/ 里条目的触发条件时(testcraft checklist 列出,落地前的整组里也会说一遍),按条目查一遍,查出问题就改好。修 bug 时,写不成测试、又能从改动看出来的坑,加一条清单。',
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 会话说明:接入了"测试写法"的仓库才说。 */
|
|
19
|
+
export function brief(label: string, repo?: Repo): string[] {
|
|
20
|
+
return repo && joined(repo.root) ? guide(label) : []
|
|
21
|
+
}
|
package/src/mcp.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 确认工具的 MCP 服务:只有一个工具 confirm_with_user,把检查要用户同意的改动给用户确认。
|
|
2
|
+
// 工具标了 anthropic/requiresUserInteraction:Claude Code 每次都弹窗,任何权限模式、允许规则都跳不过,
|
|
3
|
+
// 用户在弹窗里看到 text 的原文(检查写好的白话),同意了工具才会执行、记下确认。用标准输入输出收发一行一条的 JSON-RPC。
|
|
4
|
+
// Antigravity 不认这个标记:它从插件根上的 mcp_config.json 起这个服务,每次调用前由插件的 hook 输出 force_ask 弹窗(hookformat.ts),
|
|
5
|
+
// "总是允许"在那个弹窗里选不了;hook 出错时拒绝这次调用(hooks/antigravity.sh)。
|
|
6
|
+
// 这个进程跟着会话开着,插件更新了也不换代码,所以工具只认检查存下的编号和文字(见 base/confirm.ts),不引用任何模块、不做判断。
|
|
7
|
+
|
|
8
|
+
import { createInterface } from 'node:readline'
|
|
9
|
+
import { confirm, CONFIRM_TOOL } from './base/confirm.ts'
|
|
10
|
+
import { PLUGIN_NAME, VERSION } from './base/version.ts'
|
|
11
|
+
|
|
12
|
+
const TOOL = {
|
|
13
|
+
name: CONFIRM_TOOL,
|
|
14
|
+
description:
|
|
15
|
+
'把检查要求用户同意的改动(放松了测试、放宽了规则这类)给用户确认:弹窗里用户看到每一项,同意后才记下。只在 testpace 的检查要求时调用;repo、id、text 都照检查输出的原样填,text 一字不改。调用前先在对话里用白话向用户讲清每一项原来是什么样、现在是什么样、为什么。',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
repo: { type: 'string', description: '仓库路径,照检查输出的填' },
|
|
20
|
+
id: { type: 'string', description: '编号,照检查输出的填' },
|
|
21
|
+
text: { type: 'string', description: '给用户确认的文字,照检查输出的原样填,一字不改' },
|
|
22
|
+
},
|
|
23
|
+
required: ['repo', 'id', 'text'],
|
|
24
|
+
},
|
|
25
|
+
_meta: { 'anthropic/requiresUserInteraction': true },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Request {
|
|
29
|
+
jsonrpc: '2.0'
|
|
30
|
+
id?: number | string
|
|
31
|
+
method: string
|
|
32
|
+
params?: Record<string, unknown>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function reply(id: Request['id'], body: { result: unknown } | { error: { code: number; message: string } }): void {
|
|
36
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, ...body })}\n`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function handle(request: Request): void {
|
|
40
|
+
// 通知(没有 id)不用回
|
|
41
|
+
if (request.id === undefined) return
|
|
42
|
+
const params = request.params ?? {}
|
|
43
|
+
switch (request.method) {
|
|
44
|
+
case 'initialize':
|
|
45
|
+
return reply(request.id, {
|
|
46
|
+
result: {
|
|
47
|
+
protocolVersion: typeof params.protocolVersion === 'string' ? params.protocolVersion : '2025-06-18',
|
|
48
|
+
capabilities: { tools: {} },
|
|
49
|
+
serverInfo: { name: PLUGIN_NAME, version: VERSION },
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
case 'ping':
|
|
53
|
+
return reply(request.id, { result: {} })
|
|
54
|
+
case 'tools/list':
|
|
55
|
+
return reply(request.id, { result: { tools: [TOOL] } })
|
|
56
|
+
case 'tools/call': {
|
|
57
|
+
const args = (params.arguments ?? {}) as Record<string, unknown>
|
|
58
|
+
if (params.name !== TOOL.name) return reply(request.id, { error: { code: -32602, message: `没有这个工具:${String(params.name)}` } })
|
|
59
|
+
if (typeof args.repo !== 'string' || typeof args.id !== 'string' || typeof args.text !== 'string') {
|
|
60
|
+
return reply(request.id, { result: { content: [{ type: 'text', text: 'repo、id、text 都要填文字' }], isError: true } })
|
|
61
|
+
}
|
|
62
|
+
const confirmed = confirm(args.repo, args.id, args.text)
|
|
63
|
+
return reply(request.id, { result: { content: [{ type: 'text', text: confirmed.text }], isError: !confirmed.ok } })
|
|
64
|
+
}
|
|
65
|
+
default:
|
|
66
|
+
return reply(request.id, { error: { code: -32601, message: `不支持 ${request.method}` } })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
createInterface({ input: process.stdin }).on('line', line => {
|
|
71
|
+
if (line.trim() === '') return
|
|
72
|
+
let request: Request
|
|
73
|
+
try {
|
|
74
|
+
request = JSON.parse(line) as Request
|
|
75
|
+
} catch {
|
|
76
|
+
return reply(undefined, { error: { code: -32700, message: '不是合法的 JSON' } })
|
|
77
|
+
}
|
|
78
|
+
handle(request)
|
|
79
|
+
})
|
package/src/modules.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// 装配:把这个插件里的检查模块登记给底座。命令行入口(cli.ts、testcraft.ts、modwall.ts)、钩子入口(hooks/testpace.ts)和测试都先引用这个文件。
|
|
2
|
+
// 底座(base/)不引用模块,模块之间也不互相引用;知道有哪些模块的只有这里。
|
|
3
|
+
// 顺序就是整组里各段的先后(检查在前、全部测试在后)和会话说明里各模块的先后。
|
|
4
|
+
|
|
5
|
+
import { registerModules } from './base/module.ts'
|
|
6
|
+
import { craft } from './craft/index.ts'
|
|
7
|
+
import { pace } from './pace/index.ts'
|
|
8
|
+
import { wall } from './wall/index.ts'
|
|
9
|
+
|
|
10
|
+
registerModules([wall, craft, pace])
|
package/src/modwall.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// modwall 命令行入口:init、check、db check、status(实现在 wall/commands.ts)。
|
|
2
|
+
// 这个文件的路径不能变:bin/modwall 和整组里"模块边界"的那一段按它找。
|
|
3
|
+
|
|
4
|
+
import './modules.ts'
|
|
5
|
+
import { runCommandLine } from './base/commandline.ts'
|
|
6
|
+
import { main, outside } from './wall/commands.ts'
|
|
7
|
+
|
|
8
|
+
process.exitCode = await runCommandLine({ name: 'modwall', outside, run: main }, process.argv.slice(2))
|