worktree-compose 1.1.2 → 2.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 (77) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +31 -16
  3. package/SKILL.md +73 -76
  4. package/dist/cli.js +85 -10
  5. package/dist/commands/down.d.ts +2 -0
  6. package/dist/commands/down.js +7 -0
  7. package/dist/commands/list.d.ts +2 -0
  8. package/dist/commands/list.js +43 -6
  9. package/dist/commands/passthrough.d.ts +13 -0
  10. package/dist/commands/passthrough.js +27 -0
  11. package/dist/commands/stop.d.ts +3 -1
  12. package/dist/commands/stop.js +2 -2
  13. package/dist/compose/detect.d.ts +19 -0
  14. package/dist/compose/detect.js +56 -0
  15. package/dist/compose/isolation.d.ts +20 -7
  16. package/dist/compose/isolation.js +88 -36
  17. package/dist/compose/override.d.ts +54 -4
  18. package/dist/compose/override.js +179 -52
  19. package/dist/compose/parse.d.ts +11 -0
  20. package/dist/compose/parse.js +260 -13
  21. package/dist/compose/status.d.ts +14 -0
  22. package/dist/compose/status.js +58 -1
  23. package/dist/compose/types.d.ts +56 -0
  24. package/dist/config.d.ts +33 -0
  25. package/dist/context.d.ts +26 -0
  26. package/dist/context.js +140 -29
  27. package/dist/core/clean.d.ts +3 -1
  28. package/dist/core/clean.js +8 -3
  29. package/dist/core/compose.d.ts +87 -13
  30. package/dist/core/compose.js +282 -57
  31. package/dist/core/doctor.d.ts +2 -8
  32. package/dist/core/doctor.js +116 -79
  33. package/dist/core/down.d.ts +37 -0
  34. package/dist/core/down.js +54 -0
  35. package/dist/core/health.d.ts +90 -0
  36. package/dist/core/health.js +198 -0
  37. package/dist/core/list.d.ts +53 -6
  38. package/dist/core/list.js +144 -58
  39. package/dist/core/passthrough.d.ts +69 -0
  40. package/dist/core/passthrough.js +216 -0
  41. package/dist/core/promote.d.ts +4 -2
  42. package/dist/core/promote.js +5 -3
  43. package/dist/core/restart.d.ts +3 -3
  44. package/dist/core/restart.js +6 -5
  45. package/dist/core/seed.d.ts +50 -0
  46. package/dist/core/seed.js +245 -0
  47. package/dist/core/shared.d.ts +63 -0
  48. package/dist/core/shared.js +194 -0
  49. package/dist/core/start.d.ts +32 -5
  50. package/dist/core/start.js +297 -49
  51. package/dist/core/stop.d.ts +3 -1
  52. package/dist/core/stop.js +6 -3
  53. package/dist/core/teardown.d.ts +5 -2
  54. package/dist/core/teardown.js +33 -8
  55. package/dist/core/types.d.ts +2 -0
  56. package/dist/git/promote.d.ts +11 -3
  57. package/dist/git/promote.js +19 -5
  58. package/dist/mcp/server.js +154 -28
  59. package/dist/ports/allocate.d.ts +35 -23
  60. package/dist/ports/allocate.js +108 -58
  61. package/dist/ports/probe.d.ts +11 -0
  62. package/dist/ports/probe.js +40 -0
  63. package/dist/ports/types.d.ts +5 -0
  64. package/dist/selectors.d.ts +17 -0
  65. package/dist/selectors.js +19 -0
  66. package/dist/state/registry.d.ts +23 -3
  67. package/dist/state/registry.js +57 -17
  68. package/dist/sync/env.d.ts +42 -2
  69. package/dist/sync/env.js +79 -8
  70. package/dist/sync/envsync.d.ts +91 -0
  71. package/dist/sync/envsync.js +338 -0
  72. package/dist/sync/files.d.ts +87 -5
  73. package/dist/sync/files.js +343 -18
  74. package/dist/utils/paths.d.ts +2 -0
  75. package/dist/utils/paths.js +9 -0
  76. package/package.json +1 -1
  77. package/wtc.schema.json +155 -13
@@ -0,0 +1,27 @@
1
+ import { composeSubcommand, execArgs, logsArgs, resolveStackCall, runAttached } from "../core/passthrough.js";
2
+ import { unlinkSharedServices } from "../core/shared.js";
3
+ /** `wtc compose [-w <worktree>] <args…>`: any compose command on the worktree's stack. */
4
+ export async function composeCommand(args, options) {
5
+ if (args.length === 0)
6
+ throw new Error("Give a compose command to run, e.g. 'wtc compose ps'.");
7
+ const call = resolveStackCall(options.worktree, { live: true });
8
+ // The main checkout's shared containers sit on the stack's networks: `down` cannot remove
9
+ // those otherwise. A dry run changes nothing, so it must not disconnect them either.
10
+ const { command, dryRun } = composeSubcommand(args);
11
+ if (command === "down" && !dryRun)
12
+ unlinkSharedServices(call.engine, call.worktree.project, call.mainDirs);
13
+ process.exitCode = await runAttached(call, args);
14
+ }
15
+ /** `wtc exec [-w <worktree>] <service> <command…>`: a command in a running service container. */
16
+ export async function execCommand(service, command, options) {
17
+ if (command.length === 0)
18
+ throw new Error(`Give a command to run in "${service}", e.g. 'wtc exec ${service} sh'.`);
19
+ const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
20
+ process.exitCode = await runAttached(resolveStackCall(options.worktree, { live: true }), execArgs(service, command, interactive));
21
+ }
22
+ /** `wtc logs [-w <worktree>] [services…]`: the stack's logs. */
23
+ export async function logsCommand(services, options) {
24
+ process.exitCode = await runAttached(resolveStackCall(options.worktree, { live: true }, { readOnly: true }),
25
+ // In a terminal compose colours the service names itself.
26
+ logsArgs({ ...options, services }).filter((a) => a !== "--no-color" || !process.stdout.isTTY));
27
+ }
@@ -1 +1,3 @@
1
- export declare function stopCommand(worktrees: string[]): Promise<void>;
1
+ export declare function stopCommand(worktrees: string[], options?: {
2
+ all?: boolean;
3
+ }): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { stopWorktrees } from "../core/stop.js";
2
2
  import { consoleReporter } from "../utils/log.js";
3
- export async function stopCommand(worktrees) {
4
- const result = await stopWorktrees({ worktrees }, consoleReporter, { live: true });
3
+ export async function stopCommand(worktrees, options = {}) {
4
+ const result = await stopWorktrees({ worktrees, all: options.all }, consoleReporter, { live: true });
5
5
  if (result.failures > 0)
6
6
  process.exitCode = 1;
7
7
  }
@@ -1,2 +1,21 @@
1
1
  export declare const COMPOSE_FILENAMES: string[];
2
2
  export declare function detectComposeFile(repoRoot: string): string | null;
3
+ export interface ComposeRoots {
4
+ /** The files compose is given, absolute, in order; empty when none was found. */
5
+ files: string[];
6
+ /**
7
+ * Compose would not find these by itself from the repository root (a
8
+ * custom name, a subdirectory, several files): every call must name them.
9
+ */
10
+ custom: boolean;
11
+ /** Said once, when wtc picked a file outside the repository root by itself. */
12
+ note?: string;
13
+ }
14
+ /**
15
+ * The project's compose files: the config's `composeFile` (one path or
16
+ * several, relative to the repository root), else a default name at the
17
+ * root, else the single compose file in a usual subdirectory (`docker/`,
18
+ * `deploy/`, `.devcontainer/`…). Several candidates there are an error
19
+ * that names them: wtc does not guess which one is the project's.
20
+ */
21
+ export declare function resolveComposeRoots(repoRoot: string, configured?: string | string[]): ComposeRoots;
@@ -1,11 +1,14 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { resolveInside } from "../utils/paths.js";
3
4
  export const COMPOSE_FILENAMES = [
4
5
  "compose.yaml",
5
6
  "compose.yml",
6
7
  "docker-compose.yaml",
7
8
  "docker-compose.yml",
8
9
  ];
10
+ /** Directories searched for a compose file when the repository root has none. */
11
+ const COMPOSE_DIRS = ["docker", ".docker", "compose", "deploy", "infra", ".devcontainer"];
9
12
  export function detectComposeFile(repoRoot) {
10
13
  for (const name of COMPOSE_FILENAMES) {
11
14
  const full = path.join(repoRoot, name);
@@ -14,3 +17,56 @@ export function detectComposeFile(repoRoot) {
14
17
  }
15
18
  return null;
16
19
  }
20
+ /**
21
+ * The project's compose files: the config's `composeFile` (one path or
22
+ * several, relative to the repository root), else a default name at the
23
+ * root, else the single compose file in a usual subdirectory (`docker/`,
24
+ * `deploy/`, `.devcontainer/`…). Several candidates there are an error
25
+ * that names them: wtc does not guess which one is the project's.
26
+ */
27
+ export function resolveComposeRoots(repoRoot, configured) {
28
+ if (configured !== undefined) {
29
+ const entries = Array.isArray(configured) ? configured : [configured];
30
+ const files = entries.map((entry) => {
31
+ const abs = resolveInside(repoRoot, entry);
32
+ if (!abs) {
33
+ throw new Error(`Invalid "composeFile" entry "${entry}": it must be a path inside the repository.`);
34
+ }
35
+ const stat = fs.statSync(abs, { throwIfNoEntry: false });
36
+ if (!stat) {
37
+ throw new Error(`"composeFile" entry "${entry}" does not exist (${abs}).`);
38
+ }
39
+ if (!stat.isFile()) {
40
+ throw new Error(`"composeFile" entry "${entry}" is not a file (${abs}): name the compose file itself.`);
41
+ }
42
+ return abs;
43
+ });
44
+ const isDefault = files.length === 1 &&
45
+ path.dirname(files[0]) === path.resolve(repoRoot) &&
46
+ detectComposeFile(repoRoot) === files[0];
47
+ return { files, custom: !isDefault };
48
+ }
49
+ const atRoot = detectComposeFile(repoRoot);
50
+ if (atRoot)
51
+ return { files: [atRoot], custom: false };
52
+ const found = [];
53
+ for (const dir of COMPOSE_DIRS) {
54
+ const file = detectComposeFile(path.join(repoRoot, dir));
55
+ if (file)
56
+ found.push(file);
57
+ }
58
+ if (found.length === 1) {
59
+ const rel = path.relative(repoRoot, found[0]);
60
+ return {
61
+ files: found,
62
+ custom: true,
63
+ note: `Using ${rel} as the compose file (none at the repository root). Set "composeFile" in .wtcrc.json to choose another.`,
64
+ };
65
+ }
66
+ if (found.length > 1) {
67
+ throw new Error(`No compose file at the root of ${repoRoot}, and several elsewhere: ${found
68
+ .map((f) => path.relative(repoRoot, f))
69
+ .join(", ")}. Set "composeFile" in .wtcrc.json to the one (or the list) your project runs.`);
70
+ }
71
+ return { files: [], custom: false };
72
+ }
@@ -7,7 +7,7 @@ import type { ComposeFile } from "./types.js";
7
7
  * a fixed `name:` or `external` (every stack shares them). Services in
8
8
  * `reset` have their container_name dropped at runtime, so they are fine.
9
9
  */
10
- export declare function composeIsolationWarnings(composeFile: ComposeFile, reset?: ReadonlySet<string>): string[];
10
+ export declare function composeIsolationWarnings(composeFile: ComposeFile, reset?: ReadonlySet<string>, unpinned?: ReadonlySet<string>): string[];
11
11
  /**
12
12
  * Hardcoded `host:container` port mappings that stay the same in every
13
13
  * worktree: those not in `remapped` (remapped at runtime).
@@ -15,12 +15,25 @@ export declare function composeIsolationWarnings(composeFile: ComposeFile, reset
15
15
  export declare function rawPortWarnings(portMappings: PortMapping[], remapped?: PortMapping[]): string[];
16
16
  /**
17
17
  * What runtime remapping does, for `wtc start` (info, not warnings: the
18
- * stacks no longer collide). Remapped ports have no variable, so env values
19
- * cannot follow them; the hint says how to give one a name.
18
+ * stacks no longer collide). A remapped port has no variable in the compose
19
+ * file; the note says under which generated name env values can use it.
20
+ * Long lists are cut unless `full` (doctor).
20
21
  */
21
- export declare function remapNotes(targets: RemapTargets, portMappings: PortMapping[]): string[];
22
+ export declare function remapNotes(targets: RemapTargets, portMappings: PortMapping[], full?: boolean): string[];
22
23
  /**
23
- * Advisory cross-worktree collision warning over the indices actually in use
24
- * (live worktrees plus orphans that still reserve theirs).
24
+ * Host directories outside the repository that services mount read-write:
25
+ * every worktree stack mounts the very same one, so what they write there
26
+ * is shared (two databases on one data directory corrupt it). Left out:
27
+ * the home directory (credentials and caches are meant to be shared),
28
+ * sockets, and read-only mounts.
25
29
  */
26
- export declare function portCollisionWarnings(portMappings: PortMapping[], portStride: number, indices: number[], remapped?: PortMapping[]): string[];
30
+ export declare function sharedHostPaths(composeFile: ComposeFile, repoRoot: string): string[];
31
+ /**
32
+ * `environment` values that name a host port the service's stack publishes
33
+ * (`PLAINTEXT://127.0.0.1:9092` as a broker's advertised address): a
34
+ * worktree stack publishes another port, so clients on the host that follow
35
+ * the value reach the main checkout's stack. `localhost` and `0.0.0.0` are
36
+ * left out — in a container's environment they mostly mean the container
37
+ * itself, or the address it listens on.
38
+ */
39
+ export declare function hostPortsInEnvironment(composeFile: ComposeFile, mappings: PortMapping[]): string[];
@@ -1,5 +1,8 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
1
3
  import { suggestEnvVars } from "../ports/extract.js";
2
- import { detectCrossWorktreeCollisions, recommendPortStride, } from "../ports/allocate.js";
4
+ import { GENERATED_VAR_PREFIX } from "../ports/allocate.js";
5
+ import { isWithin, realPath } from "../utils/paths.js";
3
6
  import { isProjectScopedName } from "./parse.js";
4
7
  /**
5
8
  * Compose settings that defeat per-worktree isolation: a fixed
@@ -7,8 +10,18 @@ import { isProjectScopedName } from "./parse.js";
7
10
  * a fixed `name:` or `external` (every stack shares them). Services in
8
11
  * `reset` have their container_name dropped at runtime, so they are fine.
9
12
  */
10
- export function composeIsolationWarnings(composeFile, reset = new Set()) {
13
+ export function composeIsolationWarnings(composeFile, reset = new Set(), unpinned = new Set()) {
11
14
  const warnings = [];
15
+ for (const n of composeFile.pinnedNetworks ?? []) {
16
+ if (unpinned.has(n))
17
+ continue;
18
+ warnings.push(`Network "${n}" pins its subnet (ipam.config) — a second stack cannot create the same subnet, so it fails to start. Remove the subnet, or let the engine choose it.`);
19
+ }
20
+ for (const svc of composeFile.services) {
21
+ if (svc.hostNetwork) {
22
+ warnings.push(`Service "${svc.name}" uses network_mode: host — it listens straight on the host, so every worktree stack would use the same ports.`);
23
+ }
24
+ }
12
25
  for (const svc of composeFile.services) {
13
26
  if (svc.containerName && !isProjectScopedName(svc.containerName) && !reset.has(svc.name)) {
14
27
  warnings.push(`Service "${svc.name}" sets container_name "${svc.containerName}" — every worktree stack would use the same name and the second one fails to start. Remove container_name.`);
@@ -37,55 +50,94 @@ export function rawPortWarnings(portMappings, remapped = []) {
37
50
  : `Service "${p.serviceName}" uses a raw port mapping (${p.raw}). ` +
38
51
  `To enable port isolation, change it to: "\${${suggestions.get(p)}:-${p.defaultPort}}:${p.containerPort}"`);
39
52
  }
53
+ /** A list for a one-line note: the first few items, then how many more there are. */
54
+ function brief(items, full, limit = 6) {
55
+ if (full || items.length <= limit)
56
+ return items.join(", ");
57
+ return `${items.slice(0, limit).join(", ")} and ${items.length - limit} more ('wtc doctor' lists them all)`;
58
+ }
40
59
  /**
41
60
  * What runtime remapping does, for `wtc start` (info, not warnings: the
42
- * stacks no longer collide). Remapped ports have no variable, so env values
43
- * cannot follow them; the hint says how to give one a name.
61
+ * stacks no longer collide). A remapped port has no variable in the compose
62
+ * file; the note says under which generated name env values can use it.
63
+ * Long lists are cut unless `full` (doctor).
44
64
  */
45
- export function remapNotes(targets, portMappings) {
65
+ export function remapNotes(targets, portMappings, full = false) {
46
66
  const notes = [];
47
67
  if (targets.ports.length > 0) {
48
- const suggestions = suggestEnvVars(portMappings);
49
68
  const first = targets.ports[0];
69
+ const name = `${GENERATED_VAR_PREFIX}${suggestEnvVars(portMappings).get(first)}`;
50
70
  notes.push(`Remapping hardcoded host ports per worktree at runtime (your compose file is unchanged): ` +
51
- `${targets.ports.map((m) => `${m.serviceName} ${m.raw}`).join(", ")}. ` +
52
- `To use one in env values, give it a variable, e.g. "\${${suggestions.get(first)}:-${first.defaultPort}}:${first.containerPort}".`);
71
+ `${brief(targets.ports.map((m) => `${m.serviceName} ${m.raw}`), full)}. ` +
72
+ `In env values each goes by a generated name, e.g. \${${name}}.`);
53
73
  }
54
74
  if (targets.containerNames.length > 0) {
55
75
  notes.push(`Dropping fixed container names per worktree at runtime (your compose file is unchanged): ` +
56
- `${targets.containerNames.map((c) => `${c.service} ("${c.name}")`).join(", ")}.`);
76
+ `${brief(targets.containerNames.map((c) => `${c.service} ("${c.name}")`), full)}.`);
77
+ }
78
+ if ((targets.networks ?? []).length > 0) {
79
+ notes.push(`Dropping fixed subnets per worktree at runtime (the engine picks a free one for each stack): ` +
80
+ `network ${targets.networks.map((n) => `"${n}"`).join(", ")}.`);
57
81
  }
58
82
  return notes;
59
83
  }
60
84
  /**
61
- * Advisory cross-worktree collision warning over the indices actually in use
62
- * (live worktrees plus orphans that still reserve theirs).
85
+ * Host directories outside the repository that services mount read-write:
86
+ * every worktree stack mounts the very same one, so what they write there
87
+ * is shared (two databases on one data directory corrupt it). Left out:
88
+ * the home directory (credentials and caches are meant to be shared),
89
+ * sockets, and read-only mounts.
63
90
  */
64
- export function portCollisionWarnings(portMappings, portStride, indices, remapped = []) {
65
- const inUse = [...new Set(indices)];
66
- if (inUse.length < 2)
67
- return [];
68
- // Collision detection is advisory; an allocation failure here must never
69
- // abort the command that triggered the warning.
70
- let collisions;
71
- try {
72
- collisions = detectCrossWorktreeCollisions(portMappings, portStride, inUse, remapped);
91
+ export function sharedHostPaths(composeFile, repoRoot) {
92
+ const warnings = [];
93
+ const seen = new Set();
94
+ // Bind sources are resolved against the compose file's real directory.
95
+ const roots = [repoRoot, realPath(repoRoot), os.homedir(), realPath(os.homedir())];
96
+ for (const svc of composeFile.services) {
97
+ for (const bind of svc.binds ?? []) {
98
+ if (bind.readOnly || roots.some((root) => isWithin(root, bind.source)))
99
+ continue;
100
+ if (/\.sock$/.test(bind.source) || bind.source.startsWith("/var/run/") || bind.source.startsWith("/run/"))
101
+ continue;
102
+ if (bind.source === path.parse(bind.source).root || /^\/(dev|proc|sys)(\/|$)/.test(bind.source))
103
+ continue;
104
+ const key = `${svc.name}\0${bind.source}`;
105
+ if (seen.has(key))
106
+ continue;
107
+ seen.add(key);
108
+ warnings.push(`Service "${svc.name}" mounts the host path ${bind.source} read-write — every worktree stack mounts the same one, so what they write there is shared (not isolated).`);
109
+ }
73
110
  }
74
- catch {
75
- return [];
111
+ return warnings;
112
+ }
113
+ /** Hosts under which a container's environment can only mean "a port published on this machine". */
114
+ const PUBLISHED_HOST = /(?<![A-Za-z0-9_.-])(127\.0\.0\.1|host\.docker\.internal):(\d+)(?!\d)/g;
115
+ /**
116
+ * `environment` values that name a host port the service's stack publishes
117
+ * (`PLAINTEXT://127.0.0.1:9092` as a broker's advertised address): a
118
+ * worktree stack publishes another port, so clients on the host that follow
119
+ * the value reach the main checkout's stack. `localhost` and `0.0.0.0` are
120
+ * left out — in a container's environment they mostly mean the container
121
+ * itself, or the address it listens on.
122
+ */
123
+ export function hostPortsInEnvironment(composeFile, mappings) {
124
+ const published = new Map();
125
+ for (const m of mappings)
126
+ if (!m.range)
127
+ published.set(m.defaultPort, m);
128
+ const suggestions = suggestEnvVars(mappings);
129
+ const warnings = [];
130
+ for (const svc of composeFile.services) {
131
+ for (const [key, value] of Object.entries(svc.environment ?? {})) {
132
+ for (const match of value.matchAll(PUBLISHED_HOST)) {
133
+ const mapping = published.get(Number(match[2]));
134
+ if (!mapping)
135
+ continue;
136
+ const name = mapping.envVar ?? `${GENERATED_VAR_PREFIX}${suggestions.get(mapping)}`;
137
+ warnings.push(`Service "${svc.name}": ${key} names ${match[1]}:${match[2]}, the port "${mapping.serviceName}" publishes in the main checkout (in a worktree: \${${name}}).`);
138
+ break;
139
+ }
140
+ }
76
141
  }
77
- if (collisions.length === 0)
78
- return [];
79
- const examples = collisions
80
- .slice(0, 3)
81
- .map((c) => `${c.port} (wt${c.a.worktreeIndex}/${c.a.serviceName} ↔ wt${c.b.worktreeIndex}/${c.b.serviceName})`)
82
- .join(", ");
83
- const recommended = recommendPortStride(portMappings, Math.max(...inUse), remapped);
84
- const fix = recommended > 0
85
- ? `Set "portStride": ${recommended} in .wtcrc.json (or package.json#wtc) to resolve.`
86
- : `No single portStride resolves this — check for services sharing the same default port.`;
87
- return [
88
- `Cross-worktree port collisions detected with portStride=${portStride} ` +
89
- `across worktrees ${inUse.sort((a, b) => a - b).join(", ")}: ${collisions.length} collision(s), e.g. ${examples}. ${fix}`,
90
- ];
142
+ return warnings;
91
143
  }
@@ -34,6 +34,17 @@ export interface RemapTargets {
34
34
  name: string;
35
35
  noAlias?: boolean;
36
36
  }[];
37
+ /**
38
+ * Networks whose pinned addresses (`ipam.config`) are dropped, so the
39
+ * engine picks a free subnet for each stack: two networks cannot hold the
40
+ * same subnet, and the main checkout's stack already has it.
41
+ */
42
+ networks?: string[];
43
+ /** Fixed `ipv4_address` / `ipv6_address` of services on those networks: dropped with the subnet. */
44
+ staticIps?: {
45
+ service: string;
46
+ network: string;
47
+ }[];
37
48
  }
38
49
  export declare function remapIsEmpty(t: RemapTargets): boolean;
39
50
  /**
@@ -89,18 +100,40 @@ export declare function overridePath(commonDir: string, project: string): string
89
100
  * wtc wrote into a worktree's env file, exported into the shell by a tool
90
101
  * that loads `.env` (direnv's `dotenv`, mise, autoenv). That is not a file
91
102
  * list of the user's, so it must not switch remapping off. Any other list
92
- * (a file added, another override picked) is the user's.
103
+ * (a file added, another override picked) is the user's. With a configured
104
+ * `composeFile`, `roots` are those files relative to the repository root:
105
+ * wtc then writes them (in the worktree) in place of the single default file.
93
106
  */
94
- export declare function isWtcComposeFile(value: string, commonDir: string): boolean;
107
+ export declare function isWtcComposeFile(value: string, commonDir: string, roots?: readonly string[]): boolean;
95
108
  /**
96
109
  * Whether the inherited `COMPOSE_FILE` names `file`: a list the shell still
97
110
  * holds (direnv, or one the user extended) would break if it were deleted.
98
111
  */
99
112
  export declare function inheritedComposeFileNames(file: string): boolean;
100
113
  /** A `COMPOSE_FILE` the user set (not one wtc wrote), from a value. */
101
- export declare function isUserComposeFile(value: string | null | undefined, commonDir: string): boolean;
114
+ export declare function isUserComposeFile(value: string | null | undefined, commonDir: string, roots?: readonly string[]): boolean;
102
115
  export declare function writeOverride(file: string, content: string): void;
103
116
  export declare function removeOverride(file: string): void;
117
+ /** The profile wtc gives a shared service in a worktree stack: nothing enables it, so the service does not start. */
118
+ export declare const SHARED_PROFILE = "wtc-shared";
119
+ /** What a stack's override carries besides remapping. */
120
+ export interface OverrideExtras {
121
+ /**
122
+ * Services the stack does not run: every worktree shares the main
123
+ * checkout's instance. They get a profile nothing enables.
124
+ */
125
+ shared?: string[];
126
+ /**
127
+ * `depends_on` per service, replacing the service's own: its
128
+ * dependencies without the shared services, which this stack does not start.
129
+ */
130
+ dependsOn?: Record<string, Record<string, Record<string, unknown>>>;
131
+ /** Env files (absolute) a service reads after its own, per service. */
132
+ envFiles?: Record<string, string[]>;
133
+ /** A service's whole `env_file` list (absolute paths, in order), replacing its own. */
134
+ envFileLists?: Record<string, string[]>;
135
+ }
136
+ export declare function extrasAreEmpty(extra: OverrideExtras): boolean;
104
137
  /**
105
138
  * The override YAML for one stack. A service whose hardcoded ports are
106
139
  * remapped gets its whole `ports` list (`!override` replaces it): every
@@ -109,7 +142,7 @@ export declare function removeOverride(file: string): void;
109
142
  * its own networks. Strings are quoted, so YAML 1.1 parsers never read
110
143
  * `2222:22` as a base-60 number.
111
144
  */
112
- export declare function renderOverride(project: string, composeFile: ComposeFile, targets: RemapTargets, allocations: PortAllocation[]): string;
145
+ export declare function renderOverride(project: string, composeFile: ComposeFile, targets: RemapTargets, allocations: PortAllocation[], extra?: OverrideExtras): string;
113
146
  /** True when `config` output shows the probe override applied: one port, published on 2, no container_name. */
114
147
  export declare function probeApplied(stdout: string): boolean;
115
148
  /** Forget cached probe results (tests). */
@@ -145,8 +178,25 @@ export interface RemapInputs {
145
178
  envFiles: (string | null)[];
146
179
  /** The root `envOverrides`, which wtc writes into the worktree's env file. */
147
180
  envOverrides?: Record<string, string>;
181
+ /**
182
+ * The configured compose files, relative to the repository root, when
183
+ * compose would not find them by itself: a `COMPOSE_FILE` that lists
184
+ * exactly these is one wtc wrote, not the user's.
185
+ */
186
+ composeRoots?: readonly string[];
148
187
  /** Resolves the engine; throwing means "no engine" (nothing to remap with). */
149
188
  engine: () => ComposeEngine;
150
189
  }
190
+ /**
191
+ * Why wtc cannot remap anything in this repository at runtime — a
192
+ * `COMPOSE_FILE` of the user's (wtc's would replace it), a different path
193
+ * separator, or an engine that does not apply `!override` / `!reset` — or
194
+ * null when it can. `engine: false` means no engine was available at all
195
+ * (nothing runs; the engine problem is reported elsewhere).
196
+ */
197
+ export declare function remapBlocker(inputs: Omit<RemapInputs, "composeFile" | "mappings">): {
198
+ problem: string | null;
199
+ engine: boolean;
200
+ };
151
201
  /** Decide what to remap for this repository (see the module comment). */
152
202
  export declare function decideRemap(inputs: RemapInputs): RemapDecision;