Metadata-Version: 2.5
Name: foresto
Version: 1.0.0
Summary: CLI tool for creating isolated working copies for parallel AI-assisted development
Project-URL: Repository, https://github.com/j4rviscmd/foresto
Project-URL: Issues, https://github.com/j4rviscmd/foresto/issues
Author: j4rviscmd
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agents,cli,developer-tools,git,worktree
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.11
Requires-Dist: psutil
Description-Content-Type: text/markdown

# foresto

[![CI](https://github.com/j4rviscmd/foresto/actions/workflows/ci.yml/badge.svg)](https://github.com/j4rviscmd/foresto/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/foresto)](https://pypi.org/project/foresto/)
[![Python](https://img.shields.io/pypi/pyversions/foresto)](https://pypi.org/project/foresto/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/j4rviscmd/foresto/blob/main/LICENSE)

A CLI tool that creates isolated working copies of a project for parallel AI-assisted development.

`foresto start` checks out git-tracked files with `git worktree add` and copies non-git files (`.env`, `node_modules`, etc.) declared in the `share` setting of `.foresto.toml`. Each copy is registered as a git worktree, so you can switch between them with tools like `lazygit`.

## Installation

```bash
# uv (recommended)
uv tool install foresto

# pip
pip install foresto

# straight from GitHub
uv tool install git+https://github.com/j4rviscmd/foresto
```

## Usage

| Command | Purpose | Example |
| --- | --- | --- |
| `foresto --version` | Show version | `foresto --version` |
| `foresto start <base_path> <name>` | Create a working copy | `foresto start ./my-app quick-silver-moon` |
| `foresto finish <name>` | Remove a working copy | `foresto finish quick-silver-moon` |
| `foresto list` | List working copies | Run from the base directory |

### Create a working copy

```bash
foresto start <base_path> <name>
```

- `base_path` — path to the source project (absolute or relative)
- `name` — identifier in kebab-case (e.g. `quick-silver-moon`)

Example:

```bash
foresto start ./my-app quick-silver-moon
# -> .worktrees/quick-silver-moon
```

After running:

- git-tracked files are checked out with `git worktree add`
- non-git files listed in `[start].share` of `.foresto.toml` are copied
- a git branch named `name` is created in the working copy
- the relative path is printed to stdout (so callers can capture it)

### Remove a working copy

```bash
foresto finish <name>
```

Run from the base project directory.

Example:

```bash
cd my-app
foresto finish quick-silver-moon
```

After running:

- Stops with a warning if unpushed commits exist. When the remote branch was deleted after a squash merge, `gh pr view` is consulted and the command proceeds only if the PR is MERGED and the head SHA at merge time matches the local HEAD.
- The working directory is removed with `git worktree remove`
- `git pull` runs on the current branch
- The local branch is deleted
- The `finish` commands in `.foresto.toml` run in the base directory

Use `--no-pull` to skip `git pull`:

```bash
foresto finish --no-pull quick-silver-moon
```

### List working copies

```bash
foresto list
```

Run from the base project directory.

## Configuration

Place `.foresto.toml` in the project root. The lookup location depends on the command.

| Command | Lookup location | Description |
| --- | --- | --- |
| `foresto start` | `{base_path}/.foresto.toml` | Directly under the project path you passed |
| `foresto finish` | `{cwd}/.foresto.toml` | Directly under the current directory |

```toml
[start]
commands = ["npm install"]
share = [".env", "node_modules"]

[finish]
commands = ["npm install"]
```

- `[start].commands` — run inside the working copy after the worktree is created
- `[start].share` — patterns of non-git files to copy into the working copy
  - Basename pattern (no `/`): matches by name at any depth (e.g. `.env`, `node_modules`)
  - Path pattern (contains `/`): matches a path relative to the project root (e.g. `secrets/local.env`)
  - Symbolic links are preserved as links (keeps structures like pnpm's `node_modules`). On Windows, falls back to a real copy with a warning when symlink creation is not permitted
- `[finish].commands` — run in the base directory after removal

If the file does not exist, nothing is run.

## Typical workflow

```text
1. foresto start ./my-app add-auth-feature
2. cd .worktrees/add-auth-feature
   (the add-auth-feature branch is already created)
3. (work, commit, push, open a PR, merge)
4. cd ../..
5. foresto finish add-auth-feature
   -> git pull runs and the merged changes land in the base
   -> the local branch is deleted
```

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Success |
| 1 | `base_path` does not exist, or no subcommand was given |
| 2 | `name` is not kebab-case |
| 3 | The worktree already exists |
| 4 | `git worktree add` failed |
| 5 | A start command failed |
| 6 | `.worktrees/` not found (finish was run outside the base directory) |
| 7 | The worktree was not found |
| 8 | A finish command failed |
| 10 | `git pull` failed |
| 11 | `git worktree remove` failed |
| 12 | Unpushed commits were detected (during finish) |
| 13 | Invalid `share` pattern in `.foresto.toml` |

## License

MIT
