Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fullscreen-search-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": minor
---

Support searching conversations in fullscreen mode with `Ctrl+F` or `/find`.
5 changes: 5 additions & 0 deletions .changeset/fullscreen-search-pi-tui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/pi-tui": minor
---

Default alternate-screen transcript search to `Ctrl+F` with `↑`/`↓` navigation, and add programmatic search opening.
25 changes: 10 additions & 15 deletions apps/kimi-code/src/tui/commands/dispatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Component, Focusable } from '@moonshot-ai/pi-tui';
import { TuiAltScreen, type Component, type Focusable } from '@moonshot-ai/pi-tui';
import type { DeviceAuthorization } from '@moonshot-ai/kimi-code-oauth';
import type { ReverseRpcModalOwner } from '../reverse-rpc/modal-coordinator';

Expand Down Expand Up @@ -59,7 +59,7 @@ import { handleReloadCommand, handleReloadTuiCommand } from './reload';
import type { SkillListSession } from './skills';
import {
canRestoreSubmittedInput,
resolveUserInput,
resolveHostUserInput,
type SlashCommandIntent,
slashBusyMessage,
slashCommandBusyReason,
Expand Down Expand Up @@ -207,19 +207,7 @@ export function dispatchInput(
text: string,
delivery: FollowUpDelivery = 'default',
): void {
const { intent, activations } = resolveUserInput({
input: text,
skillCommandMap: host.skillCommandMap,
pluginCommandMap: host.pluginCommandMap,
isStreaming: host.state.appState.streamingPhase !== 'idle',
isCompacting: host.state.appState.isCompacting,
skillVariantPathForCommand: host.skillVariantPathForCommand === undefined
? undefined
: (commandName, tokenStart) => host.skillVariantPathForCommand!(commandName, tokenStart),
defaultSkillPathForCommand: host.defaultSkillPathForCommand === undefined
? undefined
: (commandName) => host.defaultSkillPathForCommand!(commandName),
});
const { intent, activations } = resolveHostUserInput(host, text);
if (intent.kind === 'skill' || (activations.length > 0 && intent.kind !== 'builtin')) {
const leading = activations[0];
if (intent.kind === 'skill' && leading?.args !== undefined && host.state.appState.model.trim().length > 0) {
Expand Down Expand Up @@ -373,6 +361,13 @@ async function handleBuiltInSlashCommand(
case 'help':
host.showHelpPanel();
return;
case 'find': {
if (host.state.ui instanceof TuiAltScreen) {
const query = args.trim();
host.state.ui.openSearch(query.length > 0 ? query : undefined);
}
return;
}
case 'version':
host.showStatus(`Kimi Code v${host.state.appState.version}`);
return;
Expand Down
36 changes: 35 additions & 1 deletion apps/kimi-code/src/tui/commands/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { readdirSync, statSync } from 'node:fs';
import { homedir } from 'node:os';
import { basename, dirname, join, relative, resolve } from 'pathe';

import type { AutocompleteItem } from '@moonshot-ai/pi-tui';
import type { AutocompleteItem, TuiMode } from '@moonshot-ai/pi-tui';

import { completeLeadingArg, type ArgCompletionSpec } from './complete-args';
import { isExperimentalFlagEnabled } from './experimental-flags';
import type { KimiSlashCommand, SlashCommandAvailability } from './types';

const GOAL_ARG_COMPLETIONS: readonly ArgCompletionSpec[] = [
Expand Down Expand Up @@ -236,6 +237,15 @@ export const BUILTIN_SLASH_COMMANDS = [
priority: 80,
availability: 'always',
},
{
name: 'find',
aliases: [],
description: 'Search the conversation',
priority: 80,
argumentHint: '[query]',
availability: 'always',
visible: ({ tuiMode }) => tuiMode === 'fullscreen',
},
{
name: 'new',
aliases: ['clear'],
Expand Down Expand Up @@ -465,13 +475,37 @@ export const BUILTIN_SLASH_COMMANDS = [
export type BuiltinSlashCommand = (typeof BUILTIN_SLASH_COMMANDS)[number];
export type BuiltinSlashCommandName = BuiltinSlashCommand['name'];

export function isSlashCommandVisible(
command: KimiSlashCommand,
tuiMode: TuiMode,
): boolean {
return (
isExperimentalFlagEnabled(command.experimentalFlag) &&
(command.visible?.({ tuiMode }) ?? true)
);
}

export function findBuiltInSlashCommand(commandName: string): BuiltinSlashCommand | undefined {
const commands = BUILTIN_SLASH_COMMANDS as readonly KimiSlashCommand<BuiltinSlashCommandName>[];
return commands.find(
(command) => command.name === commandName || command.aliases.includes(commandName),
) as BuiltinSlashCommand | undefined;
}

export function findVisibleBuiltInSlashCommand(
commandName: string,
tuiMode: TuiMode,
): BuiltinSlashCommand | undefined {
const command = findBuiltInSlashCommand(commandName);
return command !== undefined && isSlashCommandVisible(command, tuiMode) ? command : undefined;
}

export function getVisibleBuiltInSlashCommands(tuiMode: TuiMode): KimiSlashCommand[] {
return sortSlashCommands(
BUILTIN_SLASH_COMMANDS.filter((command) => isSlashCommandVisible(command, tuiMode)),
);
}

export function resolveSlashCommandAvailability(
command: KimiSlashCommand,
args: string,
Expand Down
48 changes: 40 additions & 8 deletions apps/kimi-code/src/tui/commands/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { TuiMode } from '@moonshot-ai/pi-tui';

import {
findBuiltInSlashCommand,
findVisibleBuiltInSlashCommand,
resolveSlashCommandAvailability,
type BuiltinSlashCommand,
type BuiltinSlashCommandName,
} from './registry';
import { isExperimentalFlagEnabled } from './experimental-flags';
import { parseSlashInput } from './parse';
import type { TUIState } from '../tui-state';
import type { InlineSkillActivation } from '../types';
import { extractInlineSkillActivations, findInlineSkillTokens } from '../utils/inline-skill-tokens';
import type {
KimiSlashCommand,
ParsedSlashInput,
SlashCommandBusyReason,
SlashCommandInvalidReason,
Expand Down Expand Up @@ -55,6 +55,7 @@ export interface ResolveSlashCommandInput {
readonly pluginCommandMap: ReadonlyMap<string, string>;
readonly isStreaming: boolean;
readonly isCompacting: boolean;
readonly tuiMode: TuiMode;
readonly skillVariantPathForCommand?: (commandName: string, tokenStart: number) => string | undefined;
readonly defaultSkillPathForCommand?: (commandName: string) => string | undefined;
}
Expand All @@ -63,11 +64,8 @@ export function resolveSlashCommandInput(options: ResolveSlashCommandInput): Sla
const parsed = parseSlashInput(options.input);
if (parsed === null) return { kind: 'not-command' };

const command = findBuiltInSlashCommand(parsed.name);
if (
command !== undefined &&
isExperimentalFlagEnabled((command as KimiSlashCommand).experimentalFlag)
) {
const command = findVisibleBuiltInSlashCommand(parsed.name, options.tuiMode);
if (command !== undefined) {
const busyReason = slashCommandBusyReason(options);
if (
busyReason !== undefined &&
Expand Down Expand Up @@ -172,6 +170,40 @@ export function resolveUserInput(options: ResolveSlashCommandInput): {
return { intent, activations: selectedActivations };
}

export interface SlashCommandResolutionHost {
readonly state: {
readonly appState: Pick<TUIState['appState'], 'streamingPhase' | 'isCompacting'>;
readonly ui: Pick<TUIState['ui'], 'mode'>;
};
readonly skillCommandMap: ReadonlyMap<string, string>;
readonly pluginCommandMap: ReadonlyMap<string, string>;
readonly skillVariantPathForCommand?: (commandName: string, tokenStart: number) => string | undefined;
readonly defaultSkillPathForCommand?: (commandName: string) => string | undefined;
}

export function resolveHostUserInput(
host: SlashCommandResolutionHost,
input: string,
overrides?: Partial<Pick<ResolveSlashCommandInput, 'isStreaming' | 'isCompacting' | 'tuiMode'>>,
): ReturnType<typeof resolveUserInput> {
return resolveUserInput({
input,
skillCommandMap: host.skillCommandMap,
pluginCommandMap: host.pluginCommandMap,
isStreaming: overrides?.isStreaming ?? host.state.appState.streamingPhase !== 'idle',
isCompacting: overrides?.isCompacting ?? host.state.appState.isCompacting,
tuiMode: overrides?.tuiMode ?? host.state.ui.mode,
skillVariantPathForCommand:
host.skillVariantPathForCommand === undefined
? undefined
: (commandName, tokenStart) => host.skillVariantPathForCommand!(commandName, tokenStart),
defaultSkillPathForCommand:
host.defaultSkillPathForCommand === undefined
? undefined
: (commandName) => host.defaultSkillPathForCommand!(commandName),
});
}

export function resolveSkillCommand(
skillCommandMap: ReadonlyMap<string, string>,
commandName: string,
Expand Down
7 changes: 6 additions & 1 deletion apps/kimi-code/src/tui/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { AutocompleteItem, SlashCommand } from '@moonshot-ai/pi-tui';
import type { AutocompleteItem, SlashCommand, TuiMode } from '@moonshot-ai/pi-tui';
import type { SkillSummary } from '@moonshot-ai/kimi-code-sdk';

export type SlashCommandAvailability = 'always' | 'idle-only';

export interface SlashCommandContext {
readonly tuiMode: TuiMode;
}

export interface KimiSlashCommand<Name extends string = string> extends SlashCommand {
readonly name: Name;
readonly aliases: readonly string[];
Expand All @@ -14,6 +18,7 @@ export interface KimiSlashCommand<Name extends string = string> extends SlashCom
readonly priority?: number;
readonly availability?: SlashCommandAvailability | ((args: string) => SlashCommandAvailability);
readonly experimentalFlag?: string;
readonly visible?: (context: SlashCommandContext) => boolean;
readonly completeArgs?: (argumentPrefix: string) => AutocompleteItem[] | null;
}

Expand Down
3 changes: 3 additions & 0 deletions apps/kimi-code/src/tui/components/dialogs/help-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Key,
decodeKittyPrintable,
type Focusable,
type TuiMode,
truncateToWidth,
} from '@moonshot-ai/pi-tui';
import {
Expand Down Expand Up @@ -34,10 +35,12 @@ const SUBMIT_DESCRIPTIONS: Readonly<Record<FollowUpDelivery, string>> = {
export function keyboardShortcuts(
followUpBehavior: FollowUpBehavior,
ctrlEnterRecognized: boolean,
tuiMode: TuiMode = 'regular',
): readonly KeyboardShortcut[] {
const submit = FOLLOW_UP_KEYMAP[followUpBehavior];
return [
{ keys: 'Shift-Tab', description: 'Toggle plan mode' },
...(tuiMode === 'fullscreen' ? [{ keys: 'Ctrl-F', description: 'Search conversation' }] : []),
{ keys: 'Ctrl-G', description: 'Edit in external editor ($VISUAL / $EDITOR)' },
{ keys: 'Ctrl-O', description: 'Toggle tool output / compaction summary expansion' },
{ keys: 'Ctrl-S', description: 'Steer — inject a follow-up during streaming' },
Expand Down
Loading
Loading