Skip to content

refactor(web): extract input-history recall into a composable#1011

Merged
wbxl2000 merged 2 commits into
mainfrom
refactor/web-extract-input-history
Jun 23, 2026
Merged

refactor(web): extract input-history recall into a composable#1011
wbxl2000 merged 2 commits into
mainfrom
refactor/web-extract-input-history

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

Part of the apps/kimi-web god-component split tracked in web-refactor-plan.md (follows #998 Sidebar→WorkspaceGroup, #1001 ChatPane helpers, #1010 ConversationPane→ConversationToc). This is the first, lowest-risk step of splitting Composer.vue (the hot-path component deferred to last). No standalone issue.

Problem

Composer.vue is the largest remaining god component (~2100 lines) and the hottest input path: it owns the draft, the slash and mention menus, attachment upload, the toolbar, and the keydown orchestration. The plan calls for splitting it into focused composables. This PR takes the cleanest, least-coupled slice first — the shell-style ↑/↓ recall of previously sent messages — which touches only the text ref, the textarea ref, and autosize, and has no dependency on props or emits.

What changed

  • New apps/kimi-web/src/composables/useInputHistory.ts:
    • Owns the history list, the browsing cursor, and the textarea caret/selection work needed to apply a recalled entry.
    • Takes { text, textareaRef, autosize } as deps (same DI shape as the existing useXxx(rawState, deps) client modules) and returns push, caretAtFirstLine, recallOlder, recallNewer, resetBrowsing, isBrowsing, hasHistory.
  • Composer.vue:
    • Replaces the inline history block with const history = useInputHistory({ text, textareaRef, autosize });.
    • handleInput calls history.resetBrowsing(); submit/steer call history.push(trimmed); the keydown handler reads history.isBrowsing() / history.hasHistory() / history.caretAtFirstLine() and calls history.recallOlder() / history.recallNewer().
    • The keydown orchestration stays in the composer — it also juggles the slash and mention menus, so it belongs at the call site rather than inside the history composable.
    • 2104 → 2050 lines.

No user-visible behavior change. Logic moved verbatim; only the call sites were re-wired.

Verification

  • pnpm --filter @moonshot-ai/kimi-web typecheck — pass (vue-tsc --noEmit)
  • pnpm --filter @moonshot-ai/kimi-web test — 40 passed
  • pnpm --filter @moonshot-ai/kimi-web build — pass
  • oxlint --type-aware on the two changed files — 0 warnings, 0 errors

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (N/A — pure refactor; the web app has no component tests since test(kimi-web): keep only pure logic unit tests #959. vue-tsc --noEmit is the safety net, plus manual verification.)
  • Ran gen-changesets skill, or this PR needs no changeset. (Added .changeset/web-extract-composer-input-history.md, patch on @moonshot-ai/kimi-code.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing change.)

Move the shell-style up/down recall of previously sent messages out of
Composer into useInputHistory. The composable owns the history list, the
browsing cursor, and the textarea caret/selection work needed to apply a
recalled entry, taking the text ref, textarea ref, and autosize as deps.

The composer keeps the keydown orchestration (which also juggles the slash
and mention menus) and calls into the composable for push / recall / caret /
browsing state.

Composer.vue: 2104 -> 2050 lines. No behavior change.
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3fa8402

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@3fa8402
npx https://pkg.pr.new/@moonshot-ai/kimi-code@3fa8402

commit: 3fa8402

Add unit tests for the extracted input-history composable: push dedup and
empty-skip, walking backward/forward through entries, restoring the live
draft (empty and non-empty), empty-history no-op, resetBrowsing, and the
caretAtFirstLine gate.
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.

1 participant