worktree-compose 0.1.4 → 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 +560 -125
- 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 +200 -12
- package/dist/compose/status.d.ts +84 -0
- package/dist/compose/status.js +227 -0
- package/dist/compose/types.d.ts +25 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.js +23 -6
- package/dist/context.d.ts +90 -3
- package/dist/context.js +293 -20
- 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 -116
- package/dist/ports/allocate.d.ts +34 -2
- package/dist/ports/allocate.js +69 -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 +16 -1
- package/dist/sync/files.js +136 -36
- 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 +13 -9
- package/wtc.schema.json +62 -0
package/dist/context.js
CHANGED
|
@@ -1,29 +1,302 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { detectComposeFile } from "./compose/detect.js";
|
|
2
3
|
import { parseComposeFile } from "./compose/parse.js";
|
|
4
|
+
import { resolveEngine } from "./compose/engine.js";
|
|
5
|
+
import { createStackProbe } from "./compose/status.js";
|
|
6
|
+
import { composeIsolationWarnings, portCollisionWarnings, rawPortWarnings, } from "./compose/isolation.js";
|
|
3
7
|
import { extractPortMappings } from "./ports/extract.js";
|
|
4
8
|
import { loadConfig } from "./config.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
import { assertMainCheckout, getRepoInfo, listRepoWorktrees } from "./git/repo.js";
|
|
10
|
+
import { isCandidate, samePath } from "./git/worktree.js";
|
|
11
|
+
import { hasRecord, peekState, reconcileWorktrees } from "./state/registry.js";
|
|
12
|
+
import { escapeRegExp, sanitize } from "./utils/sanitize.js";
|
|
13
|
+
import { resolveWorkspaces } from "./workspaces/resolve.js";
|
|
14
|
+
import { resolveSyncEntries } from "./sync/files.js";
|
|
15
|
+
import { DEFAULT_ENV_FILE } from "./sync/env.js";
|
|
16
|
+
function emptyComposeFile(composePath) {
|
|
17
|
+
return {
|
|
18
|
+
services: [],
|
|
19
|
+
composePath,
|
|
20
|
+
sourceFiles: [],
|
|
21
|
+
sharedVolumes: [],
|
|
22
|
+
sharedNetworks: [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Characters compose allows in a project name. */
|
|
26
|
+
const COMPOSE_PROJECT_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
27
|
+
/**
|
|
28
|
+
* Identities of running stacks that worktrees may adopt, keyed by worktree
|
|
29
|
+
* path: compose projects named like this repository's worktree stacks
|
|
30
|
+
* (`<repo>-wt-<n>-…`) whose `working_dir` label is one of `worktrees`.
|
|
31
|
+
* Compose records the directory it ran in, so a registry that was lost,
|
|
32
|
+
* corrupted, or never written (0.2) is rebuilt from the stacks themselves
|
|
33
|
+
* instead of renumbering them. One-off `compose run` containers are
|
|
34
|
+
* ignored; when several projects ran from one worktree, the one with the
|
|
35
|
+
* most running (then total) containers, then the lowest index, wins.
|
|
36
|
+
*/
|
|
37
|
+
export function adoptableStacks(containers, repoName, worktrees) {
|
|
38
|
+
const prefix = sanitize(repoName);
|
|
39
|
+
const pattern = new RegExp(`^${prefix ? `${escapeRegExp(prefix)}-` : ""}wt-(\\d+)-`);
|
|
40
|
+
const stacks = new Map();
|
|
41
|
+
for (const c of containers) {
|
|
42
|
+
if (!c.project || !c.workingDir || c.oneoff)
|
|
43
|
+
continue;
|
|
44
|
+
// Only a name compose accepts may become a record's project: a label
|
|
45
|
+
// that could not be parsed cleanly must never be persisted.
|
|
46
|
+
if (!COMPOSE_PROJECT_NAME.test(c.project))
|
|
47
|
+
continue;
|
|
48
|
+
const m = pattern.exec(c.project);
|
|
49
|
+
if (!m)
|
|
50
|
+
continue;
|
|
51
|
+
const wt = worktrees.find((w) => samePath(w.path, c.workingDir));
|
|
52
|
+
if (!wt)
|
|
53
|
+
continue;
|
|
54
|
+
const stack = stacks.get(c.project) ?? {
|
|
55
|
+
index: Number(m[1]),
|
|
56
|
+
project: c.project,
|
|
57
|
+
path: path.resolve(wt.path),
|
|
58
|
+
running: 0,
|
|
59
|
+
total: 0,
|
|
60
|
+
};
|
|
61
|
+
stack.total++;
|
|
62
|
+
if (c.running)
|
|
63
|
+
stack.running++;
|
|
64
|
+
stacks.set(c.project, stack);
|
|
65
|
+
}
|
|
66
|
+
const best = new Map();
|
|
67
|
+
const ranked = [...stacks.values()].sort((a, b) => b.running - a.running || b.total - a.total || a.index - b.index);
|
|
68
|
+
for (const s of ranked) {
|
|
69
|
+
if (s.index > 0 && !best.has(s.path))
|
|
70
|
+
best.set(s.path, { index: s.index, project: s.project });
|
|
71
|
+
}
|
|
72
|
+
return best;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* What worktrees seen for the first time may adopt — computed before the
|
|
76
|
+
* registry lock is taken: a slow engine must never hold the lock other wtc
|
|
77
|
+
* processes wait on. `undefined` when the engine is unavailable (no probe).
|
|
78
|
+
*/
|
|
79
|
+
function stacksToAdopt(stacks, repo, listWorktrees) {
|
|
80
|
+
const recorded = peekState(repo.commonDir);
|
|
81
|
+
const unrecorded = listWorktrees().filter((wt) => isCandidate(wt) && !hasRecord(recorded, wt));
|
|
82
|
+
// Every live worktree has a record: nothing to adopt, no `ps` needed.
|
|
83
|
+
if (unrecorded.length === 0)
|
|
84
|
+
return new Map();
|
|
85
|
+
if (stacks.problem !== null)
|
|
86
|
+
return undefined;
|
|
87
|
+
const containers = stacks.containers();
|
|
88
|
+
// Unparseable `ps` (per-project fallback): the engine answers, but no labels to adopt from.
|
|
89
|
+
return containers ? adoptableStacks(containers, repo.repoName, unrecorded) : new Map();
|
|
90
|
+
}
|
|
91
|
+
export function buildContext(cli = {}, opts = {}) {
|
|
92
|
+
const cwd = path.resolve(opts.cwd ?? process.cwd());
|
|
93
|
+
const repo = getRepoInfo(cwd);
|
|
94
|
+
if (opts.requireMainFor)
|
|
95
|
+
assertMainCheckout(repo, opts.requireMainFor);
|
|
96
|
+
const repoRoot = repo.mainRoot;
|
|
97
|
+
const warnings = [...repo.warnings];
|
|
9
98
|
const composePath = detectComposeFile(repoRoot);
|
|
10
|
-
if (!composePath) {
|
|
99
|
+
if (!composePath && !opts.allowMissingCompose) {
|
|
11
100
|
throw new Error(`No compose file found in ${repoRoot}. Expected one of: compose.yaml, compose.yml, docker-compose.yaml, docker-compose.yml`);
|
|
12
101
|
}
|
|
13
|
-
const composeFile =
|
|
102
|
+
const composeFile = composePath
|
|
103
|
+
? parseComposeFile(composePath)
|
|
104
|
+
: emptyComposeFile(path.join(repoRoot, "compose.yaml"));
|
|
14
105
|
const portMappings = extractPortMappings(composeFile.services);
|
|
15
|
-
const config = loadConfig(repoRoot);
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
106
|
+
const config = resolveConfig(loadConfig(repoRoot), cli);
|
|
107
|
+
const portStride = config.portStride ?? 1;
|
|
108
|
+
if (!Number.isInteger(portStride) || portStride < 1) {
|
|
109
|
+
throw new Error(`Invalid "portStride": ${String(portStride)}. Expected a positive integer.`);
|
|
110
|
+
}
|
|
111
|
+
warnings.push(...resolveSyncEntries(repoRoot, config.sync).warnings);
|
|
112
|
+
let engine = null;
|
|
113
|
+
const getEngine = () => {
|
|
114
|
+
engine ??= resolveEngine(config);
|
|
115
|
+
return engine;
|
|
116
|
+
};
|
|
117
|
+
let stacks = null;
|
|
118
|
+
if (opts.probeStacks) {
|
|
119
|
+
let problem = null;
|
|
120
|
+
try {
|
|
121
|
+
getEngine();
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
problem = err instanceof Error ? err.message : String(err);
|
|
125
|
+
}
|
|
126
|
+
stacks = createStackProbe(engine, problem, repoRoot);
|
|
127
|
+
}
|
|
128
|
+
const listWorktrees = () => listRepoWorktrees(repo);
|
|
129
|
+
const reconciled = reconcileWorktrees({
|
|
130
|
+
commonDir: repo.commonDir,
|
|
131
|
+
repoName: repo.repoName,
|
|
132
|
+
listWorktrees,
|
|
133
|
+
adoptable: stacks ? stacksToAdopt(stacks, repo, listWorktrees) : undefined,
|
|
134
|
+
// Without the main checkout identities are only computed: a stand-in
|
|
135
|
+
// main (and the repo name derived from it) must never be persisted.
|
|
136
|
+
readOnly: opts.readOnly || repo.mainRootIsFallback,
|
|
137
|
+
mainCheckout: repo.recordMain ? repo.mainRoot : undefined,
|
|
28
138
|
});
|
|
139
|
+
warnings.push(...reconciled.warnings);
|
|
140
|
+
const all = reconciled.listed;
|
|
141
|
+
const prunable = all.filter((wt) => !wt.isMain && wt.prunable);
|
|
142
|
+
for (const wt of prunable) {
|
|
143
|
+
warnings.push(`Worktree ${wt.path} is missing on disk — run 'git worktree prune'.`);
|
|
144
|
+
}
|
|
145
|
+
for (const wt of all.filter((w) => !w.isMain && w.missing)) {
|
|
146
|
+
const held = reconciled.unavailable.find((u) => u.reason === "missing" && samePath(u.path, wt.path));
|
|
147
|
+
warnings.push(`Worktree ${wt.path} is locked but missing on disk (unmounted drive?) — skipped` +
|
|
148
|
+
(held ? `; its index ${held.index} and stack ${held.project} are kept until it is back.` : "."));
|
|
149
|
+
}
|
|
150
|
+
for (const u of reconciled.unavailable.filter((r) => r.reason === "main")) {
|
|
151
|
+
warnings.push(`The main checkout ${u.path} was worktree ${u.index} (${u.project}) before it became the main checkout; ` +
|
|
152
|
+
`wtc leaves that stack alone (stop or remove it yourself if you no longer need it).`);
|
|
153
|
+
}
|
|
154
|
+
const isolationWarnings = [
|
|
155
|
+
...rawPortWarnings(portMappings),
|
|
156
|
+
...composeIsolationWarnings(composeFile),
|
|
157
|
+
...portCollisionWarnings(portMappings, portStride, [
|
|
158
|
+
...reconciled.worktrees.map((w) => w.index),
|
|
159
|
+
...reconciled.orphans.map((o) => o.index),
|
|
160
|
+
...reconciled.unavailable.map((u) => u.index),
|
|
161
|
+
]),
|
|
162
|
+
];
|
|
163
|
+
return {
|
|
164
|
+
repo,
|
|
165
|
+
repoRoot,
|
|
166
|
+
repoName: repo.repoName,
|
|
167
|
+
cwd,
|
|
168
|
+
composeFile,
|
|
169
|
+
hasComposeFile: composePath !== null,
|
|
170
|
+
portMappings,
|
|
171
|
+
config,
|
|
172
|
+
portStride,
|
|
173
|
+
worktrees: reconciled.worktrees,
|
|
174
|
+
orphans: reconciled.orphans,
|
|
175
|
+
unavailable: reconciled.unavailable,
|
|
176
|
+
prunable,
|
|
177
|
+
warnings,
|
|
178
|
+
isolationWarnings,
|
|
179
|
+
stacks,
|
|
180
|
+
getEngine,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** Merge CLI overrides over the loaded config and validate it. */
|
|
184
|
+
export function resolveConfig(config, cli) {
|
|
185
|
+
const envFile = cli.envFile ?? config.envFile ?? DEFAULT_ENV_FILE;
|
|
186
|
+
validateEnvFileName(envFile);
|
|
187
|
+
const workspaces = cli.workspaces && cli.workspaces.length > 0
|
|
188
|
+
? cli.workspaces
|
|
189
|
+
: (config.workspaces ?? []);
|
|
190
|
+
if (!Array.isArray(workspaces) ||
|
|
191
|
+
workspaces.some((w) => typeof w !== "string" || w.trim() === "")) {
|
|
192
|
+
throw new Error(`Invalid "workspaces" config: expected an array of workspace names.`);
|
|
193
|
+
}
|
|
194
|
+
if (config.sync !== undefined &&
|
|
195
|
+
(!Array.isArray(config.sync) ||
|
|
196
|
+
config.sync.some((s) => typeof s !== "string" || s.trim() === ""))) {
|
|
197
|
+
throw new Error(`Invalid "sync" config: expected an array of repo-relative paths.`);
|
|
198
|
+
}
|
|
199
|
+
const cmd = config.composeCommand;
|
|
200
|
+
if (cmd !== undefined &&
|
|
201
|
+
!(typeof cmd === "string" && cmd.trim() !== "") &&
|
|
202
|
+
!(Array.isArray(cmd) &&
|
|
203
|
+
cmd.length > 0 &&
|
|
204
|
+
cmd.every((c) => typeof c === "string" && c.trim() !== ""))) {
|
|
205
|
+
throw new Error(`Invalid "composeCommand" config: expected a command string such as "podman compose" or an array such as ["docker-compose"].`);
|
|
206
|
+
}
|
|
207
|
+
validateOverrides("envOverrides", config.envOverrides);
|
|
208
|
+
if (config.workspaceEnvOverrides !== undefined) {
|
|
209
|
+
const map = config.workspaceEnvOverrides;
|
|
210
|
+
if (typeof map !== "object" || map === null || Array.isArray(map)) {
|
|
211
|
+
throw new Error(`Invalid "workspaceEnvOverrides" config: expected an object of workspace -> overrides.`);
|
|
212
|
+
}
|
|
213
|
+
for (const [name, overrides] of Object.entries(map)) {
|
|
214
|
+
validateOverrides(`workspaceEnvOverrides.${name}`, overrides);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return { ...config, envFile, workspaces };
|
|
218
|
+
}
|
|
219
|
+
function validateEnvFileName(name) {
|
|
220
|
+
if (!name ||
|
|
221
|
+
name === "." ||
|
|
222
|
+
name === ".." ||
|
|
223
|
+
name.includes("/") ||
|
|
224
|
+
name.includes("\\") ||
|
|
225
|
+
path.isAbsolute(name)) {
|
|
226
|
+
throw new Error(`Invalid env file name "${name}". Expected a bare filename such as ".env" or ".env.development".`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function validateOverrides(label, overrides) {
|
|
230
|
+
if (overrides === undefined)
|
|
231
|
+
return;
|
|
232
|
+
if (typeof overrides !== "object" ||
|
|
233
|
+
overrides === null ||
|
|
234
|
+
Array.isArray(overrides)) {
|
|
235
|
+
throw new Error(`Invalid "${label}" config: expected an object of VAR -> value.`);
|
|
236
|
+
}
|
|
237
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
238
|
+
if (typeof value !== "string") {
|
|
239
|
+
throw new Error(`Invalid "${label}.${key}": expected a string value (got ${typeof value}).`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Env targets for a run: the repo root always, plus every selected workspace.
|
|
245
|
+
* Workspace targets are additive — the root env file is what docker compose
|
|
246
|
+
* interpolates port values from, so it must never be skipped.
|
|
247
|
+
*/
|
|
248
|
+
export function getEnvTargets(ctx) {
|
|
249
|
+
const envFileName = ctx.config.envFile ?? DEFAULT_ENV_FILE;
|
|
250
|
+
const targets = [
|
|
251
|
+
{
|
|
252
|
+
dir: "",
|
|
253
|
+
label: "root",
|
|
254
|
+
envFileName,
|
|
255
|
+
overrides: ctx.config.envOverrides,
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
const workspaces = resolveWorkspaces(ctx.repoRoot, ctx.config.workspaces ?? []);
|
|
259
|
+
for (const ws of workspaces) {
|
|
260
|
+
targets.push({
|
|
261
|
+
dir: ws.dir,
|
|
262
|
+
label: `workspace ${ws.name} (${ws.dir})`,
|
|
263
|
+
envFileName,
|
|
264
|
+
overrides: findWorkspaceOverrides(ctx.config.workspaceEnvOverrides, ws, workspaces),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return targets;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Validate env-related CLI options up front: build the context and resolve
|
|
271
|
+
* its env targets, which throws for invalid env file names, malformed
|
|
272
|
+
* config, and unknown workspace selectors. Restart paths call this before
|
|
273
|
+
* stopping any worktree, so bad options never leave things stopped.
|
|
274
|
+
*/
|
|
275
|
+
export function preflightEnvOptions(cli = {}, cwd, opts = {}) {
|
|
276
|
+
getEnvTargets(buildContext(cli, { cwd, readOnly: true, requireMainFor: opts.requireMainFor }));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Look up a workspace's overrides by package name, then directory basename,
|
|
280
|
+
* then repo-relative path — the key order resolveWorkspaces matches
|
|
281
|
+
* selectors in. A bare basename applies only when it identifies exactly one
|
|
282
|
+
* workspace, mirroring selector resolution's ambiguity rule: workspaces
|
|
283
|
+
* sharing a directory name must be reached by full path.
|
|
284
|
+
*/
|
|
285
|
+
function findWorkspaceOverrides(map, ws, workspaces) {
|
|
286
|
+
if (!map)
|
|
287
|
+
return undefined;
|
|
288
|
+
const basename = path.posix.basename(ws.dir);
|
|
289
|
+
const basenameUnique = workspaces.filter((w) => path.posix.basename(w.dir) === basename)
|
|
290
|
+
.length === 1;
|
|
291
|
+
for (const key of [
|
|
292
|
+
ws.name,
|
|
293
|
+
...(basenameUnique ? [basename] : []),
|
|
294
|
+
ws.dir,
|
|
295
|
+
`./${ws.dir}`,
|
|
296
|
+
]) {
|
|
297
|
+
const overrides = map[key];
|
|
298
|
+
if (overrides && typeof overrides === "object")
|
|
299
|
+
return overrides;
|
|
300
|
+
}
|
|
301
|
+
return undefined;
|
|
29
302
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { SweepResult, SweepRunner } from "./teardown.js";
|
|
2
|
+
import type { WtcContext } from "../context.js";
|
|
3
|
+
import type { ResolvedWorktree } from "../state/registry.js";
|
|
4
|
+
import type { Reporter } from "../utils/log.js";
|
|
5
|
+
import type { CoreIo } from "./types.js";
|
|
6
|
+
export interface CleanOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Also remove worktrees with uncommitted changes, commits on no branch,
|
|
9
|
+
* or unpushed submodule commits — and locked ones.
|
|
10
|
+
*/
|
|
11
|
+
force?: boolean;
|
|
12
|
+
/** Tear down stacks (deleting their volumes) but keep every worktree. */
|
|
13
|
+
keepWorktrees?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Report what would happen; change nothing — not even the registry (the
|
|
16
|
+
* context is built read-only).
|
|
17
|
+
*/
|
|
18
|
+
dryRun?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Also remove stacks named after this repo's worktree stacks
|
|
21
|
+
* (`<repo>-wt-<n>-…`) whose working directory no longer exists — stale
|
|
22
|
+
* leftovers, e.g. of wtc ≤0.2. Never a stack whose directory exists.
|
|
23
|
+
*/
|
|
24
|
+
sweep?: boolean;
|
|
25
|
+
/** Container CLI runner for the stale sweep (tests). */
|
|
26
|
+
sweepRunner?: SweepRunner;
|
|
27
|
+
}
|
|
28
|
+
export interface CleanResult {
|
|
29
|
+
dryRun: boolean;
|
|
30
|
+
stacks: {
|
|
31
|
+
project: string;
|
|
32
|
+
orphan: boolean;
|
|
33
|
+
ok: boolean;
|
|
34
|
+
error?: string;
|
|
35
|
+
}[];
|
|
36
|
+
removed: string[];
|
|
37
|
+
/** Worktrees deliberately kept: dirty, locked, current, main checkout. Not failures. */
|
|
38
|
+
skipped: {
|
|
39
|
+
path: string;
|
|
40
|
+
reason: string;
|
|
41
|
+
}[];
|
|
42
|
+
/** Worktrees whose `git worktree remove` failed. */
|
|
43
|
+
removeFailed: {
|
|
44
|
+
path: string;
|
|
45
|
+
reason: string;
|
|
46
|
+
}[];
|
|
47
|
+
sweep: SweepResult | null;
|
|
48
|
+
forgotten: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Real failures (non-zero → exit 1 / MCP isError): stacks that could not
|
|
51
|
+
* be torn down, worktree removals and sweep removals/listings that
|
|
52
|
+
* failed. Always 0 for a dry run.
|
|
53
|
+
*/
|
|
54
|
+
failures: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Which uncommitted paths in a worktree are wtc's own artifacts rather than
|
|
58
|
+
* the user's work:
|
|
59
|
+
* - the env files wtc writes: `<dir>/<envFile>` for the root and each
|
|
60
|
+
* configured workspace, plus whatever the worktree's last `start` wrote
|
|
61
|
+
* (`--env`/`--workspace` may name others) — not every `.env.*` file, so an
|
|
62
|
+
* edited `.env.test` or `apps/x/.env.production` is the user's work;
|
|
63
|
+
* - compose sources (incl. includes), synced Dockerfiles and files under
|
|
64
|
+
* `sync` entries, but only while they are byte-identical to the main
|
|
65
|
+
* checkout's copy, i.e. exactly what start's sync wrote. An edit made in
|
|
66
|
+
* the worktree (or a file only the worktree has) is the user's work. If
|
|
67
|
+
* main changed since the last start this errs towards "dirty", which
|
|
68
|
+
* --force overrides.
|
|
69
|
+
*/
|
|
70
|
+
export declare function managedPathMatcher(ctx: WtcContext, wtPath: string, envFiles?: string[]): (rel: string) => boolean;
|
|
71
|
+
/** Uncommitted paths in a worktree that wtc did not put there. */
|
|
72
|
+
export declare function unmanagedChanges(statusPaths: string[], isManaged: (rel: string) => boolean): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Commits that removing the worktree would make unreachable, beyond what
|
|
75
|
+
* `git status` shows:
|
|
76
|
+
* - a detached HEAD with commits no branch, tag or remote reaches (the
|
|
77
|
+
* worktree's HEAD reflog goes with it);
|
|
78
|
+
* - submodule commits not on any remote: the submodules' repositories live
|
|
79
|
+
* in the worktree's admin dir, which `git worktree remove --force`
|
|
80
|
+
* deletes (plain `remove` refuses worktrees with submodules for this
|
|
81
|
+
* reason; wtc needs --force for its own artifacts).
|
|
82
|
+
* Returns a reason, or `null` when nothing would be lost.
|
|
83
|
+
*/
|
|
84
|
+
export declare function unreachableWork(wt: ResolvedWorktree): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* Tear down every worktree stack (live and orphaned), remove worktrees that
|
|
87
|
+
* hold no work of their own, sweep leftovers this checkout owns, and forget
|
|
88
|
+
* what was removed. Never removes the main checkout or the worktree it runs
|
|
89
|
+
* from.
|
|
90
|
+
*/
|
|
91
|
+
export declare function clean(options: CleanOptions, reporter: Reporter, io: CoreIo): Promise<CleanResult>;
|