Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
permissions:
contents: write
pull-requests: write
issues: write

concurrency:
group: tend
Expand Down
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ with the evidence. When an update touches nothing, it stays quiet.
model: groq/openai/gpt-oss-120b
```

Merge the workflow and tend runs once right away. Its first pull request is a
tidy-up with a short welcome: it removes dependencies nothing in the project
uses and moves the code off deprecated libraries, proven by your own tests.
Merge the workflow and tend runs once right away. It catches the project
up in at most four pull requests, one after another, each proven by your
own build and tests:

1. Fixes: security fixes, changes to the APIs your code calls, moves off
deprecated libraries, and the removal of dependencies nothing uses. When
your tests are too thin to prove the rest, this one first adds tests that
pin down how the code behaves today.
2. Runtimes and build tooling: runtime pins past their end of life, base
images, Actions, compilers and bundlers.
3. Major upgrades, a major at a time when the jump fails.
4. Migrations and replacements: wide migrations, and deprecated libraries
with no single replacement, where tend picks one itself and proves it.

After that, tend runs on a schedule and opens one PR at a time, only for
changes that touch your code.
changes that touch your code. What it could not do on its own it lists in
one tracking issue.

## What a pull request looks like

Expand Down Expand Up @@ -69,11 +81,13 @@ the first one.
uses get a PR. Plain version bumps do not, unless you turn them on.
- There is never more than one tend PR open, and it holds the whole change:
manifest, lockfile, every call site, and the tests that had to move.
- Security comes first, then API changes that break your code, then
- The catch-up comes first and carries what it can of the rest. After it,
security comes first, then API changes that break your code, then
deprecations, then breaking releases.
- When there is no single replacement, the PR changes nothing and lists the
options. Comment `tend apply 2` to pick one, `tend skip` to say no, or
`tend retry` to try again.
- When there is more than one way off something, tend takes the first its
rule allows that passes the proof, and says why. Comment `tend apply 2` to
have another, `tend skip` to say no, or `tend retry` to try again. Only
when none passes does the PR change nothing and list the options.
- Releases younger than three days wait, except security fixes, deprecations
and API changes.

Expand All @@ -90,7 +104,9 @@ deliver: {automerge: security}
```

[docs/config.md](docs/config.md) describes every key. `deliver: {mode: commit}`
commits to the branch instead of opening PRs.
commits to the branch instead of opening PRs, and keeps a repo current with
no one watching: it pushes only what passed its proof, waits for your CI on
each commit, and reverts its own commit when CI fails on it.

## Running it locally

Expand Down
16 changes: 13 additions & 3 deletions action/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ tags() {
}

# An explicit version wins. Then a full tag in the action ref. Then the newest
# release inside the ref's major (uses: ...@v1), else the newest release.
# release inside the ref's major (uses: ...@v1), followed by the one before
# it, else the newest release.
resolve() {
local major list
if [ -n "${1:-}" ]; then
Expand All @@ -40,7 +41,7 @@ resolve() {
v[0-9]*)
major=${ref%%.*}
list=$(api_get "$api/repos/$repo/releases?per_page=100" | tags) || die "could not list releases of $repo"
{ echo "$list" | grep -E "^${major}\.[0-9]+\.[0-9]+\$" || true; } | sort -t. -k2,2n -k3,3n | tail -n 1
{ echo "$list" | grep -E "^${major}\.[0-9]+\.[0-9]+\$" || true; } | sort -t. -k2,2nr -k3,3nr | head -n 2
return
;;
esac
Expand All @@ -66,8 +67,17 @@ sha256_of() {
fi
}

tag=$(resolve "${1:-}")
tags=$(resolve "${1:-}")
tag=$(echo "$tags" | sed -n 1p)
[ -n "$tag" ] || die "no release of $repo matches ${1:-${ref:-the latest release}}"
# The newest release of a major may still be uploading its files when a
# scheduled run starts; the one before it is installed instead. Either is
# checked the same way below.
older=$(echo "$tags" | sed -n 2p)
if [ -n "$older" ] && ! curl -fsSL --retry 2 -o /dev/null "$dl/$repo/releases/download/$tag/checksums.txt.sig" 2>/dev/null; then
echo "tend install: $tag has no signed checksums yet; installing $older" >&2
tag=$older
fi
version=${tag#v}

case "${RUNNER_OS:-$(uname -s)}" in
Expand Down
54 changes: 34 additions & 20 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,28 @@ schedule: 6h

`pr`, `quiet` or `off`, default `pr`. What tend's first run on a repo does.

- `pr`: the first PR is a tidy-up that opens with a short welcome. It removes
the dependencies nothing in the project uses and moves the code off
deprecated libraries where the move can be proven, and lists what only
looks unused and what it could not move. A repo with nothing to tidy gets
a `tend.yml` with every key commented out, so the PR is not empty.
- `quiet`: no first PR. tend starts its usual work and says once, in its
- `pr`: tend catches the repo up in a few PRs, a stage each: fixes, then
runtimes and build tooling, then major upgrades, then migrations and
replacements. The first opens with a short welcome, removes the
dependencies nothing in the project uses, adds a test baseline when the
project's tests are too thin to prove the rest, and lists the stages to
come. A repo with nothing to catch up on gets a `tend.yml` with every key
commented out, so the PR is not empty.
- `quiet`: no catch-up. tend starts its usual work and says once, in its
output, which dependencies nothing uses.
- `off`: no first PR, and no look for unused dependencies.
- `off`: no catch-up, and no look for unused dependencies.

The first run is the first on a repo where tend has never opened a PR, open,
closed or merged; the forge says so even when tend's state is lost. The first
PR is the one open PR like any other: only a security fix goes ahead of it,
and it comes back once that fix merges. Closing it unmerged is final: tend
does not open it again and goes on with its usual work. Setting `quiet` or
`off` while it is open closes it on the next run. In commit mode there is no
first PR. [docs/pr-anatomy.md](pr-anatomy.md#the-first-pull-request)
shows one and how tend decides what nothing uses.
closed or merged; the forge says so even when tend's state is lost. A
catch-up PR is the one open PR like any other, and nothing goes ahead of it:
a security fix goes in it, and a tend PR left open from before is closed and
folded in. Once it merges, the next stage opens. Closing one unmerged is
final: tend ends the catch-up and goes on with its usual work. Setting
`quiet` or `off` while one is open closes it on the next run. In commit mode
each stage is a commit.
[docs/how-it-works.md](how-it-works.md#the-catch-up) says what goes in each
stage, and [docs/pr-anatomy.md](pr-anatomy.md#the-first-pull-request) shows
the PRs and how tend decides what nothing uses.

```yaml
onboarding: quiet
Expand Down Expand Up @@ -242,7 +247,8 @@ deps:

Optional. Without a model, tend applies version bumps and codemods, and opens
a decision PR when a change needs real code edits. With one, it also writes the
migration for call sites no codemod covers. [how-it-works.md](how-it-works.md#what-leaves-the-machine) says what is sent.
migration for call sites no codemod covers, and the tests a catch-up's
baseline needs. [how-it-works.md](how-it-works.md#what-leaves-the-machine) says what is sent.

The whole entry can be one line naming the provider and the model it serves:

Expand All @@ -258,14 +264,16 @@ model: groq/openai/gpt-oss-120b
| `key_env` | string | `""` | name of the env var holding the API key. Empty tries `TEND_MODEL_KEY`, then the provider's usual variable (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GROQ_API_KEY`). `ollama` needs none, and sends `TEND_MODEL_KEY` when it is set. `GITHUB_TOKEN`, `GH_TOKEN` and tend's own `TEND_*` variables are refused |
| `command` | string | `""` | for `provider: command`: a shell line that reads the prompt on stdin and writes the reply on stdout. It runs without tokens and keys in its environment; name the one it needs in `key_env` |
| `attempts` | int | `2` | tries at a usable diff, for the `command` provider |
| `turns` | int | `30` | tool calls a model with tool calling may make on one change |
| `tokens` | int | `400000` | tokens it may spend on one change, prompts and replies together. `0` means no limit |
| `turns` | int | `30` | tool calls a model with tool calling may make on one change, once more for every 10 call sites the change moves, up to five times |
| `tokens` | int | `400000` | tokens it may spend on one change, prompts and replies together, scaled as `turns` is. `0` means no limit |

A provider with tool calling (all but `command`) works the change itself: it
reads and searches the worktree, edits the files the change explains and their
tests, and runs the project's own install, build and test commands. It is done
when every command passes, not when it says so. Running out of `turns` or
`tokens` turns the PR into a decision with what was tried.
`tokens` turns the PR into a decision with what was tried. A catch-up of a
large or old project is a lot of migration; a stronger model than the
example's gets further with it.

The `command` provider writes one diff instead; a reply that holds no diff, or
one that does not apply, is sent back with the reason, up to `attempts` times.
Expand Down Expand Up @@ -308,7 +316,7 @@ How the result leaves your machine.

| key | type | default | meaning |
|---|---|---|---|
| `mode` | `pr`, `commit` | `pr` | `commit` pushes straight to `branch`. Opt in only; it skips review |
| `mode` | `pr`, `commit` | `pr` | `commit` pushes straight to `branch`, only what passed its proof, and reverts it when the repository's CI fails on it. Opt in only; it skips review |
| `branch` | string | `""` | commit mode: the branch to push to. Empty means `base` |
| `labels` | list of strings | `[tend]` | added to every PR. Missing labels are created with color `0e8a16` |
| `draft` | bool | `false` | open every PR as a draft. A PR is a draft anyway when vetting flags something or the tests already fail on the base |
Expand Down Expand Up @@ -348,7 +356,13 @@ deliver:

In commit mode the push must fast-forward. If the branch moved, nothing is
pushed, since the tree on top of the new tip was never proven, and the next run
does the change again from there.
does the change again from there. A change with no build or test command to
prove it, or one that ends as a decision, is never pushed. The next run waits
for the repository's CI on the commit, and reverts the commit when CI fails
on it and did not fail on the one before; the tracking issue lists what was
reverted and why. CI runs on tend's commits only when the token can start
workflows, which the default token cannot.
[How it works](how-it-works.md#commit-mode) has the details.

## Environment

Expand Down
14 changes: 10 additions & 4 deletions docs/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
paths: [.github/workflows/tend.yml]
schedule: [{cron: "17 6 * * *"}]
workflow_dispatch:
permissions: {contents: write, pull-requests: write}
permissions: {contents: write, pull-requests: write, issues: write, checks: read, statuses: read}
concurrency: {group: tend, cancel-in-progress: false}
jobs:
tend:
Expand All @@ -27,7 +27,9 @@ jobs:
with: {model-key: "${{ secrets.TEND_MODEL_KEY }}"}
```

The `model-key` line is only needed if `tend.yml` names a model. On a private
The `model-key` line is only needed if `tend.yml` names a model. `issues:
write` lets tend keep its one tracking issue; `checks: read` and
`statuses: read` let commit mode read your CI on the commits it pushed. On a private
repository every run uses Actions minutes. To run weekly, set `schedule: 7d`
before `tend init --ci`, or change the cron to `"17 6 * * 1"`.

Expand All @@ -40,7 +42,9 @@ The default `GITHUB_TOKEN` has two more limits. PRs it opens do not start
your other workflows, so your CI and auto-merge never run on them. It also
cannot push changes to `.github/workflows`, so Action bumps fail. Pass a
fine-grained token with the workflows permission, or a GitHub App token from
`actions/create-github-app-token`, as `token:` to lift both.
`actions/create-github-app-token`, as `token:` to lift both. In commit mode
this matters more: a push with the default token starts no CI, so tend has no
CI result to revert by.

## Inputs

Expand All @@ -53,5 +57,7 @@ fine-grained token with the workflows permission, or a GitHub App token from
| `version` | newest release of the action's major | the tend version to install |
| `model-key` | none | the key for the model `tend.yml` names |

`@v1` moves to the newest `v1.x.y`; pin `@v1.2.3` to stay put. The action
`@v1` moves to the newest `v1.x.y`, or to the one before it while the
newest release's files are still being uploaded, so a scheduled run never
fails on a release in progress; pin `@v1.2.3` to stay put. The action
checks the release signature before it puts the binary on the path.
Loading
Loading