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 @@
log.info(border)


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

Check warning on line 40 in agentstack/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

agentstack/cli/cli.py#L40

Added line #L40 was not covered by tests

changed_files = repo.get_uncommitted_files()

Check warning on line 42 in agentstack/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

agentstack/cli/cli.py#L42

Added line #L42 was not covered by tests
if changed_files:
log.warning("There are uncommitted changes that may be overwritten.")

Check warning on line 44 in agentstack/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

agentstack/cli/cli.py#L44

Added line #L44 was not covered by tests
for changed in changed_files:
log.info(f" - {changed}")
should_continue = inquirer.confirm(

Check warning on line 47 in agentstack/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

agentstack/cli/cli.py#L46-L47

Added lines #L46 - L47 were not covered by tests
message="Do you want to continue?",
default=False,
)
if not should_continue:
return

Check warning on line 52 in agentstack/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

agentstack/cli/cli.py#L52

Added line #L52 was not covered by tests

repo.revert_last_commit(hard=True)

Check warning on line 54 in agentstack/cli/cli.py

View check run for this annotation

Codecov / codecov/patch

agentstack/cli/cli.py#L54

Added line #L54 was not covered by tests


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 @@
)
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])

Check warning on line 159 in agentstack/main.py

View check run for this annotation

Codecov / codecov/patch

agentstack/main.py#L158-L159

Added lines #L158 - L159 were not covered by tests

# 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 @@
generate_parser.print_help()
elif args.command in ['export', 'e']:
export_template(args.filename)
elif args.command in ['undo']:
undo()

Check warning on line 234 in agentstack/main.py

View check run for this annotation

Codecov / codecov/patch

agentstack/main.py#L234

Added line #L234 was not covered by tests
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 @@
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

Check warning on line 202 in agentstack/repo.py

View check run for this annotation

Codecov / codecov/patch

agentstack/repo.py#L199-L202

Added lines #L199 - L202 were not covered by tests

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

Check warning on line 206 in agentstack/repo.py

View check run for this annotation

Codecov / codecov/patch

agentstack/repo.py#L205-L206

Added lines #L205 - L206 were not covered by tests

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

Check warning on line 209 in agentstack/repo.py

View check run for this annotation

Codecov / codecov/patch

agentstack/repo.py#L208-L209

Added lines #L208 - L209 were not covered by tests

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)}")

Check warning on line 213 in agentstack/repo.py

View check run for this annotation

Codecov / codecov/patch

agentstack/repo.py#L211-L213

Added lines #L211 - L213 were not covered by tests
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