Metadata-Version: 2.4
Name: goaloop
Version: 0.1.1
Summary: Goal-driven multi-attempt iteration loop driven by `claude -p`
Author: luohaha
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/luohaha/GoaLoop
Project-URL: Repository, https://github.com/luohaha/GoaLoop
Keywords: claude,claude-code,agent,automation,iteration,goal-driven
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Build Tools
Classifier: Operating System :: POSIX
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: python-dotenv>=1.0
Dynamic: license-file

<p align="center">
  <img src="docs/assets/logo.png" alt="GoaLoop" width="160">
</p>

<h1 align="center">GoaLoop</h1>

> The discipline layer for loop engineering — turn "iterate until it's
> right" into a verifiable protocol.

GoaLoop turns "iterate until the target is met" into a small, sharp
protocol on top of Claude Code. You write a `goal.md` that spells out
what "done" looks like and how to verify it. A small background
orchestrator then runs each attempt as a fresh **`claude -p` Runner** —
read context, verify, advance by one unit if needed, record — until the
verification passes or you stop it.

The framework is a lean Python package (`goaloop`: a `claude -p` adapter,
the attempt loop, and a `run`/`status`/`stop`/`continue` CLI) plus the
Claude Code skills and the Runner's system prompt. The orchestrator is
detached, so it keeps iterating even if you close the Claude Code session
that started it. On a Claude Code subscription, `claude -p` is
subscription-covered — no per-token API rates.

## Why

Many software engineering tasks share the same shape — define a
target, iterate, verify, repeat:

- Performance optimization
- Flaky test reduction
- Build-time optimization
- ML hyperparameter or model tuning
- Writing iteration (until a rubric passes)
- Cost optimization
- Security hardening

Existing tools for this pattern tend to bake in domain assumptions like
"artifact = GitHub PR" and "isolation = git worktree". GoaLoop makes no
domain assumptions — your `goal.md` and its verification scripts carry
all the domain knowledge.

Writing a loop is trivial; making it *trustworthy* is not. The goal is
for GoaLoop to be the foundational framework for **loop engineering** —
the place where ad-hoc "keep trying until it works" scripts become an
engineered protocol: goal-defined, independently verified, resumable,
and safe to leave running unattended.

See [`docs/design.md`](docs/design.md) for the full design and
rationale.

## Architecture in one picture

<p align="center">
  <img src="docs/assets/architecture.png" alt="GoaLoop architecture: a Manager starts an Orchestrator, which spawns a fresh Runner per attempt; each Runner verifies, and on fail the loop spawns the next Runner until it passes" width="640">
</p>

Three layers: a **Manager** — the Claude Code agent you operate — starts
the **Orchestrator** (a detached loop, not an LLM), which spawns a fresh
**Runner** agent (`claude -p`) for each attempt. Every Runner verifies the
current state — on `pass` the loop exits; on `fail` it advances one unit
and the Orchestrator spawns the next Runner. The loop repeats until the
verification passes.

## Install

Two pieces, two commands: install the `goaloop` CLI (the orchestrator),
then deploy the Claude Code skills (the Manager front-end). Both ship in
the package — no source checkout needed.

```bash
uv tool install goaloop      # provides the `goaloop` command (stdlib-only, Python ≥ 3.10)
goaloop install              # deploys /goal-init, /goal-run, /goal-flash + the goal-runner agent into ~/.claude
```

`uvx goaloop ...` works too if you prefer not to install persistently;
`pip install goaloop` is equivalent if you don't use uv. The Runner's
system prompt ships inside the package (override with
`GOALOOP_RUNNER_PROMPT`). The CLI shells out to `claude`, so the Claude
Code CLI must be on your `PATH` and authenticated.

`goaloop install` skips any skill/agent that already exists; pass
`--force` to overwrite. Verify by opening Claude Code and typing
`/goal-init` — it should be recognized. (You can also drive the
orchestrator entirely from the shell with `goaloop run`, skipping the
skills.)

<details>
<summary>From source (development)</summary>

```bash
git clone https://github.com/luohaha/GoaLoop ~/GoaLoop
uv pip install -e ~/GoaLoop      # or: pip install -e ~/GoaLoop
goaloop install                  # same skill/agent deploy as above
# run without installing:  python3 -m goaloop ...  (from ~/GoaLoop)
```
</details>

## Quickstart

```
> /goal-init
```

Claude interviews you with seven questions: workspace name (the
workspace lives at `~/.goaloop/<name>`), objective, hard constraints,
how to verify the objective (concretely!), how to verify each
constraint, what environment/tools the verification needs, and any
initial context.

The interview is **strict** about getting concrete verification — if
you can't articulate a real check, GoaLoop refuses to write the
`goal.md`. That refusal is the point: a goal you can't verify is a
goal you can't reach.

When the interview completes, your workspace looks like:

```
<workspace>/
├── goal.md           # the spec — edit it mid-run if you want
├── memory/           # Runner-curated knowledge accumulates here
└── attempts/         # one file per attempt, write-once audit trail
```

Then start it (either way):

```
> /goal-run                  # via Claude Code: starts the orchestrator, relays status
$ goaloop run <name>         # or straight from the shell
```

### Fast path: `/goal-flash`

When the task is already clear enough to state in a sentence, the
seven-question interview is overkill. `/goal-flash <one-line task>`
infers a complete `goal.md` in one shot (workspace name, constraints,
environment — all derived; no question-at-a-time), shows it to you, and
starts the orchestrator immediately. The same hard rule still applies:
if a concrete verification can't be inferred, it refuses and sends you
to `/goal-init` rather than fabricating one. Since the goal was inferred,
`goal.md` stays the steering wheel — edit it mid-run if the inference was
off, or `goaloop stop`.

## Running

GoaLoop runs as a single self-driven loop — the `goaloop run`
orchestrator (a deterministic process, not an LLM). It is not wrapped in
`/loop`: in the default `auto` mode it paces itself between attempts
(`--interval`, default 30s), runs each attempt as a fresh `claude -p`
Runner, and exits on `pass`. Because it's a detached process, it keeps
going even if you close Claude Code.

```
> /goal-run                  # start + watch from Claude Code
$ goaloop status <name>      # check on it from the shell
$ tail -f ~/.goaloop/<name>/.goaloop/orchestrator.log   # watch live
$ goaloop continue <name>    # release the next attempt (copilot mode)
$ goaloop stop <name>        # stop early
```

The orchestrator terminates when:

- The Runner reports `pass` — goal met; the process exits.
- The Runner reports `blocked` — it judges the goal unreachable without a
  human; the process exits and `/goal-run` quotes the reason.
- It gives up with `error` after bounded retries of malformed / failing
  attempts (a broken-Runner guard, not a goal condition).
- You run `goaloop stop <name>` (SIGTERM).

(An API `quota` limit is not a stop — the orchestrator sleeps and resumes
the same session indefinitely.)

You stay in control throughout: read what each attempt did via
`/goal-run` or `goaloop status`; **edit `goal.md`** for a permanent
change or **drop a `suggestions/NNN.md`** note for a transient per-attempt
nudge — the Runner of that attempt reads it. There's no live conversation into
a running Runner.

### Configuration & modes

An optional `<workspace>/config.yaml` sets defaults with flat keys —
`model` (model id for `claude -p`), `interval` (seconds between attempts,
default 30), and `mode` (`auto` default, or `copilot`). CLI flags
(`--model`, `--interval`, `--mode`) override `config.yaml`, which
overrides the built-in defaults.

In **copilot mode** the orchestrator pauses after each `advanced` attempt
and waits for your approval before the next one; release it with
`goaloop continue <name>`. (`pass`/`blocked`/`error` are terminal, and
`in_progress` resumes automatically — only `advanced` waits.)

`suggestions/` is an optional async channel — a directory parallel to
`attempts/`: the Runner of attempt NNN reads `suggestions/NNN.md` at the start
of that attempt, so the manager drops a note named for the round that will read
it (e.g. `suggestions/006.md` while attempt 005 runs). The file stays in place
afterward as part of the audit trail. Use `goal.md` for permanent/structural
changes, `suggestions/` for transient nudges (e.g. left while AFK).

## Workspace contents

After running, the workspace looks like:

```
<workspace>/
├── goal.md
├── config.yaml           # optional: model / interval / mode / caps
├── suggestions/          # optional: per-attempt human notes (NNN.md read by attempt NNN)
├── memory/
│   └── learnings.md      # ~4KB cap; Runner curates this
└── attempts/
    ├── 001.md            # one Markdown file per attempt
    ├── 002.md
    └── ...
```

- **`goal.md`** is the authoritative spec. Edit it mid-run to change
  the target or constraints — the next attempt picks it up.
- **`memory/learnings.md`** is the Runner's "textbook" — validated
  approaches, ruled-out hypotheses, surprising observations.
- **`attempts/NNN.md`** is the audit trail. Each Runner writes one
  and never modifies others. ~30 lines each.

## Design highlights

- **Verification is load-bearing.** The `goal.md` Verification section
  is a literal command/procedure, written by you at init time. The
  Runner executes it; never makes up a judgment.
- **Two-state verification, four terminators.** Verification itself is
  `pass` / `fail`, but each Runner ends with one of four statuses — `pass`
  (done), `advanced` (did one unit of work, go again), `in_progress`
  (paused to wait out a long pollable job, resume the same session), or
  `blocked` (stuck, needs a human). Long-running checks are completed
  inside one attempt rather than split across attempts.
- **Anti-cheat by time.** Each Runner is a fresh `claude -p` session.
  The Runner in attempt N judges what attempt N−1 left behind, with no
  shared context. Even for LLM-as-judge verification, no nested agent is
  needed — the time separation gives you arm's-length judging.
- **Honest about what the framework can enforce.** No budget caps and no
  forced attempt limits in `goal.md` — GoaLoop can read each attempt's
  reported cost but won't pretend to cap it mid-stream. The terminal states
  are `pass` (goal met), `blocked` (Runner judges it needs a human),
  `error` (the orchestrator gives up after bounded retries), and human
  `goaloop stop`.

## When NOT to use GoaLoop

- When you can't articulate a concrete verification procedure. If
  "what success looks like" is purely a human judgment call, the
  framework's load-bearing assumption breaks. Use direct conversation
  with Claude instead.
- When the iteration unit is sub-second. Spawning a `claude -p` Runner
  per attempt has a multi-second floor.
- When you need parallel exploration across independent hypotheses.
  Each orchestrator runs one Runner at a time. You can run multiple workspaces
  in parallel (`goaloop run` each), but there's no built-in coordination
  between them.

## Comparison to other tools

The closest sibling is Codex's built-in `goal` feature, which solves the
same "keep working toward a target across many turns" problem with nearly
opposite choices: an **in-process, continuation-based** loop with
self-audited completion, versus GoaLoop's **out-of-process, fresh-attempt**
loop with an externally verified gate. In short — Codex makes the agent its
own tireless project manager; GoaLoop makes the system an impartial referee
over disposable workers, with verification as a load-bearing, executable
gate rather than a self-report.

See [`docs/comparison-codex.md`](docs/comparison-codex.md) for the full
side-by-side — architecture, data model, and an in-depth look at where the
verification mechanisms diverge.

Claude Code's own built-in `/goal` command is the closest in-host sibling:
an in-process loop gated by a fresh small model that judges your condition
from the **conversation transcript** (it can't run commands itself), versus
GoaLoop's out-of-process loop gated by a fresh process that **re-runs the
check against real workspace state**. On the verification-independence axis
Claude `/goal` sits between Codex's self-audit and GoaLoop's executable
gate. See [`docs/comparison-claude-goal.md`](docs/comparison-claude-goal.md)
for the full side-by-side.

The closest competitor on verification independence is the
[pi](https://github.com/earendil-works/pi) agent's `pi-goal-x` extension:
it spawns an **independent auditor** (a separate agent with read-only tools)
that inspects the real workspace — but only **once, when the agent claims
completion**, and as a semantic LLM verdict. GoaLoop makes the same kind of
independent verification the **entrance gate of every attempt**, with a
deterministic, mandatory check and a disposable executor. See
[`docs/comparison-pi-goal.md`](docs/comparison-pi-goal.md) for the full
side-by-side (and a note on the several pi goal extensions).

## Status

v0.1. The `goaloop` loop, CLI, and skills are implemented and pass an
end-to-end smoke test; not yet battle-tested across diverse domains. The
design and rationale are in [`docs/design.md`](docs/design.md).

## License

Apache License 2.0. See [LICENSE](LICENSE).
