@@ -3,78 +3,17 @@ import {
33 CLI_FRESH_WATCHDOG_DEFAULTS ,
44 CLI_RESUME_WATCHDOG_DEFAULTS ,
55} from "openclaw/plugin-sdk/cli-backend" ;
6-
7- const CLAUDE_MODEL_ALIASES : Record < string , string > = {
8- opus : "opus" ,
9- "opus-4.6" : "opus" ,
10- "opus-4.5" : "opus" ,
11- "opus-4" : "opus" ,
12- "claude-opus-4-6" : "opus" ,
13- "claude-opus-4-5" : "opus" ,
14- "claude-opus-4" : "opus" ,
15- sonnet : "sonnet" ,
16- "sonnet-4.6" : "sonnet" ,
17- "sonnet-4.5" : "sonnet" ,
18- "sonnet-4.1" : "sonnet" ,
19- "sonnet-4.0" : "sonnet" ,
20- "claude-sonnet-4-6" : "sonnet" ,
21- "claude-sonnet-4-5" : "sonnet" ,
22- "claude-sonnet-4-1" : "sonnet" ,
23- "claude-sonnet-4-0" : "sonnet" ,
24- haiku : "haiku" ,
25- "haiku-3.5" : "haiku" ,
26- "claude-haiku-3-5" : "haiku" ,
27- } ;
28-
29- const CLAUDE_LEGACY_SKIP_PERMISSIONS_ARG = "--dangerously-skip-permissions" ;
30- const CLAUDE_PERMISSION_MODE_ARG = "--permission-mode" ;
31- const CLAUDE_BYPASS_PERMISSIONS_MODE = "bypassPermissions" ;
32-
33- function normalizeClaudePermissionArgs ( args ?: string [ ] ) : string [ ] | undefined {
34- if ( ! args ) {
35- return args ;
36- }
37- const normalized : string [ ] = [ ] ;
38- let sawLegacySkip = false ;
39- let hasPermissionMode = false ;
40- for ( let i = 0 ; i < args . length ; i += 1 ) {
41- const arg = args [ i ] ;
42- if ( arg === CLAUDE_LEGACY_SKIP_PERMISSIONS_ARG ) {
43- sawLegacySkip = true ;
44- continue ;
45- }
46- if ( arg === CLAUDE_PERMISSION_MODE_ARG ) {
47- hasPermissionMode = true ;
48- normalized . push ( arg ) ;
49- const maybeValue = args [ i + 1 ] ;
50- if ( typeof maybeValue === "string" ) {
51- normalized . push ( maybeValue ) ;
52- i += 1 ;
53- }
54- continue ;
55- }
56- if ( arg . startsWith ( `${ CLAUDE_PERMISSION_MODE_ARG } =` ) ) {
57- hasPermissionMode = true ;
58- }
59- normalized . push ( arg ) ;
60- }
61- if ( sawLegacySkip && ! hasPermissionMode ) {
62- normalized . push ( CLAUDE_PERMISSION_MODE_ARG , CLAUDE_BYPASS_PERMISSIONS_MODE ) ;
63- }
64- return normalized ;
65- }
66-
67- function normalizeClaudeBackendConfig ( config : CliBackendConfig ) : CliBackendConfig {
68- return {
69- ...config ,
70- args : normalizeClaudePermissionArgs ( config . args ) ,
71- resumeArgs : normalizeClaudePermissionArgs ( config . resumeArgs ) ,
72- } ;
73- }
6+ import {
7+ CLAUDE_CLI_BACKEND_ID ,
8+ CLAUDE_CLI_CLEAR_ENV ,
9+ CLAUDE_CLI_MODEL_ALIASES ,
10+ CLAUDE_CLI_SESSION_ID_FIELDS ,
11+ normalizeClaudeBackendConfig ,
12+ } from "./cli-shared.js" ;
7413
7514export function buildAnthropicCliBackend ( ) : CliBackendPlugin {
7615 return {
77- id : "claude-cli" ,
16+ id : CLAUDE_CLI_BACKEND_ID ,
7817 bundleMcp : true ,
7918 config : {
8019 command : "claude" ,
@@ -99,14 +38,14 @@ export function buildAnthropicCliBackend(): CliBackendPlugin {
9938 output : "jsonl" ,
10039 input : "arg" ,
10140 modelArg : "--model" ,
102- modelAliases : CLAUDE_MODEL_ALIASES ,
41+ modelAliases : CLAUDE_CLI_MODEL_ALIASES ,
10342 sessionArg : "--session-id" ,
10443 sessionMode : "always" ,
105- sessionIdFields : [ "session_id" , "sessionId" , "conversation_id" , "conversationId" ] ,
44+ sessionIdFields : [ ... CLAUDE_CLI_SESSION_ID_FIELDS ] ,
10645 systemPromptArg : "--append-system-prompt" ,
10746 systemPromptMode : "append" ,
10847 systemPromptWhen : "first" ,
109- clearEnv : [ "ANTHROPIC_API_KEY" , "ANTHROPIC_API_KEY_OLD" ] ,
48+ clearEnv : [ ... CLAUDE_CLI_CLEAR_ENV ] ,
11049 reliability : {
11150 watchdog : {
11251 fresh : { ...CLI_FRESH_WATCHDOG_DEFAULTS } ,
0 commit comments