foresto 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- foresto-1.0.0/.gitignore +8 -0
- foresto-1.0.0/LICENSE +21 -0
- foresto-1.0.0/PKG-INFO +180 -0
- foresto-1.0.0/README.md +154 -0
- foresto-1.0.0/pyproject.toml +51 -0
- foresto-1.0.0/src/foresto/__init__.py +0 -0
- foresto-1.0.0/src/foresto/__main__.py +5 -0
- foresto-1.0.0/src/foresto/cli.py +68 -0
- foresto-1.0.0/src/foresto/config.py +133 -0
- foresto-1.0.0/src/foresto/core.py +928 -0
foresto-1.0.0/.gitignore
ADDED
foresto-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 j4rviscmd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
foresto-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: foresto
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: CLI tool for creating isolated working copies for parallel AI-assisted development
|
|
5
|
+
Project-URL: Repository, https://github.com/j4rviscmd/foresto
|
|
6
|
+
Project-URL: Issues, https://github.com/j4rviscmd/foresto/issues
|
|
7
|
+
Author: j4rviscmd
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai-agents,cli,developer-tools,git,worktree
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Software Development
|
|
22
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: psutil
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# foresto
|
|
28
|
+
|
|
29
|
+
[](https://github.com/j4rviscmd/foresto/actions/workflows/ci.yml)
|
|
30
|
+
[](https://pypi.org/project/foresto/)
|
|
31
|
+
[](https://pypi.org/project/foresto/)
|
|
32
|
+
[](https://github.com/j4rviscmd/foresto/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
A CLI tool that creates isolated working copies of a project for parallel AI-assisted development.
|
|
35
|
+
|
|
36
|
+
`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`.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# uv (recommended)
|
|
42
|
+
uv tool install foresto
|
|
43
|
+
|
|
44
|
+
# pip
|
|
45
|
+
pip install foresto
|
|
46
|
+
|
|
47
|
+
# straight from GitHub
|
|
48
|
+
uv tool install git+https://github.com/j4rviscmd/foresto
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
| Command | Purpose | Example |
|
|
54
|
+
| --- | --- | --- |
|
|
55
|
+
| `foresto --version` | Show version | `foresto --version` |
|
|
56
|
+
| `foresto start <base_path> <name>` | Create a working copy | `foresto start ./my-app quick-silver-moon` |
|
|
57
|
+
| `foresto finish <name>` | Remove a working copy | `foresto finish quick-silver-moon` |
|
|
58
|
+
| `foresto list` | List working copies | Run from the base directory |
|
|
59
|
+
|
|
60
|
+
### Create a working copy
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
foresto start <base_path> <name>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `base_path` — path to the source project (absolute or relative)
|
|
67
|
+
- `name` — identifier in kebab-case (e.g. `quick-silver-moon`)
|
|
68
|
+
|
|
69
|
+
Example:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
foresto start ./my-app quick-silver-moon
|
|
73
|
+
# -> .worktrees/quick-silver-moon
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
After running:
|
|
77
|
+
|
|
78
|
+
- git-tracked files are checked out with `git worktree add`
|
|
79
|
+
- non-git files listed in `[start].share` of `.foresto.toml` are copied
|
|
80
|
+
- a git branch named `name` is created in the working copy
|
|
81
|
+
- the relative path is printed to stdout (so callers can capture it)
|
|
82
|
+
|
|
83
|
+
### Remove a working copy
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
foresto finish <name>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Run from the base project directory.
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
cd my-app
|
|
95
|
+
foresto finish quick-silver-moon
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
After running:
|
|
99
|
+
|
|
100
|
+
- 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.
|
|
101
|
+
- The working directory is removed with `git worktree remove`
|
|
102
|
+
- `git pull` runs on the current branch
|
|
103
|
+
- The local branch is deleted
|
|
104
|
+
- The `finish` commands in `.foresto.toml` run in the base directory
|
|
105
|
+
|
|
106
|
+
Use `--no-pull` to skip `git pull`:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
foresto finish --no-pull quick-silver-moon
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### List working copies
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
foresto list
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Run from the base project directory.
|
|
119
|
+
|
|
120
|
+
## Configuration
|
|
121
|
+
|
|
122
|
+
Place `.foresto.toml` in the project root. The lookup location depends on the command.
|
|
123
|
+
|
|
124
|
+
| Command | Lookup location | Description |
|
|
125
|
+
| --- | --- | --- |
|
|
126
|
+
| `foresto start` | `{base_path}/.foresto.toml` | Directly under the project path you passed |
|
|
127
|
+
| `foresto finish` | `{cwd}/.foresto.toml` | Directly under the current directory |
|
|
128
|
+
|
|
129
|
+
```toml
|
|
130
|
+
[start]
|
|
131
|
+
commands = ["npm install"]
|
|
132
|
+
share = [".env", "node_modules"]
|
|
133
|
+
|
|
134
|
+
[finish]
|
|
135
|
+
commands = ["npm install"]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- `[start].commands` — run inside the working copy after the worktree is created
|
|
139
|
+
- `[start].share` — patterns of non-git files to copy into the working copy
|
|
140
|
+
- Basename pattern (no `/`): matches by name at any depth (e.g. `.env`, `node_modules`)
|
|
141
|
+
- Path pattern (contains `/`): matches a path relative to the project root (e.g. `secrets/local.env`)
|
|
142
|
+
- 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
|
|
143
|
+
- `[finish].commands` — run in the base directory after removal
|
|
144
|
+
|
|
145
|
+
If the file does not exist, nothing is run.
|
|
146
|
+
|
|
147
|
+
## Typical workflow
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
1. foresto start ./my-app add-auth-feature
|
|
151
|
+
2. cd .worktrees/add-auth-feature
|
|
152
|
+
(the add-auth-feature branch is already created)
|
|
153
|
+
3. (work, commit, push, open a PR, merge)
|
|
154
|
+
4. cd ../..
|
|
155
|
+
5. foresto finish add-auth-feature
|
|
156
|
+
-> git pull runs and the merged changes land in the base
|
|
157
|
+
-> the local branch is deleted
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Exit codes
|
|
161
|
+
|
|
162
|
+
| Code | Meaning |
|
|
163
|
+
| --- | --- |
|
|
164
|
+
| 0 | Success |
|
|
165
|
+
| 1 | `base_path` does not exist, or no subcommand was given |
|
|
166
|
+
| 2 | `name` is not kebab-case |
|
|
167
|
+
| 3 | The worktree already exists |
|
|
168
|
+
| 4 | `git worktree add` failed |
|
|
169
|
+
| 5 | A start command failed |
|
|
170
|
+
| 6 | `.worktrees/` not found (finish was run outside the base directory) |
|
|
171
|
+
| 7 | The worktree was not found |
|
|
172
|
+
| 8 | A finish command failed |
|
|
173
|
+
| 10 | `git pull` failed |
|
|
174
|
+
| 11 | `git worktree remove` failed |
|
|
175
|
+
| 12 | Unpushed commits were detected (during finish) |
|
|
176
|
+
| 13 | Invalid `share` pattern in `.foresto.toml` |
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|
foresto-1.0.0/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# foresto
|
|
2
|
+
|
|
3
|
+
[](https://github.com/j4rviscmd/foresto/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/foresto/)
|
|
5
|
+
[](https://pypi.org/project/foresto/)
|
|
6
|
+
[](https://github.com/j4rviscmd/foresto/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
A CLI tool that creates isolated working copies of a project for parallel AI-assisted development.
|
|
9
|
+
|
|
10
|
+
`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`.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# uv (recommended)
|
|
16
|
+
uv tool install foresto
|
|
17
|
+
|
|
18
|
+
# pip
|
|
19
|
+
pip install foresto
|
|
20
|
+
|
|
21
|
+
# straight from GitHub
|
|
22
|
+
uv tool install git+https://github.com/j4rviscmd/foresto
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
| Command | Purpose | Example |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `foresto --version` | Show version | `foresto --version` |
|
|
30
|
+
| `foresto start <base_path> <name>` | Create a working copy | `foresto start ./my-app quick-silver-moon` |
|
|
31
|
+
| `foresto finish <name>` | Remove a working copy | `foresto finish quick-silver-moon` |
|
|
32
|
+
| `foresto list` | List working copies | Run from the base directory |
|
|
33
|
+
|
|
34
|
+
### Create a working copy
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
foresto start <base_path> <name>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- `base_path` — path to the source project (absolute or relative)
|
|
41
|
+
- `name` — identifier in kebab-case (e.g. `quick-silver-moon`)
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
foresto start ./my-app quick-silver-moon
|
|
47
|
+
# -> .worktrees/quick-silver-moon
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
After running:
|
|
51
|
+
|
|
52
|
+
- git-tracked files are checked out with `git worktree add`
|
|
53
|
+
- non-git files listed in `[start].share` of `.foresto.toml` are copied
|
|
54
|
+
- a git branch named `name` is created in the working copy
|
|
55
|
+
- the relative path is printed to stdout (so callers can capture it)
|
|
56
|
+
|
|
57
|
+
### Remove a working copy
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
foresto finish <name>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Run from the base project directory.
|
|
64
|
+
|
|
65
|
+
Example:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
cd my-app
|
|
69
|
+
foresto finish quick-silver-moon
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
After running:
|
|
73
|
+
|
|
74
|
+
- 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.
|
|
75
|
+
- The working directory is removed with `git worktree remove`
|
|
76
|
+
- `git pull` runs on the current branch
|
|
77
|
+
- The local branch is deleted
|
|
78
|
+
- The `finish` commands in `.foresto.toml` run in the base directory
|
|
79
|
+
|
|
80
|
+
Use `--no-pull` to skip `git pull`:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
foresto finish --no-pull quick-silver-moon
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### List working copies
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
foresto list
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Run from the base project directory.
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
Place `.foresto.toml` in the project root. The lookup location depends on the command.
|
|
97
|
+
|
|
98
|
+
| Command | Lookup location | Description |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `foresto start` | `{base_path}/.foresto.toml` | Directly under the project path you passed |
|
|
101
|
+
| `foresto finish` | `{cwd}/.foresto.toml` | Directly under the current directory |
|
|
102
|
+
|
|
103
|
+
```toml
|
|
104
|
+
[start]
|
|
105
|
+
commands = ["npm install"]
|
|
106
|
+
share = [".env", "node_modules"]
|
|
107
|
+
|
|
108
|
+
[finish]
|
|
109
|
+
commands = ["npm install"]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- `[start].commands` — run inside the working copy after the worktree is created
|
|
113
|
+
- `[start].share` — patterns of non-git files to copy into the working copy
|
|
114
|
+
- Basename pattern (no `/`): matches by name at any depth (e.g. `.env`, `node_modules`)
|
|
115
|
+
- Path pattern (contains `/`): matches a path relative to the project root (e.g. `secrets/local.env`)
|
|
116
|
+
- 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
|
|
117
|
+
- `[finish].commands` — run in the base directory after removal
|
|
118
|
+
|
|
119
|
+
If the file does not exist, nothing is run.
|
|
120
|
+
|
|
121
|
+
## Typical workflow
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
1. foresto start ./my-app add-auth-feature
|
|
125
|
+
2. cd .worktrees/add-auth-feature
|
|
126
|
+
(the add-auth-feature branch is already created)
|
|
127
|
+
3. (work, commit, push, open a PR, merge)
|
|
128
|
+
4. cd ../..
|
|
129
|
+
5. foresto finish add-auth-feature
|
|
130
|
+
-> git pull runs and the merged changes land in the base
|
|
131
|
+
-> the local branch is deleted
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Exit codes
|
|
135
|
+
|
|
136
|
+
| Code | Meaning |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| 0 | Success |
|
|
139
|
+
| 1 | `base_path` does not exist, or no subcommand was given |
|
|
140
|
+
| 2 | `name` is not kebab-case |
|
|
141
|
+
| 3 | The worktree already exists |
|
|
142
|
+
| 4 | `git worktree add` failed |
|
|
143
|
+
| 5 | A start command failed |
|
|
144
|
+
| 6 | `.worktrees/` not found (finish was run outside the base directory) |
|
|
145
|
+
| 7 | The worktree was not found |
|
|
146
|
+
| 8 | A finish command failed |
|
|
147
|
+
| 10 | `git pull` failed |
|
|
148
|
+
| 11 | `git worktree remove` failed |
|
|
149
|
+
| 12 | Unpushed commits were detected (during finish) |
|
|
150
|
+
| 13 | Invalid `share` pattern in `.foresto.toml` |
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "foresto"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "CLI tool for creating isolated working copies for parallel AI-assisted development"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "j4rviscmd" }]
|
|
14
|
+
keywords = ["git", "worktree", "cli", "ai-agents", "developer-tools"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Software Development",
|
|
27
|
+
"Topic :: Software Development :: Version Control :: Git",
|
|
28
|
+
]
|
|
29
|
+
dependencies = ["psutil"]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Repository = "https://github.com/j4rviscmd/foresto"
|
|
33
|
+
Issues = "https://github.com/j4rviscmd/foresto/issues"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
foresto = "foresto.cli:main"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = ["src", "LICENSE", "README.md", "pyproject.toml"]
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
target-version = "py311"
|
|
43
|
+
|
|
44
|
+
[tool.ruff.lint]
|
|
45
|
+
select = ["E", "F", "I", "UP", "B", "SIM", "PLW", "PIE", "FURB"]
|
|
46
|
+
ignore = ["E501"]
|
|
47
|
+
|
|
48
|
+
[dependency-groups]
|
|
49
|
+
dev = [
|
|
50
|
+
"ruff==0.17.6",
|
|
51
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from importlib.metadata import version
|
|
3
|
+
|
|
4
|
+
from .core import cmd_finish, cmd_list, cmd_start
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
8
|
+
"""Build and return the CLI argument parser for ``foresto``.
|
|
9
|
+
|
|
10
|
+
Defines three subcommands:
|
|
11
|
+
|
|
12
|
+
- ``start`` -- create an isolated working copy.
|
|
13
|
+
- ``finish`` -- remove a working copy and pull latest changes.
|
|
14
|
+
- ``list`` -- list active worktrees.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
The configured :class:`argparse.ArgumentParser` instance.
|
|
18
|
+
"""
|
|
19
|
+
parser = argparse.ArgumentParser(prog="foresto")
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"--version", action="version", version=f"%(prog)s {version('foresto')}"
|
|
22
|
+
)
|
|
23
|
+
sub = parser.add_subparsers(dest="command")
|
|
24
|
+
|
|
25
|
+
p_start = sub.add_parser("start", help="create an isolated working copy")
|
|
26
|
+
p_start.add_argument("base_path", help="path to the base project")
|
|
27
|
+
p_start.add_argument("name", help="kebab-case identifier (e.g. quick-silver-moon)")
|
|
28
|
+
|
|
29
|
+
p_finish = sub.add_parser("finish", help="remove a working copy")
|
|
30
|
+
p_finish.add_argument(
|
|
31
|
+
"name", help="kebab-case identifier of the worktree to remove"
|
|
32
|
+
)
|
|
33
|
+
p_finish.add_argument(
|
|
34
|
+
"--no-pull", action="store_true", help="skip automatic git pull"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
sub.add_parser("list", help="list active worktrees")
|
|
38
|
+
|
|
39
|
+
return parser
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main() -> int:
|
|
43
|
+
"""Entry point for the ``foresto`` CLI.
|
|
44
|
+
|
|
45
|
+
Parses command-line arguments and dispatches to the appropriate
|
|
46
|
+
:mod:`core` command function. Prints help text and returns ``1``
|
|
47
|
+
when no subcommand is provided.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Exit code -- ``0`` on success, ``1`` when no subcommand is given.
|
|
51
|
+
"""
|
|
52
|
+
parser = build_parser()
|
|
53
|
+
args = parser.parse_args()
|
|
54
|
+
|
|
55
|
+
if args.command == "start":
|
|
56
|
+
result = cmd_start(args.base_path, args.name)
|
|
57
|
+
print(result)
|
|
58
|
+
return 0
|
|
59
|
+
elif args.command == "finish":
|
|
60
|
+
cmd_finish(args.name, no_pull=args.no_pull)
|
|
61
|
+
return 0
|
|
62
|
+
elif args.command == "list":
|
|
63
|
+
for name in cmd_list():
|
|
64
|
+
print(name)
|
|
65
|
+
return 0
|
|
66
|
+
else:
|
|
67
|
+
parser.print_help()
|
|
68
|
+
return 1
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import tomllib
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _config_error(msg: str) -> None:
|
|
8
|
+
"""Report a configuration error and exit."""
|
|
9
|
+
print(f"error: .foresto.toml: {msg}", file=sys.stderr)
|
|
10
|
+
sys.exit(13)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class SharePatterns:
|
|
15
|
+
"""Validated list of share patterns for non-git-managed files.
|
|
16
|
+
|
|
17
|
+
Patterns are classified into two categories based on whether they
|
|
18
|
+
contain a path separator (``/``):
|
|
19
|
+
|
|
20
|
+
- **Basename patterns** (no ``/``): matched against directory and file
|
|
21
|
+
names at every depth (e.g. ``.env``, ``node_modules``).
|
|
22
|
+
- **Path patterns** (contains ``/``): matched as relative paths from
|
|
23
|
+
the project root (e.g. ``secrets/local.env``).
|
|
24
|
+
|
|
25
|
+
This follows the same semantics as ``.gitignore``: a pattern containing
|
|
26
|
+
a slash is anchored to the root, otherwise it matches anywhere.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
_basename_patterns: list[str] = field(default_factory=list)
|
|
30
|
+
_path_patterns: list[str] = field(default_factory=list)
|
|
31
|
+
|
|
32
|
+
def __init__(self, raw_patterns: list[str] | None = None) -> None:
|
|
33
|
+
basename: list[str] = []
|
|
34
|
+
path: list[str] = []
|
|
35
|
+
seen: set[str] = set()
|
|
36
|
+
|
|
37
|
+
for p in raw_patterns or []:
|
|
38
|
+
if not p:
|
|
39
|
+
_config_error("share pattern must not be empty")
|
|
40
|
+
if p.startswith("!"):
|
|
41
|
+
_config_error(f"share pattern must not start with '!': {p!r}")
|
|
42
|
+
|
|
43
|
+
normalized = p.replace("\\", "/").rstrip("/")
|
|
44
|
+
|
|
45
|
+
if not normalized:
|
|
46
|
+
_config_error("share pattern must not be empty")
|
|
47
|
+
|
|
48
|
+
if ".." in normalized.split("/"):
|
|
49
|
+
_config_error(f"share pattern must not contain '..': {p!r}")
|
|
50
|
+
|
|
51
|
+
if normalized in seen:
|
|
52
|
+
continue
|
|
53
|
+
seen.add(normalized)
|
|
54
|
+
|
|
55
|
+
if "/" in normalized:
|
|
56
|
+
path.append(normalized)
|
|
57
|
+
else:
|
|
58
|
+
basename.append(normalized)
|
|
59
|
+
|
|
60
|
+
self._basename_patterns = basename
|
|
61
|
+
self._path_patterns = path
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def basename_patterns(self) -> list[str]:
|
|
65
|
+
"""Basename-only patterns matched at any directory level."""
|
|
66
|
+
return list(self._basename_patterns)
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def path_patterns(self) -> list[str]:
|
|
70
|
+
"""Path patterns matched relative to the project root."""
|
|
71
|
+
return list(self._path_patterns)
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def patterns(self) -> list[str]:
|
|
75
|
+
"""All patterns combined (basename + path)."""
|
|
76
|
+
return self._basename_patterns + self._path_patterns
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass
|
|
80
|
+
class StepConfig:
|
|
81
|
+
"""Configuration for a single workflow step (``start`` or ``finish``).
|
|
82
|
+
|
|
83
|
+
Attributes:
|
|
84
|
+
commands: Shell commands to execute during the step.
|
|
85
|
+
share: Patterns for non-git-managed files to copy into the worktree.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
commands: list[str] = field(default_factory=list)
|
|
89
|
+
share: SharePatterns = field(default_factory=SharePatterns)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass
|
|
93
|
+
class Config:
|
|
94
|
+
"""Top-level configuration loaded from ``.foresto.toml``.
|
|
95
|
+
|
|
96
|
+
Attributes:
|
|
97
|
+
start: Configuration applied when creating a new worktree.
|
|
98
|
+
finish: Configuration applied when removing a worktree.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
start: StepConfig = field(default_factory=StepConfig)
|
|
102
|
+
finish: StepConfig = field(default_factory=StepConfig)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def load_config(base_path: Path) -> Config:
|
|
106
|
+
"""Load project configuration from ``.foresto.toml``.
|
|
107
|
+
|
|
108
|
+
Reads the TOML file at ``base_path / .foresto.toml`` and returns a
|
|
109
|
+
validated :class:`Config` object. If the file does not exist, returns
|
|
110
|
+
a default (empty) configuration.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
base_path: Project root directory.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Parsed configuration, or defaults when the file is absent.
|
|
117
|
+
"""
|
|
118
|
+
config_path = base_path / ".foresto.toml"
|
|
119
|
+
if not config_path.is_file():
|
|
120
|
+
return Config()
|
|
121
|
+
with open(config_path, "rb") as f:
|
|
122
|
+
data = tomllib.load(f)
|
|
123
|
+
start_section = data.get("start", {})
|
|
124
|
+
finish_section = data.get("finish", {})
|
|
125
|
+
return Config(
|
|
126
|
+
start=StepConfig(
|
|
127
|
+
commands=start_section.get("commands", []),
|
|
128
|
+
share=SharePatterns(start_section.get("share", [])),
|
|
129
|
+
),
|
|
130
|
+
finish=StepConfig(
|
|
131
|
+
commands=finish_section.get("commands", []),
|
|
132
|
+
),
|
|
133
|
+
)
|