Skip to content

Commit ca495c9

Browse files
authored
Merge pull request #293 from tcdent/undo
Undo
2 parents c9ed3a6 + 3630692 commit ca495c9

File tree

5 files changed

+104
-10
lines changed

5 files changed

+104
-10
lines changed

agentstack/cli/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
from .cli import configure_default_model, welcome_message, get_validated_input, parse_insertion_point
1+
from .cli import (
2+
configure_default_model,
3+
welcome_message,
4+
get_validated_input,
5+
parse_insertion_point,
6+
undo,
7+
)
28
from .init import init_project
39
from .wizard import run_wizard
410
from .run import run_project

agentstack/cli/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from agentstack.exceptions import ValidationError
88
from agentstack.utils import validator_not_empty, is_snake_case
99
from agentstack.generation import InsertionPoint
10+
from agentstack import repo
1011

1112

1213
PREFERRED_MODELS = [
@@ -34,6 +35,25 @@ def welcome_message():
3435
log.info(border)
3536

3637

38+
def undo() -> None:
39+
"""Undo the last committed changes."""
40+
conf.assert_project()
41+
42+
changed_files = repo.get_uncommitted_files()
43+
if changed_files:
44+
log.warning("There are uncommitted changes that may be overwritten.")
45+
for changed in changed_files:
46+
log.info(f" - {changed}")
47+
should_continue = inquirer.confirm(
48+
message="Do you want to continue?",
49+
default=False,
50+
)
51+
if not should_continue:
52+
return
53+
54+
repo.revert_last_commit(hard=True)
55+
56+
3757
def configure_default_model():
3858
"""Set the default model"""
3959
agentstack_config = ConfigFile()

agentstack/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
add_task,
1414
run_project,
1515
export_template,
16+
undo,
1617
)
1718
from agentstack.telemetry import track_cli_command, update_telemetry
1819
from agentstack.utils import get_version, term_color
@@ -154,7 +155,8 @@ def _main():
154155
)
155156
export_parser.add_argument('filename', help='The name of the file to export to')
156157

157-
update = subparsers.add_parser('update', aliases=['u'], help='Check for updates', parents=[global_parser])
158+
undo_parser = subparsers.add_parser('undo', help='Undo the last change to your project', parents=[global_parser])
159+
update_parser = subparsers.add_parser('update', aliases=['u'], help='Check for updates', parents=[global_parser])
158160

159161
# Parse known args and store unknown args in extras; some commands use them later on
160162
args, extra_args = parser.parse_known_args()
@@ -228,6 +230,8 @@ def _main():
228230
generate_parser.print_help()
229231
elif args.command in ['export', 'e']:
230232
export_template(args.filename)
233+
elif args.command in ['undo']:
234+
undo()
231235
else:
232236
parser.print_help()
233237

agentstack/repo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,24 @@ def get_uncommitted_files() -> list[str]:
190190
untracked = repo.untracked_files
191191
modified = [item.a_path for item in repo.index.diff(None) if item.a_path]
192192
return untracked + modified
193+
194+
195+
def revert_last_commit(hard: bool = False) -> None:
196+
"""
197+
Revert the last commit in the current project.
198+
"""
199+
try:
200+
repo = _get_repo()
201+
except EnvironmentError as e:
202+
return # git is not installed or tracking is disabled
203+
204+
if len(repo.head.commit.parents) == 0:
205+
log.error("No commits to revert.")
206+
return
207+
208+
def _format_commit_message(commit):
209+
return commit.message.split('\n')[0]
210+
211+
log.info(f"Reverting: {_format_commit_message(repo.head.commit)}")
212+
repo.git.reset('HEAD~1', hard=hard)
213+
log.info(f"Head is now at: {_format_commit_message(repo.head.commit)}")

docs/llms.txt

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,6 @@ which adheres to a common pattern or exporting your project to share.
514514
Templates are versioned, and each previous version provides a method to convert
515515
it's content to the current version.
516516

517-
> TODO: Templates are currently identified as `proj_templates` since they conflict
518-
with the templates used by `generation`. Move existing templates to be part of
519-
the generation package.
520-
521517
### `TemplateConfig.from_user_input(identifier: str)`
522518
`<TemplateConfig>` Returns a `TemplateConfig` object for either a URL, file path,
523519
or builtin template name.
@@ -716,7 +712,7 @@ title: 'System Analyzer'
716712
description: 'Inspect a project directory and improve it'
717713
---
718714

719-
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/proj_templates/system_analyzer.json)
715+
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/system_analyzer.json)
720716

721717
```bash
722718
agentstack init --template=system_analyzer
@@ -737,7 +733,7 @@ title: 'Researcher'
737733
description: 'Research and report result from a query'
738734
---
739735

740-
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/proj_templates/research.json)
736+
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/research.json)
741737

742738
```bash
743739
agentstack init --template=research
@@ -828,7 +824,54 @@ title: 'Content Creator'
828824
description: 'Research a topic and create content on it'
829825
---
830826

831-
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/proj_templates/content_creator.json)
827+
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/content_creator.json)
828+
829+
## frameworks/list.mdx
830+
831+
---
832+
title: Frameworks
833+
description: 'Supported frameworks in AgentStack'
834+
icon: 'ship'
835+
---
836+
837+
These are documentation links to the frameworks supported directly by AgentStack.
838+
839+
To start a project with one of these frameworks, use
840+
```bash
841+
agentstack init <project_name> --framework <framework_name>
842+
```
843+
844+
## Framework Docs
845+
<CardGroup cols={3}>
846+
<Card
847+
title="CrewAI"
848+
icon="ship"
849+
href="https://docs.crewai.com/introduction"
850+
>
851+
An intuitive agentic framework (recommended)
852+
</Card>
853+
<Card
854+
title="LangGraph"
855+
icon="circle-nodes"
856+
href="https://langchain-ai.github.io/langgraph/"
857+
>
858+
A complex but capable framework with a _steep_ learning curve
859+
</Card>
860+
<Card
861+
title="OpenAI Swarms"
862+
icon="bee"
863+
href="https://github.com/openai/swarm"
864+
>
865+
A simple framework with a cult following
866+
</Card>
867+
<Card
868+
title="LlamaIndex"
869+
icon="layer-group"
870+
href="https://docs.llamaindex.ai/en/stable/"
871+
>
872+
An expansive framework with many ancillary features
873+
</Card>
874+
</CardGroup>
832875

833876
## tools/package-structure.mdx
834877

@@ -1043,7 +1086,7 @@ You can pass the `--wizard` flag to `agentstack init` to use an interactive proj
10431086
You can also pass a `--template=<template_name>` argument to `agentstack init` which will pre-populate your project with functionality
10441087
from a built-in template, or one found on the internet. A `template_name` can be one of three identifiers:
10451088

1046-
- A built-in AgentStack template (see the `templates/proj_templates` directory in the AgentStack repo for bundled templates).
1089+
- A built-in AgentStack template (see the `templates` directory in the AgentStack repo for bundled templates).
10471090
- A template file from the internet; pass the full https URL of the template.
10481091
- A local template file; pass an absolute or relative path.
10491092

0 commit comments

Comments
 (0)