From 209ae03aeb2491fa1b2f2ec51c025005f91a2e63 Mon Sep 17 00:00:00 2001 From: Senko Rasic Date: Sat, 23 Mar 2024 10:02:23 -0700 Subject: [PATCH] Use a React-based TODO app as an example project --- pilot/const/common.py | 101 ++++++++++++++++++++------- pilot/helpers/agents/Architect.py | 26 ++++--- pilot/helpers/agents/ProductOwner.py | 7 +- pilot/helpers/agents/TechLead.py | 30 ++++---- 4 files changed, 110 insertions(+), 54 deletions(-) diff --git a/pilot/const/common.py b/pilot/const/common.py index 9a5b18cc53..f372775b1f 100644 --- a/pilot/const/common.py +++ b/pilot/const/common.py @@ -52,30 +52,77 @@ IGNORE_SIZE_THRESHOLD = 50000 # 50K+ files are ignored by default PROMPT_DATA_TO_IGNORE = {'directory_tree', 'name'} -EXAMPLE_PROJECT_DESCRIPTION = ( - "A simple webchat application in node/express using MongoDB. " - "Use Bootstrap and jQuery on the frontend, for a simple, clean UI. " - "Use socket.io for real-time communication between backend and frontend.\n\n" - "Visiting http://localhost:3000/, users must first log in or create an account using " - "a username and a password (no email required).\n\n" - "Once authenticated, on the home screen users see list of active chat rooms and a button to create a new chat. " - "They can either click a link to one of the chat rooms which redirects them to `//` " - "or click the button to create a new chat. Creating a new chat should ask for the chat name, " - "and then create a new chat with that name (which doesn't need to be unique), and a unique chat id. " - "The user should then be redirected to the chat page.\n\n" - "Chat page should have the chat name as the title. There's no possibility to edit chat name. " - "Below that, show previous messages in the chat (these should get loaded from the database " - "whenever the user visits the page so the user sees previous conversation in that chat - " - "no pagination, entire history should be loaded). " - "User has a text field and a button 'send' to send the message " - "(pressing enter in the text field should also send the message). " - "There's also a button to change user's nickname (default is equal to username, " - "there's no need to store the nickname in the user's profile).\n\n" - "Sent messages should be immediately shown to other participants in the same chat (use socket.io), " - "and stored in the database (forever - no message expiry). " - "All messages are text-only: no image upload, no embedding, no special markup in the messages. " - "There's no message size limit. Also, there's no need to notify/alert user of new messages, or keep track of unread messages.\n\n" - "All channels are available to all authenticated users, there are no private messages. " - "Anonymous users can't see or join any chat rooms, the can only log in or create an account. " - "No moderation, filtering or any admin functionality is required. Keep everything else as simple as possible." -) +EXAMPLE_PROJECT_DESCRIPTION = """ +The application is a simple ToDo app built using React. Its primary function is to allow users to manage a list of tasks (todos). Each task has a description and a state (open or completed, with the default state being open). The application is frontend-only, with no user sign-up or authentication process. The goal is to provide a straightforward and user-friendly interface for task management. + +Features: +1. Display of Todos: A list that displays all todo items. Each item shows its description and a checkbox to indicate its state (open or completed). +2. Add New Todo: A button to add a new todo item. Clicking this button will prompt the user to enter a description for the new todo. +3. Toggle State: Each todo item includes a checkbox. Checking/unchecking this box toggles the todo's state between open and completed. +4. Local Storage: The application will use the browser's local storage to persist todos between sessions, ensuring that users do not lose their data upon reloading the application. + +Functional Specification: +- Upon loading the application, it fetches existing todos from the local storage and displays them in a list. +- Each todo item in the list displays a checkbox and a description. The checkbox reflects the todo's current state (checked for completed, unchecked for open). +- When the user checks or unchecks a checkbox, the application updates the state of the corresponding todo item and saves the updated list to local storage. +- Clicking the "Add New Todo" button prompts the user to enter a description for the new todo. Upon confirmation, the application adds the new todo (with the default state of open) to the list and updates local storage. +- The application does not support deleting or editing todo items to keep the interface and interactions simple. +- Todos persist between sessions using the browser's local storage. The application saves any changes to the todo list (additions or state changes) in local storage and retrieves this data when the application is reloaded. + +Technical Specification: +- Platform/Technologies: The application is a web application developed using React. No backend technologies are required. +- Styling: Use Bootstrap 5 for a simple and functional interface. Load Boostrap from the CDN (don't install it locally): + - https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css + - https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js +- State Management: Directly in the React component + - make sure to initialize the state from the local storage as default (... = useState(JSON.parse(localStorage.getItem('todos')) || []) to avoid race conditions +- Data Persistence: The application uses the browser's local storage to persist todos between sessions. It stores the array of todos as a JSON string and parses this data on application load. +""" + +EXAMPLE_PROJECT_ARCHITECTURE = { + "architecture": ( + "The application is a client-side React web application that uses local storage for data persistence. " + "It consists of a single page with components for listing todos, adding new todos, and toggling their completion status. " + "State management is handled directly within React components, leveraging useState and useEffect hooks for state manipulation and side effects, respectively. " + "Bootstrap 5 is used for styling to provide a responsive and accessible UI." + ), + "system_dependencies": [ + { + "name": "Node.js", + "description": "JavaScript runtime needed to run the React development tools and build the project.", + "test": "node --version", + "required_locally": True + } + ], + "package_dependencies": [ + { + "name": "react", + "description": "A JavaScript library for building user interfaces." + }, + { + "name": "react-dom", + "description": "Serves as the entry point to the DOM and server renderers for React." + }, + { + "name": "bootstrap", + "description": "Frontend framework for developing responsive and mobile-first websites." + } + ], + "template": "javascript_react" +} + +EXAMPLE_PROJECT_PLAN = [ + { + "description": ( + "Create a new component TodoList: This component will display the list of todo items. " + "Use localStorage directly to access the current state of todos and map over them, rendering each todo item as a list item. " + "Each item should display the todo's description and a checkbox that reflects the todo's state (checked for completed, unchecked for open). " + "When the checkbox is clicked, dispatch an action to toggle the state of the todo. " + "Also create AddTodo: This component will include a button that, when clicked, displays a prompt asking the user for a description of the new todo. " + "Upon confirmation, dispatch an action to add the new todo to the state with a default state of open. " + "Ensure the component also updates the local storage with the new list of todos. " + "Finally, use TodoList and AddTodo components in App component to implement the required functionality. " + "Integrate Boostrap 5 for styling - add CSS/JS to index.html, style App.jsx and other files as appropriate." + ) + } +] diff --git a/pilot/helpers/agents/Architect.py b/pilot/helpers/agents/Architect.py index 21efc1648c..cc028ae928 100644 --- a/pilot/helpers/agents/Architect.py +++ b/pilot/helpers/agents/Architect.py @@ -4,6 +4,7 @@ import json from utils.style import color_green_bold, color_yellow_bold from const.function_calls import ARCHITECTURE +from const.common import EXAMPLE_PROJECT_ARCHITECTURE import platform from utils.utils import should_execute_step, generate_app_data @@ -64,17 +65,20 @@ class Architect(Agent): logger.info("Planning project architecture...") self.convo_architecture = AgentConvo(self) - llm_response = self.convo_architecture.send_message('architecture/technologies.prompt', - {'name': self.project.args['name'], - 'app_summary': self.project.project_description, - 'user_stories': self.project.user_stories, - 'user_tasks': self.project.user_tasks, - "os": platform.system(), - 'app_type': self.project.args['app_type'], - "templates": PROJECT_TEMPLATES, - }, - ARCHITECTURE - ) + if self.project.project_manager.is_example_project: + llm_response = EXAMPLE_PROJECT_ARCHITECTURE + else: + llm_response = self.convo_architecture.send_message('architecture/technologies.prompt', + {'name': self.project.args['name'], + 'app_summary': self.project.project_description, + 'user_stories': self.project.user_stories, + 'user_tasks': self.project.user_tasks, + "os": platform.system(), + 'app_type': self.project.args['app_type'], + "templates": PROJECT_TEMPLATES, + }, + ARCHITECTURE + ) self.project.architecture = llm_response["architecture"] self.project.system_dependencies = llm_response["system_dependencies"] diff --git a/pilot/helpers/agents/ProductOwner.py b/pilot/helpers/agents/ProductOwner.py index 51cfc375e9..bfaecbec75 100644 --- a/pilot/helpers/agents/ProductOwner.py +++ b/pilot/helpers/agents/ProductOwner.py @@ -19,6 +19,7 @@ USER_TASKS_STEP = 'user_tasks' class ProductOwner(Agent): def __init__(self, project): super().__init__('product_owner', project) + self.is_example_project = False def get_project_description(self, spec_writer): print(json.dumps({ @@ -40,7 +41,7 @@ class ProductOwner(Agent): # PROJECT DESCRIPTION self.project.current_step = PROJECT_DESCRIPTION_STEP - is_example_project = False + self.is_example_project = False if 'app_type' not in self.project.args: self.project.args['app_type'] = ask_for_app_type() @@ -58,7 +59,7 @@ class ProductOwner(Agent): print(f"Hold your horses cowboy! Please, give project NAME with max {MAX_PROJECT_NAME_LENGTH} characters.") if project_name.lower() == 'start an example project': - is_example_project = True + self.is_example_project = True project_name = 'Example Project' self.project.args['name'] = clean_filename(project_name) @@ -67,7 +68,7 @@ class ProductOwner(Agent): self.project.set_root_path(setup_workspace(self.project.args)) - if is_example_project: + if self.is_example_project: print(EXAMPLE_PROJECT_DESCRIPTION) self.project.main_prompt = EXAMPLE_PROJECT_DESCRIPTION else: diff --git a/pilot/helpers/agents/TechLead.py b/pilot/helpers/agents/TechLead.py index 2d1bb415b3..ed758339bc 100644 --- a/pilot/helpers/agents/TechLead.py +++ b/pilot/helpers/agents/TechLead.py @@ -7,6 +7,7 @@ from utils.utils import should_execute_step, generate_app_data from database.database import save_progress, get_progress_steps, save_feature, get_features_by_app_id from logger.logger import logger from const.function_calls import DEVELOPMENT_PLAN +from const.common import EXAMPLE_PROJECT_PLAN from templates import apply_project_template from utils.exit import trace_code_event @@ -36,19 +37,22 @@ class TechLead(Agent): print(color_green_bold("Starting to create the action plan for development...\n"), category='agent:tech-lead') logger.info("Starting to create the action plan for development...") - llm_response = self.convo_development_plan.send_message('development/plan.prompt', - { - "name": self.project.args['name'], - "app_type": self.project.args['app_type'], - "app_summary": self.project.project_description, - "user_stories": self.project.user_stories, - "user_tasks": self.project.user_tasks, - "architecture": self.project.architecture, - "technologies": self.project.system_dependencies + self.project.package_dependencies, - "existing_summary": existing_summary, - "files": self.project.get_all_coded_files(), - "task_type": 'app', - }, DEVELOPMENT_PLAN) + if self.project.project_manager.is_example_project: + llm_response = {"plan": EXAMPLE_PROJECT_PLAN} + else: + llm_response = self.convo_development_plan.send_message('development/plan.prompt', + { + "name": self.project.args['name'], + "app_type": self.project.args['app_type'], + "app_summary": self.project.project_description, + "user_stories": self.project.user_stories, + "user_tasks": self.project.user_tasks, + "architecture": self.project.architecture, + "technologies": self.project.system_dependencies + self.project.package_dependencies, + "existing_summary": existing_summary, + "files": self.project.get_all_coded_files(), + "task_type": 'app', + }, DEVELOPMENT_PLAN) self.project.development_plan = llm_response['plan'] logger.info('Plan for development is created.')