Skip to content

refactor(hermesagent): collapse repeated path expressions and align checks output root - #2484

Merged
dyoshikawa merged 2 commits into
mainfrom
resolve-scrap-issue-2439-hermes-cleanup
Jul 29, 2026
Merged

refactor(hermesagent): collapse repeated path expressions and align checks output root#2484
dyoshikawa merged 2 commits into
mainfrom
resolve-scrap-issue-2439-hermes-cleanup

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

Part of #2439 (findings 3, 4, 6, 7, 8) — the separable cleanups, following #2483 which took findings 1, 2, 5, 9 and 10. Finding 11 (the migration note about stale ~/.hermes/* files) is a release-notes item, not a code change, so the issue stays open for the maintainer to close.

Finding 3 (mid) — the five-times-repeated path comparison

HermesagentCommandAuxiliaryFile rebuilt the same this.getRelativePathFromCwd() === toPosixPath(getHermesagentRelativeFilePath({ global: this.global, relativeFilePath: <CONST> })) expression in shouldMergeExistingFileContent, setFileContent, and three branches of getFileContent. A private matchesPath(relativeFilePath) collapses ~40 lines to five call sites and removes the chance of pairing a branch with the wrong constant.

Finding 4 (low) — duplication against the kimi-code utility

getHermesagentRulesyncOutputRoot and getKimiCodeRulesyncOutputRoot were identical apart from the home getter, so both now delegate to a shared getToolRulesyncOutputRoot({ nativeOutputRoot, global, toolHome }).

One deviation from the issue's suggestion: it lives in a new src/utils/tool-home.ts rather than in tool-output-root.ts. tool-output-root.ts imports both tool utils, so putting the helper there and importing it back would have created a genuine hermesagent → tool-output-root → hermesagent cycle. The new module is a leaf that imports only getHomeDirectory.

The issue's local duplication is gone too: getHermesagentRelativeDirPath({ global, relativeDirPath: <PLUGIN_DIR> }) was spelled out three times in hermesagent-command.ts and twice in hermesagent-subagent.ts, and is now one const pluginDirPath per function.

Finding 6 (low) — per-class global coverage

HermesagentMcp, HermesagentHooks, HermesagentPermissions, HermesagentSkill and HermesagentSubagent each get a getSettablePaths({ global: true }) case in both configurations: anchored on the platform profile directory when HERMES_HOME is unset, and de-prefixed when it names the profile root. Previously only the helper in src/utils/hermesagent.ts and the e2e suite covered this.

Finding 7 (low) — convert/generate disagreement on checks

generateChecksCore passed outputRoot verbatim while convert.ts's buildChecksStrategy already ran it through resolveToolOutputRoot. Aligned. generateIgnoreCore is deliberately left alone, per the comment justifying its verbatim pass-through.

Finding 8 (low) — undocumented precedence

docs/reference/cli-commands.md gains a short section stating that HERMES_HOME / KIMI_CODE_HOME override outputRoots and --output-roots in global scope, why (the variable names where the tool itself looks), and that an unusable value is rejected with an error naming the variable. Skill docs synced.

Verification

Full pnpm cicheck is green (8054 unit tests). The Hermes-touching e2e specs pass locally. No behavior change is intended anywhere except generateChecksCore, which now matches the convert path.

🤖 Generated with Claude Code

cm-dyoshikawa and others added 2 commits July 29, 2026 11:51
…hecks output root

The remaining #2439 cleanups (findings 3, 4, 6, 7, 8):

- HermesagentCommandAuxiliaryFile compared its own path against a rebuilt
  getHermesagentRelativeFilePath five times; a private matchesPath helper
  replaces the block and makes passing the wrong constant impossible.
- getHermesagentRulesyncOutputRoot and getKimiCodeRulesyncOutputRoot differed
  only in which home getter they called, so both delegate to a shared
  getToolRulesyncOutputRoot parameterized by that getter. It lives in a new
  leaf module rather than tool-output-root.ts, which would have formed an
  import cycle with the two tool utils. The plugin dir expression repeated
  three times in hermesagent-command.ts and twice in hermesagent-subagent.ts
  is now one local const each.
- Per-class getSettablePaths({ global: true }) coverage with HERMES_HOME both
  set and unset, on all five global Hermes classes.
- generateChecksCore resolves the tool output root like convert.ts's
  buildChecksStrategy already did; generateIgnoreCore is left alone per its
  comment.
- Documents that HERMES_HOME/KIMI_CODE_HOME override --output-roots in global
  scope, and that an unusable value is rejected naming the variable.

Part of #2439 (findings 3, 4, 6, 7, 8).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ation

Review follow-ups (all low):

- The global settable-path tests compared against getHermesagentGlobalDir(),
  which restates the implementation rather than asserting it; both platform
  literals are pinned instead. Unit CI is ubuntu-only, so the win32 arm was
  otherwise unasserted anywhere.
- getKimiCodeRulesyncOutputRoot gained a test: the shared helper extraction
  rewrote two call sites but only the hermes one was covered.
- Records why generateIgnoreCore still passes outputRoot verbatim after checks
  was aligned — the tools with a home override are not global ignore targets.
- The precedence note mentions convert as well as generate, and links to the
  Hermes profile description in supported-tools.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dyoshikawa
dyoshikawa merged commit 38671a9 into main Jul 29, 2026
9 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-scrap-issue-2439-hermes-cleanup branch July 29, 2026 19:12
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