@@ -12,17 +12,29 @@ import { query } from "../query.js";
1212import { allTools } from "../tools.js" ;
1313import { createPermissionContext , createCheckPermissionFn } from "../utils/permissions.js" ;
1414import { DEFAULT_MODEL } from "../types/index.js" ;
15- import type { Message } from "../types/index.js" ;
15+ import type { Message , PermissionMode } from "../types/index.js" ;
16+ import { tryExecuteCommand } from "../commands/index.js" ;
17+ import { compactMessages } from "../services/compact/compact.js" ;
18+
19+ interface REPLProps {
20+ model ?: string ;
21+ maxTokens ?: number ;
22+ permissionMode ?: PermissionMode ;
23+ }
1624
17- export function REPL ( ) {
25+ export function REPL ( { model : modelProp , maxTokens : maxTokensProp , permissionMode : permModeProp } : REPLProps = { } ) {
1826 const { exit } = useApp ( ) ;
1927 const [ messages , setMessages ] = useState < Message [ ] > ( [ ] ) ;
2028 const [ input , setInput ] = useState ( "" ) ;
2129 const [ isLoading , setIsLoading ] = useState ( false ) ;
2230 const [ streamText , setStreamText ] = useState ( "" ) ;
2331 const [ tokenUsage , setTokenUsage ] = useState ( { input : 0 , output : 0 } ) ;
2432
25- const permCtx = createPermissionContext ( "auto" ) ;
33+ const activeModel = modelProp ?? DEFAULT_MODEL ;
34+ const activeMaxTokens = maxTokensProp ?? 4096 ;
35+ const activePermMode = permModeProp ?? "auto" ;
36+
37+ const permCtx = createPermissionContext ( activePermMode ) ;
2638 const checkPerm = createCheckPermissionFn ( permCtx ) ;
2739
2840 const handleSubmit = useCallback ( async ( value : string ) => {
@@ -35,14 +47,32 @@ export function REPL() {
3547 return ;
3648 }
3749
50+ // 检查斜杠命令
51+ const cmdResult = tryExecuteCommand ( trimmed ) ;
52+ if ( cmdResult !== null ) {
53+ if ( trimmed === "/clear" ) {
54+ setMessages ( [ ] ) ;
55+ } else if ( trimmed === "/compact" ) {
56+ setMessages ( ( prev ) => compactMessages ( prev ) ) ;
57+ }
58+ // 将命令结果作为系统消息显示
59+ setMessages ( ( prev ) => [ ...prev , {
60+ type : "system" as const ,
61+ subtype : "local_command" as const ,
62+ message : cmdResult ,
63+ } ] ) ;
64+ setInput ( "" ) ;
65+ return ;
66+ }
67+
3868 setInput ( "" ) ;
3969 setIsLoading ( true ) ;
4070 setStreamText ( "" ) ;
4171
4272 try {
4373 const result = await query ( trimmed , [ ...messages ] , {
44- model : DEFAULT_MODEL ,
45- maxTokens : 4096 ,
74+ model : activeModel ,
75+ maxTokens : activeMaxTokens ,
4676 checkPermission : checkPerm ,
4777 onText : ( text ) => {
4878 setStreamText ( ( prev ) => prev + text ) ;
@@ -74,7 +104,7 @@ export function REPL() {
74104 { /* Header */ }
75105 < Box marginBottom = { 1 } >
76106 < Text bold color = "cyan" > mini-claude</ Text >
77- < Text dimColor > | { DEFAULT_MODEL } | { allTools . length } tools | tokens: { tokenUsage . input } ↑ { tokenUsage . output } ↓</ Text >
107+ < Text dimColor > | { activeModel } | { allTools . length } tools | tokens: { tokenUsage . input } ↑ { tokenUsage . output } ↓</ Text >
78108 </ Box >
79109
80110 { /* Message History */ }
0 commit comments