Metadata-Version: 2.4
Name: workplan
Version: 0.4.0
Summary: Plan and record development work in git, for agent-driven and AI-assisted development
Author: Bay Information Systems
License-Expression: MIT
Project-URL: Homepage, https://workplan.bayis.co.uk
Project-URL: Documentation, https://workplan.bayis.co.uk/getting-started.html
Project-URL: Protocol, https://workplan.bayis.co.uk/protocol.html
Project-URL: Changelog, https://workplan.bayis.co.uk/changelog.html
Project-URL: Repository, https://github.com/bayinfosys/workplan
Project-URL: Issues, https://github.com/bayinfosys/workplan/issues
Project-URL: Bay Information Systems, https://www.bayis.co.uk/
Keywords: git,planning,agents,ai,workflow
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# workplan

Plan and record development work in git, for agent-driven and
AI-assisted development.

[Site](https://workplan.bayis.co.uk) |
[PyPI](https://pypi.org/project/workplan/) |
[GitHub](https://github.com/bayinfosys/workplan)

A workplan breaks one goal into tasks. Each task is one commit; the
workplan reaches the parent branch, master or main, as one squash
commit listing every task. The
plans and the task definitions are Markdown files in `workplans/`, and
every task's state comes from git history. Any clone holds the whole
record, and every step can be done by hand with git and an editor:
[PROTOCOL.md](PROTOCOL.md) defines the protocol and gives each step as
git commands.

An agent, such as Claude Code, Codex, or a model behind any
OpenAI-compatible endpoint, defines the tasks and produces each task's
patch in a separate worktree. The maintainer reads each diff and
accepts or rejects it.

- **Git as state.** Plans, tasks and their states are files and
  commits; there is no other store, and any clone is the whole record.
- **A protocol, not a service.** No server, no account, any agent or
  none; [PROTOCOL.md](PROTOCOL.md) is enough to implement it again.

Every step can be done by hand; PROTOCOL.md gives each as git commands.
Most steps are several git operations in a fixed order: `patch accept`
applies the patch, checks COMMIT_MSG and commits it with the task's
files; `merge` runs the tests, squashes, commits and deletes the
branch. The library ensures that order, checks what a step needs
before it starts, and restores the tree when a step fails. It reads
and changes the repository through git commands only.

## Install

```bash
pipx install workplan
```

Python 3.11 or later and git. No other dependencies. It runs on
Linux; the hooks and dispatch.sh need a POSIX shell.

The command is `wp`; `workplan` is its full name, for use where
WP-CLI, the WordPress command line, also installs `wp`.

## Getting started

[GETTING_STARTED.md](GETTING_STARTED.md): trying it on this repository,
a first workplan without an agent, then with one.

## Commands

`wp` works on the current workplan, its tasks and its patches, as git
works on the checked-out branch. The checked-out branch names the
current workplan: `workplan/<id>/definition` and
`workplan/<id>/task/<nnnn>` both name `<id>`. Switching branch is
switching workplan, one git command, so there is no `wp switch`; for a
workplan held only on the remote, git creates the tracking branch:

```bash
wp list                                   # the workplans, and the branch holding each
git switch workplan/<id>/definition       # that workplan becomes current
```

Off a workplan branch, the current workplan is the newest dated
workplan by id, else the only workplan; otherwise a command needs the
id. `list`, `changelog` and `serve` read across every workplan; `new`
and `merge` move between the parent branch and a workplan branch.

The commands that complete a step or change a document commit it:
`init`, `new`, `edit`, `task add`, `task gen`, `task edit`,
`task drop`, `patch accept`, `merge` and `release`. `patch apply`
stages a patch for review and commits nothing. `publish` is the only
command that pushes to a branch the remote already has.

The workplan's commands are verbs on their own: `new`, `list`, `show`,
`edit` and `merge`; `new` and `merge` are the two that change branches.
Tasks and patches take a noun, then a verb: `task add`, `patch show`.
`list` and `show` read; `add` is you supplying something; `gen` is the
agent producing it; `edit` changes a document; `apply`, `accept`,
`reject` and `merge` are the protocol's steps. `status` is a second
name for `task list`.

"master", in these documents and in the command's help and prompts,
refers to the parent branch of the workplan branch.

To write tasks yourself in place of `task gen`, use
`task add "Say goodbye" --depend 0000` for each.

`new` opens the editor git uses for commit messages, on WORKPLAN.md
rendered from its template; closing it unchanged creates nothing.
`new greeting -m "app.txt says goodbye"` writes the goal and skips the
editor. `new greeting --reply WORKPLAN.md` takes a whole WORKPLAN.md,
written by a chat or by hand; its heading must name the new id. `edit` and `task edit` open the editor the same way on an
existing document.

Every command that changes a document commits it, on the checked-out
branch and with nothing else that is staged: `new` as `<id> workplan`,
`task add` as `<id> add <nnnn>`, `task add --reply` as
`<id> define tasks`, and `edit` and `task edit` as
`<id> edit <document>`. An edit that changes nothing commits nothing.

Every command also runs under its full name, `workplan`.

Protocol commands change the repository in the protocol's terms; each
links to its git commands in PROTOCOL.md.

| Command | Does |
|---|---|
| [`init`](PROTOCOL.md#wp-init) | create `workplans/` with README, PRINCIPLES.md, BACKLOG.md, config.toml and dispatch.sh; add the working files to .gitignore; commit |
| [`new NAME [-m GOAL \| --reply FILE]`](PROTOCOL.md#wp-new) | `workplans/<date>-NAME/WORKPLAN.md` from its template, or the whole file given, on a new branch from the parent branch; commit |
| [`edit [ID]`](PROTOCOL.md#wp-edit) | WORKPLAN.md in the editor; commit |
| [`merge [ID] [-m MESSAGE] [--show]`](PROTOCOL.md#wp-merge) | run `test.command` and stop if it fails; squash the workplan into the parent branch, with the message from its template; `--show` prints the message |
| [`publish [ID]`](PROTOCOL.md#wp-publish) | push the parent branch to the remote, then each tag on its head, then delete the workplan's branches there; stops, doing nothing after it, if a push is refused; after `release`, pushes the branch and the tag |
| [`release VERSION [--show]`](PROTOCOL.md#wp-release) | run `test.command` and stop if it fails; write the changelog section for VERSION under the title of CHANGELOG.md, commit it as `release VERSION` and tag that commit VERSION; refuses unless the parent branch is checked out with no changes to tracked files, VERSION is a new tag, and a workplan was merged since the latest tag; `--show` prints the section |
| [`task add TITLE [--depend N] [-m CHANGE]`](PROTOCOL.md#wp-task-add) | the next task's TASK.md and BREAKDOWN.md from their templates, and its line in WORKPLAN.md; the editor opens on TASK.md; commit |
| `task add --reply FILE` | the new tasks in a `task gen` reply from a chat; `-` reads standard input; commit |
| [`task gen [ID] [--prompt]`](PROTOCOL.md#wp-task-gen) | the agent writes each new task's TASK.md and BREAKDOWN.md; they are listed in WORKPLAN.md and committed with it; `--prompt` prints the prompt for a chat |
| [`task edit NNNN [--doc NAME]`](PROTOCOL.md#wp-task-edit) | TASK.md, BREAKDOWN.md or NOTES.md in the editor; commit |
| [`task drop NNNN`](PROTOCOL.md#wp-task-drop) | move the task to `## Dropped` in WORKPLAN.md and commit WORKPLAN.md |
| [`patch add NNNN [FILE]`](PROTOCOL.md#wp-patch-add) | a reply from a chat, with its commit message line and diff, becomes output.patch and COMMIT_MSG; standard input when FILE is left out |
| [`patch gen NNNN [--prompt]`](PROTOCOL.md#wp-patch-gen) | the agent writes output.patch and COMMIT_MSG; `--prompt` prints the prompt for a chat |
| [`patch apply NNNN`](PROTOCOL.md#wp-patch-apply) | stage the patch in the tree and the index |
| [`patch accept NNNN`](PROTOCOL.md#wp-patch-accept) | commit the patch with COMMIT_MSG, together with the task's directory and WORKPLAN.md |
| [`patch reject NNNN`](PROTOCOL.md#wp-patch-reject) | take an applied patch back out |
| [`patch drop NNNN`](PROTOCOL.md#wp-patch-drop) | delete an unapplied output.patch and its COMMIT_MSG |

Supporting commands read git or run the library; they change nothing
in the protocol.

| Command | Does |
|---|---|
| `list` | every workplan, in the tree or on another branch, and whether it is editable |
| `show [ID]` | the workplan's goal and its tasks' states |
| `task list [ID]`, `status [ID]` | each task's state; a workplan held only on another branch shows its committed states |
| `task show NNNN` | the task's state and TASK.md |
| `patch show NNNN` | the task, its state, COMMIT_MSG, its dependencies and their states, the files changed; then the staged change if applied, else output.patch |
| `changelog [FROM] [TO] [--audience NAME] [--version VERSION] [--all]` | the changelog in Markdown, from the squash commits between two tags or commits and their tasks' trailers; `--version` heads it VERSION, dated today; `--all` gives a section per tag, newest first; writes nothing |
| `route [REV] [--dispatch]` | the next step after a commit |
| `install` | post-commit and post-merge hooks that run `route --dispatch` |
| `serve [--port N]` | the board in a local web page, on 127.0.0.1 |

A task is `ID/NNNN`, or `NNNN` in the current branch's workplan. Every
command takes `--json` to print its result as JSON.

## Manual mode with a chat

With no agent configured, any chat can do the agent's work. `--prompt`
prints the prompt the `none` agent would send, with the files it
names; paste it into a chat, and paste the reply back:

```bash
wp task gen --prompt          # paste into a chat
wp task add --reply reply.txt # its new tasks; - reads standard input
wp patch gen 0000 --prompt
wp patch add 0000 reply.txt   # its diff and commit message line
```

`patch add` applies the reply's diff to the head of the workplan's
branch in a separate worktree, and refuses a reply with no diff or one
that does not apply. In the page, Copy prompt and Paste reply do the
same, beside Gen tasks and Gen patch.

## Changelog

Each task ends with git trailers saying what kind of change it makes,
for whom, and what it breaks:

```
Depends: 0000
Change: feat
Audience: users
Breaking: wp add-task is now wp task add
```

`wp changelog` reads the squash commits since the latest tag,
and each of their tasks' trailers, and prints a changelog: breaking
changes first, then Added, Fixed, Changed and Other.

```bash
wp changelog                     # the latest tag to HEAD
wp changelog v0.1.0 v0.2.0       # between two tags or commits
wp changelog --audience users    # leave out developers and internal
wp changelog --version v0.4.0    # headed v0.4.0, dated today, before the tag exists
wp changelog --all               # a section per tag, newest first
```

A section is headed by `--version`, else by a tag at TO, else
"Unreleased". `--all` takes the tags in version order, each section
from the tag before it, with the section since the latest tag first
when a workplan was merged since.

It reads git and writes nothing; its output can go into CHANGELOG.md
or a release. The squash commits in the range with a Workplan trailer
give the workplans, and each task's trailers, as the files stand at
TO, give its section:

```bash
from=v0.1.0; to=HEAD
git log --reverse --format='%(trailers:key=Workplan,valueonly)' $from..$to |
  while read -r plan; do
    [ -n "$plan" ] || continue
    for f in $(dirname "$plan")/[0-9][0-9][0-9][0-9]/TASK.md; do
      echo "$f"; git show "$to:$f" | git interpret-trailers --parse
    done
  done
```

## Configuration

`workplans/config.toml`; `wp init` writes it with every key, and
writes `workplans/dispatch.sh` for `route.dispatch`.
Environment variables override it, and API keys come from the
environment only.

| Key | Variable | Default |
|---|---|---|
| `parent` | `WORKPLAN_PARENT` | `master`; `init` writes the branch checked out |
| `remote` | `WORKPLAN_REMOTE` | `origin` |
| `llm.api_base` | `WORKPLAN_API_BASE` | `http://localhost:8000/v1` |
| `llm.api_key_env` | | `WORKPLAN_API_KEY` |
| `llm.params` | | `{}`, added to each request body |
| `route.classifier` | `WORKPLAN_ROUTE_CLASSIFIER` | `rules` |
| `route.model` | `WORKPLAN_ROUTE_MODEL` | |
| `route.dispatch` | `WORKPLAN_ROUTE_DISPATCH` | |
| `agent.name` | `WORKPLAN_AGENT` | `none` |
| `agent.model` | `WORKPLAN_AGENT_MODEL` | |
| `agent.setup` | `WORKPLAN_AGENT_SETUP` | |
| `agent.command` | `WORKPLAN_AGENT_COMMAND` | `[]` |
| `agent.attempts`, `agent.timeout` | | `3`, `1800` |
| `test.command` | `WORKPLAN_TEST_COMMAND` | |

## Agents

`task gen` and `patch gen` work in a worktree at the head of the
workplan branch, so the maintainer's own tree is never touched:

```bash
git worktree add --detach /tmp/wt $b
cp -r workplans /tmp/wt/                             # uncommitted edits are seen
( cd /tmp/wt && <agent.setup> )
git -C /tmp/wt add -A && base=$(git -C /tmp/wt write-tree)
( cd /tmp/wt && <the agent> )
x=":(exclude)workplans/*/*/output.patch"; y=":(exclude)workplans/*/*/COMMIT_MSG"
git -C /tmp/wt add -A -- . "$x" "$y"
git -C /tmp/wt diff --cached --binary $base -- . "$x" "$y" > $t/output.patch
cp /tmp/wt/$t/COMMIT_MSG $t/
git worktree remove --force /tmp/wt
```

- `task gen`: the new task directories the agent wrote under
  `workplans/<id>/` are copied back; existing tasks are left alone.
- `patch gen`: the worktree's diff from the base, output.patch and
  COMMIT_MSG left out, becomes output.patch; it can change files under
  `workplans/`, and the documents copied in are not part of it.

| `agent.name` | Runs |
|---|---|
| `none` | completions from `llm.api_base`; the plan files and the files they name go in the prompt; the reply holds the task files or a diff, retried with the error up to `agent.attempts` times |
| `claude-code` | `claude -p --allowedTools Read,Edit,Write,Glob,Grep,Bash`, prompt on stdin |
| `codex` | `codex exec --sandbox workspace-write <prompt>` |
| `command` | `agent.command`; a `{prompt}` argument is replaced by the prompt, else it goes on stdin |

`claude-code` and `codex` are presets of `command`; setting
`agent.command` replaces the preset's arguments. Agents with a shell
build the code and run its checks in the worktree. Containers, ports
and other host resources are shared with the host, so integration runs
stay with the maintainer.

A `command` agent receives `WORKPLAN_ACTION` (`task-gen` or
`patch-gen`) and `WORKPLAN_TARGET` (the workplan or task id) in its
environment, and for `patch-gen`, `WORKPLAN_COMMIT_MSG`: the path
to write the commit message to. When it writes none, COMMIT_MSG is the
task id and TASK.md's title.

### Examples

Claude Code, with the project's dependencies installed first:

```toml
[agent]
name = "claude-code"
setup = "uv sync"
```

Codex:

```toml
[agent]
name = "codex"
```

A model behind an OpenAI-compatible endpoint, with no agent:

```toml
[llm]
api_base = "https://api.anthropic.com/v1"     # or https://api.openai.com/v1
api_key_env = "ANTHROPIC_API_KEY"             # or OPENAI_API_KEY

[agent]
name = "none"
model = "<model name>"
```

A local model, through [marigold](https://marigold.run) or Ollama:

```toml
[llm]
api_base = "http://localhost:8000/v1"         # Ollama: http://localhost:11434/v1

[agent]
name = "none"
model = "<model name>"
```

## Routing

`wp route` reads a commit and prints the next step: `complete`,
`review`, `patch-gen`, `task-gen` or `none`, with its targets.
The rules take the first action in this table that has targets:

| Action | When | Targets |
|---|---|---|
| `complete` | a commit on the parent branch with a `Workplan:` trailer | the workplan |
| `review` | code changed in a commit whose subject is a task id | the task |
| `patch-gen` | TASK.md or BREAKDOWN.md changed | each task |
| `task-gen` | WORKPLAN.md changed | the workplan |
| `none` | anything else, such as a change to the protocol's files | -- |

A task's commit, which also carries its files and WORKPLAN.md, leads
to `review`; the commit that defines the tasks leads to `patch-gen`.
The rules read `git show --name-only --format='%s%n%(trailers:key=Workplan)' REV`.
With `route.classifier = "llm"`,
a model chooses the action from the prompt in
`templates/prompts/route.md`; the targets still come from the commit,
and an answer that is not an action with targets falls back to the
rules. stderr shows both choices:

```
$ wp route
route: llm chose patch-gen; the rules chose patch-gen
patch-gen 2026-11-24-greeting/0000
```

`wp install` adds hooks that run `route --dispatch` in the background
after each commit. `--dispatch` runs `route.dispatch` with the action
and its targets. `wp init` writes a dispatch script,
`workplans/dispatch.sh`: for `task-gen` it runs `task gen`, for
`patch-gen` it runs `patch gen` for each target in parallel, and on
`review` it produces each stale patch again. The hooks and the script
call the command by its full name, `workplan`. Set
`route.dispatch = "workplans/dispatch.sh"` and run `wp install` for
full auto.
The hooks clear the variables git sets for hooks, such as
`GIT_INDEX_FILE`, so that the commands a dispatch script runs work in
their own worktrees.

## Serve

```bash
wp serve                     # http://127.0.0.1:8765/?token=...
```

`serve` starts a web server on 127.0.0.1 and prints its address, with
a token made at startup. The page runs the same operations as the
commands, so the whole flow can run from the browser, for instance
over a screen share while a team refines the tasks. A workplan is
editable while its definition branch is checked out; workplans on
other branches are shown read-only, read from their branches.

The page shows the workplan's title, branch and goal, and a board with
a column for each state. A card opens the task's TASK.md, BREAKDOWN.md,
NOTES.md and patch, rendered, with Edit and Save; its buttons are the
steps its state allows: Gen patch, Apply, Accept, Reject. The
header holds Gen tasks and Merge, and the merge message opens in a
text box. New workplan asks for a name and a goal. The selector lists
every workplan, those on other branches marked read-only. The page
refreshes every five seconds, so commits made in a terminal appear on
their own.

The page and the commands share one API: every command but `init`,
`install` and `serve` has a route, given by its verb and noun.
`task list` is `GET /api/workplan/{id}/task`, `patch accept` is
`POST /api/task/{id}/{nnnn}/patch/accept`, and so on; registry.py
holds the rule.

Every request must name 127.0.0.1 or localhost as its host, and every
API request must carry the token, so another site open in the browser
can neither read nor change anything. Operations that change the
repository run one at a time. The server keeps no state of its own:
everything it shows comes from the files and git.

## Templates

Documents, prompts and the squash commit message are rendered from
templates with `string.Template`: `$name` is replaced and nothing else
happens. To change one, copy it from `src/workplan/templates/<kind>/`
into `workplans/templates/<kind>/` and edit the copy; the rest keep the
package's version. The document templates are listed in PROTOCOL.md;
the prompts are the library's:

| Template | Values |
|---|---|
| prompts/task-gen.md | `$id`, `$next`, `$context`, `$task_template`, `$breakdown_template` |
| prompts/task-gen-none.md | as task-gen.md |
| prompts/patch-gen.md | `$id`, `$workplan`, `$context`, `$commit_msg` |
| prompts/patch-gen-none.md | as patch-gen.md |
| prompts/route.md | `$branch`, `$parents`, `$subject`, `$workplan`, `$paths` |

## Development

```bash
python -m unittest discover -s tests
```

workplans/config.toml sets this as `test.command`, so `wp merge` runs
it, quietly, before squashing a workplan into master, and `wp release`
before a release.

The tests build temporary repositories, compare each command with its
by-hand git sequence, rehearse two clones sharing one origin, and
run the `none` agent and the classifier against a local fake endpoint.

The version comes from git tags through setuptools-scm. A release is a
`vX.Y.Z` tag on master, on the commit that adds its changelog section:

```bash
wp release v0.4.0 --show         # the section it will write
wp release v0.4.0                # test.command, CHANGELOG.md, commit, tag
wp publish                       # push master, then the tag
```

`.github/workflows/release.yaml` builds the package on every push to
master; on a `v*` tag it publishes the package to PyPI and creates the
GitHub release, with the tag's changelog section, from `wp changelog`,
as its notes. It runs in the `release` environment and needs the
repository secret `PYPI_API_TOKEN`.

## Removing workplan

```bash
rm .git/hooks/post-commit .git/hooks/post-merge   # if wp install wrote them
$EDITOR .gitignore                                # remove the two workplans/ lines
git rm -r workplans && git commit -m "remove workplans"
pipx uninstall workplan
```

The history keeps every workplan's squash commit and its Workplan
trailer.

## Licence

MIT. See [LICENSE](LICENSE).
