-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ENG-9646: Reflex Init --agents #6620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ def _init( | |
| name: str, | ||
| template: str | None = None, | ||
| ai: bool = False, | ||
| agents: bool = False, | ||
| ): | ||
| """Initialize a new Reflex app in the given directory.""" | ||
| from reflex.utils import exec, frontend_skeleton, prerequisites, templates | ||
|
|
@@ -89,6 +90,10 @@ def _init( | |
| # Initialize the .gitignore. | ||
| frontend_skeleton.initialize_gitignore() | ||
|
|
||
| # Optionally write a sample AGENTS.md for AI coding agents. | ||
| if agents: | ||
| frontend_skeleton.initialize_agents_md() | ||
|
|
||
| template_msg = f" using the {template} template" if template else "" | ||
| if Path(constants.PyprojectToml.FILE).exists(): | ||
| needs_user_manual_update = False | ||
|
|
@@ -122,13 +127,19 @@ def _init( | |
| is_flag=True, | ||
| help="Use AI to create the initial template. Cannot be used with existing app or `--template` option.", | ||
| ) | ||
| @click.option( | ||
| "--agents", | ||
| is_flag=True, | ||
| help="Write a sample AGENTS.md to guide AI coding agents working in the app.", | ||
| ) | ||
|
Comment on lines
+130
to
+134
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought we wanted this be turned on by default? |
||
| def init( | ||
| name: str, | ||
| template: str | None, | ||
| ai: bool, | ||
| agents: bool, | ||
| ): | ||
| """Initialize a new Reflex app in the current directory.""" | ||
| _init(name, template, ai) | ||
| _init(name, template, ai, agents) | ||
|
|
||
|
|
||
| def _compile_app(*, avoid_dirty_check: bool = True): | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |||||||||||||
|
|
||||||||||||||
| from reflex.compiler import templates | ||||||||||||||
| from reflex.compiler.utils import write_file | ||||||||||||||
| from reflex.utils import console, path_ops | ||||||||||||||
| from reflex.utils import console, net, path_ops | ||||||||||||||
| from reflex.utils.prerequisites import get_project_hash, get_web_dir | ||||||||||||||
| from reflex.utils.registry import get_npm_registry | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -43,6 +43,37 @@ def initialize_gitignore( | |||||||||||||
| gitignore_file.write_text("\n".join(files_to_ignore) + "\n") | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def initialize_agents_md( | ||||||||||||||
| agents_file: Path = constants.AgentsMd.FILE, | ||||||||||||||
| url: str = constants.AgentsMd.CANONICAL_URL, | ||||||||||||||
| ): | ||||||||||||||
| """Write the AGENTS.md for AI coding agents, fetched from the canonical repo. | ||||||||||||||
|
|
||||||||||||||
| Does not overwrite an existing file so a user's customizations are preserved. | ||||||||||||||
| Aborts if the canonical file cannot be fetched. | ||||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
| agents_file: The AGENTS.md file to create in the app root. | ||||||||||||||
| url: The canonical AGENTS.md to download. | ||||||||||||||
| """ | ||||||||||||||
| if agents_file.exists(): | ||||||||||||||
| console.debug(f"{agents_file} already exists, skipping.") | ||||||||||||||
| return | ||||||||||||||
|
|
||||||||||||||
| import httpx | ||||||||||||||
|
|
||||||||||||||
| console.debug(f"Fetching {url}") | ||||||||||||||
| try: | ||||||||||||||
| response = net.get(url, timeout=5) | ||||||||||||||
| response.raise_for_status() | ||||||||||||||
| except httpx.HTTPError as e: | ||||||||||||||
| console.error(f"Failed to fetch AGENTS.md from {url} due to {e}.") | ||||||||||||||
| raise SystemExit(1) from None | ||||||||||||||
|
Comment on lines
+69
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| console.debug(f"Creating {agents_file}") | ||||||||||||||
| agents_file.write_text(response.text) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have a starter marker and finish marker so one can add other things in AGENTS.md |
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def _read_dependency_file(file_path: Path) -> tuple[str | None, str | None]: | ||||||||||||||
| """Read a dependency file with a forgiving encoding strategy. | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you test the efficacy of this line