1919 from kimi_agent_sdk import MCPConfig
2020
2121
22- def _coerce_work_dir (work_dir : Path | str | None ) -> KaosPath :
23- if work_dir is None :
24- return KaosPath .cwd ()
25- if isinstance (work_dir , KaosPath ):
26- return work_dir .expanduser ()
27- if isinstance (work_dir , Path ):
28- return KaosPath .unsafe_from_local_path (work_dir ).expanduser ()
29- return KaosPath (str (work_dir )).expanduser ()
22+ def _ensure_type (name : str , value : object , expected : type ) -> None :
23+ if not isinstance (value , expected ):
24+ raise TypeError (f"{ name } must be { expected .__name__ } , got { type (value ).__name__ } " )
3025
3126
3227class Session :
@@ -44,7 +39,7 @@ def __init__(self, cli: KimiCLI) -> None:
4439
4540 @staticmethod
4641 async def create (
47- work_dir : Path | str | None = None ,
42+ work_dir : KaosPath | None = None ,
4843 * ,
4944 # Basic configuration
5045 session_id : str | None = None ,
@@ -56,7 +51,7 @@ async def create(
5651 # Extensions
5752 agent_file : Path | None = None ,
5853 mcp_configs : list [MCPConfig ] | list [dict [str , Any ]] | None = None ,
59- skills_dir : Path | None = None ,
54+ skills_dir : KaosPath | None = None ,
6055 # Loop control
6156 max_steps_per_turn : int | None = None ,
6257 max_retries_per_step : int | None = None ,
@@ -66,15 +61,15 @@ async def create(
6661 Create a new Session instance.
6762
6863 Args:
69- work_dir: Working directory. Defaults to current directory.
64+ work_dir: Working directory (KaosPath) . Defaults to current directory.
7065 session_id: Custom session ID (optional).
7166 config: Configuration object or path to a config file.
7267 model: Model name, e.g. "kimi".
7368 thinking: Whether to enable thinking mode (requires model support).
7469 yolo: Automatically approve all approval requests.
7570 agent_file: Agent specification file path.
7671 mcp_configs: MCP server configurations.
77- skills_dir: Skills directory.
72+ skills_dir: Skills directory (KaosPath) .
7873 max_steps_per_turn: Maximum number of steps in one turn.
7974 max_retries_per_step: Maximum number of retries per step.
8075 max_ralph_iterations: Extra iterations in Ralph mode (-1 for unlimited).
@@ -91,7 +86,14 @@ async def create(
9186 MCPRuntimeError(KimiCLIException, RuntimeError): When any MCP server cannot be
9287 connected.
9388 """
94- work_dir_path = _coerce_work_dir (work_dir )
89+ if work_dir is None :
90+ work_dir_path = KaosPath .cwd ()
91+ else :
92+ _ensure_type ("work_dir" , work_dir , KaosPath )
93+ work_dir_path = work_dir
94+
95+ if skills_dir is not None :
96+ _ensure_type ("skills_dir" , skills_dir , KaosPath )
9597 cli_session = await CliSession .create (work_dir_path , session_id )
9698 cli = await KimiCLI .create (
9799 cli_session ,
@@ -110,7 +112,7 @@ async def create(
110112
111113 @staticmethod
112114 async def resume (
113- work_dir : Path | str ,
115+ work_dir : KaosPath ,
114116 session_id : str | None = None ,
115117 * ,
116118 # Basic configuration
@@ -122,7 +124,7 @@ async def resume(
122124 # Extensions
123125 agent_file : Path | None = None ,
124126 mcp_configs : list [MCPConfig ] | list [dict [str , Any ]] | None = None ,
125- skills_dir : Path | None = None ,
127+ skills_dir : KaosPath | None = None ,
126128 # Loop control
127129 max_steps_per_turn : int | None = None ,
128130 max_retries_per_step : int | None = None ,
@@ -132,15 +134,15 @@ async def resume(
132134 Resume an existing session.
133135
134136 Args:
135- work_dir: Working directory to resume from.
137+ work_dir: Working directory to resume from (KaosPath) .
136138 session_id: Session ID to resume. If None, resumes the most recent session.
137139 config: Configuration object or path to a config file.
138140 model: Model name, e.g. "kimi".
139141 thinking: Whether to enable thinking mode (requires model support).
140142 yolo: Automatically approve all approval requests.
141143 agent_file: Agent specification file path.
142144 mcp_configs: MCP server configurations.
143- skills_dir: Skills directory.
145+ skills_dir: Skills directory (KaosPath) .
144146 max_steps_per_turn: Maximum number of steps in one turn.
145147 max_retries_per_step: Maximum number of retries per step.
146148 max_ralph_iterations: Extra iterations in Ralph mode (-1 for unlimited).
@@ -157,11 +159,13 @@ async def resume(
157159 MCPRuntimeError(KimiCLIException, RuntimeError): When any MCP server cannot be
158160 connected.
159161 """
160- work_dir_path = _coerce_work_dir (work_dir )
162+ _ensure_type ("work_dir" , work_dir , KaosPath )
163+ if skills_dir is not None :
164+ _ensure_type ("skills_dir" , skills_dir , KaosPath )
161165 if session_id is None :
162- cli_session = await CliSession .continue_ (work_dir_path )
166+ cli_session = await CliSession .continue_ (work_dir )
163167 else :
164- cli_session = await CliSession .find (work_dir_path , session_id )
168+ cli_session = await CliSession .find (work_dir , session_id )
165169 if cli_session is None :
166170 return None
167171 cli = await KimiCLI .create (
0 commit comments