Skip to content

Commit b11e895

Browse files
committed
[IMP] F#T66868 workflow has commit_if_change option
1 parent dc19f0d commit b11e895

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ Or one of the above command can be ran to run the agent with multiple instructio
3636
steps:
3737
- name: name of the step
3838
original: original instruction
39-
work_dir: optionally work directory
39+
work_dir: optional work directory
4040
command: bash command to run
4141
- name: name of other step
4242
original: original instruction
43-
condition: bash command to run and check the return code
43+
condition: optional bash command to run and check the return code
4444
instruction: instruction to run the agent
4545
- name: name of other step
4646
original: original instruction
4747
ignore: true
4848
notes: notes
4949
```
5050
51+
step can have `files` set to a list of files to inclde in the instruction for the agent to consult.
52+
53+
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.
54+
5155
```bash
5256
--backend <agent name>
5357
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "trobz-agent"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
description = "Run an AI agent"
55
authors = [{name = "Hai Lang", email = "hailn@trobz.com"}]
66
requires-python = ">=3.10"

trobz_agent/agent.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def run(cwd, *args, **kwargs):
2828
return subprocess.run(args, **kwargs) # noqa: S603
2929

3030

31+
def run_read(cwd, *args, **kwargs):
32+
"""Shortcut to run a command in a given directory."""
33+
return run(cwd, *args, **kwargs, stdout=subprocess.PIPE).stdout.decode("utf-8")
34+
35+
3136
def run_agent(cwd, instructions, backend, mode, model):
3237
if backend == "codex":
3338
cmd_args = ["codex", "--full-auto"]
@@ -64,6 +69,21 @@ def inject_var(command):
6469
return command.replace("{module_dir}", ".")
6570

6671

72+
def commit_if_change(cwd, step):
73+
changes = run_read(cwd, "git", "status", "--short")
74+
if not changes:
75+
return
76+
for line in changes.split("\n"):
77+
line = line[3:]
78+
if not line.strip() or line.startswith(".."):
79+
continue
80+
run(cwd, "git", "add", line.strip())
81+
message = step["commit_if_change"]
82+
if message == True: # noqa: E712
83+
message = step["name"]
84+
run(cwd, "git", "commit", "-m", message)
85+
86+
6787
def run_workflow(workflow_dir, workflow, backend, mode, model): # noqa: C901
6888
for step in workflow["steps"]:
6989
if step.get("ignore", False):
@@ -98,6 +118,8 @@ def run_workflow(workflow_dir, workflow, backend, mode, model): # noqa: C901
98118
instruction += "\n```\n"
99119
if not error:
100120
run_agent(cwd, instruction, backend, mode, model)
121+
if step.get("commit_if_change"):
122+
commit_if_change(cwd, step)
101123

102124

103125
def main(

0 commit comments

Comments
 (0)