Skip to content

Commit ad968a0

Browse files
Merge pull request aden-hive#1458 from TimothyZhang7/release/v_0_3_0
DX Improvements: Linting, Formatting & Pre-Commit Hooks
2 parents 9c28284 + 5d79a70 commit ad968a0

75 files changed

Lines changed: 1021 additions & 564 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write|NotebookEdit",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "ruff check --fix \"$CLAUDE_FILE_PATH\" 2>/dev/null; ruff format \"$CLAUDE_FILE_PATH\" 2>/dev/null; true"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
}

.cursorrules

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This project uses ruff for Python linting and formatting.
2+
3+
Rules:
4+
- Line length: 100 characters
5+
- Python target: 3.11+
6+
- Use double quotes for strings
7+
- Sort imports with isort (ruff I rules): stdlib, third-party, first-party (framework), local
8+
- Combine as-imports
9+
- Use type hints on all function signatures
10+
- Use `from __future__ import annotations` for modern type syntax
11+
- Raise exceptions with `from` in except blocks (B904)
12+
- No unused imports (F401), no unused variables (F841)
13+
- Prefer list/dict/set comprehensions over map/filter (C4)
14+
15+
Run `make lint` to auto-fix, `make check` to verify without modifying files.
16+
Run `make format` to apply ruff formatting.
17+
18+
The ruff config lives in core/pyproject.toml under [tool.ruff].

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ indent_size = 2
1111
insert_final_newline = true
1212
trim_trailing_whitespace = true
1313

14+
[*.py]
15+
indent_size = 4
16+
1417
[*.md]
1518
trim_trailing_whitespace = false
1619

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ jobs:
2929
pip install -e .
3030
pip install -r requirements-dev.txt
3131
32-
- name: Run ruff
32+
- name: Ruff lint
3333
run: |
34-
cd core
35-
ruff check .
34+
cd core && ruff check .
35+
cd tools && ruff check .
36+
37+
- name: Ruff format
38+
run: |
39+
cd core && ruff format --check .
40+
cd tools && ruff format --check .
3641
3742
test:
3843
name: Test Python Framework

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.8.6
4+
hooks:
5+
- id: ruff
6+
name: ruff lint (core)
7+
args: [--fix]
8+
files: ^core/
9+
- id: ruff
10+
name: ruff lint (tools)
11+
args: [--fix]
12+
files: ^tools/
13+
- id: ruff-format
14+
name: ruff format (core)
15+
files: ^core/
16+
- id: ruff-format
17+
name: ruff format (tools)
18+
files: ^tools/

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"charliermarsh.ruff",
4+
"editorconfig.editorconfig",
5+
"ms-python.python"
6+
]
7+
}

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.PHONY: lint format check test install-hooks help
2+
3+
help: ## Show this help
4+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
5+
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
6+
7+
lint: ## Run ruff linter (with auto-fix)
8+
cd core && ruff check --fix .
9+
cd tools && ruff check --fix .
10+
11+
format: ## Run ruff formatter
12+
cd core && ruff format .
13+
cd tools && ruff format .
14+
15+
check: ## Run all checks without modifying files (CI-safe)
16+
cd core && ruff check .
17+
cd tools && ruff check .
18+
cd core && ruff format --check .
19+
cd tools && ruff format --check .
20+
21+
test: ## Run all tests
22+
cd core && python -m pytest tests/ -v
23+
24+
install-hooks: ## Install pre-commit hooks
25+
pip install pre-commit
26+
pre-commit install

core/examples/manual_agent.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ def greet(name: str) -> str:
2424
"""Generate a simple greeting."""
2525
return f"Hello, {name}!"
2626

27+
2728
def uppercase(greeting: str) -> str:
2829
"""Convert text to uppercase."""
2930
return greeting.upper()
3031

32+
3133
async def main():
3234
print("🚀 Setting up Manual Agent...")
3335

@@ -42,9 +44,9 @@ async def main():
4244
"id": "greeting_generated",
4345
"description": "Greeting produced",
4446
"metric": "custom",
45-
"target": "any"
47+
"target": "any",
4648
}
47-
]
49+
],
4850
)
4951

5052
# 3. Define Nodes
@@ -56,7 +58,7 @@ async def main():
5658
node_type="function",
5759
function="greet", # Matches the registered function name
5860
input_keys=["name"],
59-
output_keys=["greeting"]
61+
output_keys=["greeting"],
6062
)
6163

6264
node2 = NodeSpec(
@@ -66,7 +68,7 @@ async def main():
6668
node_type="function",
6769
function="uppercase",
6870
input_keys=["greeting"],
69-
output_keys=["final_greeting"]
71+
output_keys=["final_greeting"],
7072
)
7173

7274
# 4. Define Edges
@@ -75,7 +77,7 @@ async def main():
7577
id="greet-to-upper",
7678
source="greeter",
7779
target="uppercaser",
78-
condition=EdgeCondition.ON_SUCCESS
80+
condition=EdgeCondition.ON_SUCCESS,
7981
)
8082

8183
# 5. Create Graph
@@ -92,6 +94,7 @@ async def main():
9294
# 6. Initialize Runtime & Executor
9395
# Runtime handles state/memory; Executor runs the graph
9496
from pathlib import Path
97+
9598
runtime = Runtime(storage_path=Path("./agent_logs"))
9699
executor = GraphExecutor(runtime=runtime)
97100

@@ -103,11 +106,7 @@ async def main():
103106
# 8. Execute Agent
104107
print("▶ Executing agent with input: name='Alice'...")
105108

106-
result = await executor.execute(
107-
graph=graph,
108-
goal=goal,
109-
input_data={"name": "Alice"}
110-
)
109+
result = await executor.execute(graph=graph, goal=goal, input_data={"name": "Alice"})
111110

112111
# 9. Verify Results
113112
if result.success:
@@ -117,6 +116,7 @@ async def main():
117116
else:
118117
print(f"\n❌ Failed: {result.error}")
119118

119+
120120
if __name__ == "__main__":
121121
# Optional: Enable logging to see internal decision flow
122122
# logging.basicConfig(level=logging.INFO)

core/framework/builder/query.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ def suggest_improvements(self, goal_id: str) -> list[dict[str, Any]]:
355355
"target": goal_id,
356356
"reason": f"Goal success rate is only {patterns.success_rate:.1%}",
357357
"recommendation": (
358-
"Consider restructuring the agent graph "
359-
"or improving goal definition"
358+
"Consider restructuring the agent graph or improving goal definition"
360359
),
361360
"priority": "high",
362361
}
@@ -428,9 +427,7 @@ def _generate_suggestions(
428427
# Check for constraint issues
429428
if decision.active_constraints:
430429
constraints = ", ".join(decision.active_constraints)
431-
suggestions.append(
432-
f"Review constraints: {constraints} - may be too restrictive"
433-
)
430+
suggestions.append(f"Review constraints: {constraints} - may be too restrictive")
434431

435432
# Check for reported problems with suggestions
436433
for problem in run.problems:

core/framework/graph/code_sandbox.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ def validate(self, code: str) -> list[str]:
165165
# Check for blocked node types
166166
if type(node) in self.blocked_nodes:
167167
lineno = getattr(node, "lineno", "?")
168-
issues.append(
169-
f"Blocked operation: {type(node).__name__} at line {lineno}"
170-
)
168+
issues.append(f"Blocked operation: {type(node).__name__} at line {lineno}")
171169

172170
# Check for dangerous attribute access
173171
if isinstance(node, ast.Attribute):

0 commit comments

Comments
 (0)