worktree-compose 0.2.0 → 1.0.0
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.
- package/README.md +458 -140
- package/SKILL.md +113 -0
- package/dist/cli.js +94 -33
- package/dist/commands/clean.d.ts +2 -1
- package/dist/commands/clean.js +8 -48
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.js +30 -0
- package/dist/commands/list.d.ts +4 -1
- package/dist/commands/list.js +62 -44
- package/dist/commands/promote.d.ts +3 -1
- package/dist/commands/promote.js +4 -34
- package/dist/commands/prune.d.ts +2 -0
- package/dist/commands/prune.js +7 -0
- package/dist/commands/restart.d.ts +2 -1
- package/dist/commands/restart.js +11 -5
- package/dist/commands/skill.d.ts +4 -0
- package/dist/commands/skill.js +10 -0
- package/dist/commands/start.d.ts +2 -1
- package/dist/commands/start.js +7 -34
- package/dist/commands/stop.d.ts +1 -1
- package/dist/commands/stop.js +6 -23
- package/dist/compose/detect.d.ts +1 -2
- package/dist/compose/detect.js +1 -10
- package/dist/compose/engine.d.ts +61 -0
- package/dist/compose/engine.js +129 -0
- package/dist/compose/isolation.d.ts +15 -0
- package/dist/compose/isolation.js +62 -0
- package/dist/compose/parse.d.ts +5 -0
- package/dist/compose/parse.js +89 -11
- package/dist/compose/status.d.ts +84 -0
- package/dist/compose/status.js +227 -0
- package/dist/compose/types.d.ts +20 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.js +23 -6
- package/dist/context.d.ts +89 -3
- package/dist/context.js +278 -45
- package/dist/core/clean.d.ts +91 -0
- package/dist/core/clean.js +343 -0
- package/dist/core/compose.d.ts +30 -0
- package/dist/core/compose.js +45 -0
- package/dist/core/doctor.d.ts +28 -0
- package/dist/core/doctor.js +277 -0
- package/dist/core/list.d.ts +42 -0
- package/dist/core/list.js +94 -0
- package/dist/core/promote.d.ts +40 -0
- package/dist/core/promote.js +117 -0
- package/dist/core/prune.d.ts +32 -0
- package/dist/core/prune.js +75 -0
- package/dist/core/restart.d.ts +14 -0
- package/dist/core/restart.js +18 -0
- package/dist/core/start.d.ts +31 -0
- package/dist/core/start.js +99 -0
- package/dist/core/stop.d.ts +32 -0
- package/dist/core/stop.js +57 -0
- package/dist/core/teardown.d.ts +121 -0
- package/dist/core/teardown.js +298 -0
- package/dist/core/types.d.ts +15 -0
- package/dist/core/types.js +1 -0
- package/dist/git/promote.d.ts +49 -2
- package/dist/git/promote.js +160 -38
- package/dist/git/repo.d.ts +72 -0
- package/dist/git/repo.js +167 -0
- package/dist/git/status.d.ts +8 -0
- package/dist/git/status.js +25 -0
- package/dist/git/worktree.d.ts +63 -3
- package/dist/git/worktree.js +173 -29
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +230 -115
- package/dist/ports/allocate.d.ts +14 -3
- package/dist/ports/allocate.js +20 -4
- package/dist/selectors.d.ts +10 -0
- package/dist/selectors.js +106 -0
- package/dist/skill.d.ts +13 -0
- package/dist/skill.js +28 -0
- package/dist/state/registry.d.ts +194 -0
- package/dist/state/registry.js +595 -0
- package/dist/sync/env.d.ts +77 -2
- package/dist/sync/env.js +151 -32
- package/dist/sync/files.d.ts +15 -1
- package/dist/sync/files.js +126 -38
- package/dist/utils/exec.d.ts +69 -4
- package/dist/utils/exec.js +221 -15
- package/dist/utils/log.d.ts +37 -0
- package/dist/utils/log.js +68 -4
- package/dist/utils/paths.d.ts +61 -0
- package/dist/utils/paths.js +163 -0
- package/dist/utils/sanitize.d.ts +7 -0
- package/dist/utils/sanitize.js +12 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/workspaces/resolve.d.ts +21 -0
- package/dist/workspaces/resolve.js +235 -0
- package/package.json +18 -14
- package/wtc.schema.json +62 -0
package/SKILL.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: worktree-compose
|
|
3
|
+
description: Run several git worktrees in parallel, each with its own isolated Docker Compose stack (ports, containers, networks, volumes), using worktree-compose (`wtc`). Use when starting, stopping, inspecting, or cleaning up per-worktree Docker stacks, finding a worktree's ports or URL, promoting a worktree's changes, configuring `.wtcrc.json`, or calling the wtc MCP tools (`wtc_start`, `wtc_list`, …).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# worktree-compose (`wtc`)
|
|
7
|
+
|
|
8
|
+
`wtc` gives every git worktree its own Docker Compose stack: its own host ports, containers, networks, and volumes, from the repo's existing compose file. Docs: https://www.worktree-compose.com
|
|
9
|
+
|
|
10
|
+
## Invoke it as `wtc`
|
|
11
|
+
|
|
12
|
+
- Installed globally: `npm install -g worktree-compose`, then run `wtc <command>`.
|
|
13
|
+
- Never run `npx wtc`: an unrelated npm package is named `wtc`. Without a global install, use `npx worktree-compose <command>`.
|
|
14
|
+
- Run from the main checkout or any worktree. Compose file, config, and env files always come from the main checkout.
|
|
15
|
+
|
|
16
|
+
## Everyday loop
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git worktree add -b my-feature ../myapp-my-feature # 1. create the worktree
|
|
20
|
+
cd ../myapp-my-feature
|
|
21
|
+
wtc start . # 2. sync infra files, inject ports, compose up -d --build
|
|
22
|
+
wtc list # 3. status, URL and ports (wtc list --json for parsing)
|
|
23
|
+
wtc restart . # after Dockerfile, compose, env or migration changes
|
|
24
|
+
wtc stop . # pause; containers and data are kept, start resumes them
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Prefer `.` (the worktree containing the current directory) when working inside a worktree. Other selectors: the stable **index** (`2`), the **branch** (`my-feature`), the **directory name** (`myapp-my-feature`), or a **path**. No selector = all worktrees. A number that is both an index and another worktree's branch/directory name is rejected as ambiguous; pass the branch, directory name, or the path the error suggests (e.g. `../2`).
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
| Command | Effect |
|
|
32
|
+
|---------|--------|
|
|
33
|
+
| `wtc start [wt...] [--env <file>] [--workspace <ws>]... [--no-build]` | Sync compose/Dockerfiles/`sync` paths from main, copy env files fresh from main, inject ports + `COMPOSE_PROJECT_NAME`, `compose up -d --build`. Stops at the first failure. |
|
|
34
|
+
| `wtc stop [wt...]` | `compose stop`. Containers and **all volumes are kept**. |
|
|
35
|
+
| `wtc restart [wt...] [same flags]` | `compose stop`, then start with `--remove-orphans`; changed services are recreated, volumes kept. |
|
|
36
|
+
| `wtc list` / `wtc ls` `[--json]` | Read-only. Rows: `index, branch, path, project, status, running, total, url, ports, orphan, unavailable`. Status: `up`, `partial`, `exited` (stopped), `down` (no containers), `?` (engine unreachable). `unavailable`: `"missing"` (locked, directory missing — e.g. unmounted drive), `"main"` (became the main checkout), or `null`. |
|
|
37
|
+
| `wtc promote <wt> [--force]` | Copy the worktree's changes (committed since it branched, staged, unstaged, untracked; deletions too) into the checkout you run it from, uncommitted. Skips compose files and local env files. |
|
|
38
|
+
| `wtc prune [--dry-run]` | Tear down (`down -v`, **deletes volumes**) and forget stacks of worktrees that were already deleted. |
|
|
39
|
+
| `wtc clean [--dry-run] [--force] [--keep-worktrees] [--sweep]` | `down -v` on **every** stack (**deletes all their volumes**), remove worktrees that hold no work, sweep leftovers this checkout owns. |
|
|
40
|
+
| `wtc doctor [--json]` | Diagnose git, compose file, config, engine + daemon, port isolation, `container_name` / shared volumes, collisions, orphans, busy ports. Exit 1 on any ✖. |
|
|
41
|
+
| `wtc skill [--install] [--dir <path>]` | Print this skill, or install it to `~/.claude/skills/worktree-compose/SKILL.md` (or `<path>/worktree-compose/`). |
|
|
42
|
+
| `wtc mcp` | MCP server on stdio. |
|
|
43
|
+
|
|
44
|
+
## Data safety: stop vs. clean
|
|
45
|
+
|
|
46
|
+
- To pause or free CPU/RAM, use `wtc stop`. Data survives; `wtc start` resumes.
|
|
47
|
+
- `wtc clean` and `wtc prune` delete volumes (databases, caches). `clean` deletes them for **every** stack, including worktrees it keeps and with `--keep-worktrees`. Get the user's go-ahead before running them, preview with `--dry-run`, and never add `--force` on your own.
|
|
48
|
+
- `clean` never removes the main checkout or the worktree it runs from. Without `--force` it also keeps worktrees with uncommitted changes (other than files wtc wrote), commits on a detached HEAD that no branch/tag/remote has, unpushed submodule commits, or a lock, and prints why.
|
|
49
|
+
- `clean` only removes Docker resources of stacks this checkout owns. `--sweep` also removes `<repo>-wt-<n>-…` stacks whose worktree directory no longer exists (e.g. left by wtc 0.2), as long as they still have a container; volumes or networks with no container left are listed for the user to remove, never removed.
|
|
50
|
+
|
|
51
|
+
## Identity, ports, project names
|
|
52
|
+
|
|
53
|
+
- A worktree's index and compose project are recorded in `.git/wtc/state.json` the first time wtc acts on it (`list`, `doctor` and dry runs only read) and never change: removing a worktree never renumbers the others, renaming its branch keeps the project, `git worktree move` keeps everything. A new worktree gets the lowest free index.
|
|
54
|
+
- A deleted worktree becomes an orphan: `wtc list` shows `(removed)` and its index stays reserved until `wtc prune` or `wtc clean`. A worktree git still lists is never an orphan: a locked one whose directory is missing shows `(locked, missing on disk)` and `prune`/`clean` leave its stack alone.
|
|
55
|
+
- If wtc cannot tell which checkout is the main one (bare repo whose default-branch worktree is mid-rebase/on another branch, or a `--separate-git-dir` repo seen from a linked worktree before wtc ran in the main checkout), `start`, `restart` and `clean` refuse with the fix in the message; tell the user rather than working around it.
|
|
56
|
+
- Ports: `20000 + default_port + index × portStride` (`portStride` default `1`). Only host ports written as `${VAR:-default}` (upper-case `VAR`) are isolated; hardcoded ones are warned about.
|
|
57
|
+
- Project: `{repo}-wt-{index}-{branch}`, sanitized (e.g. `myapp-wt-1-feature-auth`).
|
|
58
|
+
|
|
59
|
+
## Env files
|
|
60
|
+
|
|
61
|
+
- Every start/restart copies `<envFile>` (default `.env`, fallback `.env.example`) **fresh from main**, then writes `COMPOSE_PROJECT_NAME` (root only), the allocated `*_PORT` variables, and `envOverrides`. Existing keys are rewritten in place; the rest go in a `# --- wtc port overrides ---` block.
|
|
62
|
+
- Edits made only in a worktree's env file are lost on the next start. Put lasting values in main's env file or in `envOverrides` / `workspaceEnvOverrides`.
|
|
63
|
+
- Only those keys are written. A value with a port inside (`DATABASE_URL=…:5434/app`) needs an override: `"DATABASE_URL": "postgresql://app:app@localhost:${POSTGRES_PORT}/app"`. `${COMPOSE_PROJECT_NAME}` interpolates too.
|
|
64
|
+
- With the default `.env`, a plain `docker compose ps|logs|exec` inside the worktree reaches the worktree's stack. With a custom `envFile` (e.g. `.env.development`), add `--env-file .env.development` or `-p <project>` (from `wtc list --json`).
|
|
65
|
+
- Monorepos: `--env .env.development --workspace server` (repeatable) also copies and injects `apps/server/.env.development`. Use `--env`, never `--env-file` (Node intercepts it).
|
|
66
|
+
|
|
67
|
+
## Promote rules
|
|
68
|
+
|
|
69
|
+
`wtc promote <wt>` runs from the checkout that should receive the changes (usually main) and aborts before writing anything when:
|
|
70
|
+
|
|
71
|
+
- a file it would touch has uncommitted or untracked changes there: commit or stash first;
|
|
72
|
+
- a file it would touch was also committed on that branch since the worktree branched: promoting would revert those commits. Merge that branch into the worktree first (the error prints the command); `--force` overwrites anyway;
|
|
73
|
+
- a path escapes the repo or goes through a symlinked directory, or the worktree is the current checkout.
|
|
74
|
+
|
|
75
|
+
## Diagnose
|
|
76
|
+
|
|
77
|
+
Run `wtc doctor` first when a stack won't start, ports look wrong, or `wtc list` shows `?` or `(removed)` rows. Typical fixes: remove `container_name` (or use `${COMPOSE_PROJECT_NAME}`), drop fixed `name:`/`external` on volumes and networks, write host ports as `${VAR:-default}`, raise `portStride` on collisions, `wtc prune` for orphans, start the Docker/Podman daemon or set `WTC_COMPOSE_COMMAND`.
|
|
78
|
+
|
|
79
|
+
## Config (optional)
|
|
80
|
+
|
|
81
|
+
`.wtcrc.json` at the main checkout's root (or `"wtc"` in `package.json`):
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"$schema": "https://unpkg.com/worktree-compose/wtc.schema.json",
|
|
86
|
+
"sync": [".generated/prisma-client"],
|
|
87
|
+
"envFile": ".env.development",
|
|
88
|
+
"workspaces": ["server"],
|
|
89
|
+
"envOverrides": { "VITE_API_URL": "http://localhost:${BACKEND_PORT}" },
|
|
90
|
+
"workspaceEnvOverrides": { "server": { "DATABASE_URL": "postgresql://app:app@localhost:${POSTGRES_PORT}/app" } },
|
|
91
|
+
"portStride": 100,
|
|
92
|
+
"composeCommand": "podman compose"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Engines: auto-detects `docker compose` → `podman compose` → `docker-compose` → `podman-compose` (preferring one whose daemon answers). `composeCommand` may only be one of those four; anything custom (e.g. `docker --context colima compose`) goes in the `WTC_COMPOSE_COMMAND` environment variable.
|
|
97
|
+
|
|
98
|
+
## MCP tools
|
|
99
|
+
|
|
100
|
+
Register: `claude mcp add --scope user wtc -- wtc mcp` (Claude Code), or `{"command": "wtc", "args": ["mcp"]}` in `.mcp.json` / `.cursor/mcp.json`, or `[mcp_servers.wtc]` with `command = "wtc"`, `args = ["mcp"]` in `~/.codex/config.toml`. The server acts on the repo of the directory it starts in.
|
|
101
|
+
|
|
102
|
+
| Tool | Parameters | Notes |
|
|
103
|
+
|------|-----------|-------|
|
|
104
|
+
| `wtc_start` | `indices?`, `envFile?`, `workspaces?`, `build?` (default true) | |
|
|
105
|
+
| `wtc_stop` | `indices?` | keeps containers and volumes |
|
|
106
|
+
| `wtc_restart` | `indices?`, `envFile?`, `workspaces?`, `build?` | |
|
|
107
|
+
| `wtc_list` | — | read-only; `content[0]` is the JSON array, warnings follow |
|
|
108
|
+
| `wtc_promote` | `index`, `force?` | destructive: writes into the server's checkout |
|
|
109
|
+
| `wtc_clean` | `force?`, `keepWorktrees?`, `dryRun?`, `sweep?` | destructive: deletes volumes, removes worktrees |
|
|
110
|
+
| `wtc_prune` | `dryRun?` | destructive: deletes removed worktrees' volumes |
|
|
111
|
+
| `wtc_doctor` | — | read-only; returns JSON |
|
|
112
|
+
|
|
113
|
+
`indices` is an array of numbers (always indices) or strings (index, branch, directory name, path, `.`); omit it for all worktrees. Failures return `isError: true` with the reason. Mutating tools run one at a time; cancelling a request stops its compose command, and a request cancelled while it waits its turn does not run.
|
package/dist/cli.js
CHANGED
|
@@ -6,70 +6,131 @@ import { restartCommand } from "./commands/restart.js";
|
|
|
6
6
|
import { listCommand } from "./commands/list.js";
|
|
7
7
|
import { promoteCommand } from "./commands/promote.js";
|
|
8
8
|
import { cleanCommand } from "./commands/clean.js";
|
|
9
|
+
import { pruneCommand } from "./commands/prune.js";
|
|
10
|
+
import { doctorCommand } from "./commands/doctor.js";
|
|
11
|
+
import { skillCommand } from "./commands/skill.js";
|
|
9
12
|
import { startMcpServer } from "./mcp/server.js";
|
|
10
|
-
import { error } from "./utils/log.js";
|
|
13
|
+
import { error, setLogStream } from "./utils/log.js";
|
|
14
|
+
import { VERSION } from "./version.js";
|
|
11
15
|
const program = new Command();
|
|
12
16
|
program
|
|
13
17
|
.name("wtc")
|
|
14
18
|
.description("Zero-config Docker Compose isolation for git worktrees")
|
|
15
|
-
.version(
|
|
16
|
-
|
|
19
|
+
.version(VERSION);
|
|
20
|
+
function collectWorkspace(value, previous) {
|
|
21
|
+
return [...previous, value];
|
|
22
|
+
}
|
|
23
|
+
function startCliOptions(options) {
|
|
24
|
+
return {
|
|
25
|
+
envFile: options.env,
|
|
26
|
+
workspaces: options.workspace,
|
|
27
|
+
build: options.build !== false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const WORKTREES_ARG_HELP = "Worktrees by index, branch, directory name, path, or . (omit for all)";
|
|
31
|
+
function withStartOptions(command) {
|
|
32
|
+
return command
|
|
33
|
+
.option("--env <name>", 'Env filename to copy and inject (default: config "envFile", else ".env")')
|
|
34
|
+
.option("--workspace <name>", "Workspace to also inject env into (repeatable)", collectWorkspace, [])
|
|
35
|
+
.option("--no-build", "Skip --build on docker compose up");
|
|
36
|
+
}
|
|
37
|
+
withStartOptions(program
|
|
17
38
|
.command("start")
|
|
18
39
|
.description("Start Docker Compose stacks for worktrees")
|
|
19
|
-
.argument("[
|
|
20
|
-
|
|
21
|
-
wrap(() => startCommand(indices.map(Number)));
|
|
40
|
+
.argument("[worktrees...]", WORKTREES_ARG_HELP)).action(async (worktrees, options) => {
|
|
41
|
+
await wrap(() => startCommand(worktrees, startCliOptions(options)));
|
|
22
42
|
});
|
|
23
43
|
program
|
|
24
44
|
.command("stop")
|
|
25
|
-
.description("Stop
|
|
26
|
-
.argument("[
|
|
27
|
-
.action((
|
|
28
|
-
wrap(() => stopCommand(
|
|
45
|
+
.description("Stop the containers of worktree stacks (start resumes them)")
|
|
46
|
+
.argument("[worktrees...]", WORKTREES_ARG_HELP)
|
|
47
|
+
.action(async (worktrees) => {
|
|
48
|
+
await wrap(() => stopCommand(worktrees));
|
|
29
49
|
});
|
|
30
|
-
program
|
|
50
|
+
withStartOptions(program
|
|
31
51
|
.command("restart")
|
|
32
52
|
.description("Restart Docker Compose stacks for worktrees")
|
|
33
|
-
.argument("[
|
|
34
|
-
|
|
35
|
-
wrap(() => restartCommand(indices.map(Number)));
|
|
53
|
+
.argument("[worktrees...]", WORKTREES_ARG_HELP)).action(async (worktrees, options) => {
|
|
54
|
+
await wrap(() => restartCommand(worktrees, startCliOptions(options)));
|
|
36
55
|
});
|
|
37
56
|
program
|
|
38
57
|
.command("list")
|
|
39
58
|
.alias("ls")
|
|
40
|
-
.description("List
|
|
41
|
-
.
|
|
42
|
-
|
|
59
|
+
.description("List worktrees with status, ports and URLs")
|
|
60
|
+
.option("--json", "Print machine-readable JSON")
|
|
61
|
+
.action(async (options) => {
|
|
62
|
+
await wrap(() => listCommand({ json: options.json }));
|
|
43
63
|
});
|
|
44
64
|
program
|
|
45
65
|
.command("promote")
|
|
46
|
-
.description("Copy changed files from a worktree into the current
|
|
47
|
-
.argument("<
|
|
48
|
-
.
|
|
49
|
-
|
|
66
|
+
.description("Copy changed files from a worktree into the current checkout")
|
|
67
|
+
.argument("<worktree>", "Worktree by index, branch, directory name, or path")
|
|
68
|
+
.option("--force", "Also promote files the current branch changed since the worktree branched (overwrites those commits)")
|
|
69
|
+
.action(async (worktree, options) => {
|
|
70
|
+
await wrap(() => promoteCommand(worktree, { force: options.force }));
|
|
50
71
|
});
|
|
51
72
|
program
|
|
52
73
|
.command("clean")
|
|
53
|
-
.description("
|
|
54
|
-
.
|
|
55
|
-
|
|
74
|
+
.description("Tear down every worktree stack (down -v: deletes their volumes), remove worktrees that hold no work, sweep leftovers this checkout owns")
|
|
75
|
+
.option("--force", "Also remove worktrees with uncommitted changes, commits on no branch, unpushed submodule commits, and locked ones")
|
|
76
|
+
.option("--keep-worktrees", "Tear down stacks (deleting their volumes) but keep every worktree")
|
|
77
|
+
.option("--dry-run", "Show what would be stopped/removed; change nothing")
|
|
78
|
+
.option("--sweep", "Also remove <repo>-wt-N-* stacks whose worktree directory no longer exists (e.g. left by wtc 0.2), judged from their containers: volumes or networks with no container left are listed, never removed")
|
|
79
|
+
.action(async (options) => {
|
|
80
|
+
await wrap(() => cleanCommand({
|
|
81
|
+
force: options.force,
|
|
82
|
+
keepWorktrees: options.keepWorktrees,
|
|
83
|
+
dryRun: options.dryRun,
|
|
84
|
+
sweep: options.sweep,
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
program
|
|
88
|
+
.command("prune")
|
|
89
|
+
.description("Tear down stacks of deleted worktrees (down -v: deletes their volumes) and forget them")
|
|
90
|
+
.option("--dry-run", "Show what would be pruned; change nothing")
|
|
91
|
+
.action(async (options) => {
|
|
92
|
+
await wrap(() => pruneCommand({ dryRun: options.dryRun }));
|
|
93
|
+
});
|
|
94
|
+
program
|
|
95
|
+
.command("doctor")
|
|
96
|
+
.description("Check git, compose, engine, ports and isolation settings")
|
|
97
|
+
.option("--json", "Print machine-readable JSON")
|
|
98
|
+
.action(async (options) => {
|
|
99
|
+
await wrap(() => doctorCommand({ json: options.json }));
|
|
100
|
+
});
|
|
101
|
+
program
|
|
102
|
+
.command("skill")
|
|
103
|
+
.description("Print the bundled agent skill (SKILL.md), or install it")
|
|
104
|
+
.option("--install", "Write it to ~/.claude/skills/worktree-compose/SKILL.md")
|
|
105
|
+
.option("--dir <path>", "Install under <path>/worktree-compose/ instead")
|
|
106
|
+
.action(async (options) => {
|
|
107
|
+
await wrap(() => skillCommand(options));
|
|
56
108
|
});
|
|
57
109
|
program
|
|
58
110
|
.command("mcp")
|
|
59
111
|
.description("Start the MCP server (stdio transport)")
|
|
60
|
-
.action(() => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
112
|
+
.action(async () => {
|
|
113
|
+
// stdout carries JSON-RPC: route every log line (and any stray
|
|
114
|
+
// console.log) to stderr before anything else runs.
|
|
115
|
+
setLogStream("stderr");
|
|
116
|
+
console.log = console.error;
|
|
117
|
+
console.info = console.error;
|
|
118
|
+
console.debug = console.error;
|
|
119
|
+
try {
|
|
120
|
+
await startMcpServer();
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
error(err instanceof Error ? err.message : String(err));
|
|
124
|
+
process.exitCode = 1;
|
|
125
|
+
}
|
|
65
126
|
});
|
|
66
|
-
function wrap(fn) {
|
|
127
|
+
async function wrap(fn) {
|
|
67
128
|
try {
|
|
68
|
-
fn();
|
|
129
|
+
await fn();
|
|
69
130
|
}
|
|
70
131
|
catch (err) {
|
|
71
132
|
error(err instanceof Error ? err.message : String(err));
|
|
72
|
-
process.
|
|
133
|
+
process.exitCode = 1;
|
|
73
134
|
}
|
|
74
135
|
}
|
|
75
|
-
program.
|
|
136
|
+
await program.parseAsync();
|
package/dist/commands/clean.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { CleanOptions } from "../core/clean.js";
|
|
2
|
+
export declare function cleanCommand(options?: CleanOptions): Promise<void>;
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,49 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const worktrees = getNonMainWorktrees(repoRoot);
|
|
10
|
-
const currentWt = execSafe("git rev-parse --show-toplevel") ?? repoRoot;
|
|
11
|
-
for (let i = 0; i < worktrees.length; i++) {
|
|
12
|
-
const wt = worktrees[i];
|
|
13
|
-
const idx = i + 1;
|
|
14
|
-
const project = composeProjectName(repoName, idx, wt.branch);
|
|
15
|
-
log.info(`Stopping containers for ${project}...`);
|
|
16
|
-
try {
|
|
17
|
-
exec(`docker compose -p "${project}" down`, { cwd: wt.path });
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
// already stopped
|
|
21
|
-
}
|
|
22
|
-
if (wt.path === currentWt) {
|
|
23
|
-
log.warn(`Skipping removal of current worktree: ${wt.path}`);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
log.info(`Removing worktree: ${wt.path}`);
|
|
27
|
-
try {
|
|
28
|
-
exec(`git -C "${repoRoot}" worktree remove "${wt.path}" --force`);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
log.warn(`Could not remove ${wt.path}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
execSafe(`git -C "${repoRoot}" worktree prune`);
|
|
35
|
-
const staleContainers = execSafe(`docker ps -aq --filter "label=com.docker.compose.project" --filter "name=-wt-"`);
|
|
36
|
-
if (staleContainers) {
|
|
37
|
-
log.info("Removing stale worktree containers...");
|
|
38
|
-
execSafe(`docker rm -f ${staleContainers}`);
|
|
39
|
-
}
|
|
40
|
-
const staleNetworks = execSafe(`docker network ls -q --filter "name=${repoName}-wt-"`);
|
|
41
|
-
if (staleNetworks) {
|
|
42
|
-
execSafe(`docker network rm ${staleNetworks}`);
|
|
43
|
-
}
|
|
44
|
-
const staleVolumes = execSafe(`docker volume ls -q --filter "name=${repoName}-wt-"`);
|
|
45
|
-
if (staleVolumes) {
|
|
46
|
-
execSafe(`docker volume rm ${staleVolumes}`);
|
|
47
|
-
}
|
|
48
|
-
log.success("Cleanup complete.");
|
|
1
|
+
import { clean } from "../core/clean.js";
|
|
2
|
+
import { consoleReporter } from "../utils/log.js";
|
|
3
|
+
export async function cleanCommand(options = {}) {
|
|
4
|
+
const result = await clean(options, consoleReporter, { live: true });
|
|
5
|
+
// Kept (dirty, locked, current) worktrees are intended outcomes; only
|
|
6
|
+
// real failures make the exit code non-zero.
|
|
7
|
+
if (result.failures > 0)
|
|
8
|
+
process.exitCode = 1;
|
|
49
9
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { doctor } from "../core/doctor.js";
|
|
3
|
+
import { print } from "../utils/log.js";
|
|
4
|
+
const ICONS = {
|
|
5
|
+
ok: chalk.green("✔"),
|
|
6
|
+
warn: chalk.yellow("⚠"),
|
|
7
|
+
fail: chalk.red("✖"),
|
|
8
|
+
};
|
|
9
|
+
export async function doctorCommand(options = {}) {
|
|
10
|
+
const result = await doctor({ live: true });
|
|
11
|
+
if (options.json) {
|
|
12
|
+
console.log(JSON.stringify(result, null, 2));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
for (const check of result.checks) {
|
|
16
|
+
print(`${ICONS[check.status]} ${check.title}`);
|
|
17
|
+
if (check.detail)
|
|
18
|
+
print(chalk.dim(` ${check.detail}`));
|
|
19
|
+
if (check.hint)
|
|
20
|
+
print(chalk.cyan(` → ${check.hint}`));
|
|
21
|
+
}
|
|
22
|
+
const fails = result.checks.filter((c) => c.status === "fail").length;
|
|
23
|
+
const warns = result.checks.filter((c) => c.status === "warn").length;
|
|
24
|
+
print(`\n${fails > 0 ? chalk.red(`${fails} problem(s)`) : chalk.green("No problems")}` +
|
|
25
|
+
(warns > 0 ? `, ${chalk.yellow(`${warns} warning(s)`)}` : "") +
|
|
26
|
+
".");
|
|
27
|
+
}
|
|
28
|
+
if (!result.ok)
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
}
|
package/dist/commands/list.d.ts
CHANGED
package/dist/commands/list.js
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
import Table from "cli-table3";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { listWorktrees } from "../core/list.js";
|
|
4
|
+
import { print, warn } from "../utils/log.js";
|
|
5
|
+
function renderStatus(row) {
|
|
6
|
+
switch (row.status) {
|
|
7
|
+
case "up":
|
|
8
|
+
return chalk.green("up");
|
|
9
|
+
case "partial":
|
|
10
|
+
return chalk.yellow(`partial ${row.running}/${row.total}`);
|
|
11
|
+
case "exited":
|
|
12
|
+
return chalk.yellow("exited");
|
|
13
|
+
case "down":
|
|
14
|
+
return chalk.red("down");
|
|
15
|
+
default:
|
|
16
|
+
return chalk.dim("?");
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
|
-
export function listCommand() {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
export async function listCommand(options = {}) {
|
|
20
|
+
const result = listWorktrees({ live: true });
|
|
21
|
+
if (options.json) {
|
|
22
|
+
// Keep stdout machine-readable: warnings go to stderr.
|
|
23
|
+
for (const w of result.warnings)
|
|
24
|
+
console.error(`⚠ ${w}`);
|
|
25
|
+
console.log(JSON.stringify(result.rows, null, 2));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// After start/restart (`quiet`), the warnings were already printed.
|
|
29
|
+
for (const w of options.quiet ? [] : result.warnings)
|
|
30
|
+
warn(w);
|
|
31
|
+
if (!options.quiet && result.isolationWarnings.length > 0) {
|
|
32
|
+
warn(`${result.isolationWarnings.length} isolation warning(s) — run 'wtc doctor'`);
|
|
19
33
|
}
|
|
20
|
-
if (
|
|
21
|
-
|
|
34
|
+
if (result.rows.length === 0) {
|
|
35
|
+
print("\nNo extra worktrees found. Create one with:\n git worktree add ../my-branch my-branch\n");
|
|
22
36
|
return;
|
|
23
37
|
}
|
|
24
38
|
const table = new Table({
|
|
@@ -30,42 +44,46 @@ export function listCommand() {
|
|
|
30
44
|
chalk.white("Ports"),
|
|
31
45
|
],
|
|
32
46
|
});
|
|
33
|
-
const overridable = ctx.portMappings.filter((m) => m.envVar !== null);
|
|
34
|
-
const defaultPorts = overridable
|
|
35
|
-
.map((m) => `${m.serviceName}:${m.defaultPort}`)
|
|
36
|
-
.join(" ");
|
|
37
47
|
table.push([
|
|
38
48
|
chalk.dim("-"),
|
|
39
49
|
chalk.dim("main"),
|
|
40
50
|
chalk.dim("-"),
|
|
41
51
|
chalk.dim("-"),
|
|
42
|
-
chalk.dim(
|
|
52
|
+
chalk.dim(result.mainPorts.map((p) => `${p.service}:${p.port}`).join(" ")),
|
|
43
53
|
]);
|
|
44
|
-
for (
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const project = composeProjectName(ctx.repoName, idx, wt.branch);
|
|
48
|
-
const allocations = allocateWorktreePorts(ctx.portMappings, idx, ctx.portStride);
|
|
49
|
-
const up = isWorktreeUp(project, wt.path);
|
|
50
|
-
const ports = allocations
|
|
51
|
-
.map((a) => `${a.serviceName}:${a.port}`)
|
|
54
|
+
for (const row of result.rows) {
|
|
55
|
+
const ports = Object.entries(row.ports)
|
|
56
|
+
.map(([envVar, port]) => `${envVar}=${port}`)
|
|
52
57
|
.join(" ");
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
if (row.orphan || row.unavailable) {
|
|
59
|
+
const note = row.orphan
|
|
60
|
+
? "removed"
|
|
61
|
+
: row.unavailable === "missing"
|
|
62
|
+
? "locked, missing on disk"
|
|
63
|
+
: "now the main checkout";
|
|
64
|
+
table.push([
|
|
65
|
+
chalk.dim(String(row.index)),
|
|
66
|
+
chalk.dim(`${row.branch} (${note})`),
|
|
67
|
+
renderStatus(row),
|
|
68
|
+
chalk.dim("-"),
|
|
69
|
+
chalk.dim(ports),
|
|
70
|
+
]);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const url = row.url ?? "-";
|
|
62
74
|
table.push([
|
|
63
|
-
String(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
up ? chalk.underline(url) : chalk.dim(url),
|
|
75
|
+
String(row.index),
|
|
76
|
+
row.branch,
|
|
77
|
+
renderStatus(row),
|
|
78
|
+
row.status === "up" || row.status === "partial" ? chalk.underline(url) : chalk.dim(url),
|
|
67
79
|
ports,
|
|
68
80
|
]);
|
|
69
81
|
}
|
|
70
|
-
|
|
82
|
+
print(table.toString());
|
|
83
|
+
if (result.rows.some((r) => r.orphan)) {
|
|
84
|
+
print(chalk.dim("(removed) = the worktree is gone but its stack/record remains. Run 'wtc prune' to tear it down."));
|
|
85
|
+
}
|
|
86
|
+
if (result.rows.some((r) => r.unavailable === "missing")) {
|
|
87
|
+
print(chalk.dim("(locked, missing on disk) = remount it (e.g. an unmounted drive) to use it; wtc keeps its stack and index meanwhile."));
|
|
88
|
+
}
|
|
71
89
|
}
|
package/dist/commands/promote.js
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function promoteCommand(index) {
|
|
6
|
-
const repoRoot = getRepoRoot();
|
|
7
|
-
const wt = getWorktreeByIndex(repoRoot, index);
|
|
8
|
-
if (!wt) {
|
|
9
|
-
log.error(`Worktree index ${index} not found. Run 'wtc list' to see available worktrees.`);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
const currentBranch = getWorktreeBranch(repoRoot);
|
|
13
|
-
const displayCurrent = currentBranch === "HEAD" ? "detached HEAD" : currentBranch;
|
|
14
|
-
log.info(`Promoting worktree ${index} (${wt.branch}) into ${displayCurrent}`);
|
|
15
|
-
const files = getChangedFiles(repoRoot, wt.path, currentBranch, wt.branch);
|
|
16
|
-
if (files.length === 0) {
|
|
17
|
-
log.info("No changes to promote.");
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const dirtyFiles = getLocalDirtyFiles(repoRoot);
|
|
21
|
-
const conflicts = findConflicts(files, dirtyFiles);
|
|
22
|
-
if (conflicts.length > 0) {
|
|
23
|
-
log.error("Abort: the following files have uncommitted changes and would be overwritten:");
|
|
24
|
-
for (const f of conflicts) {
|
|
25
|
-
console.log(` ${f}`);
|
|
26
|
-
}
|
|
27
|
-
console.log("\nCommit or stash your local changes first, then re-run promote.");
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
promoteFiles(repoRoot, wt.path, files);
|
|
31
|
-
log.success(`Promoted ${files.length} file(s). Changes are uncommitted in ${currentBranch}.`);
|
|
32
|
-
for (const f of files) {
|
|
33
|
-
console.log(` ${f}`);
|
|
34
|
-
}
|
|
1
|
+
import { promoteWorktree } from "../core/promote.js";
|
|
2
|
+
import { consoleReporter } from "../utils/log.js";
|
|
3
|
+
export async function promoteCommand(worktree, options = {}) {
|
|
4
|
+
await promoteWorktree({ worktree, force: options.force }, consoleReporter, { live: true });
|
|
35
5
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { prune } from "../core/prune.js";
|
|
2
|
+
import { consoleReporter } from "../utils/log.js";
|
|
3
|
+
export async function pruneCommand(options = {}) {
|
|
4
|
+
const result = await prune(options, consoleReporter, { live: true });
|
|
5
|
+
if (result.failures > 0)
|
|
6
|
+
process.exitCode = 1;
|
|
7
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { StartOptions } from "../core/start.js";
|
|
2
|
+
export declare function restartCommand(worktrees: string[], options?: Omit<StartOptions, "worktrees">): Promise<void>;
|
package/dist/commands/restart.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { restartWorktrees } from "../core/restart.js";
|
|
2
|
+
import { consoleReporter, print } from "../utils/log.js";
|
|
3
|
+
import { listCommand } from "./list.js";
|
|
4
|
+
export async function restartCommand(worktrees, options = {}) {
|
|
5
|
+
// Env options and selectors are validated before anything is stopped, so
|
|
6
|
+
// an invalid --env name or unknown --workspace never leaves stacks down.
|
|
7
|
+
const result = await restartWorktrees({ ...options, worktrees }, consoleReporter, { live: true });
|
|
8
|
+
if (result.started.length === 0)
|
|
9
|
+
return;
|
|
10
|
+
print("");
|
|
11
|
+
await listCommand({ quiet: true });
|
|
6
12
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { installSkill, readSkill } from "../skill.js";
|
|
2
|
+
import * as log from "../utils/log.js";
|
|
3
|
+
export async function skillCommand(options = {}) {
|
|
4
|
+
if (options.install || options.dir) {
|
|
5
|
+
const dest = installSkill(options.dir);
|
|
6
|
+
log.success(`Installed the worktree-compose skill at ${dest}`);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
process.stdout.write(readSkill());
|
|
10
|
+
}
|
package/dist/commands/start.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { StartOptions } from "../core/start.js";
|
|
2
|
+
export declare function startCommand(worktrees: string[], options?: Omit<StartOptions, "worktrees">): Promise<void>;
|