feat(plugins): enable Impeccable hooks for Codex and trim extensions
- Register Impeccable's design-detector PostToolUse and Stop hooks in the Codex config through new no-op-safe wrappers; Claude already gets them from the Impeccable plugin. - Make Caveman Claude-only: a '-' codex_method marks Claude-only entries, which the Codex selector omits and sync removes from owned Codex installs. Drop the thinkhome Caveman Windows hook repair. - Remove Anthropic Frontend Design from the manifest, plugin workflow, and docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb7cecaaa2
commit
f7222a90c2
20 files changed
+109
-95
No files matched your search
@@ -109,6 +109,39 @@ class InstallOptionsTests(unittest.TestCase):
|
||||
self.assertNotIn('qmd-warm', result)
|
||||
self.assertNotIn('hooks.SessionStart', result)
|
||||
|
||||
def test_codex_merge_registers_impeccable_hooks_once(self):
|
||||
managed = (ROOT / 'adapters/codex/config/config.toml').read_text(encoding='utf-8')
|
||||
managed = managed.replace('__IMPECCABLE_HOOK_SCRIPT__', 'invoke-impeccable-hook.sh')
|
||||
merged = OPTIONS.merge_toml(OPTIONS.merge_toml('', managed), managed)
|
||||
hooks = tomllib.loads(merged)['hooks']
|
||||
impeccable = lambda groups: [group for group in groups if 'impeccable-hook' in group['hooks'][0]['command']]
|
||||
self.assertEqual(1, len(impeccable(hooks['PostToolUse'])))
|
||||
self.assertEqual('Edit|Write|apply_patch', impeccable(hooks['PostToolUse'])[0]['matcher'])
|
||||
self.assertEqual(1, len(impeccable(hooks['Stop'])))
|
||||
|
||||
def test_impeccable_hook_wrappers_forward_event_or_are_noops(self):
|
||||
scripts = ROOT / 'shared/hooks/scripts'
|
||||
shells = [(shutil.which('bash'), [], 'invoke-impeccable-hook.sh', 'impeccable', 'printf "%s:" "$1"; cat\n')]
|
||||
if os.name == 'nt':
|
||||
shells.append((shutil.which('powershell'), ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File'],
|
||||
'Invoke-ImpeccableHook.ps1', 'impeccable.cmd', '@echo off\r\n<nul set /p=%1:\r\nmore\r\n'))
|
||||
for executable, arguments, name, launcher_name, launcher_body in shells:
|
||||
if not executable:
|
||||
continue
|
||||
with self.subTest(shell=name), tempfile.TemporaryDirectory() as directory:
|
||||
home = Path(directory)
|
||||
env = dict(os.environ, HOME=str(home), USERPROFILE=str(home), CODEX_HOME=str(home / '.codex'))
|
||||
run = lambda: subprocess.run([executable, *arguments, str(scripts / name)], input='{"event":1}',
|
||||
env=env, capture_output=True, text=True, timeout=60)
|
||||
result = run()
|
||||
self.assertEqual((0, ''), (result.returncode, result.stdout), result.stderr)
|
||||
launcher = home / '.agents/skills/impeccable/scripts' / launcher_name
|
||||
launcher.parent.mkdir(parents=True)
|
||||
launcher.write_text(launcher_body, newline='')
|
||||
result = run()
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('hook:{"event":1}', result.stdout.strip())
|
||||
|
||||
def test_instruction_line_only_with_semantic_search(self):
|
||||
text = 'Line one.\nWhen `semantic-search` is installed, run it first.\nLine three.\n'
|
||||
self.assertEqual(OPTIONS.filter_instructions(text, False), 'Line one.\nLine three.\n')
|
||||
|
||||
@@ -224,55 +224,14 @@ class ManagedExtensionTests(unittest.TestCase):
|
||||
self.manager().sync([plugin()], ['claude'], {'Example'})
|
||||
self.assertEqual(3, command.call_count)
|
||||
|
||||
@unittest.skipUnless(os.name == 'nt', 'Windows hook compatibility')
|
||||
def test_owned_caveman_hook_repair_runs_in_powershell_and_is_idempotent(self):
|
||||
entry = dict(plugin('Caveman'), codex_plugin='caveman@thinkhome-caveman')
|
||||
root = self.home / '.codex/plugins/cache/thinkhome-caveman/caveman/1.0.0'
|
||||
path = root / 'hooks/hooks.json'
|
||||
path.parent.mkdir(parents=True)
|
||||
hook = {'type': 'command', 'command': 'unchanged',
|
||||
'commandWindows': 'node "%PLUGIN_ROOT%\\hooks\\caveman-hook.mjs"'}
|
||||
path.write_text(json.dumps({'hooks': {event: [{'hooks': [dict(hook)]}]
|
||||
for event in ['SessionStart', 'UserPromptSubmit', 'SubagentStart']}}))
|
||||
upstream = path.read_bytes()
|
||||
self.manager().sync([entry], ['codex'], {'Caveman'})
|
||||
repaired = path.read_bytes()
|
||||
for groups in json.loads(repaired)['hooks'].values():
|
||||
self.assertNotIn('%PLUGIN_ROOT%', groups[0]['hooks'][0]['commandWindows'])
|
||||
self.assertEqual('unchanged', groups[0]['hooks'][0]['command'])
|
||||
self.manager().sync([entry], ['codex'], {'Caveman'})
|
||||
self.assertEqual(repaired, path.read_bytes())
|
||||
path.write_bytes(upstream)
|
||||
self.manager(update=True).sync([entry], ['codex'], {'Caveman'})
|
||||
self.assertEqual(repaired, path.read_bytes())
|
||||
if not shutil.which('node'):
|
||||
self.skipTest('Node is unavailable for launcher execution')
|
||||
(root / 'hooks/caveman-hook.mjs').write_text("process.stdout.write('hook-ok');")
|
||||
command = json.loads(repaired)['hooks']['SessionStart'][0]['hooks'][0]['commandWindows']
|
||||
result = subprocess.run(['powershell', '-NoProfile', '-Command', command],
|
||||
env=dict(os.environ, PLUGIN_ROOT=str(root)), capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('hook-ok', result.stdout)
|
||||
|
||||
@unittest.skipUnless(os.name == 'nt', 'Windows hook compatibility')
|
||||
def test_caveman_repair_preserves_foreign_and_custom_hooks_and_dry_runs(self):
|
||||
entry = dict(plugin('Caveman'), codex_plugin='caveman@thinkhome-caveman')
|
||||
path = self.home / '.codex/plugins/cache/thinkhome-caveman/caveman/1.0.0/hooks/hooks.json'
|
||||
path.parent.mkdir(parents=True)
|
||||
original = json.dumps({'hooks': {'SessionStart': [{'hooks': [{'commandWindows':
|
||||
'node "%PLUGIN_ROOT%\\hooks\\caveman-hook.mjs"'}]}]}}).encode()
|
||||
path.write_bytes(original)
|
||||
self.installed['codex'][entry['codex_plugin']] = {}
|
||||
self.manager().sync([entry], ['codex'], {'Caveman'})
|
||||
self.assertEqual([], self.manager().state['resources'])
|
||||
self.assertEqual(original, path.read_bytes())
|
||||
self.installed['codex'].clear()
|
||||
self.manager(dry_run=True).sync([entry], ['codex'], {'Caveman'})
|
||||
self.assertEqual(original, path.read_bytes())
|
||||
original = b'{"hooks":{"SessionStart":[{"hooks":[{"commandWindows":"custom"}]}]}}'
|
||||
path.write_bytes(original)
|
||||
self.manager().sync([entry], ['codex'], {'Caveman'})
|
||||
self.assertEqual(original, path.read_bytes())
|
||||
def test_claude_only_entry_removes_owned_codex_install_and_keeps_claude(self):
|
||||
self.manager().sync([plugin('Caveman')], ['claude', 'codex'], {'Caveman'})
|
||||
installed = len(self.commands)
|
||||
claude_only = dict(plugin('Caveman'), codex_method='-', codex_plugin='-')
|
||||
for action in ('install', 'sync'):
|
||||
self.manager().sync([claude_only], ['claude', 'codex'], {'Caveman'}, action)
|
||||
self.assertEqual([['codex', 'plugin', 'remove', 'caveman@test']], [c for c in self.commands[installed:] if c[0] == 'codex'])
|
||||
self.assertEqual(['claude'], [r['client'] for r in self.manager().state['resources']])
|
||||
|
||||
def test_dry_run_summary_has_one_line(self):
|
||||
with contextlib.redirect_stdout(io.StringIO()) as output:
|
||||
|
||||
@@ -37,7 +37,7 @@ catch { $failed = $true }
|
||||
$env:AI_CONFIG_VERBOSE = $null
|
||||
if (-not $failed -or $diagnostics -notcontains 'download progress' -or $diagnostics -notcontains 'WARN test warning') { throw 'Plugin failure must retain full diagnostics and fail.' }
|
||||
$global:LASTEXITCODE = 0
|
||||
$script:codexInventory = '{"installed":[{"pluginId":"ponytail@ponytail"},{"pluginId":"i-have-adhd@i-have-adhd"},{"pluginId":"superpowers@openai-curated-remote"},{"pluginId":"context7@context7-marketplace"},{"pluginId":"caveman@thinkhome-caveman"}],"available":[]}'
|
||||
$script:codexInventory = '{"installed":[{"pluginId":"ponytail@ponytail"},{"pluginId":"i-have-adhd@i-have-adhd"},{"pluginId":"superpowers@openai-curated-remote"},{"pluginId":"context7@context7-marketplace"}],"available":[]}'
|
||||
function codex { $script:observedCodexHome = $env:CODEX_HOME; $script:observedProfile = $env:USERPROFILE; $script:codexInventory }
|
||||
$testHome = Join-Path ([System.IO.Path]::GetTempPath()) 'ai-config-plugin-test-home'
|
||||
$previousCodexHome = [Environment]::GetEnvironmentVariable('CODEX_HOME', 'Process')
|
||||
@@ -47,7 +47,8 @@ if ($observedCodexHome -ne (Join-Path $testHome '.codex') -or $observedProfile -
|
||||
if ([Environment]::GetEnvironmentVariable('CODEX_HOME', 'Process') -ne $previousCodexHome -or [Environment]::GetEnvironmentVariable('USERPROFILE', 'Process') -ne $previousProfile) { throw 'Plugin inspection must restore the process environment.' }
|
||||
$script:answers.Enqueue('done')
|
||||
$selection = Select-ConfiguredPlugins -RepositoryRoot (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -Client Codex -Mode Update
|
||||
if (@($selection.Selected | Where-Object { $_.codex_method -eq 'plugin' }).Count -ne 5) { throw 'All installed Codex plugins must start checked when updating.' }
|
||||
if (@($selection.Selected | Where-Object { $_.codex_method -eq 'plugin' }).Count -ne 4) { throw 'All installed Codex plugins must start checked when updating.' }
|
||||
if (@($selection.Selected + $selection.Deselected | Where-Object { $_.name -eq 'Caveman' }).Count) { throw 'Claude-only extensions must not be offered for Codex.' }
|
||||
$script:answers.Enqueue('4')
|
||||
$script:answers.Enqueue('done')
|
||||
$selection = Select-ConfiguredPlugins -RepositoryRoot (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -Client Codex -Mode Update
|
||||
|
||||
@@ -48,6 +48,7 @@ select_configured_plugins "$root" codex Update true selected deselected
|
||||
printf '%s\n' '{"mcpServers":{"context7":{"baseUrl":"https://example.invalid/mcp"}}}' > "$test_home/.mcporter/mcporter.json"
|
||||
select_configured_plugins "$root" codex Update true selected deselected
|
||||
[[ " ${deselected[*]} " == *' Context7 '* ]] || { printf 'A different MCPorter server must not select Context7.\n' >&2; exit 1; }
|
||||
[[ " ${selected[*]} ${deselected[*]} " != *' Caveman '* ]] || { printf 'Claude-only extensions must not be offered for Codex.\n' >&2; exit 1; }
|
||||
npm_prefix=$(mktemp -d "$root/.npm-test.XXXXXX")
|
||||
cli_name="ai-config-test-cli-${npm_prefix##*.}"
|
||||
npm() { printf '%s\n' "$npm_prefix"; }
|
||||
|
||||
@@ -35,15 +35,15 @@ class SelectionTests(unittest.TestCase):
|
||||
self.assertFalse(self.path.exists())
|
||||
|
||||
def test_selection_round_trip_and_last_successful_write(self):
|
||||
self.save('--selected', 'Superpowers', 'Anthropic Frontend Design', '--deselected', 'Context7')
|
||||
self.save('--selected', 'Superpowers', 'Humanizer', '--deselected', 'Context7')
|
||||
original = self.path.read_bytes()
|
||||
state = json.loads(self.run_state('read').stdout)
|
||||
self.assertEqual(state['shell'], 'powershell')
|
||||
self.assertEqual(state['client'], 'both')
|
||||
self.assertEqual(state['selected'], ['Superpowers', 'Anthropic Frontend Design'])
|
||||
self.assertEqual(state['selected'], ['Superpowers', 'Humanizer'])
|
||||
self.assertEqual(state['deselected'], ['Context7'])
|
||||
self.assertEqual(self.path.read_bytes(), original)
|
||||
self.assertIn('selected\tAnthropic Frontend Design', self.run_state('read', '--format', 'tsv').stdout)
|
||||
self.assertIn('selected\tHumanizer', self.run_state('read', '--format', 'tsv').stdout)
|
||||
self.save('--selected', 'Context7')
|
||||
self.assertEqual(json.loads(self.run_state('read').stdout)['selected'], ['Context7'])
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ foreach ($shell in @('powershell','bash')) {
|
||||
if ($shell -eq 'powershell' -and $content -match 'WindowStyle\s+Hidden') { throw "PowerShell hook hides the terminal in $package" }
|
||||
if ($client -eq 'codex') {
|
||||
$events = @([regex]::Matches($content, '(?m)^\[\[hooks\.([^.\]]+)\]\]\s*$') | ForEach-Object { $_.Groups[1].Value })
|
||||
if ((($events | Sort-Object) -join ',') -ne 'PreToolUse,SessionStart,Stop,Stop,UserPromptSubmit' -or $content -match 'flashbang-if-input' -or $content -match '(?m)^async\s*=\s*true\s*$') { throw "Codex finish hook is incorrect in $package" }
|
||||
if ((($events | Sort-Object) -join ',') -ne 'PostToolUse,PreToolUse,SessionStart,Stop,Stop,Stop,UserPromptSubmit' -or $content -match 'flashbang-if-input' -or $content -match '(?m)^async\s*=\s*true\s*$') { throw "Codex finish hook is incorrect in $package" }
|
||||
if ($content -notmatch 'approvals_reviewer\s*=\s*"auto_review"') { throw "Codex auto review is missing in $package" }
|
||||
if ($content -notmatch '(?m)^sandbox_mode\s*=\s*"danger-full-access"\s*$') { throw "Codex full access is missing in $package" }
|
||||
if ($content -notmatch '(?m)^max_depth\s*=\s*1\s*$') { throw "Codex agent depth limit is missing in $package" }
|
||||
|
||||
@@ -80,7 +80,7 @@ for shell in powershell bash; do
|
||||
grep -q 'bash .*flashbang.sh' "$package/$file"
|
||||
fi
|
||||
if [ "$client" = codex ]; then
|
||||
[ "$(sed -n 's/^\[\[hooks\.\([^].]*\)\]\][[:space:]]*$/\1/p' "$package/$file" | sort)" = $'PreToolUse\nSessionStart\nStop\nStop\nUserPromptSubmit' ]
|
||||
[ "$(sed -n 's/^\[\[hooks\.\([^].]*\)\]\][[:space:]]*$/\1/p' "$package/$file" | sort)" = $'PostToolUse\nPreToolUse\nSessionStart\nStop\nStop\nStop\nUserPromptSubmit' ]
|
||||
! grep -q 'flashbang-if-input' "$package/$file"
|
||||
! grep -Eq '^async[[:space:]]*=[[:space:]]*true[[:space:]]*$' "$package/$file"
|
||||
grep -q 'approvals_reviewer[[:space:]]*=[[:space:]]*"auto_review"' "$package/$file"
|
||||
|
||||
Reference in new issue
Block a user