gatelight 0.18.0 → 0.18.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatelight",
3
3
  "displayName": "gatelight",
4
- "version": "0.18.0",
4
+ "version": "0.18.1",
5
5
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, plus test-writing conventions and a change-triggered checklist",
6
6
  "author": {
7
7
  "name": "coffeecoproject"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatelight",
3
3
  "displayName": "gatelight",
4
- "version": "0.18.0",
4
+ "version": "0.18.1",
5
5
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, plus test-writing conventions and a change-triggered checklist",
6
6
  "author": {
7
7
  "name": "coffeecoproject"
@@ -0,0 +1,10 @@
1
+ {
2
+ "mcpServers": {
3
+ "gatelight": {
4
+ "command": "sh",
5
+ "args": ["./.codex-plugin/mcp.sh"],
6
+ "cwd": ".",
7
+ "default_tools_approval_mode": "approve"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ # Codex 起确认工具服务的入口(.codex-plugin/mcp.json):Codex 起服务的环境里不一定有能运行 TypeScript 的 node,先找一个,
3
+ # 再起 src/mcp.ts(参数 codex:服务自己向 Codex 发表单问用户)。找不到 node 时说一声、退出,Codex 里就没有这个工具。
4
+ dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
5
+ . "$dir/bin/node.sh"
6
+ node=$(testpace_node) || { echo "gatelight 的确认工具没有启动:找不到 22.18 以上的 node(要能直接运行 TypeScript)。装一个,或用 TESTPACE_NODE 指给它。" >&2; exit 1; }
7
+ exec "$node" --disable-warning=ExperimentalWarning "$dir/src/mcp.ts" codex
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatelight",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, plus test-writing conventions and a change-triggered checklist",
5
5
  "author": {
6
6
  "name": "coffeecoproject"
@@ -8,6 +8,7 @@
8
8
  "license": "MIT",
9
9
  "keywords": ["testing", "test selection", "merge gate", "test quality", "module boundaries", "coding agent"],
10
10
  "hooks": "./hooks/codex.json",
11
+ "mcpServers": "./.codex-plugin/mcp.json",
11
12
  "skills": "./skills/",
12
13
  "interface": {
13
14
  "displayName": "gatelight",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatelight",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, plus test-writing conventions and a change-triggered checklist",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/coffeecoproject/gatelight#readme",
@@ -1,12 +1,12 @@
1
1
  // 用户确认:检查里有要用户同意的改动(放松了测试、放宽了规则)时,模块把条目交到这里,不自己弹窗、不自己存同意记录。
2
2
  // 同意只能来自确认工具(src/mcp.ts 的 confirm_with_user):每次调用都要用户在弹窗里同意(Claude Code 靠工具上的标记,
3
- // Antigravity 靠 hook 的 force_ask),agent 自己说"用户同意了"不算。
3
+ // Antigravity 靠 hook 的 force_ask,Codex 靠服务自己向客户端发的表单),agent 自己说"用户同意了"不算。
4
4
  //
5
5
  // 同意按项记:一项是"哪个模块的、改之前是什么、改成什么、用户当时看到的文字",四样都一样才是同一项。
6
6
  // 几个分支合到一起,没再动过的那一项不用重新确认;文字相同但改之前的内容不同,是另一项,要重新确认。
7
7
  //
8
8
  // 两步:检查(askUser)把还没同意的条目按编号存好,输出编号和弹窗文字让 agent 去调工具;
9
- // 工具(confirm)只按编号取存下的内容,核对传来的文字一字不差,记下同意。工具进程跟着会话开着、插件更新后还是旧代码,
9
+ // 工具(check、record)只按编号取存下的内容,核对传来的文字一字不差,用户同意了再记下。工具进程跟着会话开着、插件更新后还是旧代码,
10
10
  // 所以它不打开改动、不做任何判断。
11
11
  //
12
12
  // 记录在 .git/testpace/confirm/ 下(所有 worktree 共用):pending.json 等用户过目的,confirmed.json 用户同意过的。
@@ -135,11 +135,21 @@ export interface Confirmed {
135
135
  /** 编号是 32 位十六进制。 */
136
136
  const ID = /^[0-9a-f]{32}$/
137
137
 
138
- /** 确认工具调:核对传来的文字就是检查给这个编号存下的弹窗内容,记下用户同意了里面的每一项。 */
139
- export function confirm(repoPath: string, id: string, text: string): Confirmed {
138
+ /** 核对通过、还没记下的一次确认:popup 是检查给这个编号存下的弹窗文字,用户同意了再调 record。 */
139
+ export interface Checked {
140
+ ok: true
141
+ popup: string
142
+ record: () => Confirmed
143
+ }
144
+
145
+ /**
146
+ * 只核对、不记:编号和文字对得上时返回存下的弹窗文字和记下同意的办法。
147
+ * 工具自己问用户的 agent(Codex:服务向客户端发表单)先核对再问,用户同意了才 record;对不上的不问用户。
148
+ */
149
+ export function check(repoPath: string, id: string, text: string): Checked | { ok: false; text: string } {
140
150
  const root = existsSync(repoPath) ? repoRoot(repoPath) : undefined
141
- if (!root) return { ok: false, text: `${repoPath} 不在 git 仓库里` }
142
- const missing = { ok: false, text: '没有这个编号要确认的内容:重跑要求确认的那条检查,照它输出的编号和文字填。' }
151
+ if (!root) return { ok: false as const, text: `${repoPath} 不在 git 仓库里` }
152
+ const missing = { ok: false as const, text: '没有这个编号要确认的内容:重跑要求确认的那条检查,照它输出的编号和文字填。' }
143
153
  if (!ID.test(id)) return missing
144
154
  const store = new Store(commonDir(root))
145
155
  // 编号是外面传来的:模块记录只取文件里这个键自己的
@@ -154,8 +164,14 @@ export function confirm(repoPath: string, id: string, text: string): Confirmed {
154
164
  if (plain(text) !== plain(pending.text)) {
155
165
  return { ok: false, text: '传来的文字和检查给这个编号的不一致:照它输出的原样填,不要改写、增删。' }
156
166
  }
157
- const records = confirmedOf(store)
158
- const at = Date.now()
159
- for (const item of pending.items) records.put(item.key, { module: pending.module, text: item.text, at })
160
- return { ok: true, text: `已记下:用户确认并同意了这 ${pending.items.length} 项。再跑一次要求确认的那条检查。` }
167
+ return {
168
+ ok: true,
169
+ popup: pending.text,
170
+ record: () => {
171
+ const records = confirmedOf(store)
172
+ const at = Date.now()
173
+ for (const item of pending.items) records.put(item.key, { module: pending.module, text: item.text, at })
174
+ return { ok: true, text: `已记下:用户确认并同意了这 ${pending.items.length} 项。再跑一次要求确认的那条检查。` }
175
+ },
176
+ }
161
177
  }
package/src/mcp.ts CHANGED
@@ -1,14 +1,20 @@
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)。
1
+ // 确认工具的 MCP 服务:只有一个工具 confirm_with_user,把检查要用户同意的改动给用户确认。用标准输入输出收发一行一条的 JSON-RPC。
2
+ // 三个 agent 怎么保证每次都是用户本人在弹窗里同意(用户看到的都是检查存下的原文,同意了工具才记下):
3
+ // - Claude Code:工具标了 anthropic/requiresUserInteraction,每次都弹窗,任何权限模式、允许规则都跳不过。
4
+ // - Antigravity:不认这个标记。它从插件根上的 mcp_config.json 起这个服务,每次调用前由插件的 hook 输出 force_ask 弹窗(hookformat.ts),
5
+ // "总是允许"在那个弹窗里选不了;hook 出错时拒绝这次调用(hooks/antigravity.sh)。
6
+ // - Codex:也不认这个标记,hook 也要不了弹窗,工具审批还可能交给自动审查(AI)。它从 .codex-plugin/mcp.json 起这个服务、
7
+ // 参数带 codex:服务核对编号和文字后,自己向 Codex 发一张表单(MCP 的 elicitation),表单到用户面前、用户点同意才记下;
8
+ // 拒绝、取消(不能交互的 codex exec 直接取消)都不记。不支持表单的客户端不记,说明原因。
6
9
  // 这个进程跟着会话开着,插件更新了也不换代码,所以工具只认检查存下的编号和文字(见 base/confirm.ts),不引用任何模块、不做判断。
7
10
 
8
11
  import { createInterface } from 'node:readline'
9
- import { confirm, CONFIRM_TOOL } from './base/confirm.ts'
12
+ import { check, CONFIRM_TOOL, type Confirmed } from './base/confirm.ts'
10
13
  import { PLUGIN_NAME, VERSION } from './base/version.ts'
11
14
 
15
+ /** 服务自己向客户端发表单问用户(Codex):启动参数里带 codex。 */
16
+ const ASK_BY_FORM = process.argv.slice(2).includes('codex')
17
+
12
18
  const TOOL = {
13
19
  name: CONFIRM_TOOL,
14
20
  description:
@@ -25,55 +31,108 @@ const TOOL = {
25
31
  _meta: { 'anthropic/requiresUserInteraction': true },
26
32
  }
27
33
 
28
- interface Request {
34
+ type Id = number | string
35
+
36
+ interface Message {
29
37
  jsonrpc: '2.0'
30
- id?: number | string
31
- method: string
38
+ id?: Id
39
+ method?: string
32
40
  params?: Record<string, unknown>
41
+ result?: Record<string, unknown>
42
+ error?: { code: number; message: string }
43
+ }
44
+
45
+ function send(message: Record<string, unknown>): void {
46
+ process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', ...message })}\n`)
47
+ }
48
+
49
+ function reply(id: Message['id'], body: { result: unknown } | { error: { code: number; message: string } }): void {
50
+ send({ id, ...body })
51
+ }
52
+
53
+ /** 客户端在 initialize 里说了支持表单(elicitation 的 form;只写了 elicitation 的按老版本,也是表单)。 */
54
+ let formSupported = false
55
+
56
+ /** 服务发给客户端、还在等回答的请求。 */
57
+ const waiting = new Map<Id, (answer: Message) => void>()
58
+ let nextAsk = 0
59
+
60
+ /** 向客户端发表单问用户,返回用户的选择(accept、decline、cancel),客户端出错时是 undefined。 */
61
+ function askByForm(message: string): Promise<string | undefined> {
62
+ const id = `${PLUGIN_NAME}-ask-${++nextAsk}`
63
+ return new Promise(resolve => {
64
+ waiting.set(id, answer => resolve(typeof answer.result?.action === 'string' ? answer.result.action : undefined))
65
+ send({ id, method: 'elicitation/create', params: { message, requestedSchema: { type: 'object', properties: {} } } })
66
+ })
33
67
  }
34
68
 
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`)
69
+ const text = (body: string, isError: boolean) => ({ result: { content: [{ type: 'text', text: body }], isError } })
70
+
71
+ async function callTool(id: Id, args: Record<string, unknown>): Promise<void> {
72
+ if (typeof args.repo !== 'string' || typeof args.id !== 'string' || typeof args.text !== 'string') {
73
+ return reply(id, text('repo、id、text 都要填文字', true))
74
+ }
75
+ const checked = check(args.repo, args.id, args.text)
76
+ if (!checked.ok) return reply(id, text(checked.text, true))
77
+ let done: Confirmed
78
+ if (!ASK_BY_FORM) done = checked.record()
79
+ else if (!formSupported) {
80
+ done = { ok: false, text: '这个客户端不支持向用户弹表单(MCP elicitation),没法让用户本人确认,没有记下。升级客户端,或在 Claude Code 里确认。' }
81
+ } else {
82
+ const action = await askByForm(`${PLUGIN_NAME} 要你确认:\n\n${checked.popup}`)
83
+ done =
84
+ action === 'accept'
85
+ ? checked.record()
86
+ : { ok: false, text: action === 'decline' ? '用户拒绝了,没有记下:照用户的意思改回去或换个做法。' : '用户没有确认(表单取消了或弹不出来,比如不能交互的 codex exec),没有记下。' }
87
+ }
88
+ return reply(id, text(done.text, !done.ok))
37
89
  }
38
90
 
39
- function handle(request: Request): void {
91
+ function handle(message: Message): void {
92
+ // 客户端对服务发出的请求(表单)的回答
93
+ if (message.method === undefined) {
94
+ if (message.id !== undefined) {
95
+ waiting.get(message.id)?.(message)
96
+ waiting.delete(message.id)
97
+ }
98
+ return
99
+ }
40
100
  // 通知(没有 id)不用回
41
- if (request.id === undefined) return
42
- const params = request.params ?? {}
43
- switch (request.method) {
44
- case 'initialize':
45
- return reply(request.id, {
101
+ if (message.id === undefined) return
102
+ const params = message.params ?? {}
103
+ switch (message.method) {
104
+ case 'initialize': {
105
+ const elicitation = (params.capabilities as { elicitation?: { form?: unknown; url?: unknown } } | undefined)?.elicitation
106
+ formSupported = elicitation !== undefined && (elicitation.form !== undefined || elicitation.url === undefined)
107
+ return reply(message.id, {
46
108
  result: {
47
109
  protocolVersion: typeof params.protocolVersion === 'string' ? params.protocolVersion : '2025-06-18',
48
110
  capabilities: { tools: {} },
49
111
  serverInfo: { name: PLUGIN_NAME, version: VERSION },
50
112
  },
51
113
  })
114
+ }
52
115
  case 'ping':
53
- return reply(request.id, { result: {} })
116
+ return reply(message.id, { result: {} })
54
117
  case 'tools/list':
55
- return reply(request.id, { result: { tools: [TOOL] } })
118
+ return reply(message.id, { result: { tools: [TOOL] } })
56
119
  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 } })
120
+ if (params.name !== TOOL.name) return reply(message.id, { error: { code: -32602, message: `没有这个工具:${String(params.name)}` } })
121
+ void callTool(message.id, (params.arguments ?? {}) as Record<string, unknown>)
122
+ return
64
123
  }
65
124
  default:
66
- return reply(request.id, { error: { code: -32601, message: `不支持 ${request.method}` } })
125
+ return reply(message.id, { error: { code: -32601, message: `不支持 ${message.method}` } })
67
126
  }
68
127
  }
69
128
 
70
129
  createInterface({ input: process.stdin }).on('line', line => {
71
130
  if (line.trim() === '') return
72
- let request: Request
131
+ let message: Message
73
132
  try {
74
- request = JSON.parse(line) as Request
133
+ message = JSON.parse(line) as Message
75
134
  } catch {
76
135
  return reply(undefined, { error: { code: -32700, message: '不是合法的 JSON' } })
77
136
  }
78
- handle(request)
137
+ handle(message)
79
138
  })