Skip to content

refactor(hooks): use shared converter for Codex CLI, add auxiliary file support and TOML error handling#1535

Merged
dyoshikawa merged 1 commit intomainfrom
codex/fix-issue-1445-in-rulesync
Apr 21, 2026
Merged

refactor(hooks): use shared converter for Codex CLI, add auxiliary file support and TOML error handling#1535
dyoshikawa merged 1 commit intomainfrom
codex/fix-issue-1445-in-rulesync

Conversation

@dyoshikawa
Copy link
Copy Markdown
Owner

Motivation

  • Reduce duplicated Codex CLI hooks conversion logic by reusing a shared converter and make Codex-specific behavior configurable.
  • Ensure .codex/config.toml generation preserves existing [features] and surfaces parse errors clearly.
  • Generalize auxiliary file generation so processors do not need tool-specific branching.

Description

  • Introduced supportedHookTypes and passthroughFields options to ToolHooksConverterConfig and updated canonicalToToolHooks/toolHooksToCanonical to honor them and to drop empty entries.
  • Refactored CodexcliHooks to use the shared canonicalToToolHooks/toolHooksToCanonical with a CODEXCLI_CONVERTER_CONFIG (command-only, passthrough name/description, no project-dir prefix).
  • Added robust TOML parsing in buildCodexConfigTomlContent to throw a readable error on invalid .codex/config.toml and preserve existing [features] values while enabling codex_hooks.
  • Added ToolHooks.getAuxiliaryFiles() (default no-op) and CodexcliHooks.getAuxiliaryFiles() to return the generated CodexcliConfigToml, and updated HooksProcessor to merge auxiliary files into results instead of using a codex-specific branch.
  • Updated and added tests to cover Codex CLI conversion, auxiliary file generation, preservation of existing [features], and TOML parse error behavior, and updated code formatting/types accordingly.

Testing

  • Ran targeted unit tests: pnpm vitest run src/features/hooks/codexcli-hooks.test.ts src/features/hooks/hooks-processor.test.ts and they passed (both files passed during iterative runs).
  • Ran full repository checks with pnpm cicheck (includes formatting, linting, typecheck, and the entire test suite) and it completed successfully with all tests passing.
  • Fixed initial formatting/type issues and re-ran pnpm fmt and pnpm cicheck until clean; final run reports all tests green.

Codex Task

Copilot AI review requested due to automatic review settings April 21, 2026 14:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Codex CLI hooks conversion to reuse the shared hooks converter, adds a generic auxiliary-file mechanism for hook processors, and improves .codex/config.toml generation by preserving existing [features] values and surfacing TOML parse errors.

Changes:

  • Extended the shared hooks converter with supportedHookTypes + passthroughFields, and made export drop empty matcher/event entries.
  • Refactored CodexcliHooks to use the shared converter and added robust TOML parsing/preservation for .codex/config.toml.
  • Added ToolHooks.getAuxiliaryFiles() and updated HooksProcessor to merge auxiliary generated files (e.g., Codex config.toml) without tool-specific branching; updated tests accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/features/hooks/tool-hooks.ts Adds a base getAuxiliaryFiles() hook for tools to emit extra generated files.
src/features/hooks/tool-hooks-converter.ts Adds converter config options for hook-type filtering and passthrough fields; drops empty outputs.
src/features/hooks/hooks-processor.ts Removes codex-specific branching and merges auxiliary files from hook tool classes.
src/features/hooks/hooks-processor.test.ts Adds coverage ensuring Codex conversion returns hooks + auxiliary config TOML.
src/features/hooks/codexcli-hooks.ts Switches Codex hooks conversion to the shared converter and improves .codex/config.toml parsing/error reporting.
src/features/hooks/codexcli-hooks.test.ts Adds tests for [features] preservation and readable TOML parse errors.

Comment on lines 174 to 180
: cmd;
const hookType = h.type === "command" || h.type === "prompt" ? h.type : "command";
const timeout = typeof h.timeout === "number" ? h.timeout : undefined;
const prompt = typeof h.prompt === "string" ? h.prompt : undefined;
defs.push({
type: hookType,
...(command !== undefined && command !== null && { command }),
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supportedHookTypes is applied in canonicalToToolHooks, but toolHooksToCanonical currently ignores it and will import prompt hooks (etc.) into canonical config even when a converter config declares command-only support (e.g. Codex CLI). Apply the same supportedHookTypes filtering on import so round-trips don’t reintroduce unsupported hook types.

Copilot uses AI. Check for mistakes.
Comment on lines 161 to +167
const hookDefs = rawEntry.hooks ?? [];
for (const h of hookDefs) {
const cmd = typeof h.command === "string" ? h.command : undefined;
const command =
typeof cmd === "string" && cmd.includes(`${converterConfig.projectDirVar}/`)
converterConfig.projectDirVar !== "" &&
typeof cmd === "string" &&
cmd.includes(`${converterConfig.projectDirVar}/`)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toolHooksToCanonical assumes every element in rawEntry.hooks is a non-null object. If a tool config contains hooks: [null] (or other non-object values), h.command / h.type access will throw at runtime during import. Add a guard inside the for (const h of hookDefs) loop to skip non-object entries before reading properties.

Copilot uses AI. Check for mistakes.
@dyoshikawa dyoshikawa merged commit 67811a4 into main Apr 21, 2026
14 checks passed
@dyoshikawa dyoshikawa deleted the codex/fix-issue-1445-in-rulesync branch April 21, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants