Skip to content

Commit ee1ed3f

Browse files
committed
added step cli for Agent Tide
1 parent e1ccfca commit ee1ed3f

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

codetide/agents/tide/cli.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_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_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)