-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtypes.py
More file actions
215 lines (170 loc) · 7.11 KB
/
Copy pathtypes.py
File metadata and controls
215 lines (170 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
"""Settings schema types matching TypeScript settings/types.ts."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Literal
PermissionModeType = Literal["default", "plan", "bypassPermissions"]
@dataclass
class PermissionRule:
"""A single permission rule."""
tool: str = ""
allow: bool = True
glob: str | None = None
regex: str | None = None
description: str = ""
source: str = "user" # "user" | "project" | "managed" | "cli"
@dataclass
class ToolSettings:
"""Per-tool configuration."""
enabled: bool = True
allowed_commands: list[str] = field(default_factory=list)
denied_commands: list[str] = field(default_factory=list)
timeout_seconds: int = 120
@dataclass
class OutputStyleSettings:
"""Output style configuration."""
style: str = "default" # "default" | "concise" | "verbose" | "markdown"
max_width: int = 120
show_thinking: bool = False
@dataclass
class CompactSettings:
"""Compaction settings."""
auto_compact: bool = True
threshold_tokens: int = 100_000
max_compact_retries: int = 3
@dataclass
class HookSettings:
"""Hook configuration."""
enabled: bool = True
timeout_ms: int = 30_000
max_concurrent: int = 5
@dataclass
class McpServerSettings:
"""MCP server configuration."""
command: str = ""
args: list[str] = field(default_factory=list)
env: dict[str, str] = field(default_factory=dict)
enabled: bool = True
@dataclass
class SettingsSchema:
"""Full settings schema matching TypeScript SettingsSchema."""
# Model
model: str = ""
small_fast_model: str = ""
# Advisor — reviewer tool. Empty string = unset (no /advisor).
# Persisted analogue of TS appState.advisorModel; the /advisor slash
# command writes here, and _call_model_sync reads from here at request
# time. See src/utils/advisor.py.
advisor_model: str = ""
# Provider key (matches ~/.clawcodex/config.json's providers map) that
# serves the advisor call. REQUIRED when advisor_model is set —
# clawcodex is multi-provider and the same model name (e.g.
# ``claude-opus-4-7``) can live behind anthropic, openai (litellm),
# openrouter, bedrock, ... so name-based inference is ambiguous.
# The /advisor command writes both fields together via the
# ``<provider>:<model>`` syntax. Empty + advisor_model set = misconfig
# that surfaces as a clear error at the first advisor call.
advisor_provider: str = ""
# Force client-side advisor mode (tool dispatch + separate API call)
# even when the main provider is first-party Anthropic. Default False
# lets the server-side beta path engage when applicable. Set via
# ``/advisor <model> --client``. See decide_advisor_mode() in
# src/utils/advisor.py for the full activation table.
advisor_client_mode: bool = False
# Provider
provider: str = "anthropic"
# Permission mode
permission_mode: PermissionModeType = "default"
# Permission rules
permissions: list[PermissionRule] = field(default_factory=list)
# Tool settings
tools: dict[str, ToolSettings] = field(default_factory=dict)
# Output
output_style: OutputStyleSettings = field(default_factory=OutputStyleSettings)
# Compact
compact: CompactSettings = field(default_factory=CompactSettings)
# Hooks
hooks: HookSettings = field(default_factory=HookSettings)
# MCP servers
mcp_servers: dict[str, McpServerSettings] = field(default_factory=dict)
# Max turns
max_turns: int = 0 # 0 = unlimited
# Max cost (USD)
max_cost_usd: float = 0.0 # 0 = unlimited
# Effort
effort: str = "" # "", "low", "medium", "high", "max"
# Plan mode
plan_mode: bool = False
# Non-interactive / SDK mode
non_interactive: bool = False
# Custom system prompt
custom_system_prompt: str = ""
# Append system prompt
append_system_prompt: str = ""
# Allowed tools list (empty = all)
allowed_tools: list[str] = field(default_factory=list)
# Denied tools list
denied_tools: list[str] = field(default_factory=list)
# Fast mode (use small model)
fast_mode: bool = False
# Display preferences persisted by the AppState side-effect router
# (#280; TS onChangeAppState.ts:123-136). ``expanded_view`` stores the
# Python store's own 'none' | 'tasks' | 'teammates' shape directly
# rather than the TS legacy showExpandedTodos/showSpinnerTree boolean
# pair — this port's config file is not shared with TS Claude Code.
verbose: bool = False
expanded_view: str = "" # "" = unset (AppState default applies)
# Provider key paired with the persisted ``model`` (#280): a /model
# choice is only restored when the next launch uses the same provider
# (the advisor_model/advisor_provider precedent — model names are
# provider-scoped in a multi-provider config).
model_provider: str = ""
# Disable dynamic workflows (also honored via CLAUDE_CODE_DISABLE_WORKFLOWS
# and the camelCase ``disableWorkflows`` JSON key). See src/workflow/gating.py.
disable_workflows: bool = False
# Session retention days
session_retention_days: int = 30
# Extra raw fields for forward compatibility
extra: dict[str, Any] = field(default_factory=dict)
def to_dict(self) -> dict[str, Any]:
"""Serialize to dict."""
import dataclasses
d = dataclasses.asdict(self)
extra = d.pop("extra", {})
d.update(extra)
return d
@classmethod
def from_dict(cls, data: dict[str, Any]) -> SettingsSchema:
"""Deserialize from dict."""
import dataclasses
known_fields = {f.name for f in dataclasses.fields(cls)}
known: dict[str, Any] = {}
extra: dict[str, Any] = {}
for k, v in data.items():
if k in known_fields:
known[k] = v
else:
extra[k] = v
# Convert nested objects
if "permissions" in known and isinstance(known["permissions"], list):
known["permissions"] = [
PermissionRule(**r) if isinstance(r, dict) else r
for r in known["permissions"]
]
if "output_style" in known and isinstance(known["output_style"], dict):
known["output_style"] = OutputStyleSettings(**known["output_style"])
if "compact" in known and isinstance(known["compact"], dict):
known["compact"] = CompactSettings(**known["compact"])
if "hooks" in known and isinstance(known["hooks"], dict):
known["hooks"] = HookSettings(**known["hooks"])
if "tools" in known and isinstance(known["tools"], dict):
known["tools"] = {
name: ToolSettings(**v) if isinstance(v, dict) else v
for name, v in known["tools"].items()
}
if "mcp_servers" in known and isinstance(known["mcp_servers"], dict):
known["mcp_servers"] = {
name: McpServerSettings(**v) if isinstance(v, dict) else v
for name, v in known["mcp_servers"].items()
}
known["extra"] = extra
return cls(**known)