Skip to content

Commit aebf0c9

Browse files
committed
refactored cli_step into dedicated file and added full agenttide as individual cli
1 parent 32fb3fc commit aebf0c9

File tree

2 files changed

+96
-56
lines changed

2 files changed

+96
-56
lines changed

codetide/agents/tide/cli.py

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,40 @@
1-
from ...mcp.utils import initCodeTide
2-
from . import AgentTide
3-
4-
5-
try:
6-
from aicore.logger import _logger
7-
from aicore.config import Config
8-
from aicore.llm import Llm
9-
except ImportError as e:
10-
raise ImportError(
11-
"The 'codetide.agents' module requires the 'aicore' package. "
12-
"Install it with: pip install codetide[agents]"
13-
) from e
141

152
from pathlib import Path
16-
import os
3+
import argparse
4+
import asyncio
175

18-
DEFAULT_AGENT_TIDE_LLM_CONFIG = "./config/agent_tide_llm_config.yml"
19-
DEFAULT_MAX_TOKENS = 48000
6+
from ...mcp.utils import initCodeTide
7+
from .cli_step import init_llm, DEFAULT_MAX_HISTORY_TOKENS
8+
from .agent import AgentTide
209

21-
def init_llm(project_path :Path)->Llm:
22-
# TODO change this to from default path
23-
config_path = os.getenv("AGENT_TIDE_CONFIG_PATH", DEFAULT_AGENT_TIDE_LLM_CONFIG)
24-
llm = Llm.from_config(Config.from_yaml(project_path / config_path).llm)
25-
return llm
10+
def main():
11+
parser = argparse.ArgumentParser(description="AgentTide Full Terminal CLI")
12+
parser.add_argument(
13+
"--project_path",
14+
type=str,
15+
default=".",
16+
help="Path to the project root (default: current directory)"
17+
)
18+
parser.add_argument(
19+
"--max_history_tokens",
20+
type=int,
21+
default=DEFAULT_MAX_HISTORY_TOKENS,
22+
help=f"Maximum number of tokens to keep in history (default: {DEFAULT_MAX_HISTORY_TOKENS})"
23+
)
24+
args = parser.parse_args()
2625

27-
async def run_tide_step(project_path :str, history :list):
28-
if not history:
29-
return
26+
asyncio.run(run_agent_tide_cli(args.project_path, args.max_history_tokens))
3027

28+
async def run_agent_tide_cli(project_path: str, max_history_tokens: int):
3129
project_path = Path(project_path)
32-
_logger.logger.remove()
33-
3430
llm = init_llm(project_path)
3531
tide = await initCodeTide(workspace=project_path)
36-
37-
aTide = AgentTide(
32+
agent = AgentTide(
3833
llm=llm,
3934
tide=tide,
40-
history=history
35+
history=[]
4136
)
42-
aTide.trim_messages(aTide.history, llm.tokenizer, os.getenv("AGENT_TIDE_MAX_HISTORY_TOKENS", DEFAULT_MAX_TOKENS))
43-
44-
await aTide.agent_loop()
45-
37+
await agent.run(max_tokens=max_history_tokens)
4638

47-
def parse_history_arg(history_arg):
48-
import json
49-
import os
50-
if not history_arg:
51-
return []
52-
if os.path.isfile(history_arg):
53-
with open(history_arg, "r", encoding="utf-8") as f:
54-
return json.load(f)
55-
try:
56-
return json.loads(history_arg)
57-
except Exception:
58-
return [history_arg]
59-
60-
61-
def main():
62-
import argparse
63-
import asyncio
64-
parser = argparse.ArgumentParser(description="AgentTide Step CLI")
65-
parser.add_argument("project_path", help="Path to the project root")
66-
parser.add_argument("history", nargs="?", default=None, help="History as JSON string, file path, or single message")
67-
args = parser.parse_args()
68-
history = parse_history_arg(args.history)
69-
asyncio.run(run_tide_step(args.project_path, history))
39+
if __name__ == "__main__":
40+
main()

codetide/agents/tide/cli_step.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from ...mcp.utils import initCodeTide
2+
from . import AgentTide
3+
4+
5+
try:
6+
from aicore.logger import _logger
7+
from aicore.config import Config
8+
from aicore.llm import Llm
9+
except ImportError as e:
10+
raise ImportError(
11+
"The 'codetide.agents' module requires the 'aicore' package. "
12+
"Install it with: pip install codetide[agents]"
13+
) from e
14+
15+
from pathlib import Path
16+
import os
17+
18+
DEFAULT_AGENT_TIDE_LLM_CONFIG = "./config/agent_tide_llm_config.yml"
19+
DEFAULT_MAX_HISTORY_TOKENS = 48000
20+
21+
def init_llm(project_path :Path)->Llm:
22+
# TODO change this to from default path
23+
config_path = os.getenv("AGENT_TIDE_CONFIG_PATH", DEFAULT_AGENT_TIDE_LLM_CONFIG)
24+
llm = Llm.from_config(Config.from_yaml(project_path / config_path).llm)
25+
return llm
26+
27+
async def run_tide_step(project_path :str, history :list):
28+
if not history:
29+
return
30+
31+
project_path = Path(project_path)
32+
_logger.logger.remove()
33+
34+
llm = init_llm(project_path)
35+
tide = await initCodeTide(workspace=project_path)
36+
37+
aTide = AgentTide(
38+
llm=llm,
39+
tide=tide,
40+
history=history
41+
)
42+
aTide.trim_messages(aTide.history, llm.tokenizer, os.getenv("AGENT_TIDE_MAX_HISTORY_TOKENS", DEFAULT_MAX_HISTORY_TOKENS))
43+
44+
await aTide.agent_loop()
45+
46+
47+
def parse_history_arg(history_arg):
48+
import json
49+
import os
50+
if not history_arg:
51+
return []
52+
if os.path.isfile(history_arg):
53+
with open(history_arg, "r", encoding="utf-8") as f:
54+
return json.load(f)
55+
try:
56+
return json.loads(history_arg)
57+
except Exception:
58+
return [history_arg]
59+
60+
61+
def main():
62+
import argparse
63+
import asyncio
64+
parser = argparse.ArgumentParser(description="AgentTide Step CLI")
65+
parser.add_argument("project_path", help="Path to the project root")
66+
parser.add_argument("history", nargs="?", default=None, help="History as JSON string, file path, or single message")
67+
args = parser.parse_args()
68+
history = parse_history_arg(args.history)
69+
asyncio.run(run_tide_step(args.project_path, history))

0 commit comments

Comments
 (0)