@christang/keel 5.231.12 → 5.232.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +5 -3
- package/README.zh-CN.md +5 -3
- package/assets/bootstrap/AGENTS.md +2 -2
- package/bin/keel.js +163 -24
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/plugins/keel/hooks.json +23 -0
- package/plugins/keel/plugin.json +10 -0
- package/plugins/keel/scripts/pretooluse-guard.js +42 -1
- package/plugins/keel/scripts/session-start.js +47 -6
- package/scripts/bump_version.js +3 -0
- package/scripts/install_to_repo.py +4 -3
- package/scripts/test_codex_host.js +44 -0
- package/scripts/validation/agy.py +770 -0
- package/scripts/validation/baseline.py +19 -3
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/hosts.py +7 -3
- package/scripts/validation/registry.py +7 -0
- package/src/core/capabilities.js +65 -13
- package/src/core/codex-host.js +18 -11
- package/src/core/gates.js +3 -3
- package/src/core/projection.js +1 -1
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
"""Keel validation: Google Antigravity (AGY) native single-session adapter."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import tempfile
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from validation.common import PACKAGE_VERSION, ROOT, report, run_keel
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _agy_hook_env(home: Path) -> dict[str, str]:
|
|
15
|
+
env = {k: v for k, v in os.environ.items() if not k.startswith(("CLAUDE", "KEEL_"))}
|
|
16
|
+
env["HOME"] = str(home)
|
|
17
|
+
env["KEEL_CLI"] = f'"{shutil.which("node") or "node"}" "{ROOT / "bin" / "keel.js"}"'
|
|
18
|
+
return env
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _init_git_repo(repo: Path) -> None:
|
|
22
|
+
subprocess.run(["git", "init", "-q", "-b", "main"], cwd=repo, check=True)
|
|
23
|
+
subprocess.run(["git", "config", "user.name", "Keel Test"], cwd=repo, check=True)
|
|
24
|
+
subprocess.run(["git", "config", "user.email", "keel@example.com"], cwd=repo, check=True)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def validate_agy_plugin_package_scenario() -> int:
|
|
28
|
+
plugin_root = ROOT / "plugins" / "keel"
|
|
29
|
+
manifest_path = plugin_root / "plugin.json"
|
|
30
|
+
if not manifest_path.is_file():
|
|
31
|
+
report("agy-plugin-package: missing plugins/keel/plugin.json")
|
|
32
|
+
return 1
|
|
33
|
+
try:
|
|
34
|
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
35
|
+
except json.JSONDecodeError as exc:
|
|
36
|
+
report(f"agy-plugin-package: invalid JSON in plugins/keel/plugin.json: {exc}")
|
|
37
|
+
return 1
|
|
38
|
+
if manifest.get("name") != "keel":
|
|
39
|
+
report(f"agy-plugin-package: plugin.json name is {manifest.get('name')!r}, expected 'keel'")
|
|
40
|
+
return 1
|
|
41
|
+
if manifest.get("version") != PACKAGE_VERSION:
|
|
42
|
+
report(
|
|
43
|
+
f"agy-plugin-package: plugin.json version is {manifest.get('version')!r}, "
|
|
44
|
+
f"expected {PACKAGE_VERSION!r}"
|
|
45
|
+
)
|
|
46
|
+
return 1
|
|
47
|
+
|
|
48
|
+
hooks_path = plugin_root / "hooks.json"
|
|
49
|
+
if not hooks_path.is_file():
|
|
50
|
+
report("agy-plugin-package: missing plugins/keel/hooks.json")
|
|
51
|
+
return 1
|
|
52
|
+
try:
|
|
53
|
+
hooks = json.loads(hooks_path.read_text(encoding="utf-8"))
|
|
54
|
+
except json.JSONDecodeError as exc:
|
|
55
|
+
report(f"agy-plugin-package: invalid JSON in plugins/keel/hooks.json: {exc}")
|
|
56
|
+
return 1
|
|
57
|
+
keel_hook = hooks.get("keel")
|
|
58
|
+
if not isinstance(keel_hook, dict):
|
|
59
|
+
report("agy-plugin-package: hooks.json must declare top-level named hook 'keel'")
|
|
60
|
+
return 1
|
|
61
|
+
|
|
62
|
+
session_start = keel_hook.get("SessionStart")
|
|
63
|
+
if not isinstance(session_start, list) or len(session_start) == 0:
|
|
64
|
+
report("agy-plugin-package: hooks.json keel.SessionStart must be a non-empty flat handler list")
|
|
65
|
+
return 1
|
|
66
|
+
ss_handler = session_start[0]
|
|
67
|
+
if not isinstance(ss_handler, dict):
|
|
68
|
+
report("agy-plugin-package: SessionStart handler must be an object")
|
|
69
|
+
return 1
|
|
70
|
+
if "hooks" in ss_handler:
|
|
71
|
+
report("agy-plugin-package: SessionStart must be flat, not grouped with a nested hooks key")
|
|
72
|
+
return 1
|
|
73
|
+
ss_cmd = ss_handler.get("command", "")
|
|
74
|
+
if "./scripts/session-start.js" not in ss_cmd:
|
|
75
|
+
report(f"agy-plugin-package: SessionStart command must use relative ./scripts/session-start.js: {ss_cmd!r}")
|
|
76
|
+
return 1
|
|
77
|
+
if "--host agy" not in ss_cmd:
|
|
78
|
+
report(f"agy-plugin-package: SessionStart command must pass --host agy: {ss_cmd!r}")
|
|
79
|
+
return 1
|
|
80
|
+
|
|
81
|
+
pre_tool = keel_hook.get("PreToolUse")
|
|
82
|
+
if not isinstance(pre_tool, list) or len(pre_tool) == 0:
|
|
83
|
+
report("agy-plugin-package: hooks.json keel.PreToolUse must be a non-empty grouped list")
|
|
84
|
+
return 1
|
|
85
|
+
pt_group = pre_tool[0]
|
|
86
|
+
if not isinstance(pt_group, dict):
|
|
87
|
+
report("agy-plugin-package: PreToolUse entry must be an object")
|
|
88
|
+
return 1
|
|
89
|
+
if pt_group.get("matcher") != "edit_file|write_file|run_command":
|
|
90
|
+
report(
|
|
91
|
+
f"agy-plugin-package: PreToolUse matcher is {pt_group.get('matcher')!r}, "
|
|
92
|
+
"expected 'edit_file|write_file|run_command'"
|
|
93
|
+
)
|
|
94
|
+
return 1
|
|
95
|
+
pt_handlers = pt_group.get("hooks")
|
|
96
|
+
if not isinstance(pt_handlers, list) or len(pt_handlers) == 0:
|
|
97
|
+
report("agy-plugin-package: PreToolUse matcher group must declare a non-empty hooks list")
|
|
98
|
+
return 1
|
|
99
|
+
pt_cmd = pt_handlers[0].get("command", "")
|
|
100
|
+
if "./scripts/pretooluse-guard.js" not in pt_cmd:
|
|
101
|
+
report(f"agy-plugin-package: PreToolUse command must use relative ./scripts/pretooluse-guard.js: {pt_cmd!r}")
|
|
102
|
+
return 1
|
|
103
|
+
if "--host agy" not in pt_cmd:
|
|
104
|
+
report(f"agy-plugin-package: PreToolUse command must pass --host agy: {pt_cmd!r}")
|
|
105
|
+
return 1
|
|
106
|
+
|
|
107
|
+
for runtime in (".claude-plugin", ".codex-plugin"):
|
|
108
|
+
other = plugin_root / runtime / "plugin.json"
|
|
109
|
+
if not other.is_file():
|
|
110
|
+
report(f"agy-plugin-package: co-located manifest missing: plugins/keel/{runtime}/plugin.json")
|
|
111
|
+
return 1
|
|
112
|
+
|
|
113
|
+
with tempfile.TemporaryDirectory(prefix="keel-agy-bump-") as raw:
|
|
114
|
+
scratch = Path(raw)
|
|
115
|
+
for relative in (
|
|
116
|
+
"package.json",
|
|
117
|
+
"npm-shrinkwrap.json",
|
|
118
|
+
".claude-plugin/marketplace.json",
|
|
119
|
+
".claude-plugin/plugin.json",
|
|
120
|
+
"plugins/keel/plugin.json",
|
|
121
|
+
"plugins/keel/.claude-plugin/plugin.json",
|
|
122
|
+
"plugins/keel/.codex-plugin/plugin.json",
|
|
123
|
+
"scripts/bump_version.js",
|
|
124
|
+
"scripts/validation/common.py",
|
|
125
|
+
"AGENTS.md",
|
|
126
|
+
"keel/CHANGELOG.md",
|
|
127
|
+
):
|
|
128
|
+
(scratch / relative).parent.mkdir(parents=True, exist_ok=True)
|
|
129
|
+
shutil.copy2(ROOT / relative, scratch / relative)
|
|
130
|
+
bumped = subprocess.run(
|
|
131
|
+
["node", str(scratch / "scripts/bump_version.js"), "99.0.0"],
|
|
132
|
+
cwd=scratch,
|
|
133
|
+
capture_output=True,
|
|
134
|
+
text=True,
|
|
135
|
+
check=False,
|
|
136
|
+
)
|
|
137
|
+
if bumped.returncode != 0:
|
|
138
|
+
report(f"agy-plugin-package: bump_version.js failed: {(bumped.stderr or bumped.stdout).strip()}")
|
|
139
|
+
return 1
|
|
140
|
+
bumped_manifest = json.loads((scratch / "plugins/keel/plugin.json").read_text(encoding="utf-8"))
|
|
141
|
+
if bumped_manifest.get("version") != "99.0.0":
|
|
142
|
+
report(
|
|
143
|
+
"agy-plugin-package: bump_version.js did not update plugins/keel/plugin.json "
|
|
144
|
+
f"(got {bumped_manifest.get('version')!r})"
|
|
145
|
+
)
|
|
146
|
+
return 1
|
|
147
|
+
|
|
148
|
+
print("agy-plugin-package scenario passed.")
|
|
149
|
+
return 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def validate_agy_session_start_scenario() -> int:
|
|
153
|
+
script = ROOT / "plugins" / "keel" / "scripts" / "session-start.js"
|
|
154
|
+
with tempfile.TemporaryDirectory(prefix="keel-agy-ss-") as raw:
|
|
155
|
+
base = Path(raw).resolve()
|
|
156
|
+
repo = base / "repo"
|
|
157
|
+
repo.mkdir()
|
|
158
|
+
_init_git_repo(repo)
|
|
159
|
+
(repo / "openspec" / "changes").mkdir(parents=True)
|
|
160
|
+
(repo / "AGENTS.md").write_text(
|
|
161
|
+
f"# Protocol\n<!-- keel:start version={PACKAGE_VERSION} -->\n<!-- keel:end -->\n",
|
|
162
|
+
encoding="utf-8",
|
|
163
|
+
)
|
|
164
|
+
env = _agy_hook_env(base)
|
|
165
|
+
|
|
166
|
+
agy_event = {
|
|
167
|
+
"conversationId": "conv-agy-1",
|
|
168
|
+
"workspacePaths": [str(repo)],
|
|
169
|
+
"transcriptPath": str(base / "transcript.jsonl"),
|
|
170
|
+
"artifactDirectoryPath": str(base / "artifacts"),
|
|
171
|
+
"modelName": "gemini-4",
|
|
172
|
+
"hookEventName": "SessionStart",
|
|
173
|
+
"cwd": str(repo),
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
# 1) Explicit --host agy invocation
|
|
177
|
+
res = subprocess.run(
|
|
178
|
+
["node", str(script), "--host", "agy"],
|
|
179
|
+
input=json.dumps(agy_event),
|
|
180
|
+
capture_output=True,
|
|
181
|
+
text=True,
|
|
182
|
+
env=env,
|
|
183
|
+
check=False,
|
|
184
|
+
)
|
|
185
|
+
if res.returncode != 0:
|
|
186
|
+
report(f"agy-session-start: --host agy exited {res.returncode}: {res.stderr.strip()}")
|
|
187
|
+
return 1
|
|
188
|
+
try:
|
|
189
|
+
payload = json.loads(res.stdout)
|
|
190
|
+
except json.JSONDecodeError as exc:
|
|
191
|
+
report(f"agy-session-start: stdout is not valid JSON: {exc}; raw={res.stdout!r}")
|
|
192
|
+
return 1
|
|
193
|
+
if "hookSpecificOutput" in payload:
|
|
194
|
+
report("agy-session-start: AGY output must not emit Claude hookSpecificOutput")
|
|
195
|
+
return 1
|
|
196
|
+
steps = payload.get("injectSteps")
|
|
197
|
+
if not isinstance(steps, list):
|
|
198
|
+
report(f"agy-session-start: missing injectSteps list in {payload!r}")
|
|
199
|
+
return 1
|
|
200
|
+
if len(steps) != 1:
|
|
201
|
+
report(f"agy-session-start: expected 1 injectStep, got {len(steps)}")
|
|
202
|
+
return 1
|
|
203
|
+
sys_msg = steps[0].get("systemMessage")
|
|
204
|
+
if not isinstance(sys_msg, dict):
|
|
205
|
+
report(f"agy-session-start: injectSteps[0].systemMessage must be an object: {steps[0]!r}")
|
|
206
|
+
return 1
|
|
207
|
+
if "metadata" in sys_msg:
|
|
208
|
+
report("agy-session-start: AGY SessionStart must not include metadata key (silently dropped on agy 1.5.20)")
|
|
209
|
+
return 1
|
|
210
|
+
body = sys_msg.get("systemMessage", "")
|
|
211
|
+
if "Keel session projection" not in body:
|
|
212
|
+
report(f"agy-session-start: injected message lacks projection header: {body!r}")
|
|
213
|
+
return 1
|
|
214
|
+
|
|
215
|
+
# 2) Auto-detected camelCase stdin without --host flag
|
|
216
|
+
res_auto = subprocess.run(
|
|
217
|
+
["node", str(script)],
|
|
218
|
+
input=json.dumps(agy_event),
|
|
219
|
+
capture_output=True,
|
|
220
|
+
text=True,
|
|
221
|
+
env=env,
|
|
222
|
+
check=False,
|
|
223
|
+
)
|
|
224
|
+
if res_auto.returncode != 0:
|
|
225
|
+
report(f"agy-session-start: auto-detect exited {res_auto.returncode}: {res_auto.stderr.strip()}")
|
|
226
|
+
return 1
|
|
227
|
+
auto_payload = json.loads(res_auto.stdout)
|
|
228
|
+
if not isinstance(auto_payload.get("injectSteps"), list):
|
|
229
|
+
report(f"agy-session-start: camelCase stdin without --host did not emit injectSteps: {auto_payload!r}")
|
|
230
|
+
return 1
|
|
231
|
+
|
|
232
|
+
# 3) Root plugin.json version mismatch detection on AGY copy
|
|
233
|
+
plugin_copy = base / "plugin-copy"
|
|
234
|
+
shutil.copytree(ROOT / "plugins" / "keel", plugin_copy)
|
|
235
|
+
m_path = plugin_copy / "plugin.json"
|
|
236
|
+
m_data = json.loads(m_path.read_text(encoding="utf-8"))
|
|
237
|
+
m_data["version"] = "5.0.0"
|
|
238
|
+
m_path.write_text(json.dumps(m_data), encoding="utf-8")
|
|
239
|
+
res_drift = subprocess.run(
|
|
240
|
+
["node", str(plugin_copy / "scripts" / "session-start.js"), "--host", "agy"],
|
|
241
|
+
input=json.dumps(agy_event),
|
|
242
|
+
capture_output=True,
|
|
243
|
+
text=True,
|
|
244
|
+
env=env,
|
|
245
|
+
check=False,
|
|
246
|
+
)
|
|
247
|
+
if res_drift.returncode != 0:
|
|
248
|
+
report(f"agy-session-start: drift probe exited {res_drift.returncode}")
|
|
249
|
+
return 1
|
|
250
|
+
drift_body = json.loads(res_drift.stdout)["injectSteps"][0]["systemMessage"]["systemMessage"]
|
|
251
|
+
if "plugin 5.0.0" not in drift_body:
|
|
252
|
+
report(f"agy-session-start: AGY did not read root plugin.json version 5.0.0: {drift_body!r}")
|
|
253
|
+
return 1
|
|
254
|
+
if "claude plugin update" in drift_body:
|
|
255
|
+
report(f"agy-session-start: AGY drift message must not recommend claude plugin update: {drift_body!r}")
|
|
256
|
+
return 1
|
|
257
|
+
|
|
258
|
+
# 4) Claude stdin still emits hookSpecificOutput and reads .claude-plugin remedy
|
|
259
|
+
claude_copy = base / "claude-copy"
|
|
260
|
+
shutil.copytree(ROOT / "plugins" / "keel", claude_copy)
|
|
261
|
+
cm_path = claude_copy / ".claude-plugin" / "plugin.json"
|
|
262
|
+
cm_data = json.loads(cm_path.read_text(encoding="utf-8"))
|
|
263
|
+
cm_data["version"] = "5.0.0"
|
|
264
|
+
cm_path.write_text(json.dumps(cm_data), encoding="utf-8")
|
|
265
|
+
claude_event = {"session_id": "sess-1", "cwd": str(repo), "source": "startup"}
|
|
266
|
+
res_claude = subprocess.run(
|
|
267
|
+
["node", str(claude_copy / "scripts" / "session-start.js")],
|
|
268
|
+
input=json.dumps(claude_event),
|
|
269
|
+
capture_output=True,
|
|
270
|
+
text=True,
|
|
271
|
+
env=env,
|
|
272
|
+
check=False,
|
|
273
|
+
)
|
|
274
|
+
if res_claude.returncode != 0:
|
|
275
|
+
report(f"agy-session-start: Claude regression exited {res_claude.returncode}")
|
|
276
|
+
return 1
|
|
277
|
+
c_payload = json.loads(res_claude.stdout)
|
|
278
|
+
hso = c_payload.get("hookSpecificOutput")
|
|
279
|
+
if not isinstance(hso, dict):
|
|
280
|
+
report(f"agy-session-start: Claude output missing hookSpecificOutput: {c_payload!r}")
|
|
281
|
+
return 1
|
|
282
|
+
if "`claude plugin update`" not in hso.get("additionalContext", ""):
|
|
283
|
+
report(f"agy-session-start: Claude lost its update remedy: {hso!r}")
|
|
284
|
+
return 1
|
|
285
|
+
|
|
286
|
+
print("agy-session-start scenario passed.")
|
|
287
|
+
return 0
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def validate_agy_pretooluse_guard_scenario() -> int:
|
|
291
|
+
script = ROOT / "plugins" / "keel" / "scripts" / "pretooluse-guard.js"
|
|
292
|
+
with tempfile.TemporaryDirectory(prefix="keel-agy-ptu-") as raw:
|
|
293
|
+
base = Path(raw).resolve()
|
|
294
|
+
repo = base / "repo"
|
|
295
|
+
repo.mkdir()
|
|
296
|
+
_init_git_repo(repo)
|
|
297
|
+
(repo / "src").mkdir()
|
|
298
|
+
(repo / "src" / "allowed.txt").write_text("a\n", encoding="utf-8")
|
|
299
|
+
(repo / "src" / "blocked.txt").write_text("b\n", encoding="utf-8")
|
|
300
|
+
(repo / "keel").mkdir()
|
|
301
|
+
(repo / "keel" / "config.yaml").write_text(
|
|
302
|
+
"authorize:\n"
|
|
303
|
+
" - push:agy/*\n"
|
|
304
|
+
" - push-protected:main\n",
|
|
305
|
+
encoding="utf-8",
|
|
306
|
+
)
|
|
307
|
+
change_dir = repo / "openspec" / "changes" / "demo"
|
|
308
|
+
(change_dir / "specs" / "demo-cap").mkdir(parents=True)
|
|
309
|
+
(change_dir / "proposal.md").write_text("# Proposal\n\n## Why\nDemo.\n\n## What Changes\n- Demo.\n", encoding="utf-8")
|
|
310
|
+
(change_dir / "design.md").write_text("# Design\n", encoding="utf-8")
|
|
311
|
+
(change_dir / "specs" / "demo-cap" / "spec.md").write_text(
|
|
312
|
+
"## ADDED Requirements\n\n### Requirement: Demo\nDemo MUST work.\n\n"
|
|
313
|
+
"#### Scenario: Demo works\n- **WHEN** tested\n- **THEN** it works\n",
|
|
314
|
+
encoding="utf-8",
|
|
315
|
+
)
|
|
316
|
+
(change_dir / "tasks.md").write_text(
|
|
317
|
+
"# Tasks\n\n## 1. Demo\n\n- [ ] 1.1 Demo task\n"
|
|
318
|
+
" - Covers:\n - demo-cap / Demo / Demo works\n"
|
|
319
|
+
" - Touch:\n - src/allowed.txt\n"
|
|
320
|
+
" - Verify:\n - Strategy: evidence-first\n - Reason: test fixture\n - M1: true\n"
|
|
321
|
+
" - Evidence:\n - Contract: pending\n - M1: pending\n"
|
|
322
|
+
" - Review:\n - Status: pending\n - Acceptance check: pending\n"
|
|
323
|
+
" - Scope check: pending\n - Findings: pending\n"
|
|
324
|
+
" - Blocker: none\n - Reauthorizations: none\n\n"
|
|
325
|
+
"## Invalidates\n\n- None.\n\n## Expectation Coverage\n\n- None.\n",
|
|
326
|
+
encoding="utf-8",
|
|
327
|
+
)
|
|
328
|
+
subprocess.run(["git", "add", "-A"], cwd=repo, check=True)
|
|
329
|
+
subprocess.run(["git", "commit", "-q", "-m", "init"], cwd=repo, check=True)
|
|
330
|
+
|
|
331
|
+
# Verify runGate task-start with target: "agy" writes keel/guard.json by default and skips with --no-guard
|
|
332
|
+
gate_js = (
|
|
333
|
+
'const { runGate } = require(process.argv[1]);'
|
|
334
|
+
'const r1 = runGate(process.argv[2], "task-start", { change: "demo", task: "1.1", target: "agy", noGuard: true });'
|
|
335
|
+
'const fs = require("fs"); const path = require("path");'
|
|
336
|
+
'const existsAfterNoGuard = fs.existsSync(path.join(process.argv[2], "keel", "guard.json"));'
|
|
337
|
+
'const r2 = runGate(process.argv[2], "task-start", { change: "demo", task: "1.1", target: "agy", noGuard: false });'
|
|
338
|
+
'const existsAfterDefault = fs.existsSync(path.join(process.argv[2], "keel", "guard.json"));'
|
|
339
|
+
'console.log(JSON.stringify({ s1: r1.status, existsAfterNoGuard, s2: r2.status, existsAfterDefault }));'
|
|
340
|
+
)
|
|
341
|
+
gate_res = subprocess.run(
|
|
342
|
+
["node", "-e", gate_js, str(ROOT / "src" / "core" / "gates.js"), str(repo)],
|
|
343
|
+
capture_output=True,
|
|
344
|
+
text=True,
|
|
345
|
+
check=False,
|
|
346
|
+
)
|
|
347
|
+
if gate_res.returncode != 0:
|
|
348
|
+
report(f"agy-pretooluse-guard: gateTaskStart probe failed: {gate_res.stderr.strip()}")
|
|
349
|
+
return 1
|
|
350
|
+
gate_data = json.loads(gate_res.stdout)
|
|
351
|
+
if gate_data.get("s1") != "pass":
|
|
352
|
+
report(f"agy-pretooluse-guard: task-start --no-guard did not pass: {gate_data!r}")
|
|
353
|
+
return 1
|
|
354
|
+
if gate_data.get("existsAfterNoGuard") is not False:
|
|
355
|
+
report("agy-pretooluse-guard: task-start --target agy --no-guard must not write keel/guard.json")
|
|
356
|
+
return 1
|
|
357
|
+
if gate_data.get("s2") != "pass":
|
|
358
|
+
report(f"agy-pretooluse-guard: task-start default did not pass: {gate_data!r}")
|
|
359
|
+
return 1
|
|
360
|
+
if gate_data.get("existsAfterDefault") is not True:
|
|
361
|
+
report("agy-pretooluse-guard: task-start --target agy must write keel/guard.json by default")
|
|
362
|
+
return 1
|
|
363
|
+
|
|
364
|
+
env = _agy_hook_env(base)
|
|
365
|
+
|
|
366
|
+
def call_guard(tool_name: str, args: dict, explicit_flag: bool = True) -> subprocess.CompletedProcess:
|
|
367
|
+
cmd = ["node", str(script)]
|
|
368
|
+
if explicit_flag:
|
|
369
|
+
cmd.extend(["--host", "agy"])
|
|
370
|
+
ev = {
|
|
371
|
+
"conversationId": "conv-agy-2",
|
|
372
|
+
"cwd": str(repo),
|
|
373
|
+
"hookEventName": "PreToolUse",
|
|
374
|
+
"stepIdx": 2,
|
|
375
|
+
"toolCall": {"id": "call-1", "name": tool_name, "args": args},
|
|
376
|
+
}
|
|
377
|
+
return subprocess.run(cmd, input=json.dumps(ev), capture_output=True, text=True, env=env, check=False)
|
|
378
|
+
|
|
379
|
+
# 1) edit_file & write_file outside Touch -> deny
|
|
380
|
+
for tool in ("edit_file", "write_file"):
|
|
381
|
+
r = call_guard(tool, {"Path": str(repo / "src" / "blocked.txt")})
|
|
382
|
+
if r.returncode != 0:
|
|
383
|
+
report(f"agy-pretooluse-guard: {tool} outside Touch exited {r.returncode}")
|
|
384
|
+
return 1
|
|
385
|
+
if not r.stdout.strip():
|
|
386
|
+
report(f"agy-pretooluse-guard: {tool} outside Touch returned empty stdout instead of deny")
|
|
387
|
+
return 1
|
|
388
|
+
d = json.loads(r.stdout)
|
|
389
|
+
if d.get("decision") != "deny":
|
|
390
|
+
report(f"agy-pretooluse-guard: {tool} outside Touch expected decision deny, got {d!r}")
|
|
391
|
+
return 1
|
|
392
|
+
if "hookSpecificOutput" in d:
|
|
393
|
+
report(f"agy-pretooluse-guard: {tool} AGY response must be top-level decision, not hookSpecificOutput")
|
|
394
|
+
return 1
|
|
395
|
+
|
|
396
|
+
# 2) edit_file inside Touch, record layer, and outside repo -> empty stdout (pass-through)
|
|
397
|
+
for label, target_path in (
|
|
398
|
+
("inside Touch", repo / "src" / "allowed.txt"),
|
|
399
|
+
("record layer", change_dir / "tasks.md"),
|
|
400
|
+
("outside repo", base / "scratch.txt"),
|
|
401
|
+
):
|
|
402
|
+
r = call_guard("write_file", {"Path": str(target_path)})
|
|
403
|
+
if r.returncode != 0:
|
|
404
|
+
report(f"agy-pretooluse-guard: {label} exited {r.returncode}")
|
|
405
|
+
return 1
|
|
406
|
+
if r.stdout.strip() != "":
|
|
407
|
+
report(f"agy-pretooluse-guard: {label} must emit empty stdout on pass-through, got {r.stdout!r}")
|
|
408
|
+
return 1
|
|
409
|
+
|
|
410
|
+
# 3) run_command unauthorized branch -> deny
|
|
411
|
+
r_unauth = call_guard("run_command", {"CommandLine": "git push origin feature/bad"}, explicit_flag=False)
|
|
412
|
+
if r_unauth.returncode != 0:
|
|
413
|
+
report(f"agy-pretooluse-guard: unauthorized push exited {r_unauth.returncode}")
|
|
414
|
+
return 1
|
|
415
|
+
d_unauth = json.loads(r_unauth.stdout or "{}")
|
|
416
|
+
if d_unauth.get("decision") != "deny":
|
|
417
|
+
report(f"agy-pretooluse-guard: unauthorized push expected decision deny, got {r_unauth.stdout!r}")
|
|
418
|
+
return 1
|
|
419
|
+
|
|
420
|
+
# 4) run_command push-protected branch -> force_ask
|
|
421
|
+
r_prot = call_guard("run_command", {"CommandLine": "git push origin main"})
|
|
422
|
+
if r_prot.returncode != 0:
|
|
423
|
+
report(f"agy-pretooluse-guard: protected push exited {r_prot.returncode}")
|
|
424
|
+
return 1
|
|
425
|
+
d_prot = json.loads(r_prot.stdout or "{}")
|
|
426
|
+
if d_prot.get("decision") != "force_ask":
|
|
427
|
+
report(f"agy-pretooluse-guard: push-protected expected decision force_ask, got {r_prot.stdout!r}")
|
|
428
|
+
return 1
|
|
429
|
+
|
|
430
|
+
# 5) run_command authorized branch & non-push command -> empty stdout
|
|
431
|
+
for label, cmdline in (
|
|
432
|
+
("authorized push", "git push origin agy/ok"),
|
|
433
|
+
("non-push command", "echo hello"),
|
|
434
|
+
):
|
|
435
|
+
r_ok = call_guard("run_command", {"CommandLine": cmdline})
|
|
436
|
+
if r_ok.returncode != 0:
|
|
437
|
+
report(f"agy-pretooluse-guard: {label} exited {r_ok.returncode}")
|
|
438
|
+
return 1
|
|
439
|
+
if r_ok.stdout.strip() != "":
|
|
440
|
+
report(f"agy-pretooluse-guard: {label} must emit empty stdout, got {r_ok.stdout!r}")
|
|
441
|
+
return 1
|
|
442
|
+
|
|
443
|
+
print("agy-pretooluse-guard scenario passed.")
|
|
444
|
+
return 0
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def _agy_cli_env(home: Path, agy_config: Path | None = None, bin_dir: Path | None = None) -> dict[str, str]:
|
|
448
|
+
env = {k: v for k, v in os.environ.items() if not k.startswith(("CLAUDE", "KEEL_"))}
|
|
449
|
+
env["HOME"] = str(home)
|
|
450
|
+
env["CODEX_HOME"] = str(home / "codex-home")
|
|
451
|
+
if agy_config is not None:
|
|
452
|
+
env["KEEL_AGY_CONFIG_DIR"] = str(agy_config)
|
|
453
|
+
if bin_dir is not None:
|
|
454
|
+
env["PATH"] = f"{bin_dir}{os.pathsep}{env.get('PATH', '')}"
|
|
455
|
+
return env
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def validate_agy_capabilities_project_scenario() -> int:
|
|
459
|
+
with tempfile.TemporaryDirectory(prefix="keel-agy-cap-") as raw:
|
|
460
|
+
base = Path(raw).resolve()
|
|
461
|
+
repo = base / "repo"
|
|
462
|
+
repo.mkdir()
|
|
463
|
+
env = _agy_cli_env(base, base / "agy-cfg")
|
|
464
|
+
|
|
465
|
+
cap = run_keel(repo, "capabilities", "--target", "agy", "--json", env=env)
|
|
466
|
+
if cap.returncode != 0:
|
|
467
|
+
report(f"agy-capabilities-project: capabilities exited {cap.returncode}: {(cap.stderr or cap.stdout).strip()}")
|
|
468
|
+
return 1
|
|
469
|
+
payload = json.loads(cap.stdout)
|
|
470
|
+
if payload.get("target") != "agy":
|
|
471
|
+
report(f"agy-capabilities-project: target is {payload.get('target')!r}, expected 'agy'")
|
|
472
|
+
return 1
|
|
473
|
+
caps = payload.get("capabilities", {})
|
|
474
|
+
if len(caps) != 6:
|
|
475
|
+
report(f"agy-capabilities-project: expected 6 capabilities, got {sorted(caps)}")
|
|
476
|
+
return 1
|
|
477
|
+
not_manual = [name for name, item in caps.items() if item.get("level") != "manual"]
|
|
478
|
+
if not_manual:
|
|
479
|
+
report(f"agy-capabilities-project: core capabilities must stay manual: {not_manual}")
|
|
480
|
+
return 1
|
|
481
|
+
guard = payload.get("guard", {})
|
|
482
|
+
if guard.get("enforcement", {}).get("level") != "advisory":
|
|
483
|
+
report(f"agy-capabilities-project: guard.enforcement must be advisory, got {guard!r}")
|
|
484
|
+
return 1
|
|
485
|
+
boundary_ev = guard.get("boundary", {}).get("evidence", "")
|
|
486
|
+
for tool_name in ("edit_file", "write_file", "run_command"):
|
|
487
|
+
if tool_name not in boundary_ev:
|
|
488
|
+
report(f"agy-capabilities-project: guard.boundary evidence missing {tool_name!r}: {boundary_ev!r}")
|
|
489
|
+
return 1
|
|
490
|
+
comp = payload.get("compaction", {})
|
|
491
|
+
if comp.get("postCompactReinjection", {}).get("level") != "manual":
|
|
492
|
+
report(f"agy-capabilities-project: compaction must stay manual, got {comp!r}")
|
|
493
|
+
return 1
|
|
494
|
+
|
|
495
|
+
plain = run_keel(repo, "capabilities", "--target", "agy", env=env)
|
|
496
|
+
if plain.returncode != 0:
|
|
497
|
+
report(f"agy-capabilities-project: plain capabilities exited {plain.returncode}")
|
|
498
|
+
return 1
|
|
499
|
+
if "Target capabilities (agy):" not in plain.stdout:
|
|
500
|
+
report(f"agy-capabilities-project: plain capabilities missing header: {plain.stdout!r}")
|
|
501
|
+
return 1
|
|
502
|
+
|
|
503
|
+
# Projection structure matches codex
|
|
504
|
+
_init_git_repo(repo)
|
|
505
|
+
init = run_keel(repo, "--init", "--target", "codex", env=env)
|
|
506
|
+
if init.returncode != 0:
|
|
507
|
+
report(f"agy-capabilities-project: codex init failed: {(init.stderr or init.stdout).strip()}")
|
|
508
|
+
return 1
|
|
509
|
+
proj_agy = run_keel(repo, "project", "--target", "agy", "--event", "startup", "--json", env=env)
|
|
510
|
+
if proj_agy.returncode != 0:
|
|
511
|
+
report(f"agy-capabilities-project: project agy exited {proj_agy.returncode}: {(proj_agy.stderr or proj_agy.stdout).strip()}")
|
|
512
|
+
return 1
|
|
513
|
+
proj_codex = run_keel(repo, "project", "--target", "codex", "--event", "startup", "--json", env=env)
|
|
514
|
+
if proj_codex.returncode != 0:
|
|
515
|
+
report(f"agy-capabilities-project: project codex exited {proj_codex.returncode}")
|
|
516
|
+
return 1
|
|
517
|
+
agy_data = json.loads(proj_agy.stdout)
|
|
518
|
+
codex_data = json.loads(proj_codex.stdout)
|
|
519
|
+
if set(agy_data) != set(codex_data):
|
|
520
|
+
report(f"agy-capabilities-project: project keys differ: agy={sorted(agy_data)} codex={sorted(codex_data)}")
|
|
521
|
+
return 1
|
|
522
|
+
if agy_data.get("target") != "agy":
|
|
523
|
+
report(f"agy-capabilities-project: project target is {agy_data.get('target')!r}, expected 'agy'")
|
|
524
|
+
return 1
|
|
525
|
+
|
|
526
|
+
print("agy-capabilities-project scenario passed.")
|
|
527
|
+
return 0
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def validate_agy_init_doctor_update_scenario() -> int:
|
|
531
|
+
with tempfile.TemporaryDirectory(prefix="keel-agy-init-") as raw:
|
|
532
|
+
base = Path(raw).resolve()
|
|
533
|
+
repo = base / "repo"
|
|
534
|
+
repo.mkdir()
|
|
535
|
+
_init_git_repo(repo)
|
|
536
|
+
agy_cfg = base / "agy-config"
|
|
537
|
+
agy_cfg.mkdir()
|
|
538
|
+
|
|
539
|
+
# PATH with node/git/python3 but no agy binary
|
|
540
|
+
clean_bin = base / "clean-bin"
|
|
541
|
+
clean_bin.mkdir()
|
|
542
|
+
for tool in ("node", "git", "python3", "sh"):
|
|
543
|
+
found = shutil.which(tool)
|
|
544
|
+
if found:
|
|
545
|
+
(clean_bin / tool).symlink_to(found)
|
|
546
|
+
env_no_agy = _agy_cli_env(base, agy_cfg)
|
|
547
|
+
env_no_agy["PATH"] = str(clean_bin)
|
|
548
|
+
|
|
549
|
+
# 1) Direct install_to_repo.py --target agy works
|
|
550
|
+
direct_repo = base / "direct-repo"
|
|
551
|
+
direct_repo.mkdir()
|
|
552
|
+
direct = subprocess.run(
|
|
553
|
+
["python3", str(ROOT / "scripts" / "install_to_repo.py"), str(direct_repo), "--target", "agy"],
|
|
554
|
+
capture_output=True,
|
|
555
|
+
text=True,
|
|
556
|
+
check=False,
|
|
557
|
+
)
|
|
558
|
+
if direct.returncode != 0:
|
|
559
|
+
report(f"agy-init-doctor-update: install_to_repo.py --target agy exited {direct.returncode}: {(direct.stderr or direct.stdout).strip()}")
|
|
560
|
+
return 1
|
|
561
|
+
if not (direct_repo / "AGENTS.md").is_file():
|
|
562
|
+
report("agy-init-doctor-update: install_to_repo.py --target agy did not write AGENTS.md")
|
|
563
|
+
return 1
|
|
564
|
+
|
|
565
|
+
# 2) keel --init --target agy, --check, --doctor (missing agy CLI and absent plugins.json)
|
|
566
|
+
init = run_keel(repo, "--init", "--target", "agy", env=env_no_agy)
|
|
567
|
+
if init.returncode != 0:
|
|
568
|
+
report(f"agy-init-doctor-update: --init --target agy exited {init.returncode}: {(init.stderr or init.stdout).strip()}")
|
|
569
|
+
return 1
|
|
570
|
+
if not (repo / "AGENTS.md").is_file():
|
|
571
|
+
report("agy-init-doctor-update: --init --target agy did not create AGENTS.md")
|
|
572
|
+
return 1
|
|
573
|
+
if not (repo / ".agents" / "skills" / "openspec-apply-change" / "SKILL.md").is_file():
|
|
574
|
+
report("agy-init-doctor-update: --init --target agy did not create .agents/skills/openspec-apply-change/SKILL.md")
|
|
575
|
+
return 1
|
|
576
|
+
if (repo / ".claude").exists():
|
|
577
|
+
report("agy-init-doctor-update: --init --target agy must not create .claude/")
|
|
578
|
+
return 1
|
|
579
|
+
|
|
580
|
+
chk = run_keel(repo, "--check", "--target", "agy", env=env_no_agy)
|
|
581
|
+
if chk.returncode != 0:
|
|
582
|
+
report(f"agy-init-doctor-update: --check --target agy exited {chk.returncode}: {(chk.stderr or chk.stdout).strip()}")
|
|
583
|
+
return 1
|
|
584
|
+
|
|
585
|
+
doc_absent = run_keel(repo, "--doctor", "--target", "agy", env=env_no_agy)
|
|
586
|
+
if doc_absent.returncode != 0:
|
|
587
|
+
report(f"agy-init-doctor-update: --doctor --target agy without agy CLI exited {doc_absent.returncode}")
|
|
588
|
+
return 1
|
|
589
|
+
if "Target capabilities (agy):" not in doc_absent.stdout:
|
|
590
|
+
report(f"agy-init-doctor-update: doctor missing 'Target capabilities (agy):': {doc_absent.stdout!r}")
|
|
591
|
+
return 1
|
|
592
|
+
if "AGY CLI: not found" not in doc_absent.stdout:
|
|
593
|
+
report(f"agy-init-doctor-update: doctor missing 'AGY CLI: not found': {doc_absent.stdout!r}")
|
|
594
|
+
return 1
|
|
595
|
+
if "AGY plugin config: not found" not in doc_absent.stdout:
|
|
596
|
+
report(f"agy-init-doctor-update: doctor missing 'AGY plugin config: not found': {doc_absent.stdout!r}")
|
|
597
|
+
return 1
|
|
598
|
+
|
|
599
|
+
# 3) Configure stub agy CLI, plugins.json mounting keel, disabled config.json, and workspace .agents/plugins
|
|
600
|
+
stub_bin = base / "stub-bin"
|
|
601
|
+
stub_bin.mkdir()
|
|
602
|
+
for tool in ("node", "git", "python3", "sh"):
|
|
603
|
+
found = shutil.which(tool)
|
|
604
|
+
if found:
|
|
605
|
+
(stub_bin / tool).symlink_to(found)
|
|
606
|
+
stub_agy = stub_bin / "agy"
|
|
607
|
+
stub_agy.write_text("#!/bin/sh\nif [ \"$1\" = \"--version\" ]; then echo '1.5.20'; exit 0; fi\nexit 0\n", encoding="utf-8")
|
|
608
|
+
stub_agy.chmod(0o755)
|
|
609
|
+
plugins_json = agy_cfg / "plugins.json"
|
|
610
|
+
plugins_json_content = json.dumps({"entries": [{"path": str(ROOT / "plugins")}]}) + "\n"
|
|
611
|
+
plugins_json.write_text(plugins_json_content, encoding="utf-8")
|
|
612
|
+
config_json = agy_cfg / "config.json"
|
|
613
|
+
config_json.write_text(json.dumps({"plugins": {"keel": {"enabled": False}}}) + "\n", encoding="utf-8")
|
|
614
|
+
(repo / ".agents" / "plugins" / "keel").mkdir(parents=True)
|
|
615
|
+
(repo / ".agents" / "plugins" / "keel" / "plugin.json").write_text('{"name":"keel"}\n', encoding="utf-8")
|
|
616
|
+
|
|
617
|
+
env_stub = _agy_cli_env(base, agy_cfg)
|
|
618
|
+
env_stub["PATH"] = str(stub_bin)
|
|
619
|
+
doc_present = run_keel(repo, "--doctor", "--target", "agy", env=env_stub)
|
|
620
|
+
if doc_present.returncode != 0:
|
|
621
|
+
report(f"agy-init-doctor-update: --doctor --target agy with stub exited {doc_present.returncode}")
|
|
622
|
+
return 1
|
|
623
|
+
if "AGY CLI: ok - 1.5.20" not in doc_present.stdout:
|
|
624
|
+
report(f"agy-init-doctor-update: doctor missing stub AGY CLI version: {doc_present.stdout!r}")
|
|
625
|
+
return 1
|
|
626
|
+
if "plugins.json" not in doc_present.stdout:
|
|
627
|
+
report(f"agy-init-doctor-update: doctor did not mention plugins.json: {doc_present.stdout!r}")
|
|
628
|
+
return 1
|
|
629
|
+
if ".agents/plugins" not in doc_present.stdout:
|
|
630
|
+
report(f"agy-init-doctor-update: doctor did not mention .agents/plugins: {doc_present.stdout!r}")
|
|
631
|
+
return 1
|
|
632
|
+
if "disabled" not in doc_present.stdout:
|
|
633
|
+
report(f"agy-init-doctor-update: doctor did not report disabled keel entry from config.json: {doc_present.stdout!r}")
|
|
634
|
+
return 1
|
|
635
|
+
|
|
636
|
+
# 4) --uninstall --target agy --dry-run states shared surface and keeps .claude untouched
|
|
637
|
+
init_claude = run_keel(repo, "--init", "--target", "claude", env=env_stub)
|
|
638
|
+
if init_claude.returncode != 0:
|
|
639
|
+
report(f"agy-init-doctor-update: claude init failed: {init_claude.stderr.strip()}")
|
|
640
|
+
return 1
|
|
641
|
+
uninst = run_keel(repo, "--uninstall", "--target", "agy", "--dry-run", env=env_stub)
|
|
642
|
+
if uninst.returncode != 0:
|
|
643
|
+
report(f"agy-init-doctor-update: --uninstall --target agy --dry-run exited {uninst.returncode}")
|
|
644
|
+
return 1
|
|
645
|
+
if "shared with Codex" not in uninst.stdout:
|
|
646
|
+
report(f"agy-init-doctor-update: uninstall plan missing shared-surface note: {uninst.stdout!r}")
|
|
647
|
+
return 1
|
|
648
|
+
|
|
649
|
+
# 5) keel gate task-start --target agy via CLI writes keel/guard.json by default
|
|
650
|
+
cdir = repo / "openspec" / "changes" / "cli-demo"
|
|
651
|
+
(cdir / "specs" / "cli-cap").mkdir(parents=True)
|
|
652
|
+
(cdir / "proposal.md").write_text("# Proposal\n\n## Why\nDemo.\n\n## What Changes\n- Demo.\n", encoding="utf-8")
|
|
653
|
+
(cdir / "design.md").write_text("# Design\n", encoding="utf-8")
|
|
654
|
+
(cdir / "specs" / "cli-cap" / "spec.md").write_text(
|
|
655
|
+
"## ADDED Requirements\n\n### Requirement: CliDemo\nCliDemo MUST work.\n\n"
|
|
656
|
+
"#### Scenario: CliDemo works\n- **WHEN** run\n- **THEN** ok\n",
|
|
657
|
+
encoding="utf-8",
|
|
658
|
+
)
|
|
659
|
+
(cdir / "tasks.md").write_text(
|
|
660
|
+
"# Tasks\n\n## 1. Demo\n\n- [ ] 1.1 Demo\n"
|
|
661
|
+
" - Covers:\n - cli-cap / CliDemo / CliDemo works\n"
|
|
662
|
+
" - Touch:\n - AGENTS.md\n"
|
|
663
|
+
" - Verify:\n - Strategy: evidence-first\n - Reason: test fixture\n - M1: true\n"
|
|
664
|
+
" - Evidence:\n - Contract: pending\n - M1: pending\n"
|
|
665
|
+
" - Review:\n - Status: pending\n - Acceptance check: pending\n - Scope check: pending\n - Findings: pending\n"
|
|
666
|
+
" - Blocker: none\n - Reauthorizations: none\n\n"
|
|
667
|
+
"## Invalidates\n\n- None.\n\n## Expectation Coverage\n\n- None.\n",
|
|
668
|
+
encoding="utf-8",
|
|
669
|
+
)
|
|
670
|
+
gate_cli = run_keel(repo, "gate", "task-start", "--change", "cli-demo", "--task", "1.1", "--target", "agy", "--json", env=env_stub)
|
|
671
|
+
if gate_cli.returncode != 0:
|
|
672
|
+
report(f"agy-init-doctor-update: CLI gate task-start --target agy failed: {(gate_cli.stderr or gate_cli.stdout).strip()}")
|
|
673
|
+
return 1
|
|
674
|
+
if not (repo / "keel" / "guard.json").is_file():
|
|
675
|
+
report("agy-init-doctor-update: CLI gate task-start --target agy did not write keel/guard.json")
|
|
676
|
+
return 1
|
|
677
|
+
|
|
678
|
+
# 6) keel --update rejects --target agy, and without --target emits read-only AGY notice without modifying agy_cfg
|
|
679
|
+
upd_bad = run_keel(repo, "--update", "--target", "agy", env=env_stub)
|
|
680
|
+
if upd_bad.returncode == 0:
|
|
681
|
+
report("agy-init-doctor-update: keel --update --target agy must exit non-zero")
|
|
682
|
+
return 1
|
|
683
|
+
if "does not accept --target" not in upd_bad.stderr:
|
|
684
|
+
report(f"agy-init-doctor-update: keel --update --target agy wrong error: {upd_bad.stderr!r}")
|
|
685
|
+
return 1
|
|
686
|
+
|
|
687
|
+
upd_env = dict(env_stub)
|
|
688
|
+
upd_env["KEEL_UPDATE_NPM"] = str(stub_bin / "npm")
|
|
689
|
+
upd_env["KEEL_UPDATE_CLAUDE"] = str(stub_bin / "missing-claude")
|
|
690
|
+
upd_env["KEEL_UPDATE_CODEX"] = str(stub_bin / "missing-codex")
|
|
691
|
+
stub_npm = stub_bin / "npm"
|
|
692
|
+
stub_npm.write_text(
|
|
693
|
+
"#!/bin/sh\n"
|
|
694
|
+
"if [ \"$1\" = \"pack\" ]; then\n"
|
|
695
|
+
" dest=\"\"\n"
|
|
696
|
+
" while [ $# -gt 0 ]; do\n"
|
|
697
|
+
" if [ \"$1\" = \"--pack-destination\" ]; then shift; dest=\"$1\"; fi\n"
|
|
698
|
+
" shift\n"
|
|
699
|
+
" done\n"
|
|
700
|
+
" if [ -n \"$dest\" ]; then : > \"$dest/keel-0.0.0.tgz\"; fi\n"
|
|
701
|
+
"fi\n"
|
|
702
|
+
"exit 0\n",
|
|
703
|
+
encoding="utf-8",
|
|
704
|
+
)
|
|
705
|
+
stub_npm.chmod(0o755)
|
|
706
|
+
upd_ok = run_keel(repo, "--update", env=upd_env)
|
|
707
|
+
if upd_ok.returncode != 0:
|
|
708
|
+
report(f"agy-init-doctor-update: keel --update exited {upd_ok.returncode}: {(upd_ok.stderr or upd_ok.stdout).strip()}")
|
|
709
|
+
return 1
|
|
710
|
+
if "agy plugin" not in upd_ok.stdout:
|
|
711
|
+
report(f"agy-init-doctor-update: keel --update missing read-only agy plugin notice: {upd_ok.stdout!r}")
|
|
712
|
+
return 1
|
|
713
|
+
if plugins_json.read_text(encoding="utf-8") != plugins_json_content:
|
|
714
|
+
report("agy-init-doctor-update: keel --update mutated KEEL_AGY_CONFIG_DIR/plugins.json")
|
|
715
|
+
return 1
|
|
716
|
+
|
|
717
|
+
print("agy-init-doctor-update scenario passed.")
|
|
718
|
+
return 0
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
def validate_agy_docs_scenario() -> int:
|
|
722
|
+
with tempfile.TemporaryDirectory(prefix="keel-agy-docs-") as raw:
|
|
723
|
+
base = Path(raw).resolve()
|
|
724
|
+
env = _agy_cli_env(base, base / "agy-cfg")
|
|
725
|
+
|
|
726
|
+
help_res = run_keel(ROOT, "--help", env=env)
|
|
727
|
+
if help_res.returncode != 0:
|
|
728
|
+
report(f"agy-docs: --help exited {help_res.returncode}")
|
|
729
|
+
return 1
|
|
730
|
+
target_lines = [line for line in help_res.stdout.splitlines() if "--target claude|" in line]
|
|
731
|
+
if not target_lines:
|
|
732
|
+
report("agy-docs: --help printed no --target lines")
|
|
733
|
+
return 1
|
|
734
|
+
missing_agy = [line.strip() for line in target_lines if "agy" not in line]
|
|
735
|
+
if missing_agy:
|
|
736
|
+
report(f"agy-docs: --help target lines without agy: {missing_agy}")
|
|
737
|
+
return 1
|
|
738
|
+
|
|
739
|
+
bare = run_keel(base, "--init", "--target", env=env)
|
|
740
|
+
if bare.returncode == 0:
|
|
741
|
+
report("agy-docs: --init --target with no value unexpectedly succeeded")
|
|
742
|
+
return 1
|
|
743
|
+
if "agy" not in bare.stderr:
|
|
744
|
+
report(f"agy-docs: missing-target error does not name agy: {bare.stderr!r}")
|
|
745
|
+
return 1
|
|
746
|
+
|
|
747
|
+
bootstrap = (ROOT / "assets" / "bootstrap" / "AGENTS.md").read_text(encoding="utf-8")
|
|
748
|
+
if "On Claude and AGY a passing `task-start` guards it by default" not in bootstrap:
|
|
749
|
+
report("agy-docs: assets/bootstrap/AGENTS.md must name Claude and AGY for default task-start guard")
|
|
750
|
+
return 1
|
|
751
|
+
|
|
752
|
+
agents_md = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
|
|
753
|
+
if "on Claude and AGY a passing `task-start` writes the disposable write-guard manifest by default" not in agents_md:
|
|
754
|
+
report("agy-docs: AGENTS.md must name Claude and AGY for default task-start guard")
|
|
755
|
+
return 1
|
|
756
|
+
|
|
757
|
+
for name in ("README.md", "README.zh-CN.md"):
|
|
758
|
+
text = (ROOT / name).read_text(encoding="utf-8")
|
|
759
|
+
if "--target agy" not in text:
|
|
760
|
+
report(f"agy-docs: {name} does not document --target agy")
|
|
761
|
+
return 1
|
|
762
|
+
if "AGY" not in text.splitlines()[4]:
|
|
763
|
+
report(f"agy-docs: {name} tagline does not name AGY")
|
|
764
|
+
return 1
|
|
765
|
+
if "AGY" not in text.splitlines()[8]:
|
|
766
|
+
report(f"agy-docs: {name} targets badge does not name AGY")
|
|
767
|
+
return 1
|
|
768
|
+
|
|
769
|
+
print("agy-docs scenario passed.")
|
|
770
|
+
return 0
|