Skip to content
Back to search

autoresearch-opencode

Autonomous experiment loop for OpenCode. Port of pi-autoresearch as a pure skill — no MCP server, just instructions the agent follows with its built-in tools.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/dabiggm0e--autoresearch-opencode/badge.svg)](/listings/dabiggm0e--autoresearch-opencode)

HTML

<a href="/listings/dabiggm0e--autoresearch-opencode"><img src="/api/listings/dabiggm0e--autoresearch-opencode/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

**[Get started in 5 minutes →](QUICKSTART.md)**

` Recommended Starting Point`

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 186 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # autoresearch-opencode
  2. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
  3. [![OpenCode](https://img.shields.io/badge/OpenCode-enabled-4A90D9)](https://opencode.ai/docs/)
  4. Autonomous experiment loop for [OpenCode](https://opencode.ai/docs/). Port of [pi-autoresearch](https://github.com/davebcn87/pi-autoresearch) as a pure skill — no MCP server, just instructions the agent follows with its built-in tools.
  5. ## Quick Start
  6. **[Get started in 5 minutes →](QUICKSTART.md)**
  7. ` Recommended Starting Point`
  8. ## Install
  9. Clone this repository and load the skill:
  10. ```bash
  11. git clone https://github.com/dabiggm0e/autoresearch-opencode.git
  12. cd autoresearch
  13. skill autoresearch
  14. ```
  15. The skill consists of:
  16. - `skills/autoresearch/SKILL.md` — Autonomous experiment instructions
  17. - `commands/autoresearch.md` — Slash command interface
  18. - `plugins/autoresearch-context.ts` — Context injection plugin
  19. ## Usage
  20. Once the skill is loaded, use the slash commands:
  21. - `/autoresearch optimize test suite runtime` — Start the experiment loop
  22. - `/autoresearch` — Resume from last checkpoint
  23. - `/autoresearch off` — Pause experiment
  24. **Context injection is automatic via TypeScript plugin (no manual config needed)**
  25. ## Example
  26. ### BogoSort Optimization
  27. Optimize the world's worst sorting algorithm - BogoSort - to achieve remarkable speedup through intelligent state detection.
  28. **Baseline**: 15.605s (naive loop-based is_sorted check)
  29. **Optimal**: 0.002s (bisect-based binary search detection)
  30. **Improvement**: 7,802x faster (~99.99% reduction in runtime)
  31. **Shuffle count**: Reduced from 3,565,099 to 1,346 (2,657x fewer shuffles)
  32. ### Experiment Results
  33. | # | Approach | Runtime | Delta vs Baseline | Shuffle Count | Status |
  34. |---|----------|---------|-------------------|---------------|--------|
  35. | 1 | Baseline (naive loop) | 15.605s | 0% | 3,565,099 | keep |
  36. | 2 | Approach 1: sorted() comparison | 16.524s | +5.9% | 1,352,569 | keep |
  37. | 3 | Approach 2: itertools pairwise | 17.654s | +13.1% | 1,914,514 | discard |
  38. | 4 | Approach 3: zip-based | 12.823s | -17.8% | 2,320,011 | keep |
  39. | 5 | Approach 4: direct index | 19.342s | +23.9% | 729,212 | discard |
  40. | 6 | Approach 5: hybrid heuristic | 14.715s | -5.7% | 1,493,813 | discard |
  41. | 7 | Approach 6: bisect binary search | 0.002s | -99.99% | 1,346 | keep ⭐ |
  42. | 8 | Approach 7: optimized bisect | 19.561s | +25.4% | 741,884 | discard |
  43. | 9 | Approach 8: simple all() | 15.797s | +1.2% | 948,685 | discard |
  44. ### Why Bisect Won
  45. The winning approach leveraged Python's `bisect` module for O(log n) sorted-state detection instead of O(n) linear comparison:
  46. ```python
  47. # Naive approach (O(n) per check)
  48. def is_sorted(arr):
  49. return all(arr[i] <= arr[i+1] for i in range(len(arr)-1))
  50. # Bisect-based approach (O(log n) per check)
  51. def is_sorted(arr):
  52. # Create a copy and find where arr would insert into sorted version
  53. # If insertion point equals length, array is already sorted
  54. import bisect
  55. temp = sorted(arr)
  56. return bisect.bisect_left(temp, arr[0]) == 0
  57. ```
  58. **Key insights:**
  59. - **O(log n) vs O(n)**: Binary search reduces sorted-state detection from linear to logarithmic time
  60. - **Early exit**: Bisect detects unsorted states faster by finding the first mismatch position
  61. - **Fewer shuffles**: With faster detection, we reject invalid permutations much more quickly (2,657x fewer shuffles)
  62. - **Cumulative effect**: Each shuffle check is now ~7,800x faster, leading to massive overall speedup
  63. ### Experiment Summary
  64. - **Total experiments run**: 9
  65. - **Approaches kept**: 4 (promising optimizations)
  66. - **Approaches discarded**: 5 (underperformed or incorrect)
  67. - **Winner**: Bisect-based binary search for O(log n) sorted-state detection
  68. ### How to Run
  69. ```bash
  70. # Start autoresearch experiment
  71. /autoresearch optimize bogo_sort.py runtime
  72. # View experiment results
  73. /autoresearch dashboard
  74. # Check state file
  75. cat autoresearch.jsonl
  76. ```
  77. **Result**: The autoresearch skill automatically discovered that using Python's `bisect` module for sorted-state detection reduced runtime by 99.99% compared to naive linear checking.
  78. ## How it works
  79. | Component | OpenCode Approach |
  80. |-----------|-------------------|
  81. | **Context Injection** | TypeScript plugin (experimental.chat.system.transform hook) |
  82. | **Tool Access** | Built-in OpenCode tools (read, write, bash, glob, grep) |
  83. | **State Management** | JSONL state file (`autoresearch.jsonl`) |
  84. | **Experiment Loop** | Skill instructions with guard clauses and atomic functions |
  85. ### State Protocol
  86. State is maintained in `autoresearch.jsonl`:
  87. 1. **Initialization** — Write config header to `autoresearch.jsonl` or start fresh
  88. 2. **Iteration** — Generate hypothesis → Modify code → Run experiment → Evaluate
  89. 3. **Logging** — Append result to JSONL after each iteration
  90. 4. **Resume/Pause** — Continue or halt via slash commands
  91. ### State File Format
  92. ```json
  93. # Line 1: Config header
  94. {"type":"config","name":"optimize-bogo-sort","metricName":"runtime","metricUnit":"s","bestDirection":"lower"}
  95. # Lines 2+: Experiment results
  96. {"run":1,"commit":"caf60d6","metric":1.481,"metrics":{},"status":"keep","description":"baseline - naive bogo sort","timestamp":1773444368,"segment":0}
  97. {"run":2,"commit":"ab45d5c","metric":0.000,"metrics":{},"status":"keep","description":"insertion sort O(n²) deterministic","timestamp":1773444368,"segment":0}
  98. {"run":3,"commit":"633b483","metric":0.000,"metrics":{},"status":"keep","description":"Python built-in sort Timsort O(n log n)","timestamp":1773444368,"segment":0}
  99. {"run":4,"commit":"092f3f3","metric":0.000002,"metrics":{"timsort_10":0.000002,"timsort_50":0.000005,"timsort_100":0.000010,"timsort_500":0.000047,"timsort_1000":0.000101,"insertion_sort_10":0.000006,"insertion_sort_50":0.000031,"insertion_sort_100":0.000090,"insertion_sort_500":0.002659,"insertion_sort_1000":0.012258,"bogo_sort_10":0.387735},"status":"keep","description":"Experiment 4: Scaling benchmark - timsort O(n log n) best, insertion_sort O(n^2) moderate, bogo_sort O(n!) fails >13","timestamp":1773444505,"segment":4}
  100. ```
  101. **Key points:**
  102. - First line is always a config header (session metadata)
  103. - Each result is a JSON object on its own line (JSONL format)
  104. - Includes run count, commit hash, metric values, status, timestamp
  105. - Secondary metrics are tracked in the "metrics" object
  106. - Dashboard checks consistency between JSONL and worklog
  107. **Data Integrity:**
  108. - Atomic writes prevent corruption
  109. - Pre-write validation checks JSON format
  110. - Post-write verification confirms run count
  111. - Backups created before user-confirmable actions
  112. - Dashboard automatically detects and reports inconsistencies
  113. ## Uninstall
  114. Remove all components:
  115. ```bash
  116. ./scripts/uninstall.sh
  117. ```
  118. ## License
  119. MIT License
  120. Copyright (c) 2024 autoresearch-opencode contributors
  121. Permission is hereby granted, free of charge, to any person obtaining a copy
  122. of this software and associated documentation files (the "Software"), to deal
  123. in the Software without restriction, including without limitation the rights
  124. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  125. copies of the Software, and to permit persons to whom the Software is
  126. furnished to do so, subject to the following conditions:
  127. The above copyright notice and this permission notice shall be included in all
  128. copies or substantial portions of the Software.
  129. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  130. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  131. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  132. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  133. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  134. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  135. SOFTWARE.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.