splithub 0.1.9 → 0.2.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/dist/chunk-3DUWIEHB.js +561 -0
- package/dist/chunk-3DUWIEHB.js.map +1 -0
- package/dist/chunk-3VACHXWE.js +319 -0
- package/dist/chunk-3VACHXWE.js.map +1 -0
- package/dist/chunk-3VY5CP3E.js +383 -0
- package/dist/chunk-3VY5CP3E.js.map +1 -0
- package/dist/chunk-74NI7BED.js +58 -0
- package/dist/chunk-74NI7BED.js.map +1 -0
- package/dist/chunk-A2RCSPG6.js +184 -0
- package/dist/chunk-A2RCSPG6.js.map +1 -0
- package/dist/chunk-AJO3C4BS.js +97 -0
- package/dist/chunk-AJO3C4BS.js.map +1 -0
- package/dist/chunk-C5S7RPYM.js +54 -0
- package/dist/chunk-C5S7RPYM.js.map +1 -0
- package/dist/chunk-EUF75FUC.js +160 -0
- package/dist/chunk-EUF75FUC.js.map +1 -0
- package/dist/chunk-EYYLDI5J.js +195 -0
- package/dist/chunk-EYYLDI5J.js.map +1 -0
- package/dist/chunk-GVARYUL3.js +28 -0
- package/dist/chunk-GVARYUL3.js.map +1 -0
- package/dist/chunk-HSH4ZI2V.js +72 -0
- package/dist/chunk-HSH4ZI2V.js.map +1 -0
- package/dist/chunk-PLXDG4B5.js +134 -0
- package/dist/chunk-PLXDG4B5.js.map +1 -0
- package/dist/chunk-PWSRKABE.js +113 -0
- package/dist/chunk-PWSRKABE.js.map +1 -0
- package/dist/chunk-QOXGIB3R.js +393 -0
- package/dist/chunk-QOXGIB3R.js.map +1 -0
- package/dist/chunk-UUTLLC54.js +158 -0
- package/dist/chunk-UUTLLC54.js.map +1 -0
- package/dist/chunk-V3DLUVOE.js +112 -0
- package/dist/chunk-V3DLUVOE.js.map +1 -0
- package/dist/chunk-YSXW2HN6.js +104 -0
- package/dist/chunk-YSXW2HN6.js.map +1 -0
- package/dist/ci-ZQZ6RBUJ.js +16 -0
- package/dist/ci-ZQZ6RBUJ.js.map +1 -0
- package/dist/create-K75OY6XK.js +18 -0
- package/dist/create-K75OY6XK.js.map +1 -0
- package/dist/dev-WQWFEA6I.js +11 -0
- package/dist/dev-WQWFEA6I.js.map +1 -0
- package/dist/doctor-MFYBZUKO.js +13 -0
- package/dist/doctor-MFYBZUKO.js.map +1 -0
- package/dist/holdout-PECSNGAD.js +44 -0
- package/dist/holdout-PECSNGAD.js.map +1 -0
- package/dist/index.js +84 -2239
- package/dist/index.js.map +1 -1
- package/dist/init-QAAM2GQ7.js +15 -0
- package/dist/init-QAAM2GQ7.js.map +1 -0
- package/dist/lifecycle-56HM7ITG.js +12 -0
- package/dist/lifecycle-56HM7ITG.js.map +1 -0
- package/dist/login-TTWSQ7XS.js +18 -0
- package/dist/login-TTWSQ7XS.js.map +1 -0
- package/dist/menu-UQX3K5QR.js +162 -0
- package/dist/menu-UQX3K5QR.js.map +1 -0
- package/dist/plan-BSFSMKTU.js +135 -0
- package/dist/plan-BSFSMKTU.js.map +1 -0
- package/dist/push-YVS25VVD.js +16 -0
- package/dist/push-YVS25VVD.js.map +1 -0
- package/dist/refs-ZDNH6NRK.js +44 -0
- package/dist/refs-ZDNH6NRK.js.map +1 -0
- package/dist/remove-KFQUK367.js +54 -0
- package/dist/remove-KFQUK367.js.map +1 -0
- package/dist/report-TF2BLJMC.js +64 -0
- package/dist/report-TF2BLJMC.js.map +1 -0
- package/dist/results-TLV5KJWO.js +17 -0
- package/dist/results-TLV5KJWO.js.map +1 -0
- package/dist/review-EIZDOGDC.js +34 -0
- package/dist/review-EIZDOGDC.js.map +1 -0
- package/dist/ship-4YX2WCBP.js +450 -0
- package/dist/ship-4YX2WCBP.js.map +1 -0
- package/dist/skills-HWQT3DTJ.js +13 -0
- package/dist/skills-HWQT3DTJ.js.map +1 -0
- package/dist/status-CWI7ZCYJ.js +11 -0
- package/dist/status-CWI7ZCYJ.js.map +1 -0
- package/package.json +22 -5
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CliError,
|
|
4
|
+
fail
|
|
5
|
+
} from "./chunk-V3DLUVOE.js";
|
|
6
|
+
|
|
7
|
+
// src/config-file.ts
|
|
8
|
+
import { isSplitHubConfig } from "@splithub/core";
|
|
9
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
10
|
+
import { basename } from "path";
|
|
11
|
+
import { pathToFileURL } from "url";
|
|
12
|
+
async function loadConfig(file) {
|
|
13
|
+
let mod;
|
|
14
|
+
try {
|
|
15
|
+
const { createJiti } = await import("jiti");
|
|
16
|
+
const jiti = createJiti(pathToFileURL(file).href, { fsCache: false, moduleCache: false });
|
|
17
|
+
mod = await jiti.import(file, { default: true });
|
|
18
|
+
} catch (error) {
|
|
19
|
+
fail("CONFIG_PARSE", `${basename(file)} doesn't load: ${error instanceof Error ? error.message.split("\n")[0] : String(error)}`, "Fix the error in the file, then run npx splithub doctor.");
|
|
20
|
+
}
|
|
21
|
+
if (!isSplitHubConfig(mod)) {
|
|
22
|
+
fail("CONFIG_PARSE", `${basename(file)} must \`export default defineConfig({...})\` from @splithub/core.`);
|
|
23
|
+
}
|
|
24
|
+
return mod;
|
|
25
|
+
}
|
|
26
|
+
var REGEX_BEFORE = /* @__PURE__ */ new Set(["", "(", ",", "=", ":", "[", "!", "&", "|", "?", "{", "}", ";", "+", "-", "*", "%", "<", ">", "~", "^"]);
|
|
27
|
+
function maskSource(source) {
|
|
28
|
+
const out = source.split("");
|
|
29
|
+
const blank = (from, to) => {
|
|
30
|
+
for (let j = from; j < to && j < out.length; j++) if (out[j] !== "\n" && out[j] !== "\r") out[j] = " ";
|
|
31
|
+
};
|
|
32
|
+
let lastCode = "";
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < source.length) {
|
|
35
|
+
const ch = source[i];
|
|
36
|
+
const next = source[i + 1];
|
|
37
|
+
if (ch === "/" && next === "/") {
|
|
38
|
+
const end = source.indexOf("\n", i);
|
|
39
|
+
const stop = end < 0 ? source.length : end;
|
|
40
|
+
blank(i, stop);
|
|
41
|
+
i = stop;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ch === "/" && next === "*") {
|
|
45
|
+
const end = source.indexOf("*/", i + 2);
|
|
46
|
+
const stop = end < 0 ? source.length : end + 2;
|
|
47
|
+
blank(i, stop);
|
|
48
|
+
i = stop;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (ch === "'" || ch === '"') {
|
|
52
|
+
let j = i + 1;
|
|
53
|
+
while (j < source.length && source[j] !== ch && source[j] !== "\n") j += source[j] === "\\" ? 2 : 1;
|
|
54
|
+
blank(i + 1, j);
|
|
55
|
+
i = j + 1;
|
|
56
|
+
lastCode = ch;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (ch === "`") {
|
|
60
|
+
let j = i + 1;
|
|
61
|
+
let depth = 0;
|
|
62
|
+
while (j < source.length) {
|
|
63
|
+
const c = source[j];
|
|
64
|
+
if (c === "\\") {
|
|
65
|
+
j += 2;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (depth === 0 && c === "`") break;
|
|
69
|
+
if (c === "$" && source[j + 1] === "{") {
|
|
70
|
+
depth++;
|
|
71
|
+
j += 2;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (depth > 0 && c === "{") depth++;
|
|
75
|
+
else if (depth > 0 && c === "}") depth--;
|
|
76
|
+
j++;
|
|
77
|
+
}
|
|
78
|
+
blank(i + 1, j);
|
|
79
|
+
i = j + 1;
|
|
80
|
+
lastCode = "`";
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (ch === "/" && REGEX_BEFORE.has(lastCode)) {
|
|
84
|
+
let j = i + 1;
|
|
85
|
+
let inClass = false;
|
|
86
|
+
while (j < source.length && source[j] !== "\n") {
|
|
87
|
+
const c = source[j];
|
|
88
|
+
if (c === "\\") {
|
|
89
|
+
j += 2;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (c === "[") inClass = true;
|
|
93
|
+
else if (c === "]") inClass = false;
|
|
94
|
+
else if (c === "/" && !inClass) break;
|
|
95
|
+
j++;
|
|
96
|
+
}
|
|
97
|
+
blank(i + 1, j);
|
|
98
|
+
i = j + 1;
|
|
99
|
+
lastCode = "/";
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!/\s/.test(ch)) lastCode = /[\w$)\]]/.test(ch) ? "x" : ch;
|
|
103
|
+
i++;
|
|
104
|
+
}
|
|
105
|
+
return out.join("");
|
|
106
|
+
}
|
|
107
|
+
function matchingClose(masked, open) {
|
|
108
|
+
let depth = 0;
|
|
109
|
+
for (let i = open; i < masked.length; i++) {
|
|
110
|
+
const ch = masked[i];
|
|
111
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
112
|
+
else if (ch === "}" || ch === ")" || ch === "]") {
|
|
113
|
+
depth--;
|
|
114
|
+
if (depth === 0) return i;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function objectEntries(source, masked, open, close) {
|
|
120
|
+
const entries = [];
|
|
121
|
+
let i = open + 1;
|
|
122
|
+
const ws = () => {
|
|
123
|
+
while (i < close && /[\s,]/.test(masked[i])) i++;
|
|
124
|
+
};
|
|
125
|
+
const valueTo = (from) => {
|
|
126
|
+
let j = from;
|
|
127
|
+
while (j < close) {
|
|
128
|
+
const ch = masked[j];
|
|
129
|
+
if (ch === ",") break;
|
|
130
|
+
if (ch === "{" || ch === "(" || ch === "[") {
|
|
131
|
+
const m = matchingClose(masked, j);
|
|
132
|
+
j = m === null ? close : m + 1;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
j++;
|
|
136
|
+
}
|
|
137
|
+
return j;
|
|
138
|
+
};
|
|
139
|
+
for (; ; ) {
|
|
140
|
+
ws();
|
|
141
|
+
if (i >= close) break;
|
|
142
|
+
const start = i;
|
|
143
|
+
let key = null;
|
|
144
|
+
let kind = "expr";
|
|
145
|
+
if (masked.startsWith("...", i)) {
|
|
146
|
+
kind = "spread";
|
|
147
|
+
i += 3;
|
|
148
|
+
} else {
|
|
149
|
+
const ch = masked[i];
|
|
150
|
+
if (ch === "'" || ch === '"') {
|
|
151
|
+
const end2 = masked.indexOf(ch, i + 1);
|
|
152
|
+
key = source.slice(i + 1, end2).replace(/\\(.)/g, "$1");
|
|
153
|
+
i = end2 + 1;
|
|
154
|
+
} else if (ch === "[") {
|
|
155
|
+
kind = "computed";
|
|
156
|
+
const m = matchingClose(masked, i);
|
|
157
|
+
i = m === null ? close : m + 1;
|
|
158
|
+
} else {
|
|
159
|
+
const m = /^[\w$-]+/.exec(masked.slice(i, close));
|
|
160
|
+
if (!m) break;
|
|
161
|
+
key = m[0];
|
|
162
|
+
i += m[0].length;
|
|
163
|
+
}
|
|
164
|
+
while (i < close && /\s/.test(masked[i])) i++;
|
|
165
|
+
if (masked[i] === ":") i++;
|
|
166
|
+
}
|
|
167
|
+
while (i < close && /\s/.test(masked[i])) i++;
|
|
168
|
+
const valueStart = i;
|
|
169
|
+
const stop = valueTo(i);
|
|
170
|
+
let valueEnd = stop;
|
|
171
|
+
while (valueEnd > valueStart && /\s/.test(masked[valueEnd - 1])) valueEnd--;
|
|
172
|
+
if (kind === "expr" && masked[valueStart] === "{" && matchingClose(masked, valueStart) === valueEnd - 1) kind = "object";
|
|
173
|
+
const end = masked[stop] === "," ? stop + 1 : valueEnd;
|
|
174
|
+
entries.push({ key, kind, start, valueStart, valueEnd, end });
|
|
175
|
+
i = stop;
|
|
176
|
+
}
|
|
177
|
+
return entries;
|
|
178
|
+
}
|
|
179
|
+
function locateExperiments(source) {
|
|
180
|
+
const masked = maskSource(source);
|
|
181
|
+
let open = -1;
|
|
182
|
+
const root = /defineConfig\s*\(\s*\{|export\s+default\s+\{/.exec(masked);
|
|
183
|
+
if (root) {
|
|
184
|
+
const rootOpen = root.index + root[0].length - 1;
|
|
185
|
+
const rootClose = matchingClose(masked, rootOpen);
|
|
186
|
+
if (rootClose !== null) {
|
|
187
|
+
const exp = objectEntries(source, masked, rootOpen, rootClose).find((e) => e.key === "experiments");
|
|
188
|
+
if (exp && exp.kind !== "object") {
|
|
189
|
+
fail("CONFIG_UNSAFE", "`experiments` in the config is not written inline, so the CLI cannot edit it safely.", "Edit the experiments where they are defined, or write them inline as experiments: { ... }.");
|
|
190
|
+
}
|
|
191
|
+
if (exp) open = exp.valueStart;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (open < 0) {
|
|
195
|
+
const m = /\bexperiments\s*:\s*\{/.exec(masked);
|
|
196
|
+
if (!m) fail("CONFIG_UNSAFE", "Couldn't find `experiments: {` in the config file.", "Add experiments: {} to defineConfig({...}) and retry.");
|
|
197
|
+
open = m.index + m[0].length - 1;
|
|
198
|
+
}
|
|
199
|
+
const close = matchingClose(masked, open);
|
|
200
|
+
if (close === null) fail("CONFIG_PARSE", "The braces after `experiments: {` are not balanced.");
|
|
201
|
+
return { masked, open, close, entries: objectEntries(source, masked, open, close) };
|
|
202
|
+
}
|
|
203
|
+
function unsafeHint(key) {
|
|
204
|
+
return `Edit "${key}" where it is defined (it comes from a spread or an imported constant), then run npx splithub doctor.`;
|
|
205
|
+
}
|
|
206
|
+
function experimentEntry(source, key) {
|
|
207
|
+
const loc = locateExperiments(source);
|
|
208
|
+
const entry = loc.entries.find((e) => e.key === key);
|
|
209
|
+
if (!entry) {
|
|
210
|
+
if (loc.entries.some((e) => e.kind === "spread" || e.kind === "computed")) {
|
|
211
|
+
fail("CONFIG_UNSAFE", `"${key}" isn't written inline in the config (the experiments use a spread), so the CLI can't edit it safely.`, unsafeHint(key));
|
|
212
|
+
}
|
|
213
|
+
fail("EXPERIMENT_NOT_FOUND", `There's no experiment "${key}" in the config.`, "See the ids with npx splithub status.");
|
|
214
|
+
}
|
|
215
|
+
return { ...loc, entry };
|
|
216
|
+
}
|
|
217
|
+
function hasExperiment(source, key) {
|
|
218
|
+
try {
|
|
219
|
+
return locateExperiments(source).entries.some((e) => e.key === key);
|
|
220
|
+
} catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function indentAt(source, index) {
|
|
225
|
+
const lineStart = source.lastIndexOf("\n", index - 1) + 1;
|
|
226
|
+
return /^[ \t]*/.exec(source.slice(lineStart))?.[0] ?? "";
|
|
227
|
+
}
|
|
228
|
+
function appendProperty(source, masked, open, close, render) {
|
|
229
|
+
const outerIndent = indentAt(source, open);
|
|
230
|
+
const indent = outerIndent + " ";
|
|
231
|
+
let last = close - 1;
|
|
232
|
+
while (last > open && /\s/.test(masked[last])) last--;
|
|
233
|
+
const needsComma = last > open && masked[last] !== ",";
|
|
234
|
+
const lineStart = source.lastIndexOf("\n", close - 1) + 1;
|
|
235
|
+
const closeOnOwnLine = source.slice(lineStart, close).trim() === "";
|
|
236
|
+
const block = `${indent}${render(indent)},
|
|
237
|
+
`;
|
|
238
|
+
const at = closeOnOwnLine && lineStart > last ? lineStart : close;
|
|
239
|
+
const text = at === close ? `
|
|
240
|
+
${block}${outerIndent}` : block;
|
|
241
|
+
const comma = needsComma ? "," : "";
|
|
242
|
+
const head = at === close ? source.slice(0, last + 1) + comma : source.slice(0, last + 1) + comma + source.slice(last + 1, at);
|
|
243
|
+
return head + text + source.slice(at);
|
|
244
|
+
}
|
|
245
|
+
function q(s) {
|
|
246
|
+
return `'${s.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n")}'`;
|
|
247
|
+
}
|
|
248
|
+
function k(s) {
|
|
249
|
+
return /^[a-z_$][\w$]*$/i.test(s) ? s : q(s);
|
|
250
|
+
}
|
|
251
|
+
function renderExperiment(e, indent = " ") {
|
|
252
|
+
const i2 = indent + " ";
|
|
253
|
+
const i3 = i2 + " ";
|
|
254
|
+
const lines = [`${k(e.key)}: {`];
|
|
255
|
+
lines.push(`${i2}kind: ${q(e.kind)},`);
|
|
256
|
+
lines.push(`${i2}status: ${q(e.status)},`);
|
|
257
|
+
if (e.match) lines.push(`${i2}match: ${q(e.match)},`);
|
|
258
|
+
if (e.kind === "mvt") {
|
|
259
|
+
lines.push(`${i2}factors: {`);
|
|
260
|
+
for (const [factor, levels] of Object.entries(e.factors ?? {})) {
|
|
261
|
+
lines.push(`${i3}${k(factor)}: { ${Object.entries(levels).map(([l, v]) => `${k(l)}: ${q(v)}`).join(", ")} },`);
|
|
262
|
+
}
|
|
263
|
+
lines.push(`${i2}},`);
|
|
264
|
+
} else if (e.kind === "component") {
|
|
265
|
+
lines.push(`${i2}variants: { ${e.variants.map((v) => `${k(v.key)}: ${v.weight}`).join(", ")} },`);
|
|
266
|
+
} else {
|
|
267
|
+
lines.push(`${i2}variants: {`);
|
|
268
|
+
for (const v of e.variants) {
|
|
269
|
+
const extra = e.kind === "value" ? `value: ${q(v.value ?? "")}` : `to: ${q(v.to ?? "/")}`;
|
|
270
|
+
lines.push(`${i3}${k(v.key)}: { weight: ${v.weight}, ${extra} },`);
|
|
271
|
+
}
|
|
272
|
+
lines.push(`${i2}},`);
|
|
273
|
+
}
|
|
274
|
+
if (e.goal) lines.push(`${i2}goal: ${q(e.goal)},`);
|
|
275
|
+
if (e.traffic !== void 0 && e.traffic !== 1) lines.push(`${i2}traffic: ${e.traffic},`);
|
|
276
|
+
if (e.maxExposures) lines.push(`${i2}maxExposures: ${e.maxExposures},`);
|
|
277
|
+
if (e.minDays !== void 0) lines.push(`${i2}minDays: ${e.minDays},`);
|
|
278
|
+
if (e.schedule && (e.schedule.startAt || e.schedule.endAt)) lines.push(`${i2}schedule: { ${[e.schedule.startAt ? `startAt: ${q(e.schedule.startAt)}` : null, e.schedule.endAt ? `endAt: ${q(e.schedule.endAt)}` : null].filter(Boolean).join(", ")} },`);
|
|
279
|
+
if (e.metrics && (e.metrics.secondary?.length || e.metrics.guardrails?.length)) {
|
|
280
|
+
const parts = [];
|
|
281
|
+
if (e.metrics.secondary?.length) parts.push(`secondary: [${e.metrics.secondary.map(q).join(", ")}]`);
|
|
282
|
+
if (e.metrics.guardrails?.length) parts.push(`guardrails: [${e.metrics.guardrails.map((g) => typeof g === "string" ? q(g) : `{ goal: ${q(g.goal)}, worse: ${q(g.worse)} }`).join(", ")}]`);
|
|
283
|
+
lines.push(`${i2}metrics: { ${parts.join(", ")} },`);
|
|
284
|
+
}
|
|
285
|
+
if (e.layer) lines.push(`${i2}layer: { key: ${q(e.layer.key)}, range: [${e.layer.range[0]}, ${e.layer.range[1]}] },`);
|
|
286
|
+
if (e.description) lines.push(`${i2}description: ${q(e.description)},`);
|
|
287
|
+
if (e.flow) {
|
|
288
|
+
const json = JSON.stringify(e.flow, null, 2).split("\n");
|
|
289
|
+
lines.push(`${i2}// targeting graph from the dashboard; edit it there or by hand
|
|
290
|
+
${i2}flow: ${json.map((l, n) => n === 0 ? l : i2 + l).join("\n")},`);
|
|
291
|
+
}
|
|
292
|
+
lines.push(`${indent}}`);
|
|
293
|
+
return lines.join("\n");
|
|
294
|
+
}
|
|
295
|
+
function insertExperiment(source, e) {
|
|
296
|
+
const { masked, open, close, entries } = locateExperiments(source);
|
|
297
|
+
if (entries.some((x) => x.key === e.key)) fail("EXPERIMENT_EXISTS", `There's already an experiment "${e.key}".`, "Pick another id: an old id keeps its history.");
|
|
298
|
+
return appendProperty(source, masked, open, close, (indent) => renderExperiment(e, indent));
|
|
299
|
+
}
|
|
300
|
+
function setExperimentStatus(source, key, status) {
|
|
301
|
+
const { masked, entry } = experimentEntry(source, key);
|
|
302
|
+
if (entry.kind !== "object") fail("CONFIG_UNSAFE", `"${key}" points to a value defined elsewhere, so the CLI can't edit it safely.`, unsafeHint(key));
|
|
303
|
+
const inner = objectEntries(source, masked, entry.valueStart, entry.valueEnd - 1);
|
|
304
|
+
const field = inner.filter((x) => x.key === "status").pop();
|
|
305
|
+
if (field) {
|
|
306
|
+
const raw = masked.slice(field.valueStart, field.valueEnd);
|
|
307
|
+
if (!/^(['"])\s*\1$/.test(raw)) fail("CONFIG_UNSAFE", `The status of "${key}" isn't a plain string, so the CLI can't change it safely.`, `Set status: '${status}' by hand.`);
|
|
308
|
+
const quote = raw[0];
|
|
309
|
+
return source.slice(0, field.valueStart) + `${quote}${status}${quote}` + source.slice(field.valueEnd);
|
|
310
|
+
}
|
|
311
|
+
return appendProperty(source, masked, entry.valueStart, entry.valueEnd - 1, () => `status: ${q(status)}`);
|
|
312
|
+
}
|
|
313
|
+
function removeExperiment(source, key) {
|
|
314
|
+
return removeEntry(source, experimentEntry(source, key).entry);
|
|
315
|
+
}
|
|
316
|
+
function removeEntry(source, entry) {
|
|
317
|
+
const lineStart = source.lastIndexOf("\n", entry.start - 1) + 1;
|
|
318
|
+
const from = source.slice(lineStart, entry.start).trim() === "" ? lineStart : entry.start;
|
|
319
|
+
let to = entry.end;
|
|
320
|
+
const lineEnd = source.indexOf("\n", to);
|
|
321
|
+
const rest = source.slice(to, lineEnd < 0 ? source.length : lineEnd);
|
|
322
|
+
if (rest.trim() === "" && from === lineStart) to = lineEnd < 0 ? source.length : lineEnd + 1;
|
|
323
|
+
return source.slice(0, from) + source.slice(to);
|
|
324
|
+
}
|
|
325
|
+
function locateRoot(source) {
|
|
326
|
+
const masked = maskSource(source);
|
|
327
|
+
const root = /defineConfig\s*\(\s*\{|export\s+default\s+\{/.exec(masked);
|
|
328
|
+
if (!root) fail("CONFIG_UNSAFE", "Couldn't find defineConfig({ ... }) in the config file.", "Make the change by hand in splithub.config.ts.");
|
|
329
|
+
const open = root.index + root[0].length - 1;
|
|
330
|
+
const close = matchingClose(masked, open);
|
|
331
|
+
if (close === null) fail("CONFIG_PARSE", "The braces of defineConfig({ ... }) are not balanced.");
|
|
332
|
+
return { masked, open, close, entries: objectEntries(source, masked, open, close) };
|
|
333
|
+
}
|
|
334
|
+
function setTopLevel(source, name, valueText) {
|
|
335
|
+
const { masked, open, close, entries } = locateRoot(source);
|
|
336
|
+
const entry = entries.find((e) => e.key === name);
|
|
337
|
+
if (valueText === null) return entry ? removeEntry(source, entry) : source;
|
|
338
|
+
if (entry) return source.slice(0, entry.valueStart) + valueText + source.slice(entry.valueEnd);
|
|
339
|
+
return appendProperty(source, masked, open, close, () => `${k(name)}: ${valueText}`);
|
|
340
|
+
}
|
|
341
|
+
function ensureLayer(source, key) {
|
|
342
|
+
const { masked, open, close, entries } = locateRoot(source);
|
|
343
|
+
const layers = entries.find((e) => e.key === "layers");
|
|
344
|
+
if (!layers) return appendProperty(source, masked, open, close, () => `layers: { ${k(key)}: {} }`);
|
|
345
|
+
if (layers.kind !== "object") fail("CONFIG_UNSAFE", "`layers` in the config is not written inline.", `Add ${key}: {} to layers by hand.`);
|
|
346
|
+
if (objectEntries(source, masked, layers.valueStart, layers.valueEnd - 1).some((e) => e.key === key)) return source;
|
|
347
|
+
return appendProperty(source, masked, layers.valueStart, layers.valueEnd - 1, () => `${k(key)}: {}`);
|
|
348
|
+
}
|
|
349
|
+
function readSource(file) {
|
|
350
|
+
return readFileSync(file, "utf8");
|
|
351
|
+
}
|
|
352
|
+
function writeSource(file, source) {
|
|
353
|
+
writeFileSync(file, source, "utf8");
|
|
354
|
+
}
|
|
355
|
+
async function writeConfigChecked(file, original, updated, verify) {
|
|
356
|
+
writeSource(file, updated);
|
|
357
|
+
let problem = null;
|
|
358
|
+
let config = null;
|
|
359
|
+
try {
|
|
360
|
+
config = await loadConfig(file);
|
|
361
|
+
problem = verify(config);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
problem = error instanceof CliError || error instanceof Error ? error.message : String(error);
|
|
364
|
+
}
|
|
365
|
+
if (problem || !config) {
|
|
366
|
+
writeSource(file, original);
|
|
367
|
+
fail("CONFIG_WRITE", `Couldn't update ${basename(file)}: ${problem ?? "it did not load"}. The file is back as it was.`, "Make the change by hand in the config, then run npx splithub doctor.");
|
|
368
|
+
}
|
|
369
|
+
return config;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export {
|
|
373
|
+
loadConfig,
|
|
374
|
+
hasExperiment,
|
|
375
|
+
insertExperiment,
|
|
376
|
+
setExperimentStatus,
|
|
377
|
+
removeExperiment,
|
|
378
|
+
setTopLevel,
|
|
379
|
+
ensureLayer,
|
|
380
|
+
readSource,
|
|
381
|
+
writeConfigChecked
|
|
382
|
+
};
|
|
383
|
+
//# sourceMappingURL=chunk-3VY5CP3E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config-file.ts"],"sourcesContent":["import { isSplitHubConfig, type ExperimentKind, type ExperimentStatus, type SplitHubConfig } from '@splithub/core';\nimport { readFileSync, writeFileSync } from 'node:fs';\nimport { basename } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { CliError, fail } from './errors';\n\n/** Load splithub.config.ts (TypeScript or JS) through jiti. CONFIG_PARSE when it does not load. */\nexport async function loadConfig(file: string): Promise<SplitHubConfig> {\n let mod: unknown;\n try {\n const { createJiti } = await import('jiti');\n const jiti = createJiti(pathToFileURL(file).href, { fsCache: false, moduleCache: false });\n mod = await jiti.import(file, { default: true });\n } catch (error) {\n fail('CONFIG_PARSE', `${basename(file)} doesn't load: ${error instanceof Error ? error.message.split('\\n')[0] : String(error)}`, 'Fix the error in the file, then run npx splithub doctor.');\n }\n if (!isSplitHubConfig(mod)) {\n fail('CONFIG_PARSE', `${basename(file)} must \\`export default defineConfig({...})\\` from @splithub/core.`);\n }\n return mod;\n}\n\n// ---------------------------------------------------------------------------\n// Source scanning. Edits work on a \"masked\" copy of the file where string\n// contents, template literals, regex literals and comments are blanked out\n// (same length, newlines kept), so braces and quotes inside them never count.\n// ---------------------------------------------------------------------------\n\nconst REGEX_BEFORE = new Set(['', '(', ',', '=', ':', '[', '!', '&', '|', '?', '{', '}', ';', '+', '-', '*', '%', '<', '>', '~', '^']);\n\n/** Copy of `source` with strings (contents), templates, regexes and comments blanked. */\nexport function maskSource(source: string): string {\n const out = source.split('');\n const blank = (from: number, to: number) => {\n for (let j = from; j < to && j < out.length; j++) if (out[j] !== '\\n' && out[j] !== '\\r') out[j] = ' ';\n };\n let lastCode = '';\n let i = 0;\n while (i < source.length) {\n const ch = source[i]!;\n const next = source[i + 1];\n if (ch === '/' && next === '/') {\n const end = source.indexOf('\\n', i);\n const stop = end < 0 ? source.length : end;\n blank(i, stop);\n i = stop;\n continue;\n }\n if (ch === '/' && next === '*') {\n const end = source.indexOf('*/', i + 2);\n const stop = end < 0 ? source.length : end + 2;\n blank(i, stop);\n i = stop;\n continue;\n }\n if (ch === \"'\" || ch === '\"') {\n let j = i + 1;\n while (j < source.length && source[j] !== ch && source[j] !== '\\n') j += source[j] === '\\\\' ? 2 : 1;\n blank(i + 1, j);\n i = j + 1;\n lastCode = ch;\n continue;\n }\n if (ch === '`') {\n let j = i + 1;\n let depth = 0;\n while (j < source.length) {\n const c = source[j]!;\n if (c === '\\\\') {\n j += 2;\n continue;\n }\n if (depth === 0 && c === '`') break;\n if (c === '$' && source[j + 1] === '{') {\n depth++;\n j += 2;\n continue;\n }\n if (depth > 0 && c === '{') depth++;\n else if (depth > 0 && c === '}') depth--;\n j++;\n }\n blank(i + 1, j);\n i = j + 1;\n lastCode = '`';\n continue;\n }\n if (ch === '/' && REGEX_BEFORE.has(lastCode)) {\n let j = i + 1;\n let inClass = false;\n while (j < source.length && source[j] !== '\\n') {\n const c = source[j]!;\n if (c === '\\\\') {\n j += 2;\n continue;\n }\n if (c === '[') inClass = true;\n else if (c === ']') inClass = false;\n else if (c === '/' && !inClass) break;\n j++;\n }\n blank(i + 1, j);\n i = j + 1;\n lastCode = '/';\n continue;\n }\n if (!/\\s/.test(ch)) lastCode = /[\\w$)\\]]/.test(ch) ? 'x' : ch;\n i++;\n }\n return out.join('');\n}\n\n/** Index of the bracket closing the one at `open` in masked text, or null. */\nfunction matchingClose(masked: string, open: number): number | null {\n let depth = 0;\n for (let i = open; i < masked.length; i++) {\n const ch = masked[i]!;\n if (ch === '{' || ch === '(' || ch === '[') depth++;\n else if (ch === '}' || ch === ')' || ch === ']') {\n depth--;\n if (depth === 0) return i;\n }\n }\n return null;\n}\n\nexport interface Entry {\n /** Property name; null for spreads and computed keys. */\n key: string | null;\n /** object: `key: { ... }` · expr: any other value (identifier, call, shorthand) · spread: `...x` · computed: `[k]: v`. */\n kind: 'object' | 'expr' | 'spread' | 'computed';\n start: number;\n valueStart: number;\n /** Exclusive end of the value (trailing whitespace excluded). */\n valueEnd: number;\n /** After the trailing comma when there is one, else `valueEnd`. */\n end: number;\n}\n\n/** Top-level properties of the object literal between `open` and `close` (its braces). */\nexport function objectEntries(source: string, masked: string, open: number, close: number): Entry[] {\n const entries: Entry[] = [];\n let i = open + 1;\n const ws = () => {\n while (i < close && /[\\s,]/.test(masked[i]!)) i++;\n };\n // A value runs to the next comma at depth 0 (or the closing brace).\n const valueTo = (from: number): number => {\n let j = from;\n while (j < close) {\n const ch = masked[j]!;\n if (ch === ',') break;\n if (ch === '{' || ch === '(' || ch === '[') {\n const m = matchingClose(masked, j);\n j = m === null ? close : m + 1;\n continue;\n }\n j++;\n }\n return j;\n };\n for (;;) {\n ws();\n if (i >= close) break;\n const start = i;\n let key: string | null = null;\n let kind: Entry['kind'] = 'expr';\n if (masked.startsWith('...', i)) {\n kind = 'spread';\n i += 3;\n } else {\n const ch = masked[i]!;\n if (ch === \"'\" || ch === '\"') {\n const end = masked.indexOf(ch, i + 1);\n key = source.slice(i + 1, end).replace(/\\\\(.)/g, '$1');\n i = end + 1;\n } else if (ch === '[') {\n kind = 'computed';\n const m = matchingClose(masked, i);\n i = m === null ? close : m + 1;\n } else {\n const m = /^[\\w$-]+/.exec(masked.slice(i, close));\n if (!m) break;\n key = m[0];\n i += m[0].length;\n }\n while (i < close && /\\s/.test(masked[i]!)) i++;\n if (masked[i] === ':') i++;\n }\n while (i < close && /\\s/.test(masked[i]!)) i++;\n const valueStart = i;\n const stop = valueTo(i);\n let valueEnd = stop;\n while (valueEnd > valueStart && /\\s/.test(masked[valueEnd - 1]!)) valueEnd--;\n if (kind === 'expr' && masked[valueStart] === '{' && matchingClose(masked, valueStart) === valueEnd - 1) kind = 'object';\n const end = masked[stop] === ',' ? stop + 1 : valueEnd;\n entries.push({ key, kind, start, valueStart, valueEnd, end });\n i = stop;\n }\n return entries;\n}\n\ninterface Located {\n masked: string;\n open: number;\n close: number;\n entries: Entry[];\n}\n\n/** The `experiments: { ... }` object of the config, with its entries. */\nfunction locateExperiments(source: string): Located {\n const masked = maskSource(source);\n let open = -1;\n // Prefer the object passed to defineConfig({ ... }) / export default { ... }.\n const root = /defineConfig\\s*\\(\\s*\\{|export\\s+default\\s+\\{/.exec(masked);\n if (root) {\n const rootOpen = root.index + root[0].length - 1;\n const rootClose = matchingClose(masked, rootOpen);\n if (rootClose !== null) {\n const exp = objectEntries(source, masked, rootOpen, rootClose).find((e) => e.key === 'experiments');\n if (exp && exp.kind !== 'object') {\n fail('CONFIG_UNSAFE', '`experiments` in the config is not written inline, so the CLI cannot edit it safely.', 'Edit the experiments where they are defined, or write them inline as experiments: { ... }.');\n }\n if (exp) open = exp.valueStart;\n }\n }\n if (open < 0) {\n const m = /\\bexperiments\\s*:\\s*\\{/.exec(masked);\n if (!m) fail('CONFIG_UNSAFE', \"Couldn't find `experiments: {` in the config file.\", 'Add experiments: {} to defineConfig({...}) and retry.');\n open = m.index + m[0].length - 1;\n }\n const close = matchingClose(masked, open);\n if (close === null) fail('CONFIG_PARSE', 'The braces after `experiments: {` are not balanced.');\n return { masked, open, close, entries: objectEntries(source, masked, open, close) };\n}\n\nfunction unsafeHint(key: string): string {\n return `Edit \"${key}\" where it is defined (it comes from a spread or an imported constant), then run npx splithub doctor.`;\n}\n\n/** The literal `key: { ... }` entry of an experiment. Throws when it can't be edited safely. */\nfunction experimentEntry(source: string, key: string): Located & { entry: Entry } {\n const loc = locateExperiments(source);\n const entry = loc.entries.find((e) => e.key === key);\n if (!entry) {\n if (loc.entries.some((e) => e.kind === 'spread' || e.kind === 'computed')) {\n fail('CONFIG_UNSAFE', `\"${key}\" isn't written inline in the config (the experiments use a spread), so the CLI can't edit it safely.`, unsafeHint(key));\n }\n fail('EXPERIMENT_NOT_FOUND', `There's no experiment \"${key}\" in the config.`, 'See the ids with npx splithub status.');\n }\n return { ...loc, entry };\n}\n\nexport function hasExperiment(source: string, key: string): boolean {\n try {\n return locateExperiments(source).entries.some((e) => e.key === key);\n } catch {\n return false;\n }\n}\n\n/** Indentation of the line holding `index`. */\nfunction indentAt(source: string, index: number): string {\n const lineStart = source.lastIndexOf('\\n', index - 1) + 1;\n return /^[ \\t]*/.exec(source.slice(lineStart))?.[0] ?? '';\n}\n\n/**\n * Append `render(indent)` as the last property of the object `open..close`,\n * adding the comma the previous property may be missing.\n */\nfunction appendProperty(source: string, masked: string, open: number, close: number, render: (indent: string) => string): string {\n const outerIndent = indentAt(source, open);\n const indent = outerIndent + ' ';\n let last = close - 1;\n while (last > open && /\\s/.test(masked[last]!)) last--;\n const needsComma = last > open && masked[last] !== ',';\n const lineStart = source.lastIndexOf('\\n', close - 1) + 1;\n const closeOnOwnLine = source.slice(lineStart, close).trim() === '';\n const block = `${indent}${render(indent)},\\n`;\n const at = closeOnOwnLine && lineStart > last ? lineStart : close;\n const text = at === close ? `\\n${block}${outerIndent}` : block;\n const comma = needsComma ? ',' : '';\n // Inline object (`{ a: 1 }`): the whitespace before `}` gives way to the new line.\n const head = at === close ? source.slice(0, last + 1) + comma : source.slice(0, last + 1) + comma + source.slice(last + 1, at);\n return head + text + source.slice(at);\n}\n\nexport interface NewExperiment {\n key: string;\n kind: ExperimentKind;\n status: ExperimentStatus;\n variants: Array<{ key: string; weight: number; value?: string; to?: string }>;\n /** Multivariate: factor → level → value; the variants are derived and not written. */\n factors?: Record<string, Record<string, string>>;\n goal?: string;\n match?: string;\n description?: string;\n /** Targeting graph from the dashboard, written verbatim as JSON. */\n flow?: unknown;\n traffic?: number;\n maxExposures?: number;\n /** Days before a verdict (0..30); absent means the default of 1. */\n minDays?: number;\n schedule?: { startAt?: string | null; endAt?: string | null };\n /** Secondary goals to watch, and guardrails that must not get worse. */\n metrics?: { secondary?: string[]; guardrails?: Array<string | { goal: string; worse: 'lower' | 'higher' }> };\n /** Mutual exclusion layer and its bucket range [start, end). */\n layer?: { key: string; range: [number, number] };\n}\n\n/** Single-quoted string literal. */\nfunction q(s: string): string {\n return `'${s.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\").replace(/\\n/g, '\\\\n')}'`;\n}\n\n/** Object key: bare when it is a valid identifier, quoted otherwise. */\nfunction k(s: string): string {\n return /^[a-z_$][\\w$]*$/i.test(s) ? s : q(s);\n}\n\n/** Render an experiment entry. Every line after the first carries its own indentation. */\nexport function renderExperiment(e: NewExperiment, indent = ' '): string {\n const i2 = indent + ' ';\n const i3 = i2 + ' ';\n const lines: string[] = [`${k(e.key)}: {`];\n lines.push(`${i2}kind: ${q(e.kind)},`);\n lines.push(`${i2}status: ${q(e.status)},`);\n if (e.match) lines.push(`${i2}match: ${q(e.match)},`);\n if (e.kind === 'mvt') {\n lines.push(`${i2}factors: {`);\n for (const [factor, levels] of Object.entries(e.factors ?? {})) {\n lines.push(`${i3}${k(factor)}: { ${Object.entries(levels).map(([l, v]) => `${k(l)}: ${q(v)}`).join(', ')} },`);\n }\n lines.push(`${i2}},`);\n } else if (e.kind === 'component') {\n lines.push(`${i2}variants: { ${e.variants.map((v) => `${k(v.key)}: ${v.weight}`).join(', ')} },`);\n } else {\n lines.push(`${i2}variants: {`);\n for (const v of e.variants) {\n const extra = e.kind === 'value' ? `value: ${q(v.value ?? '')}` : `to: ${q(v.to ?? '/')}`;\n lines.push(`${i3}${k(v.key)}: { weight: ${v.weight}, ${extra} },`);\n }\n lines.push(`${i2}},`);\n }\n if (e.goal) lines.push(`${i2}goal: ${q(e.goal)},`);\n if (e.traffic !== undefined && e.traffic !== 1) lines.push(`${i2}traffic: ${e.traffic},`);\n if (e.maxExposures) lines.push(`${i2}maxExposures: ${e.maxExposures},`);\n if (e.minDays !== undefined) lines.push(`${i2}minDays: ${e.minDays},`);\n if (e.schedule && (e.schedule.startAt || e.schedule.endAt)) lines.push(`${i2}schedule: { ${[e.schedule.startAt ? `startAt: ${q(e.schedule.startAt)}` : null, e.schedule.endAt ? `endAt: ${q(e.schedule.endAt)}` : null].filter(Boolean).join(', ')} },`);\n if (e.metrics && (e.metrics.secondary?.length || e.metrics.guardrails?.length)) {\n const parts: string[] = [];\n if (e.metrics.secondary?.length) parts.push(`secondary: [${e.metrics.secondary.map(q).join(', ')}]`);\n if (e.metrics.guardrails?.length) parts.push(`guardrails: [${e.metrics.guardrails.map((g) => (typeof g === 'string' ? q(g) : `{ goal: ${q(g.goal)}, worse: ${q(g.worse)} }`)).join(', ')}]`);\n lines.push(`${i2}metrics: { ${parts.join(', ')} },`);\n }\n if (e.layer) lines.push(`${i2}layer: { key: ${q(e.layer.key)}, range: [${e.layer.range[0]}, ${e.layer.range[1]}] },`);\n if (e.description) lines.push(`${i2}description: ${q(e.description)},`);\n if (e.flow) {\n const json = JSON.stringify(e.flow, null, 2).split('\\n');\n lines.push(`${i2}// targeting graph from the dashboard; edit it there or by hand\\n${i2}flow: ${json.map((l, n) => (n === 0 ? l : i2 + l)).join('\\n')},`);\n }\n lines.push(`${indent}}`);\n return lines.join('\\n');\n}\n\n/** Append a new experiment at the end of the `experiments: { ... }` object. */\nexport function insertExperiment(source: string, e: NewExperiment): string {\n const { masked, open, close, entries } = locateExperiments(source);\n if (entries.some((x) => x.key === e.key)) fail('EXPERIMENT_EXISTS', `There's already an experiment \"${e.key}\".`, 'Pick another id: an old id keeps its history.');\n return appendProperty(source, masked, open, close, (indent) => renderExperiment(e, indent));\n}\n\nexport function setExperimentStatus(source: string, key: string, status: ExperimentStatus): string {\n const { masked, entry } = experimentEntry(source, key);\n if (entry.kind !== 'object') fail('CONFIG_UNSAFE', `\"${key}\" points to a value defined elsewhere, so the CLI can't edit it safely.`, unsafeHint(key));\n const inner = objectEntries(source, masked, entry.valueStart, entry.valueEnd - 1);\n const field = inner.filter((x) => x.key === 'status').pop();\n if (field) {\n const raw = masked.slice(field.valueStart, field.valueEnd);\n if (!/^(['\"])\\s*\\1$/.test(raw)) fail('CONFIG_UNSAFE', `The status of \"${key}\" isn't a plain string, so the CLI can't change it safely.`, `Set status: '${status}' by hand.`);\n const quote = raw[0]!;\n return source.slice(0, field.valueStart) + `${quote}${status}${quote}` + source.slice(field.valueEnd);\n }\n // No status written (or only through a spread): append one, so it wins over any spread.\n return appendProperty(source, masked, entry.valueStart, entry.valueEnd - 1, () => `status: ${q(status)}`);\n}\n\n/** Remove an experiment's entry (and its line) from the config source. */\nexport function removeExperiment(source: string, key: string): string {\n return removeEntry(source, experimentEntry(source, key).entry);\n}\n\n/** Remove a property, its whole line when it stands alone. */\nfunction removeEntry(source: string, entry: Entry): string {\n const lineStart = source.lastIndexOf('\\n', entry.start - 1) + 1;\n const from = source.slice(lineStart, entry.start).trim() === '' ? lineStart : entry.start;\n let to = entry.end;\n const lineEnd = source.indexOf('\\n', to);\n const rest = source.slice(to, lineEnd < 0 ? source.length : lineEnd);\n if (rest.trim() === '' && from === lineStart) to = lineEnd < 0 ? source.length : lineEnd + 1;\n return source.slice(0, from) + source.slice(to);\n}\n\n/** The object passed to defineConfig({ ... }) / export default { ... }. */\nfunction locateRoot(source: string): Located {\n const masked = maskSource(source);\n const root = /defineConfig\\s*\\(\\s*\\{|export\\s+default\\s+\\{/.exec(masked);\n if (!root) fail('CONFIG_UNSAFE', \"Couldn't find defineConfig({ ... }) in the config file.\", 'Make the change by hand in splithub.config.ts.');\n const open = root.index + root[0].length - 1;\n const close = matchingClose(masked, open);\n if (close === null) fail('CONFIG_PARSE', 'The braces of defineConfig({ ... }) are not balanced.');\n return { masked, open, close, entries: objectEntries(source, masked, open, close) };\n}\n\n/** Set a top-level config property (`holdout: { ... }`), replacing it when it is there. */\nexport function setTopLevel(source: string, name: string, valueText: string | null): string {\n const { masked, open, close, entries } = locateRoot(source);\n const entry = entries.find((e) => e.key === name);\n if (valueText === null) return entry ? removeEntry(source, entry) : source;\n if (entry) return source.slice(0, entry.valueStart) + valueText + source.slice(entry.valueEnd);\n return appendProperty(source, masked, open, close, () => `${k(name)}: ${valueText}`);\n}\n\n/** Make sure `layers: { <key>: {} }` declares a layer. */\nexport function ensureLayer(source: string, key: string): string {\n const { masked, open, close, entries } = locateRoot(source);\n const layers = entries.find((e) => e.key === 'layers');\n if (!layers) return appendProperty(source, masked, open, close, () => `layers: { ${k(key)}: {} }`);\n if (layers.kind !== 'object') fail('CONFIG_UNSAFE', '`layers` in the config is not written inline.', `Add ${key}: {} to layers by hand.`);\n if (objectEntries(source, masked, layers.valueStart, layers.valueEnd - 1).some((e) => e.key === key)) return source;\n return appendProperty(source, masked, layers.valueStart, layers.valueEnd - 1, () => `${k(key)}: {}`);\n}\n\nexport function readSource(file: string): string {\n return readFileSync(file, 'utf8');\n}\n\nexport function writeSource(file: string, source: string): void {\n writeFileSync(file, source, 'utf8');\n}\n\n/**\n * Write the config, load it back and check the change landed. On any problem the\n * original file is restored and CONFIG_WRITE is thrown: the CLI never leaves a broken config.\n */\nexport async function writeConfigChecked(file: string, original: string, updated: string, verify: (config: SplitHubConfig) => string | null): Promise<SplitHubConfig> {\n writeSource(file, updated);\n let problem: string | null = null;\n let config: SplitHubConfig | null = null;\n try {\n config = await loadConfig(file);\n problem = verify(config);\n } catch (error) {\n problem = error instanceof CliError || error instanceof Error ? error.message : String(error);\n }\n if (problem || !config) {\n writeSource(file, original);\n fail('CONFIG_WRITE', `Couldn't update ${basename(file)}: ${problem ?? 'it did not load'}. The file is back as it was.`, 'Make the change by hand in the config, then run npx splithub doctor.');\n }\n return config;\n}\n"],"mappings":";;;;;;;AAAA,SAAS,wBAAyF;AAClG,SAAS,cAAc,qBAAqB;AAC5C,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAI9B,eAAsB,WAAW,MAAuC;AACtE,MAAI;AACJ,MAAI;AACF,UAAM,EAAE,WAAW,IAAI,MAAM,OAAO,MAAM;AAC1C,UAAM,OAAO,WAAW,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,MAAM,WAAW,IAAI;AAC9B,cAAU,OAAO,MAAM;AAAA,EACzB,SAAS,OAAO;AACd,cAAU,iBAAiB,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,EAC9F;AACA,MAAI,WAAW,CAAC,QAAQ;AACtB,gBAAY,MAAM,QAAQ;AAC1B,SAAK,gBAAgB,mBAAmB,SAAS,IAAI,CAAC,KAAK,WAAW,iBAAiB,iCAAiC,sEAAsE;AAAA,EAChM;AACA,SAAO;AACT;","names":["end"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
fetchStatus,
|
|
4
|
+
resolveTarget
|
|
5
|
+
} from "./chunk-EUF75FUC.js";
|
|
6
|
+
import {
|
|
7
|
+
detectProject
|
|
8
|
+
} from "./chunk-PLXDG4B5.js";
|
|
9
|
+
import {
|
|
10
|
+
bar,
|
|
11
|
+
c,
|
|
12
|
+
printJson,
|
|
13
|
+
statusColor,
|
|
14
|
+
table,
|
|
15
|
+
verdictColor,
|
|
16
|
+
verdictIcon
|
|
17
|
+
} from "./chunk-V3DLUVOE.js";
|
|
18
|
+
|
|
19
|
+
// src/commands/status.ts
|
|
20
|
+
async function status(flags) {
|
|
21
|
+
const target = resolveTarget(flags, detectProject());
|
|
22
|
+
const data = await fetchStatus(target);
|
|
23
|
+
const finished = data.experiments.filter((e) => e.status === "finished").map((e) => e.experiment);
|
|
24
|
+
const next = finished.length ? `Finished but still in the code: ${finished.join(", ")}. Decide which variant to keep, then run npx splithub ship <id> --keep <variant> (agents: the splithub-ship skill).` : null;
|
|
25
|
+
if (flags.json) {
|
|
26
|
+
printJson(next ? { ...data, next } : data);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
console.log(`${c.bold("SplitHub")} ${c.dim("\xB7")} project ${c.cyan(data.project)} ${c.dim(`\xB7 ${target.url}`)}
|
|
30
|
+
`);
|
|
31
|
+
if (data.experiments.length === 0) {
|
|
32
|
+
console.log(c.dim("No experiments in splithub.config.ts yet. Run `splithub create`."));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const maxVisitors = Math.max(1, ...data.experiments.map((e) => e.visitors));
|
|
36
|
+
console.log(
|
|
37
|
+
table(
|
|
38
|
+
["EXPERIMENT", "KIND", "STATUS", "VISITORS", "", "DAYS", "VERDICT", "NEXT CHECK"],
|
|
39
|
+
data.experiments.map((e) => [
|
|
40
|
+
e.experiment === "__holdout" ? c.bold("Holdout: long-term impact") : c.bold(e.experiment),
|
|
41
|
+
e.kind,
|
|
42
|
+
statusColor(e.status),
|
|
43
|
+
String(e.visitors),
|
|
44
|
+
bar(e.visitors, maxVisitors, 12, e.status === "running" ? c.green : c.dim),
|
|
45
|
+
e.days ? String(e.days) : "\u2013",
|
|
46
|
+
verdictColor(e.verdict, `${verdictIcon(e.goal ? e.verdict : null)} ${e.headline ?? (e.goal ? "no data" : "no goal")}`),
|
|
47
|
+
e.status === "running" && e.daysToVerdict && e.daysToVerdict > 0 ? c.dim(`in ~${Math.ceil(e.daysToVerdict)}d`) : ""
|
|
48
|
+
])
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
if (next) console.log(`
|
|
52
|
+
${c.dim(next)}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
status
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=chunk-74NI7BED.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/status.ts"],"sourcesContent":["import { fetchStatus, resolveTarget } from '../api';\nimport { detectProject } from '../project';\nimport { printJson } from '../errors';\nimport { bar, c, statusColor, table, verdictColor, verdictIcon } from '../ui';\n\nexport async function status(flags: Record<string, unknown>): Promise<void> {\n const target = resolveTarget(flags, detectProject());\n const data = await fetchStatus(target);\n const finished = data.experiments.filter((e) => e.status === 'finished').map((e) => e.experiment);\n const next = finished.length ? `Finished but still in the code: ${finished.join(', ')}. Decide which variant to keep, then run npx splithub ship <id> --keep <variant> (agents: the splithub-ship skill).` : null;\n if (flags.json) {\n printJson(next ? { ...data, next } : data);\n return;\n }\n console.log(`${c.bold('SplitHub')} ${c.dim('·')} project ${c.cyan(data.project)} ${c.dim(`· ${target.url}`)}\\n`);\n if (data.experiments.length === 0) {\n console.log(c.dim('No experiments in splithub.config.ts yet. Run `splithub create`.'));\n return;\n }\n // Visitors as a bar relative to the busiest experiment, verdict with its icon.\n const maxVisitors = Math.max(1, ...data.experiments.map((e) => e.visitors));\n console.log(\n table(\n ['EXPERIMENT', 'KIND', 'STATUS', 'VISITORS', '', 'DAYS', 'VERDICT', 'NEXT CHECK'],\n data.experiments.map((e) => [\n e.experiment === '__holdout' ? c.bold('Holdout: long-term impact') : c.bold(e.experiment),\n e.kind,\n statusColor(e.status),\n String(e.visitors),\n bar(e.visitors, maxVisitors, 12, e.status === 'running' ? c.green : c.dim),\n e.days ? String(e.days) : '–',\n verdictColor(e.verdict, `${verdictIcon(e.goal ? e.verdict : null)} ${e.headline ?? (e.goal ? 'no data' : 'no goal')}`),\n e.status === 'running' && e.daysToVerdict && e.daysToVerdict > 0 ? c.dim(`in ~${Math.ceil(e.daysToVerdict)}d`) : '',\n ])\n )\n );\n if (next) console.log(`\\n${c.dim(next)}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,eAAsB,OAAO,OAA+C;AAC1E,QAAM,SAAS,cAAc,OAAO,cAAc,CAAC;AACnD,QAAM,OAAO,MAAM,YAAY,MAAM;AACrC,QAAM,WAAW,KAAK,YAAY,OAAO,CAAC,MAAM,EAAE,WAAW,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU;AAChG,QAAM,OAAO,SAAS,SAAS,mCAAmC,SAAS,KAAK,IAAI,CAAC,wHAAwH;AAC7M,MAAI,MAAM,MAAM;AACd,cAAU,OAAO,EAAE,GAAG,MAAM,KAAK,IAAI,IAAI;AACzC;AAAA,EACF;AACA,UAAQ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