Skip to content

refactor(web): extract slash-command menu into a composable#1026

Merged
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-slash-menu
Jun 23, 2026
Merged

refactor(web): extract slash-command menu into a composable#1026
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-slash-menu

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 #1011 useInputHistory). This is the next Composer slice. No standalone issue.

Problem

Composer.vue is still the largest component (~2058 lines). The / slash-command menu is a self-contained feature — its open/items/active state, the filter logic, and item selection — that lived inline in the composer alongside the draft, the mention menu, attachments, and the keydown orchestration.

What changed

  • New apps/kimi-web/src/composables/useSlashMenu.ts:
    • Owns the open / items / active state, the update() filter logic, and select(item) (acceptsInput leaves the command in the box; bare commands emit + record history).
    • Takes { text, textareaRef, autosize, skills, emitCommand, historyPush } as deps — same DI shape as useInputHistory.
  • Composer.vue:
    • Replaces the inline slash section with a useSlashMenu(...) call, destructured back to the original names (slashOpen, slashItems, slashActive, updateSlashMenu, selectSlashCommand) so the rest of the component — the keydown navigation, handleSubmit, handleSteer, and the <SlashMenu> template binding — is unchanged.
    • The keydown orchestration stays in the composer because it also juggles the mention menu and history recall.
    • 2058 → 2035 lines.
  • Added test/slash-menu.test.ts (9 cases: open/filter/close rules, skills, select for acceptsInput and bare commands).

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 — 64 passed
  • pnpm --filter @moonshot-ai/kimi-web build — pass
  • oxlint --type-aware on the 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. (test/slash-menu.test.ts.)
  • Ran gen-changesets skill, or this PR needs no changeset. (Added .changeset/web-extract-slash-menu.md, patch on @moonshot-ai/kimi-code.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing change.)

Move the slash menu's open/items/active state, the filter logic, and item
selection out of Composer into useSlashMenu. The composable takes the text
ref, textarea ref, autosize, a skills getter, and the emit/history-push
callbacks as deps.

The composer keeps the keydown orchestration (arrow keys, Enter/Tab, Escape)
because it also juggles the mention menu and history recall; it consumes the
returned open/items/active refs directly and calls update/select. The
destructured refs are aliased back to the original names so the rest of the
component is unchanged.

Composer.vue: 2058 -> 2035 lines. Adds unit tests for useSlashMenu. No
behavior change.
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f7e863f

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@f7e863f
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f7e863f

commit: f7e863f

@wbxl2000 wbxl2000 merged commit 318c964 into main Jun 23, 2026
9 checks passed
@wbxl2000 wbxl2000 deleted the refactor/web-extract-slash-menu branch June 23, 2026 10:17
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
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