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,184 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
hasExperiment,
|
|
4
|
+
insertExperiment,
|
|
5
|
+
loadConfig,
|
|
6
|
+
readSource,
|
|
7
|
+
writeConfigChecked
|
|
8
|
+
} from "./chunk-3VY5CP3E.js";
|
|
9
|
+
import {
|
|
10
|
+
apiError,
|
|
11
|
+
cloudTarget,
|
|
12
|
+
requireCloudToken
|
|
13
|
+
} from "./chunk-EUF75FUC.js";
|
|
14
|
+
import {
|
|
15
|
+
detectProject,
|
|
16
|
+
requireConfig
|
|
17
|
+
} from "./chunk-PLXDG4B5.js";
|
|
18
|
+
import {
|
|
19
|
+
c,
|
|
20
|
+
fail,
|
|
21
|
+
printJson
|
|
22
|
+
} from "./chunk-V3DLUVOE.js";
|
|
23
|
+
|
|
24
|
+
// src/commands/push.ts
|
|
25
|
+
import { relative } from "path";
|
|
26
|
+
function factorsOf(e) {
|
|
27
|
+
const out = {};
|
|
28
|
+
for (const f of e.factors ?? []) {
|
|
29
|
+
out[f.key] = {};
|
|
30
|
+
for (const level of f.levels) {
|
|
31
|
+
const combo = e.variants.find((v) => v.levels?.[f.key] === level);
|
|
32
|
+
const value = combo?.value?.[f.key];
|
|
33
|
+
out[f.key][level] = typeof value === "string" ? value : value === void 0 ? level : JSON.stringify(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
async function adoptCloudExperiments(file, cloudOnly) {
|
|
39
|
+
if (!cloudOnly || cloudOnly.length === 0) return [];
|
|
40
|
+
const original = readSource(file);
|
|
41
|
+
let source = original;
|
|
42
|
+
const written = [];
|
|
43
|
+
for (const e of cloudOnly) {
|
|
44
|
+
if (hasExperiment(source, e.key)) continue;
|
|
45
|
+
const total = e.variants.reduce((s, v) => s + v.weight, 0) || 1;
|
|
46
|
+
source = insertExperiment(source, {
|
|
47
|
+
key: e.key,
|
|
48
|
+
kind: e.kind,
|
|
49
|
+
status: e.status,
|
|
50
|
+
goal: e.goal ?? void 0,
|
|
51
|
+
match: e.match ?? void 0,
|
|
52
|
+
description: e.description ?? void 0,
|
|
53
|
+
flow: e.flow ?? void 0,
|
|
54
|
+
traffic: e.traffic,
|
|
55
|
+
maxExposures: e.maxExposures ?? void 0,
|
|
56
|
+
minDays: e.minDays ?? void 0,
|
|
57
|
+
schedule: e.schedule ?? void 0,
|
|
58
|
+
variants: e.variants.map((v) => ({ key: v.key, weight: Math.round(v.weight / total * 100), value: typeof v.value === "string" ? v.value : v.value === void 0 ? void 0 : JSON.stringify(v.value), to: v.to })),
|
|
59
|
+
...e.kind === "mvt" && e.factors ? { factors: factorsOf(e) } : {}
|
|
60
|
+
});
|
|
61
|
+
written.push(e.key);
|
|
62
|
+
}
|
|
63
|
+
if (written.length) {
|
|
64
|
+
await writeConfigChecked(file, original, source, (config) => {
|
|
65
|
+
const missing = written.filter((k) => !config.experiments.some((x) => x.key === k));
|
|
66
|
+
return missing.length ? `${missing.join(", ")} did not load back` : null;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return written;
|
|
70
|
+
}
|
|
71
|
+
function configDiff(local, cloud) {
|
|
72
|
+
const added = local.filter((e) => !cloud.some((x) => x.key === e.key)).map((e) => e.key);
|
|
73
|
+
const removed = cloud.filter((x) => x.origin !== "dashboard" && !local.some((e) => e.key === x.key)).map((x) => x.key);
|
|
74
|
+
const changed = [];
|
|
75
|
+
for (const e of local) {
|
|
76
|
+
const x = cloud.find((y) => y.key === e.key);
|
|
77
|
+
if (!x) continue;
|
|
78
|
+
const fields = [];
|
|
79
|
+
if (x.status !== e.status) fields.push("status");
|
|
80
|
+
if ((x.goal ?? null) !== (e.goal ?? null)) fields.push("goal");
|
|
81
|
+
if (x.kind !== e.kind) fields.push("kind");
|
|
82
|
+
if (x.variants.map((v) => `${v.key}:${v.weight}`).join() !== e.variants.map((v) => `${v.key}:${v.weight}`).join()) fields.push("variants");
|
|
83
|
+
if ((x.traffic ?? 1) !== (e.traffic ?? 1)) fields.push("traffic");
|
|
84
|
+
if (fields.length) changed.push({ experiment: e.key, fields });
|
|
85
|
+
}
|
|
86
|
+
return { added, removed, changed };
|
|
87
|
+
}
|
|
88
|
+
async function cloudFetch(url, init) {
|
|
89
|
+
try {
|
|
90
|
+
return await fetch(url, init);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
fail("UNREACHABLE", `Can't reach ${url}: ${error instanceof Error ? error.message : String(error)}.`, "Check your connection, or --api / SPLITHUB_API.");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function push(flags) {
|
|
96
|
+
const project = requireConfig();
|
|
97
|
+
const config = await loadConfig(project.configFile);
|
|
98
|
+
if (flags["dry-run"]) return dryRun(flags, config);
|
|
99
|
+
if (config.storage.mode !== "cloud") {
|
|
100
|
+
fail("NOT_CLOUD", `This project stores events itself (storage.mode is "${config.storage.mode}"), so there's nothing to push.`, "Set storage: { mode: 'cloud' } in splithub.config.ts to use SplitHub Cloud.");
|
|
101
|
+
}
|
|
102
|
+
const target = requireCloudToken(flags);
|
|
103
|
+
const res = await cloudFetch(`${target.url}/config`, {
|
|
104
|
+
method: "PUT",
|
|
105
|
+
headers: { authorization: `Bearer ${target.token}`, "content-type": "application/json" },
|
|
106
|
+
body: JSON.stringify({ config })
|
|
107
|
+
});
|
|
108
|
+
const body = await res.json().catch(() => ({}));
|
|
109
|
+
if (!res.ok) throw apiError(res.status, body, `${target.url}/config responded ${res.status}`);
|
|
110
|
+
let keyWritten = false;
|
|
111
|
+
if (body.publicKey && !config.storage.key) {
|
|
112
|
+
const source = readSource(project.configFile);
|
|
113
|
+
const updated = source.replace(/(mode\s*:\s*['"]cloud['"]\s*)(,?)(\s*\})/, (_m, a, _comma, b) => `${a}, key: '${body.publicKey}'${b}`);
|
|
114
|
+
if (updated !== source) {
|
|
115
|
+
await writeConfigChecked(project.configFile, source, updated, (loaded) => loaded.storage.mode === "cloud" && loaded.storage.key === body.publicKey ? null : "storage.key did not load back");
|
|
116
|
+
keyWritten = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const adopted = await adoptCloudExperiments(project.configFile, body.cloudOnly);
|
|
120
|
+
const out = { ...body, configFile: relative(project.root, project.configFile), keyWritten, adopted };
|
|
121
|
+
if (flags.json) {
|
|
122
|
+
printJson(out);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
console.log(`${c.green("\u2714")} pushed ${c.bold(String(body.project))} v${body.version} \xB7 ${body.experiments} experiment(s) \u2192 ${target.url}`);
|
|
126
|
+
if (adopted.length) console.log(`${c.green("\u2714")} written into ${out.configFile} from the dashboard: ${adopted.join(", ")} (wire them in code if they are value/component experiments)`);
|
|
127
|
+
if (body.publicKey) {
|
|
128
|
+
console.log(keyWritten ? `${c.green("\u2714")} public key written to ${out.configFile}` : `${c.dim("public key:")} ${body.publicKey}`);
|
|
129
|
+
if (!keyWritten && !config.storage.key) console.log(c.yellow(`Add it to splithub.config.ts: storage: { mode: 'cloud', key: '${body.publicKey}' }`));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function dryRun(flags, config) {
|
|
133
|
+
const experiments = config.experiments.map((e) => ({ experiment: e.key, kind: e.kind, status: e.status, goal: e.goal ?? null }));
|
|
134
|
+
let diff = null;
|
|
135
|
+
let cloud = config.storage.mode === "cloud" ? "not connected" : "self mode";
|
|
136
|
+
if (config.storage.mode === "cloud") {
|
|
137
|
+
const target = cloudTarget(flags);
|
|
138
|
+
if (target.token) {
|
|
139
|
+
const res = await cloudFetch(`${target.url}/config`, { headers: { authorization: `Bearer ${target.token}` } });
|
|
140
|
+
const body = await res.json().catch(() => ({}));
|
|
141
|
+
if (res.status === 404 || res.status === 409) diff = configDiff(config.experiments, []);
|
|
142
|
+
else if (!res.ok) throw apiError(res.status, body, `${target.url}/config responded ${res.status}`);
|
|
143
|
+
else diff = configDiff(config.experiments, body.config?.experiments ?? []);
|
|
144
|
+
cloud = "compared";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const out = { ok: true, dryRun: true, mode: config.storage.mode, project: config.project, experiments, cloud, diff };
|
|
148
|
+
if (flags.json) {
|
|
149
|
+
printJson(out);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
console.log(`${c.green("\u2714")} config loads \xB7 ${experiments.length} experiment(s) \xB7 ${config.storage.mode} mode`);
|
|
153
|
+
if (!diff) console.log(c.dim(cloud === "self mode" ? "Self mode: nothing to push." : "Not connected, so nothing to compare. Run npx splithub login."));
|
|
154
|
+
else if (!diff.added.length && !diff.removed.length && !diff.changed.length) console.log(c.dim("The cloud already has this config."));
|
|
155
|
+
else {
|
|
156
|
+
for (const k of diff.added) console.log(`${c.green("+")} ${k}`);
|
|
157
|
+
for (const k of diff.removed) console.log(`${c.red("-")} ${k}`);
|
|
158
|
+
for (const ch of diff.changed) console.log(`${c.yellow("~")} ${ch.experiment} ${c.dim(`(${ch.fields.join(", ")})`)}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function pull(flags) {
|
|
162
|
+
const target = requireCloudToken(flags);
|
|
163
|
+
const res = await cloudFetch(`${target.url}/config`, { headers: { authorization: `Bearer ${target.token}` } });
|
|
164
|
+
const body = await res.json().catch(() => ({}));
|
|
165
|
+
if (!res.ok) throw apiError(res.status, body, `${target.url}/config responded ${res.status}`);
|
|
166
|
+
const project = detectProject();
|
|
167
|
+
const dashboardOnes = (body.config?.experiments ?? []).filter((e) => e.origin === "dashboard");
|
|
168
|
+
const adopted = project.configFile ? await adoptCloudExperiments(project.configFile, dashboardOnes) : [];
|
|
169
|
+
if (flags.json) {
|
|
170
|
+
printJson({ ...body, adopted });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
console.log(`${c.bold("cloud config")} v${body.version} ${c.dim(`pushed ${body.pushedAt}`)} \xB7 public key ${body.publicKey}`);
|
|
174
|
+
if (adopted.length) console.log(`${c.green("\u2714")} written into ${relative(project.root, project.configFile ?? "")}: ${adopted.join(", ")}`);
|
|
175
|
+
else if (dashboardOnes.length) console.log(c.dim(`dashboard experiments already present locally: ${dashboardOnes.map((e) => e.key).join(", ")}`));
|
|
176
|
+
else console.log(c.dim("no dashboard-created experiments to pull"));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
configDiff,
|
|
181
|
+
push,
|
|
182
|
+
pull
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=chunk-A2RCSPG6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/push.ts"],"sourcesContent":["import type { SplitHubConfig } from '@splithub/core';\nimport { relative } from 'node:path';\nimport { apiError, cloudTarget, requireCloudToken } from '../api';\nimport { hasExperiment, insertExperiment, loadConfig, readSource, writeConfigChecked } from '../config-file';\nimport { fail, printJson } from '../errors';\nimport { detectProject, requireConfig } from '../project';\nimport { c } from '../ui';\nimport type { Flags } from './init';\n\ninterface CloudExperiment {\n key: string;\n kind: 'component' | 'value' | 'redirect' | 'mvt';\n status: 'draft' | 'running' | 'paused' | 'finished';\n goal: string | null;\n match: string | null;\n description: string | null;\n variants: Array<{ key: string; weight: number; value?: unknown; to?: string; levels?: Record<string, string> }>;\n /** Multivariate: the factors whose combinations the variants are. */\n factors?: Array<{ key: string; levels: string[] }>;\n flow?: unknown;\n traffic?: number;\n maxExposures?: number | null;\n minDays?: number | null;\n schedule?: { startAt?: string | null; endAt?: string | null } | null;\n}\n\ninterface PushResponse {\n ok: boolean;\n project: string;\n version: number;\n pushedAt: string;\n publicKey: string;\n experiments: number;\n /** Experiments created in the dashboard that the local file does not have yet. */\n cloudOnly?: CloudExperiment[];\n}\n\n/** Write dashboard-created experiments into the local config file. Returns the keys written. */\n/** Factor → level → value, read back from the combinations the cloud generated. */\nfunction factorsOf(e: CloudExperiment): Record<string, Record<string, string>> {\n const out: Record<string, Record<string, string>> = {};\n for (const f of e.factors ?? []) {\n out[f.key] = {};\n for (const level of f.levels) {\n const combo = e.variants.find((v) => v.levels?.[f.key] === level);\n const value = (combo?.value as Record<string, unknown> | undefined)?.[f.key];\n out[f.key]![level] = typeof value === 'string' ? value : value === undefined ? level : JSON.stringify(value);\n }\n }\n return out;\n}\n\nasync function adoptCloudExperiments(file: string, cloudOnly: CloudExperiment[] | undefined): Promise<string[]> {\n if (!cloudOnly || cloudOnly.length === 0) return [];\n const original = readSource(file);\n let source = original;\n const written: string[] = [];\n for (const e of cloudOnly) {\n if (hasExperiment(source, e.key)) continue;\n const total = e.variants.reduce((s, v) => s + v.weight, 0) || 1;\n source = insertExperiment(source, {\n key: e.key,\n kind: e.kind,\n status: e.status,\n goal: e.goal ?? undefined,\n match: e.match ?? undefined,\n description: e.description ?? undefined,\n flow: e.flow ?? undefined,\n traffic: e.traffic,\n maxExposures: e.maxExposures ?? undefined,\n minDays: e.minDays ?? undefined,\n schedule: e.schedule ?? undefined,\n variants: e.variants.map((v) => ({ key: v.key, weight: Math.round((v.weight / total) * 100), value: typeof v.value === 'string' ? v.value : v.value === undefined ? undefined : JSON.stringify(v.value), to: v.to })),\n ...(e.kind === 'mvt' && e.factors ? { factors: factorsOf(e) } : {}),\n });\n written.push(e.key);\n }\n if (written.length) {\n await writeConfigChecked(file, original, source, (config) => {\n const missing = written.filter((k) => !config.experiments.some((x) => x.key === k));\n return missing.length ? `${missing.join(', ')} did not load back` : null;\n });\n }\n return written;\n}\n\ntype LocalExperiment = SplitHubConfig['experiments'][number];\n\nexport interface ConfigDiff {\n added: string[];\n removed: string[];\n changed: Array<{ experiment: string; fields: string[] }>;\n}\n\n/** What a push would change in the cloud, by experiment key. */\nexport function configDiff(local: LocalExperiment[], cloud: Array<CloudExperiment & { origin?: string }>): ConfigDiff {\n const added = local.filter((e) => !cloud.some((x) => x.key === e.key)).map((e) => e.key);\n const removed = cloud.filter((x) => x.origin !== 'dashboard' && !local.some((e) => e.key === x.key)).map((x) => x.key);\n const changed: ConfigDiff['changed'] = [];\n for (const e of local) {\n const x = cloud.find((y) => y.key === e.key);\n if (!x) continue;\n const fields: string[] = [];\n if (x.status !== e.status) fields.push('status');\n if ((x.goal ?? null) !== (e.goal ?? null)) fields.push('goal');\n if (x.kind !== e.kind) fields.push('kind');\n if (x.variants.map((v) => `${v.key}:${v.weight}`).join() !== e.variants.map((v) => `${v.key}:${v.weight}`).join()) fields.push('variants');\n if ((x.traffic ?? 1) !== (e.traffic ?? 1)) fields.push('traffic');\n if (fields.length) changed.push({ experiment: e.key, fields });\n }\n return { added, removed, changed };\n}\n\nasync function cloudFetch(url: string, init: RequestInit): Promise<Response> {\n try {\n return await fetch(url, init);\n } catch (error) {\n fail('UNREACHABLE', `Can't reach ${url}: ${error instanceof Error ? error.message : String(error)}.`, 'Check your connection, or --api / SPLITHUB_API.');\n }\n}\n\n/**\n * `splithub push`: upload the normalized splithub.config.ts to SplitHub Cloud.\n * Needs a project API key (sk_...) via --token or SPLITHUB_API_KEY. The first\n * push returns the public key (pk_...) which is written into the config's\n * `storage.key` when it is still empty. `--dry-run` only checks and compares.\n */\nexport async function push(flags: Flags): Promise<void> {\n const project = requireConfig();\n const config = await loadConfig(project.configFile);\n if (flags['dry-run']) return dryRun(flags, config);\n if (config.storage.mode !== 'cloud') {\n fail('NOT_CLOUD', `This project stores events itself (storage.mode is \"${config.storage.mode}\"), so there's nothing to push.`, \"Set storage: { mode: 'cloud' } in splithub.config.ts to use SplitHub Cloud.\");\n }\n const target = requireCloudToken(flags);\n\n const res = await cloudFetch(`${target.url}/config`, {\n method: 'PUT',\n headers: { authorization: `Bearer ${target.token}`, 'content-type': 'application/json' },\n body: JSON.stringify({ config }),\n });\n const body = (await res.json().catch(() => ({}))) as Partial<PushResponse> & { error?: string };\n if (!res.ok) throw apiError(res.status, body, `${target.url}/config responded ${res.status}`);\n\n // Write the public key into the config when it is missing.\n let keyWritten = false;\n if (body.publicKey && !config.storage.key) {\n const source = readSource(project.configFile);\n const updated = source.replace(/(mode\\s*:\\s*['\"]cloud['\"]\\s*)(,?)(\\s*\\})/, (_m, a: string, _comma: string, b: string) => `${a}, key: '${body.publicKey}'${b}`);\n if (updated !== source) {\n await writeConfigChecked(project.configFile, source, updated, (loaded) => (loaded.storage.mode === 'cloud' && loaded.storage.key === body.publicKey ? null : 'storage.key did not load back'));\n keyWritten = true;\n }\n }\n\n const adopted = await adoptCloudExperiments(project.configFile, body.cloudOnly);\n const out = { ...body, configFile: relative(project.root, project.configFile), keyWritten, adopted };\n if (flags.json) {\n printJson(out);\n return;\n }\n console.log(`${c.green('✔')} pushed ${c.bold(String(body.project))} v${body.version} · ${body.experiments} experiment(s) → ${target.url}`);\n if (adopted.length) console.log(`${c.green('✔')} written into ${out.configFile} from the dashboard: ${adopted.join(', ')} (wire them in code if they are value/component experiments)`);\n if (body.publicKey) {\n console.log(keyWritten ? `${c.green('✔')} public key written to ${out.configFile}` : `${c.dim('public key:')} ${body.publicKey}`);\n if (!keyWritten && !config.storage.key) console.log(c.yellow(`Add it to splithub.config.ts: storage: { mode: 'cloud', key: '${body.publicKey}' }`));\n }\n}\n\n/** `push --dry-run`: the config loads; when connected, what a push would change. Writes nothing. */\nasync function dryRun(flags: Flags, config: SplitHubConfig): Promise<void> {\n const experiments = config.experiments.map((e) => ({ experiment: e.key, kind: e.kind, status: e.status, goal: e.goal ?? null }));\n let diff: ConfigDiff | null = null;\n let cloud: 'compared' | 'not connected' | 'self mode' = config.storage.mode === 'cloud' ? 'not connected' : 'self mode';\n if (config.storage.mode === 'cloud') {\n const target = cloudTarget(flags);\n if (target.token) {\n const res = await cloudFetch(`${target.url}/config`, { headers: { authorization: `Bearer ${target.token}` } });\n const body = (await res.json().catch(() => ({}))) as { config?: { experiments?: CloudExperiment[] } };\n if (res.status === 404 || res.status === 409) diff = configDiff(config.experiments, []);\n else if (!res.ok) throw apiError(res.status, body, `${target.url}/config responded ${res.status}`);\n else diff = configDiff(config.experiments, body.config?.experiments ?? []);\n cloud = 'compared';\n }\n }\n const out = { ok: true, dryRun: true, mode: config.storage.mode, project: config.project, experiments, cloud, diff };\n if (flags.json) {\n printJson(out);\n return;\n }\n console.log(`${c.green('✔')} config loads · ${experiments.length} experiment(s) · ${config.storage.mode} mode`);\n if (!diff) console.log(c.dim(cloud === 'self mode' ? 'Self mode: nothing to push.' : 'Not connected, so nothing to compare. Run npx splithub login.'));\n else if (!diff.added.length && !diff.removed.length && !diff.changed.length) console.log(c.dim('The cloud already has this config.'));\n else {\n for (const k of diff.added) console.log(`${c.green('+')} ${k}`);\n for (const k of diff.removed) console.log(`${c.red('-')} ${k}`);\n for (const ch of diff.changed) console.log(`${c.yellow('~')} ${ch.experiment} ${c.dim(`(${ch.fields.join(', ')})`)}`);\n }\n}\n\n/** `splithub pull`: print the config stored in the cloud (for inspection or recovery). */\nexport async function pull(flags: Flags): Promise<void> {\n const target = requireCloudToken(flags);\n const res = await cloudFetch(`${target.url}/config`, { headers: { authorization: `Bearer ${target.token}` } });\n const body = (await res.json().catch(() => ({}))) as { error?: string; config?: { experiments?: Array<CloudExperiment & { origin?: string }> }; version?: number; pushedAt?: string; publicKey?: string };\n if (!res.ok) throw apiError(res.status, body, `${target.url}/config responded ${res.status}`);\n const project = detectProject();\n const dashboardOnes = (body.config?.experiments ?? []).filter((e) => e.origin === 'dashboard');\n const adopted = project.configFile ? await adoptCloudExperiments(project.configFile, dashboardOnes) : [];\n if (flags.json) {\n printJson({ ...body, adopted });\n return;\n }\n console.log(`${c.bold('cloud config')} v${body.version} ${c.dim(`pushed ${body.pushedAt}`)} · public key ${body.publicKey}`);\n if (adopted.length) console.log(`${c.green('✔')} written into ${relative(project.root, project.configFile ?? '')}: ${adopted.join(', ')}`);\n else if (dashboardOnes.length) console.log(c.dim(`dashboard experiments already present locally: ${dashboardOnes.map((e) => e.key).join(', ')}`));\n else console.log(c.dim('no dashboard-created experiments to pull'));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,gBAAgB;AAsCzB,SAAS,UAAU,GAA4D;AAC7E,QAAM,MAA8C,CAAC;AACrD,aAAW,KAA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EAAE,MAAM,QAAG,CAAC,iBAAiB,SAAS,QAAQ,MAAM,QAAQ,cAAc,EAAE,CAAC,KAAK,QAAQ,KAAK,IAAI,CAAC,EAAE;AAAA,WAChI,cAAc,OAAQ,SAAQ,IAAI,EAAE,IAAI,kDAAkD,cAAc,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;AAAA,MAC3I,SAAQ,IAAI,EAAE,IAAI,0CAA0C,CAAC;AACpE;","names":[]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
AGENTS_SECTION,
|
|
4
|
+
CURSOR_RULE,
|
|
5
|
+
MCP_SERVER_ENTRY,
|
|
6
|
+
SKILLS
|
|
7
|
+
} from "./chunk-3DUWIEHB.js";
|
|
8
|
+
import {
|
|
9
|
+
detectProject
|
|
10
|
+
} from "./chunk-PLXDG4B5.js";
|
|
11
|
+
import {
|
|
12
|
+
c
|
|
13
|
+
} from "./chunk-V3DLUVOE.js";
|
|
14
|
+
|
|
15
|
+
// src/commands/skills.ts
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
17
|
+
import { dirname, join, relative } from "path";
|
|
18
|
+
function writeFile(file, content, force, out) {
|
|
19
|
+
if (existsSync(file) && !force) {
|
|
20
|
+
const current = readFileSync(file, "utf8");
|
|
21
|
+
if (current === content) {
|
|
22
|
+
out.skipped.push(file);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!/SplitHub|splithub/.test(current)) {
|
|
26
|
+
out.skipped.push(file);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
31
|
+
writeFileSync(file, content, "utf8");
|
|
32
|
+
out.written.push(file);
|
|
33
|
+
}
|
|
34
|
+
function registerMcp(file, out) {
|
|
35
|
+
let json = {};
|
|
36
|
+
if (existsSync(file)) {
|
|
37
|
+
try {
|
|
38
|
+
json = JSON.parse(readFileSync(file, "utf8"));
|
|
39
|
+
} catch {
|
|
40
|
+
out.skipped.push(`${file} (not valid JSON, left untouched)`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const servers = json.mcpServers ?? {};
|
|
45
|
+
if (JSON.stringify(servers.splithub) === JSON.stringify(MCP_SERVER_ENTRY)) {
|
|
46
|
+
out.skipped.push(file);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
json.mcpServers = { ...servers, splithub: MCP_SERVER_ENTRY };
|
|
50
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
51
|
+
writeFileSync(file, JSON.stringify(json, null, 2) + "\n", "utf8");
|
|
52
|
+
out.mcp.push(file);
|
|
53
|
+
}
|
|
54
|
+
function installSkills(root, options = {}) {
|
|
55
|
+
const out = { written: [], skipped: [], mcp: [] };
|
|
56
|
+
for (const s of SKILLS) writeFile(join(root, ".claude", "skills", s.dir, "SKILL.md"), s.body, Boolean(options.force), out);
|
|
57
|
+
writeFile(join(root, ".cursor", "rules", "splithub.mdc"), CURSOR_RULE, Boolean(options.force), out);
|
|
58
|
+
const agentsFile = ["AGENTS.md", "CLAUDE.md"].map((f) => join(root, f)).find((f) => existsSync(f)) ?? join(root, "AGENTS.md");
|
|
59
|
+
if (!existsSync(agentsFile)) {
|
|
60
|
+
writeFileSync(agentsFile, `# ${detectProject(root).name}
|
|
61
|
+
${AGENTS_SECTION}`, "utf8");
|
|
62
|
+
out.written.push(agentsFile);
|
|
63
|
+
} else if (!/SplitHub/.test(readFileSync(agentsFile, "utf8"))) {
|
|
64
|
+
writeFileSync(agentsFile, readFileSync(agentsFile, "utf8") + `
|
|
65
|
+
${AGENTS_SECTION}`, "utf8");
|
|
66
|
+
out.written.push(`${agentsFile} (section appended)`);
|
|
67
|
+
} else {
|
|
68
|
+
out.skipped.push(agentsFile);
|
|
69
|
+
}
|
|
70
|
+
if (options.mcp) {
|
|
71
|
+
registerMcp(join(root, ".mcp.json"), out);
|
|
72
|
+
registerMcp(join(root, ".cursor", "mcp.json"), out);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
async function skills(flags) {
|
|
77
|
+
const project = detectProject();
|
|
78
|
+
const result = installSkills(project.root, { mcp: Boolean(flags.mcp), force: Boolean(flags.force) });
|
|
79
|
+
if (flags.json) {
|
|
80
|
+
console.log(JSON.stringify(result));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const rel = (f) => relative(project.root, f) || f;
|
|
84
|
+
if (result.written.length) console.log(`${c.green("\u2714")} wrote
|
|
85
|
+
${result.written.map(rel).join("\n ")}`);
|
|
86
|
+
if (result.mcp.length) console.log(`${c.green("\u2714")} MCP server registered in
|
|
87
|
+
${result.mcp.map(rel).join("\n ")}`);
|
|
88
|
+
if (result.skipped.length) console.log(c.dim(`unchanged: ${result.skipped.map(rel).join(", ")}`));
|
|
89
|
+
if (!flags.mcp) console.log(c.dim(`add --mcp to register the SplitHub MCP server (Claude Code .mcp.json, Cursor .cursor/mcp.json; Codex and Copilot read AGENTS.md)`));
|
|
90
|
+
console.log(c.dim("skills: splithub (library + CLI), ab-testing (how to test well), splithub-api (HTTP API), splithub-mcp (MCP tools), splithub-self-hosted (your own database), splithub-ship (keep the winner, remove the test), splithub-loop (the whole loop, tool by tool)"));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
installSkills,
|
|
95
|
+
skills
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=chunk-AJO3C4BS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/skills.ts"],"sourcesContent":["// `splithub skills [--mcp] [--force]`: install or refresh the agent skills in\n// this project (.claude/skills/<name>/SKILL.md, .cursor/rules/splithub.mdc,\n// an AGENTS.md section) and, with --mcp, register the SplitHub MCP server in\n// .mcp.json (Claude Code) and .cursor/mcp.json (Cursor). `init` calls this too.\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\nimport { detectProject } from '../project';\nimport { AGENTS_SECTION, CURSOR_RULE } from '../templates';\nimport { MCP_SERVER_ENTRY, SKILLS } from '../skills';\nimport { c } from '../ui';\nimport type { Flags } from './init';\n\nexport interface SkillsResult {\n written: string[];\n skipped: string[];\n mcp: string[];\n}\n\nfunction writeFile(file: string, content: string, force: boolean, out: SkillsResult): void {\n if (existsSync(file) && !force) {\n const current = readFileSync(file, 'utf8');\n if (current === content) {\n out.skipped.push(file);\n return;\n }\n // Skills we wrote earlier get refreshed; a user-edited file is left alone unless --force.\n if (!/SplitHub|splithub/.test(current)) {\n out.skipped.push(file);\n return;\n }\n }\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, content, 'utf8');\n out.written.push(file);\n}\n\n/** Merge our server into an MCP config file ({ mcpServers: {...} }) without touching other entries. */\nfunction registerMcp(file: string, out: SkillsResult): void {\n let json: { mcpServers?: Record<string, unknown> } = {};\n if (existsSync(file)) {\n try {\n json = JSON.parse(readFileSync(file, 'utf8')) as typeof json;\n } catch {\n out.skipped.push(`${file} (not valid JSON, left untouched)`);\n return;\n }\n }\n const servers = json.mcpServers ?? {};\n if (JSON.stringify(servers.splithub) === JSON.stringify(MCP_SERVER_ENTRY)) {\n out.skipped.push(file);\n return;\n }\n json.mcpServers = { ...servers, splithub: MCP_SERVER_ENTRY };\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, JSON.stringify(json, null, 2) + '\\n', 'utf8');\n out.mcp.push(file);\n}\n\nexport function installSkills(root: string, options: { mcp?: boolean; force?: boolean } = {}): SkillsResult {\n const out: SkillsResult = { written: [], skipped: [], mcp: [] };\n for (const s of SKILLS) writeFile(join(root, '.claude', 'skills', s.dir, 'SKILL.md'), s.body, Boolean(options.force), out);\n writeFile(join(root, '.cursor', 'rules', 'splithub.mdc'), CURSOR_RULE, Boolean(options.force), out);\n\n const agentsFile = ['AGENTS.md', 'CLAUDE.md'].map((f) => join(root, f)).find((f) => existsSync(f)) ?? join(root, 'AGENTS.md');\n if (!existsSync(agentsFile)) {\n writeFileSync(agentsFile, `# ${detectProject(root).name}\\n${AGENTS_SECTION}`, 'utf8');\n out.written.push(agentsFile);\n } else if (!/SplitHub/.test(readFileSync(agentsFile, 'utf8'))) {\n writeFileSync(agentsFile, readFileSync(agentsFile, 'utf8') + `\\n${AGENTS_SECTION}`, 'utf8');\n out.written.push(`${agentsFile} (section appended)`);\n } else {\n out.skipped.push(agentsFile);\n }\n\n if (options.mcp) {\n registerMcp(join(root, '.mcp.json'), out);\n registerMcp(join(root, '.cursor', 'mcp.json'), out);\n }\n return out;\n}\n\nexport async function skills(flags: Flags): Promise<void> {\n const project = detectProject();\n const result = installSkills(project.root, { mcp: Boolean(flags.mcp), force: Boolean(flags.force) });\n if (flags.json) {\n console.log(JSON.stringify(result));\n return;\n }\n const rel = (f: string) => relative(project.root, f) || f;\n if (result.written.length) console.log(`${c.green('✔')} wrote\\n ${result.written.map(rel).join('\\n ')}`);\n if (result.mcp.length) console.log(`${c.green('✔')} MCP server registered in\\n ${result.mcp.map(rel).join('\\n ')}`);\n if (result.skipped.length) console.log(c.dim(`unchanged: ${result.skipped.map(rel).join(', ')}`));\n if (!flags.mcp) console.log(c.dim(`add --mcp to register the SplitHub MCP server (Claude Code .mcp.json, Cursor .cursor/mcp.json; Codex and Copilot read AGENTS.md)`));\n console.log(c.dim('skills: splithub (library + CLI), ab-testing (how to test well), splithub-api (HTTP API), splithub-mcp (MCP tools), splithub-self-hosted (your own database), splithub-ship (keep the winner, remove the test), splithub-loop (the whole loop, tool by tool)'));\n}\n"],"mappings":";;;;;;;;;;;;;;;AAIA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,MAAM,gBAAgB;AAaxC,SAAS,UAAU,MAAc,SAAiB,OAAgB,KAAyB;AACzF,MAAI,WAAW,IAAI,KAA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AQ,SAAQ,IAAI,GAAG,EAAE,MAAM,QAAG,CAAC;AAAA,IAAgC,OAAO,IAAI,IAAI,GAAG,EAAE,KAAK,MAAM,CAAC,EAAE;AACpH,MAAI,OAAO,QAAQ,OAAQ,SAAQ,IAAI,EAAE,IAAI,cAAc,OAAO,QAAQ,IAAI,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;AAChG,MAAI,CAAC,MAAM,IAAK,SAAQ,IAAI,EAAE,IAAI,kIAAkI,CAAC;AACrK,UAAQ,IAAI,EAAE,IAAI,8PAA8P,CAAC;AACnR;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
loadConfig,
|
|
4
|
+
readSource,
|
|
5
|
+
setExperimentStatus,
|
|
6
|
+
writeConfigChecked
|
|
7
|
+
} from "./chunk-3VY5CP3E.js";
|
|
8
|
+
import {
|
|
9
|
+
applyLiveStatus
|
|
10
|
+
} from "./chunk-EUF75FUC.js";
|
|
11
|
+
import {
|
|
12
|
+
requireConfig
|
|
13
|
+
} from "./chunk-PLXDG4B5.js";
|
|
14
|
+
import {
|
|
15
|
+
c,
|
|
16
|
+
fail,
|
|
17
|
+
printJson
|
|
18
|
+
} from "./chunk-V3DLUVOE.js";
|
|
19
|
+
|
|
20
|
+
// src/commands/lifecycle.ts
|
|
21
|
+
import { relative } from "path";
|
|
22
|
+
var MAP = { start: "running", pause: "paused", finish: "finished" };
|
|
23
|
+
async function lifecycle(command, id, flags) {
|
|
24
|
+
const status = MAP[command];
|
|
25
|
+
if (!status) fail("USAGE", `Unknown command "${command}".`);
|
|
26
|
+
if (!id) fail("USAGE", `Which experiment? npx splithub ${command} <id>`);
|
|
27
|
+
const project = requireConfig();
|
|
28
|
+
const file = relative(project.root, project.configFile);
|
|
29
|
+
const before = await loadConfig(project.configFile);
|
|
30
|
+
const current = before.experiments.find((e) => e.key === id);
|
|
31
|
+
if (!current) fail("EXPERIMENT_NOT_FOUND", `There's no experiment "${id}" in ${file}.`, "See the ids with npx splithub status.");
|
|
32
|
+
if (current.status !== status) {
|
|
33
|
+
const original = readSource(project.configFile);
|
|
34
|
+
const updated = setExperimentStatus(original, id, status);
|
|
35
|
+
await writeConfigChecked(project.configFile, original, updated, (config) => {
|
|
36
|
+
const e = config.experiments.find((x) => x.key === id);
|
|
37
|
+
return !e ? `"${id}" disappeared` : e.status !== status ? `"${id}" is still ${e.status}` : null;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const live = before.storage.mode === "cloud" ? await applyLiveStatus(flags, id, status) : "skipped";
|
|
41
|
+
const next = status === "finished" ? `Read the verdict (npx splithub results ${id}), decide which variant to keep, then run npx splithub ship ${id} --keep <variant> to remove the test from the code and the config.` : null;
|
|
42
|
+
if (flags.json) printJson({ experiment: id, status, previous: current.status, configFile: file, live, ...next ? { next } : {} });
|
|
43
|
+
else {
|
|
44
|
+
console.log(`${c.green("\u2714")} ${c.bold(id)} \u2192 ${status} ${c.dim(`(${file})`)}`);
|
|
45
|
+
if (live === "applied") console.log(`${c.green("\u2714")} live in the cloud within 60s, no deploy needed (the config change ships with your next deploy)`);
|
|
46
|
+
else if (live !== "skipped") console.log(c.yellow(`! ${live}`));
|
|
47
|
+
if (next) console.log(c.dim(`Next: ${next}`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
lifecycle
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=chunk-C5S7RPYM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/lifecycle.ts"],"sourcesContent":["import type { ExperimentStatus } from '@splithub/core';\nimport { relative } from 'node:path';\nimport { applyLiveStatus } from '../api';\nimport { loadConfig, readSource, setExperimentStatus, writeConfigChecked } from '../config-file';\nimport { fail, printJson } from '../errors';\nimport { requireConfig } from '../project';\nimport { c } from '../ui';\nimport type { Flags } from './init';\n\nconst MAP: Record<string, ExperimentStatus> = { start: 'running', pause: 'paused', finish: 'finished' };\n\nexport async function lifecycle(command: string, id: string | undefined, flags: Flags): Promise<void> {\n const status = MAP[command];\n if (!status) fail('USAGE', `Unknown command \"${command}\".`);\n if (!id) fail('USAGE', `Which experiment? npx splithub ${command} <id>`);\n const project = requireConfig();\n const file = relative(project.root, project.configFile);\n\n // Validate before touching the file: the config must load and know the experiment.\n const before = await loadConfig(project.configFile);\n const current = before.experiments.find((e) => e.key === id);\n if (!current) fail('EXPERIMENT_NOT_FOUND', `There's no experiment \"${id}\" in ${file}.`, 'See the ids with npx splithub status.');\n\n if (current.status !== status) {\n const original = readSource(project.configFile);\n const updated = setExperimentStatus(original, id, status);\n await writeConfigChecked(project.configFile, original, updated, (config) => {\n const e = config.experiments.find((x) => x.key === id);\n return !e ? `\"${id}\" disappeared` : e.status !== status ? `\"${id}\" is still ${e.status}` : null;\n });\n }\n\n // Cloud mode: also apply it live through a remote override, so no deploy is needed.\n const live = before.storage.mode === 'cloud' ? await applyLiveStatus(flags, id, status) : 'skipped';\n\n // A finished test keeps its numbers, but every variant is still in the code until someone decides.\n const next = status === 'finished' ? `Read the verdict (npx splithub results ${id}), decide which variant to keep, then run npx splithub ship ${id} --keep <variant> to remove the test from the code and the config.` : null;\n if (flags.json) printJson({ experiment: id, status, previous: current.status, configFile: file, live, ...(next ? { next } : {}) });\n else {\n console.log(`${c.green('✔')} ${c.bold(id)} → ${status} ${c.dim(`(${file})`)}`);\n if (live === 'applied') console.log(`${c.green('✔')} live in the cloud within 60s, no deploy needed (the config change ships with your next deploy)`);\n else if (live !== 'skipped') console.log(c.yellow(`! ${live}`));\n if (next) console.log(c.dim(`Next: ${next}`));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,SAAS,gBAAgB;AAQzB,IAAM,MAAwC,EAAE,OAAO,WAAW,OAAO,UAAU,QAAQ,WAAW;AAEtG,eAAsB,UAAU,SAAiB,IAAwB,OAA6B;AACpG,QAAM,SAA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AAS,UAAW,SAAQ,IAAI,GAAG,EAAE,MAAM,QAAG,CAAC,iGAAiG;AAAA,aAC3I,SAAS,UAAW,SAAQ,IAAI,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;AAC9D,QAAI,KAAM,SAAQ,IAAI,EAAE,IAAI,SAAS,IAAI,EAAE,CAAC;AAAA,EAC9C;AACF;","names":[]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CliError,
|
|
4
|
+
fail
|
|
5
|
+
} from "./chunk-V3DLUVOE.js";
|
|
6
|
+
|
|
7
|
+
// src/credentials.ts
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
import { join, resolve } from "path";
|
|
11
|
+
function credentialsFile() {
|
|
12
|
+
const base = process.env.XDG_CONFIG_HOME || (process.platform === "win32" ? process.env.APPDATA || join(homedir(), "AppData", "Roaming") : join(homedir(), ".config"));
|
|
13
|
+
return join(base, "splithub", "credentials.json");
|
|
14
|
+
}
|
|
15
|
+
function read() {
|
|
16
|
+
const file = credentialsFile();
|
|
17
|
+
if (!existsSync(file)) return {};
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function loadCredential(api, root = process.cwd()) {
|
|
25
|
+
return read()[api]?.[resolve(root)] ?? null;
|
|
26
|
+
}
|
|
27
|
+
function saveCredential(api, root, cred) {
|
|
28
|
+
const file = credentialsFile();
|
|
29
|
+
const store = read();
|
|
30
|
+
store[api] = { ...store[api] ?? {}, [resolve(root)]: cred };
|
|
31
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
32
|
+
writeFileSync(file, JSON.stringify(store, null, 2) + "\n", { mode: 384 });
|
|
33
|
+
return file;
|
|
34
|
+
}
|
|
35
|
+
function listCredentials(api) {
|
|
36
|
+
const store = read();
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const [a, dirs] of Object.entries(store)) {
|
|
39
|
+
if (api && a !== api) continue;
|
|
40
|
+
for (const [root, cred] of Object.entries(dirs)) out.push({ api: a, root, cred });
|
|
41
|
+
}
|
|
42
|
+
return out.sort((x, y) => y.cred.savedAt.localeCompare(x.cred.savedAt));
|
|
43
|
+
}
|
|
44
|
+
function removeCredential(api, root = process.cwd()) {
|
|
45
|
+
const store = read();
|
|
46
|
+
const key = resolve(root);
|
|
47
|
+
if (!store[api]?.[key]) return false;
|
|
48
|
+
delete store[api][key];
|
|
49
|
+
writeFileSync(credentialsFile(), JSON.stringify(store, null, 2) + "\n", { mode: 384 });
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/api.ts
|
|
54
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
55
|
+
var CLOUD_API = "https://go.splithub.io/v1";
|
|
56
|
+
function storageFromConfig(project) {
|
|
57
|
+
const fallback = { mode: "self", endpoint: "/api/splithub" };
|
|
58
|
+
if (!project?.configFile) return fallback;
|
|
59
|
+
try {
|
|
60
|
+
const src = readFileSync2(project.configFile, "utf8");
|
|
61
|
+
const mode = /mode\s*:\s*['"](cloud|self)['"]/.exec(src)?.[1];
|
|
62
|
+
const endpoint = /endpoint\s*:\s*['"]([^'"]+)['"]/.exec(src)?.[1];
|
|
63
|
+
return { mode: mode ?? "self", endpoint: endpoint ?? "/api/splithub" };
|
|
64
|
+
} catch {
|
|
65
|
+
return fallback;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function cloudTarget(flags) {
|
|
69
|
+
const url = typeof flags.api === "string" && flags.api || process.env.SPLITHUB_API || CLOUD_API;
|
|
70
|
+
const base = url.replace(/\/+$/, "");
|
|
71
|
+
const token = typeof flags.token === "string" && flags.token || process.env.SPLITHUB_API_KEY || loadCredential(base)?.apiKey || void 0;
|
|
72
|
+
return { url: base, token };
|
|
73
|
+
}
|
|
74
|
+
function resolveTarget(flags, project) {
|
|
75
|
+
const explicit = typeof flags.url === "string" && flags.url || process.env.SPLITHUB_URL;
|
|
76
|
+
const storage = storageFromConfig(project);
|
|
77
|
+
if (!explicit && storage.mode === "cloud") return cloudTarget(flags);
|
|
78
|
+
const port = project?.framework === "next" ? 3e3 : 5173;
|
|
79
|
+
const url = explicit || `http://localhost:${port}${storage.endpoint}`;
|
|
80
|
+
const token = typeof flags.token === "string" && flags.token || process.env.SPLITHUB_ADMIN_TOKEN || void 0;
|
|
81
|
+
return { url: url.replace(/\/+$/, ""), token };
|
|
82
|
+
}
|
|
83
|
+
function apiErrorMessage(status, body, fallback) {
|
|
84
|
+
const error = body?.error;
|
|
85
|
+
const text = typeof error === "string" ? error : typeof error?.message === "string" ? error.message : fallback;
|
|
86
|
+
return status === 401 ? `${text} This folder is not signed in: run npx splithub login (or set SPLITHUB_API_KEY).` : text;
|
|
87
|
+
}
|
|
88
|
+
function apiError(status, body, fallback, experiment) {
|
|
89
|
+
const message = apiErrorMessage(status, body, fallback);
|
|
90
|
+
if (status === 401) return new CliError("NOT_LOGGED_IN", message, "Run npx splithub login (or set SPLITHUB_API_KEY), then retry.");
|
|
91
|
+
const b = body;
|
|
92
|
+
if (status === 403 && b?.code === "insufficient_scope") return new CliError("INSUFFICIENT_SCOPE", message, `This API key lacks the "${typeof b.needed === "string" ? b.needed : "write"}" scope. Create one with it in the dashboard (Settings, API keys) or run npx splithub login --yes.`);
|
|
93
|
+
if (status === 404 && experiment) return new CliError("EXPERIMENT_NOT_FOUND", message, `Check the id with npx splithub status. In cloud mode, push the config first.`);
|
|
94
|
+
return new CliError("API_ERROR", message);
|
|
95
|
+
}
|
|
96
|
+
async function request(target, path, init = {}, experiment) {
|
|
97
|
+
const headers = { ...init.headers ?? {} };
|
|
98
|
+
if (target.token) headers.authorization = `Bearer ${target.token}`;
|
|
99
|
+
if (init.body) headers["content-type"] = "application/json";
|
|
100
|
+
let res;
|
|
101
|
+
try {
|
|
102
|
+
res = await fetch(`${target.url}${path}`, { ...init, headers });
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new CliError("UNREACHABLE", `Can't reach ${target.url}: ${error instanceof Error ? error.message : String(error)}.`, "Is your app running? Set --url or SPLITHUB_URL.");
|
|
105
|
+
}
|
|
106
|
+
const body = await res.json().catch(() => ({}));
|
|
107
|
+
if (!res.ok) throw apiError(res.status, body, `${target.url}${path} responded ${res.status}`, experiment);
|
|
108
|
+
return body;
|
|
109
|
+
}
|
|
110
|
+
function requireCloudToken(flags) {
|
|
111
|
+
const target = cloudTarget(flags);
|
|
112
|
+
if (!target.token) fail("NOT_LOGGED_IN", "This folder is not connected to SplitHub Cloud.", "Run npx splithub login, or pass --token sk_... / SPLITHUB_API_KEY.");
|
|
113
|
+
return target;
|
|
114
|
+
}
|
|
115
|
+
function putOverride(target, experiment, body) {
|
|
116
|
+
return request(target, `/overrides/${encodeURIComponent(experiment)}`, { method: "PUT", body: JSON.stringify(body) }, experiment);
|
|
117
|
+
}
|
|
118
|
+
async function applyLiveStatus(flags, experiment, status) {
|
|
119
|
+
const target = cloudTarget(flags);
|
|
120
|
+
if (!target.token) return "no API key (run npx splithub login or set SPLITHUB_API_KEY to apply it without a deploy)";
|
|
121
|
+
try {
|
|
122
|
+
await putOverride(target, experiment, { status });
|
|
123
|
+
return "applied";
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return `cloud refused: ${error instanceof Error ? error.message : String(error)}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function archiveLive(flags, experiment) {
|
|
129
|
+
const target = cloudTarget(flags);
|
|
130
|
+
if (!target.token) return "no API key (run npx splithub login or set SPLITHUB_API_KEY to archive it in the cloud)";
|
|
131
|
+
try {
|
|
132
|
+
await request(target, `/archive/${encodeURIComponent(experiment)}`, { method: "PUT", body: "{}" });
|
|
133
|
+
return "archived";
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof CliError && (error.code === "EXPERIMENT_NOT_FOUND" || error.code === "API_ERROR")) {
|
|
136
|
+
const finished = await applyLiveStatus(flags, experiment, "finished");
|
|
137
|
+
return finished === "applied" ? "finished" : finished;
|
|
138
|
+
}
|
|
139
|
+
return `cloud refused: ${error instanceof Error ? error.message : String(error)}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
var fetchStatus = (t) => request(t, "/status");
|
|
143
|
+
var fetchResults = (t, key) => request(t, `/results/${encodeURIComponent(key)}`, {}, key);
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
credentialsFile,
|
|
147
|
+
loadCredential,
|
|
148
|
+
saveCredential,
|
|
149
|
+
listCredentials,
|
|
150
|
+
removeCredential,
|
|
151
|
+
cloudTarget,
|
|
152
|
+
resolveTarget,
|
|
153
|
+
apiError,
|
|
154
|
+
requireCloudToken,
|
|
155
|
+
applyLiveStatus,
|
|
156
|
+
archiveLive,
|
|
157
|
+
fetchStatus,
|
|
158
|
+
fetchResults
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=chunk-EUF75FUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/credentials.ts","../src/api.ts"],"sourcesContent":["// Credentials saved by `splithub login`: ~/.config/splithub/credentials.json\n// { \"<api base>\": { \"<project root>\": { apiKey, projectId, projectName, savedAt } } }\n// `cloudTarget` falls back to the entry for the current directory when neither\n// --token nor SPLITHUB_API_KEY is set.\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\nexport interface SavedCredential {\n apiKey: string;\n projectId: string | null;\n projectName: string | null;\n /** Public key of the project (pk_...), written into splithub.config.ts by init. */\n publicKey?: string | null;\n savedAt: string;\n}\n\ntype Store = Record<string, Record<string, SavedCredential>>;\n\nexport function credentialsFile(): string {\n const base = process.env.XDG_CONFIG_HOME || (process.platform === 'win32' ? process.env.APPDATA || join(homedir(), 'AppData', 'Roaming') : join(homedir(), '.config'));\n return join(base, 'splithub', 'credentials.json');\n}\n\nfunction read(): Store {\n const file = credentialsFile();\n if (!existsSync(file)) return {};\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as Store;\n } catch {\n return {};\n }\n}\n\nexport function loadCredential(api: string, root = process.cwd()): SavedCredential | null {\n return read()[api]?.[resolve(root)] ?? null;\n}\n\nexport function saveCredential(api: string, root: string, cred: SavedCredential): string {\n const file = credentialsFile();\n const store = read();\n store[api] = { ...(store[api] ?? {}), [resolve(root)]: cred };\n mkdirSync(join(file, '..'), { recursive: true });\n writeFileSync(file, JSON.stringify(store, null, 2) + '\\n', { mode: 0o600 });\n return file;\n}\n\n/** Every saved credential on this machine: which directory is connected to which project. */\nexport function listCredentials(api?: string): Array<{ api: string; root: string; cred: SavedCredential }> {\n const store = read();\n const out: Array<{ api: string; root: string; cred: SavedCredential }> = [];\n for (const [a, dirs] of Object.entries(store)) {\n if (api && a !== api) continue;\n for (const [root, cred] of Object.entries(dirs)) out.push({ api: a, root, cred });\n }\n return out.sort((x, y) => y.cred.savedAt.localeCompare(x.cred.savedAt));\n}\n\nexport function removeCredential(api: string, root = process.cwd()): boolean {\n const store = read();\n const key = resolve(root);\n if (!store[api]?.[key]) return false;\n delete store[api][key];\n writeFileSync(credentialsFile(), JSON.stringify(store, null, 2) + '\\n', { mode: 0o600 });\n return true;\n}\n","import type { ExperimentResults, StatusRow } from '@splithub/node';\nimport { readFileSync } from 'node:fs';\nimport { loadCredential } from './credentials';\nimport { CliError, fail } from './errors';\nimport type { ProjectInfo } from './project';\n\nexport interface Target {\n url: string;\n token?: string;\n}\n\nexport const CLOUD_API = 'https://go.splithub.io/v1';\n\n/** Storage settings from splithub.config.ts, read textually to avoid loading the config. */\nfunction storageFromConfig(project?: ProjectInfo): { mode: 'self' | 'cloud'; endpoint: string } {\n const fallback = { mode: 'self' as const, endpoint: '/api/splithub' };\n if (!project?.configFile) return fallback;\n try {\n const src = readFileSync(project.configFile, 'utf8');\n const mode = /mode\\s*:\\s*['\"](cloud|self)['\"]/.exec(src)?.[1] as 'self' | 'cloud' | undefined;\n const endpoint = /endpoint\\s*:\\s*['\"]([^'\"]+)['\"]/.exec(src)?.[1];\n return { mode: mode ?? 'self', endpoint: endpoint ?? '/api/splithub' };\n } catch {\n return fallback;\n }\n}\n\n/** Cloud API base + project API key (sk_...). */\nexport function cloudTarget(flags: Record<string, unknown>): Target {\n const url = (typeof flags.api === 'string' && flags.api) || process.env.SPLITHUB_API || CLOUD_API;\n const base = url.replace(/\\/+$/, '');\n const token = (typeof flags.token === 'string' && flags.token) || process.env.SPLITHUB_API_KEY || loadCredential(base)?.apiKey || undefined;\n return { url: base, token };\n}\n\n/**\n * Where to read results from:\n * - --url / SPLITHUB_URL always win;\n * - cloud mode → the cloud API with the project API key;\n * - self mode → the local dev server (3000 for Next.js, 5173 for Vite) + the endpoint from the config.\n */\nexport function resolveTarget(flags: Record<string, unknown>, project?: ProjectInfo): Target {\n const explicit = (typeof flags.url === 'string' && flags.url) || process.env.SPLITHUB_URL;\n const storage = storageFromConfig(project);\n if (!explicit && storage.mode === 'cloud') return cloudTarget(flags);\n const port = project?.framework === 'next' ? 3000 : 5173;\n const url = explicit || `http://localhost:${port}${storage.endpoint}`;\n const token = (typeof flags.token === 'string' && flags.token) || process.env.SPLITHUB_ADMIN_TOKEN || undefined;\n return { url: url.replace(/\\/+$/, ''), token };\n}\n\n/**\n * Readable message from an API error body. Most routes answer `{ error: 'text' }`; the auth layer\n * answers `{ success: false, error: { code, message } }`. Without this the CLI printed \"[object Object]\".\n */\nexport function apiErrorMessage(status: number, body: unknown, fallback: string): string {\n const error = (body as { error?: unknown } | null)?.error;\n const text = typeof error === 'string' ? error : typeof (error as { message?: unknown } | undefined)?.message === 'string' ? (error as { message: string }).message : fallback;\n return status === 401 ? `${text} This folder is not signed in: run npx splithub login (or set SPLITHUB_API_KEY).` : text;\n}\n\n/** CliError for a failed API response: 401 → NOT_LOGGED_IN, 404 on an experiment → EXPERIMENT_NOT_FOUND. */\nexport function apiError(status: number, body: unknown, fallback: string, experiment?: string): CliError {\n const message = apiErrorMessage(status, body, fallback);\n if (status === 401) return new CliError('NOT_LOGGED_IN', message, 'Run npx splithub login (or set SPLITHUB_API_KEY), then retry.');\n const b = body as { code?: unknown; needed?: unknown } | null;\n if (status === 403 && b?.code === 'insufficient_scope') return new CliError('INSUFFICIENT_SCOPE', message, `This API key lacks the \"${typeof b.needed === 'string' ? b.needed : 'write'}\" scope. Create one with it in the dashboard (Settings, API keys) or run npx splithub login --yes.`);\n if (status === 404 && experiment) return new CliError('EXPERIMENT_NOT_FOUND', message, `Check the id with npx splithub status. In cloud mode, push the config first.`);\n return new CliError('API_ERROR', message);\n}\n\nasync function request<T>(target: Target, path: string, init: RequestInit = {}, experiment?: string): Promise<T> {\n const headers: Record<string, string> = { ...((init.headers as Record<string, string> | undefined) ?? {}) };\n if (target.token) headers.authorization = `Bearer ${target.token}`;\n if (init.body) headers['content-type'] = 'application/json';\n let res: Response;\n try {\n res = await fetch(`${target.url}${path}`, { ...init, headers });\n } catch (error) {\n throw new CliError('UNREACHABLE', `Can't reach ${target.url}: ${error instanceof Error ? error.message : String(error)}.`, 'Is your app running? Set --url or SPLITHUB_URL.');\n }\n const body: unknown = await res.json().catch(() => ({}));\n if (!res.ok) throw apiError(res.status, body, `${target.url}${path} responded ${res.status}`, experiment);\n return body as T;\n}\n\n/** Cloud target that must carry an API key. */\nexport function requireCloudToken(flags: Record<string, unknown>): Target & { token: string } {\n const target = cloudTarget(flags);\n if (!target.token) fail('NOT_LOGGED_IN', 'This folder is not connected to SplitHub Cloud.', 'Run npx splithub login, or pass --token sk_... / SPLITHUB_API_KEY.');\n return target as Target & { token: string };\n}\n\n/** PUT /overrides/<experiment>: live status, traffic or weights without a deploy. */\nexport function putOverride(target: Target, experiment: string, body: Record<string, unknown>): Promise<unknown> {\n return request<unknown>(target, `/overrides/${encodeURIComponent(experiment)}`, { method: 'PUT', body: JSON.stringify(body) }, experiment);\n}\n\n/**\n * Apply a status live in cloud mode. Never throws: the config file already changed,\n * so a refused or unreachable cloud is reported, not fatal.\n */\nexport async function applyLiveStatus(flags: Record<string, unknown>, experiment: string, status: string): Promise<string> {\n const target = cloudTarget(flags);\n if (!target.token) return 'no API key (run npx splithub login or set SPLITHUB_API_KEY to apply it without a deploy)';\n try {\n await putOverride(target, experiment, { status });\n return 'applied';\n } catch (error) {\n return `cloud refused: ${error instanceof Error ? error.message : String(error)}`;\n }\n}\n\n/** daysToVerdict: days until a verdict at the current traffic; null when unknown (older servers omit it). */\n/**\n * Archive an experiment in the cloud (PUT /archive/<id>): it stops, keeps its numbers and leaves the\n * active list. Older servers without the route get it finished instead. Never throws.\n */\nexport async function archiveLive(flags: Record<string, unknown>, experiment: string): Promise<string> {\n const target = cloudTarget(flags);\n if (!target.token) return 'no API key (run npx splithub login or set SPLITHUB_API_KEY to archive it in the cloud)';\n try {\n await request<unknown>(target, `/archive/${encodeURIComponent(experiment)}`, { method: 'PUT', body: '{}' });\n return 'archived';\n } catch (error) {\n // 404 from a server without the route (or any non-auth refusal): finishing still stops the test.\n if (error instanceof CliError && (error.code === 'EXPERIMENT_NOT_FOUND' || error.code === 'API_ERROR')) {\n const finished = await applyLiveStatus(flags, experiment, 'finished');\n return finished === 'applied' ? 'finished' : finished;\n }\n return `cloud refused: ${error instanceof Error ? error.message : String(error)}`;\n }\n}\n\nexport type ResultsWithPlan = ExperimentResults & { daysToVerdict?: number | null; visitorsPerDay?: number | null };\nexport type StatusRowWithPlan = StatusRow & { daysToVerdict?: number | null };\n\nexport const fetchStatus = (t: Target) => request<{ project: string; experiments: StatusRowWithPlan[] }>(t, '/status');\nexport const fetchResults = (t: Target, key: string) => request<ResultsWithPlan>(t, `/results/${encodeURIComponent(key)}`, {}, key);\n"],"mappings":";;;;;;;AAIA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,eAAe;AACxB,SAAS,MAAM,eAAe;AAavB,SA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