Datasets:
Add tool-calling harness dataset
Browse files- README.md +129 -0
- codex/eval.jsonl +5 -0
- codex/tool_inventory.json +241 -0
- codex/train.jsonl +0 -0
- configs/codex-qwen35.toml +11 -0
- configs/opencode-qwen35.json +39 -0
- opencode/eval.jsonl +5 -0
- opencode/tool_inventory.json +159 -0
- opencode/train.jsonl +0 -0
- scripts/generate_codex_dataset.py +527 -0
- scripts/generate_opencode_dataset.py +490 -0
- scripts/generate_swival_dataset.py +633 -0
- scripts/run_codex_eval.py +227 -0
- scripts/run_opencode_eval.py +182 -0
- scripts/run_swival_eval.py +149 -0
- scripts/validate_codex_dataset.py +99 -0
- scripts/validate_opencode_dataset.py +100 -0
- scripts/validate_swival_dataset.py +101 -0
- swival/eval.jsonl +5 -0
- swival/tool_inventory.json +267 -0
- swival/train.jsonl +0 -0
README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
pretty_name: Tool Calling Harness Training Corpus
|
| 6 |
+
tags:
|
| 7 |
+
- tool-calling
|
| 8 |
+
- agents
|
| 9 |
+
- codex
|
| 10 |
+
- opencode
|
| 11 |
+
- swival
|
| 12 |
+
- function-calling
|
| 13 |
+
task_categories:
|
| 14 |
+
- text-generation
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Tool Calling Harness Training Corpus
|
| 18 |
+
|
| 19 |
+
This dataset contains supervised tool-calling conversations and executable eval tasks for three local coding-agent harnesses:
|
| 20 |
+
|
| 21 |
+
- Swival
|
| 22 |
+
- opencode
|
| 23 |
+
- Codex CLI
|
| 24 |
+
|
| 25 |
+
The examples are OpenAI-style chat records. Assistant tool calls use a `tool_calls` array with JSON-encoded function arguments, followed by tool-result messages and final assistant responses. The corpus is intended for fine-tuning and evaluating local models that need to choose the right tool, use the correct argument shape, recover from harness-specific mistakes, and verify coding work through the actual harness.
|
| 26 |
+
|
| 27 |
+
## Files
|
| 28 |
+
|
| 29 |
+
Training splits:
|
| 30 |
+
|
| 31 |
+
- `swival/train.jsonl`: 6,064 examples
|
| 32 |
+
- `opencode/train.jsonl`: 6,290 examples
|
| 33 |
+
- `codex/train.jsonl`: 6,410 examples
|
| 34 |
+
|
| 35 |
+
Eval task specs:
|
| 36 |
+
|
| 37 |
+
- `swival/eval.jsonl`: 5 executable eval tasks
|
| 38 |
+
- `opencode/eval.jsonl`: 5 executable eval tasks
|
| 39 |
+
- `codex/eval.jsonl`: 5 executable eval tasks
|
| 40 |
+
|
| 41 |
+
Tool inventories:
|
| 42 |
+
|
| 43 |
+
- `swival/tool_inventory.json`
|
| 44 |
+
- `opencode/tool_inventory.json`
|
| 45 |
+
- `codex/tool_inventory.json`
|
| 46 |
+
|
| 47 |
+
Harness support files:
|
| 48 |
+
|
| 49 |
+
- `configs/opencode-qwen35.json`
|
| 50 |
+
- `configs/codex-qwen35.toml`
|
| 51 |
+
- `scripts/run_swival_eval.py`
|
| 52 |
+
- `scripts/run_opencode_eval.py`
|
| 53 |
+
- `scripts/run_codex_eval.py`
|
| 54 |
+
- `scripts/validate_dataset.py`
|
| 55 |
+
- `scripts/validate_opencode_dataset.py`
|
| 56 |
+
- `scripts/validate_codex_dataset.py`
|
| 57 |
+
|
| 58 |
+
## Local Harness Targets
|
| 59 |
+
|
| 60 |
+
The generated eval runners were tested against a local OpenAI-compatible `qwen35` server at `http://127.0.0.1:8000`.
|
| 61 |
+
|
| 62 |
+
Swival uses:
|
| 63 |
+
|
| 64 |
+
```sh
|
| 65 |
+
swival --profile omlx
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
opencode uses:
|
| 69 |
+
|
| 70 |
+
```sh
|
| 71 |
+
bunx opencode-ai@latest run --model qwen35/qwen35
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
Codex uses:
|
| 75 |
+
|
| 76 |
+
```sh
|
| 77 |
+
env OMLX_API_KEY=omlx codex -a never exec --json --ephemeral --skip-git-repo-check --sandbox workspace-write -c model_provider=\"omlx\" -m qwen35
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## Validation
|
| 81 |
+
|
| 82 |
+
The source workspace validated the generated artifacts with:
|
| 83 |
+
|
| 84 |
+
```sh
|
| 85 |
+
uv run python scripts/validate_dataset.py data/swival_tool_calling_train.jsonl
|
| 86 |
+
uv run python scripts/validate_dataset.py data/swival_tool_calling_eval.jsonl
|
| 87 |
+
uv run python scripts/validate_opencode_dataset.py data/opencode_tool_calling_train.jsonl
|
| 88 |
+
uv run python scripts/validate_opencode_dataset.py data/opencode_tool_calling_eval.jsonl
|
| 89 |
+
uv run python scripts/validate_codex_dataset.py data/codex_tool_calling_train.jsonl
|
| 90 |
+
uv run python scripts/validate_codex_dataset.py data/codex_tool_calling_eval.jsonl
|
| 91 |
+
uv run python scripts/run_swival_eval.py --self-check
|
| 92 |
+
uv run python scripts/run_opencode_eval.py --self-check
|
| 93 |
+
uv run python scripts/run_codex_eval.py --self-check
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
Live smoke tests were also run for opencode and Codex against the local `qwen35` endpoint. Swival, opencode, and Codex each have their own tool naming and argument conventions, so the examples intentionally avoid collapsing them into one generic schema.
|
| 97 |
+
|
| 98 |
+
## Schema
|
| 99 |
+
|
| 100 |
+
Training rows use:
|
| 101 |
+
|
| 102 |
+
```json
|
| 103 |
+
{
|
| 104 |
+
"id": "string",
|
| 105 |
+
"split": "train",
|
| 106 |
+
"tags": ["harness", "tool_name"],
|
| 107 |
+
"messages": [
|
| 108 |
+
{"role": "user", "content": "task"},
|
| 109 |
+
{
|
| 110 |
+
"role": "assistant",
|
| 111 |
+
"content": "",
|
| 112 |
+
"tool_calls": [
|
| 113 |
+
{
|
| 114 |
+
"id": "call_1",
|
| 115 |
+
"type": "function",
|
| 116 |
+
"function": {
|
| 117 |
+
"name": "tool_name",
|
| 118 |
+
"arguments": "{\"key\":\"value\"}"
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
]
|
| 122 |
+
},
|
| 123 |
+
{"role": "tool", "tool_call_id": "call_1", "name": "tool_name", "content": "tool result"},
|
| 124 |
+
{"role": "assistant", "content": "final response"}
|
| 125 |
+
]
|
| 126 |
+
}
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
Eval rows define disposable workspace files plus verifiers such as exact file contents, substring checks, missing-file checks, JSON field checks, and command checks.
|
codex/eval.jsonl
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id":"codex-eval-edit","prompt":"In settings.py, change only the second timeout from 5 to 10. Do not change the first timeout.","files":{"settings.py":"timeout = 5\nretries = 2\ntimeout = 5\n"},"verify":{"settings.py":"timeout = 5\nretries = 2\ntimeout = 10\n"},"expected_events":["command_execution"]}
|
| 2 |
+
{"id":"codex-eval-add-file","prompt":"Create docs/notes.md containing a short note that says done.","files":{"README.md":"# Demo\n"},"verify_contains":{"docs/notes.md":["done"]},"expected_events":[]}
|
| 3 |
+
{"id":"codex-eval-run-test","prompt":"Run `python3 tests/check.py` and report whether it passed.","files":{"tests/check.py":"assert 2 + 3 == 5\nprint('ok')\n"},"verify_command":["python3","tests/check.py"],"expected_events":["command_execution"]}
|
| 4 |
+
{"id":"codex-eval-grep-edit","prompt":"Find the TODO in src and remove the TODO marker, leaving the explanatory text.","files":{"src/app.py":"def main():\n # TODO remove fallback\n return True\n"},"verify":{"src/app.py":"def main():\n # remove fallback\n return True\n"},"expected_events":["command_execution"]}
|
| 5 |
+
{"id":"codex-eval-summary-json","prompt":"Read README.md and write summary.json with fields name and kind. Use name Widget and kind tiny router.","files":{"README.md":"# Widget\n\nA tiny router.\n"},"verify_json":{"summary.json":{"name":"Widget","kind":"tiny router"}},"expected_events":["command_execution"]}
|
codex/tool_inventory.json
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "Codex CLI help, official Codex manual, current session tool surfaces, and codex exec JSONL event stream",
|
| 3 |
+
"harness": "env OMLX_API_KEY=omlx codex -a never exec --json --ephemeral --skip-git-repo-check --sandbox workspace-write -c model_provider=\"omlx\" -m qwen35",
|
| 4 |
+
"config": "/private/tmp/callers/configs/codex-qwen35.toml",
|
| 5 |
+
"tools": [
|
| 6 |
+
{
|
| 7 |
+
"name": "exec_command",
|
| 8 |
+
"description": "Run shell commands inside Codex's sandbox. JSONL events surface these as command_execution items.",
|
| 9 |
+
"required": [
|
| 10 |
+
"cmd"
|
| 11 |
+
],
|
| 12 |
+
"properties": [
|
| 13 |
+
"cmd",
|
| 14 |
+
"workdir",
|
| 15 |
+
"yield_time_ms",
|
| 16 |
+
"max_output_tokens",
|
| 17 |
+
"sandbox_permissions",
|
| 18 |
+
"justification",
|
| 19 |
+
"prefix_rule"
|
| 20 |
+
],
|
| 21 |
+
"event_types": [
|
| 22 |
+
"command_execution"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "write_stdin",
|
| 27 |
+
"description": "Send input to an existing long-running Codex exec session.",
|
| 28 |
+
"required": [
|
| 29 |
+
"session_id"
|
| 30 |
+
],
|
| 31 |
+
"properties": [
|
| 32 |
+
"session_id",
|
| 33 |
+
"chars",
|
| 34 |
+
"yield_time_ms",
|
| 35 |
+
"max_output_tokens"
|
| 36 |
+
],
|
| 37 |
+
"event_types": [
|
| 38 |
+
"command_execution"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "apply_patch",
|
| 43 |
+
"description": "Edit files through Codex's patch tool. Use for manual file edits instead of ad hoc shell writes.",
|
| 44 |
+
"required": [
|
| 45 |
+
"patch"
|
| 46 |
+
],
|
| 47 |
+
"properties": [
|
| 48 |
+
"patch"
|
| 49 |
+
],
|
| 50 |
+
"event_types": [
|
| 51 |
+
"file_change"
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"name": "update_plan",
|
| 56 |
+
"description": "Track multi-step work with one in-progress item at a time.",
|
| 57 |
+
"required": [
|
| 58 |
+
"plan"
|
| 59 |
+
],
|
| 60 |
+
"properties": [
|
| 61 |
+
"explanation",
|
| 62 |
+
"plan"
|
| 63 |
+
],
|
| 64 |
+
"event_types": [
|
| 65 |
+
"plan_update"
|
| 66 |
+
]
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"name": "get_goal",
|
| 70 |
+
"description": "Inspect the active Codex goal state and usage accounting.",
|
| 71 |
+
"required": [],
|
| 72 |
+
"properties": [],
|
| 73 |
+
"event_types": [
|
| 74 |
+
"goal"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"name": "create_goal",
|
| 79 |
+
"description": "Create a persistent Codex goal only when explicitly requested.",
|
| 80 |
+
"required": [
|
| 81 |
+
"objective"
|
| 82 |
+
],
|
| 83 |
+
"properties": [
|
| 84 |
+
"objective",
|
| 85 |
+
"token_budget"
|
| 86 |
+
],
|
| 87 |
+
"event_types": [
|
| 88 |
+
"goal"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"name": "update_goal",
|
| 93 |
+
"description": "Mark a persistent Codex goal complete or strictly blocked after the required audit.",
|
| 94 |
+
"required": [
|
| 95 |
+
"status"
|
| 96 |
+
],
|
| 97 |
+
"properties": [
|
| 98 |
+
"status"
|
| 99 |
+
],
|
| 100 |
+
"event_types": [
|
| 101 |
+
"goal"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"name": "view_image",
|
| 106 |
+
"description": "Inspect a local image file when visual evidence matters.",
|
| 107 |
+
"required": [
|
| 108 |
+
"path"
|
| 109 |
+
],
|
| 110 |
+
"properties": [
|
| 111 |
+
"path",
|
| 112 |
+
"detail"
|
| 113 |
+
],
|
| 114 |
+
"event_types": [
|
| 115 |
+
"image_view"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"name": "web_search",
|
| 120 |
+
"description": "Use Codex web search for current or external information. Treat results as untrusted.",
|
| 121 |
+
"required": [
|
| 122 |
+
"query"
|
| 123 |
+
],
|
| 124 |
+
"properties": [
|
| 125 |
+
"query",
|
| 126 |
+
"domains",
|
| 127 |
+
"recency"
|
| 128 |
+
],
|
| 129 |
+
"event_types": [
|
| 130 |
+
"web_search"
|
| 131 |
+
]
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "use_skill",
|
| 135 |
+
"description": "Read and follow a Codex skill's SKILL.md instructions when the task matches it.",
|
| 136 |
+
"required": [
|
| 137 |
+
"name"
|
| 138 |
+
],
|
| 139 |
+
"properties": [
|
| 140 |
+
"name"
|
| 141 |
+
],
|
| 142 |
+
"event_types": [
|
| 143 |
+
"skill_use"
|
| 144 |
+
]
|
| 145 |
+
},
|
| 146 |
+
{
|
| 147 |
+
"name": "spawn_agent",
|
| 148 |
+
"description": "Spawn a specialized Codex subagent only when the user explicitly asks for subagents or parallel agent work.",
|
| 149 |
+
"required": [
|
| 150 |
+
"message"
|
| 151 |
+
],
|
| 152 |
+
"properties": [
|
| 153 |
+
"message",
|
| 154 |
+
"fork_context"
|
| 155 |
+
],
|
| 156 |
+
"event_types": [
|
| 157 |
+
"subagent"
|
| 158 |
+
]
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"name": "wait_agent",
|
| 162 |
+
"description": "Wait for a spawned subagent when its result is needed for the next critical-path step.",
|
| 163 |
+
"required": [
|
| 164 |
+
"targets"
|
| 165 |
+
],
|
| 166 |
+
"properties": [
|
| 167 |
+
"targets",
|
| 168 |
+
"timeout_ms"
|
| 169 |
+
],
|
| 170 |
+
"event_types": [
|
| 171 |
+
"subagent"
|
| 172 |
+
]
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"name": "read_mcp_resource",
|
| 176 |
+
"description": "Read a listed MCP resource when an enabled MCP server provides relevant private or external context.",
|
| 177 |
+
"required": [
|
| 178 |
+
"server",
|
| 179 |
+
"uri"
|
| 180 |
+
],
|
| 181 |
+
"properties": [
|
| 182 |
+
"server",
|
| 183 |
+
"uri"
|
| 184 |
+
],
|
| 185 |
+
"event_types": [
|
| 186 |
+
"mcp_tool_call"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"name": "list_mcp_resources",
|
| 191 |
+
"description": "List available MCP resources before reading one.",
|
| 192 |
+
"required": [],
|
| 193 |
+
"properties": [
|
| 194 |
+
"server",
|
| 195 |
+
"cursor"
|
| 196 |
+
],
|
| 197 |
+
"event_types": [
|
| 198 |
+
"mcp_tool_call"
|
| 199 |
+
]
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"name": "imagegen",
|
| 203 |
+
"description": "Generate or edit bitmap images when the task explicitly asks for image generation.",
|
| 204 |
+
"required": [
|
| 205 |
+
"prompt"
|
| 206 |
+
],
|
| 207 |
+
"properties": [
|
| 208 |
+
"prompt"
|
| 209 |
+
],
|
| 210 |
+
"event_types": [
|
| 211 |
+
"image_generation"
|
| 212 |
+
]
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"name": "request_user_input",
|
| 216 |
+
"description": "Ask concise structured questions only in Plan mode when a risky unknown cannot be resolved locally.",
|
| 217 |
+
"required": [
|
| 218 |
+
"questions"
|
| 219 |
+
],
|
| 220 |
+
"properties": [
|
| 221 |
+
"questions"
|
| 222 |
+
],
|
| 223 |
+
"event_types": [
|
| 224 |
+
"elicitation"
|
| 225 |
+
]
|
| 226 |
+
},
|
| 227 |
+
{
|
| 228 |
+
"name": "final_answer",
|
| 229 |
+
"description": "Finish with a concise user-facing response after implementation and verification.",
|
| 230 |
+
"required": [
|
| 231 |
+
"content"
|
| 232 |
+
],
|
| 233 |
+
"properties": [
|
| 234 |
+
"content"
|
| 235 |
+
],
|
| 236 |
+
"event_types": [
|
| 237 |
+
"agent_message"
|
| 238 |
+
]
|
| 239 |
+
}
|
| 240 |
+
]
|
| 241 |
+
}
|
codex/train.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
configs/codex-qwen35.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_provider = "omlx"
|
| 2 |
+
model = "qwen35"
|
| 3 |
+
model_reasoning_effort = "high"
|
| 4 |
+
|
| 5 |
+
[model_providers.omlx]
|
| 6 |
+
name = "oMLX"
|
| 7 |
+
base_url = "http://127.0.0.1:8000/v1"
|
| 8 |
+
env_key = "OMLX_API_KEY"
|
| 9 |
+
|
| 10 |
+
[sandbox_workspace_write]
|
| 11 |
+
network_access = false
|
configs/opencode-qwen35.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://opencode.ai/config.json",
|
| 3 |
+
"model": "qwen35/qwen35",
|
| 4 |
+
"small_model": "qwen35/qwen35",
|
| 5 |
+
"provider": {
|
| 6 |
+
"qwen35": {
|
| 7 |
+
"npm": "@ai-sdk/openai-compatible",
|
| 8 |
+
"name": "qwen35 local OpenAI-compatible server",
|
| 9 |
+
"options": {
|
| 10 |
+
"baseURL": "http://127.0.0.1:8000/v1",
|
| 11 |
+
"apiKey": "omlx"
|
| 12 |
+
},
|
| 13 |
+
"models": {
|
| 14 |
+
"qwen35": {
|
| 15 |
+
"name": "qwen35",
|
| 16 |
+
"tool_call": true,
|
| 17 |
+
"limit": {
|
| 18 |
+
"context": 128000,
|
| 19 |
+
"output": 65536
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
"permission": {
|
| 26 |
+
"bash": "allow",
|
| 27 |
+
"edit": "allow",
|
| 28 |
+
"read": "allow",
|
| 29 |
+
"grep": "allow",
|
| 30 |
+
"glob": "allow",
|
| 31 |
+
"webfetch": "allow",
|
| 32 |
+
"websearch": "allow",
|
| 33 |
+
"lsp": "allow",
|
| 34 |
+
"skill": "allow",
|
| 35 |
+
"todowrite": "allow",
|
| 36 |
+
"task": "allow"
|
| 37 |
+
},
|
| 38 |
+
"share": "disabled"
|
| 39 |
+
}
|
opencode/eval.jsonl
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id":"opencode-eval-edit","prompt":"In settings.py, change only the second timeout from 5 to 10.","files":{"settings.py":"timeout = 5\nretries = 2\ntimeout = 5\n"},"verify":{"settings.py":"timeout = 5\nretries = 2\ntimeout = 10\n"},"expected_tools":["read","edit"]}
|
| 2 |
+
{"id":"opencode-eval-patch","prompt":"Use a patch to add docs/notes.md containing a short note that says done.","files":{"README.md":"# Demo\n"},"verify_contains":{"docs/notes.md":["done"]},"expected_tools":["apply_patch"]}
|
| 3 |
+
{"id":"opencode-eval-bash","prompt":"Run `python3 tests/check.py` and report whether it passed.","files":{"tests/check.py":"assert 2 + 3 == 5\nprint('ok')\n"},"verify_command":["python3","tests/check.py"],"expected_tools":["bash"]}
|
| 4 |
+
{"id":"opencode-eval-write","prompt":"Read README.md and create docs/summary.md with the project name Widget and the phrase tiny router.","files":{"README.md":"# Widget\n\nA tiny router.\n"},"verify_contains":{"docs/summary.md":["Widget","tiny router"]},"expected_tools":["read","write"]}
|
| 5 |
+
{"id":"opencode-eval-grep","prompt":"Find the TODO in src and remove the TODO marker, leaving the explanatory text.","files":{"src/app.py":"def main():\n # TODO remove fallback\n return True\n"},"verify":{"src/app.py":"def main():\n # remove fallback\n return True\n"},"expected_tools":["grep","read","edit"]}
|
opencode/tool_inventory.json
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "opencode docs plus local @opencode-ai/plugin SDK types",
|
| 3 |
+
"harness": "bunx opencode-ai@latest run --model qwen35/qwen35 --format json",
|
| 4 |
+
"config": "/private/tmp/callers/configs/opencode-qwen35.json",
|
| 5 |
+
"tools": [
|
| 6 |
+
{
|
| 7 |
+
"name": "bash",
|
| 8 |
+
"description": "Execute shell commands in the project environment.",
|
| 9 |
+
"required": [
|
| 10 |
+
"command"
|
| 11 |
+
],
|
| 12 |
+
"properties": [
|
| 13 |
+
"command",
|
| 14 |
+
"description",
|
| 15 |
+
"timeout"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"name": "read",
|
| 20 |
+
"description": "Read file contents, optionally with a line range.",
|
| 21 |
+
"required": [
|
| 22 |
+
"filePath"
|
| 23 |
+
],
|
| 24 |
+
"properties": [
|
| 25 |
+
"filePath",
|
| 26 |
+
"offset",
|
| 27 |
+
"limit"
|
| 28 |
+
]
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"name": "edit",
|
| 32 |
+
"description": "Modify an existing file using exact string replacement.",
|
| 33 |
+
"required": [
|
| 34 |
+
"filePath",
|
| 35 |
+
"oldString",
|
| 36 |
+
"newString"
|
| 37 |
+
],
|
| 38 |
+
"properties": [
|
| 39 |
+
"filePath",
|
| 40 |
+
"oldString",
|
| 41 |
+
"newString",
|
| 42 |
+
"replaceAll"
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"name": "write",
|
| 47 |
+
"description": "Create a new file or overwrite an existing one.",
|
| 48 |
+
"required": [
|
| 49 |
+
"filePath",
|
| 50 |
+
"content"
|
| 51 |
+
],
|
| 52 |
+
"properties": [
|
| 53 |
+
"filePath",
|
| 54 |
+
"content"
|
| 55 |
+
]
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"name": "grep",
|
| 59 |
+
"description": "Search file contents with a regular expression.",
|
| 60 |
+
"required": [
|
| 61 |
+
"pattern"
|
| 62 |
+
],
|
| 63 |
+
"properties": [
|
| 64 |
+
"pattern",
|
| 65 |
+
"path",
|
| 66 |
+
"include"
|
| 67 |
+
]
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"name": "glob",
|
| 71 |
+
"description": "Find files by glob pattern.",
|
| 72 |
+
"required": [
|
| 73 |
+
"pattern"
|
| 74 |
+
],
|
| 75 |
+
"properties": [
|
| 76 |
+
"pattern",
|
| 77 |
+
"path"
|
| 78 |
+
]
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"name": "lsp",
|
| 82 |
+
"description": "Use language-server code intelligence.",
|
| 83 |
+
"required": [
|
| 84 |
+
"operation"
|
| 85 |
+
],
|
| 86 |
+
"properties": [
|
| 87 |
+
"operation",
|
| 88 |
+
"filePath",
|
| 89 |
+
"line",
|
| 90 |
+
"character",
|
| 91 |
+
"symbol"
|
| 92 |
+
]
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"name": "apply_patch",
|
| 96 |
+
"description": "Apply a patch with paths embedded in patch marker lines.",
|
| 97 |
+
"required": [
|
| 98 |
+
"patchText"
|
| 99 |
+
],
|
| 100 |
+
"properties": [
|
| 101 |
+
"patchText"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"name": "skill",
|
| 106 |
+
"description": "Load a SKILL.md instruction file.",
|
| 107 |
+
"required": [
|
| 108 |
+
"name"
|
| 109 |
+
],
|
| 110 |
+
"properties": [
|
| 111 |
+
"name"
|
| 112 |
+
]
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"name": "todowrite",
|
| 116 |
+
"description": "Create or update the coding-session todo list.",
|
| 117 |
+
"required": [
|
| 118 |
+
"todos"
|
| 119 |
+
],
|
| 120 |
+
"properties": [
|
| 121 |
+
"todos"
|
| 122 |
+
]
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"name": "webfetch",
|
| 126 |
+
"description": "Fetch and read a web page.",
|
| 127 |
+
"required": [
|
| 128 |
+
"url"
|
| 129 |
+
],
|
| 130 |
+
"properties": [
|
| 131 |
+
"url",
|
| 132 |
+
"prompt"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"name": "websearch",
|
| 137 |
+
"description": "Search the web when enabled by provider or EXA config.",
|
| 138 |
+
"required": [
|
| 139 |
+
"query"
|
| 140 |
+
],
|
| 141 |
+
"properties": [
|
| 142 |
+
"query"
|
| 143 |
+
]
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"name": "task",
|
| 147 |
+
"description": "Run a subtask with another agent.",
|
| 148 |
+
"required": [
|
| 149 |
+
"description",
|
| 150 |
+
"prompt"
|
| 151 |
+
],
|
| 152 |
+
"properties": [
|
| 153 |
+
"description",
|
| 154 |
+
"prompt",
|
| 155 |
+
"subagent_type"
|
| 156 |
+
]
|
| 157 |
+
}
|
| 158 |
+
]
|
| 159 |
+
}
|
opencode/train.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/generate_codex_dataset.py
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import random
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 13 |
+
DATA_DIR = ROOT / "data"
|
| 14 |
+
TMP_DIR = ROOT / "tmp"
|
| 15 |
+
CONFIG_PATH = ROOT / "configs" / "codex-qwen35.toml"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
CODEX_TOOLS: list[dict[str, Any]] = [
|
| 19 |
+
{
|
| 20 |
+
"name": "exec_command",
|
| 21 |
+
"description": "Run shell commands inside Codex's sandbox. JSONL events surface these as command_execution items.",
|
| 22 |
+
"required": ["cmd"],
|
| 23 |
+
"properties": ["cmd", "workdir", "yield_time_ms", "max_output_tokens", "sandbox_permissions", "justification", "prefix_rule"],
|
| 24 |
+
"event_types": ["command_execution"],
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "write_stdin",
|
| 28 |
+
"description": "Send input to an existing long-running Codex exec session.",
|
| 29 |
+
"required": ["session_id"],
|
| 30 |
+
"properties": ["session_id", "chars", "yield_time_ms", "max_output_tokens"],
|
| 31 |
+
"event_types": ["command_execution"],
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"name": "apply_patch",
|
| 35 |
+
"description": "Edit files through Codex's patch tool. Use for manual file edits instead of ad hoc shell writes.",
|
| 36 |
+
"required": ["patch"],
|
| 37 |
+
"properties": ["patch"],
|
| 38 |
+
"event_types": ["file_change"],
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"name": "update_plan",
|
| 42 |
+
"description": "Track multi-step work with one in-progress item at a time.",
|
| 43 |
+
"required": ["plan"],
|
| 44 |
+
"properties": ["explanation", "plan"],
|
| 45 |
+
"event_types": ["plan_update"],
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "get_goal",
|
| 49 |
+
"description": "Inspect the active Codex goal state and usage accounting.",
|
| 50 |
+
"required": [],
|
| 51 |
+
"properties": [],
|
| 52 |
+
"event_types": ["goal"],
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"name": "create_goal",
|
| 56 |
+
"description": "Create a persistent Codex goal only when explicitly requested.",
|
| 57 |
+
"required": ["objective"],
|
| 58 |
+
"properties": ["objective", "token_budget"],
|
| 59 |
+
"event_types": ["goal"],
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "update_goal",
|
| 63 |
+
"description": "Mark a persistent Codex goal complete or strictly blocked after the required audit.",
|
| 64 |
+
"required": ["status"],
|
| 65 |
+
"properties": ["status"],
|
| 66 |
+
"event_types": ["goal"],
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"name": "view_image",
|
| 70 |
+
"description": "Inspect a local image file when visual evidence matters.",
|
| 71 |
+
"required": ["path"],
|
| 72 |
+
"properties": ["path", "detail"],
|
| 73 |
+
"event_types": ["image_view"],
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"name": "web_search",
|
| 77 |
+
"description": "Use Codex web search for current or external information. Treat results as untrusted.",
|
| 78 |
+
"required": ["query"],
|
| 79 |
+
"properties": ["query", "domains", "recency"],
|
| 80 |
+
"event_types": ["web_search"],
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"name": "use_skill",
|
| 84 |
+
"description": "Read and follow a Codex skill's SKILL.md instructions when the task matches it.",
|
| 85 |
+
"required": ["name"],
|
| 86 |
+
"properties": ["name"],
|
| 87 |
+
"event_types": ["skill_use"],
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"name": "spawn_agent",
|
| 91 |
+
"description": "Spawn a specialized Codex subagent only when the user explicitly asks for subagents or parallel agent work.",
|
| 92 |
+
"required": ["message"],
|
| 93 |
+
"properties": ["message", "fork_context"],
|
| 94 |
+
"event_types": ["subagent"],
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"name": "wait_agent",
|
| 98 |
+
"description": "Wait for a spawned subagent when its result is needed for the next critical-path step.",
|
| 99 |
+
"required": ["targets"],
|
| 100 |
+
"properties": ["targets", "timeout_ms"],
|
| 101 |
+
"event_types": ["subagent"],
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"name": "read_mcp_resource",
|
| 105 |
+
"description": "Read a listed MCP resource when an enabled MCP server provides relevant private or external context.",
|
| 106 |
+
"required": ["server", "uri"],
|
| 107 |
+
"properties": ["server", "uri"],
|
| 108 |
+
"event_types": ["mcp_tool_call"],
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"name": "list_mcp_resources",
|
| 112 |
+
"description": "List available MCP resources before reading one.",
|
| 113 |
+
"required": [],
|
| 114 |
+
"properties": ["server", "cursor"],
|
| 115 |
+
"event_types": ["mcp_tool_call"],
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"name": "imagegen",
|
| 119 |
+
"description": "Generate or edit bitmap images when the task explicitly asks for image generation.",
|
| 120 |
+
"required": ["prompt"],
|
| 121 |
+
"properties": ["prompt"],
|
| 122 |
+
"event_types": ["image_generation"],
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"name": "request_user_input",
|
| 126 |
+
"description": "Ask concise structured questions only in Plan mode when a risky unknown cannot be resolved locally.",
|
| 127 |
+
"required": ["questions"],
|
| 128 |
+
"properties": ["questions"],
|
| 129 |
+
"event_types": ["elicitation"],
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"name": "final_answer",
|
| 133 |
+
"description": "Finish with a concise user-facing response after implementation and verification.",
|
| 134 |
+
"required": ["content"],
|
| 135 |
+
"properties": ["content"],
|
| 136 |
+
"event_types": ["agent_message"],
|
| 137 |
+
},
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
EXEMPLARS: dict[str, list[dict[str, Any]]] = {
|
| 142 |
+
"exec_command": [
|
| 143 |
+
{"cmd": "rg -n \"TODO|FIXME\" src", "workdir": "/workspace/project", "yield_time_ms": 10000, "max_output_tokens": 12000},
|
| 144 |
+
{"cmd": "uv run pytest tests/test_parser.py", "workdir": "/workspace/project", "yield_time_ms": 30000, "max_output_tokens": 20000},
|
| 145 |
+
{"cmd": "git diff --check", "workdir": "/workspace/project", "yield_time_ms": 10000, "max_output_tokens": 12000},
|
| 146 |
+
],
|
| 147 |
+
"write_stdin": [
|
| 148 |
+
{"session_id": 1, "chars": "q\n", "yield_time_ms": 1000, "max_output_tokens": 12000},
|
| 149 |
+
{"session_id": 2, "chars": "", "yield_time_ms": 5000, "max_output_tokens": 20000},
|
| 150 |
+
],
|
| 151 |
+
"apply_patch": [
|
| 152 |
+
{"patch": "*** Begin Patch\n*** Update File: src/app.py\n@@\n-return False\n+return True\n*** End Patch\n"},
|
| 153 |
+
{"patch": "*** Begin Patch\n*** Add File: docs/notes.md\n+# Notes\n+\n+Done.\n*** End Patch\n"},
|
| 154 |
+
],
|
| 155 |
+
"update_plan": [
|
| 156 |
+
{"plan": [{"step": "Inspect current behavior", "status": "in_progress"}, {"step": "Patch failing path", "status": "pending"}, {"step": "Run focused tests", "status": "pending"}]},
|
| 157 |
+
{"explanation": "The implementation is patched, so verification is now the active step.", "plan": [{"step": "Inspect current behavior", "status": "completed"}, {"step": "Patch failing path", "status": "completed"}, {"step": "Run focused tests", "status": "in_progress"}]},
|
| 158 |
+
],
|
| 159 |
+
"get_goal": [
|
| 160 |
+
{},
|
| 161 |
+
],
|
| 162 |
+
"create_goal": [
|
| 163 |
+
{"objective": "Finish the migration and verify all tests pass."},
|
| 164 |
+
{"objective": "Audit the repository for parser regressions.", "token_budget": 50000},
|
| 165 |
+
],
|
| 166 |
+
"update_goal": [
|
| 167 |
+
{"status": "complete"},
|
| 168 |
+
{"status": "blocked"},
|
| 169 |
+
],
|
| 170 |
+
"view_image": [
|
| 171 |
+
{"path": "screenshots/failure.png", "detail": "high"},
|
| 172 |
+
{"path": "assets/logo.webp", "detail": "original"},
|
| 173 |
+
],
|
| 174 |
+
"web_search": [
|
| 175 |
+
{"query": "official OpenAI Codex non-interactive mode codex exec JSONL", "domains": ["developers.openai.com"]},
|
| 176 |
+
{"query": "Python argparse subcommands current docs", "recency": 30},
|
| 177 |
+
],
|
| 178 |
+
"use_skill": [
|
| 179 |
+
{"name": "openai-docs"},
|
| 180 |
+
{"name": "github:gh-fix-ci"},
|
| 181 |
+
{"name": "frontend-design"},
|
| 182 |
+
],
|
| 183 |
+
"spawn_agent": [
|
| 184 |
+
{"message": "Inspect tests/test_parser.py and report the expected empty-name behavior. Do not edit files.", "fork_context": False},
|
| 185 |
+
{"message": "Patch README examples only. Do not touch source files.", "fork_context": False},
|
| 186 |
+
],
|
| 187 |
+
"wait_agent": [
|
| 188 |
+
{"targets": ["agent-1"], "timeout_ms": 300000},
|
| 189 |
+
{"targets": ["agent-1", "agent-2"], "timeout_ms": 600000},
|
| 190 |
+
],
|
| 191 |
+
"read_mcp_resource": [
|
| 192 |
+
{"server": "docs", "uri": "docs://parser-api"},
|
| 193 |
+
{"server": "github", "uri": "repo://owner/project/pull/123"},
|
| 194 |
+
],
|
| 195 |
+
"list_mcp_resources": [
|
| 196 |
+
{},
|
| 197 |
+
{"server": "docs"},
|
| 198 |
+
],
|
| 199 |
+
"imagegen": [
|
| 200 |
+
{"prompt": "A clean product mockup screenshot of a compact task dashboard."},
|
| 201 |
+
{"prompt": "Transparent PNG icon of a simple command terminal."},
|
| 202 |
+
],
|
| 203 |
+
"request_user_input": [
|
| 204 |
+
{"questions": [{"header": "Scope", "id": "scope", "question": "Which scope should I modify?", "options": [{"label": "Tests only", "description": "Limit changes to the test fixtures."}, {"label": "Source too", "description": "Allow source changes as well."}]}]},
|
| 205 |
+
],
|
| 206 |
+
"final_answer": [
|
| 207 |
+
{"content": "Implemented the parser fix and verified the focused tests pass."},
|
| 208 |
+
],
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
@dataclass(frozen=True)
|
| 213 |
+
class Example:
|
| 214 |
+
id: str
|
| 215 |
+
split: str
|
| 216 |
+
tags: list[str]
|
| 217 |
+
messages: list[dict[str, Any]]
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def user(content: str) -> dict[str, Any]:
|
| 221 |
+
return {"role": "user", "content": content}
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def assistant(content: str) -> dict[str, Any]:
|
| 225 |
+
return {"role": "assistant", "content": content}
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def tool_call(name: str, args: dict[str, Any], call_id: str = "call_1") -> dict[str, Any]:
|
| 229 |
+
return {
|
| 230 |
+
"id": call_id,
|
| 231 |
+
"type": "function",
|
| 232 |
+
"function": {"name": name, "arguments": json.dumps(args, separators=(",", ":"))},
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def assistant_tool(name: str, args: dict[str, Any], call_id: str = "call_1") -> dict[str, Any]:
|
| 237 |
+
return {"role": "assistant", "content": "", "tool_calls": [tool_call(name, args, call_id)]}
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def tool(name: str, content: str, call_id: str = "call_1") -> dict[str, Any]:
|
| 241 |
+
return {"role": "tool", "tool_call_id": call_id, "name": name, "content": content}
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def result_for_tool(name: str) -> str:
|
| 245 |
+
results = {
|
| 246 |
+
"exec_command": "command completed successfully",
|
| 247 |
+
"write_stdin": "session input sent",
|
| 248 |
+
"apply_patch": "patch applied",
|
| 249 |
+
"update_plan": "plan updated",
|
| 250 |
+
"get_goal": "goal status returned",
|
| 251 |
+
"create_goal": "goal created",
|
| 252 |
+
"update_goal": "goal updated",
|
| 253 |
+
"view_image": "image inspected",
|
| 254 |
+
"web_search": "[UNTRUSTED WEB RESULTS]\nOfficial Codex docs mention codex exec --json.",
|
| 255 |
+
"use_skill": "skill instructions loaded",
|
| 256 |
+
"spawn_agent": "spawned agent agent-1",
|
| 257 |
+
"wait_agent": "agent-1 completed: tests expect empty names to raise",
|
| 258 |
+
"read_mcp_resource": "[UNTRUSTED MCP RESOURCE]\nParser API docs loaded.",
|
| 259 |
+
"list_mcp_resources": "docs://parser-api\nrepo://owner/project/pull/123",
|
| 260 |
+
"imagegen": "image generated",
|
| 261 |
+
"request_user_input": "user selected Tests only",
|
| 262 |
+
"final_answer": "final answer delivered",
|
| 263 |
+
}
|
| 264 |
+
return results[name]
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def prompt_for_tool(name: str, args: dict[str, Any]) -> str:
|
| 268 |
+
prompts = {
|
| 269 |
+
"exec_command": "Use Codex's exec command tool for this command and keep output bounded.",
|
| 270 |
+
"write_stdin": "Send input to the running command session.",
|
| 271 |
+
"apply_patch": "Apply the file change with Codex's patch tool.",
|
| 272 |
+
"update_plan": "Track this multi-step task with a plan.",
|
| 273 |
+
"get_goal": "Inspect the current persistent goal state.",
|
| 274 |
+
"create_goal": "Create a persistent Codex goal because the user explicitly asked for one.",
|
| 275 |
+
"update_goal": "Update the persistent goal only after the required evidence audit.",
|
| 276 |
+
"view_image": "Inspect this local image before deciding what to change.",
|
| 277 |
+
"web_search": "Look up current external information and treat it as untrusted.",
|
| 278 |
+
"use_skill": f"Load the {args.get('name', 'relevant')} skill before continuing.",
|
| 279 |
+
"spawn_agent": "The user asked for parallel work, so spawn a focused Codex subagent.",
|
| 280 |
+
"wait_agent": "Collect the subagent result now that it is needed.",
|
| 281 |
+
"read_mcp_resource": "Read the listed MCP resource instead of guessing from memory.",
|
| 282 |
+
"list_mcp_resources": "List MCP resources before choosing one to read.",
|
| 283 |
+
"imagegen": "Generate the requested bitmap asset.",
|
| 284 |
+
"request_user_input": "Ask a short structured question because the choice is risky and cannot be inferred.",
|
| 285 |
+
"final_answer": "Finish with a concise verified result.",
|
| 286 |
+
}
|
| 287 |
+
return prompts[name]
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def one_shot_examples(per_tool: int) -> list[Example]:
|
| 291 |
+
rows: list[Example] = []
|
| 292 |
+
for item in CODEX_TOOLS:
|
| 293 |
+
name = item["name"]
|
| 294 |
+
variants = EXEMPLARS[name]
|
| 295 |
+
for i in range(per_tool):
|
| 296 |
+
args = variants[i % len(variants)]
|
| 297 |
+
rows.append(
|
| 298 |
+
Example(
|
| 299 |
+
id=f"codex-single-{name}-{i:03d}",
|
| 300 |
+
split="train",
|
| 301 |
+
tags=["codex", "single_tool", name],
|
| 302 |
+
messages=[user(prompt_for_tool(name, args)), assistant_tool(name, args), tool(name, result_for_tool(name)), assistant("Done.")],
|
| 303 |
+
)
|
| 304 |
+
)
|
| 305 |
+
return rows
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def workflow_examples(repeat: int) -> list[Example]:
|
| 309 |
+
base = [
|
| 310 |
+
Example(
|
| 311 |
+
id="codex-workflow-search-read-patch-test",
|
| 312 |
+
split="train",
|
| 313 |
+
tags=["codex", "exec_command", "apply_patch", "final_answer"],
|
| 314 |
+
messages=[
|
| 315 |
+
user("Find the parser function that accepts empty names, patch it, and run the focused tests."),
|
| 316 |
+
assistant_tool("update_plan", {"plan": [{"step": "Find parser path", "status": "in_progress"}, {"step": "Patch empty-name handling", "status": "pending"}, {"step": "Run focused tests", "status": "pending"}]}, "call_1"),
|
| 317 |
+
tool("update_plan", "plan updated", "call_1"),
|
| 318 |
+
assistant_tool("exec_command", {"cmd": "rg -n \"normalize_name|parse_identifier\" src tests", "workdir": "/workspace/project", "yield_time_ms": 10000, "max_output_tokens": 12000}, "call_2"),
|
| 319 |
+
tool("exec_command", "src/names.py:5:def normalize_name(name):\ntests/test_names.py:4:def test_empty_name_rejected():", "call_2"),
|
| 320 |
+
assistant_tool("exec_command", {"cmd": "sed -n '1,80p' src/names.py", "workdir": "/workspace/project", "yield_time_ms": 10000, "max_output_tokens": 12000}, "call_3"),
|
| 321 |
+
tool("exec_command", "def normalize_name(name):\n return name.strip()\n", "call_3"),
|
| 322 |
+
assistant_tool("apply_patch", {"patch": "*** Begin Patch\n*** Update File: src/names.py\n@@\n-def normalize_name(name):\n- return name.strip()\n+def normalize_name(name):\n+ normalized = name.strip()\n+ if not normalized:\n+ raise ValueError(\"empty name\")\n+ return normalized\n*** End Patch\n"}, "call_4"),
|
| 323 |
+
tool("apply_patch", "patch applied", "call_4"),
|
| 324 |
+
assistant_tool("exec_command", {"cmd": "uv run pytest tests/test_names.py", "workdir": "/workspace/project", "yield_time_ms": 30000, "max_output_tokens": 20000}, "call_5"),
|
| 325 |
+
tool("exec_command", "1 passed", "call_5"),
|
| 326 |
+
assistant_tool("final_answer", {"content": "Patched `normalize_name` to reject empty names and verified `tests/test_names.py` passes."}, "call_6"),
|
| 327 |
+
],
|
| 328 |
+
),
|
| 329 |
+
Example(
|
| 330 |
+
id="codex-workflow-subagent",
|
| 331 |
+
split="train",
|
| 332 |
+
tags=["codex", "spawn_agent", "wait_agent", "exec_command"],
|
| 333 |
+
messages=[
|
| 334 |
+
user("Use a subagent to inspect docs while you list source files locally."),
|
| 335 |
+
assistant_tool("spawn_agent", {"message": "Inspect docs/*.md for stale Codex CLI examples. Do not edit files.", "fork_context": False}, "call_1"),
|
| 336 |
+
tool("spawn_agent", "spawned agent agent-1", "call_1"),
|
| 337 |
+
assistant_tool("exec_command", {"cmd": "rg --files src", "workdir": "/workspace/project", "yield_time_ms": 10000, "max_output_tokens": 12000}, "call_2"),
|
| 338 |
+
tool("exec_command", "src/app.py\nsrc/cli.py", "call_2"),
|
| 339 |
+
assistant_tool("wait_agent", {"targets": ["agent-1"], "timeout_ms": 300000}, "call_3"),
|
| 340 |
+
tool("wait_agent", "agent-1 completed: README should use codex exec --json for automation examples.", "call_3"),
|
| 341 |
+
assistant("Collected the docs review and source file list."),
|
| 342 |
+
],
|
| 343 |
+
),
|
| 344 |
+
Example(
|
| 345 |
+
id="codex-workflow-docs-skill-web",
|
| 346 |
+
split="train",
|
| 347 |
+
tags=["codex", "use_skill", "web_search", "apply_patch"],
|
| 348 |
+
messages=[
|
| 349 |
+
user("Use official Codex docs to update our automation note."),
|
| 350 |
+
assistant_tool("use_skill", {"name": "openai-docs"}, "call_1"),
|
| 351 |
+
tool("use_skill", "skill instructions loaded", "call_1"),
|
| 352 |
+
assistant_tool("web_search", {"query": "Codex non-interactive mode codex exec --json official docs", "domains": ["developers.openai.com"]}, "call_2"),
|
| 353 |
+
tool("web_search", "[UNTRUSTED WEB RESULTS]\nCodex exec supports --json event streams.", "call_2"),
|
| 354 |
+
assistant_tool("apply_patch", {"patch": "*** Begin Patch\n*** Update File: docs/automation.md\n@@\n-Run Codex manually.\n+Run `codex exec --json` for non-interactive automation.\n*** End Patch\n"}, "call_3"),
|
| 355 |
+
tool("apply_patch", "patch applied", "call_3"),
|
| 356 |
+
assistant("Updated the automation note from official-doc evidence."),
|
| 357 |
+
],
|
| 358 |
+
),
|
| 359 |
+
Example(
|
| 360 |
+
id="codex-workflow-recover-harness-shape",
|
| 361 |
+
split="train",
|
| 362 |
+
tags=["codex", "error_recovery", "exec_command", "apply_patch"],
|
| 363 |
+
messages=[
|
| 364 |
+
user("A previous attempt tried Swival's `run_command` argv array. In Codex, use the exec command tool to run the same test."),
|
| 365 |
+
assistant_tool("exec_command", {"cmd": "python3 tests/check.py", "workdir": "/workspace/project", "yield_time_ms": 10000, "max_output_tokens": 12000}, "call_1"),
|
| 366 |
+
tool("exec_command", "ok", "call_1"),
|
| 367 |
+
user("A previous attempt tried to write files with `cat >`. Use Codex's patch tool for the edit."),
|
| 368 |
+
assistant_tool("apply_patch", {"patch": "*** Begin Patch\n*** Update File: README.md\n@@\n-old\n+new\n*** End Patch\n"}, "call_2"),
|
| 369 |
+
tool("apply_patch", "patch applied", "call_2"),
|
| 370 |
+
assistant("Used Codex's native shell and patch shapes."),
|
| 371 |
+
],
|
| 372 |
+
),
|
| 373 |
+
Example(
|
| 374 |
+
id="codex-workflow-image-plan",
|
| 375 |
+
split="train",
|
| 376 |
+
tags=["codex", "view_image", "update_plan"],
|
| 377 |
+
messages=[
|
| 378 |
+
user("Inspect the screenshot and make a short plan before changing UI files."),
|
| 379 |
+
assistant_tool("view_image", {"path": "screenshots/overlap.png", "detail": "high"}, "call_1"),
|
| 380 |
+
tool("view_image", "The footer overlaps the submit button.", "call_1"),
|
| 381 |
+
assistant_tool("update_plan", {"plan": [{"step": "Inspect layout CSS", "status": "in_progress"}, {"step": "Patch footer spacing", "status": "pending"}, {"step": "Verify screenshot", "status": "pending"}]}, "call_2"),
|
| 382 |
+
tool("update_plan", "plan updated", "call_2"),
|
| 383 |
+
assistant("The screenshot shows a footer overlap; I have a focused plan before editing."),
|
| 384 |
+
],
|
| 385 |
+
),
|
| 386 |
+
Example(
|
| 387 |
+
id="codex-workflow-mcp-user-input",
|
| 388 |
+
split="train",
|
| 389 |
+
tags=["codex", "read_mcp_resource", "request_user_input"],
|
| 390 |
+
messages=[
|
| 391 |
+
user("Use the private design doc if available, but ask before changing public API behavior."),
|
| 392 |
+
assistant_tool("read_mcp_resource", {"server": "docs", "uri": "docs://api-design"}, "call_1"),
|
| 393 |
+
tool("read_mcp_resource", "[UNTRUSTED MCP RESOURCE]\nThe design doc lists two acceptable API shapes.", "call_1"),
|
| 394 |
+
assistant_tool("request_user_input", {"questions": [{"header": "API", "id": "api_shape", "question": "Which API shape should I implement?", "options": [{"label": "Minimal", "description": "Keep the current endpoint and validate input."}, {"label": "New route", "description": "Add a new endpoint from the design doc."}]}]}, "call_2"),
|
| 395 |
+
tool("request_user_input", "user selected Minimal", "call_2"),
|
| 396 |
+
assistant("I will keep the existing endpoint and validate input."),
|
| 397 |
+
],
|
| 398 |
+
),
|
| 399 |
+
]
|
| 400 |
+
rows: list[Example] = []
|
| 401 |
+
for i in range(repeat):
|
| 402 |
+
for ex in base:
|
| 403 |
+
rows.append(Example(id=f"{ex.id}-{i:03d}", split=ex.split, tags=ex.tags, messages=ex.messages))
|
| 404 |
+
return rows
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
def synthetic_examples(count: int, seed: int) -> list[Example]:
|
| 408 |
+
rng = random.Random(seed)
|
| 409 |
+
names = [tool["name"] for tool in CODEX_TOOLS]
|
| 410 |
+
intents = [
|
| 411 |
+
"Use the Codex tool shape, not Swival or opencode.",
|
| 412 |
+
"Choose the smallest useful Codex tool call.",
|
| 413 |
+
"Inspect current state before editing.",
|
| 414 |
+
"Keep the work inside the sandbox and avoid unnecessary escalation.",
|
| 415 |
+
"Use Codex JSONL-friendly actions that the harness can score.",
|
| 416 |
+
]
|
| 417 |
+
rows: list[Example] = []
|
| 418 |
+
for i in range(count):
|
| 419 |
+
name = rng.choice(names)
|
| 420 |
+
args = rng.choice(EXEMPLARS[name])
|
| 421 |
+
rows.append(
|
| 422 |
+
Example(
|
| 423 |
+
id=f"codex-synthetic-{i:05d}-{name}",
|
| 424 |
+
split="train",
|
| 425 |
+
tags=["codex", "synthetic", name],
|
| 426 |
+
messages=[user(f"{rng.choice(intents)} Task {i + 1}."), assistant_tool(name, args), tool(name, result_for_tool(name)), assistant("Done.")],
|
| 427 |
+
)
|
| 428 |
+
)
|
| 429 |
+
return rows
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
def eval_rows() -> list[dict[str, Any]]:
|
| 433 |
+
return [
|
| 434 |
+
{
|
| 435 |
+
"id": "codex-eval-edit",
|
| 436 |
+
"prompt": "In settings.py, change only the second timeout from 5 to 10. Do not change the first timeout.",
|
| 437 |
+
"files": {"settings.py": "timeout = 5\nretries = 2\ntimeout = 5\n"},
|
| 438 |
+
"verify": {"settings.py": "timeout = 5\nretries = 2\ntimeout = 10\n"},
|
| 439 |
+
"expected_events": ["command_execution"],
|
| 440 |
+
},
|
| 441 |
+
{
|
| 442 |
+
"id": "codex-eval-add-file",
|
| 443 |
+
"prompt": "Create docs/notes.md containing a short note that says done.",
|
| 444 |
+
"files": {"README.md": "# Demo\n"},
|
| 445 |
+
"verify_contains": {"docs/notes.md": ["done"]},
|
| 446 |
+
"expected_events": [],
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
"id": "codex-eval-run-test",
|
| 450 |
+
"prompt": "Run `python3 tests/check.py` and report whether it passed.",
|
| 451 |
+
"files": {"tests/check.py": "assert 2 + 3 == 5\nprint('ok')\n"},
|
| 452 |
+
"verify_command": ["python3", "tests/check.py"],
|
| 453 |
+
"expected_events": ["command_execution"],
|
| 454 |
+
},
|
| 455 |
+
{
|
| 456 |
+
"id": "codex-eval-grep-edit",
|
| 457 |
+
"prompt": "Find the TODO in src and remove the TODO marker, leaving the explanatory text.",
|
| 458 |
+
"files": {"src/app.py": "def main():\n # TODO remove fallback\n return True\n"},
|
| 459 |
+
"verify": {"src/app.py": "def main():\n # remove fallback\n return True\n"},
|
| 460 |
+
"expected_events": ["command_execution"],
|
| 461 |
+
},
|
| 462 |
+
{
|
| 463 |
+
"id": "codex-eval-summary-json",
|
| 464 |
+
"prompt": "Read README.md and write summary.json with fields name and kind. Use name Widget and kind tiny router.",
|
| 465 |
+
"files": {"README.md": "# Widget\n\nA tiny router.\n"},
|
| 466 |
+
"verify_json": {"summary.json": {"name": "Widget", "kind": "tiny router"}},
|
| 467 |
+
"expected_events": ["command_execution"],
|
| 468 |
+
},
|
| 469 |
+
]
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
def write_jsonl(path: Path, rows: list[Example]) -> None:
|
| 473 |
+
with path.open("w") as f:
|
| 474 |
+
for row in rows:
|
| 475 |
+
f.write(json.dumps({"id": row.id, "split": row.split, "tags": row.tags, "messages": row.messages}, separators=(",", ":")) + "\n")
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def main() -> int:
|
| 479 |
+
parser = argparse.ArgumentParser()
|
| 480 |
+
parser.add_argument("--per-tool", type=int, default=30)
|
| 481 |
+
parser.add_argument("--workflow-repeat", type=int, default=150)
|
| 482 |
+
parser.add_argument("--synthetic-count", type=int, default=5000)
|
| 483 |
+
parser.add_argument("--seed", type=int, default=20260607)
|
| 484 |
+
parser.add_argument("--clean", action="store_true")
|
| 485 |
+
args = parser.parse_args()
|
| 486 |
+
|
| 487 |
+
DATA_DIR.mkdir(exist_ok=True)
|
| 488 |
+
TMP_DIR.mkdir(exist_ok=True)
|
| 489 |
+
if args.clean:
|
| 490 |
+
for path in [
|
| 491 |
+
DATA_DIR / "codex_tool_calling_train.jsonl",
|
| 492 |
+
DATA_DIR / "codex_tool_calling_eval.jsonl",
|
| 493 |
+
DATA_DIR / "codex_tool_inventory.json",
|
| 494 |
+
]:
|
| 495 |
+
if path.exists():
|
| 496 |
+
path.unlink()
|
| 497 |
+
|
| 498 |
+
rows = one_shot_examples(args.per_tool)
|
| 499 |
+
rows.extend(workflow_examples(args.workflow_repeat))
|
| 500 |
+
rows.extend(synthetic_examples(args.synthetic_count, args.seed))
|
| 501 |
+
write_jsonl(DATA_DIR / "codex_tool_calling_train.jsonl", rows)
|
| 502 |
+
|
| 503 |
+
with (DATA_DIR / "codex_tool_inventory.json").open("w") as f:
|
| 504 |
+
json.dump(
|
| 505 |
+
{
|
| 506 |
+
"source": "Codex CLI help, official Codex manual, current session tool surfaces, and codex exec JSONL event stream",
|
| 507 |
+
"harness": "env OMLX_API_KEY=omlx codex -a never exec --json --ephemeral --skip-git-repo-check --sandbox workspace-write -c model_provider=\"omlx\" -m qwen35",
|
| 508 |
+
"config": str(CONFIG_PATH),
|
| 509 |
+
"tools": CODEX_TOOLS,
|
| 510 |
+
},
|
| 511 |
+
f,
|
| 512 |
+
indent=2,
|
| 513 |
+
)
|
| 514 |
+
f.write("\n")
|
| 515 |
+
|
| 516 |
+
with (DATA_DIR / "codex_tool_calling_eval.jsonl").open("w") as f:
|
| 517 |
+
for row in eval_rows():
|
| 518 |
+
f.write(json.dumps(row, separators=(",", ":")) + "\n")
|
| 519 |
+
|
| 520 |
+
print(f"wrote {len(rows)} codex training examples")
|
| 521 |
+
print(f"wrote {len(eval_rows())} codex eval tasks")
|
| 522 |
+
print(f"covered {len(CODEX_TOOLS)} codex tool surfaces")
|
| 523 |
+
return 0
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
if __name__ == "__main__":
|
| 527 |
+
raise SystemExit(main())
|
scripts/generate_opencode_dataset.py
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import random
|
| 7 |
+
import shutil
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
DATA_DIR = ROOT / "data"
|
| 15 |
+
TMP_DIR = ROOT / "tmp"
|
| 16 |
+
CONFIG_PATH = ROOT / "configs" / "opencode-qwen35.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
OPENCODE_TOOLS: list[dict[str, Any]] = [
|
| 20 |
+
{
|
| 21 |
+
"name": "bash",
|
| 22 |
+
"description": "Execute shell commands in the project environment.",
|
| 23 |
+
"required": ["command"],
|
| 24 |
+
"properties": ["command", "description", "timeout"],
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "read",
|
| 28 |
+
"description": "Read file contents, optionally with a line range.",
|
| 29 |
+
"required": ["filePath"],
|
| 30 |
+
"properties": ["filePath", "offset", "limit"],
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"name": "edit",
|
| 34 |
+
"description": "Modify an existing file using exact string replacement.",
|
| 35 |
+
"required": ["filePath", "oldString", "newString"],
|
| 36 |
+
"properties": ["filePath", "oldString", "newString", "replaceAll"],
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"name": "write",
|
| 40 |
+
"description": "Create a new file or overwrite an existing one.",
|
| 41 |
+
"required": ["filePath", "content"],
|
| 42 |
+
"properties": ["filePath", "content"],
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "grep",
|
| 46 |
+
"description": "Search file contents with a regular expression.",
|
| 47 |
+
"required": ["pattern"],
|
| 48 |
+
"properties": ["pattern", "path", "include"],
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"name": "glob",
|
| 52 |
+
"description": "Find files by glob pattern.",
|
| 53 |
+
"required": ["pattern"],
|
| 54 |
+
"properties": ["pattern", "path"],
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"name": "lsp",
|
| 58 |
+
"description": "Use language-server code intelligence.",
|
| 59 |
+
"required": ["operation"],
|
| 60 |
+
"properties": ["operation", "filePath", "line", "character", "symbol"],
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"name": "apply_patch",
|
| 64 |
+
"description": "Apply a patch with paths embedded in patch marker lines.",
|
| 65 |
+
"required": ["patchText"],
|
| 66 |
+
"properties": ["patchText"],
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"name": "skill",
|
| 70 |
+
"description": "Load a SKILL.md instruction file.",
|
| 71 |
+
"required": ["name"],
|
| 72 |
+
"properties": ["name"],
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "todowrite",
|
| 76 |
+
"description": "Create or update the coding-session todo list.",
|
| 77 |
+
"required": ["todos"],
|
| 78 |
+
"properties": ["todos"],
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"name": "webfetch",
|
| 82 |
+
"description": "Fetch and read a web page.",
|
| 83 |
+
"required": ["url"],
|
| 84 |
+
"properties": ["url", "prompt"],
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"name": "websearch",
|
| 88 |
+
"description": "Search the web when enabled by provider or EXA config.",
|
| 89 |
+
"required": ["query"],
|
| 90 |
+
"properties": ["query"],
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"name": "task",
|
| 94 |
+
"description": "Run a subtask with another agent.",
|
| 95 |
+
"required": ["description", "prompt"],
|
| 96 |
+
"properties": ["description", "prompt", "subagent_type"],
|
| 97 |
+
},
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
EXEMPLARS: dict[str, list[dict[str, Any]]] = {
|
| 102 |
+
"bash": [
|
| 103 |
+
{"command": "python3 -m pytest tests/test_parser.py", "description": "Run parser tests", "timeout": 120},
|
| 104 |
+
{"command": "rg -n 'TODO|FIXME' src", "description": "Find TODO markers"},
|
| 105 |
+
{"command": "npm run dev", "description": "Start the dev server", "timeout": 5},
|
| 106 |
+
],
|
| 107 |
+
"read": [
|
| 108 |
+
{"filePath": "src/app.py"},
|
| 109 |
+
{"filePath": "src/app.py", "offset": 80, "limit": 60},
|
| 110 |
+
{"filePath": "README.md", "limit": 120},
|
| 111 |
+
],
|
| 112 |
+
"edit": [
|
| 113 |
+
{"filePath": "src/app.py", "oldString": "return False\n", "newString": "return True\n"},
|
| 114 |
+
{"filePath": "README.md", "oldString": "teh", "newString": "the", "replaceAll": True},
|
| 115 |
+
],
|
| 116 |
+
"write": [
|
| 117 |
+
{"filePath": "docs/summary.md", "content": "# Summary\n\nProject: demo\n"},
|
| 118 |
+
{"filePath": "tmp/generated.txt", "content": "generated\n"},
|
| 119 |
+
],
|
| 120 |
+
"grep": [
|
| 121 |
+
{"pattern": "TODO|FIXME", "path": "src"},
|
| 122 |
+
{"pattern": "authorization", "path": "src", "include": "**/*.py"},
|
| 123 |
+
],
|
| 124 |
+
"glob": [
|
| 125 |
+
{"pattern": "**/*.py"},
|
| 126 |
+
{"pattern": "docs/**/*.md", "path": "."},
|
| 127 |
+
],
|
| 128 |
+
"lsp": [
|
| 129 |
+
{"operation": "documentSymbol", "filePath": "src/app.py"},
|
| 130 |
+
{"operation": "findReferences", "filePath": "src/app.py", "line": 42, "character": 12},
|
| 131 |
+
{"operation": "workspaceSymbol", "symbol": "Session"},
|
| 132 |
+
],
|
| 133 |
+
"apply_patch": [
|
| 134 |
+
{"patchText": "*** Begin Patch\n*** Update File: src/app.py\n@@\n-return False\n+return True\n*** End Patch\n"},
|
| 135 |
+
{"patchText": "*** Begin Patch\n*** Add File: docs/notes.md\n+# Notes\n+\n+Done.\n*** End Patch\n"},
|
| 136 |
+
],
|
| 137 |
+
"skill": [
|
| 138 |
+
{"name": "frontend-design"},
|
| 139 |
+
{"name": "github:gh-fix-ci"},
|
| 140 |
+
],
|
| 141 |
+
"todowrite": [
|
| 142 |
+
{"todos": [{"content": "inspect parser", "status": "pending"}, {"content": "patch failing case", "status": "pending"}, {"content": "run focused tests", "status": "pending"}]},
|
| 143 |
+
{"todos": [{"content": "inspect parser", "status": "completed"}, {"content": "patch failing case", "status": "in_progress"}]},
|
| 144 |
+
],
|
| 145 |
+
"webfetch": [
|
| 146 |
+
{"url": "https://example.com/api-reference", "prompt": "Summarize the endpoint shape relevant to parser errors."},
|
| 147 |
+
{"url": "https://example.com/status.txt"},
|
| 148 |
+
],
|
| 149 |
+
"websearch": [
|
| 150 |
+
{"query": "opencode OpenAI compatible provider baseURL config"},
|
| 151 |
+
{"query": "Python argparse subcommands examples"},
|
| 152 |
+
],
|
| 153 |
+
"task": [
|
| 154 |
+
{"description": "Inspect tests", "prompt": "Inspect tests/test_parser.py and report the expected empty-name behavior. Do not edit files.", "subagent_type": "general"},
|
| 155 |
+
{"description": "Review docs", "prompt": "Review docs/usage.md for stale opencode command examples. Return paths and replacements only."},
|
| 156 |
+
],
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
@dataclass(frozen=True)
|
| 161 |
+
class Example:
|
| 162 |
+
id: str
|
| 163 |
+
split: str
|
| 164 |
+
tags: list[str]
|
| 165 |
+
messages: list[dict[str, Any]]
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def user(text: str) -> dict[str, Any]:
|
| 169 |
+
return {"role": "user", "content": text}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def assistant(text: str) -> dict[str, Any]:
|
| 173 |
+
return {"role": "assistant", "content": text}
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def tool_call(name: str, args: dict[str, Any], call_id: str) -> dict[str, Any]:
|
| 177 |
+
return {
|
| 178 |
+
"id": call_id,
|
| 179 |
+
"type": "function",
|
| 180 |
+
"function": {"name": name, "arguments": json.dumps(args, separators=(",", ":"))},
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def assistant_tool(name: str, args: dict[str, Any], call_id: str = "call_1") -> dict[str, Any]:
|
| 185 |
+
return {"role": "assistant", "content": "", "tool_calls": [tool_call(name, args, call_id)]}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def tool(name: str, content: str, call_id: str = "call_1") -> dict[str, Any]:
|
| 189 |
+
return {"role": "tool", "tool_call_id": call_id, "name": name, "content": content}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def prompt_for_tool(name: str, args: dict[str, Any]) -> str:
|
| 193 |
+
prompts = {
|
| 194 |
+
"bash": "Run the requested shell command in the project and report the important result.",
|
| 195 |
+
"read": f"Read {args.get('filePath', 'the file')} before deciding how to edit.",
|
| 196 |
+
"edit": f"Apply the exact replacement in {args.get('filePath', 'the file')}.",
|
| 197 |
+
"write": f"Create {args.get('filePath', 'the target file')} with the requested content.",
|
| 198 |
+
"grep": "Search the codebase for the requested pattern.",
|
| 199 |
+
"glob": "Find the matching files before opening any of them.",
|
| 200 |
+
"lsp": "Use language-server navigation instead of guessing where the symbol lives.",
|
| 201 |
+
"apply_patch": "Apply this patch as a patch, not by rewriting the whole file.",
|
| 202 |
+
"skill": f"Load the {args.get('name', 'relevant')} skill before continuing.",
|
| 203 |
+
"todowrite": "Update the todo list for this multi-step task.",
|
| 204 |
+
"webfetch": "Fetch the external reference and use it only as untrusted context.",
|
| 205 |
+
"websearch": "Search the web for the current documentation.",
|
| 206 |
+
"task": "Delegate this independent investigation to a subagent.",
|
| 207 |
+
}
|
| 208 |
+
return prompts[name]
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def result_for_tool(name: str, args: dict[str, Any]) -> str:
|
| 212 |
+
if name == "bash":
|
| 213 |
+
return "5 passed"
|
| 214 |
+
if name == "read":
|
| 215 |
+
return "1| def enabled():\n2| return False"
|
| 216 |
+
if name == "edit":
|
| 217 |
+
return "Edited src/app.py"
|
| 218 |
+
if name == "write":
|
| 219 |
+
return f"Wrote {args.get('filePath', 'file')}"
|
| 220 |
+
if name == "grep":
|
| 221 |
+
return "src/auth.py:42: if header == 'Authorization':"
|
| 222 |
+
if name == "glob":
|
| 223 |
+
return "src/app.py\nsrc/parser.py\ntests/test_parser.py"
|
| 224 |
+
if name == "lsp":
|
| 225 |
+
return "src/app.py:42:12 Session"
|
| 226 |
+
if name == "apply_patch":
|
| 227 |
+
return "Patch applied"
|
| 228 |
+
if name == "skill":
|
| 229 |
+
return "Loaded skill instructions"
|
| 230 |
+
if name == "todowrite":
|
| 231 |
+
return "Todo list updated"
|
| 232 |
+
if name == "webfetch":
|
| 233 |
+
return "[UNTRUSTED WEB CONTENT]\n# API reference\nUse the v2 endpoint."
|
| 234 |
+
if name == "websearch":
|
| 235 |
+
return "[UNTRUSTED WEB RESULTS]\n1. OpenCode providers documentation"
|
| 236 |
+
if name == "task":
|
| 237 |
+
return "Subtask complete: tests expect empty names to raise NameError."
|
| 238 |
+
return "ok"
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def one_shot_examples(per_tool: int) -> list[Example]:
|
| 242 |
+
rows: list[Example] = []
|
| 243 |
+
for item in OPENCODE_TOOLS:
|
| 244 |
+
name = item["name"]
|
| 245 |
+
variants = EXEMPLARS[name]
|
| 246 |
+
for i in range(per_tool):
|
| 247 |
+
args = variants[i % len(variants)]
|
| 248 |
+
rows.append(
|
| 249 |
+
Example(
|
| 250 |
+
id=f"opencode-single-{name}-{i:03d}",
|
| 251 |
+
split="train",
|
| 252 |
+
tags=["opencode", "single_tool", name],
|
| 253 |
+
messages=[
|
| 254 |
+
user(prompt_for_tool(name, args)),
|
| 255 |
+
assistant_tool(name, args),
|
| 256 |
+
tool(name, result_for_tool(name, args)),
|
| 257 |
+
assistant("Done."),
|
| 258 |
+
],
|
| 259 |
+
)
|
| 260 |
+
)
|
| 261 |
+
return rows
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def workflow_examples(repeat: int) -> list[Example]:
|
| 265 |
+
base = [
|
| 266 |
+
Example(
|
| 267 |
+
id="opencode-workflow-glob-read-edit-bash",
|
| 268 |
+
split="train",
|
| 269 |
+
tags=["opencode", "glob", "read", "edit", "bash"],
|
| 270 |
+
messages=[
|
| 271 |
+
user("Find the parser implementation, reject empty identifiers, and run the focused tests."),
|
| 272 |
+
assistant_tool("glob", {"pattern": "**/*parser*.py"}, "call_1"),
|
| 273 |
+
tool("glob", "src/parser.py\ntests/test_parser.py", "call_1"),
|
| 274 |
+
assistant_tool("read", {"filePath": "src/parser.py", "offset": 1, "limit": 120}, "call_2"),
|
| 275 |
+
tool("read", "80| def parse_identifier(tok):\n81| if tok.value is None:\n82| raise ParseError('missing')\n83| return tok.value", "call_2"),
|
| 276 |
+
assistant_tool("edit", {"filePath": "src/parser.py", "oldString": " if tok.value is None:\n raise ParseError('missing')\n return tok.value\n", "newString": " if not tok.value:\n raise ParseError('missing')\n return tok.value\n"}, "call_3"),
|
| 277 |
+
tool("edit", "Edited src/parser.py", "call_3"),
|
| 278 |
+
assistant_tool("bash", {"command": "python3 -m pytest tests/test_parser.py", "description": "Run focused parser tests", "timeout": 120}, "call_4"),
|
| 279 |
+
tool("bash", "6 passed", "call_4"),
|
| 280 |
+
assistant("Empty identifiers are rejected and the parser tests pass."),
|
| 281 |
+
],
|
| 282 |
+
),
|
| 283 |
+
Example(
|
| 284 |
+
id="opencode-workflow-grep-read-apply-patch",
|
| 285 |
+
split="train",
|
| 286 |
+
tags=["opencode", "grep", "read", "apply_patch"],
|
| 287 |
+
messages=[
|
| 288 |
+
user("Find the duplicated timeout constant and patch both occurrences."),
|
| 289 |
+
assistant_tool("grep", {"pattern": "TIMEOUT = 5", "path": "src"}, "call_1"),
|
| 290 |
+
tool("grep", "src/client.py:4:TIMEOUT = 5\nsrc/server.py:7:TIMEOUT = 5", "call_1"),
|
| 291 |
+
assistant_tool("read", {"filePath": "src/client.py", "limit": 40}, "call_2"),
|
| 292 |
+
tool("read", "1| TIMEOUT = 5\n2| def connect(): pass", "call_2"),
|
| 293 |
+
assistant_tool("apply_patch", {"patchText": "*** Begin Patch\n*** Update File: src/client.py\n@@\n-TIMEOUT = 5\n+TIMEOUT = 10\n*** Update File: src/server.py\n@@\n-TIMEOUT = 5\n+TIMEOUT = 10\n*** End Patch\n"}, "call_3"),
|
| 294 |
+
tool("apply_patch", "Patch applied", "call_3"),
|
| 295 |
+
assistant("Updated both timeout constants with one patch."),
|
| 296 |
+
],
|
| 297 |
+
),
|
| 298 |
+
Example(
|
| 299 |
+
id="opencode-workflow-todo-task-collect",
|
| 300 |
+
split="train",
|
| 301 |
+
tags=["opencode", "todowrite", "task"],
|
| 302 |
+
messages=[
|
| 303 |
+
user("Track the work and ask a subagent to inspect docs for stale commands."),
|
| 304 |
+
assistant_tool("todowrite", {"todos": [{"content": "inspect docs", "status": "pending"}, {"content": "update examples", "status": "pending"}, {"content": "run checks", "status": "pending"}]}, "call_1"),
|
| 305 |
+
tool("todowrite", "Todo list updated", "call_1"),
|
| 306 |
+
assistant_tool("task", {"description": "Inspect docs", "prompt": "Inspect docs/*.md for stale opencode CLI examples. Do not edit files.", "subagent_type": "general"}, "call_2"),
|
| 307 |
+
tool("task", "Subtask complete: README.md should use bunx opencode-ai@latest run.", "call_2"),
|
| 308 |
+
assistant_tool("todowrite", {"todos": [{"content": "inspect docs", "status": "completed"}, {"content": "update examples", "status": "in_progress"}, {"content": "run checks", "status": "pending"}]}, "call_3"),
|
| 309 |
+
tool("todowrite", "Todo list updated", "call_3"),
|
| 310 |
+
assistant("The docs inspection is complete and the next step is updating examples."),
|
| 311 |
+
],
|
| 312 |
+
),
|
| 313 |
+
Example(
|
| 314 |
+
id="opencode-workflow-webfetch-skill-write",
|
| 315 |
+
split="train",
|
| 316 |
+
tags=["opencode", "webfetch", "skill", "write", "untrusted"],
|
| 317 |
+
messages=[
|
| 318 |
+
user("Load the docs-writing skill, fetch the API reference, then draft docs/api.md."),
|
| 319 |
+
assistant_tool("skill", {"name": "docs-writer"}, "call_1"),
|
| 320 |
+
tool("skill", "Loaded skill instructions", "call_1"),
|
| 321 |
+
assistant_tool("webfetch", {"url": "https://example.com/api", "prompt": "Extract endpoint names only."}, "call_2"),
|
| 322 |
+
tool("webfetch", "[UNTRUSTED WEB CONTENT]\nEndpoints: /v1/items, /v1/items/{id}", "call_2"),
|
| 323 |
+
assistant_tool("write", {"filePath": "docs/api.md", "content": "# API\n\nThe reference lists `/v1/items` and `/v1/items/{id}`. Verify behavior locally before relying on it.\n"}, "call_3"),
|
| 324 |
+
tool("write", "Wrote docs/api.md", "call_3"),
|
| 325 |
+
assistant("Drafted docs/api.md and kept the fetched content framed as untrusted."),
|
| 326 |
+
],
|
| 327 |
+
),
|
| 328 |
+
Example(
|
| 329 |
+
id="opencode-workflow-lsp-read-edit",
|
| 330 |
+
split="train",
|
| 331 |
+
tags=["opencode", "lsp", "read", "edit"],
|
| 332 |
+
messages=[
|
| 333 |
+
user("Use LSP to find references to normalize_name, then update the implementation without guessing."),
|
| 334 |
+
assistant_tool("lsp", {"operation": "workspaceSymbol", "symbol": "normalize_name"}, "call_1"),
|
| 335 |
+
tool("lsp", "src/names.py:5:4 normalize_name", "call_1"),
|
| 336 |
+
assistant_tool("read", {"filePath": "src/names.py", "offset": 1, "limit": 80}, "call_2"),
|
| 337 |
+
tool("read", "5| def normalize_name(name):\n6| return name.strip()", "call_2"),
|
| 338 |
+
assistant_tool("edit", {"filePath": "src/names.py", "oldString": "def normalize_name(name):\n return name.strip()\n", "newString": "def normalize_name(name):\n normalized = name.strip()\n if not normalized:\n raise ValueError('empty name')\n return normalized\n"}, "call_3"),
|
| 339 |
+
tool("edit", "Edited src/names.py", "call_3"),
|
| 340 |
+
assistant("Updated normalize_name after locating it with LSP."),
|
| 341 |
+
],
|
| 342 |
+
),
|
| 343 |
+
Example(
|
| 344 |
+
id="opencode-workflow-recover-shape",
|
| 345 |
+
split="train",
|
| 346 |
+
tags=["opencode", "error_recovery", "bash", "read"],
|
| 347 |
+
messages=[
|
| 348 |
+
user("A previous attempt used Swival-style `run_command` with an argv array and opencode rejected it. Run the same test in opencode's bash tool."),
|
| 349 |
+
assistant_tool("bash", {"command": "python3 -m pytest tests/test_math.py", "description": "Run math tests", "timeout": 120}, "call_1"),
|
| 350 |
+
tool("bash", "1 passed", "call_1"),
|
| 351 |
+
user("A previous attempt used `file_path`; opencode expects camelCase for its read tool. Read src/mathlib.py."),
|
| 352 |
+
assistant_tool("read", {"filePath": "src/mathlib.py", "limit": 80}, "call_2"),
|
| 353 |
+
tool("read", "1| def add(a, b):\n2| return a + b", "call_2"),
|
| 354 |
+
assistant("The tests passed and I read the file using opencode's `filePath` argument shape."),
|
| 355 |
+
],
|
| 356 |
+
),
|
| 357 |
+
]
|
| 358 |
+
rows: list[Example] = []
|
| 359 |
+
for i in range(repeat):
|
| 360 |
+
for ex in base:
|
| 361 |
+
rows.append(Example(id=f"{ex.id}-{i:03d}", split=ex.split, tags=ex.tags, messages=ex.messages))
|
| 362 |
+
return rows
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def synthetic_examples(count: int, seed: int) -> list[Example]:
|
| 366 |
+
rng = random.Random(seed)
|
| 367 |
+
names = [tool["name"] for tool in OPENCODE_TOOLS]
|
| 368 |
+
intents = [
|
| 369 |
+
"Choose the exact opencode tool for this step.",
|
| 370 |
+
"Use opencode's native argument shape, not Swival's.",
|
| 371 |
+
"Make the smallest useful tool call.",
|
| 372 |
+
"Recover by using the real opencode tool name and arguments.",
|
| 373 |
+
"Inspect first, then act with the appropriate opencode tool.",
|
| 374 |
+
]
|
| 375 |
+
rows: list[Example] = []
|
| 376 |
+
for i in range(count):
|
| 377 |
+
name = rng.choice(names)
|
| 378 |
+
args = rng.choice(EXEMPLARS[name])
|
| 379 |
+
rows.append(
|
| 380 |
+
Example(
|
| 381 |
+
id=f"opencode-synthetic-{i:05d}-{name}",
|
| 382 |
+
split="train",
|
| 383 |
+
tags=["opencode", "synthetic", name],
|
| 384 |
+
messages=[
|
| 385 |
+
user(f"{rng.choice(intents)} Task {i + 1}."),
|
| 386 |
+
assistant_tool(name, args),
|
| 387 |
+
tool(name, result_for_tool(name, args)),
|
| 388 |
+
assistant("Done."),
|
| 389 |
+
],
|
| 390 |
+
)
|
| 391 |
+
)
|
| 392 |
+
return rows
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def eval_rows() -> list[dict[str, Any]]:
|
| 396 |
+
return [
|
| 397 |
+
{
|
| 398 |
+
"id": "opencode-eval-edit",
|
| 399 |
+
"prompt": "In settings.py, change only the second timeout from 5 to 10.",
|
| 400 |
+
"files": {"settings.py": "timeout = 5\nretries = 2\ntimeout = 5\n"},
|
| 401 |
+
"verify": {"settings.py": "timeout = 5\nretries = 2\ntimeout = 10\n"},
|
| 402 |
+
"expected_tools": ["read", "edit"],
|
| 403 |
+
},
|
| 404 |
+
{
|
| 405 |
+
"id": "opencode-eval-patch",
|
| 406 |
+
"prompt": "Use a patch to add docs/notes.md containing a short note that says done.",
|
| 407 |
+
"files": {"README.md": "# Demo\n"},
|
| 408 |
+
"verify_contains": {"docs/notes.md": ["done"]},
|
| 409 |
+
"expected_tools": ["apply_patch"],
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"id": "opencode-eval-bash",
|
| 413 |
+
"prompt": "Run `python3 tests/check.py` and report whether it passed.",
|
| 414 |
+
"files": {"tests/check.py": "assert 2 + 3 == 5\nprint('ok')\n"},
|
| 415 |
+
"verify_command": ["python3", "tests/check.py"],
|
| 416 |
+
"expected_tools": ["bash"],
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
"id": "opencode-eval-write",
|
| 420 |
+
"prompt": "Read README.md and create docs/summary.md with the project name Widget and the phrase tiny router.",
|
| 421 |
+
"files": {"README.md": "# Widget\n\nA tiny router.\n"},
|
| 422 |
+
"verify_contains": {"docs/summary.md": ["Widget", "tiny router"]},
|
| 423 |
+
"expected_tools": ["read", "write"],
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"id": "opencode-eval-grep",
|
| 427 |
+
"prompt": "Find the TODO in src and remove the TODO marker, leaving the explanatory text.",
|
| 428 |
+
"files": {"src/app.py": "def main():\n # TODO remove fallback\n return True\n"},
|
| 429 |
+
"verify": {"src/app.py": "def main():\n # remove fallback\n return True\n"},
|
| 430 |
+
"expected_tools": ["grep", "read", "edit"],
|
| 431 |
+
},
|
| 432 |
+
]
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
def write_jsonl(path: Path, rows: list[Example]) -> None:
|
| 436 |
+
with path.open("w") as f:
|
| 437 |
+
for row in rows:
|
| 438 |
+
f.write(json.dumps({"id": row.id, "split": row.split, "tags": row.tags, "messages": row.messages}, separators=(",", ":")) + "\n")
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def main() -> int:
|
| 442 |
+
parser = argparse.ArgumentParser()
|
| 443 |
+
parser.add_argument("--per-tool", type=int, default=30)
|
| 444 |
+
parser.add_argument("--workflow-repeat", type=int, default=150)
|
| 445 |
+
parser.add_argument("--synthetic-count", type=int, default=5000)
|
| 446 |
+
parser.add_argument("--seed", type=int, default=20260607)
|
| 447 |
+
parser.add_argument("--clean", action="store_true")
|
| 448 |
+
args = parser.parse_args()
|
| 449 |
+
|
| 450 |
+
DATA_DIR.mkdir(exist_ok=True)
|
| 451 |
+
TMP_DIR.mkdir(exist_ok=True)
|
| 452 |
+
if args.clean:
|
| 453 |
+
for path in [
|
| 454 |
+
DATA_DIR / "opencode_tool_calling_train.jsonl",
|
| 455 |
+
DATA_DIR / "opencode_tool_calling_eval.jsonl",
|
| 456 |
+
DATA_DIR / "opencode_tool_inventory.json",
|
| 457 |
+
]:
|
| 458 |
+
if path.exists():
|
| 459 |
+
path.unlink()
|
| 460 |
+
|
| 461 |
+
rows = one_shot_examples(args.per_tool)
|
| 462 |
+
rows.extend(workflow_examples(args.workflow_repeat))
|
| 463 |
+
rows.extend(synthetic_examples(args.synthetic_count, args.seed))
|
| 464 |
+
write_jsonl(DATA_DIR / "opencode_tool_calling_train.jsonl", rows)
|
| 465 |
+
|
| 466 |
+
with (DATA_DIR / "opencode_tool_inventory.json").open("w") as f:
|
| 467 |
+
json.dump(
|
| 468 |
+
{
|
| 469 |
+
"source": "opencode docs plus local @opencode-ai/plugin SDK types",
|
| 470 |
+
"harness": "bunx opencode-ai@latest run --model qwen35/qwen35 --format json",
|
| 471 |
+
"config": str(CONFIG_PATH),
|
| 472 |
+
"tools": OPENCODE_TOOLS,
|
| 473 |
+
},
|
| 474 |
+
f,
|
| 475 |
+
indent=2,
|
| 476 |
+
)
|
| 477 |
+
f.write("\n")
|
| 478 |
+
|
| 479 |
+
with (DATA_DIR / "opencode_tool_calling_eval.jsonl").open("w") as f:
|
| 480 |
+
for row in eval_rows():
|
| 481 |
+
f.write(json.dumps(row, separators=(",", ":")) + "\n")
|
| 482 |
+
|
| 483 |
+
print(f"wrote {len(rows)} opencode training examples")
|
| 484 |
+
print(f"wrote {len(eval_rows())} opencode eval tasks")
|
| 485 |
+
print(f"covered {len(OPENCODE_TOOLS)} opencode tools")
|
| 486 |
+
return 0
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
if __name__ == "__main__":
|
| 490 |
+
raise SystemExit(main())
|
scripts/generate_swival_dataset.py
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import ast
|
| 6 |
+
import json
|
| 7 |
+
import random
|
| 8 |
+
import shutil
|
| 9 |
+
from dataclasses import dataclass
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 15 |
+
DATA_DIR = ROOT / "data"
|
| 16 |
+
TMP_DIR = ROOT / "tmp"
|
| 17 |
+
SWIVAL_ROOT = Path("/Users/j/src/swival")
|
| 18 |
+
SWIVAL_TOOLS = SWIVAL_ROOT / "swival" / "tools.py"
|
| 19 |
+
PYTEST_SHIM = """import importlib.util
|
| 20 |
+
import pathlib
|
| 21 |
+
import sys
|
| 22 |
+
|
| 23 |
+
failed = 0
|
| 24 |
+
for raw in sys.argv[1:]:
|
| 25 |
+
path = pathlib.Path(raw)
|
| 26 |
+
spec = importlib.util.spec_from_file_location(path.stem, path)
|
| 27 |
+
mod = importlib.util.module_from_spec(spec)
|
| 28 |
+
spec.loader.exec_module(mod)
|
| 29 |
+
for name in dir(mod):
|
| 30 |
+
if name.startswith("test_"):
|
| 31 |
+
try:
|
| 32 |
+
getattr(mod, name)()
|
| 33 |
+
except Exception as exc:
|
| 34 |
+
failed = 1
|
| 35 |
+
print(f"FAILED {raw}::{name}: {exc}")
|
| 36 |
+
if failed:
|
| 37 |
+
sys.exit(1)
|
| 38 |
+
print("passed")
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
TOOL_EXEMPLARS: dict[str, list[dict[str, Any]]] = {
|
| 43 |
+
"read_file": [
|
| 44 |
+
{"file_path": "src/app.py"},
|
| 45 |
+
{"file_path": "logs/server.log", "tail_lines": 80},
|
| 46 |
+
{"file_path": "src/app.py", "offset": 201, "limit": 80},
|
| 47 |
+
{"file_path": "."},
|
| 48 |
+
],
|
| 49 |
+
"read_multiple_files": [
|
| 50 |
+
{"files": [{"file_path": "pyproject.toml"}, {"file_path": "src/app.py", "offset": 40, "limit": 80}]},
|
| 51 |
+
{"files": [{"file_path": "README.md"}, {"file_path": "tests/test_app.py", "tail_lines": 120}]},
|
| 52 |
+
],
|
| 53 |
+
"write_file": [
|
| 54 |
+
{"file_path": "notes/summary.md", "content": "# Summary\n\nDone.\n"},
|
| 55 |
+
{"file_path": "src/config.py", "move_from": "tmp/generated_config.py"},
|
| 56 |
+
],
|
| 57 |
+
"edit_file": [
|
| 58 |
+
{"file_path": "src/app.py", "old_string": "return False\n", "new_string": "return True\n", "line_number": 42},
|
| 59 |
+
{"file_path": "README.md", "old_string": "teh", "new_string": "the", "replace_all": True},
|
| 60 |
+
{"file_path": "src/app.py", "old_string": "timeout = 5\n", "new_string": "timeout = 10\n", "checksum": "1a2b3c4d"},
|
| 61 |
+
],
|
| 62 |
+
"list_files": [
|
| 63 |
+
{"pattern": "**/*.py"},
|
| 64 |
+
{"pattern": "*.md", "path": "docs"},
|
| 65 |
+
],
|
| 66 |
+
"grep": [
|
| 67 |
+
{"pattern": "TODO|FIXME", "path": ".", "include": "**/*.py"},
|
| 68 |
+
{"pattern": "authorization", "path": "src", "include": "**/*.py", "case_insensitive": True, "context_lines": 2},
|
| 69 |
+
],
|
| 70 |
+
"think": [
|
| 71 |
+
{"thought": "The failure is probably in the parsing layer, so inspect callers before editing.", "thought_number": 1, "total_thoughts": 3},
|
| 72 |
+
{"thought": "The first plan missed the generated file path; revise the target to src/generated.py.", "mode": "revision", "revises_thought": 1},
|
| 73 |
+
{"thought": "Try a narrower edit that keeps the public API unchanged.", "mode": "branch", "branch_from_thought": 2, "branch_id": "minimal-fix"},
|
| 74 |
+
],
|
| 75 |
+
"todo": [
|
| 76 |
+
{"action": "add", "tasks": ["inspect parser", "patch failing case", "run focused tests"]},
|
| 77 |
+
{"action": "done", "tasks": "inspect parser"},
|
| 78 |
+
{"action": "list"},
|
| 79 |
+
{"action": "clear"},
|
| 80 |
+
],
|
| 81 |
+
"view_image": [
|
| 82 |
+
{"image_path": "screenshots/failure.png", "question": "Which UI element overlaps the submit button?"},
|
| 83 |
+
{"image_path": "assets/logo.webp"},
|
| 84 |
+
],
|
| 85 |
+
"delete_file": [
|
| 86 |
+
{"file_path": "src/old_module.py"},
|
| 87 |
+
],
|
| 88 |
+
"fetch_url": [
|
| 89 |
+
{"url": "https://example.com/api-reference", "format": "markdown", "timeout": 20},
|
| 90 |
+
{"url": "https://example.com/status.txt", "format": "text"},
|
| 91 |
+
],
|
| 92 |
+
"snapshot": [
|
| 93 |
+
{"action": "save", "label": "parser investigation"},
|
| 94 |
+
{"action": "status"},
|
| 95 |
+
{"action": "restore", "summary": "Parser bug is in src/parser.py:88. The tokenizer accepts empty identifiers; fix by rejecting zero-length names and run tests/test_parser.py.", "force": True},
|
| 96 |
+
{"action": "cancel"},
|
| 97 |
+
],
|
| 98 |
+
"outline": [
|
| 99 |
+
{"file_path": "src/app.py", "depth": 2},
|
| 100 |
+
{"file_path": "src", "depth": 1},
|
| 101 |
+
{"files": [{"file_path": "src/app.py", "depth": 2}, {"file_path": "src/parser.py", "depth": 3}]},
|
| 102 |
+
],
|
| 103 |
+
"use_skill": [
|
| 104 |
+
{"name": "frontend-design"},
|
| 105 |
+
{"name": "github:gh-fix-ci"},
|
| 106 |
+
],
|
| 107 |
+
"run_metaskill": [
|
| 108 |
+
{"name": "repo_survey", "input": {"task": "find the CLI entrypoint"}, "max_ask_calls": 3},
|
| 109 |
+
{"name": "focused_review", "input": {"path": "src/auth.py", "question": "look for token validation bugs"}, "max_command_calls": 0},
|
| 110 |
+
],
|
| 111 |
+
"run_command": [
|
| 112 |
+
{"command": ["uv", "run", "pytest", "tests/test_parser.py"], "timeout": 120},
|
| 113 |
+
{"command": ["rg", "-n", "SessionUsage", "swival"], "timeout": 30},
|
| 114 |
+
{"command": ["npm", "run", "dev"], "background": True, "timeout": 5},
|
| 115 |
+
],
|
| 116 |
+
"run_shell_command": [
|
| 117 |
+
{"command": "rg -n 'TODO|FIXME' src | head -20", "timeout": 30},
|
| 118 |
+
{"command": "python3 -m http.server 8000 > server.log 2>&1", "background": True, "timeout": 5},
|
| 119 |
+
],
|
| 120 |
+
"complete_goal": [
|
| 121 |
+
{},
|
| 122 |
+
],
|
| 123 |
+
"spawn_subagent": [
|
| 124 |
+
{"task": "Inspect src/parser.py and tests/test_parser.py. Report the smallest change that would fix empty identifiers. Do not edit files."},
|
| 125 |
+
{"task": "Patch the README examples only. Do not touch source files.", "max_turns": 6},
|
| 126 |
+
{"task": "Review docs/usage.md for stale commands.", "system_hint": "Return file paths and suggested replacements only."},
|
| 127 |
+
],
|
| 128 |
+
"check_subagents": [
|
| 129 |
+
{"action": "poll"},
|
| 130 |
+
{"action": "collect", "subagent_id": "subagent-1", "timeout": 300},
|
| 131 |
+
{"action": "cancel", "subagent_id": "subagent-2"},
|
| 132 |
+
],
|
| 133 |
+
"mcp__docs__search": [
|
| 134 |
+
{"query": "parser API reject empty identifiers", "limit": 3},
|
| 135 |
+
{"query": "command provider argv tool calling"},
|
| 136 |
+
],
|
| 137 |
+
"a2a__reviewer": [
|
| 138 |
+
{"message": "Review the proposed auth change in src/auth.py: reject blank bearer tokens before lookup."},
|
| 139 |
+
{"message": "Continue reviewing the same task and focus on missing tests.", "context_id": "ctx-123", "task_id": "task-456"},
|
| 140 |
+
],
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
@dataclass(frozen=True)
|
| 145 |
+
class Example:
|
| 146 |
+
id: str
|
| 147 |
+
split: str
|
| 148 |
+
tags: list[str]
|
| 149 |
+
messages: list[dict[str, Any]]
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def _literal(node: ast.AST) -> Any:
|
| 153 |
+
try:
|
| 154 |
+
return ast.literal_eval(node)
|
| 155 |
+
except Exception:
|
| 156 |
+
return None
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def extract_tool_inventory(path: Path = SWIVAL_TOOLS) -> list[dict[str, Any]]:
|
| 160 |
+
source = path.read_text()
|
| 161 |
+
tree = ast.parse(source, filename=str(path))
|
| 162 |
+
values: dict[str, Any] = {}
|
| 163 |
+
tools: list[dict[str, Any]] = []
|
| 164 |
+
|
| 165 |
+
for node in tree.body:
|
| 166 |
+
if isinstance(node, ast.Assign):
|
| 167 |
+
val = _literal(node.value)
|
| 168 |
+
for target in node.targets:
|
| 169 |
+
if isinstance(target, ast.Name) and val is not None:
|
| 170 |
+
values[target.id] = val
|
| 171 |
+
if target.id == "TOOLS":
|
| 172 |
+
tools = list(val)
|
| 173 |
+
elif isinstance(node, ast.Expr) and isinstance(node.value, ast.Call):
|
| 174 |
+
call = node.value
|
| 175 |
+
if isinstance(call.func, ast.Attribute) and call.func.attr == "append":
|
| 176 |
+
if isinstance(call.func.value, ast.Name) and call.func.value.id == "TOOLS":
|
| 177 |
+
arg = call.args[0] if call.args else None
|
| 178 |
+
if isinstance(arg, ast.Name) and arg.id in values:
|
| 179 |
+
tools.append(values[arg.id])
|
| 180 |
+
|
| 181 |
+
for name in [
|
| 182 |
+
"USE_SKILL_TOOL",
|
| 183 |
+
"RUN_METASKILL_TOOL",
|
| 184 |
+
"RUN_COMMAND_TOOL",
|
| 185 |
+
"RUN_SHELL_COMMAND_TOOL",
|
| 186 |
+
"COMPLETE_GOAL_TOOL",
|
| 187 |
+
]:
|
| 188 |
+
if name in values:
|
| 189 |
+
tools.append(values[name])
|
| 190 |
+
|
| 191 |
+
seen: set[str] = set()
|
| 192 |
+
out: list[dict[str, Any]] = []
|
| 193 |
+
for tool in tools:
|
| 194 |
+
fn = tool.get("function", {})
|
| 195 |
+
name = fn.get("name")
|
| 196 |
+
if not name or name in seen:
|
| 197 |
+
continue
|
| 198 |
+
seen.add(name)
|
| 199 |
+
params = fn.get("parameters", {})
|
| 200 |
+
out.append(
|
| 201 |
+
{
|
| 202 |
+
"name": name,
|
| 203 |
+
"description": fn.get("description", ""),
|
| 204 |
+
"required": params.get("required", []),
|
| 205 |
+
"properties": sorted((params.get("properties") or {}).keys()),
|
| 206 |
+
}
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
for dynamic in ["spawn_subagent", "check_subagents"]:
|
| 210 |
+
if dynamic not in seen:
|
| 211 |
+
out.append(
|
| 212 |
+
{
|
| 213 |
+
"name": dynamic,
|
| 214 |
+
"description": "Runtime conditional Swival subagent tool.",
|
| 215 |
+
"required": ["task"] if dynamic == "spawn_subagent" else ["action"],
|
| 216 |
+
"properties": ["task", "max_turns", "system_hint"] if dynamic == "spawn_subagent" else ["action", "subagent_id", "timeout"],
|
| 217 |
+
}
|
| 218 |
+
)
|
| 219 |
+
for dynamic in ["mcp__docs__search", "a2a__reviewer"]:
|
| 220 |
+
if dynamic not in seen:
|
| 221 |
+
out.append(
|
| 222 |
+
{
|
| 223 |
+
"name": dynamic,
|
| 224 |
+
"description": "Representative dynamic Swival integration tool.",
|
| 225 |
+
"required": ["query"] if dynamic.startswith("mcp__") else ["message"],
|
| 226 |
+
"properties": ["query", "limit"] if dynamic.startswith("mcp__") else ["message", "context_id", "task_id"],
|
| 227 |
+
}
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
return sorted(out, key=lambda item: item["name"])
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def tool_call(name: str, args: dict[str, Any], call_id: str = "call_1") -> dict[str, Any]:
|
| 234 |
+
return {
|
| 235 |
+
"id": call_id,
|
| 236 |
+
"type": "function",
|
| 237 |
+
"function": {"name": name, "arguments": json.dumps(args, separators=(",", ":"))},
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def user(text: str) -> dict[str, Any]:
|
| 242 |
+
return {"role": "user", "content": text}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def assistant_tool(name: str, args: dict[str, Any], call_id: str = "call_1") -> dict[str, Any]:
|
| 246 |
+
return {"role": "assistant", "content": "", "tool_calls": [tool_call(name, args, call_id)]}
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def tool(name: str, content: str, call_id: str = "call_1") -> dict[str, Any]:
|
| 250 |
+
return {"role": "tool", "tool_call_id": call_id, "name": name, "content": content}
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def assistant(text: str) -> dict[str, Any]:
|
| 254 |
+
return {"role": "assistant", "content": text}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def one_shot_examples(inventory: list[dict[str, Any]], per_tool: int) -> list[Example]:
|
| 258 |
+
examples: list[Example] = []
|
| 259 |
+
for item in inventory:
|
| 260 |
+
name = item["name"]
|
| 261 |
+
variants = TOOL_EXEMPLARS.get(name, [{}])
|
| 262 |
+
for idx in range(per_tool):
|
| 263 |
+
args = variants[idx % len(variants)]
|
| 264 |
+
task = prompt_for_tool(name, args, idx)
|
| 265 |
+
result = result_for_tool(name, args)
|
| 266 |
+
examples.append(
|
| 267 |
+
Example(
|
| 268 |
+
id=f"single-{name}-{idx:03d}",
|
| 269 |
+
split="train",
|
| 270 |
+
tags=["single_tool", name],
|
| 271 |
+
messages=[user(task), assistant_tool(name, args), tool(name, result), assistant(final_for_tool(name))],
|
| 272 |
+
)
|
| 273 |
+
)
|
| 274 |
+
return examples
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def prompt_for_tool(name: str, args: dict[str, Any], idx: int) -> str:
|
| 278 |
+
prompts = {
|
| 279 |
+
"read_file": f"Open {args.get('file_path', 'the file')} and show the relevant part before making changes.",
|
| 280 |
+
"read_multiple_files": "Read the project config and the implementation together so you can compare them.",
|
| 281 |
+
"write_file": f"Create or move the requested file at {args.get('file_path', 'the destination')}.",
|
| 282 |
+
"edit_file": f"Apply the smallest edit to {args.get('file_path', 'the file')} using the text I already identified.",
|
| 283 |
+
"list_files": f"Find files matching {args.get('pattern', '**/*')} for the next pass.",
|
| 284 |
+
"grep": f"Search the workspace for {args.get('pattern', 'the pattern')}.",
|
| 285 |
+
"think": "Think through the next move before touching files.",
|
| 286 |
+
"todo": "Track this work with a checklist.",
|
| 287 |
+
"view_image": f"Inspect {args.get('image_path', 'the image')} before deciding what changed.",
|
| 288 |
+
"delete_file": f"Remove {args.get('file_path', 'the obsolete file')} safely.",
|
| 289 |
+
"fetch_url": f"Look up the external reference at {args.get('url', 'the URL')}.",
|
| 290 |
+
"snapshot": f"Use context management for this long investigation, step {idx + 1}.",
|
| 291 |
+
"outline": "Survey the code structure before reading implementation bodies.",
|
| 292 |
+
"use_skill": f"Load the {args.get('name', 'relevant')} skill before proceeding.",
|
| 293 |
+
"run_metaskill": f"Run the {args.get('name', 'metaskill')} workflow for this subtask.",
|
| 294 |
+
"run_command": "Run the focused local command with argv arguments.",
|
| 295 |
+
"run_shell_command": "Run this shell pipeline exactly as a shell command.",
|
| 296 |
+
"complete_goal": "The objective has been fully verified against current evidence. Mark it complete.",
|
| 297 |
+
"spawn_subagent": "Delegate this independent side task to a subagent while continuing locally.",
|
| 298 |
+
"check_subagents": "Check the status of the delegated subagent work.",
|
| 299 |
+
"mcp__docs__search": "Search the configured MCP documentation server for the relevant API entry.",
|
| 300 |
+
"a2a__reviewer": "Ask the remote reviewer agent for a focused second opinion.",
|
| 301 |
+
}
|
| 302 |
+
return prompts.get(name, f"Use the Swival `{name}` tool with the right arguments.")
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def result_for_tool(name: str, args: dict[str, Any]) -> str:
|
| 306 |
+
if name == "read_file":
|
| 307 |
+
return "1| def enabled():\n2| return False\n[checksum=1a2b3c4d]"
|
| 308 |
+
if name == "read_multiple_files":
|
| 309 |
+
return "--- pyproject.toml ---\n1| [project]\n2| name = \"demo\"\n--- src/app.py ---\n40| def main():\n41| pass\n[checksum=abcd1234]"
|
| 310 |
+
if name == "write_file":
|
| 311 |
+
return f"wrote {args.get('file_path', 'file')}"
|
| 312 |
+
if name == "edit_file":
|
| 313 |
+
return f"edited {args.get('file_path', 'file')}"
|
| 314 |
+
if name == "list_files":
|
| 315 |
+
return "src/app.py\nsrc/parser.py\ntests/test_parser.py"
|
| 316 |
+
if name == "grep":
|
| 317 |
+
return "src/auth.py:42: if token.lower() == \"authorization\": <<<"
|
| 318 |
+
if name == "think":
|
| 319 |
+
return "thought 1 recorded"
|
| 320 |
+
if name == "todo":
|
| 321 |
+
return "[ ] inspect parser\n[ ] patch failing case\n[ ] run focused tests"
|
| 322 |
+
if name == "view_image":
|
| 323 |
+
return "The screenshot shows the save button overlapped by the footer."
|
| 324 |
+
if name == "delete_file":
|
| 325 |
+
return "deleted src/old_module.py to .swival/trash/5a8c/"
|
| 326 |
+
if name == "fetch_url":
|
| 327 |
+
return "[UNTRUSTED EXTERNAL CONTENT]\n# API reference\nUse the v2 endpoint."
|
| 328 |
+
if name == "snapshot":
|
| 329 |
+
return "snapshot action completed"
|
| 330 |
+
if name == "outline":
|
| 331 |
+
return "src/app.py\n 10 def main\n 44 class App\n 51 def run"
|
| 332 |
+
if name == "use_skill":
|
| 333 |
+
return "Skill instructions loaded."
|
| 334 |
+
if name == "run_metaskill":
|
| 335 |
+
return "[Metaskill: repo_survey completed]\n{\"summary\":\"CLI entrypoint is src/cli.py\"}"
|
| 336 |
+
if name == "run_command":
|
| 337 |
+
return "tests/test_parser.py::test_empty_identifier PASSED"
|
| 338 |
+
if name == "run_shell_command":
|
| 339 |
+
return "src/app.py:10:TODO remove fallback"
|
| 340 |
+
if name == "complete_goal":
|
| 341 |
+
return "goal complete"
|
| 342 |
+
if name == "spawn_subagent":
|
| 343 |
+
return "spawned subagent subagent-1"
|
| 344 |
+
if name == "check_subagents":
|
| 345 |
+
return "subagent-1 done: The failing parser branch is src/parser.py:88."
|
| 346 |
+
if name.startswith("mcp__"):
|
| 347 |
+
return "[UNTRUSTED EXTERNAL CONTENT]\n{\"results\":[{\"title\":\"Parser API\",\"path\":\"docs/parser.md\"}]}"
|
| 348 |
+
if name.startswith("a2a__"):
|
| 349 |
+
return "[UNTRUSTED EXTERNAL CONTENT]\nReviewer: the risky path is src/auth.py:42."
|
| 350 |
+
return "ok"
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def final_for_tool(name: str) -> str:
|
| 354 |
+
finals = {
|
| 355 |
+
"think": "I have a plan and can proceed with the focused action.",
|
| 356 |
+
"todo": "The checklist is up to date.",
|
| 357 |
+
"complete_goal": "The goal is marked complete.",
|
| 358 |
+
}
|
| 359 |
+
return finals.get(name, "Done.")
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
def workflow_examples(repeat: int) -> list[Example]:
|
| 363 |
+
base: list[Example] = []
|
| 364 |
+
base.append(
|
| 365 |
+
Example(
|
| 366 |
+
id="workflow-edit-ambiguous-line-retry",
|
| 367 |
+
split="train",
|
| 368 |
+
tags=["edit_file", "read_file", "error_recovery", "line_number"],
|
| 369 |
+
messages=[
|
| 370 |
+
user("In src/settings.py, change only the second timeout from 5 to 10."),
|
| 371 |
+
assistant_tool("read_file", {"file_path": "src/settings.py"}, "call_1"),
|
| 372 |
+
tool("read_file", "1| timeout = 5\n2| retries = 2\n3| timeout = 5\n[checksum=0badcafe]", "call_1"),
|
| 373 |
+
assistant_tool("edit_file", {"file_path": "src/settings.py", "old_string": "timeout = 5\n", "new_string": "timeout = 10\n", "checksum": "0badcafe"}, "call_2"),
|
| 374 |
+
tool("edit_file", "error: edit_file: old_string appears at multiple lines: 1, 3. Retry with line_number.", "call_2"),
|
| 375 |
+
assistant_tool("edit_file", {"file_path": "src/settings.py", "old_string": "timeout = 5\n", "new_string": "timeout = 10\n", "line_number": 3, "checksum": "0badcafe"}, "call_3"),
|
| 376 |
+
tool("edit_file", "edited src/settings.py", "call_3"),
|
| 377 |
+
assistant("Changed only the second timeout."),
|
| 378 |
+
],
|
| 379 |
+
)
|
| 380 |
+
)
|
| 381 |
+
base.append(
|
| 382 |
+
Example(
|
| 383 |
+
id="workflow-search-read-edit-test",
|
| 384 |
+
split="train",
|
| 385 |
+
tags=["grep", "read_file", "edit_file", "run_command"],
|
| 386 |
+
messages=[
|
| 387 |
+
user("Fix the parser so empty identifiers are rejected, then run the focused parser tests."),
|
| 388 |
+
assistant_tool("grep", {"pattern": "identifier", "path": "src", "include": "**/*.py", "context_lines": 2}, "call_1"),
|
| 389 |
+
tool("grep", "src/parser.py:86: def parse_identifier(tok): <<<\nsrc/parser.py:88: return tok.value", "call_1"),
|
| 390 |
+
assistant_tool("read_file", {"file_path": "src/parser.py", "offset": 80, "limit": 30}, "call_2"),
|
| 391 |
+
tool("read_file", "80| class Parser:\n86| def parse_identifier(tok):\n87| if tok.value is None:\n88| return tok.value\n[checksum=feedbeef]", "call_2"),
|
| 392 |
+
assistant_tool("edit_file", {"file_path": "src/parser.py", "old_string": " if tok.value is None:\n return tok.value\n", "new_string": " if not tok.value:\n raise ParseError(\"empty identifier\")\n return tok.value\n", "line_number": 87, "checksum": "feedbeef"}, "call_3"),
|
| 393 |
+
tool("edit_file", "edited src/parser.py", "call_3"),
|
| 394 |
+
assistant_tool("run_command", {"command": ["uv", "run", "pytest", "tests/test_parser.py"], "timeout": 120}, "call_4"),
|
| 395 |
+
tool("run_command", "5 passed", "call_4"),
|
| 396 |
+
assistant("The parser now rejects empty identifiers and the focused parser tests pass."),
|
| 397 |
+
],
|
| 398 |
+
)
|
| 399 |
+
)
|
| 400 |
+
base.append(
|
| 401 |
+
Example(
|
| 402 |
+
id="workflow-batch-read-write-move",
|
| 403 |
+
split="train",
|
| 404 |
+
tags=["read_multiple_files", "write_file", "move_from"],
|
| 405 |
+
messages=[
|
| 406 |
+
user("Generate docs/config.md from README.md and pyproject.toml, but write it through tmp first and move it into place."),
|
| 407 |
+
assistant_tool("read_multiple_files", {"files": [{"file_path": "README.md"}, {"file_path": "pyproject.toml"}]}, "call_1"),
|
| 408 |
+
tool("read_multiple_files", "--- README.md ---\n1| # Demo\n--- pyproject.toml ---\n1| [project]\n2| name = \"demo\"", "call_1"),
|
| 409 |
+
assistant_tool("write_file", {"file_path": "tmp/config.md", "content": "# Config\n\nProject: demo\n"}, "call_2"),
|
| 410 |
+
tool("write_file", "wrote tmp/config.md", "call_2"),
|
| 411 |
+
assistant_tool("write_file", {"file_path": "docs/config.md", "move_from": "tmp/config.md"}, "call_3"),
|
| 412 |
+
tool("write_file", "moved tmp/config.md to docs/config.md", "call_3"),
|
| 413 |
+
assistant("Created docs/config.md through a temporary file and moved it into place."),
|
| 414 |
+
],
|
| 415 |
+
)
|
| 416 |
+
)
|
| 417 |
+
base.append(
|
| 418 |
+
Example(
|
| 419 |
+
id="workflow-subagent-check-collect",
|
| 420 |
+
split="train",
|
| 421 |
+
tags=["spawn_subagent", "check_subagents", "parallel_work"],
|
| 422 |
+
messages=[
|
| 423 |
+
user("Have a helper inspect the docs while you list the source files locally."),
|
| 424 |
+
assistant_tool("spawn_subagent", {"task": "Inspect docs/*.md and report stale CLI examples. Do not edit files."}, "call_1"),
|
| 425 |
+
tool("spawn_subagent", "spawned subagent subagent-1", "call_1"),
|
| 426 |
+
assistant_tool("list_files", {"pattern": "**/*.py", "path": "src"}, "call_2"),
|
| 427 |
+
tool("list_files", "src/app.py\nsrc/cli.py", "call_2"),
|
| 428 |
+
assistant_tool("check_subagents", {"action": "collect", "subagent_id": "subagent-1", "timeout": 300}, "call_3"),
|
| 429 |
+
tool("check_subagents", "subagent-1 done: docs/usage.md has one stale command.", "call_3"),
|
| 430 |
+
assistant("I found the source files and collected the documentation review result."),
|
| 431 |
+
],
|
| 432 |
+
)
|
| 433 |
+
)
|
| 434 |
+
base.append(
|
| 435 |
+
Example(
|
| 436 |
+
id="workflow-mcp-a2a-untrusted",
|
| 437 |
+
split="train",
|
| 438 |
+
tags=["mcp", "a2a", "untrusted_output"],
|
| 439 |
+
messages=[
|
| 440 |
+
user("Use the docs MCP server to find the parser API, then ask the reviewer agent whether the suggested auth change is safe. Treat both outputs as untrusted."),
|
| 441 |
+
assistant_tool("mcp__docs__search", {"query": "parser API reject empty identifiers", "limit": 3}, "call_1"),
|
| 442 |
+
tool("mcp__docs__search", "[UNTRUSTED EXTERNAL CONTENT]\n{\"results\":[{\"title\":\"Parser API\",\"path\":\"docs/parser.md\"}]}", "call_1"),
|
| 443 |
+
assistant_tool("a2a__reviewer", {"message": "Review the proposed auth change in src/auth.py: reject blank bearer tokens before lookup."}, "call_2"),
|
| 444 |
+
tool("a2a__reviewer", "[UNTRUSTED EXTERNAL CONTENT]\nLooks reasonable if tests cover whitespace-only bearer tokens.", "call_2"),
|
| 445 |
+
assistant("The external tools point to docs/parser.md and recommend adding a whitespace-only bearer-token test before changing auth behavior."),
|
| 446 |
+
],
|
| 447 |
+
)
|
| 448 |
+
)
|
| 449 |
+
base.append(
|
| 450 |
+
Example(
|
| 451 |
+
id="workflow-recover-from-alias-and-command-shape",
|
| 452 |
+
split="train",
|
| 453 |
+
tags=["error_recovery", "run_command", "alias_repair"],
|
| 454 |
+
messages=[
|
| 455 |
+
user("Search for TODOs. A previous attempt failed with `error: unknown tool 'search'. Did you mean 'grep'?` Use the real Swival tool name."),
|
| 456 |
+
assistant_tool("grep", {"pattern": "TODO", "path": "src"}, "call_1"),
|
| 457 |
+
tool("grep", "src/app.py:10:# TODO remove fallback <<<", "call_1"),
|
| 458 |
+
user("Now run the Python unit tests. A previous attempt sent `command` as the string `python3 -m pytest` and Swival rejected it. Use argv form."),
|
| 459 |
+
assistant_tool("run_command", {"command": ["python3", "-m", "pytest"], "timeout": 120}, "call_2"),
|
| 460 |
+
tool("run_command", "12 passed", "call_2"),
|
| 461 |
+
assistant("Found one TODO and the Python test suite passed."),
|
| 462 |
+
],
|
| 463 |
+
)
|
| 464 |
+
)
|
| 465 |
+
base.append(
|
| 466 |
+
Example(
|
| 467 |
+
id="workflow-command-output-spill",
|
| 468 |
+
split="train",
|
| 469 |
+
tags=["run_command", "read_file", "large_output"],
|
| 470 |
+
messages=[
|
| 471 |
+
user("Run the integration tests and inspect the saved output if the command output spills."),
|
| 472 |
+
assistant_tool("run_command", {"command": ["uv", "run", "pytest", "tests/test_integration.py"], "timeout": 240}, "call_1"),
|
| 473 |
+
tool("run_command", "output too large; saved to .swival/cmd_output_123.txt", "call_1"),
|
| 474 |
+
assistant_tool("read_file", {"file_path": ".swival/cmd_output_123.txt", "tail_lines": 120}, "call_2"),
|
| 475 |
+
tool("read_file", "991| FAILED tests/test_integration.py::test_login\n992| AssertionError: expected 200, got 401\n[checksum=1234abcd]", "call_2"),
|
| 476 |
+
assistant("The integration run failed in test_login with a 401 response."),
|
| 477 |
+
],
|
| 478 |
+
)
|
| 479 |
+
)
|
| 480 |
+
base.append(
|
| 481 |
+
Example(
|
| 482 |
+
id="workflow-snapshot-after-long-readonly-investigation",
|
| 483 |
+
split="train",
|
| 484 |
+
tags=["snapshot", "outline", "grep", "read_file"],
|
| 485 |
+
messages=[
|
| 486 |
+
user("Investigate where request IDs are assigned. Summarize the context before editing."),
|
| 487 |
+
assistant_tool("snapshot", {"action": "save", "label": "request id investigation"}, "call_1"),
|
| 488 |
+
tool("snapshot", "checkpoint saved", "call_1"),
|
| 489 |
+
assistant_tool("outline", {"file_path": "src", "depth": 1}, "call_2"),
|
| 490 |
+
tool("outline", "src/server.py\n 10 def handle\nsrc/middleware.py\n 8 def attach_request_id", "call_2"),
|
| 491 |
+
assistant_tool("grep", {"pattern": "request_id", "path": "src", "include": "**/*.py"}, "call_3"),
|
| 492 |
+
tool("grep", "src/middleware.py:8:def attach_request_id(req): <<<", "call_3"),
|
| 493 |
+
assistant_tool("read_file", {"file_path": "src/middleware.py", "offset": 1, "limit": 80}, "call_4"),
|
| 494 |
+
tool("read_file", "8| def attach_request_id(req):\n9| req.id = uuid4().hex\n[checksum=5678abcd]", "call_4"),
|
| 495 |
+
assistant_tool("snapshot", {"action": "restore", "summary": "Request IDs are assigned in src/middleware.py:8 by attach_request_id, which sets req.id to uuid4().hex. The server handler calls it before routing."}, "call_5"),
|
| 496 |
+
tool("snapshot", "restored context from request id investigation", "call_5"),
|
| 497 |
+
assistant("I summarized the read-only investigation and can now make a focused edit."),
|
| 498 |
+
],
|
| 499 |
+
)
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
out: list[Example] = []
|
| 503 |
+
for i in range(repeat):
|
| 504 |
+
for ex in base:
|
| 505 |
+
out.append(Example(id=f"{ex.id}-{i:03d}", split=ex.split, tags=ex.tags, messages=ex.messages))
|
| 506 |
+
return out
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
def synthesize_examples(inventory: list[dict[str, Any]], count: int, seed: int) -> list[Example]:
|
| 510 |
+
rng = random.Random(seed)
|
| 511 |
+
names = [item["name"] for item in inventory]
|
| 512 |
+
examples: list[Example] = []
|
| 513 |
+
intents = [
|
| 514 |
+
"Inspect the relevant files before editing.",
|
| 515 |
+
"Make the smallest safe change and verify it.",
|
| 516 |
+
"Find where this behavior is implemented.",
|
| 517 |
+
"Run the focused command and summarize the result.",
|
| 518 |
+
"Recover from the tool error by sending a corrected call.",
|
| 519 |
+
]
|
| 520 |
+
for i in range(count):
|
| 521 |
+
name = rng.choice(names)
|
| 522 |
+
exemplar = rng.choice(TOOL_EXEMPLARS.get(name, [{}]))
|
| 523 |
+
args = json.loads(json.dumps(exemplar))
|
| 524 |
+
prompt = f"{rng.choice(intents)} Use the appropriate Swival tool for step {i + 1}."
|
| 525 |
+
examples.append(
|
| 526 |
+
Example(
|
| 527 |
+
id=f"synthetic-{i:05d}-{name}",
|
| 528 |
+
split="train",
|
| 529 |
+
tags=["synthetic", name],
|
| 530 |
+
messages=[user(prompt), assistant_tool(name, args), tool(name, result_for_tool(name, args)), assistant(final_for_tool(name))],
|
| 531 |
+
)
|
| 532 |
+
)
|
| 533 |
+
return examples
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
def eval_examples() -> list[dict[str, Any]]:
|
| 537 |
+
return [
|
| 538 |
+
{
|
| 539 |
+
"id": "eval-edit-line-number",
|
| 540 |
+
"prompt": "In settings.py, change only the second timeout value from 5 to 10. Do not change the first timeout.",
|
| 541 |
+
"files": {"settings.py": "timeout = 5\nretries = 2\ntimeout = 5\n"},
|
| 542 |
+
"verify": {"settings.py": "timeout = 5\nretries = 2\ntimeout = 10\n"},
|
| 543 |
+
"expected_tools": ["read_file", "edit_file"],
|
| 544 |
+
},
|
| 545 |
+
{
|
| 546 |
+
"id": "eval-grep-edit-test",
|
| 547 |
+
"prompt": "Find the Python function that accepts empty names, make it reject empty strings, and run `python3 -m pytest tests/test_names.py`.",
|
| 548 |
+
"files": {
|
| 549 |
+
"src/names.py": "class NameError(Exception):\n pass\n\n\ndef normalize_name(name):\n if name is None:\n raise NameError('missing')\n return name.strip()\n",
|
| 550 |
+
"tests/test_names.py": "from src.names import NameError, normalize_name\n\n\ndef test_empty_name_rejected():\n try:\n normalize_name(' ')\n except NameError:\n return\n raise AssertionError('empty name accepted')\n",
|
| 551 |
+
"pytest.py": PYTEST_SHIM,
|
| 552 |
+
"pyproject.toml": "[tool.pytest.ini_options]\npythonpath = ['.']\n",
|
| 553 |
+
},
|
| 554 |
+
"verify": {
|
| 555 |
+
"src/names.py": "class NameError(Exception):\n pass\n\n\ndef normalize_name(name):\n if name is None:\n raise NameError('missing')\n normalized = name.strip()\n if not normalized:\n raise NameError('missing')\n return normalized\n"
|
| 556 |
+
},
|
| 557 |
+
"expected_tools": ["grep", "read_file", "edit_file", "run_command"],
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"id": "eval-batch-read-write",
|
| 561 |
+
"prompt": "Read README.md and pyproject.toml, then create docs/summary.md with the project name and one-sentence description.",
|
| 562 |
+
"files": {
|
| 563 |
+
"README.md": "# Widget\n\nA tiny request router.\n",
|
| 564 |
+
"pyproject.toml": "[project]\nname = 'widget'\n",
|
| 565 |
+
},
|
| 566 |
+
"verify_contains": {"docs/summary.md": ["widget", "tiny request router"]},
|
| 567 |
+
"expected_tools": ["read_multiple_files", "write_file"],
|
| 568 |
+
},
|
| 569 |
+
{
|
| 570 |
+
"id": "eval-delete-obsolete",
|
| 571 |
+
"prompt": "Delete obsolete.py and leave keep.py alone.",
|
| 572 |
+
"files": {"obsolete.py": "print('old')\n", "keep.py": "print('keep')\n"},
|
| 573 |
+
"verify_missing": ["obsolete.py"],
|
| 574 |
+
"verify": {"keep.py": "print('keep')\n"},
|
| 575 |
+
"expected_tools": ["delete_file"],
|
| 576 |
+
},
|
| 577 |
+
{
|
| 578 |
+
"id": "eval-command-argv",
|
| 579 |
+
"prompt": "Run the test command `python3 -m pytest tests/test_math.py` and report whether it passed. Use argv form, not a shell string.",
|
| 580 |
+
"files": {
|
| 581 |
+
"mathlib.py": "def add(a, b):\n return a + b\n",
|
| 582 |
+
"tests/test_math.py": "from mathlib import add\n\n\ndef test_add():\n assert add(2, 3) == 5\n",
|
| 583 |
+
"pytest.py": PYTEST_SHIM,
|
| 584 |
+
},
|
| 585 |
+
"verify_command": ["python3", "-m", "pytest", "tests/test_math.py"],
|
| 586 |
+
"expected_tools": ["run_command"],
|
| 587 |
+
},
|
| 588 |
+
]
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
def write_jsonl(path: Path, examples: list[Example]) -> None:
|
| 592 |
+
with path.open("w") as f:
|
| 593 |
+
for ex in examples:
|
| 594 |
+
f.write(json.dumps({"id": ex.id, "split": ex.split, "tags": ex.tags, "messages": ex.messages}, separators=(",", ":")) + "\n")
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
def main() -> int:
|
| 598 |
+
parser = argparse.ArgumentParser()
|
| 599 |
+
parser.add_argument("--per-tool", type=int, default=12)
|
| 600 |
+
parser.add_argument("--synthetic-count", type=int, default=5000)
|
| 601 |
+
parser.add_argument("--workflow-repeat", type=int, default=100)
|
| 602 |
+
parser.add_argument("--seed", type=int, default=20260607)
|
| 603 |
+
parser.add_argument("--clean", action="store_true")
|
| 604 |
+
args = parser.parse_args()
|
| 605 |
+
|
| 606 |
+
DATA_DIR.mkdir(exist_ok=True)
|
| 607 |
+
TMP_DIR.mkdir(exist_ok=True)
|
| 608 |
+
if args.clean and DATA_DIR.exists():
|
| 609 |
+
shutil.rmtree(DATA_DIR)
|
| 610 |
+
DATA_DIR.mkdir()
|
| 611 |
+
|
| 612 |
+
inventory = extract_tool_inventory()
|
| 613 |
+
examples = []
|
| 614 |
+
examples.extend(one_shot_examples(inventory, args.per_tool))
|
| 615 |
+
examples.extend(workflow_examples(args.workflow_repeat))
|
| 616 |
+
examples.extend(synthesize_examples(inventory, args.synthetic_count, args.seed))
|
| 617 |
+
|
| 618 |
+
write_jsonl(DATA_DIR / "swival_tool_calling_train.jsonl", examples)
|
| 619 |
+
with (DATA_DIR / "swival_tool_inventory.json").open("w") as f:
|
| 620 |
+
json.dump({"source": str(SWIVAL_TOOLS), "tools": inventory}, f, indent=2)
|
| 621 |
+
f.write("\n")
|
| 622 |
+
with (DATA_DIR / "swival_tool_calling_eval.jsonl").open("w") as f:
|
| 623 |
+
for row in eval_examples():
|
| 624 |
+
f.write(json.dumps(row, separators=(",", ":")) + "\n")
|
| 625 |
+
|
| 626 |
+
print(f"wrote {len(examples)} training examples")
|
| 627 |
+
print(f"wrote {len(eval_examples())} eval tasks")
|
| 628 |
+
print(f"covered {len(inventory)} tools")
|
| 629 |
+
return 0
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
if __name__ == "__main__":
|
| 633 |
+
raise SystemExit(main())
|
scripts/run_codex_eval.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import subprocess
|
| 9 |
+
import time
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 15 |
+
DEFAULT_EVALS = ROOT / "data" / "codex_tool_calling_eval.jsonl"
|
| 16 |
+
WORK_ROOT = ROOT / "tmp" / "codex-eval"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def iter_jsonl(path: Path):
|
| 20 |
+
with path.open() as f:
|
| 21 |
+
for line in f:
|
| 22 |
+
if line.strip():
|
| 23 |
+
yield json.loads(line)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def seed_workspace(case: dict[str, Any], workdir: Path) -> None:
|
| 27 |
+
if workdir.exists():
|
| 28 |
+
shutil.rmtree(workdir)
|
| 29 |
+
workdir.mkdir(parents=True)
|
| 30 |
+
for rel, text in case["files"].items():
|
| 31 |
+
path = workdir / rel
|
| 32 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 33 |
+
path.write_text(text)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def apply_expected_outputs(case: dict[str, Any], workdir: Path) -> None:
|
| 37 |
+
for rel, text in (case.get("verify") or {}).items():
|
| 38 |
+
path = workdir / rel
|
| 39 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 40 |
+
path.write_text(text)
|
| 41 |
+
for rel, needles in (case.get("verify_contains") or {}).items():
|
| 42 |
+
path = workdir / rel
|
| 43 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 44 |
+
path.write_text("\n".join(needles) + "\n")
|
| 45 |
+
for rel, expected in (case.get("verify_json") or {}).items():
|
| 46 |
+
path = workdir / rel
|
| 47 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
path.write_text(json.dumps(expected, indent=2) + "\n")
|
| 49 |
+
for rel in case.get("verify_missing") or []:
|
| 50 |
+
path = workdir / rel
|
| 51 |
+
if path.exists():
|
| 52 |
+
path.unlink()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def verify_case(case: dict[str, Any], workdir: Path) -> list[str]:
|
| 56 |
+
errors: list[str] = []
|
| 57 |
+
for rel, expected in (case.get("verify") or {}).items():
|
| 58 |
+
path = workdir / rel
|
| 59 |
+
if not path.exists():
|
| 60 |
+
errors.append(f"{rel} is missing")
|
| 61 |
+
elif path.read_text() != expected:
|
| 62 |
+
errors.append(f"{rel} did not match expected content")
|
| 63 |
+
for rel, needles in (case.get("verify_contains") or {}).items():
|
| 64 |
+
path = workdir / rel
|
| 65 |
+
if not path.exists():
|
| 66 |
+
errors.append(f"{rel} is missing")
|
| 67 |
+
continue
|
| 68 |
+
text = path.read_text().lower()
|
| 69 |
+
for needle in needles:
|
| 70 |
+
if needle.lower() not in text:
|
| 71 |
+
errors.append(f"{rel} does not contain {needle!r}")
|
| 72 |
+
for rel, expected in (case.get("verify_json") or {}).items():
|
| 73 |
+
path = workdir / rel
|
| 74 |
+
if not path.exists():
|
| 75 |
+
errors.append(f"{rel} is missing")
|
| 76 |
+
continue
|
| 77 |
+
try:
|
| 78 |
+
actual = json.loads(path.read_text())
|
| 79 |
+
except Exception as exc:
|
| 80 |
+
errors.append(f"{rel} is not valid JSON: {exc}")
|
| 81 |
+
continue
|
| 82 |
+
for key, value in expected.items():
|
| 83 |
+
if actual.get(key) != value:
|
| 84 |
+
errors.append(f"{rel} field {key!r} expected {value!r}, got {actual.get(key)!r}")
|
| 85 |
+
for rel in case.get("verify_missing") or []:
|
| 86 |
+
if (workdir / rel).exists():
|
| 87 |
+
errors.append(f"{rel} still exists")
|
| 88 |
+
command = case.get("verify_command")
|
| 89 |
+
if command:
|
| 90 |
+
proc = subprocess.run(command, cwd=workdir, text=True, capture_output=True, timeout=120)
|
| 91 |
+
if proc.returncode != 0:
|
| 92 |
+
errors.append(f"verify_command failed: {proc.stdout}{proc.stderr}")
|
| 93 |
+
return errors
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def parse_events(stdout: str) -> tuple[list[str], list[str]]:
|
| 97 |
+
event_types: list[str] = []
|
| 98 |
+
item_types: list[str] = []
|
| 99 |
+
for line in stdout.splitlines():
|
| 100 |
+
line = line.strip()
|
| 101 |
+
if not line or not line.startswith("{"):
|
| 102 |
+
continue
|
| 103 |
+
try:
|
| 104 |
+
event = json.loads(line)
|
| 105 |
+
except json.JSONDecodeError:
|
| 106 |
+
continue
|
| 107 |
+
if isinstance(event.get("type"), str):
|
| 108 |
+
event_types.append(event["type"])
|
| 109 |
+
item = event.get("item")
|
| 110 |
+
if isinstance(item, dict) and isinstance(item.get("type"), str):
|
| 111 |
+
item_types.append(item["type"])
|
| 112 |
+
return event_types, item_types
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def event_errors(case: dict[str, Any], event_types: list[str], item_types: list[str]) -> list[str]:
|
| 116 |
+
observed = set(event_types) | set(item_types)
|
| 117 |
+
expected = set(case.get("expected_events") or [])
|
| 118 |
+
return [f"missing expected event/item type {name}" for name in sorted(expected - observed)]
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def self_check_case(case: dict[str, Any]) -> dict[str, Any]:
|
| 122 |
+
workdir = WORK_ROOT / f"self-check-{case['id']}"
|
| 123 |
+
seed_workspace(case, workdir)
|
| 124 |
+
apply_expected_outputs(case, workdir)
|
| 125 |
+
errors = verify_case(case, workdir)
|
| 126 |
+
return {"id": case["id"], "passed": not errors, "verify_errors": errors}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def run_case(case: dict[str, Any], args: argparse.Namespace) -> dict[str, Any]:
|
| 130 |
+
workdir = WORK_ROOT / case["id"]
|
| 131 |
+
seed_workspace(case, workdir)
|
| 132 |
+
last_message = workdir / "last-message.txt"
|
| 133 |
+
command = [
|
| 134 |
+
"codex",
|
| 135 |
+
"-a",
|
| 136 |
+
"never",
|
| 137 |
+
"exec",
|
| 138 |
+
"--json",
|
| 139 |
+
"--ephemeral",
|
| 140 |
+
"--skip-git-repo-check",
|
| 141 |
+
"--color",
|
| 142 |
+
"never",
|
| 143 |
+
"--sandbox",
|
| 144 |
+
args.sandbox,
|
| 145 |
+
"-C",
|
| 146 |
+
str(workdir),
|
| 147 |
+
"-c",
|
| 148 |
+
f"model_provider=\"{args.provider}\"",
|
| 149 |
+
"-m",
|
| 150 |
+
args.model,
|
| 151 |
+
"-o",
|
| 152 |
+
str(last_message),
|
| 153 |
+
case["prompt"],
|
| 154 |
+
]
|
| 155 |
+
env = os.environ.copy()
|
| 156 |
+
env.setdefault("OMLX_API_KEY", "omlx")
|
| 157 |
+
|
| 158 |
+
start = time.time()
|
| 159 |
+
proc = subprocess.run(command, cwd=workdir, text=True, capture_output=True, timeout=args.timeout, env=env)
|
| 160 |
+
event_types, item_types = parse_events(proc.stdout)
|
| 161 |
+
verify_errors = verify_case(case, workdir) if proc.returncode == 0 else ["codex exited nonzero"]
|
| 162 |
+
event_check_errors = event_errors(case, event_types, item_types) if proc.returncode == 0 else []
|
| 163 |
+
return {
|
| 164 |
+
"id": case["id"],
|
| 165 |
+
"returncode": proc.returncode,
|
| 166 |
+
"seconds": round(time.time() - start, 3),
|
| 167 |
+
"passed": proc.returncode == 0 and not verify_errors and not event_check_errors,
|
| 168 |
+
"verify_errors": verify_errors,
|
| 169 |
+
"event_errors": event_check_errors,
|
| 170 |
+
"event_types": sorted(set(event_types)),
|
| 171 |
+
"item_types": sorted(set(item_types)),
|
| 172 |
+
"last_message": last_message.read_text() if last_message.exists() else "",
|
| 173 |
+
"stdout_tail": proc.stdout[-4000:],
|
| 174 |
+
"stderr_tail": proc.stderr[-4000:],
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def main() -> int:
|
| 179 |
+
parser = argparse.ArgumentParser()
|
| 180 |
+
parser.add_argument("--evals", type=Path, default=DEFAULT_EVALS)
|
| 181 |
+
parser.add_argument("--model", default="qwen35")
|
| 182 |
+
parser.add_argument("--provider", default="omlx")
|
| 183 |
+
parser.add_argument("--sandbox", default="workspace-write")
|
| 184 |
+
parser.add_argument("--timeout", type=int, default=300)
|
| 185 |
+
parser.add_argument("--limit", type=int)
|
| 186 |
+
parser.add_argument("--self-check", action="store_true", help="Verify eval seed/check logic without invoking Codex.")
|
| 187 |
+
args = parser.parse_args()
|
| 188 |
+
|
| 189 |
+
WORK_ROOT.mkdir(parents=True, exist_ok=True)
|
| 190 |
+
cases = list(iter_jsonl(args.evals))
|
| 191 |
+
if args.limit is not None:
|
| 192 |
+
cases = cases[: args.limit]
|
| 193 |
+
|
| 194 |
+
results = []
|
| 195 |
+
for case in cases:
|
| 196 |
+
if args.self_check:
|
| 197 |
+
result = self_check_case(case)
|
| 198 |
+
else:
|
| 199 |
+
print(f"running {case['id']}")
|
| 200 |
+
try:
|
| 201 |
+
result = run_case(case, args)
|
| 202 |
+
except subprocess.TimeoutExpired as exc:
|
| 203 |
+
result = {
|
| 204 |
+
"id": case["id"],
|
| 205 |
+
"returncode": None,
|
| 206 |
+
"seconds": args.timeout,
|
| 207 |
+
"passed": False,
|
| 208 |
+
"verify_errors": ["codex timed out"],
|
| 209 |
+
"event_errors": [],
|
| 210 |
+
"event_types": [],
|
| 211 |
+
"item_types": [],
|
| 212 |
+
"last_message": "",
|
| 213 |
+
"stdout_tail": (exc.stdout or "")[-4000:],
|
| 214 |
+
"stderr_tail": (exc.stderr or "")[-4000:],
|
| 215 |
+
}
|
| 216 |
+
print(json.dumps(result, indent=2))
|
| 217 |
+
results.append(result)
|
| 218 |
+
|
| 219 |
+
out = ROOT / "tmp" / "codex-eval-results.json"
|
| 220 |
+
out.write_text(json.dumps(results, indent=2) + "\n")
|
| 221 |
+
failed = [row for row in results if not row["passed"]]
|
| 222 |
+
print(f"passed {len(results) - len(failed)}/{len(results)}")
|
| 223 |
+
return 1 if failed else 0
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
if __name__ == "__main__":
|
| 227 |
+
raise SystemExit(main())
|
scripts/run_opencode_eval.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import subprocess
|
| 9 |
+
import time
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
DEFAULT_EVALS = ROOT / "data" / "opencode_tool_calling_eval.jsonl"
|
| 15 |
+
DEFAULT_CONFIG = ROOT / "configs" / "opencode-qwen35.json"
|
| 16 |
+
WORK_ROOT = ROOT / "tmp" / "opencode-eval"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def iter_jsonl(path: Path):
|
| 20 |
+
with path.open() as f:
|
| 21 |
+
for line in f:
|
| 22 |
+
if line.strip():
|
| 23 |
+
yield json.loads(line)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def seed_workspace(case: dict, workdir: Path) -> None:
|
| 27 |
+
if workdir.exists():
|
| 28 |
+
shutil.rmtree(workdir)
|
| 29 |
+
workdir.mkdir(parents=True)
|
| 30 |
+
for rel, text in case["files"].items():
|
| 31 |
+
path = workdir / rel
|
| 32 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 33 |
+
path.write_text(text)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def apply_expected_outputs(case: dict, workdir: Path) -> None:
|
| 37 |
+
for rel, text in (case.get("verify") or {}).items():
|
| 38 |
+
path = workdir / rel
|
| 39 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 40 |
+
path.write_text(text)
|
| 41 |
+
for rel, needles in (case.get("verify_contains") or {}).items():
|
| 42 |
+
path = workdir / rel
|
| 43 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 44 |
+
path.write_text("\n".join(needles) + "\n")
|
| 45 |
+
for rel in case.get("verify_missing") or []:
|
| 46 |
+
path = workdir / rel
|
| 47 |
+
if path.exists():
|
| 48 |
+
path.unlink()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def verify_case(case: dict, workdir: Path) -> list[str]:
|
| 52 |
+
errors: list[str] = []
|
| 53 |
+
for rel, expected in (case.get("verify") or {}).items():
|
| 54 |
+
path = workdir / rel
|
| 55 |
+
if not path.exists():
|
| 56 |
+
errors.append(f"{rel} is missing")
|
| 57 |
+
elif path.read_text() != expected:
|
| 58 |
+
errors.append(f"{rel} did not match expected content")
|
| 59 |
+
for rel, needles in (case.get("verify_contains") or {}).items():
|
| 60 |
+
path = workdir / rel
|
| 61 |
+
if not path.exists():
|
| 62 |
+
errors.append(f"{rel} is missing")
|
| 63 |
+
continue
|
| 64 |
+
text = path.read_text().lower()
|
| 65 |
+
for needle in needles:
|
| 66 |
+
if needle.lower() not in text:
|
| 67 |
+
errors.append(f"{rel} does not contain {needle!r}")
|
| 68 |
+
for rel in case.get("verify_missing") or []:
|
| 69 |
+
if (workdir / rel).exists():
|
| 70 |
+
errors.append(f"{rel} still exists")
|
| 71 |
+
command = case.get("verify_command")
|
| 72 |
+
if command:
|
| 73 |
+
proc = subprocess.run(command, cwd=workdir, text=True, capture_output=True, timeout=120)
|
| 74 |
+
if proc.returncode != 0:
|
| 75 |
+
errors.append(f"verify_command failed: {proc.stdout}{proc.stderr}")
|
| 76 |
+
return errors
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def parse_tool_mentions(text: str, expected_tools: list[str]) -> list[str]:
|
| 80 |
+
found: list[str] = []
|
| 81 |
+
lower = text.lower()
|
| 82 |
+
for name in expected_tools:
|
| 83 |
+
if name.lower() in lower:
|
| 84 |
+
found.append(name)
|
| 85 |
+
return found
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def self_check_case(case: dict) -> dict:
|
| 89 |
+
workdir = WORK_ROOT / f"self-check-{case['id']}"
|
| 90 |
+
seed_workspace(case, workdir)
|
| 91 |
+
apply_expected_outputs(case, workdir)
|
| 92 |
+
errors = verify_case(case, workdir)
|
| 93 |
+
return {"id": case["id"], "passed": not errors, "verify_errors": errors}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def run_case(case: dict, args: argparse.Namespace) -> dict:
|
| 97 |
+
workdir = WORK_ROOT / case["id"]
|
| 98 |
+
seed_workspace(case, workdir)
|
| 99 |
+
config_content = args.config.read_text()
|
| 100 |
+
command = [
|
| 101 |
+
"bunx",
|
| 102 |
+
"opencode-ai@latest",
|
| 103 |
+
"run",
|
| 104 |
+
"--model",
|
| 105 |
+
args.model,
|
| 106 |
+
"--format",
|
| 107 |
+
"json",
|
| 108 |
+
"--dir",
|
| 109 |
+
str(workdir),
|
| 110 |
+
]
|
| 111 |
+
if args.dangerously_skip_permissions:
|
| 112 |
+
command.append("--dangerously-skip-permissions")
|
| 113 |
+
command.append(case["prompt"])
|
| 114 |
+
env = os.environ.copy()
|
| 115 |
+
env["OPENCODE_CONFIG_CONTENT"] = config_content
|
| 116 |
+
env.setdefault("OPENAI_API_KEY", "omlx")
|
| 117 |
+
|
| 118 |
+
start = time.time()
|
| 119 |
+
proc = subprocess.run(command, cwd=workdir, text=True, capture_output=True, timeout=args.timeout, env=env)
|
| 120 |
+
verify_errors = verify_case(case, workdir) if proc.returncode == 0 else ["opencode exited nonzero"]
|
| 121 |
+
combined = f"{proc.stdout}\n{proc.stderr}"
|
| 122 |
+
return {
|
| 123 |
+
"id": case["id"],
|
| 124 |
+
"returncode": proc.returncode,
|
| 125 |
+
"seconds": round(time.time() - start, 3),
|
| 126 |
+
"passed": proc.returncode == 0 and not verify_errors,
|
| 127 |
+
"verify_errors": verify_errors,
|
| 128 |
+
"expected_tools": case.get("expected_tools") or [],
|
| 129 |
+
"observed_tool_mentions": parse_tool_mentions(combined, case.get("expected_tools") or []),
|
| 130 |
+
"stdout_tail": proc.stdout[-4000:],
|
| 131 |
+
"stderr_tail": proc.stderr[-4000:],
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def main() -> int:
|
| 136 |
+
parser = argparse.ArgumentParser()
|
| 137 |
+
parser.add_argument("--evals", type=Path, default=DEFAULT_EVALS)
|
| 138 |
+
parser.add_argument("--config", type=Path, default=DEFAULT_CONFIG)
|
| 139 |
+
parser.add_argument("--model", default="qwen35/qwen35")
|
| 140 |
+
parser.add_argument("--timeout", type=int, default=300)
|
| 141 |
+
parser.add_argument("--limit", type=int)
|
| 142 |
+
parser.add_argument("--self-check", action="store_true", help="Verify eval seed/check logic without invoking opencode.")
|
| 143 |
+
parser.add_argument("--dangerously-skip-permissions", action="store_true", help="Pass opencode's non-interactive permission bypass flag for disposable eval workspaces.")
|
| 144 |
+
args = parser.parse_args()
|
| 145 |
+
|
| 146 |
+
WORK_ROOT.mkdir(parents=True, exist_ok=True)
|
| 147 |
+
cases = list(iter_jsonl(args.evals))
|
| 148 |
+
if args.limit is not None:
|
| 149 |
+
cases = cases[: args.limit]
|
| 150 |
+
|
| 151 |
+
results = []
|
| 152 |
+
for case in cases:
|
| 153 |
+
if args.self_check:
|
| 154 |
+
result = self_check_case(case)
|
| 155 |
+
else:
|
| 156 |
+
print(f"running {case['id']}")
|
| 157 |
+
try:
|
| 158 |
+
result = run_case(case, args)
|
| 159 |
+
except subprocess.TimeoutExpired as exc:
|
| 160 |
+
result = {
|
| 161 |
+
"id": case["id"],
|
| 162 |
+
"returncode": None,
|
| 163 |
+
"seconds": args.timeout,
|
| 164 |
+
"passed": False,
|
| 165 |
+
"verify_errors": ["opencode timed out"],
|
| 166 |
+
"expected_tools": case.get("expected_tools") or [],
|
| 167 |
+
"observed_tool_mentions": [],
|
| 168 |
+
"stdout_tail": (exc.stdout or "")[-4000:],
|
| 169 |
+
"stderr_tail": (exc.stderr or "")[-4000:],
|
| 170 |
+
}
|
| 171 |
+
print(json.dumps(result, indent=2))
|
| 172 |
+
results.append(result)
|
| 173 |
+
|
| 174 |
+
out = ROOT / "tmp" / "opencode-eval-results.json"
|
| 175 |
+
out.write_text(json.dumps(results, indent=2) + "\n")
|
| 176 |
+
failed = [row for row in results if not row["passed"]]
|
| 177 |
+
print(f"passed {len(results) - len(failed)}/{len(results)}")
|
| 178 |
+
return 1 if failed else 0
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == "__main__":
|
| 182 |
+
raise SystemExit(main())
|
scripts/run_swival_eval.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import shutil
|
| 7 |
+
import subprocess
|
| 8 |
+
import time
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 13 |
+
DEFAULT_EVALS = ROOT / "data" / "swival_tool_calling_eval.jsonl"
|
| 14 |
+
WORK_ROOT = ROOT / "tmp" / "swival-eval"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def iter_jsonl(path: Path):
|
| 18 |
+
with path.open() as f:
|
| 19 |
+
for line in f:
|
| 20 |
+
if line.strip():
|
| 21 |
+
yield json.loads(line)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def seed_workspace(case: dict, workdir: Path) -> None:
|
| 25 |
+
if workdir.exists():
|
| 26 |
+
shutil.rmtree(workdir)
|
| 27 |
+
workdir.mkdir(parents=True)
|
| 28 |
+
for rel, text in case["files"].items():
|
| 29 |
+
dest = workdir / rel
|
| 30 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 31 |
+
dest.write_text(text)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def verify_case(case: dict, workdir: Path) -> list[str]:
|
| 35 |
+
errors: list[str] = []
|
| 36 |
+
for rel, expected in (case.get("verify") or {}).items():
|
| 37 |
+
path = workdir / rel
|
| 38 |
+
if not path.exists():
|
| 39 |
+
errors.append(f"{rel} is missing")
|
| 40 |
+
elif path.read_text() != expected:
|
| 41 |
+
errors.append(f"{rel} did not match expected content")
|
| 42 |
+
for rel, needles in (case.get("verify_contains") or {}).items():
|
| 43 |
+
path = workdir / rel
|
| 44 |
+
if not path.exists():
|
| 45 |
+
errors.append(f"{rel} is missing")
|
| 46 |
+
continue
|
| 47 |
+
text = path.read_text().lower()
|
| 48 |
+
for needle in needles:
|
| 49 |
+
if needle.lower() not in text:
|
| 50 |
+
errors.append(f"{rel} does not contain {needle!r}")
|
| 51 |
+
for rel in case.get("verify_missing") or []:
|
| 52 |
+
if (workdir / rel).exists():
|
| 53 |
+
errors.append(f"{rel} still exists")
|
| 54 |
+
command = case.get("verify_command")
|
| 55 |
+
if command:
|
| 56 |
+
proc = subprocess.run(command, cwd=workdir, text=True, capture_output=True, timeout=120)
|
| 57 |
+
if proc.returncode != 0:
|
| 58 |
+
errors.append(f"verify_command failed: {proc.stdout}{proc.stderr}")
|
| 59 |
+
return errors
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def apply_expected_outputs(case: dict, workdir: Path) -> None:
|
| 63 |
+
for rel, text in (case.get("verify") or {}).items():
|
| 64 |
+
path = workdir / rel
|
| 65 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 66 |
+
path.write_text(text)
|
| 67 |
+
for rel, needles in (case.get("verify_contains") or {}).items():
|
| 68 |
+
path = workdir / rel
|
| 69 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 70 |
+
path.write_text("\n".join(needles) + "\n")
|
| 71 |
+
for rel in case.get("verify_missing") or []:
|
| 72 |
+
path = workdir / rel
|
| 73 |
+
if path.exists():
|
| 74 |
+
path.unlink()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def run_case(case: dict, profile: str, swival_bin: str, timeout: int) -> dict:
|
| 78 |
+
workdir = WORK_ROOT / case["id"]
|
| 79 |
+
seed_workspace(case, workdir)
|
| 80 |
+
cmd = [swival_bin, "--profile", profile, case["prompt"]]
|
| 81 |
+
start = time.time()
|
| 82 |
+
proc = subprocess.run(cmd, cwd=workdir, text=True, capture_output=True, timeout=timeout)
|
| 83 |
+
verify_errors = verify_case(case, workdir) if proc.returncode == 0 else ["swival exited nonzero"]
|
| 84 |
+
return {
|
| 85 |
+
"id": case["id"],
|
| 86 |
+
"returncode": proc.returncode,
|
| 87 |
+
"seconds": round(time.time() - start, 3),
|
| 88 |
+
"passed": proc.returncode == 0 and not verify_errors,
|
| 89 |
+
"verify_errors": verify_errors,
|
| 90 |
+
"stdout_tail": proc.stdout[-4000:],
|
| 91 |
+
"stderr_tail": proc.stderr[-4000:],
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def self_check_case(case: dict) -> dict:
|
| 96 |
+
workdir = WORK_ROOT / f"self-check-{case['id']}"
|
| 97 |
+
seed_workspace(case, workdir)
|
| 98 |
+
apply_expected_outputs(case, workdir)
|
| 99 |
+
errors = verify_case(case, workdir)
|
| 100 |
+
return {"id": case["id"], "passed": not errors, "verify_errors": errors}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def main() -> int:
|
| 104 |
+
parser = argparse.ArgumentParser()
|
| 105 |
+
parser.add_argument("--evals", type=Path, default=DEFAULT_EVALS)
|
| 106 |
+
parser.add_argument("--profile", default="omlx")
|
| 107 |
+
parser.add_argument("--swival-bin", default="swival")
|
| 108 |
+
parser.add_argument("--timeout", type=int, default=300)
|
| 109 |
+
parser.add_argument("--limit", type=int)
|
| 110 |
+
parser.add_argument("--self-check", action="store_true", help="Verify eval seed/check logic without invoking Swival.")
|
| 111 |
+
args = parser.parse_args()
|
| 112 |
+
|
| 113 |
+
WORK_ROOT.mkdir(parents=True, exist_ok=True)
|
| 114 |
+
cases = list(iter_jsonl(args.evals))
|
| 115 |
+
if args.limit is not None:
|
| 116 |
+
cases = cases[: args.limit]
|
| 117 |
+
|
| 118 |
+
results = []
|
| 119 |
+
for case in cases:
|
| 120 |
+
if args.self_check:
|
| 121 |
+
result = self_check_case(case)
|
| 122 |
+
print(json.dumps(result, indent=2))
|
| 123 |
+
results.append(result)
|
| 124 |
+
continue
|
| 125 |
+
print(f"running {case['id']}")
|
| 126 |
+
try:
|
| 127 |
+
result = run_case(case, args.profile, args.swival_bin, args.timeout)
|
| 128 |
+
except subprocess.TimeoutExpired as exc:
|
| 129 |
+
result = {
|
| 130 |
+
"id": case["id"],
|
| 131 |
+
"returncode": None,
|
| 132 |
+
"seconds": args.timeout,
|
| 133 |
+
"passed": False,
|
| 134 |
+
"verify_errors": ["swival timed out"],
|
| 135 |
+
"stdout_tail": (exc.stdout or "")[-4000:],
|
| 136 |
+
"stderr_tail": (exc.stderr or "")[-4000:],
|
| 137 |
+
}
|
| 138 |
+
print(json.dumps(result, indent=2))
|
| 139 |
+
results.append(result)
|
| 140 |
+
|
| 141 |
+
out = ROOT / "tmp" / "swival-eval-results.json"
|
| 142 |
+
out.write_text(json.dumps(results, indent=2) + "\n")
|
| 143 |
+
failed = [r for r in results if not r["passed"]]
|
| 144 |
+
print(f"passed {len(results) - len(failed)}/{len(results)}")
|
| 145 |
+
return 1 if failed else 0
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
if __name__ == "__main__":
|
| 149 |
+
raise SystemExit(main())
|
scripts/validate_codex_dataset.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
from collections import Counter
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
+
INVENTORY = ROOT / "data" / "codex_tool_inventory.json"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def load_inventory() -> dict[str, dict[str, Any]]:
|
| 16 |
+
blob = json.loads(INVENTORY.read_text())
|
| 17 |
+
return {tool["name"]: tool for tool in blob["tools"]}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def iter_jsonl(path: Path):
|
| 21 |
+
with path.open() as f:
|
| 22 |
+
for line_no, line in enumerate(f, 1):
|
| 23 |
+
if line.strip():
|
| 24 |
+
yield line_no, json.loads(line)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate_training(path: Path, inventory: dict[str, dict[str, Any]]) -> list[str]:
|
| 28 |
+
errors: list[str] = []
|
| 29 |
+
coverage: Counter[str] = Counter()
|
| 30 |
+
for line_no, row in iter_jsonl(path):
|
| 31 |
+
messages = row.get("messages")
|
| 32 |
+
if not isinstance(messages, list) or not messages:
|
| 33 |
+
errors.append(f"{path}:{line_no}: missing messages")
|
| 34 |
+
continue
|
| 35 |
+
has_call = False
|
| 36 |
+
for msg in messages:
|
| 37 |
+
if msg.get("role") != "assistant":
|
| 38 |
+
continue
|
| 39 |
+
for tc in msg.get("tool_calls") or []:
|
| 40 |
+
has_call = True
|
| 41 |
+
fn = tc.get("function") or {}
|
| 42 |
+
name = fn.get("name")
|
| 43 |
+
if name not in inventory:
|
| 44 |
+
errors.append(f"{path}:{line_no}: unknown tool {name!r}")
|
| 45 |
+
continue
|
| 46 |
+
coverage[name] += 1
|
| 47 |
+
try:
|
| 48 |
+
args = json.loads(fn.get("arguments"))
|
| 49 |
+
except Exception as exc:
|
| 50 |
+
errors.append(f"{path}:{line_no}: bad JSON arguments for {name}: {exc}")
|
| 51 |
+
continue
|
| 52 |
+
if not isinstance(args, dict):
|
| 53 |
+
errors.append(f"{path}:{line_no}: {name} arguments must be an object")
|
| 54 |
+
continue
|
| 55 |
+
for required in inventory[name].get("required", []):
|
| 56 |
+
if required not in args:
|
| 57 |
+
errors.append(f"{path}:{line_no}: {name} missing required argument {required}")
|
| 58 |
+
if not has_call:
|
| 59 |
+
errors.append(f"{path}:{line_no}: example has no assistant tool call")
|
| 60 |
+
missing = sorted(set(inventory) - set(coverage))
|
| 61 |
+
if missing:
|
| 62 |
+
errors.append(f"{path}: missing Codex tool coverage: {', '.join(missing)}")
|
| 63 |
+
return errors
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def validate_eval(path: Path) -> list[str]:
|
| 67 |
+
errors: list[str] = []
|
| 68 |
+
for line_no, row in iter_jsonl(path):
|
| 69 |
+
if not row.get("id") or not row.get("prompt"):
|
| 70 |
+
errors.append(f"{path}:{line_no}: eval row needs id and prompt")
|
| 71 |
+
if not isinstance(row.get("files"), dict):
|
| 72 |
+
errors.append(f"{path}:{line_no}: eval row needs files object")
|
| 73 |
+
if not any(key in row for key in ["verify", "verify_contains", "verify_missing", "verify_command", "verify_json"]):
|
| 74 |
+
errors.append(f"{path}:{line_no}: eval row has no verifier")
|
| 75 |
+
for event_type in row.get("expected_events") or []:
|
| 76 |
+
if not isinstance(event_type, str) or not event_type:
|
| 77 |
+
errors.append(f"{path}:{line_no}: expected_events must be non-empty strings")
|
| 78 |
+
return errors
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def main() -> int:
|
| 82 |
+
parser = argparse.ArgumentParser()
|
| 83 |
+
parser.add_argument("path", type=Path)
|
| 84 |
+
args = parser.parse_args()
|
| 85 |
+
|
| 86 |
+
if args.path.name.endswith("_eval.jsonl"):
|
| 87 |
+
errors = validate_eval(args.path)
|
| 88 |
+
else:
|
| 89 |
+
errors = validate_training(args.path, load_inventory())
|
| 90 |
+
if errors:
|
| 91 |
+
for error in errors:
|
| 92 |
+
print(error)
|
| 93 |
+
return 1
|
| 94 |
+
print(f"ok: {args.path}")
|
| 95 |
+
return 0
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
raise SystemExit(main())
|
scripts/validate_opencode_dataset.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
from collections import Counter
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
+
INVENTORY = ROOT / "data" / "opencode_tool_inventory.json"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def load_inventory() -> dict[str, dict[str, Any]]:
|
| 16 |
+
blob = json.loads(INVENTORY.read_text())
|
| 17 |
+
return {tool["name"]: tool for tool in blob["tools"]}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def iter_jsonl(path: Path):
|
| 21 |
+
with path.open() as f:
|
| 22 |
+
for line_no, line in enumerate(f, 1):
|
| 23 |
+
if line.strip():
|
| 24 |
+
yield line_no, json.loads(line)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate_training(path: Path, inventory: dict[str, dict[str, Any]]) -> list[str]:
|
| 28 |
+
errors: list[str] = []
|
| 29 |
+
coverage: Counter[str] = Counter()
|
| 30 |
+
for line_no, row in iter_jsonl(path):
|
| 31 |
+
messages = row.get("messages")
|
| 32 |
+
if not isinstance(messages, list) or not messages:
|
| 33 |
+
errors.append(f"{path}:{line_no}: missing messages")
|
| 34 |
+
continue
|
| 35 |
+
has_call = False
|
| 36 |
+
for msg in messages:
|
| 37 |
+
if msg.get("role") != "assistant":
|
| 38 |
+
continue
|
| 39 |
+
for tc in msg.get("tool_calls") or []:
|
| 40 |
+
has_call = True
|
| 41 |
+
fn = tc.get("function") or {}
|
| 42 |
+
name = fn.get("name")
|
| 43 |
+
if name not in inventory:
|
| 44 |
+
errors.append(f"{path}:{line_no}: unknown tool {name!r}")
|
| 45 |
+
continue
|
| 46 |
+
coverage[name] += 1
|
| 47 |
+
try:
|
| 48 |
+
args = json.loads(fn.get("arguments"))
|
| 49 |
+
except Exception as exc:
|
| 50 |
+
errors.append(f"{path}:{line_no}: bad JSON arguments for {name}: {exc}")
|
| 51 |
+
continue
|
| 52 |
+
if not isinstance(args, dict):
|
| 53 |
+
errors.append(f"{path}:{line_no}: {name} arguments must be an object")
|
| 54 |
+
continue
|
| 55 |
+
for required in inventory[name].get("required", []):
|
| 56 |
+
if required not in args:
|
| 57 |
+
errors.append(f"{path}:{line_no}: {name} missing required argument {required}")
|
| 58 |
+
if not has_call:
|
| 59 |
+
errors.append(f"{path}:{line_no}: example has no assistant tool call")
|
| 60 |
+
missing = sorted(set(inventory) - set(coverage))
|
| 61 |
+
if missing:
|
| 62 |
+
errors.append(f"{path}: missing opencode tool coverage: {', '.join(missing)}")
|
| 63 |
+
return errors
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def validate_eval(path: Path, inventory: dict[str, dict[str, Any]]) -> list[str]:
|
| 67 |
+
errors: list[str] = []
|
| 68 |
+
for line_no, row in iter_jsonl(path):
|
| 69 |
+
if not row.get("id") or not row.get("prompt"):
|
| 70 |
+
errors.append(f"{path}:{line_no}: eval row needs id and prompt")
|
| 71 |
+
if not isinstance(row.get("files"), dict):
|
| 72 |
+
errors.append(f"{path}:{line_no}: eval row needs files object")
|
| 73 |
+
for name in row.get("expected_tools") or []:
|
| 74 |
+
if name not in inventory:
|
| 75 |
+
errors.append(f"{path}:{line_no}: unknown expected tool {name}")
|
| 76 |
+
if not any(key in row for key in ["verify", "verify_contains", "verify_missing", "verify_command"]):
|
| 77 |
+
errors.append(f"{path}:{line_no}: eval row has no verifier")
|
| 78 |
+
return errors
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def main() -> int:
|
| 82 |
+
parser = argparse.ArgumentParser()
|
| 83 |
+
parser.add_argument("path", type=Path)
|
| 84 |
+
args = parser.parse_args()
|
| 85 |
+
|
| 86 |
+
inventory = load_inventory()
|
| 87 |
+
if args.path.name.endswith("_eval.jsonl"):
|
| 88 |
+
errors = validate_eval(args.path, inventory)
|
| 89 |
+
else:
|
| 90 |
+
errors = validate_training(args.path, inventory)
|
| 91 |
+
if errors:
|
| 92 |
+
for error in errors:
|
| 93 |
+
print(error)
|
| 94 |
+
return 1
|
| 95 |
+
print(f"ok: {args.path}")
|
| 96 |
+
return 0
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
raise SystemExit(main())
|
scripts/validate_swival_dataset.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
from collections import Counter
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
+
INVENTORY = ROOT / "data" / "swival_tool_inventory.json"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def load_inventory() -> dict[str, dict[str, Any]]:
|
| 16 |
+
blob = json.loads(INVENTORY.read_text())
|
| 17 |
+
return {tool["name"]: tool for tool in blob["tools"]}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def iter_jsonl(path: Path):
|
| 21 |
+
with path.open() as f:
|
| 22 |
+
for line_no, line in enumerate(f, 1):
|
| 23 |
+
if line.strip():
|
| 24 |
+
yield line_no, json.loads(line)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate_training(path: Path, inventory: dict[str, dict[str, Any]]) -> list[str]:
|
| 28 |
+
errors: list[str] = []
|
| 29 |
+
coverage: Counter[str] = Counter()
|
| 30 |
+
for line_no, row in iter_jsonl(path):
|
| 31 |
+
messages = row.get("messages")
|
| 32 |
+
if not isinstance(messages, list) or not messages:
|
| 33 |
+
errors.append(f"{path}:{line_no}: missing messages")
|
| 34 |
+
continue
|
| 35 |
+
for msg in messages:
|
| 36 |
+
if msg.get("role") == "assistant":
|
| 37 |
+
for tc in msg.get("tool_calls") or []:
|
| 38 |
+
fn = tc.get("function") or {}
|
| 39 |
+
name = fn.get("name")
|
| 40 |
+
if name not in inventory:
|
| 41 |
+
errors.append(f"{path}:{line_no}: unknown tool {name!r}")
|
| 42 |
+
continue
|
| 43 |
+
coverage[name] += 1
|
| 44 |
+
raw_args = fn.get("arguments")
|
| 45 |
+
try:
|
| 46 |
+
args = json.loads(raw_args)
|
| 47 |
+
except Exception as exc:
|
| 48 |
+
errors.append(f"{path}:{line_no}: bad JSON arguments for {name}: {exc}")
|
| 49 |
+
continue
|
| 50 |
+
if not isinstance(args, dict):
|
| 51 |
+
errors.append(f"{path}:{line_no}: arguments for {name} must be an object")
|
| 52 |
+
continue
|
| 53 |
+
for required in inventory[name].get("required", []):
|
| 54 |
+
if required not in args:
|
| 55 |
+
errors.append(f"{path}:{line_no}: {name} missing required argument {required}")
|
| 56 |
+
if not any((msg.get("tool_calls") for msg in messages if msg.get("role") == "assistant")):
|
| 57 |
+
errors.append(f"{path}:{line_no}: example has no assistant tool call")
|
| 58 |
+
|
| 59 |
+
missing = sorted(set(inventory) - set(coverage))
|
| 60 |
+
if missing:
|
| 61 |
+
errors.append(f"{path}: missing tool coverage: {', '.join(missing)}")
|
| 62 |
+
return errors
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def validate_eval(path: Path, inventory: dict[str, dict[str, Any]]) -> list[str]:
|
| 66 |
+
errors: list[str] = []
|
| 67 |
+
for line_no, row in iter_jsonl(path):
|
| 68 |
+
if not row.get("id") or not row.get("prompt"):
|
| 69 |
+
errors.append(f"{path}:{line_no}: eval row needs id and prompt")
|
| 70 |
+
if not isinstance(row.get("files"), dict):
|
| 71 |
+
errors.append(f"{path}:{line_no}: eval row needs files object")
|
| 72 |
+
expected = row.get("expected_tools") or []
|
| 73 |
+
for name in expected:
|
| 74 |
+
if name not in inventory:
|
| 75 |
+
errors.append(f"{path}:{line_no}: unknown expected tool {name}")
|
| 76 |
+
if not any(key in row for key in ["verify", "verify_contains", "verify_missing", "verify_command"]):
|
| 77 |
+
errors.append(f"{path}:{line_no}: eval row has no verifier")
|
| 78 |
+
return errors
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def main() -> int:
|
| 82 |
+
parser = argparse.ArgumentParser()
|
| 83 |
+
parser.add_argument("path", type=Path)
|
| 84 |
+
args = parser.parse_args()
|
| 85 |
+
|
| 86 |
+
inventory = load_inventory()
|
| 87 |
+
if args.path.name.endswith("_eval.jsonl"):
|
| 88 |
+
errors = validate_eval(args.path, inventory)
|
| 89 |
+
else:
|
| 90 |
+
errors = validate_training(args.path, inventory)
|
| 91 |
+
|
| 92 |
+
if errors:
|
| 93 |
+
for err in errors:
|
| 94 |
+
print(err)
|
| 95 |
+
return 1
|
| 96 |
+
print(f"ok: {args.path}")
|
| 97 |
+
return 0
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
raise SystemExit(main())
|
swival/eval.jsonl
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id":"eval-edit-line-number","prompt":"In settings.py, change only the second timeout value from 5 to 10. Do not change the first timeout.","files":{"settings.py":"timeout = 5\nretries = 2\ntimeout = 5\n"},"verify":{"settings.py":"timeout = 5\nretries = 2\ntimeout = 10\n"},"expected_tools":["read_file","edit_file"]}
|
| 2 |
+
{"id":"eval-grep-edit-test","prompt":"Find the Python function that accepts empty names, make it reject empty strings, and run `python3 -m pytest tests/test_names.py`.","files":{"src/names.py":"class NameError(Exception):\n pass\n\n\ndef normalize_name(name):\n if name is None:\n raise NameError('missing')\n return name.strip()\n","tests/test_names.py":"from src.names import NameError, normalize_name\n\n\ndef test_empty_name_rejected():\n try:\n normalize_name(' ')\n except NameError:\n return\n raise AssertionError('empty name accepted')\n","pytest.py":"import importlib.util\nimport pathlib\nimport sys\n\nfailed = 0\nfor raw in sys.argv[1:]:\n path = pathlib.Path(raw)\n spec = importlib.util.spec_from_file_location(path.stem, path)\n mod = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(mod)\n for name in dir(mod):\n if name.startswith(\"test_\"):\n try:\n getattr(mod, name)()\n except Exception as exc:\n failed = 1\n print(f\"FAILED {raw}::{name}: {exc}\")\nif failed:\n sys.exit(1)\nprint(\"passed\")\n","pyproject.toml":"[tool.pytest.ini_options]\npythonpath = ['.']\n"},"verify":{"src/names.py":"class NameError(Exception):\n pass\n\n\ndef normalize_name(name):\n if name is None:\n raise NameError('missing')\n normalized = name.strip()\n if not normalized:\n raise NameError('missing')\n return normalized\n"},"expected_tools":["grep","read_file","edit_file","run_command"]}
|
| 3 |
+
{"id":"eval-batch-read-write","prompt":"Read README.md and pyproject.toml, then create docs/summary.md with the project name and one-sentence description.","files":{"README.md":"# Widget\n\nA tiny request router.\n","pyproject.toml":"[project]\nname = 'widget'\n"},"verify_contains":{"docs/summary.md":["widget","tiny request router"]},"expected_tools":["read_multiple_files","write_file"]}
|
| 4 |
+
{"id":"eval-delete-obsolete","prompt":"Delete obsolete.py and leave keep.py alone.","files":{"obsolete.py":"print('old')\n","keep.py":"print('keep')\n"},"verify_missing":["obsolete.py"],"verify":{"keep.py":"print('keep')\n"},"expected_tools":["delete_file"]}
|
| 5 |
+
{"id":"eval-command-argv","prompt":"Run the test command `python3 -m pytest tests/test_math.py` and report whether it passed. Use argv form, not a shell string.","files":{"mathlib.py":"def add(a, b):\n return a + b\n","tests/test_math.py":"from mathlib import add\n\n\ndef test_add():\n assert add(2, 3) == 5\n","pytest.py":"import importlib.util\nimport pathlib\nimport sys\n\nfailed = 0\nfor raw in sys.argv[1:]:\n path = pathlib.Path(raw)\n spec = importlib.util.spec_from_file_location(path.stem, path)\n mod = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(mod)\n for name in dir(mod):\n if name.startswith(\"test_\"):\n try:\n getattr(mod, name)()\n except Exception as exc:\n failed = 1\n print(f\"FAILED {raw}::{name}: {exc}\")\nif failed:\n sys.exit(1)\nprint(\"passed\")\n"},"verify_command":["python3","-m","pytest","tests/test_math.py"],"expected_tools":["run_command"]}
|
swival/tool_inventory.json
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "/Users/j/src/swival/swival/tools.py",
|
| 3 |
+
"tools": [
|
| 4 |
+
{
|
| 5 |
+
"name": "a2a__reviewer",
|
| 6 |
+
"description": "Representative dynamic Swival integration tool.",
|
| 7 |
+
"required": [
|
| 8 |
+
"message"
|
| 9 |
+
],
|
| 10 |
+
"properties": [
|
| 11 |
+
"message",
|
| 12 |
+
"context_id",
|
| 13 |
+
"task_id"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"name": "check_subagents",
|
| 18 |
+
"description": "Runtime conditional Swival subagent tool.",
|
| 19 |
+
"required": [
|
| 20 |
+
"action"
|
| 21 |
+
],
|
| 22 |
+
"properties": [
|
| 23 |
+
"action",
|
| 24 |
+
"subagent_id",
|
| 25 |
+
"timeout"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "complete_goal",
|
| 30 |
+
"description": "Mark the active goal complete. ONLY call this after running a completion audit that maps every explicit requirement in the objective to real evidence in the workspace (files, command output, test results). If you are blocked or need user input, do NOT call this \u2014 return final text explaining the blocker instead.",
|
| 31 |
+
"required": [],
|
| 32 |
+
"properties": []
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"name": "delete_file",
|
| 36 |
+
"description": "Delete a file by moving it to the trash. Cannot delete directories.",
|
| 37 |
+
"required": [
|
| 38 |
+
"file_path"
|
| 39 |
+
],
|
| 40 |
+
"properties": [
|
| 41 |
+
"file_path"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "edit_file",
|
| 46 |
+
"description": "Replace old_string with new_string in an existing file. Prefer over write_file for edits.",
|
| 47 |
+
"required": [
|
| 48 |
+
"file_path",
|
| 49 |
+
"old_string",
|
| 50 |
+
"new_string"
|
| 51 |
+
],
|
| 52 |
+
"properties": [
|
| 53 |
+
"checksum",
|
| 54 |
+
"file_path",
|
| 55 |
+
"line_number",
|
| 56 |
+
"new_string",
|
| 57 |
+
"old_string",
|
| 58 |
+
"replace_all"
|
| 59 |
+
]
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "fetch_url",
|
| 63 |
+
"description": "GET an HTTP/HTTPS URL, returned as markdown, text, or html.",
|
| 64 |
+
"required": [
|
| 65 |
+
"url"
|
| 66 |
+
],
|
| 67 |
+
"properties": [
|
| 68 |
+
"format",
|
| 69 |
+
"timeout",
|
| 70 |
+
"url"
|
| 71 |
+
]
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "grep",
|
| 75 |
+
"description": "Search file contents with a Python regex. Returns matches grouped by file with line numbers.",
|
| 76 |
+
"required": [
|
| 77 |
+
"pattern"
|
| 78 |
+
],
|
| 79 |
+
"properties": [
|
| 80 |
+
"case_insensitive",
|
| 81 |
+
"context_lines",
|
| 82 |
+
"include",
|
| 83 |
+
"path",
|
| 84 |
+
"pattern"
|
| 85 |
+
]
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"name": "list_files",
|
| 89 |
+
"description": "Recursively list files matching a glob, relative to the base directory.",
|
| 90 |
+
"required": [
|
| 91 |
+
"pattern"
|
| 92 |
+
],
|
| 93 |
+
"properties": [
|
| 94 |
+
"path",
|
| 95 |
+
"pattern"
|
| 96 |
+
]
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"name": "mcp__docs__search",
|
| 100 |
+
"description": "Representative dynamic Swival integration tool.",
|
| 101 |
+
"required": [
|
| 102 |
+
"query"
|
| 103 |
+
],
|
| 104 |
+
"properties": [
|
| 105 |
+
"query",
|
| 106 |
+
"limit"
|
| 107 |
+
]
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "outline",
|
| 111 |
+
"description": "Show classes, functions, and top-level declarations with line numbers (no bodies). Survey code before reading specific sections. Pass file_path for one file or directory, or files for a batch.",
|
| 112 |
+
"required": [],
|
| 113 |
+
"properties": [
|
| 114 |
+
"depth",
|
| 115 |
+
"file_path",
|
| 116 |
+
"files"
|
| 117 |
+
]
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"name": "read_file",
|
| 121 |
+
"description": "Read a file as numbered lines. Use offset/limit to paginate forward, or tail_lines=N for the file end. Truncated output shows the next offset. Also lists directories. A [checksum=...] trailer is appended for files; pass that checksum to a later edit_file call to guard against the file changing between read and edit.",
|
| 122 |
+
"required": [
|
| 123 |
+
"file_path"
|
| 124 |
+
],
|
| 125 |
+
"properties": [
|
| 126 |
+
"file_path",
|
| 127 |
+
"limit",
|
| 128 |
+
"offset",
|
| 129 |
+
"tail_lines"
|
| 130 |
+
]
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"name": "read_multiple_files",
|
| 134 |
+
"description": "Prefer this over multiple read_file calls when you know which files you need. Reads a batch, each with optional offset/limit/tail_lines. Per-file errors are inline; the batch never fails as a whole.",
|
| 135 |
+
"required": [
|
| 136 |
+
"files"
|
| 137 |
+
],
|
| 138 |
+
"properties": [
|
| 139 |
+
"files"
|
| 140 |
+
]
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"name": "run_command",
|
| 144 |
+
"description": "Run a command and return its output. Only whitelisted commands are allowed.",
|
| 145 |
+
"required": [
|
| 146 |
+
"command"
|
| 147 |
+
],
|
| 148 |
+
"properties": [
|
| 149 |
+
"background",
|
| 150 |
+
"command",
|
| 151 |
+
"timeout"
|
| 152 |
+
]
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"name": "run_metaskill",
|
| 156 |
+
"description": "Run a dynamic skill workflow by name.",
|
| 157 |
+
"required": [
|
| 158 |
+
"name",
|
| 159 |
+
"input"
|
| 160 |
+
],
|
| 161 |
+
"properties": [
|
| 162 |
+
"input",
|
| 163 |
+
"max_ask_calls",
|
| 164 |
+
"max_command_calls",
|
| 165 |
+
"name"
|
| 166 |
+
]
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"name": "run_shell_command",
|
| 170 |
+
"description": "Run a shell command string and return its output. Supports pipes, redirects, &&, and other shell syntax.",
|
| 171 |
+
"required": [
|
| 172 |
+
"command"
|
| 173 |
+
],
|
| 174 |
+
"properties": [
|
| 175 |
+
"background",
|
| 176 |
+
"command",
|
| 177 |
+
"timeout"
|
| 178 |
+
]
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"name": "snapshot",
|
| 182 |
+
"description": "Collapse prior exploration turns into a compact summary to free context. save sets a checkpoint; restore replaces the turns since with your summary.",
|
| 183 |
+
"required": [
|
| 184 |
+
"action"
|
| 185 |
+
],
|
| 186 |
+
"properties": [
|
| 187 |
+
"action",
|
| 188 |
+
"force",
|
| 189 |
+
"label",
|
| 190 |
+
"summary"
|
| 191 |
+
]
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"name": "spawn_subagent",
|
| 195 |
+
"description": "Runtime conditional Swival subagent tool.",
|
| 196 |
+
"required": [
|
| 197 |
+
"task"
|
| 198 |
+
],
|
| 199 |
+
"properties": [
|
| 200 |
+
"task",
|
| 201 |
+
"max_turns",
|
| 202 |
+
"system_hint"
|
| 203 |
+
]
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"name": "think",
|
| 207 |
+
"description": "Private scratchpad for planning, debugging, or weighing alternatives. Use before complex actions.",
|
| 208 |
+
"required": [
|
| 209 |
+
"thought"
|
| 210 |
+
],
|
| 211 |
+
"properties": [
|
| 212 |
+
"branch_from_thought",
|
| 213 |
+
"branch_id",
|
| 214 |
+
"mode",
|
| 215 |
+
"next_thought_needed",
|
| 216 |
+
"revises_thought",
|
| 217 |
+
"thought",
|
| 218 |
+
"thought_number",
|
| 219 |
+
"total_thoughts"
|
| 220 |
+
]
|
| 221 |
+
},
|
| 222 |
+
{
|
| 223 |
+
"name": "todo",
|
| 224 |
+
"description": "Persistent checklist for multi-step work. Add items as discovered, mark done as completed. Survives context compaction.",
|
| 225 |
+
"required": [
|
| 226 |
+
"action"
|
| 227 |
+
],
|
| 228 |
+
"properties": [
|
| 229 |
+
"action",
|
| 230 |
+
"tasks"
|
| 231 |
+
]
|
| 232 |
+
},
|
| 233 |
+
{
|
| 234 |
+
"name": "use_skill",
|
| 235 |
+
"description": "Activate a skill to get detailed instructions for a specific task.",
|
| 236 |
+
"required": [
|
| 237 |
+
"name"
|
| 238 |
+
],
|
| 239 |
+
"properties": [
|
| 240 |
+
"name"
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"name": "view_image",
|
| 245 |
+
"description": "View an image file (PNG, JPEG, GIF, WebP, BMP).",
|
| 246 |
+
"required": [
|
| 247 |
+
"image_path"
|
| 248 |
+
],
|
| 249 |
+
"properties": [
|
| 250 |
+
"image_path",
|
| 251 |
+
"question"
|
| 252 |
+
]
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
"name": "write_file",
|
| 256 |
+
"description": "Create or overwrite a file with content, or atomically rename move_from to file_path (not both). Parent directories are created.",
|
| 257 |
+
"required": [
|
| 258 |
+
"file_path"
|
| 259 |
+
],
|
| 260 |
+
"properties": [
|
| 261 |
+
"content",
|
| 262 |
+
"file_path",
|
| 263 |
+
"move_from"
|
| 264 |
+
]
|
| 265 |
+
}
|
| 266 |
+
]
|
| 267 |
+
}
|
swival/train.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|