Skip to content

refactor(translate): register translators per agent - #139

Merged
Stephen Belanger (Qard) merged 3 commits into
mainfrom
refactor/register-translators
Oct 6, 2026
Merged

Stephen Belanger (Qard) merged 3 commits into
mainfrom
refactor/register-translators

Conversation

@Qard

@Qard Stephen Belanger (Qard) commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Based on main now that #138 has merged.

Registry::default_agents() built each translator factory by hand. Source aliases went through canonical_source_name plus a second hardcoded allowlist in Registry::canonical_source, which duplicated the agent identities. With this PR:

  • Agents are their own factories. TranslatorFactory now has Agent as its supertrait and no source method. Each agent type implements it directly in its translator module and registers itself alongside its other capabilities, and the registry keys factories by identity().source. The seven per-agent *TranslatorFactory structs are gone, and so is the intermediate Translate trait:

    pub(crate) trait TranslatorFactory: Agent {
        fn create(&self, session_id: &str) -> Box<dyn AgentTranslator>;
    }
  • Registry construction. Registry::default_agents() registers every agent that registered a translator, plus the debug translator, as before. The debug translator has its own debug identity but isn't in the agent registry, since it isn't a coding agent.

  • Public API. Agent is crate-private, so TranslatorFactory is too. It and the unused Registry::register are no longer exported. Nothing outside the crate implemented the trait or registered factories; the bt CLI doesn't use either.

  • Shared Git metadata cache. The cache is now process-wide instead of one per registry. That's safe because repository entries are revalidated against the git directory before reuse and "not a repository" results expire. A daemon already uses a single registry, so in practice only tests and imports in the same process now share it.

  • Alias resolution. canonical_source_name and Registry::canonical_source now resolve names through the agents' identities. Accepted names are each agent's id, its hook source, and its aliases, plus debug. Factories that a host registers under any other name are still rejected, as before.

Behaviour

None. The registered sources, the accepted aliases (claude → claude-code, open-code → opencode) and the rejection of unknown sources are unchanged. Two new tests pin them.

Testing

  • cargo clippy --all-features --all-targets -D warnings is clean.
  • cargo test --all-features --no-fail-fast: everything passes except trace_runtime::tests::doctor_reports_a_daemon_that_{cannot_authenticate_the_route,resolves_other_credentials}, which fail the same way on main in my local environment.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T12:39:56.368160Z caadc9e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-managed-run branch from f264028 to cd40bdb Compare October 6, 2026 14:04
@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-translators branch from 4a46d82 to 6184632 Compare October 6, 2026 14:04
@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-managed-run branch from cd40bdb to 2e38e1a Compare October 6, 2026 14:48
@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-translators branch from 6184632 to 86eb942 Compare October 6, 2026 14:48
@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-managed-run branch from 2e38e1a to f20a120 Compare October 6, 2026 15:03
@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-translators branch from 86eb942 to b6fe0b1 Compare October 6, 2026 15:03
Base automatically changed from refactor/register-managed-run to main October 6, 2026 15:21
Registry::default_agents constructed each agent's translator factory by
hand, and source aliases were resolved through a separate hardcoded
alias table and allowlist. Each agent type now implements `Translate`
in its translator module and registers it with the others. The
registry builds one factory per registered agent around the shared Git
metadata cache, and alias resolution uses the agents' identities.

The accepted hook sources and aliases are unchanged. A test pins them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Qard
Stephen Belanger (Qard) force-pushed the refactor/register-translators branch from b6fe0b1 to ed5dc88 Compare October 6, 2026 16:59
`Translate` existed only to inject the shared Git metadata cache into a
per-agent factory struct. Each agent type now implements the public
`TranslatorFactory` directly, and the cache is process-wide. That is
safe because repository entries are revalidated against the git
directory before reuse and negative results expire. The seven factory
structs and their `Translate` impls are gone. `Translate` remains only
as an empty marker joining `Agent` and `TranslatorFactory`, implemented
for every such type, so the registry can find agents by name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`TranslatorFactory::source` restated what each agent's identity already
says. The trait now takes `Agent` as its supertrait, and the registry
keys factories by `identity().source`. That makes the `Translate`
marker unnecessary, so it is removed and the agent registry holds
`dyn TranslatorFactory` directly. The debug translator gets its own
`debug` identity but stays out of the agent registry.

`Agent` is crate-private, so `TranslatorFactory` is too. It and the
unused `Registry::register` leave the public API. Nothing outside the
crate implemented the trait or registered factories.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Qard
Stephen Belanger (Qard) merged commit 4a2d822 into main Oct 6, 2026
20 checks passed
@Qard
Stephen Belanger (Qard) deleted the refactor/register-translators branch October 6, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants