Skip to content
Merged

Undo #293

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion agentstack/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from .cli import configure_default_model, welcome_message, get_validated_input, parse_insertion_point
from .cli import (
configure_default_model,
welcome_message,
get_validated_input,
parse_insertion_point,
undo,
)
from .init import init_project
from .wizard import run_wizard
from .run import run_project
Expand Down
20 changes: 20 additions & 0 deletions agentstack/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from agentstack.exceptions import ValidationError
from agentstack.utils import validator_not_empty, is_snake_case
from agentstack.generation import InsertionPoint
from agentstack import repo


PREFERRED_MODELS = [
Expand Down Expand Up @@ -34,6 +35,25 @@ def welcome_message():
log.info(border)


def undo() -> None:
"""Undo the last committed changes."""
conf.assert_project()

changed_files = repo.get_uncommitted_files()
if changed_files:
log.warning("There are uncommitted changes that may be overwritten.")
for changed in changed_files:
log.info(f" - {changed}")
should_continue = inquirer.confirm(
message="Do you want to continue?",
default=False,
)
if not should_continue:
return

repo.revert_last_commit(hard=True)


def configure_default_model():
"""Set the default model"""
agentstack_config = ConfigFile()
Expand Down
6 changes: 5 additions & 1 deletion agentstack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
add_task,
run_project,
export_template,
undo,
)
from agentstack.telemetry import track_cli_command, update_telemetry
from agentstack.utils import get_version, term_color
Expand Down Expand Up @@ -154,7 +155,8 @@ def _main():
)
export_parser.add_argument('filename', help='The name of the file to export to')

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

# Parse known args and store unknown args in extras; some commands use them later on
args, extra_args = parser.parse_known_args()
Expand Down Expand Up @@ -228,6 +230,8 @@ def _main():
generate_parser.print_help()
elif args.command in ['export', 'e']:
export_template(args.filename)
elif args.command in ['undo']:
undo()
else:
parser.print_help()

Expand Down
21 changes: 21 additions & 0 deletions agentstack/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,24 @@ def get_uncommitted_files() -> list[str]:
untracked = repo.untracked_files
modified = [item.a_path for item in repo.index.diff(None) if item.a_path]
return untracked + modified


def revert_last_commit(hard: bool = False) -> None:
"""
Revert the last commit in the current project.
"""
try:
repo = _get_repo()
except EnvironmentError as e:
return # git is not installed or tracking is disabled

if len(repo.head.commit.parents) == 0:
log.error("No commits to revert.")
return

def _format_commit_message(commit):
return commit.message.split('\n')[0]

log.info(f"Reverting: {_format_commit_message(repo.head.commit)}")
repo.git.reset('HEAD~1', hard=hard)
log.info(f"Head is now at: {_format_commit_message(repo.head.commit)}")
59 changes: 51 additions & 8 deletions docs/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,6 @@ which adheres to a common pattern or exporting your project to share.
Templates are versioned, and each previous version provides a method to convert
it's content to the current version.

> TODO: Templates are currently identified as `proj_templates` since they conflict
with the templates used by `generation`. Move existing templates to be part of
the generation package.

### `TemplateConfig.from_user_input(identifier: str)`
`<TemplateConfig>` Returns a `TemplateConfig` object for either a URL, file path,
or builtin template name.
Expand Down Expand Up @@ -716,7 +712,7 @@ title: 'System Analyzer'
description: 'Inspect a project directory and improve it'
---

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

```bash
agentstack init --template=system_analyzer
Expand All @@ -737,7 +733,7 @@ title: 'Researcher'
description: 'Research and report result from a query'
---

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

```bash
agentstack init --template=research
Expand Down Expand Up @@ -828,7 +824,54 @@ title: 'Content Creator'
description: 'Research a topic and create content on it'
---

[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/proj_templates/content_creator.json)
[View Template](https://github.com/AgentOps-AI/AgentStack/blob/main/agentstack/templates/content_creator.json)

## frameworks/list.mdx

---
title: Frameworks
description: 'Supported frameworks in AgentStack'
icon: 'ship'
---

These are documentation links to the frameworks supported directly by AgentStack.

To start a project with one of these frameworks, use
```bash
agentstack init <project_name> --framework <framework_name>
```

## Framework Docs
<CardGroup cols={3}>
<Card
title="CrewAI"
icon="ship"
href="https://docs.crewai.com/introduction"
>
An intuitive agentic framework (recommended)
</Card>
<Card
title="LangGraph"
icon="circle-nodes"
href="https://langchain-ai.github.io/langgraph/"
>
A complex but capable framework with a _steep_ learning curve
</Card>
<Card
title="OpenAI Swarms"
icon="bee"
href="https://github.com/openai/swarm"
>
A simple framework with a cult following
</Card>
<Card
title="LlamaIndex"
icon="layer-group"
href="https://docs.llamaindex.ai/en/stable/"
>
An expansive framework with many ancillary features
</Card>
</CardGroup>

## tools/package-structure.mdx

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

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

Expand Down