FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
kimi-cli/src/kimi_cli/cli/toad.py at main · atulk-code/kimi-cli · GitHub
atulk-code
/
kimi-cli
Public
forked from
MoonshotAI/kimi-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
kimi-cli
/
src
/
kimi_cli
/
cli
/
toad.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (60 loc) · 2.17 KB
Breadcrumbs
kimi-cli
/
src
/
kimi_cli
/
cli
/
toad.py
Copy path
File metadata and controls
73 lines (60 loc) · 2.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
importlib
.
util
import
shlex
import
shutil
import
subprocess
import
sys
from
pathlib
import
Path
import
typer
def
_default_acp_command
()
->
list
[
str
]:
argv0
=
sys
.
argv
[
0
]
if
argv0
:
resolved
=
shutil
.
which
(
argv0
)
resolved_path
=
Path
(
resolved
).
expanduser
()
if
resolved
else
Path
(
argv0
).
expanduser
()
if
(
resolved_path
.
exists
()
and
resolved_path
.
suffix
!=
".py"
and
not
resolved_path
.
name
.
startswith
((
"python"
,
"pypy"
))
):
return
[
str
(
resolved_path
),
"acp"
]
return
[
sys
.
executable
,
"-m"
,
"kimi_cli.cli"
,
"acp"
]
def
_default_toad_command
()
->
list
[
str
]:
if
sys
.
version_info
<
(
3
,
14
):
typer
.
echo
(
"`kimi term` requires Python 3.14+ because Toad requires it."
,
err
=
True
)
raise
typer
.
Exit
(
code
=
1
)
if
importlib
.
util
.
find_spec
(
"toad"
)
is
None
:
typer
.
echo
(
"Toad dependency is missing. Install kimi-cli with Python 3.14+ to use `kimi term`."
,
err
=
True
,
)
raise
typer
.
Exit
(
code
=
1
)
return
[
sys
.
executable
,
"-m"
,
"toad.cli"
]
def
_extract_project_dir
(
extra_args
:
list
[
str
])
->
Path
|
None
:
work_dir
:
str
|
None
=
None
idx
=
0
while
idx
<
len
(
extra_args
):
arg
=
extra_args
[
idx
]
if
arg
in
(
"--work-dir"
,
"-w"
):
if
idx
+
1
<
len
(
extra_args
):
work_dir
=
extra_args
[
idx
+
1
]
idx
+=
2
continue
elif
arg
.
startswith
(
"--work-dir="
)
or
arg
.
startswith
(
"-w="
):
work_dir
=
arg
.
split
(
"="
,
1
)[
1
]
elif
arg
.
startswith
(
"-w"
)
and
len
(
arg
)
>
2
:
work_dir
=
arg
[
2
:]
idx
+=
1
if
not
work_dir
:
return
None
return
Path
(
work_dir
).
expanduser
().
resolve
()
def
run_term
(
ctx
:
typer
.
Context
)
->
None
:
extra_args
=
list
(
ctx
.
args
)
acp_args
=
_default_acp_command
()
acp_command
=
shlex
.
join
(
acp_args
)
toad_parts
=
_default_toad_command
()
args
=
[
*
toad_parts
,
"acp"
,
acp_command
]
project_dir
=
_extract_project_dir
(
extra_args
)
if
project_dir
is
not
None
:
args
.
append
(
str
(
project_dir
))
result
=
subprocess
.
run
(
args
)
if
result
.
returncode
!=
0
:
raise
typer
.
Exit
(
code
=
result
.
returncode
)
Back
|
FazBrowse Home
|
New Git URL