Skip to content

Commit f12991f

Browse files
committed
tst
1 parent 4dfcb9e commit f12991f

File tree

6 files changed

+267
-2
lines changed

6 files changed

+267
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
mydatabase/
33
temp/
44
.DS_Store
5+
.aider*

aider-genius/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,46 @@ This project maintains the same license as the original Aider project. See the [
248248
---
249249

250250
*Revolutionizing AI pair programming with intelligent agentic workflows for the future of software development.*
251+
# Calculator CLI
252+
253+
This project provides a simple command-line interface (CLI) calculator that performs basic arithmetic operations.
254+
255+
## Features
256+
257+
- Addition
258+
- Subtraction
259+
- Multiplication
260+
- Division (with error handling for division by zero)
261+
262+
## Usage
263+
264+
To use the calculator, run the `cli_calculator.py` script with the desired operation and operands. For example:
265+
266+
```bash
267+
python aider-genius/cli_calculator.py add 5 3
268+
```
269+
270+
This will output:
271+
272+
```
273+
The result of adding 5.0 and 3.0 is: 8.0
274+
```
275+
276+
### Available Operations
277+
278+
- `add`: Add two numbers.
279+
- `subtract`: Subtract the second number from the first.
280+
- `multiply`: Multiply two numbers.
281+
- `divide`: Divide the first number by the second (raises an error if the second number is zero).
282+
283+
### Example Commands
284+
285+
```bash
286+
python aider-genius/cli_calculator.py subtract 10 4
287+
python aider-genius/cli_calculator.py multiply 6 7
288+
python aider-genius/cli_calculator.py divide 8 2
289+
```
290+
291+
## Error Handling
292+
293+
The calculator handles division by zero by raising a `ValueError` with a clear error message.

aider-genius/aider/genius.jac

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,76 @@ node ValidatorNode {
900900
# }
901901
}
902902

903+
# User input node for task continuation
904+
node UserInputNode {
905+
has status: str = "waiting";
906+
has user_input: str = "";
907+
has should_continue: bool = True;
908+
909+
"""Wait for user input and determine next action"""
910+
def get_user_input(coder: Any) -> Tuple[str, bool] {
911+
try {
912+
coder.io.tool_output("\n" + "="*50);
913+
coder.io.tool_output("Genius Agent - Task Completed!");
914+
coder.io.tool_output("What would you like me to do next?");
915+
coder.io.tool_output("Options:");
916+
coder.io.tool_output(" - Describe a new task");
917+
coder.io.tool_output(" - Type 'exit' or 'quit' to stop");
918+
coder.io.tool_output(" - Type 'status' to see current repository state");
919+
coder.io.tool_output("="*50);
920+
921+
user_input = input("\nNext task > ").strip();
922+
923+
if user_input.lower() in ['exit', 'quit', 'stop'] {
924+
return ("", False);
925+
} elif user_input.lower() == 'status' {
926+
return ("status", True);
927+
} elif user_input == '' {
928+
return ("empty", True); # Handle empty input separately
929+
} else {
930+
return (user_input, True);
931+
}
932+
} except (KeyboardInterrupt, EOFError) {
933+
coder.io.tool_output("\nExiting Genius Agent...");
934+
return ("", False);
935+
} except Exception as e {
936+
coder.io.tool_output(f"Error getting user input: {str(e)}");
937+
return ("", False);
938+
}
939+
}
940+
941+
"""Show current repository status"""
942+
def show_status(coder: Any) {
943+
coder.io.tool_output("\nCurrent Repository Status:");
944+
coder.io.tool_output("-" * 30);
945+
946+
if coder.abs_fnames {
947+
coder.io.tool_output("Files in current session:");
948+
for fname in coder.abs_fnames {
949+
coder.io.tool_output(f" - {fname}");
950+
}
951+
} else {
952+
coder.io.tool_output("No files in current session");
953+
}
954+
955+
if coder.repo {
956+
try {
957+
dirty_files = coder.repo.get_dirty_files();
958+
if dirty_files {
959+
coder.io.tool_output("\nModified files:");
960+
for file in dirty_files {
961+
coder.io.tool_output(f" - {file}");
962+
}
963+
} else {
964+
coder.io.tool_output("\nNo uncommitted changes");
965+
}
966+
} except Exception as e {
967+
coder.io.tool_output(f"Could not get git status: {e}");
968+
}
969+
}
970+
}
971+
}
972+
903973
# Terminal node for end of graph traversal
904974
node EndNode {}
905975
glob END = EndNode();
@@ -941,12 +1011,14 @@ walker GeniusAgent {
9411011
planning_node = PlanningNode(task=self.task, status="pending", planning_model=self.planning_model);
9421012
editor_node = EditorNode(file_path="", content="", changes=[], status="pending", editor_model=self.editor_model);
9431013
validator_node = ValidatorNode(file_path="", issues=[], status="pending", validation_model=self.editor_model);
1014+
user_input_node = UserInputNode(status="waiting");
9441015

945-
# Connect the workflow
1016+
# Connect the workflow with user input loop
9461017
root ++> planning_node;
9471018
planning_node ++> editor_node;
9481019
editor_node ++> validator_node;
949-
validator_node ++> END;
1020+
validator_node ++> user_input_node; # Go to user input instead of END
1021+
# Note: UserInputNode will handle navigation based on user choice
9501022

9511023
self.coder.io.tool_output(f"Genius Agent - Phase: Initialization | Action: Starting Genius Agent | Reasoning: Beginning autonomous development cycle for: {self.task}");
9521024

@@ -1196,9 +1268,67 @@ walker GeniusAgent {
11961268
}
11971269
}
11981270

1271+
# Generate report before moving to user input
1272+
self.generate_comprehensive_report();
1273+
11991274
visit [-->];
12001275
}
12011276

1277+
# Handle user input and decide next action
1278+
can handle_user_input with UserInputNode entry {
1279+
here.status = "waiting";
1280+
1281+
while True {
1282+
(user_input, should_continue) = here.get_user_input(self.coder);
1283+
1284+
if not should_continue {
1285+
self.coder.io.tool_output("Genius Agent - Phase: Shutdown | Action: User requested exit | Reasoning: Gracefully shutting down");
1286+
# End the walker execution
1287+
return;
1288+
}
1289+
1290+
if user_input == "status" {
1291+
here.show_status(self.coder);
1292+
continue;
1293+
}
1294+
1295+
if user_input == "empty" {
1296+
self.coder.io.tool_output("Please provide a task description or type 'exit' to quit.");
1297+
continue;
1298+
}
1299+
1300+
if user_input {
1301+
# Reset for new task
1302+
self.task = user_input;
1303+
self.task_explicitly_provided = True;
1304+
self.planning_complete = False;
1305+
self.last_error_context = None;
1306+
self.current_iteration = 0;
1307+
1308+
self.coder.io.tool_output(f"Genius Agent - Phase: New Task | Action: Starting new task | Reasoning: User provided new task: {user_input}");
1309+
1310+
# Create new nodes for the next cycle
1311+
planning_node = PlanningNode(task=self.task, status="pending", planning_model=self.planning_model);
1312+
editor_node = EditorNode(file_path="", content="", changes=[], status="pending", editor_model=self.editor_model);
1313+
validator_node = ValidatorNode(file_path="", issues=[], status="pending", validation_model=self.editor_model);
1314+
new_user_input_node = UserInputNode(status="waiting");
1315+
1316+
# Connect the new workflow
1317+
here ++> planning_node;
1318+
planning_node ++> editor_node;
1319+
editor_node ++> validator_node;
1320+
validator_node ++> new_user_input_node;
1321+
1322+
# Start the new cycle
1323+
visit [-->];
1324+
return;
1325+
} else {
1326+
here.show_status(self.coder);
1327+
self.coder.io.tool_output("Please provide a valid task or type 'exit' to quit.");
1328+
}
1329+
}
1330+
}
1331+
12021332
# Handle reaching the end
12031333
can finish with EndNode entry {
12041334
success = len(self.completed_tasks) > 0;

aider-genius/calculator.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,31 @@ def divide(self, a, b):
8989
if b == 0:
9090
raise ZeroDivisionError("Cannot divide by zero.")
9191
return a / b
92+
class Calculator:
93+
"""
94+
A simple calculator class to perform basic arithmetic operations.
95+
96+
Methods:
97+
add(a, b): Returns the sum of a and b.
98+
subtract(a, b): Returns the difference of a and b.
99+
multiply(a, b): Returns the product of a and b.
100+
divide(a, b): Returns the division of a by b, raises an error if b is zero.
101+
"""
102+
103+
def add(self, a, b):
104+
"""Return the sum of a and b."""
105+
return a + b
106+
107+
def subtract(self, a, b):
108+
"""Return the difference of a and b."""
109+
return a - b
110+
111+
def multiply(self, a, b):
112+
"""Return the product of a and b."""
113+
return a * b
114+
115+
def divide(self, a, b):
116+
"""Return the division of a by b. Raise ValueError if b is zero."""
117+
if b == 0:
118+
raise ValueError("Cannot divide by zero.")
119+
return a / b

aider-genius/cli_calculator.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,34 @@ def main():
2828

2929
if __name__ == "__main__":
3030
main()
31+
import argparse
32+
from calculator import Calculator
33+
34+
def main():
35+
parser = argparse.ArgumentParser(description="Simple CLI Calculator")
36+
parser.add_argument("operation", choices=["add", "subtract", "multiply", "divide"],
37+
help="The operation to perform: add, subtract, multiply, or divide")
38+
parser.add_argument("a", type=float, help="The first operand")
39+
parser.add_argument("b", type=float, help="The second operand")
40+
41+
args = parser.parse_args()
42+
43+
calculator = Calculator()
44+
45+
try:
46+
if args.operation == "add":
47+
result = calculator.add(args.a, args.b)
48+
elif args.operation == "subtract":
49+
result = calculator.subtract(args.a, args.b)
50+
elif args.operation == "multiply":
51+
result = calculator.multiply(args.a, args.b)
52+
elif args.operation == "divide":
53+
result = calculator.divide(args.a, args.b)
54+
55+
print(f"The result of {args.operation}ing {args.a} and {args.b} is: {result}")
56+
57+
except ValueError as e:
58+
print(f"Error: {e}")
59+
60+
if __name__ == "__main__":
61+
main()

aider-genius/test_calculator.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
import unittest
22
from calculator import Calculator
33

4+
class TestCalculator(unittest.TestCase):
5+
6+
def setUp(self):
7+
self.calculator = Calculator()
8+
9+
def test_add(self):
10+
self.assertEqual(self.calculator.add(1, 2), 3)
11+
self.assertEqual(self.calculator.add(-1, 1), 0)
12+
self.assertEqual(self.calculator.add(-1, -1), -2)
13+
14+
def test_subtract(self):
15+
self.assertEqual(self.calculator.subtract(10, 5), 5)
16+
self.assertEqual(self.calculator.subtract(-1, 1), -2)
17+
self.assertEqual(self.calculator.subtract(-1, -1), 0)
18+
19+
def test_multiply(self):
20+
self.assertEqual(self.calculator.multiply(3, 7), 21)
21+
self.assertEqual(self.calculator.multiply(-1, 1), -1)
22+
self.assertEqual(self.calculator.multiply(-1, -1), 1)
23+
24+
def test_divide(self):
25+
self.assertEqual(self.calculator.divide(10, 2), 5)
26+
self.assertEqual(self.calculator.divide(-1, 1), -1)
27+
self.assertEqual(self.calculator.divide(-1, -1), 1)
28+
with self.assertRaises(ValueError):
29+
self.calculator.divide(10, 0)
30+
31+
if __name__ == '__main__':
32+
unittest.main()
33+
import unittest
34+
from calculator import Calculator
35+
436
class TestCalculator(unittest.TestCase):
537

638
def setUp(self):

0 commit comments

Comments
 (0)