Skip to content

refactor(desktop): extract use-prompt-actions standalone helpers into utils - #55459

Merged
OutThisLife merged 1 commit into
mainfrom
bb/desktop-split-prompt-actions
Jun 30, 2026
Merged

refactor(desktop): extract use-prompt-actions standalone helpers into utils#55459
OutThisLife merged 1 commit into
mainfrom
bb/desktop-split-prompt-actions

Conversation

@OutThisLife

Copy link
Copy Markdown
Collaborator

Summary

Fifth in the apps/desktop god-file split series. usePromptActions is the textbook "god hook" AGENTS.md's TS guidance warns against. As a first, safe slice, this pulls the hook's module-level standalone helpers (no closure over hook state) into a focused, testable use-prompt-actions-utils.ts sibling.

use-prompt-actions.ts: 1,956 → 1,772 lines.

Moved into use-prompt-actions-utils.ts

  • error classifiers: isSessionNotFoundError, isSessionBusyError, isProviderSetupError, inlineErrorMessage
  • session-busy retry: withSessionBusyRetry (+ SESSION_BUSY_RETRY_* constants)
  • attachment IO: base64FromDataUrl, imageFilenameFromPath, readImageForRemoteAttach, readFileDataUrlForAttach, friendlyRemoteAttachError
  • misc: delay, isSessionIdCandidate, blobToDataUrl, renderCommandsCatalog, slashStatusText, appendText, visibleUserOrdinal, visibleUserIndexAtOrdinal, the _submitInFlight guard set, and the GatewayRequest type

Notes

  • Pure restructuring — no behavior change. Helpers moved verbatim; the usePromptActions and uploadComposerAttachment exports (and their import paths in thread.tsx / desktop-controller.tsx / the test) are unchanged.
  • A deeper decomposition of the hook body (slash dispatch, submit/retry, attachment upload, restore targeting) into colocated sub-hooks is left for a dedicated follow-up — that's a stateful refactor, not a pure move.

Test plan

  • npm run typecheck (desktop) — passes
  • eslint on changed/added files — clean
  • vitest run for use-prompt-actions-utils.test.ts + the existing use-prompt-actions.test.tsx — 51 pass
  • Smoke-test: submit, queue drain, slash commands (/help, /model, …), remote attachment upload, message edit/restore

Note: a whole-tree npm run lint reports 4 pre-existing errors in unrelated files on main; none are touched here.

… utils

The usePromptActions hook is the textbook "god hook" AGENTS.md warns against.
As a first, safe slice, pull its module-level standalone helpers (no closure
over hook state) into a focused, testable use-prompt-actions-utils.ts sibling:

- error classifiers: isSessionNotFoundError, isSessionBusyError,
  isProviderSetupError, inlineErrorMessage
- session-busy retry: withSessionBusyRetry (+ its constants)
- attachment IO: base64FromDataUrl, imageFilenameFromPath,
  readImageForRemoteAttach, readFileDataUrlForAttach, friendlyRemoteAttachError
- misc: delay, isSessionIdCandidate, blobToDataUrl, renderCommandsCatalog,
  slashStatusText, appendText, visibleUserOrdinal, visibleUserIndexAtOrdinal,
  the _submitInFlight guard set, and the GatewayRequest type

Pure restructuring, no behavior change; the usePromptActions and
uploadComposerAttachment exports (and their import paths) are unchanged. Adds
unit tests for the pure helpers. use-prompt-actions.ts: 1,956 -> 1,772.
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have labels Jun 30, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary\n\nVerdict: LGTM\n\nClean god-file split — use-prompt-actions.ts reduced from 1,956 to 1,772 lines by extracting standalone helpers into use-prompt-actions-utils.ts. Pure restructuring with no behavior change. Tests pass (51 unit tests). Well-scoped 3-file change with clear module boundaries.\n\n### Looks Good\n- Verbatim move of standalone helpers with no logic changes\n- New test file covers the extracted functions\n- TypeCheck and ESLint clean\n---\nReviewed by Hermes Agent

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review: LGTM

Clean extraction of prompt-action utility functions into a dedicated use-prompt-actions-utils.ts module. All exported functions have unit tests covering edge cases (session ID candidates, error message parsing, data URL extraction, image filename extraction, etc.). The parent hook imports from the new module without behavioral change.

Verdict: LGTM -- well-tested god-file reduction.

@OutThisLife
OutThisLife merged commit 28ba01c into main Jun 30, 2026
40 of 41 checks passed
@OutThisLife
OutThisLife deleted the bb/desktop-split-prompt-actions branch June 30, 2026 07:19
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…lit-prompt-actions

refactor(desktop): extract use-prompt-actions standalone helpers into utils
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…lit-prompt-actions

refactor(desktop): extract use-prompt-actions standalone helpers into utils
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…lit-prompt-actions

refactor(desktop): extract use-prompt-actions standalone helpers into utils
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…lit-prompt-actions

refactor(desktop): extract use-prompt-actions standalone helpers into utils
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…lit-prompt-actions

refactor(desktop): extract use-prompt-actions standalone helpers into utils
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 2026
…lit-prompt-actions

refactor(desktop): extract use-prompt-actions standalone helpers into utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants