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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ComposeEngine } from "./engine.js";
|
|
2
|
+
export interface StackState {
|
|
3
|
+
running: number;
|
|
4
|
+
total: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const PROJECT_LABELS: string[];
|
|
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 declare function parseLabelString(labels: string): Record<string, string>;
|
|
17
|
+
/** Case-insensitive field lookup: Docker uses `Labels`/`ID`, Podman `labels`/`Id`. */
|
|
18
|
+
export declare function field(obj: Record<string, unknown>, name: string): unknown;
|
|
19
|
+
export declare function labelsOf(container: Record<string, unknown>): Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Parse `--format json` listings (`ps`, `network ls`, `volume ls`): Docker
|
|
22
|
+
* emits NDJSON, Podman one JSON array. Throws when the output is neither.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseJsonListing(output: string): Record<string, unknown>[];
|
|
25
|
+
/** A container from `ps -a --format json`, reduced to what wtc needs. */
|
|
26
|
+
export interface PsContainer {
|
|
27
|
+
id: string;
|
|
28
|
+
/** First container name. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Compose project label, or `null` for non-compose containers. */
|
|
31
|
+
project: string | null;
|
|
32
|
+
/** Compose's `project.working_dir` label (the directory compose ran in). */
|
|
33
|
+
workingDir: string | null;
|
|
34
|
+
/** Lower-cased engine state: `running`, `exited`, `created`, `paused`… */
|
|
35
|
+
state: string;
|
|
36
|
+
running: boolean;
|
|
37
|
+
/** `compose run` container (one-off), not part of the stack's services. */
|
|
38
|
+
oneoff: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every container of a `ps -a --format json` listing with what wtc needs per
|
|
42
|
+
* container: compose project, working_dir (to adopt a running stack into
|
|
43
|
+
* the registry), state, and whether it is a one-off. Sibling of
|
|
44
|
+
* `parsePsJson`, which reduces the same listing to per-project counts.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parsePsContainers(output: string): PsContainer[];
|
|
47
|
+
/**
|
|
48
|
+
* Count running/total containers per compose project from `ps -a --format json`.
|
|
49
|
+
* Docker emits NDJSON with a `Labels` string; Podman emits one JSON array with
|
|
50
|
+
* a `Labels` object. One-off `compose run` containers are not counted: they
|
|
51
|
+
* are not part of the stack, and counting them shows a healthy stack as
|
|
52
|
+
* `partial` until clean. Throws when the output is neither shape.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parsePsJson(output: string): Map<string, StackState>;
|
|
55
|
+
/** One `<cli> ps -a --format json` call (bounded by a timeout). Throws on failure. */
|
|
56
|
+
export declare function listContainers(engine: ComposeEngine): PsContainer[];
|
|
57
|
+
/** One `<cli> ps -a --format json` call → state per compose project. Throws on failure. */
|
|
58
|
+
export declare function getStackStates(engine: ComposeEngine): Map<string, StackState>;
|
|
59
|
+
/**
|
|
60
|
+
* Per-project fallback: `compose -p P ps -q` (running) and `ps -a -q` (total).
|
|
61
|
+
* podman-compose's `ps` accepts only `-q` and always lists every container,
|
|
62
|
+
* so it cannot tell running from stopped: its state is unknown.
|
|
63
|
+
*/
|
|
64
|
+
export declare function probeStackDirect(engine: ComposeEngine, project: string, cwd?: string): StackState | null;
|
|
65
|
+
/** Answers "what state is project P in?" — `null` means unknown (engine unreachable). */
|
|
66
|
+
export interface StackProbe {
|
|
67
|
+
readonly engine: ComposeEngine | null;
|
|
68
|
+
/** Why states are unknown (no engine, daemon down), when they are. */
|
|
69
|
+
readonly problem: string | null;
|
|
70
|
+
state(project: string): StackState | null;
|
|
71
|
+
/**
|
|
72
|
+
* Every container the engine reports (one-offs included, flagged), or
|
|
73
|
+
* `null` when that listing is unavailable (engine down, or unparseable
|
|
74
|
+
* `ps` output — then `problem` is null and states come per project).
|
|
75
|
+
*/
|
|
76
|
+
containers(): PsContainer[] | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Lazily fetch stack states once, falling back to per-project compose calls
|
|
80
|
+
* when the `ps` JSON cannot be parsed (older engines, unexpected shapes).
|
|
81
|
+
*/
|
|
82
|
+
export declare function createStackProbe(engine: ComposeEngine | null, engineProblem?: string | null, cwd?: string): StackProbe;
|
|
83
|
+
export type StackStatus = "up" | "partial" | "exited" | "down" | "?";
|
|
84
|
+
export declare function stackStatus(state: StackState | null): StackStatus;
|
|
@@ -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
|
+
}
|
package/dist/compose/types.d.ts
CHANGED
|
@@ -4,10 +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;
|
|
13
|
+
/** Absolute path of the compose file that declared this service. */
|
|
14
|
+
sourcePath: string;
|
|
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;
|
|
9
27
|
}
|
|
10
28
|
export interface ComposeFile {
|
|
11
29
|
services: ComposeService[];
|
|
30
|
+
/** Resolved absolute path of the root compose file. */
|
|
12
31
|
composePath: string;
|
|
32
|
+
/** Absolute paths of the root file plus all transitively-included files, root first. */
|
|
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[];
|
|
13
38
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
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>>;
|
|
23
|
+
/**
|
|
24
|
+
* Per-worktree-index port stride. Allocated port =
|
|
25
|
+
* 20000 + defaultPort + worktreeIndex * portStride. Defaults to 1.
|
|
26
|
+
* Raise it (e.g. 100) when a project exposes clustered default host
|
|
27
|
+
* ports so that adjacent worktrees do not collide across services.
|
|
28
|
+
*/
|
|
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[];
|
|
4
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;
|
|
40
|
+
}
|
|
41
|
+
/** Load `.wtcrc.json`, else `package.json#wtc`, recording which file was used. */
|
|
42
|
+
export declare function loadConfigWithSource(repoRoot: string): LoadedConfig;
|
|
5
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
|
-
|
|
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
|
-
|
|
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 =
|
|
11
|
-
if (pkg
|
|
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,14 +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;
|
|
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;
|
|
12
72
|
}
|
|
13
|
-
|
|
14
|
-
|
|
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;
|