Skip to content
Merged
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/add-auto-slash-command-and-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": minor
---

Add `/auto` slash command and `--auto` CLI flag for auto permission mode.
3 changes: 3 additions & 0 deletions apps/kimi-code/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function createProgram(
)
.option('-C, --continue', 'Continue the previous session for the working directory.', false)
.option('-y, --yolo', 'Automatically approve all actions.', false)
.option('--auto', 'Start in auto permission mode.', false)
.addOption(
new Option(
'-m, --model <model>',
Expand Down Expand Up @@ -90,11 +91,13 @@ export function createProgram(
const rawSession = raw['session'] ?? raw['resume'];
const sessionValue = rawSession === true ? '' : (rawSession as string | undefined);
const yoloValue = raw['yolo'] === true || raw['yes'] === true || raw['autoApprove'] === true;
const autoValue = raw['auto'] === true;

const opts: CLIOptions = {
session: sessionValue,
continue: raw['continue'] as boolean,
yolo: yoloValue,
auto: autoValue,
plan: raw['plan'] as boolean,
model: raw['model'] as string | undefined,
outputFormat: raw['outputFormat'] as CLIOptions['outputFormat'],
Expand Down
10 changes: 10 additions & 0 deletions apps/kimi-code/src/cli/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface CLIOptions {
session: string | undefined;
continue: boolean;
yolo: boolean;
auto: boolean;
plan: boolean;
model: string | undefined;
outputFormat: PromptOutputFormat | undefined;
Expand Down Expand Up @@ -39,6 +40,9 @@ export function validateOptions(opts: CLIOptions): ValidatedOptions {
if (promptMode && opts.yolo) {
throw new OptionConflictError('Cannot combine --prompt with --yolo.');
}
if (promptMode && opts.auto) {
throw new OptionConflictError('Cannot combine --prompt with --auto.');
}
if (promptMode && opts.plan) {
throw new OptionConflictError('Cannot combine --prompt with --plan.');
}
Expand All @@ -48,9 +52,15 @@ export function validateOptions(opts: CLIOptions): ValidatedOptions {
if (opts.continue && opts.session !== undefined) {
throw new OptionConflictError('Cannot combine --continue, --session.');
}
if (opts.yolo && opts.auto) {
throw new OptionConflictError('Cannot combine --yolo with --auto.');
}
if (!promptMode && (opts.continue || opts.session !== undefined) && opts.yolo) {
throw new OptionConflictError('Cannot combine --yolo with --continue or --session.');
}
if (!promptMode && (opts.continue || opts.session !== undefined) && opts.auto) {
throw new OptionConflictError('Cannot combine --auto with --continue or --session.');
}
if (!promptMode && (opts.continue || opts.session !== undefined) && opts.plan) {
throw new OptionConflictError('Cannot combine --plan with --continue or --session.');
}
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/src/cli/run-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export async function runShell(
trackLifecycle('started', {
resumed,
yolo: opts.yolo,
auto: opts.auto,
plan: opts.plan,
afk: false,
});
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const MIGRATE_CLI_OPTIONS: CLIOptions = {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down
88 changes: 76 additions & 12 deletions apps/kimi-code/src/tui/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,85 @@ export async function handleYoloCommand(host: SlashCommandHost, args: string): P
return;
}

let enabled: boolean;
if (args === 'on') enabled = true;
else if (args === 'off') enabled = false;
else enabled = host.state.appState.permissionMode !== 'yolo';
const subcmd = args.trim().toLowerCase();
const currentMode = host.state.appState.permissionMode;

await session.setPermission(enabled ? 'yolo' : 'manual');
host.setAppState({ permissionMode: enabled ? 'yolo' : 'manual' });
if (enabled) {
host.showNotice(
'YOLO mode: ON',
'All actions will be approved automatically. Use with caution.',
);
if (subcmd === 'on') {
if (currentMode === 'yolo') {
host.showNotice('YOLO mode is already on');
return;
}
await session.setPermission('yolo');
host.setAppState({ permissionMode: 'yolo' });
host.showNotice('YOLO mode: ON', 'Workspace tools auto-approved.');
return;
}

if (subcmd === 'off') {
if (currentMode !== 'yolo') {
host.showNotice('YOLO mode is already off');
return;
}
await session.setPermission('manual');
host.setAppState({ permissionMode: 'manual' });
host.showNotice('YOLO mode: OFF');
return;
}

// toggle
if (currentMode === 'yolo') {
await session.setPermission('manual');
host.setAppState({ permissionMode: 'manual' });
host.showNotice('YOLO mode: OFF');
} else {
await session.setPermission('yolo');
host.setAppState({ permissionMode: 'yolo' });
host.showNotice('YOLO mode: ON', 'Workspace tools auto-approved.');
}
}

export async function handleAutoCommand(host: SlashCommandHost, args: string): Promise<void> {
const session = host.session;
if (session === undefined) {
host.showError(NO_ACTIVE_SESSION_MESSAGE);
return;
}
host.showNotice('YOLO mode: OFF');

const subcmd = args.trim().toLowerCase();
const currentMode = host.state.appState.permissionMode;

if (subcmd === 'on') {
if (currentMode === 'auto') {
host.showNotice('Auto mode is already on');
return;
}
await session.setPermission('auto');
host.setAppState({ permissionMode: 'auto' });
host.showNotice('Auto mode: ON', 'Tools auto-approved. Agent will not ask questions.');
return;
}

if (subcmd === 'off') {
if (currentMode !== 'auto') {
host.showNotice('Auto mode is already off');
return;
}
await session.setPermission('manual');
host.setAppState({ permissionMode: 'manual' });
host.showNotice('Auto mode: OFF');
return;
}

// toggle
if (currentMode === 'auto') {
await session.setPermission('manual');
host.setAppState({ permissionMode: 'manual' });
host.showNotice('Auto mode: OFF');
} else {
await session.setPermission('auto');
host.setAppState({ permissionMode: 'auto' });
host.showNotice('Auto mode: ON', 'Tools auto-approved. Agent will not ask questions.');
}
}

export async function handleCompactCommand(host: SlashCommandHost, args: string): Promise<void> {
Expand Down
5 changes: 5 additions & 0 deletions apps/kimi-code/src/tui/commands/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { TUIState } from '../tui-state';

import { handleConnectCommand, handleLoginCommand, handleLogoutCommand } from './auth';
import {
handleAutoCommand,
handleCompactCommand,
handleEditorCommand,
handleModelCommand,
Expand Down Expand Up @@ -52,6 +53,7 @@ export {
handleLogoutCommand,
} from './auth';
export {
handleAutoCommand,
handleCompactCommand,
handleEditorCommand,
handleModelCommand,
Expand Down Expand Up @@ -246,6 +248,9 @@ async function handleBuiltInSlashCommand(
case 'yolo':
await handleYoloCommand(host, args);
return;
case 'auto':
await handleAutoCommand(host, args);
return;
case 'plan':
await handlePlanCommand(host, args);
return;
Expand Down
7 changes: 7 additions & 0 deletions apps/kimi-code/src/tui/commands/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export const BUILTIN_SLASH_COMMANDS = [
priority: 100,
availability: 'always',
},
{
name: 'auto',
aliases: [],
description: 'Toggle auto permission mode',
priority: 100,
availability: 'always',
},
{
name: 'permission',
aliases: [],
Expand Down
6 changes: 5 additions & 1 deletion apps/kimi-code/src/tui/controllers/auth-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export class AuthFlowController {
workDir: host.state.appState.workDir,
model,
thinking: level,
permission: host.options.startup.yolo ? 'yolo' : undefined,
permission: host.options.startup.auto
? 'auto'
: host.options.startup.yolo
? 'yolo'
: undefined,
planMode: host.state.appState.planMode ? true : undefined,
});
await host.setSession(session);
Expand Down
9 changes: 7 additions & 2 deletions apps/kimi-code/src/tui/kimi-tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export interface KimiTUIStartupInput {
type EffectiveActivityPaneMode = ActivityPaneMode | 'idle' | 'session';

function createInitialAppState(input: KimiTUIStartupInput): AppState {
const startupPermission: PermissionMode = input.cliOptions.yolo ? 'yolo' : 'manual';
const startupPermission: PermissionMode = input.cliOptions.auto
? 'auto'
: input.cliOptions.yolo
? 'yolo'
: 'manual';
return {
model: '',
workDir: input.workDir,
Expand Down Expand Up @@ -238,6 +242,7 @@ export class KimiTUI {
sessionFlag: startupInput.cliOptions.session,
continueLast: startupInput.cliOptions.continue,
yolo: startupInput.cliOptions.yolo,
auto: startupInput.cliOptions.auto,
plan: startupInput.cliOptions.plan,
model: startupInput.cliOptions.model,
startupNotice: startupInput.startupNotice,
Expand Down Expand Up @@ -431,7 +436,7 @@ export class KimiTUI {
const createSessionOptions: CreateSessionOptions = {
workDir,
model: startup.model,
permission: startup.yolo ? 'yolo' : undefined,
permission: startup.auto ? 'auto' : startup.yolo ? 'yolo' : undefined,
planMode: startup.plan ? true : undefined,
};

Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/src/tui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export interface TUIStartupOptions {
readonly sessionFlag?: string;
readonly continueLast: boolean;
readonly yolo: boolean;
readonly auto: boolean;
readonly plan: boolean;
readonly model?: string;
readonly startupNotice?: string;
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/test/cli/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function defaultOpts(): CLIOptions {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/test/cli/run-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function opts(overrides: Partial<Parameters<typeof runPrompt>[0]> = {}) {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down
12 changes: 12 additions & 0 deletions apps/kimi-code/test/cli/run-shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: true,
auto: false,
plan: true,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -232,6 +233,7 @@ describe('runShell', () => {
expect(mocks.lifecycleTrack).toHaveBeenCalledWith('started', {
resumed: false,
yolo: true,
auto: false,
plan: true,
afk: false,
});
Expand Down Expand Up @@ -261,6 +263,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -300,6 +303,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -337,6 +341,7 @@ describe('runShell', () => {
session: 'ses-1',
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand All @@ -349,6 +354,7 @@ describe('runShell', () => {
expect(mocks.lifecycleTrack).toHaveBeenCalledWith('started', {
resumed: true,
yolo: false,
auto: false,
plan: false,
afk: false,
});
Expand All @@ -373,6 +379,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -405,6 +412,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -455,6 +463,7 @@ describe('runShell', () => {
session: '',
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -491,6 +500,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -527,6 +537,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down Expand Up @@ -579,6 +590,7 @@ describe('runShell', () => {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/test/tui/activity-pane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function makeStartupInput(): KimiTUIStartupInput {
session: undefined,
continue: false,
yolo: false,
auto: false,
plan: false,
model: undefined,
outputFormat: undefined,
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/test/tui/create-tui-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('createTUIState', () => {
startup: {
continueLast: false,
yolo: false,
auto: false,
plan: false,
},
};
Expand Down
Loading
Loading