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.
Files changed (94) hide show
  1. package/README.md +458 -140
  2. package/SKILL.md +113 -0
  3. package/dist/cli.js +94 -33
  4. package/dist/commands/clean.d.ts +2 -1
  5. package/dist/commands/clean.js +8 -48
  6. package/dist/commands/doctor.d.ts +3 -0
  7. package/dist/commands/doctor.js +30 -0
  8. package/dist/commands/list.d.ts +4 -1
  9. package/dist/commands/list.js +62 -44
  10. package/dist/commands/promote.d.ts +3 -1
  11. package/dist/commands/promote.js +4 -34
  12. package/dist/commands/prune.d.ts +2 -0
  13. package/dist/commands/prune.js +7 -0
  14. package/dist/commands/restart.d.ts +2 -1
  15. package/dist/commands/restart.js +11 -5
  16. package/dist/commands/skill.d.ts +4 -0
  17. package/dist/commands/skill.js +10 -0
  18. package/dist/commands/start.d.ts +2 -1
  19. package/dist/commands/start.js +7 -34
  20. package/dist/commands/stop.d.ts +1 -1
  21. package/dist/commands/stop.js +6 -23
  22. package/dist/compose/detect.d.ts +1 -2
  23. package/dist/compose/detect.js +1 -10
  24. package/dist/compose/engine.d.ts +61 -0
  25. package/dist/compose/engine.js +129 -0
  26. package/dist/compose/isolation.d.ts +15 -0
  27. package/dist/compose/isolation.js +62 -0
  28. package/dist/compose/parse.d.ts +5 -0
  29. package/dist/compose/parse.js +89 -11
  30. package/dist/compose/status.d.ts +84 -0
  31. package/dist/compose/status.js +227 -0
  32. package/dist/compose/types.d.ts +20 -0
  33. package/dist/config.d.ts +31 -0
  34. package/dist/config.js +23 -6
  35. package/dist/context.d.ts +89 -3
  36. package/dist/context.js +278 -45
  37. package/dist/core/clean.d.ts +91 -0
  38. package/dist/core/clean.js +343 -0
  39. package/dist/core/compose.d.ts +30 -0
  40. package/dist/core/compose.js +45 -0
  41. package/dist/core/doctor.d.ts +28 -0
  42. package/dist/core/doctor.js +277 -0
  43. package/dist/core/list.d.ts +42 -0
  44. package/dist/core/list.js +94 -0
  45. package/dist/core/promote.d.ts +40 -0
  46. package/dist/core/promote.js +117 -0
  47. package/dist/core/prune.d.ts +32 -0
  48. package/dist/core/prune.js +75 -0
  49. package/dist/core/restart.d.ts +14 -0
  50. package/dist/core/restart.js +18 -0
  51. package/dist/core/start.d.ts +31 -0
  52. package/dist/core/start.js +99 -0
  53. package/dist/core/stop.d.ts +32 -0
  54. package/dist/core/stop.js +57 -0
  55. package/dist/core/teardown.d.ts +121 -0
  56. package/dist/core/teardown.js +298 -0
  57. package/dist/core/types.d.ts +15 -0
  58. package/dist/core/types.js +1 -0
  59. package/dist/git/promote.d.ts +49 -2
  60. package/dist/git/promote.js +160 -38
  61. package/dist/git/repo.d.ts +72 -0
  62. package/dist/git/repo.js +167 -0
  63. package/dist/git/status.d.ts +8 -0
  64. package/dist/git/status.js +25 -0
  65. package/dist/git/worktree.d.ts +63 -3
  66. package/dist/git/worktree.js +173 -29
  67. package/dist/mcp/server.d.ts +2 -0
  68. package/dist/mcp/server.js +230 -115
  69. package/dist/ports/allocate.d.ts +14 -3
  70. package/dist/ports/allocate.js +20 -4
  71. package/dist/selectors.d.ts +10 -0
  72. package/dist/selectors.js +106 -0
  73. package/dist/skill.d.ts +13 -0
  74. package/dist/skill.js +28 -0
  75. package/dist/state/registry.d.ts +194 -0
  76. package/dist/state/registry.js +595 -0
  77. package/dist/sync/env.d.ts +77 -2
  78. package/dist/sync/env.js +151 -32
  79. package/dist/sync/files.d.ts +15 -1
  80. package/dist/sync/files.js +126 -38
  81. package/dist/utils/exec.d.ts +69 -4
  82. package/dist/utils/exec.js +221 -15
  83. package/dist/utils/log.d.ts +37 -0
  84. package/dist/utils/log.js +68 -4
  85. package/dist/utils/paths.d.ts +61 -0
  86. package/dist/utils/paths.js +163 -0
  87. package/dist/utils/sanitize.d.ts +7 -0
  88. package/dist/utils/sanitize.js +12 -0
  89. package/dist/version.d.ts +1 -0
  90. package/dist/version.js +3 -0
  91. package/dist/workspaces/resolve.d.ts +21 -0
  92. package/dist/workspaces/resolve.js +235 -0
  93. package/package.json +18 -14
  94. package/wtc.schema.json +62 -0
@@ -0,0 +1,227 @@
1
+ import path from "node:path";
2
+ import { CommandError, ENGINE_PROBE_TIMEOUT_MS, run, runSafe } from "../utils/exec.js";
3
+ import { cliCall, composeArgs, composeBin } from "./engine.js";
4
+ export const PROJECT_LABELS = ["com.docker.compose.project", "io.podman.compose.project"];
5
+ const WORKING_DIR_LABEL = "com.docker.compose.project.working_dir";
6
+ const ONEOFF_LABEL = "com.docker.compose.oneoff";
7
+ /**
8
+ * Parse Docker's `Labels` string (`k=v,k=v`, in random order). Values may
9
+ * themselves contain commas (e.g. `config_files=/a.yml,/b.yml`), so only
10
+ * split on a comma that starts a new `key=`. A key starts with a letter and
11
+ * may contain `/` (Docker Desktop adds `desktop.docker.io/binds/0/Source`
12
+ * to every container with a bind mount); a value such as `/my dir/a=b.yml`
13
+ * or `C:\x=y.yml` after a comma starts with `/` or holds `:` / `\`, so it
14
+ * is never mistaken for a new key.
15
+ */
16
+ export function parseLabelString(labels) {
17
+ const out = {};
18
+ if (!labels)
19
+ return out;
20
+ for (const pair of labels.split(/,(?=[A-Za-z][A-Za-z0-9_.\/-]*=)/)) {
21
+ const eq = pair.indexOf("=");
22
+ if (eq <= 0)
23
+ continue;
24
+ out[pair.slice(0, eq)] = pair.slice(eq + 1);
25
+ }
26
+ return out;
27
+ }
28
+ /** Case-insensitive field lookup: Docker uses `Labels`/`ID`, Podman `labels`/`Id`. */
29
+ export function field(obj, name) {
30
+ if (name in obj)
31
+ return obj[name];
32
+ const lower = name.toLowerCase();
33
+ for (const [k, v] of Object.entries(obj)) {
34
+ if (k.toLowerCase() === lower)
35
+ return v;
36
+ }
37
+ return undefined;
38
+ }
39
+ export function labelsOf(container) {
40
+ const labels = field(container, "Labels");
41
+ if (typeof labels === "string")
42
+ return parseLabelString(labels);
43
+ if (labels && typeof labels === "object") {
44
+ const out = {};
45
+ for (const [k, v] of Object.entries(labels)) {
46
+ if (typeof v === "string")
47
+ out[k] = v;
48
+ }
49
+ return out;
50
+ }
51
+ return {};
52
+ }
53
+ /**
54
+ * Parse `--format json` listings (`ps`, `network ls`, `volume ls`): Docker
55
+ * emits NDJSON, Podman one JSON array. Throws when the output is neither.
56
+ */
57
+ export function parseJsonListing(output) {
58
+ const text = output.trim();
59
+ if (!text)
60
+ return [];
61
+ let entries;
62
+ if (text.startsWith("[")) {
63
+ const parsed = JSON.parse(text);
64
+ if (!Array.isArray(parsed))
65
+ throw new Error("Unexpected JSON listing");
66
+ entries = parsed;
67
+ }
68
+ else {
69
+ entries = text
70
+ .split("\n")
71
+ .map((line) => line.trim())
72
+ .filter(Boolean)
73
+ .map((line) => JSON.parse(line));
74
+ }
75
+ return entries.map((e) => {
76
+ if (!e || typeof e !== "object" || Array.isArray(e))
77
+ throw new Error("Unexpected JSON listing entry");
78
+ return e;
79
+ });
80
+ }
81
+ function firstName(value) {
82
+ if (Array.isArray(value))
83
+ return String(value[0] ?? "");
84
+ return String(value ?? "").split(",")[0].trim();
85
+ }
86
+ /**
87
+ * Every container of a `ps -a --format json` listing with what wtc needs per
88
+ * container: compose project, working_dir (to adopt a running stack into
89
+ * the registry), state, and whether it is a one-off. Sibling of
90
+ * `parsePsJson`, which reduces the same listing to per-project counts.
91
+ */
92
+ export function parsePsContainers(output) {
93
+ return parseJsonListing(output).map((c) => {
94
+ const labels = labelsOf(c);
95
+ const name = firstName(field(c, "Names"));
96
+ const project = PROJECT_LABELS.map((l) => labels[l]).find(Boolean) ?? null;
97
+ // Docker labels `compose run` containers oneoff=True (services carry
98
+ // oneoff=False, so compare the value); podman-compose names them
99
+ // `<project>_<service>_tmp<n>`.
100
+ const oneoff = (labels[ONEOFF_LABEL] ?? "").toLowerCase() === "true" ||
101
+ (project !== null && /_tmp\d+$/.test(name) && Boolean(labels["io.podman.compose.project"]));
102
+ const state = String(field(c, "State") ?? "").toLowerCase();
103
+ return {
104
+ id: String(field(c, "ID") ?? ""),
105
+ name,
106
+ project,
107
+ workingDir: labels[WORKING_DIR_LABEL] || null,
108
+ state,
109
+ running: state === "running",
110
+ oneoff,
111
+ };
112
+ });
113
+ }
114
+ /**
115
+ * Count running/total containers per compose project from `ps -a --format json`.
116
+ * Docker emits NDJSON with a `Labels` string; Podman emits one JSON array with
117
+ * a `Labels` object. One-off `compose run` containers are not counted: they
118
+ * are not part of the stack, and counting them shows a healthy stack as
119
+ * `partial` until clean. Throws when the output is neither shape.
120
+ */
121
+ export function parsePsJson(output) {
122
+ return statesOf(parsePsContainers(output));
123
+ }
124
+ function statesOf(containers) {
125
+ const states = new Map();
126
+ for (const c of containers) {
127
+ if (!c.project || c.oneoff)
128
+ continue;
129
+ const state = states.get(c.project) ?? { running: 0, total: 0 };
130
+ state.total++;
131
+ if (c.running)
132
+ state.running++;
133
+ states.set(c.project, state);
134
+ }
135
+ return states;
136
+ }
137
+ /** One `<cli> ps -a --format json` call (bounded by a timeout). Throws on failure. */
138
+ export function listContainers(engine) {
139
+ const [file, args] = cliCall(engine, "ps", "-a", "--format", "json");
140
+ return parsePsContainers(run(file, args, { timeoutMs: ENGINE_PROBE_TIMEOUT_MS }));
141
+ }
142
+ /** One `<cli> ps -a --format json` call → state per compose project. Throws on failure. */
143
+ export function getStackStates(engine) {
144
+ return statesOf(listContainers(engine));
145
+ }
146
+ /**
147
+ * Per-project fallback: `compose -p P ps -q` (running) and `ps -a -q` (total).
148
+ * podman-compose's `ps` accepts only `-q` and always lists every container,
149
+ * so it cannot tell running from stopped: its state is unknown.
150
+ */
151
+ export function probeStackDirect(engine, project, cwd) {
152
+ if (path.basename(engine.compose[0]) === "podman-compose")
153
+ return null;
154
+ const count = (out) => out === null ? null : out.split("\n").filter((l) => l.trim()).length;
155
+ const opts = { cwd, timeoutMs: ENGINE_PROBE_TIMEOUT_MS };
156
+ const running = count(runSafe(composeBin(engine), composeArgs(engine, project, "ps", "-q"), opts));
157
+ const total = count(runSafe(composeBin(engine), composeArgs(engine, project, "ps", "-a", "-q"), opts));
158
+ if (running === null || total === null)
159
+ return null;
160
+ return { running, total };
161
+ }
162
+ /**
163
+ * Lazily fetch stack states once, falling back to per-project compose calls
164
+ * when the `ps` JSON cannot be parsed (older engines, unexpected shapes).
165
+ */
166
+ export function createStackProbe(engine, engineProblem = null, cwd) {
167
+ let mode = engine ? "pending" : "unavailable";
168
+ let states = new Map();
169
+ let listed = [];
170
+ let problem = engine ? null : engineProblem;
171
+ const cache = new Map();
172
+ const load = () => {
173
+ if (mode !== "pending" || !engine)
174
+ return;
175
+ try {
176
+ listed = listContainers(engine);
177
+ states = statesOf(listed);
178
+ mode = "map";
179
+ }
180
+ catch (err) {
181
+ if (err instanceof CommandError) {
182
+ // The CLI itself failed (daemon down, timed out, binary missing): states are unknown.
183
+ mode = "unavailable";
184
+ const last = err.message.split("\n").slice(-1)[0];
185
+ problem =
186
+ `Container engine not reachable (${engine.cliArgv.join(" ")} ps failed: ${last}). ` +
187
+ `Start it, or set WTC_COMPOSE_COMMAND to use another engine (e.g. "podman compose").`;
188
+ }
189
+ else {
190
+ // Unparseable output: ask compose per project instead.
191
+ mode = "fallback";
192
+ }
193
+ }
194
+ };
195
+ return {
196
+ engine,
197
+ get problem() {
198
+ load();
199
+ return problem;
200
+ },
201
+ state(project) {
202
+ load();
203
+ if (mode === "unavailable")
204
+ return null;
205
+ if (mode === "map")
206
+ return states.get(project) ?? { running: 0, total: 0 };
207
+ if (!cache.has(project))
208
+ cache.set(project, probeStackDirect(engine, project, cwd));
209
+ return cache.get(project) ?? null;
210
+ },
211
+ containers() {
212
+ load();
213
+ return mode === "map" ? listed : null;
214
+ },
215
+ };
216
+ }
217
+ export function stackStatus(state) {
218
+ if (!state)
219
+ return "?";
220
+ if (state.total === 0)
221
+ return "down";
222
+ if (state.running === state.total)
223
+ return "up";
224
+ if (state.running === 0)
225
+ return "exited";
226
+ return "partial";
227
+ }
@@ -4,15 +4,35 @@ export interface ComposeService {
4
4
  build?: {
5
5
  context?: string;
6
6
  dockerfile?: string;
7
+ /** `dockerfile_inline` is set: there is no Dockerfile on disk to sync. */
8
+ inline?: boolean;
7
9
  };
8
10
  envFile?: string[];
11
+ /** Fixed `container_name` — breaks running the same stack twice. */
12
+ containerName?: string;
9
13
  /** Absolute path of the compose file that declared this service. */
10
14
  sourcePath: string;
11
15
  }
16
+ /**
17
+ * A top-level volume or network that is NOT scoped to the compose project:
18
+ * it sets an explicit `name:` or is `external`. Every worktree stack would
19
+ * share it.
20
+ */
21
+ export interface SharedResource {
22
+ /** Key under `volumes:` / `networks:`. */
23
+ key: string;
24
+ /** Explicit `name:` when set. */
25
+ name?: string;
26
+ external: boolean;
27
+ }
12
28
  export interface ComposeFile {
13
29
  services: ComposeService[];
14
30
  /** Resolved absolute path of the root compose file. */
15
31
  composePath: string;
16
32
  /** Absolute paths of the root file plus all transitively-included files, root first. */
17
33
  sourceFiles: string[];
34
+ /** Top-level volumes with a fixed name or `external`. */
35
+ sharedVolumes: SharedResource[];
36
+ /** Top-level networks with a fixed name or `external`. */
37
+ sharedNetworks: SharedResource[];
18
38
  }
package/dist/config.d.ts CHANGED
@@ -1,6 +1,25 @@
1
1
  export interface WtcConfig {
2
+ /** JSON Schema reference for editor completion; ignored by wtc. */
3
+ $schema?: string;
4
+ /** Extra repo-relative files/directories copied from the main checkout on start. */
2
5
  sync?: string[];
3
6
  envOverrides?: Record<string, string>;
7
+ /**
8
+ * Env filename to copy from the main checkout into each worktree and inject
9
+ * port overrides into. Workspace targets use the same name. Defaults to `.env`.
10
+ */
11
+ envFile?: string;
12
+ /**
13
+ * Monorepo workspaces (by package name, directory name, or path) that also
14
+ * receive env file copies + port override injection, in addition to the repo
15
+ * root. Empty/omitted means root-only (the zero-config behavior).
16
+ */
17
+ workspaces?: string[];
18
+ /**
19
+ * Per-workspace env overrides, keyed by workspace name (or directory).
20
+ * Values support `${VAR}` interpolation against allocated port values.
21
+ */
22
+ workspaceEnvOverrides?: Record<string, Record<string, string>>;
4
23
  /**
5
24
  * Per-worktree-index port stride. Allocated port =
6
25
  * 20000 + defaultPort + worktreeIndex * portStride. Defaults to 1.
@@ -8,5 +27,17 @@ export interface WtcConfig {
8
27
  * ports so that adjacent worktrees do not collide across services.
9
28
  */
10
29
  portStride?: number;
30
+ /**
31
+ * Compose command to run instead of auto-detection, e.g. `"podman compose"`
32
+ * or `["docker-compose"]`. `WTC_COMPOSE_COMMAND` takes precedence.
33
+ */
34
+ composeCommand?: string | string[];
35
+ }
36
+ export interface LoadedConfig {
37
+ config: WtcConfig;
38
+ /** File the config came from, or `null` for the zero-config default. */
39
+ source: string | null;
11
40
  }
41
+ /** Load `.wtcrc.json`, else `package.json#wtc`, recording which file was used. */
42
+ export declare function loadConfigWithSource(repoRoot: string): LoadedConfig;
12
43
  export declare function loadConfig(repoRoot: string): WtcConfig;
package/dist/config.js CHANGED
@@ -1,16 +1,33 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- export function loadConfig(repoRoot) {
3
+ function readJsonFile(file) {
4
+ const raw = fs.readFileSync(file, "utf-8");
5
+ try {
6
+ return JSON.parse(raw);
7
+ }
8
+ catch (err) {
9
+ throw new Error(`Invalid JSON in ${file}: ${err instanceof Error ? err.message : String(err)}`);
10
+ }
11
+ }
12
+ /** Load `.wtcrc.json`, else `package.json#wtc`, recording which file was used. */
13
+ export function loadConfigWithSource(repoRoot) {
4
14
  const rcPath = path.join(repoRoot, ".wtcrc.json");
5
15
  if (fs.existsSync(rcPath)) {
6
- return JSON.parse(fs.readFileSync(rcPath, "utf-8"));
16
+ const doc = readJsonFile(rcPath);
17
+ if (!doc || typeof doc !== "object" || Array.isArray(doc)) {
18
+ throw new Error(`Invalid config in ${rcPath}: expected a JSON object.`);
19
+ }
20
+ return { config: doc, source: rcPath };
7
21
  }
8
22
  const pkgPath = path.join(repoRoot, "package.json");
9
23
  if (fs.existsSync(pkgPath)) {
10
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
11
- if (pkg.wtc && typeof pkg.wtc === "object") {
12
- return pkg.wtc;
24
+ const pkg = readJsonFile(pkgPath);
25
+ if (pkg && typeof pkg.wtc === "object" && pkg.wtc !== null && !Array.isArray(pkg.wtc)) {
26
+ return { config: pkg.wtc, source: `${pkgPath}#wtc` };
13
27
  }
14
28
  }
15
- return {};
29
+ return { config: {}, source: null };
30
+ }
31
+ export function loadConfig(repoRoot) {
32
+ return loadConfigWithSource(repoRoot).config;
16
33
  }
package/dist/context.d.ts CHANGED
@@ -1,15 +1,101 @@
1
+ import type { ComposeEngine } from "./compose/engine.js";
2
+ import type { PsContainer, StackProbe } from "./compose/status.js";
1
3
  import type { ComposeFile } from "./compose/types.js";
2
4
  import type { PortMapping } from "./ports/types.js";
3
5
  import type { WtcConfig } from "./config.js";
6
+ import type { RepoInfo } from "./git/repo.js";
4
7
  import type { WorktreeInfo } from "./git/worktree.js";
8
+ import type { AdoptableStack, ResolvedWorktree, UnavailableRecord, WorktreeRecord } from "./state/registry.js";
9
+ import type { EnvTarget } from "./sync/env.js";
10
+ /** One-run CLI overrides for env handling. Values fall back to `.wtcrc.json`. */
11
+ export interface EnvCliOptions {
12
+ /** Env filename to copy and inject (`--env`). */
13
+ envFile?: string;
14
+ /** Workspaces to also inject env into (`--workspace`, repeatable). */
15
+ workspaces?: string[];
16
+ }
17
+ export interface BuildContextOptions {
18
+ /** Directory wtc runs from (defaults to `process.cwd()`). */
19
+ cwd?: string;
20
+ /**
21
+ * Resolve the compose engine and probe stack states (status display). A
22
+ * worktree seen for the first time may then adopt the identity of a
23
+ * stack already running from it, and an empty registry is persisted —
24
+ * without a probe it is only computed (see ReconcileOptions.adoptable).
25
+ */
26
+ probeStacks?: boolean;
27
+ /**
28
+ * Compute identities without side effects (`--dry-run`): never write the
29
+ * registry, create worktree ids, or move a corrupt registry aside.
30
+ */
31
+ readOnly?: boolean;
32
+ /** Tolerate a main checkout without a compose file (promote, clean). */
33
+ allowMissingCompose?: boolean;
34
+ /**
35
+ * The command syncs files into, starts, or removes other checkouts: refuse
36
+ * (naming this action) when the main checkout cannot be located, instead
37
+ * of treating the current checkout as the main one.
38
+ */
39
+ requireMainFor?: string;
40
+ }
5
41
  export interface WtcContext {
42
+ repo: RepoInfo;
43
+ /** The MAIN worktree — source of compose, config and env files. */
6
44
  repoRoot: string;
7
45
  repoName: string;
46
+ cwd: string;
8
47
  composeFile: ComposeFile;
48
+ /** False only with `allowMissingCompose` when no compose file exists. */
49
+ hasComposeFile: boolean;
9
50
  portMappings: PortMapping[];
10
51
  config: WtcConfig;
11
52
  portStride: number;
12
- worktrees: WorktreeInfo[];
53
+ /** Live linked worktrees with their persistent index/project, in git order. */
54
+ worktrees: ResolvedWorktree[];
55
+ /** Registry records whose worktree is gone (stack may still exist). */
56
+ orphans: WorktreeRecord[];
57
+ /**
58
+ * Records of worktrees git still lists but wtc cannot start (locked and
59
+ * missing on disk, or now the main checkout): their stacks are left alone.
60
+ */
61
+ unavailable: UnavailableRecord[];
62
+ /** Worktrees git still lists but whose directory is missing. */
63
+ prunable: WorktreeInfo[];
64
+ /** General warnings (missing worktrees, registry problems, skipped sync entries). */
65
+ warnings: string[];
66
+ /** Settings that break isolation between worktree stacks. */
67
+ isolationWarnings: string[];
68
+ /** Stack states (only with `probeStacks`). */
69
+ stacks: StackProbe | null;
70
+ /** Resolve the compose engine (lazily; throws when none is available). */
71
+ getEngine(): ComposeEngine;
13
72
  }
14
- export declare function buildContext(): WtcContext;
15
- export declare function filterWorktrees(worktrees: WorktreeInfo[], indices: number[]): WorktreeInfo[];
73
+ /**
74
+ * Identities of running stacks that worktrees may adopt, keyed by worktree
75
+ * path: compose projects named like this repository's worktree stacks
76
+ * (`<repo>-wt-<n>-…`) whose `working_dir` label is one of `worktrees`.
77
+ * Compose records the directory it ran in, so a registry that was lost,
78
+ * corrupted, or never written (0.2) is rebuilt from the stacks themselves
79
+ * instead of renumbering them. One-off `compose run` containers are
80
+ * ignored; when several projects ran from one worktree, the one with the
81
+ * most running (then total) containers, then the lowest index, wins.
82
+ */
83
+ export declare function adoptableStacks(containers: PsContainer[], repoName: string, worktrees: WorktreeInfo[]): Map<string, AdoptableStack>;
84
+ export declare function buildContext(cli?: EnvCliOptions, opts?: BuildContextOptions): WtcContext;
85
+ /** Merge CLI overrides over the loaded config and validate it. */
86
+ export declare function resolveConfig(config: WtcConfig, cli: EnvCliOptions): WtcConfig;
87
+ /**
88
+ * Env targets for a run: the repo root always, plus every selected workspace.
89
+ * Workspace targets are additive — the root env file is what docker compose
90
+ * interpolates port values from, so it must never be skipped.
91
+ */
92
+ export declare function getEnvTargets(ctx: WtcContext): EnvTarget[];
93
+ /**
94
+ * Validate env-related CLI options up front: build the context and resolve
95
+ * its env targets, which throws for invalid env file names, malformed
96
+ * config, and unknown workspace selectors. Restart paths call this before
97
+ * stopping any worktree, so bad options never leave things stopped.
98
+ */
99
+ export declare function preflightEnvOptions(cli?: EnvCliOptions, cwd?: string, opts?: {
100
+ requireMainFor?: string;
101
+ }): void;