diff --git a/libs/agentc_cli/agentc_cli/cmds/add.py b/libs/agentc_cli/agentc_cli/cmds/add.py index 11012415..f940ad9c 100644 --- a/libs/agentc_cli/agentc_cli/cmds/add.py +++ b/libs/agentc_cli/agentc_cli/cmds/add.py @@ -2,7 +2,10 @@ import datetime import jinja2 import logging +import os import pathlib +import platform +import subprocess import typing from ..models.context import Context @@ -10,6 +13,15 @@ logger = logging.getLogger(__name__) +if os.environ.get("EDITOR"): + default_editor = os.environ.get("EDITOR") +elif os.environ.get("VISUAL"): + default_editor = os.environ.get("VISUAL") +elif platform.system() == "Windows": + default_editor = "notepad" +else: + default_editor = "vi" + def _get_name_and_description() -> tuple[str, str]: name = click.prompt("Name", type=str) @@ -37,6 +49,7 @@ def add_jinja_prompt(output: pathlib.Path, template_env: jinja2.Environment): with output_file.open("w") as fp: fp.write(rendered) click.secho(f"Jinja prompt written to: {output_file}", fg="green") + subprocess.run([default_editor, f"{output_file}"]) def add_raw_prompt(output: pathlib.Path, template_env: jinja2.Environment): @@ -56,6 +69,7 @@ def add_raw_prompt(output: pathlib.Path, template_env: jinja2.Environment): with output_file.open("w") as fp: fp.write(rendered) click.secho(f"Raw prompt written to: {output_file}", fg="green") + subprocess.run([default_editor, f"{output_file}"]) def add_http_request(output: pathlib.Path, template_env: jinja2.Environment): @@ -82,6 +96,7 @@ def add_http_request(output: pathlib.Path, template_env: jinja2.Environment): with output_file.open("w") as fp: fp.write(rendered) click.secho(f"HTML request tool written to: {output_file}", fg="green") + subprocess.run([default_editor, f"{output_file}"]) def add_python_function(output: pathlib.Path, template_env: jinja2.Environment): @@ -99,6 +114,7 @@ def add_python_function(output: pathlib.Path, template_env: jinja2.Environment): with output_file.open("w") as fp: fp.write(rendered) click.secho(f"Python (function) tool written to: {output_file}", fg="green") + subprocess.run([default_editor, f"{output_file}"]) def add_semantic_search(output: pathlib.Path, template_env: jinja2.Environment): @@ -133,6 +149,7 @@ def add_semantic_search(output: pathlib.Path, template_env: jinja2.Environment): with output_file.open("w") as fp: fp.write(rendered) click.secho(f"Semantic search tool written to: {output_file}", fg="green") + subprocess.run([default_editor, f"{output_file}"]) def add_sqlpp_query(output: pathlib.Path, template_env: jinja2.Environment): @@ -150,6 +167,7 @@ def add_sqlpp_query(output: pathlib.Path, template_env: jinja2.Environment): with output_file.open("w") as fp: fp.write(rendered) click.secho(f"SQL++ query tool written to: {output_file}", fg="green") + subprocess.run([default_editor, f"{output_file}"]) def cmd_add( diff --git a/libs/agentc_cli/agentc_cli/main.py b/libs/agentc_cli/agentc_cli/main.py index 29b4e004..54b8d084 100644 --- a/libs/agentc_cli/agentc_cli/main.py +++ b/libs/agentc_cli/agentc_cli/main.py @@ -133,7 +133,7 @@ def click_main(ctx, catalog, activity, verbose, interactive): ) @click.pass_context def add(ctx, output: pathlib.Path, record_kind: RecordKind): - """Interactively create a new tool or prompt and save it to the filesystem (output).""" + """Interactively create a new tool or prompt and save it to the filesystem (output). You MUST edit the generated file as per your requirements!""" ctx_obj: Context = ctx.obj if not ctx_obj.interactive: click.secho( diff --git a/libs/agentc_core/agentc_core/tool/generate/templates/httpreq_q.jinja b/libs/agentc_core/agentc_core/tool/generate/templates/httpreq_q.jinja index 0f7c7e31..2ee38a91 100644 --- a/libs/agentc_core/agentc_core/tool/generate/templates/httpreq_q.jinja +++ b/libs/agentc_core/agentc_core/tool/generate/templates/httpreq_q.jinja @@ -1,4 +1,3 @@ -""" This file has been generated automatically by AGENT_CATALOG at {{ time }} as a http_request tool. """ from __future__ import annotations import requests diff --git a/libs/agentc_core/agentc_core/tool/generate/templates/semantic_q.jinja b/libs/agentc_core/agentc_core/tool/generate/templates/semantic_q.jinja index f0a169c4..edad90be 100644 --- a/libs/agentc_core/agentc_core/tool/generate/templates/semantic_q.jinja +++ b/libs/agentc_core/agentc_core/tool/generate/templates/semantic_q.jinja @@ -1,4 +1,3 @@ -""" This file has been generated automatically by AGENT_CATALOG at {{ time }} as a semantic_search tool. """ from __future__ import annotations import couchbase.auth diff --git a/libs/agentc_core/agentc_core/tool/generate/templates/sqlpp_q.jinja b/libs/agentc_core/agentc_core/tool/generate/templates/sqlpp_q.jinja index d6fa4f3c..0652fd80 100644 --- a/libs/agentc_core/agentc_core/tool/generate/templates/sqlpp_q.jinja +++ b/libs/agentc_core/agentc_core/tool/generate/templates/sqlpp_q.jinja @@ -1,4 +1,3 @@ -""" This file has been generated automatically by AGENT_CATALOG at {{ time }} as a sqlpp_query tool. """ from __future__ import annotations import couchbase.auth