evoloop-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evoloop_cli/__init__.py +3 -0
- evoloop_cli/__main__.py +10 -0
- evoloop_cli/_skills/evoloop-constitution/SKILL.md +59 -0
- evoloop_cli/_skills/evoloop-constitution/references/writing-guide.md +89 -0
- evoloop_cli/_skills/evoloop-constitution/templates/config.yaml +52 -0
- evoloop_cli/_skills/evoloop-constitution/templates/constitution.md +39 -0
- evoloop_cli/_skills/evoloop-evaluate/SKILL.md +85 -0
- evoloop_cli/_skills/evoloop-evaluate/schemas/parsed_report.schema.json +170 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/parse_junit_report.py +311 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/parse_pytest_report.py +276 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/parse_report.py +101 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/update_eval_index.py +111 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/validate_parsed_report.py +178 -0
- evoloop_cli/_skills/evoloop-evaluate/templates/analysis.md +51 -0
- evoloop_cli/_skills/evoloop-evaluate/templates/progress.md +42 -0
- evoloop_cli/_skills/evoloop-evaluate/templates/tasks.md +34 -0
- evoloop_cli/_skills/evoloop-evolve/SKILL.md +76 -0
- evoloop_cli/_skills/evoloop-evolve/scripts/evolve_state.py +333 -0
- evoloop_cli/_skills/evoloop-implement/SKILL.md +57 -0
- evoloop_cli/_skills/evoloop-implement/scripts/check_scope.py +154 -0
- evoloop_cli/_skills/evoloop-implement/scripts/commit_section.py +78 -0
- evoloop_cli/_skills/evoloop-init/SKILL.md +95 -0
- evoloop_cli/_skills/evoloop-init/scripts/scaffold_evals.py +546 -0
- evoloop_cli/_skills/evoloop-init/templates/common/evals/datasets/domain_flows.yaml +33 -0
- evoloop_cli/_skills/evoloop-init/templates/common/evaluations/README.md +9 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/AgentAdapter.java +13 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/AgenticFlowEvalTest.java +71 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/DeterministicEvaluators.java +174 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/EvalFrameworkTest.java +45 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/FlowRunResult.java +25 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/__init__.py +1 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/adapter.py +63 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/deepagents_adapter.py +223 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/__init__.py +1 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/deterministic.py +234 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/llm_judge.py +189 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/fakes.py +26 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/harness.py +100 -0
- evoloop_cli/_skills/evoloop-init/templates/python/tests/conftest.py +38 -0
- evoloop_cli/_skills/evoloop-init/templates/python/tests/test_agentic_flows.py +36 -0
- evoloop_cli/_skills/evoloop-init/templates/python/tests/test_eval_framework.py +175 -0
- evoloop_cli/_skills/evoloop-new/SKILL.md +125 -0
- evoloop_cli/_skills/evoloop-new/scripts/scaffold_agent.py +911 -0
- evoloop_cli/_skills/evoloop-new/templates/common/.evoloop/constitution.md +34 -0
- evoloop_cli/_skills/evoloop-new/templates/common/.gitignore +22 -0
- evoloop_cli/_skills/evoloop-new/templates/common/AGENTS.md +17 -0
- evoloop_cli/_skills/evoloop-new/templates/common/README.md +83 -0
- evoloop_cli/_skills/evoloop-new/templates/common/skills/__DOMAIN__/SKILL.md +21 -0
- evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/AgenticFlowEvalTest.java +113 -0
- evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/EvalFrameworkTest.java +85 -0
- evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/Fake__DOMAIN_PASCAL__Client.java +37 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/Application.java +46 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/OpenAiCompatibleRunner.java +433 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +125 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/Application.java +46 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +163 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +18 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/Application.java +15 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +167 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Controller.java +41 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Factory.java +32 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +20 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/resources/application.yml +17 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/Application.java +17 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +159 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Config.java +32 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Controller.java +40 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +25 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/resources/application.yml +19 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_custom.gradle +33 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_langchain4j.gradle +40 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_micronaut.gradle +52 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_spring-ai.gradle +45 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/settings.gradle +1 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_custom.xml +57 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_langchain4j.xml +87 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_micronaut.xml +101 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_spring-ai.xml +61 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/ConversationMemory.java +36 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/Default__DOMAIN_PASCAL__Client.java +9 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/DomainRecord.java +10 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/TurnOutcome.java +15 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Client.java +8 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/fakes.py +22 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/harness_custom.py +186 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/harness_deepagents.py +100 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/tests/test_eval_framework.py +196 -0
- evoloop_cli/_skills/evoloop-new/templates/python/pyproject.toml +18 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/__init__.py +13 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/__main__.py +6 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/agent_custom.py +209 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/agent_deepagents.py +61 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/cli.py +71 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/client.py +31 -0
- evoloop_cli/_skills/evoloop-scenarios/SKILL.md +49 -0
- evoloop_cli/_skills/evoloop-scenarios/scripts/validate_scenarios.py +261 -0
- evoloop_cli/_skills/evoloop-scenarios/templates/scenario_schema.md +49 -0
- evoloop_cli/cli.py +331 -0
- evoloop_cli-0.1.0.dist-info/METADATA +214 -0
- evoloop_cli-0.1.0.dist-info/RECORD +103 -0
- evoloop_cli-0.1.0.dist-info/WHEEL +4 -0
- evoloop_cli-0.1.0.dist-info/entry_points.txt +2 -0
- evoloop_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,911 @@
|
|
|
1
|
+
#!/usr/bin/env -S uv run --script
|
|
2
|
+
# /// script
|
|
3
|
+
# requires-python = ">=3.11"
|
|
4
|
+
# dependencies = ["pyyaml>=6.0"]
|
|
5
|
+
# ///
|
|
6
|
+
"""Greenfield scaffolder: create a minimal runnable, evaluation-ready agent application from scratch."""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import importlib.util
|
|
12
|
+
import re
|
|
13
|
+
import shlex
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import yaml
|
|
20
|
+
|
|
21
|
+
TEMPLATES_DIR = Path(__file__).resolve().parent.parent / "templates"
|
|
22
|
+
INIT_SCRIPT_PATH = (
|
|
23
|
+
Path(__file__).resolve().parents[2] / "evoloop-init" / "scripts" / "scaffold_evals.py"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
IGNORED_EMPTY_DIR_ENTRIES = frozenset({".git", ".agents", ".DS_Store"})
|
|
27
|
+
IGNORED_TEMPLATE_SUFFIXES = frozenset({".iml", ".pyc"})
|
|
28
|
+
IGNORED_TEMPLATE_NAMES = frozenset({".DS_Store"})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _is_ignored_template(path: Path) -> bool:
|
|
32
|
+
return (
|
|
33
|
+
path.is_dir()
|
|
34
|
+
or path.name in IGNORED_TEMPLATE_NAMES
|
|
35
|
+
or path.suffix in IGNORED_TEMPLATE_SUFFIXES
|
|
36
|
+
or "__pycache__" in path.parts
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
AGENT_STACK_DEFAULTS: dict[str, dict[str, Any]] = {
|
|
40
|
+
"python": {
|
|
41
|
+
"build_tool": "uv",
|
|
42
|
+
"build_tools": ("uv",),
|
|
43
|
+
"framework": "deepagents",
|
|
44
|
+
"frameworks": ("deepagents", "custom"),
|
|
45
|
+
"offline_test_cmd": {"uv": "uv run pytest"},
|
|
46
|
+
"live_eval_cmd": {"uv": "uv run pytest tests/test_agentic_flows.py --run-live-agent"},
|
|
47
|
+
"live_eval_judge_cmd": {
|
|
48
|
+
"uv": "uv run pytest tests/test_agentic_flows.py --run-live-agent --run-judge"
|
|
49
|
+
},
|
|
50
|
+
"setup_cmd": {"uv": "uv sync --group eval"},
|
|
51
|
+
},
|
|
52
|
+
"java": {
|
|
53
|
+
"build_tool": "maven",
|
|
54
|
+
"build_tools": ("maven", "gradle"),
|
|
55
|
+
"framework": "custom",
|
|
56
|
+
"frameworks": ("custom", "spring-ai", "langchain4j", "micronaut"),
|
|
57
|
+
"offline_test_cmd": {"maven": "mvn test", "gradle": "./gradlew test"},
|
|
58
|
+
"live_eval_cmd": {
|
|
59
|
+
"maven": "mvn test -Dtest=AgenticFlowEvalTest -DrunLiveAgent=true",
|
|
60
|
+
"gradle": "./gradlew test --tests '*AgenticFlowEvalTest' -DrunLiveAgent=true",
|
|
61
|
+
},
|
|
62
|
+
"live_eval_judge_cmd": {
|
|
63
|
+
"maven": "mvn test -Dtest=AgenticFlowEvalTest -DrunLiveAgent=true -DrunJudge=true",
|
|
64
|
+
"gradle": "./gradlew test --tests '*AgenticFlowEvalTest' -DrunLiveAgent=true -DrunJudge=true",
|
|
65
|
+
},
|
|
66
|
+
"setup_cmd": {"maven": "mvn test-compile", "gradle": "./gradlew testClasses"},
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
DEFAULT_INVARIANTS = [
|
|
71
|
+
"**Tool-Grounded Facts Only:** Never invent, guess, or recall data that must come from a domain tool. If the agent did not call a tool for a value, do not state that value.",
|
|
72
|
+
"**Input Validation Before Tool Calls:** Do not call domain tools on missing, vague, or ambiguous inputs. Ask one clear clarifying question instead.",
|
|
73
|
+
"**Explicit Error Recovery:** If a tool returns an error or times out, reply with a brief, honest explanation. Never return an empty reply or retry in a loop.",
|
|
74
|
+
"**Scope Adherence:** Stay strictly within the documented capabilities of the agent. Decline out-of-scope requests politely without invented results or unsupported follow-ups.",
|
|
75
|
+
"**Deterministic Edge-Case Actions:** Define **one concrete behavior** for every edge case. Never write open-ended instructions that ask the model to choose between two actions.",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _load_scaffold_evals_module():
|
|
80
|
+
if not INIT_SCRIPT_PATH.is_file():
|
|
81
|
+
raise FileNotFoundError(
|
|
82
|
+
f"Sibling evoloop-init script not found at {INIT_SCRIPT_PATH}. "
|
|
83
|
+
"Ensure all evoloop-* skills are installed side-by-side under .agents/skills/."
|
|
84
|
+
)
|
|
85
|
+
spec = importlib.util.spec_from_file_location("evoloop_scaffold_evals", INIT_SCRIPT_PATH)
|
|
86
|
+
if spec is None or spec.loader is None:
|
|
87
|
+
raise RuntimeError(f"Unable to load {INIT_SCRIPT_PATH}")
|
|
88
|
+
mod = importlib.util.module_from_spec(spec)
|
|
89
|
+
spec.loader.exec_module(mod)
|
|
90
|
+
return mod
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _slug_snake(value: str, fallback: str) -> str:
|
|
94
|
+
cleaned = re.sub(r"[^a-zA-Z0-9]+", "_", value.strip()).strip("_").lower()
|
|
95
|
+
if not cleaned:
|
|
96
|
+
return fallback
|
|
97
|
+
if cleaned[0].isdigit():
|
|
98
|
+
cleaned = f"a_{cleaned}"
|
|
99
|
+
return cleaned
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _to_pascal(snake: str) -> str:
|
|
103
|
+
parts = [p for p in snake.split("_") if p]
|
|
104
|
+
return "".join(p[:1].upper() + p[1:] for p in parts) or "Domain"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _to_camel(snake: str) -> str:
|
|
108
|
+
pascal = _to_pascal(snake)
|
|
109
|
+
return pascal[:1].lower() + pascal[1:]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _parse_tools(raw_tools: str | list[str] | None) -> list[str]:
|
|
113
|
+
if raw_tools is None:
|
|
114
|
+
return ["lookup_record"]
|
|
115
|
+
items = raw_tools.split(",") if isinstance(raw_tools, str) else list(raw_tools)
|
|
116
|
+
seen: list[str] = []
|
|
117
|
+
for item in items:
|
|
118
|
+
name = _slug_snake(item, "")
|
|
119
|
+
if name and name not in seen:
|
|
120
|
+
seen.append(name)
|
|
121
|
+
return seen or ["lookup_record"]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _format_tools_md(tools: list[str]) -> str:
|
|
125
|
+
return "\n".join(f"- `{tool}` — Retrieve grounded `{tool.replace('_', ' ')}` information." for tool in tools)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _format_invariants_md(invariants: list[str] | None) -> str:
|
|
129
|
+
items = [i.strip() for i in (invariants or []) if i.strip()] or DEFAULT_INVARIANTS
|
|
130
|
+
return "\n".join(f"{idx}. {text}" for idx, text in enumerate(items, start=1))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _render_python_snippets(tools: list[str], framework: str) -> dict[str, str]:
|
|
134
|
+
deps = (
|
|
135
|
+
' "deepagents>=0.1.0",\n "langchain-openai>=0.3.0",'
|
|
136
|
+
if framework == "deepagents"
|
|
137
|
+
else ' # Pure Python stdlib OpenAI-compatible runtime (add your preferred SDK if desired)'
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
proto_lines = [f" def {t}(self, query: str) -> DomainRecord: ..." for t in tools]
|
|
141
|
+
stub_lines = [
|
|
142
|
+
f" def {t}(self, query: str) -> DomainRecord:\n"
|
|
143
|
+
f" cleaned = query.strip()\n"
|
|
144
|
+
f" if not cleaned:\n"
|
|
145
|
+
f' raise ValueError("Query cannot be empty.")\n'
|
|
146
|
+
f" # TODO(domain): Replace with your production backend call.\n"
|
|
147
|
+
f' return DomainRecord(query=cleaned, status="ok", detail="stub {t} result for " + cleaned)\n'
|
|
148
|
+
for t in tools
|
|
149
|
+
]
|
|
150
|
+
fake_lines = [
|
|
151
|
+
f" def {t}(self, query: str) -> DomainRecord:\n"
|
|
152
|
+
f' self.call_log.append({{"method": "{t}", "query": query}})\n'
|
|
153
|
+
f" self._check_faults()\n"
|
|
154
|
+
f" cleaned = query.strip()\n"
|
|
155
|
+
f" if not cleaned:\n"
|
|
156
|
+
f' raise ValueError("Query cannot be empty.")\n'
|
|
157
|
+
f' return DomainRecord(query=cleaned, status="ok", detail="{t} fixture for " + cleaned)\n'
|
|
158
|
+
for t in tools
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
deepagents_tool_blocks = []
|
|
162
|
+
for t in tools:
|
|
163
|
+
desc = t.replace("_", " ")
|
|
164
|
+
deepagents_tool_blocks.append(
|
|
165
|
+
f" @tool\n"
|
|
166
|
+
f" def {t}(query: str) -> str:\n"
|
|
167
|
+
f' """Run {desc} for a concrete identifier."""\n'
|
|
168
|
+
f" try:\n"
|
|
169
|
+
f" record = client.{t}(query)\n"
|
|
170
|
+
f" except (ValueError, RuntimeError) as exc:\n"
|
|
171
|
+
f' return f"Error: {{exc}}"\n'
|
|
172
|
+
f' return f"{{record.query}}: status={{record.status}} ({{record.detail}})"\n'
|
|
173
|
+
)
|
|
174
|
+
deepagents_tool_blocks.append(f" return [{', '.join(tools)}]")
|
|
175
|
+
|
|
176
|
+
custom_tool_blocks = []
|
|
177
|
+
for t in tools:
|
|
178
|
+
custom_tool_blocks.append(
|
|
179
|
+
f" def _{t}(query: str) -> str:\n"
|
|
180
|
+
f" try:\n"
|
|
181
|
+
f" record = client.{t}(query)\n"
|
|
182
|
+
f" except (ValueError, RuntimeError) as exc:\n"
|
|
183
|
+
f' return f"Error: {{exc}}"\n'
|
|
184
|
+
f' return f"{{record.query}}: status={{record.status}} ({{record.detail}})"\n'
|
|
185
|
+
)
|
|
186
|
+
mapping = ", ".join(f'"{t}": _{t}' for t in tools)
|
|
187
|
+
custom_tool_blocks.append(f" return {{{mapping}}}")
|
|
188
|
+
|
|
189
|
+
tools_literal = "frozenset({" + ", ".join(f'"{t}"' for t in tools) + "})"
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
"__PYTHON_DEPS__": deps,
|
|
193
|
+
"__PYTHON_PROTOCOL_METHODS__": "\n".join(proto_lines),
|
|
194
|
+
"__PYTHON_STUB_METHODS__": "\n".join(stub_lines).rstrip(),
|
|
195
|
+
"__PYTHON_FAKE_METHODS__": "\n".join(fake_lines).rstrip(),
|
|
196
|
+
"__PYTHON_DEEPAGENTS_TOOLS__": "\n".join(deepagents_tool_blocks),
|
|
197
|
+
"__PYTHON_CUSTOM_TOOLS__": "\n".join(custom_tool_blocks),
|
|
198
|
+
"__PYTHON_DOMAIN_TOOLS_SET__": tools_literal,
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _render_java_snippets(tools: list[str]) -> dict[str, str]:
|
|
203
|
+
iface_lines = [f" DomainRecord {_to_camel(t)}(String query);" for t in tools]
|
|
204
|
+
stub_lines = [
|
|
205
|
+
f" @Override\n"
|
|
206
|
+
f" public DomainRecord {_to_camel(t)}(String query) {{\n"
|
|
207
|
+
f" if (query == null || query.isBlank()) {{\n"
|
|
208
|
+
f' throw new IllegalArgumentException("Query cannot be empty.");\n'
|
|
209
|
+
f" }}\n"
|
|
210
|
+
f" String cleaned = query.trim();\n"
|
|
211
|
+
f" // TODO(domain): Replace with your production backend call.\n"
|
|
212
|
+
f' return new DomainRecord(cleaned, "ok", "stub {t} result for " + cleaned);\n'
|
|
213
|
+
f" }}\n"
|
|
214
|
+
for t in tools
|
|
215
|
+
]
|
|
216
|
+
fake_lines = [
|
|
217
|
+
f" @Override\n"
|
|
218
|
+
f" public DomainRecord {_to_camel(t)}(String query) {{\n"
|
|
219
|
+
f' callLog.add(Map.of("method", "{t}", "query", query == null ? "" : query));\n'
|
|
220
|
+
f" checkFaults();\n"
|
|
221
|
+
f" if (query == null || query.isBlank()) {{\n"
|
|
222
|
+
f' throw new IllegalArgumentException("Query cannot be empty.");\n'
|
|
223
|
+
f" }}\n"
|
|
224
|
+
f" String cleaned = query.trim();\n"
|
|
225
|
+
f' return new DomainRecord(cleaned, "ok", "{t} fixture for " + cleaned);\n'
|
|
226
|
+
f" }}\n"
|
|
227
|
+
for t in tools
|
|
228
|
+
]
|
|
229
|
+
dispatch_lines = [
|
|
230
|
+
f' case "{t}" -> {{\n'
|
|
231
|
+
f" DomainRecord r = client.{_to_camel(t)}(query);\n"
|
|
232
|
+
f' yield r.query() + ": status=" + r.status() + " (" + r.detail() + ")";\n'
|
|
233
|
+
f" }}"
|
|
234
|
+
for t in tools
|
|
235
|
+
]
|
|
236
|
+
lc4j_tool_lines = [
|
|
237
|
+
f' @Tool(name = "{t}", value = "Run {t.replace("_", " ")} for a concrete identifier.")\n'
|
|
238
|
+
f' public String {_to_camel(t)}(@P("Concrete identifier or query string.") String query) {{\n'
|
|
239
|
+
f" try {{\n"
|
|
240
|
+
f" DomainRecord r = client.{_to_camel(t)}(query);\n"
|
|
241
|
+
f' return r.query() + ": status=" + r.status() + " (" + r.detail() + ")";\n'
|
|
242
|
+
f" }} catch (RuntimeException exc) {{\n"
|
|
243
|
+
f' return "Error: " + exc.getMessage();\n'
|
|
244
|
+
f" }}\n"
|
|
245
|
+
f" }}\n"
|
|
246
|
+
for t in tools
|
|
247
|
+
]
|
|
248
|
+
micronaut_mcp_tool_lines = [
|
|
249
|
+
f' @io.micronaut.mcp.annotations.Tool(name = "{t}", description = "Run {t.replace("_", " ")} for a concrete identifier.")\n'
|
|
250
|
+
f' @dev.langchain4j.agent.tool.Tool(name = "{t}", value = "Run {t.replace("_", " ")} for a concrete identifier.")\n'
|
|
251
|
+
f' public String {_to_camel(t)}(@P("Concrete identifier or query string.") String query) {{\n'
|
|
252
|
+
f" try {{\n"
|
|
253
|
+
f" DomainRecord r = client.{_to_camel(t)}(query);\n"
|
|
254
|
+
f' return r.query() + ": status=" + r.status() + " (" + r.detail() + ")";\n'
|
|
255
|
+
f" }} catch (RuntimeException exc) {{\n"
|
|
256
|
+
f' return "Error: " + exc.getMessage();\n'
|
|
257
|
+
f" }}\n"
|
|
258
|
+
f" }}\n"
|
|
259
|
+
for t in tools
|
|
260
|
+
]
|
|
261
|
+
spring_ai_tool_lines = [
|
|
262
|
+
f' @Tool(name = "{t}", description = "Run {t.replace("_", " ")} for a concrete identifier.")\n'
|
|
263
|
+
f' public String {_to_camel(t)}(@ToolParam(description = "Concrete identifier or query string.") String query) {{\n'
|
|
264
|
+
f' recorder.add(new TurnOutcome.ToolInvocation("{t}", Map.of("query", query == null ? "" : query)));\n'
|
|
265
|
+
f" try {{\n"
|
|
266
|
+
f" DomainRecord r = client.{_to_camel(t)}(query);\n"
|
|
267
|
+
f' return r.query() + ": status=" + r.status() + " (" + r.detail() + ")";\n'
|
|
268
|
+
f" }} catch (RuntimeException exc) {{\n"
|
|
269
|
+
f' return "Error: " + exc.getMessage();\n'
|
|
270
|
+
f" }}\n"
|
|
271
|
+
f" }}\n"
|
|
272
|
+
for t in tools
|
|
273
|
+
]
|
|
274
|
+
java_tools_set = "Set.of(" + ", ".join(f'"{t}"' for t in tools) + ")"
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
"__JAVA_INTERFACE_METHODS__": "\n".join(iface_lines),
|
|
278
|
+
"__JAVA_STUB_METHODS__": "\n".join(stub_lines).rstrip(),
|
|
279
|
+
"__JAVA_FAKE_METHODS__": "\n".join(fake_lines).rstrip(),
|
|
280
|
+
"__JAVA_TOOL_DISPATCH__": "\n".join(dispatch_lines),
|
|
281
|
+
"__JAVA_LANGCHAIN4J_TOOLS__": "\n".join(lc4j_tool_lines).rstrip(),
|
|
282
|
+
"__JAVA_MICRONAUT_MCP_TOOLS__": "\n".join(micronaut_mcp_tool_lines).rstrip(),
|
|
283
|
+
"__JAVA_SPRING_AI_TOOLS__": "\n".join(spring_ai_tool_lines).rstrip(),
|
|
284
|
+
"__JAVA_DOMAIN_TOOLS_SET__": java_tools_set,
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _render_readme_snippets(
|
|
289
|
+
*,
|
|
290
|
+
stack: str,
|
|
291
|
+
build_tool: str,
|
|
292
|
+
framework: str,
|
|
293
|
+
project_name: str,
|
|
294
|
+
package_name: str,
|
|
295
|
+
domain: str,
|
|
296
|
+
domain_pascal: str,
|
|
297
|
+
pkg_path: str,
|
|
298
|
+
) -> dict[str, str]:
|
|
299
|
+
if stack == "python":
|
|
300
|
+
adapter_row = (
|
|
301
|
+
"| `evals/deepagents_adapter.py` | Built-in `DeepAgentsAdapter` for LangGraph and `deepagents` |\n"
|
|
302
|
+
if framework == "deepagents"
|
|
303
|
+
else ""
|
|
304
|
+
)
|
|
305
|
+
layout = (
|
|
306
|
+
"| Path | Purpose |\n"
|
|
307
|
+
"| :--- | :--- |\n"
|
|
308
|
+
"| `pyproject.toml` | `uv` manifest, Command-Line Interface (CLI) entrypoint, `[dependency-groups].eval`, and `pytest` config |\n"
|
|
309
|
+
f"| `src/{package_name}/client.py` | `@runtime_checkable` `{domain_pascal}Client` `Protocol` and runnable `Default{domain_pascal}Client` stub |\n"
|
|
310
|
+
f"| `src/{package_name}/agent.py` | Checkpointer-backed `{framework}` agent factory, tool bindings, and compact `SYSTEM_PROMPT` |\n"
|
|
311
|
+
f"| `src/{package_name}/cli.py` | Runnable CLI application (`--prompt` single-shot or interactive Read-Eval-Print Loop (REPL)) |\n"
|
|
312
|
+
f"| `AGENTS.md` and `skills/{domain}/SKILL.md` | Eagerly loaded rules and progressive-disclosure domain skill |\n"
|
|
313
|
+
"| `.evoloop/constitution.md` and `.evoloop/config.yaml` | Domain invariants, prompt budgets, protected paths, and stack configuration |\n"
|
|
314
|
+
f"| `evals/harness.py` and `evals/fakes.py` | Wired evaluation harness and deterministic `Fake{domain_pascal}Client` with fault injection |\n"
|
|
315
|
+
f"{adapter_row}"
|
|
316
|
+
"| `evals/evaluators/` | Deterministic evaluators (`trajectory_match`, `tool_policy`, `efficiency_budget`, `groundedness`) and LLM judge |\n"
|
|
317
|
+
f"| `evals/datasets/{domain}_flows.yaml` | Starter single-turn and multi-turn YAML evaluation scenarios |\n"
|
|
318
|
+
"| `tests/test_eval_framework.py` and `tests/test_agentic_flows.py` | Fast offline unit tests and live evaluation test runner |\n"
|
|
319
|
+
"| `evaluations/README.md` | Chronological index of evaluation runs |"
|
|
320
|
+
)
|
|
321
|
+
run_app = (
|
|
322
|
+
"```bash\n"
|
|
323
|
+
f"# Interactive chat REPL:\n"
|
|
324
|
+
f"uv run {project_name}\n\n"
|
|
325
|
+
f"# Single-shot prompt:\n"
|
|
326
|
+
f'uv run {project_name} --prompt "Run a lookup for item-1."\n'
|
|
327
|
+
"```"
|
|
328
|
+
)
|
|
329
|
+
validate_cmd = (
|
|
330
|
+
f"uv run .agents/skills/evoloop-scenarios/scripts/validate_scenarios.py \\\n"
|
|
331
|
+
f" evals/datasets/{domain}_flows.yaml --config .evoloop/config.yaml --harness evals/harness.py"
|
|
332
|
+
)
|
|
333
|
+
client_file = f"src/{package_name}/client.py"
|
|
334
|
+
fakes_file = "evals/fakes.py"
|
|
335
|
+
else:
|
|
336
|
+
build_file = "`pom.xml`" if build_tool == "maven" else "`build.gradle` and `settings.gradle`"
|
|
337
|
+
extra_rows = ""
|
|
338
|
+
if framework == "micronaut":
|
|
339
|
+
extra_rows = (
|
|
340
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Tools.java` | `@Singleton` Micronaut Model Context Protocol (MCP) (`/mcp`) and LangChain4j `@Tool` bean backed by `{domain_pascal}Client` |\n"
|
|
341
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Factory.java` | Micronaut `@Factory` for client, memory, and LangChain4j `AiServices` agent beans |\n"
|
|
342
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Controller.java` | Micronaut HTTP controller (`GET /api/{domain}/health` and `POST /api/{domain}/chat`) |\n"
|
|
343
|
+
"| `src/main/resources/application.yml` | Micronaut server, MCP HTTP server (`/mcp`), and LLM endpoint configuration |\n"
|
|
344
|
+
)
|
|
345
|
+
run_cmd = "mvn mn:run" if build_tool == "maven" else "./gradlew run"
|
|
346
|
+
run_app = (
|
|
347
|
+
"1. Start the Micronaut HTTP and MCP server. It defaults to port `9000` (`SERVER_PORT`) to avoid port `8080` conflicts with `llama-server`:\n"
|
|
348
|
+
"```bash\n"
|
|
349
|
+
f"{run_cmd}\n"
|
|
350
|
+
"```\n\n"
|
|
351
|
+
"2. Send a chat request. The server also exposes MCP tools at `http://localhost:9000/mcp`:\n"
|
|
352
|
+
"```bash\n"
|
|
353
|
+
f"curl -s -X POST http://localhost:9000/api/{domain}/chat \\\n"
|
|
354
|
+
' -H "Content-Type: application/json" \\\n'
|
|
355
|
+
' -d \'{"threadId":"demo-1","message":"Run a lookup for item-1."}\'\n'
|
|
356
|
+
"```"
|
|
357
|
+
)
|
|
358
|
+
elif framework == "spring-ai":
|
|
359
|
+
extra_rows = (
|
|
360
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Tools.java` | Spring AI `@Tool` adapter that records structured invocations for evaluation |\n"
|
|
361
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Config.java` | Spring `@Configuration` for client, memory, and Spring AI `ChatClient` agent beans |\n"
|
|
362
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Controller.java` | Spring Web `@RestController` (`GET /api/{domain}/health` and `POST /api/{domain}/chat`) |\n"
|
|
363
|
+
"| `src/main/resources/application.yml` | Spring Boot and Spring AI OpenAI configuration |\n"
|
|
364
|
+
)
|
|
365
|
+
run_cmd = "mvn spring-boot:run" if build_tool == "maven" else "./gradlew bootRun"
|
|
366
|
+
run_app = (
|
|
367
|
+
"1. Start the Spring Boot and Spring AI HTTP server. It defaults to port `9000` (`SERVER_PORT`) to avoid port `8080` conflicts with `llama-server`:\n"
|
|
368
|
+
"```bash\n"
|
|
369
|
+
f"{run_cmd}\n"
|
|
370
|
+
"```\n\n"
|
|
371
|
+
"2. Send a chat request:\n"
|
|
372
|
+
"```bash\n"
|
|
373
|
+
f"curl -s -X POST http://localhost:9000/api/{domain}/chat \\\n"
|
|
374
|
+
' -H "Content-Type: application/json" \\\n'
|
|
375
|
+
' -d \'{"threadId":"demo-1","message":"Run a lookup for item-1."}\'\n'
|
|
376
|
+
"```"
|
|
377
|
+
)
|
|
378
|
+
elif framework == "langchain4j":
|
|
379
|
+
extra_rows = (
|
|
380
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Tools.java` | LangChain4j `@Tool` adapter that calls `{domain_pascal}Client` |\n"
|
|
381
|
+
)
|
|
382
|
+
run_cmd = (
|
|
383
|
+
'mvn exec:java -Dexec.args="--prompt \'Run a lookup for item-1.\'"'
|
|
384
|
+
if build_tool == "maven"
|
|
385
|
+
else './gradlew run --args="--prompt \'Run a lookup for item-1.\'"'
|
|
386
|
+
)
|
|
387
|
+
repl_cmd = "mvn exec:java" if build_tool == "maven" else "./gradlew run"
|
|
388
|
+
run_app = (
|
|
389
|
+
"```bash\n"
|
|
390
|
+
f"# Single-shot prompt:\n{run_cmd}\n\n"
|
|
391
|
+
f"# Interactive CLI:\n{repl_cmd}\n"
|
|
392
|
+
"```"
|
|
393
|
+
)
|
|
394
|
+
else:
|
|
395
|
+
extra_rows = (
|
|
396
|
+
f"| `src/main/java/{pkg_path}/OpenAiCompatibleRunner.java` | Pure-JDK OpenAI-compatible Chat Completions runner with a recursive-descent JSON parser |\n"
|
|
397
|
+
)
|
|
398
|
+
run_cmd = (
|
|
399
|
+
'mvn exec:java -Dexec.args="--prompt \'Run a lookup for item-1.\'"'
|
|
400
|
+
if build_tool == "maven"
|
|
401
|
+
else './gradlew run --args="--prompt \'Run a lookup for item-1.\'"'
|
|
402
|
+
)
|
|
403
|
+
repl_cmd = "mvn exec:java" if build_tool == "maven" else "./gradlew run"
|
|
404
|
+
run_app = (
|
|
405
|
+
"```bash\n"
|
|
406
|
+
f"# Single-shot prompt:\n{run_cmd}\n\n"
|
|
407
|
+
f"# Interactive CLI:\n{repl_cmd}\n"
|
|
408
|
+
"```"
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
layout = (
|
|
412
|
+
"| Path | Purpose |\n"
|
|
413
|
+
"| :--- | :--- |\n"
|
|
414
|
+
f"| {build_file} | `{build_tool}` build manifest for `{framework}`, JUnit 5, and SnakeYAML |\n"
|
|
415
|
+
f"| `src/main/java/{pkg_path}/Application.java` | Runnable `{framework}` application entrypoint |\n"
|
|
416
|
+
f"{extra_rows}"
|
|
417
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Client.java` and `Default{domain_pascal}Client.java` | External client interface and runnable production stub |\n"
|
|
418
|
+
f"| `src/main/java/{pkg_path}/ConversationMemory.java` and `TurnOutcome.java` | Default thread-scoped checkpointer and structured turn result |\n"
|
|
419
|
+
f"| `src/main/java/{pkg_path}/{domain_pascal}Agent.java` | Checkpointer-backed `{framework}` agent with compact `SYSTEM_PROMPT`, tool dispatch, and `runTurn()` |\n"
|
|
420
|
+
f"| `AGENTS.md` and `skills/{domain}/SKILL.md` | Eagerly loaded rules and progressive-disclosure domain skill |\n"
|
|
421
|
+
"| `.evoloop/constitution.md` and `.evoloop/config.yaml` | Domain invariants, prompt budgets, protected paths, and stack configuration |\n"
|
|
422
|
+
f"| `src/test/java/{pkg_path}/evals/` | `Fake{domain_pascal}Client`, `AgentAdapter`, `DeterministicEvaluators`, offline `EvalFrameworkTest`, and live `AgenticFlowEvalTest` |\n"
|
|
423
|
+
f"| `evals/datasets/{domain}_flows.yaml` | Starter single-turn and multi-turn YAML evaluation scenarios |\n"
|
|
424
|
+
"| `evaluations/README.md` | Chronological index of evaluation runs |"
|
|
425
|
+
)
|
|
426
|
+
validate_cmd = (
|
|
427
|
+
f"uv run .agents/skills/evoloop-scenarios/scripts/validate_scenarios.py \\\n"
|
|
428
|
+
f" evals/datasets/{domain}_flows.yaml --config .evoloop/config.yaml"
|
|
429
|
+
)
|
|
430
|
+
client_file = f"src/main/java/{pkg_path}/Default{domain_pascal}Client.java"
|
|
431
|
+
fakes_file = f"src/test/java/{pkg_path}/evals/Fake{domain_pascal}Client.java"
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
"__PROJECT_LAYOUT_MD__": layout,
|
|
435
|
+
"__RUN_APP_SECTION_MD__": run_app,
|
|
436
|
+
"__VALIDATE_SCENARIOS_CMD__": validate_cmd,
|
|
437
|
+
"__CLIENT_FILE__": client_file,
|
|
438
|
+
"__FAKES_FILE__": fakes_file,
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def _apply_replacements(text: str, replacements: dict[str, str]) -> str:
|
|
443
|
+
result = text
|
|
444
|
+
for key, val in replacements.items():
|
|
445
|
+
result = result.replace(key, val)
|
|
446
|
+
return result
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def _render_starter_dataset(domain_title: str, primary_tool: str) -> str:
|
|
450
|
+
return (
|
|
451
|
+
f"# Golden single-turn and multi-turn agentic flow evaluation scenarios for {domain_title}\n"
|
|
452
|
+
f"# Expand starter cases using the evoloop-scenarios skill.\n\n"
|
|
453
|
+
f"cases:\n"
|
|
454
|
+
f" - id: happy_path_example\n"
|
|
455
|
+
f" description: Standard domain query calls expected tool and grounds response in tool output.\n"
|
|
456
|
+
f" category: happy_path\n"
|
|
457
|
+
f" turns:\n"
|
|
458
|
+
f' - "Run a lookup for item-1."\n'
|
|
459
|
+
f" expected_tool_calls:\n"
|
|
460
|
+
f" - name: {primary_tool}\n"
|
|
461
|
+
f' args: {{ query: "item-1" }}\n'
|
|
462
|
+
f" trajectory_match_mode: unordered\n"
|
|
463
|
+
f" max_tool_calls: 2\n"
|
|
464
|
+
f" grounded_any_of:\n"
|
|
465
|
+
f' - ["item-1"]\n'
|
|
466
|
+
f" rubric_criteria: >\n"
|
|
467
|
+
f" The agent must call {primary_tool} for item-1 and present the returned status clearly\n"
|
|
468
|
+
f" without fabricating extra fields.\n\n"
|
|
469
|
+
f" - id: vague_input_no_tools\n"
|
|
470
|
+
f" description: Vague request triggers clarification with zero domain tool calls.\n"
|
|
471
|
+
f" category: input_validation\n"
|
|
472
|
+
f" turns:\n"
|
|
473
|
+
f' - "Check that thing for me."\n'
|
|
474
|
+
f" expected_tool_calls: []\n"
|
|
475
|
+
f" trajectory_match_mode: strict\n"
|
|
476
|
+
f" forbidden_tools:\n"
|
|
477
|
+
f" - {primary_tool}\n"
|
|
478
|
+
f" max_tool_calls: 0\n"
|
|
479
|
+
f" rubric_criteria: >\n"
|
|
480
|
+
f" Because the user did not specify what to look up, the agent must NOT call {primary_tool}\n"
|
|
481
|
+
f" and must ask one clear clarifying question.\n"
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def _check_empty_target(target: Path, *, allow_non_empty: bool, force: bool) -> None:
|
|
486
|
+
if allow_non_empty or force or not target.exists():
|
|
487
|
+
return
|
|
488
|
+
existing = [p.name for p in target.iterdir() if p.name not in IGNORED_EMPTY_DIR_ENTRIES]
|
|
489
|
+
if existing:
|
|
490
|
+
preview = ", ".join(sorted(existing)[:5])
|
|
491
|
+
raise ValueError(
|
|
492
|
+
f"Target directory '{target}' is not empty (found: {preview}). "
|
|
493
|
+
"For an existing agent repository, use the `evoloop-init` skill (brownfield) instead, "
|
|
494
|
+
"or pass --allow-non-empty to scaffold here intentionally."
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _write_rendered_file(
|
|
499
|
+
dest: Path,
|
|
500
|
+
content: str,
|
|
501
|
+
*,
|
|
502
|
+
target: Path,
|
|
503
|
+
overwrite: bool,
|
|
504
|
+
dry_run: bool,
|
|
505
|
+
) -> str:
|
|
506
|
+
rel = str(dest.relative_to(target)).replace("\\", "/")
|
|
507
|
+
if dest.exists() and not overwrite:
|
|
508
|
+
return f"EXISTS (skipped): {rel}"
|
|
509
|
+
verb = "WOULD WRITE" if dry_run else ("WIRE" if dest.exists() else "CREATE")
|
|
510
|
+
if not dry_run:
|
|
511
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
512
|
+
dest.write_text(content, encoding="utf-8")
|
|
513
|
+
return f"{verb}: {rel}"
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def scaffold_agent(
|
|
517
|
+
target: Path,
|
|
518
|
+
*,
|
|
519
|
+
project_name: str | None = None,
|
|
520
|
+
domain: str = "assistant",
|
|
521
|
+
stack: str = "python",
|
|
522
|
+
framework: str | None = None,
|
|
523
|
+
build_tool: str | None = None,
|
|
524
|
+
java_package: str = "com.example.agent",
|
|
525
|
+
tools: str | list[str] | None = None,
|
|
526
|
+
invariants: list[str] | None = None,
|
|
527
|
+
max_system_prompt_words: int = 120,
|
|
528
|
+
allow_non_empty: bool = False,
|
|
529
|
+
force: bool = False,
|
|
530
|
+
dry_run: bool = False,
|
|
531
|
+
git_init: bool = False,
|
|
532
|
+
verify: bool = False,
|
|
533
|
+
) -> list[str]:
|
|
534
|
+
"""Create a minimal runnable, evaluation-ready greenfield agent application in `target`."""
|
|
535
|
+
if stack not in AGENT_STACK_DEFAULTS:
|
|
536
|
+
raise ValueError(
|
|
537
|
+
f"Unsupported stack '{stack}'. Supported stacks: {sorted(AGENT_STACK_DEFAULTS)}"
|
|
538
|
+
)
|
|
539
|
+
|
|
540
|
+
defaults = AGENT_STACK_DEFAULTS[stack]
|
|
541
|
+
resolved_build_tool = build_tool or defaults["build_tool"]
|
|
542
|
+
if resolved_build_tool not in defaults["build_tools"]:
|
|
543
|
+
raise ValueError(
|
|
544
|
+
f"Unsupported build tool '{resolved_build_tool}' for stack '{stack}'. "
|
|
545
|
+
f"Supported: {list(defaults['build_tools'])}"
|
|
546
|
+
)
|
|
547
|
+
resolved_framework = framework or defaults["framework"]
|
|
548
|
+
if resolved_framework not in defaults["frameworks"]:
|
|
549
|
+
raise ValueError(
|
|
550
|
+
f"Unsupported framework '{resolved_framework}' for stack '{stack}'. "
|
|
551
|
+
f"Supported: {list(defaults['frameworks'])}"
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
target = target.resolve()
|
|
555
|
+
_check_empty_target(target, allow_non_empty=allow_non_empty, force=force)
|
|
556
|
+
|
|
557
|
+
resolved_domain = _slug_snake(domain, "assistant")
|
|
558
|
+
resolved_project_name = (project_name or target.name or f"{resolved_domain}-agent").strip()
|
|
559
|
+
package_name = _slug_snake(resolved_project_name, f"{resolved_domain}_agent")
|
|
560
|
+
domain_pascal = _to_pascal(resolved_domain)
|
|
561
|
+
domain_title = resolved_domain.replace("_", " ").title()
|
|
562
|
+
tool_list = _parse_tools(tools)
|
|
563
|
+
primary_tool = tool_list[0]
|
|
564
|
+
pkg_path = java_package.replace(".", "/")
|
|
565
|
+
offline_test_cmd = defaults["offline_test_cmd"][resolved_build_tool]
|
|
566
|
+
live_eval_cmd = defaults["live_eval_cmd"][resolved_build_tool]
|
|
567
|
+
live_eval_judge_cmd = defaults["live_eval_judge_cmd"][resolved_build_tool]
|
|
568
|
+
setup_cmd = defaults["setup_cmd"][resolved_build_tool]
|
|
569
|
+
|
|
570
|
+
system_prompt_file = (
|
|
571
|
+
f"src/{package_name}/agent.py"
|
|
572
|
+
if stack == "python"
|
|
573
|
+
else f"src/main/java/{pkg_path}/{domain_pascal}Agent.java"
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
replacements: dict[str, str] = {
|
|
577
|
+
"__PROJECT_NAME__": resolved_project_name,
|
|
578
|
+
"__PACKAGE__": package_name,
|
|
579
|
+
"__STACK__": stack,
|
|
580
|
+
"__DOMAIN__": resolved_domain,
|
|
581
|
+
"__DOMAIN_TITLE__": domain_title,
|
|
582
|
+
"__DOMAIN_PASCAL__": domain_pascal,
|
|
583
|
+
"__FRAMEWORK__": resolved_framework,
|
|
584
|
+
"__BUILD_TOOL__": resolved_build_tool,
|
|
585
|
+
"__JAVA_PACKAGE__": java_package,
|
|
586
|
+
"__PACKAGE_PATH__": pkg_path,
|
|
587
|
+
"__PRIMARY_TOOL__": primary_tool,
|
|
588
|
+
"__PRIMARY_TOOL_CAMEL__": _to_camel(primary_tool),
|
|
589
|
+
"__TOOLS_LIST_MD__": _format_tools_md(tool_list),
|
|
590
|
+
"__TOOLS_INLINE__": ", ".join(f"`{t}`" for t in tool_list),
|
|
591
|
+
"__INVARIANTS_MD__": _format_invariants_md(invariants),
|
|
592
|
+
"__SETUP_CMD__": setup_cmd,
|
|
593
|
+
"__OFFLINE_TEST_CMD__": offline_test_cmd,
|
|
594
|
+
"__LIVE_EVAL_CMD__": live_eval_cmd,
|
|
595
|
+
"__LIVE_EVAL_JUDGE_CMD__": live_eval_judge_cmd,
|
|
596
|
+
"__MAX_SYSTEM_PROMPT_WORDS__": str(max_system_prompt_words),
|
|
597
|
+
}
|
|
598
|
+
replacements.update(
|
|
599
|
+
_render_readme_snippets(
|
|
600
|
+
stack=stack,
|
|
601
|
+
build_tool=resolved_build_tool,
|
|
602
|
+
framework=resolved_framework,
|
|
603
|
+
project_name=resolved_project_name,
|
|
604
|
+
package_name=package_name,
|
|
605
|
+
domain=resolved_domain,
|
|
606
|
+
domain_pascal=domain_pascal,
|
|
607
|
+
pkg_path=pkg_path,
|
|
608
|
+
)
|
|
609
|
+
)
|
|
610
|
+
if stack == "python":
|
|
611
|
+
replacements.update(_render_python_snippets(tool_list, resolved_framework))
|
|
612
|
+
else:
|
|
613
|
+
replacements.update(_render_java_snippets(tool_list))
|
|
614
|
+
|
|
615
|
+
actions: list[str] = []
|
|
616
|
+
if not dry_run:
|
|
617
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
618
|
+
|
|
619
|
+
def _sub_path(rel_str: str) -> str:
|
|
620
|
+
return (
|
|
621
|
+
rel_str.replace("__PACKAGE__", package_name)
|
|
622
|
+
.replace("__DOMAIN__", resolved_domain)
|
|
623
|
+
.replace("__DOMAIN_PASCAL__", domain_pascal)
|
|
624
|
+
.replace("__PACKAGE_PATH__", pkg_path)
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
# 1. Render common runtime, docs & governance templates (README.md, AGENTS.md, SKILL.md, .gitignore, constitution.md)
|
|
628
|
+
common_root = TEMPLATES_DIR / "common"
|
|
629
|
+
for src in sorted(common_root.rglob("*")):
|
|
630
|
+
if _is_ignored_template(src):
|
|
631
|
+
continue
|
|
632
|
+
rel = _sub_path(str(src.relative_to(common_root)).replace("\\", "/"))
|
|
633
|
+
rendered = _apply_replacements(src.read_text(encoding="utf-8"), replacements)
|
|
634
|
+
actions.append(
|
|
635
|
+
_write_rendered_file(
|
|
636
|
+
target / rel, rendered, target=target, overwrite=force, dry_run=dry_run
|
|
637
|
+
)
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
# 2. Render stack-specific runnable application + build manifest templates
|
|
641
|
+
stack_root = TEMPLATES_DIR / stack
|
|
642
|
+
if stack == "python":
|
|
643
|
+
for src in sorted(stack_root.rglob("*")):
|
|
644
|
+
if _is_ignored_template(src):
|
|
645
|
+
continue
|
|
646
|
+
rel_parts = src.relative_to(stack_root).parts
|
|
647
|
+
if rel_parts[0] == "eval_wiring":
|
|
648
|
+
continue
|
|
649
|
+
if src.name == "agent_deepagents.py":
|
|
650
|
+
if resolved_framework != "deepagents":
|
|
651
|
+
continue
|
|
652
|
+
rel = str(src.relative_to(stack_root).with_name("agent.py")).replace("\\", "/")
|
|
653
|
+
elif src.name == "agent_custom.py":
|
|
654
|
+
if resolved_framework != "custom":
|
|
655
|
+
continue
|
|
656
|
+
rel = str(src.relative_to(stack_root).with_name("agent.py")).replace("\\", "/")
|
|
657
|
+
else:
|
|
658
|
+
rel = str(src.relative_to(stack_root)).replace("\\", "/")
|
|
659
|
+
dest = target / _sub_path(rel)
|
|
660
|
+
rendered = _apply_replacements(src.read_text(encoding="utf-8"), replacements)
|
|
661
|
+
actions.append(
|
|
662
|
+
_write_rendered_file(dest, rendered, target=target, overwrite=force, dry_run=dry_run)
|
|
663
|
+
)
|
|
664
|
+
elif stack == "java":
|
|
665
|
+
# Build manifest selected by build_tool + framework
|
|
666
|
+
if resolved_build_tool == "maven":
|
|
667
|
+
pom_src = stack_root / "maven" / f"pom_{resolved_framework}.xml"
|
|
668
|
+
rendered = _apply_replacements(pom_src.read_text(encoding="utf-8"), replacements)
|
|
669
|
+
actions.append(
|
|
670
|
+
_write_rendered_file(
|
|
671
|
+
target / "pom.xml", rendered, target=target, overwrite=force, dry_run=dry_run
|
|
672
|
+
)
|
|
673
|
+
)
|
|
674
|
+
else:
|
|
675
|
+
gradle_src = stack_root / "gradle" / f"build_{resolved_framework}.gradle"
|
|
676
|
+
settings_src = stack_root / "gradle" / "settings.gradle"
|
|
677
|
+
actions.append(
|
|
678
|
+
_write_rendered_file(
|
|
679
|
+
target / "build.gradle",
|
|
680
|
+
_apply_replacements(gradle_src.read_text(encoding="utf-8"), replacements),
|
|
681
|
+
target=target,
|
|
682
|
+
overwrite=force,
|
|
683
|
+
dry_run=dry_run,
|
|
684
|
+
)
|
|
685
|
+
)
|
|
686
|
+
actions.append(
|
|
687
|
+
_write_rendered_file(
|
|
688
|
+
target / "settings.gradle",
|
|
689
|
+
_apply_replacements(settings_src.read_text(encoding="utf-8"), replacements),
|
|
690
|
+
target=target,
|
|
691
|
+
overwrite=force,
|
|
692
|
+
dry_run=dry_run,
|
|
693
|
+
)
|
|
694
|
+
)
|
|
695
|
+
|
|
696
|
+
# Shared core Java runtime sources
|
|
697
|
+
main_src_root = stack_root / "src"
|
|
698
|
+
for src in sorted(main_src_root.rglob("*")):
|
|
699
|
+
if _is_ignored_template(src):
|
|
700
|
+
continue
|
|
701
|
+
rel = _sub_path("src/" + str(src.relative_to(main_src_root)).replace("\\", "/"))
|
|
702
|
+
rendered = _apply_replacements(src.read_text(encoding="utf-8"), replacements)
|
|
703
|
+
actions.append(
|
|
704
|
+
_write_rendered_file(
|
|
705
|
+
target / rel, rendered, target=target, overwrite=force, dry_run=dry_run
|
|
706
|
+
)
|
|
707
|
+
)
|
|
708
|
+
|
|
709
|
+
# Framework-specific runnable application classes & resources
|
|
710
|
+
fw_root = stack_root / "frameworks" / resolved_framework
|
|
711
|
+
if fw_root.is_dir():
|
|
712
|
+
for src in sorted(fw_root.rglob("*")):
|
|
713
|
+
if _is_ignored_template(src):
|
|
714
|
+
continue
|
|
715
|
+
rel = _sub_path(str(src.relative_to(fw_root)).replace("\\", "/"))
|
|
716
|
+
rendered = _apply_replacements(src.read_text(encoding="utf-8"), replacements)
|
|
717
|
+
actions.append(
|
|
718
|
+
_write_rendered_file(
|
|
719
|
+
target / rel, rendered, target=target, overwrite=force, dry_run=dry_run
|
|
720
|
+
)
|
|
721
|
+
)
|
|
722
|
+
|
|
723
|
+
# 3. Compose evoloop-init/scripts/scaffold_evals.py for shared eval harness & config persistence
|
|
724
|
+
evals_mod = _load_scaffold_evals_module()
|
|
725
|
+
init_actions = evals_mod.scaffold_project(
|
|
726
|
+
target,
|
|
727
|
+
stack=stack,
|
|
728
|
+
domain=resolved_domain,
|
|
729
|
+
framework=resolved_framework,
|
|
730
|
+
build_tool=resolved_build_tool,
|
|
731
|
+
java_package=java_package,
|
|
732
|
+
project_name=resolved_project_name,
|
|
733
|
+
system_prompt_file=system_prompt_file,
|
|
734
|
+
force=force,
|
|
735
|
+
dry_run=dry_run,
|
|
736
|
+
)
|
|
737
|
+
actions.extend(init_actions)
|
|
738
|
+
|
|
739
|
+
# 4. Apply greenfield eval wiring (replaces generic TODO stubs with runnable wired tests + fakes)
|
|
740
|
+
wiring_root = stack_root / "eval_wiring"
|
|
741
|
+
if wiring_root.is_dir():
|
|
742
|
+
for src in sorted(wiring_root.rglob("*")):
|
|
743
|
+
if _is_ignored_template(src):
|
|
744
|
+
continue
|
|
745
|
+
if stack == "python" and src.name == "harness_deepagents.py":
|
|
746
|
+
if resolved_framework != "deepagents":
|
|
747
|
+
continue
|
|
748
|
+
rel = str(src.relative_to(wiring_root).with_name("harness.py")).replace("\\", "/")
|
|
749
|
+
elif stack == "python" and src.name == "harness_custom.py":
|
|
750
|
+
if resolved_framework != "custom":
|
|
751
|
+
continue
|
|
752
|
+
rel = str(src.relative_to(wiring_root).with_name("harness.py")).replace("\\", "/")
|
|
753
|
+
else:
|
|
754
|
+
rel = str(src.relative_to(wiring_root)).replace("\\", "/")
|
|
755
|
+
dest = target / _sub_path(rel)
|
|
756
|
+
rendered = _apply_replacements(src.read_text(encoding="utf-8"), replacements)
|
|
757
|
+
actions.append(
|
|
758
|
+
_write_rendered_file(
|
|
759
|
+
dest, rendered, target=target, overwrite=True, dry_run=dry_run
|
|
760
|
+
)
|
|
761
|
+
)
|
|
762
|
+
|
|
763
|
+
# 5. Wire starter scenario dataset to match the project's actual primary tool
|
|
764
|
+
dataset_dest = target / "evals" / "datasets" / f"{resolved_domain}_flows.yaml"
|
|
765
|
+
actions.append(
|
|
766
|
+
_write_rendered_file(
|
|
767
|
+
dataset_dest,
|
|
768
|
+
_render_starter_dataset(domain_title, primary_tool),
|
|
769
|
+
target=target,
|
|
770
|
+
overwrite=True,
|
|
771
|
+
dry_run=dry_run,
|
|
772
|
+
)
|
|
773
|
+
)
|
|
774
|
+
|
|
775
|
+
# Ensure budgets.max_system_prompt_words matches requested ceiling
|
|
776
|
+
config_path = target / ".evoloop" / "config.yaml"
|
|
777
|
+
if not dry_run and config_path.is_file():
|
|
778
|
+
cfg = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
|
|
779
|
+
cfg.setdefault("budgets", {})["max_system_prompt_words"] = max_system_prompt_words
|
|
780
|
+
cfg.setdefault("paths", {})["system_prompt_file"] = system_prompt_file
|
|
781
|
+
config_path.write_text(yaml.safe_dump(cfg, sort_keys=False), encoding="utf-8")
|
|
782
|
+
|
|
783
|
+
# 6. Optional opt-in post-scaffold steps (--git-init, --verify)
|
|
784
|
+
if git_init:
|
|
785
|
+
if dry_run:
|
|
786
|
+
actions.append("WOULD RUN: git init")
|
|
787
|
+
elif (target / ".git").exists():
|
|
788
|
+
actions.append("EXISTS (skipped): .git already initialized")
|
|
789
|
+
else:
|
|
790
|
+
proc = subprocess.run(
|
|
791
|
+
["git", "init"],
|
|
792
|
+
cwd=target,
|
|
793
|
+
capture_output=True,
|
|
794
|
+
text=True,
|
|
795
|
+
check=False,
|
|
796
|
+
)
|
|
797
|
+
if proc.returncode != 0:
|
|
798
|
+
raise RuntimeError(f"git init failed: {proc.stderr.strip()}")
|
|
799
|
+
actions.append("RUN: git init (initialized empty git repository)")
|
|
800
|
+
|
|
801
|
+
if verify:
|
|
802
|
+
if dry_run:
|
|
803
|
+
actions.append(f"WOULD RUN: {offline_test_cmd}")
|
|
804
|
+
else:
|
|
805
|
+
proc = subprocess.run(
|
|
806
|
+
shlex.split(offline_test_cmd),
|
|
807
|
+
cwd=target,
|
|
808
|
+
capture_output=True,
|
|
809
|
+
text=True,
|
|
810
|
+
check=False,
|
|
811
|
+
)
|
|
812
|
+
if proc.returncode != 0:
|
|
813
|
+
raise RuntimeError(
|
|
814
|
+
f"Offline verification failed ({offline_test_cmd}):\n"
|
|
815
|
+
f"{proc.stdout}\n{proc.stderr}".strip()
|
|
816
|
+
)
|
|
817
|
+
actions.append(f"VERIFY PASS: {offline_test_cmd}")
|
|
818
|
+
|
|
819
|
+
return actions
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
def main(argv: list[str] | None = None) -> int:
|
|
823
|
+
parser = argparse.ArgumentParser(
|
|
824
|
+
description="Scaffold a minimal runnable, evaluation-ready agent application from scratch (greenfield)."
|
|
825
|
+
)
|
|
826
|
+
parser.add_argument("--target", type=Path, default=Path("."), help="Target empty project directory.")
|
|
827
|
+
parser.add_argument("--project-name", default=None, help="Project name (defaults to target folder name).")
|
|
828
|
+
parser.add_argument("--domain", default="assistant", help="Short snake_case domain name (e.g., billing, support).")
|
|
829
|
+
parser.add_argument(
|
|
830
|
+
"--stack",
|
|
831
|
+
default="python",
|
|
832
|
+
choices=sorted(AGENT_STACK_DEFAULTS),
|
|
833
|
+
help="Target language stack.",
|
|
834
|
+
)
|
|
835
|
+
parser.add_argument(
|
|
836
|
+
"--framework",
|
|
837
|
+
default=None,
|
|
838
|
+
help="Agent framework (python: deepagents | custom; java: custom | spring-ai | langchain4j | micronaut).",
|
|
839
|
+
)
|
|
840
|
+
parser.add_argument(
|
|
841
|
+
"--build-tool",
|
|
842
|
+
default=None,
|
|
843
|
+
help="Build tool (python: uv; java: maven | gradle).",
|
|
844
|
+
)
|
|
845
|
+
parser.add_argument(
|
|
846
|
+
"--java-package",
|
|
847
|
+
default="com.example.agent",
|
|
848
|
+
help="Base Java package for --stack java.",
|
|
849
|
+
)
|
|
850
|
+
parser.add_argument(
|
|
851
|
+
"--tools",
|
|
852
|
+
default="lookup_record",
|
|
853
|
+
help="Comma-separated snake_case domain tool names (e.g., get_account,list_invoices).",
|
|
854
|
+
)
|
|
855
|
+
parser.add_argument(
|
|
856
|
+
"--invariant",
|
|
857
|
+
action="append",
|
|
858
|
+
dest="invariants",
|
|
859
|
+
default=None,
|
|
860
|
+
help="Domain invariant rule to include in .evoloop/constitution.md (repeatable).",
|
|
861
|
+
)
|
|
862
|
+
parser.add_argument(
|
|
863
|
+
"--max-system-prompt-words",
|
|
864
|
+
type=int,
|
|
865
|
+
default=120,
|
|
866
|
+
help="Word budget ceiling for SYSTEM_PROMPT (default: 120).",
|
|
867
|
+
)
|
|
868
|
+
parser.add_argument(
|
|
869
|
+
"--allow-non-empty",
|
|
870
|
+
action="store_true",
|
|
871
|
+
help="Allow scaffolding into a non-empty directory.",
|
|
872
|
+
)
|
|
873
|
+
parser.add_argument("--force", action="store_true", help="Overwrite existing scaffold files.")
|
|
874
|
+
parser.add_argument("--dry-run", action="store_true", help="Preview changes without writing files.")
|
|
875
|
+
parser.add_argument("--git-init", action="store_true", help="Initialize a Git repository after scaffolding.")
|
|
876
|
+
parser.add_argument(
|
|
877
|
+
"--verify",
|
|
878
|
+
action="store_true",
|
|
879
|
+
help="Run the configured offline test command after scaffolding.",
|
|
880
|
+
)
|
|
881
|
+
args = parser.parse_args(argv)
|
|
882
|
+
|
|
883
|
+
try:
|
|
884
|
+
actions = scaffold_agent(
|
|
885
|
+
args.target,
|
|
886
|
+
project_name=args.project_name,
|
|
887
|
+
domain=args.domain,
|
|
888
|
+
stack=args.stack,
|
|
889
|
+
framework=args.framework,
|
|
890
|
+
build_tool=args.build_tool,
|
|
891
|
+
java_package=args.java_package,
|
|
892
|
+
tools=args.tools,
|
|
893
|
+
invariants=args.invariants,
|
|
894
|
+
max_system_prompt_words=args.max_system_prompt_words,
|
|
895
|
+
allow_non_empty=args.allow_non_empty,
|
|
896
|
+
force=args.force,
|
|
897
|
+
dry_run=args.dry_run,
|
|
898
|
+
git_init=args.git_init,
|
|
899
|
+
verify=args.verify,
|
|
900
|
+
)
|
|
901
|
+
except (ValueError, FileNotFoundError, RuntimeError) as exc:
|
|
902
|
+
print(f"ERROR: {exc}", file=sys.stderr)
|
|
903
|
+
return 2
|
|
904
|
+
|
|
905
|
+
for line in actions:
|
|
906
|
+
print(line)
|
|
907
|
+
return 0
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
if __name__ == "__main__":
|
|
911
|
+
raise SystemExit(main())
|