From 94491fd7dafe1553bacb7047625bcb9fb8aa984b Mon Sep 17 00:00:00 2001 From: Hai Lang Date: Mon, 22 Dec 2025 09:43:49 +0700 Subject: [PATCH] [IMP] F#T66868 workflow has commit_if_change option --- README.md | 8 ++++++-- pyproject.toml | 2 +- trobz_agent/agent.py | 18 ++++++++++++++++++ uv.lock | 4 ++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 229d48c..fadbe10 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ Or one of the above command can be ran to run the agent with multiple instructio steps: - name: name of the step original: original instruction - work_dir: optionally work directory + work_dir: optional work directory command: bash command to run - name: name of other step original: original instruction - condition: bash command to run and check the return code + condition: optional bash command to run and check the return code instruction: instruction to run the agent - name: name of other step original: original instruction @@ -48,6 +48,10 @@ Or one of the above command can be ran to run the agent with multiple instructio notes: notes ``` +step can have `files` set to a list of files to include in the instruction for the agent to consult. + +step can have `commit_if_change` set to either `true` or a string to commit the changes. If set to true, the step name is used as the commit message. If set to a string, the string is used instead. + ```bash --backend ``` diff --git a/pyproject.toml b/pyproject.toml index 6b1bb2c..37224b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trobz-agent" -version = "1.0.0" +version = "1.0.1" description = "Run an AI agent" authors = [{name = "Hai Lang", email = "hailn@trobz.com"}] requires-python = ">=3.10" diff --git a/trobz_agent/agent.py b/trobz_agent/agent.py index 330d2d4..c089031 100644 --- a/trobz_agent/agent.py +++ b/trobz_agent/agent.py @@ -28,6 +28,11 @@ def run(cwd, *args, **kwargs): return subprocess.run(args, **kwargs) # noqa: S603 +def run_read(cwd, *args, **kwargs): + """Shortcut to run a command in a given directory.""" + return run(cwd, *args, **kwargs, stdout=subprocess.PIPE).stdout.decode("utf-8") + + def run_agent(cwd, instructions, backend, mode, model): if backend == "codex": cmd_args = ["codex", "--full-auto"] @@ -64,6 +69,17 @@ def inject_var(command): return command.replace("{module_dir}", ".") +def commit_if_change(cwd, step): + changes = run_read(cwd, "git", "status", "--short") + if not changes.strip(): + return + run(cwd, "git", "add", ".") + message = step["commit_if_change"] + if message == True: # noqa: E712 + message = step["name"] + run(cwd, "git", "commit", "-m", message) + + def run_workflow(workflow_dir, workflow, backend, mode, model): # noqa: C901 for step in workflow["steps"]: if step.get("ignore", False): @@ -98,6 +114,8 @@ def run_workflow(workflow_dir, workflow, backend, mode, model): # noqa: C901 instruction += "\n```\n" if not error: run_agent(cwd, instruction, backend, mode, model) + if step.get("commit_if_change"): + commit_if_change(cwd, step) def main( diff --git a/uv.lock b/uv.lock index 9468e79..6336fb1 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 2 +revision = 3 requires-python = ">=3.10" [[package]] @@ -343,7 +343,7 @@ wheels = [ [[package]] name = "trobz-agent" -version = "1.0.0" +version = "1.0.1" source = { editable = "." } dependencies = [ { name = "typer" },