@funnelsgrove/cli 0.1.19 → 0.1.24

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.
@@ -19,13 +19,162 @@ Contract hash: `d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf
19
19
 
20
20
  ## Procedure
21
21
 
22
- 1. Build and validate every control/variant step before activation.
23
- 2. Give each variant a stable, contract-compliant identity and normal outgoing edge.
24
- 3. Create the experiment through FunnelsGrove so the platform owns the database row, feature flag, and generated experiment snapshot.
25
- 4. Keep variant keys, labels, traffic percentages, source step, and route targets aligned.
26
- 5. Resolve assignment and any redirect before creating the destination step visit.
27
- 6. Keep the default flow valid when the experiment is stopped or assignment is unavailable.
28
- 7. Run experiment-focused tests, then `fgrove validate`.
22
+ 1. Start in a synced funnel checkout and run `fgrove status` and `git status --short`.
23
+ 2. Build the control and variant steps or offer sets in the same local change.
24
+ 3. Save one of the strict JSON specs below as `experiment.json`.
25
+ 4. Create the database draft, hosted snapshot, and matching local generated files:
26
+
27
+ ```bash
28
+ fgrove experiments create --spec experiment.json --dir .
29
+ ```
30
+
31
+ For machine-readable output, run `fgrove experiments create --spec experiment.json --dir . --json`. It emits only `experimentId`, `experimentKey`, `draftVersionId`, and `writtenPaths`, with generated paths in canonical order.
32
+ 5. Resolve assignment and any redirect before creating the destination step visit. Keep the default flow valid when assignment is stopped, missing, or invalid.
33
+ 6. Run experiment-focused tests and `fgrove validate`, then follow the delivery path below.
34
+
35
+ ## JSON contract
36
+
37
+ Use only the documented fields. Unknown top-level and variant fields are rejected.
38
+
39
+ All experiment types require non-empty `id`, `name`, and `stepId`; one `primaryMetric`; at least one unique `trackedMetrics` entry containing the primary metric; and two to five variants. Each variant requires a unique non-empty `variantKey`, `label`, and `routeToStepId`, an integer `trafficPercent` from 0 through 100, and `isControl`. Exactly one variant is the control and traffic must total 100.
40
+
41
+ Length limits are enforced after surrounding whitespace is trimmed: `variantKey` is at most 120 characters. `id`, `name`, `stepId`, `label`, `routeToStepId`, and `offerSetKey` are each at most 200 characters after trimming. `offerSetKey` applies only to pricing variants.
42
+
43
+ Metrics are exactly `step_completion`, `next_step_reached`, `checkout_opened`, `funnel_completed`, or `paying_customer`.
44
+
45
+ ### Step experiment
46
+
47
+ Every variant routes to the step that implements that experience.
48
+
49
+ ```json
50
+ {
51
+ "id": "claim-headline-v1",
52
+ "name": "Claim headline experiment",
53
+ "type": "step",
54
+ "stepId": "claim",
55
+ "primaryMetric": "next_step_reached",
56
+ "trackedMetrics": [
57
+ "next_step_reached",
58
+ "funnel_completed"
59
+ ],
60
+ "variants": [
61
+ {
62
+ "variantKey": "control",
63
+ "label": "Control",
64
+ "routeToStepId": "claim",
65
+ "trafficPercent": 50,
66
+ "isControl": true
67
+ },
68
+ {
69
+ "variantKey": "variant_b",
70
+ "label": "Variant B",
71
+ "routeToStepId": "claim-b",
72
+ "trafficPercent": 50,
73
+ "isControl": false
74
+ }
75
+ ]
76
+ }
77
+ ```
78
+
79
+ ### Paywall experiment
80
+
81
+ Like `step`, every variant has a route target. Use `type: "paywall"` when the routes select complete paywall step variants.
82
+
83
+ ```json
84
+ {
85
+ "id": "paywall-layout-v1",
86
+ "name": "Paywall layout experiment",
87
+ "type": "paywall",
88
+ "stepId": "paywall-entry",
89
+ "primaryMetric": "checkout_opened",
90
+ "trackedMetrics": [
91
+ "checkout_opened",
92
+ "paying_customer"
93
+ ],
94
+ "variants": [
95
+ {
96
+ "variantKey": "control",
97
+ "label": "Control",
98
+ "routeToStepId": "paywall-control",
99
+ "trafficPercent": 50,
100
+ "isControl": true
101
+ },
102
+ {
103
+ "variantKey": "compact",
104
+ "label": "Compact",
105
+ "routeToStepId": "paywall-compact",
106
+ "trafficPercent": 50,
107
+ "isControl": false
108
+ }
109
+ ]
110
+ }
111
+ ```
112
+
113
+ ### Pricing experiment
114
+
115
+ Each pricing variant also requires a non-empty `offerSetKey`, and every `routeToStepId` must exactly equal the top-level `stepId`.
116
+
117
+ ```json
118
+ {
119
+ "id": "paywall-price-v1",
120
+ "name": "Paywall pricing experiment",
121
+ "type": "pricing",
122
+ "stepId": "paywall",
123
+ "primaryMetric": "paying_customer",
124
+ "trackedMetrics": [
125
+ "checkout_opened",
126
+ "paying_customer"
127
+ ],
128
+ "variants": [
129
+ {
130
+ "variantKey": "control",
131
+ "label": "Control",
132
+ "routeToStepId": "paywall",
133
+ "trafficPercent": 50,
134
+ "isControl": true,
135
+ "offerSetKey": "default-paywall"
136
+ },
137
+ {
138
+ "variantKey": "annual_focus",
139
+ "label": "Annual focus",
140
+ "routeToStepId": "paywall",
141
+ "trafficPercent": 50,
142
+ "isControl": false,
143
+ "offerSetKey": "annual-focus"
144
+ }
145
+ ]
146
+ }
147
+ ```
148
+
149
+ ## Creation guarantees
150
+
151
+ The stable `id` becomes the experiment key. Keep it unchanged for an exact retry: an identical same-key draft is reused, while a different definition or non-draft experiment is rejected rather than overwritten.
152
+
153
+ Creation always produces a draft. It does not create or activate a PostHog flag, start traffic, or make unfinished variant steps or offer sets runnable. Activation remains a separate pre-activation UI/API action.
154
+
155
+ The API creates the experiment and variants atomically, commits the matching generated snapshot to the hosted draft, and only then returns. The draft is immediately visible in the FunnelsGrove UI and hosted previews use the same snapshot. The CLI installs the exact returned bytes at `src/config/experiments.generated.ts` and `src/config/experiments.ts`, then updates the sync manifest last. `.funnelsgrove-sync.json` stays local and ignored; never commit or push it.
156
+
157
+ ## Recovery and errors
158
+
159
+ - Missing `.funnelsgrove-sync.json`: run `fgrove sync down` into a clean directory first.
160
+ - Invalid local JSON or `[FG-EXPERIMENT-SPEC]`: fix the reported field and retry with the same stable `id`.
161
+ - `[FG-EXPERIMENT-STALE-DRAFT]`: do not overwrite remote work. Download the latest draft into a clean temporary directory, merge deliberately, rerun validation, and retry the same exact spec.
162
+ - `[FG-EXPERIMENT-DRAFT-CONFLICT]`: the stable key already belongs to a different definition, owner, or lifecycle state. Reuse the original exact definition for a retry, or choose a new stable `id` only for a genuinely new experiment.
163
+ - Locally changed generated experiment files are never overwritten. Resolve those edits before retrying.
164
+ - If the API succeeded but the process stopped, retry safely with the same `id`. A ready local journal is automatically recovered before the next create or sync command; an interruption before the journal simply repeats the exact API request.
165
+
166
+ ## Validate and deliver
167
+
168
+ After implementing all referenced variant steps or offer sets, run:
169
+
170
+ ```bash
171
+ fgrove validate
172
+ git status --short
173
+ ```
174
+
175
+ For a funnel without GitHub source sync, deliver all local source changes with `fgrove sync up`.
176
+
177
+ For a GitHub-connected funnel, commit and push the generated source files with the rest of the source change, then run `fgrove github pull`. Never use `fgrove sync up` for the same GitHub-connected diff, and never add `.funnelsgrove-sync.json` to git.
29
178
 
30
179
  ## Pre-activation QA
31
180
 
@@ -226,6 +226,32 @@ describe('funnel agent documentation supply', () => {
226
226
  );
227
227
  });
228
228
 
229
+ it('documents the complete JSON-driven experiment creation workflow', async () => {
230
+ const content = await readFile(
231
+ join(templateRoot, 'docs/funnelsgrove/recipes/add-experiment.md'),
232
+ 'utf8',
233
+ );
234
+ const examples = [...content.matchAll(/```json\n([\s\S]*?)\n```/g)]
235
+ .map((match) => JSON.parse(match[1]) as { type?: unknown });
236
+
237
+ expect(examples.map(({ type }) => type)).toEqual(['step', 'paywall', 'pricing']);
238
+ expect(content).toContain('fgrove experiments create --spec experiment.json --dir .');
239
+ expect(content).toContain('fgrove experiments create --spec experiment.json --dir . --json');
240
+ expect(content).toContain('`experimentId`, `experimentKey`, `draftVersionId`, and `writtenPaths`');
241
+ expect(content).toContain(
242
+ '`variantKey` is at most 120 characters. `id`, `name`, `stepId`, `label`, `routeToStepId`, and `offerSetKey` are each at most 200 characters after trimming.',
243
+ );
244
+ expect(content).toContain('does not create or activate a PostHog flag');
245
+ expect(content).toContain('immediately visible in the FunnelsGrove UI');
246
+ expect(content).toContain('src/config/experiments.generated.ts');
247
+ expect(content).toContain('[FG-EXPERIMENT-STALE-DRAFT]');
248
+ expect(content).toContain('[FG-EXPERIMENT-DRAFT-CONFLICT]');
249
+ expect(content).toContain('[FG-EXPERIMENT-SPEC]');
250
+ expect(content).toContain('fgrove sync up');
251
+ expect(content).toContain('fgrove github pull');
252
+ expect(content).toContain('`.funnelsgrove-sync.json` stays local and ignored');
253
+ });
254
+
229
255
  it('keeps intro engagement explicitly non-automatic', async () => {
230
256
  const content = await readFile(
231
257
  join(templateRoot, 'docs/funnelsgrove/steps/intro_hero.md'),
@@ -311,7 +337,7 @@ describe('funnel agent documentation supply', () => {
311
337
 
312
338
  expect(manifest).toMatchObject({
313
339
  schemaVersion: 1,
314
- bundleVersion: '2.0.7',
340
+ bundleVersion: '2.0.12',
315
341
  stepContractVersion: contract.stepContractVersion,
316
342
  contractHash: contract.contractHash,
317
343
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "bundleVersion": "2.0.7",
3
+ "bundleVersion": "2.0.12",
4
4
  "contractSource": "funnelsgrove-repository://apps/funnel-runtime/contracts/step-contract-v2.json",
5
5
  "fullyGenerated": [
6
6
  ".funnelsgrove-docs.json",
@@ -9,7 +9,7 @@
9
9
  "version": "0.1.0",
10
10
  "dependencies": {
11
11
  "@funnelsgrove/analytics": "^0.1.37",
12
- "@funnelsgrove/payments": "^0.1.53",
12
+ "@funnelsgrove/payments": "^0.1.55",
13
13
  "@funnelsgrove/runtime": "^0.1.60",
14
14
  "@stripe/react-stripe-js": "^5.6.0",
15
15
  "@stripe/stripe-js": "^8.7.0",
@@ -899,9 +899,9 @@
899
899
  }
900
900
  },
901
901
  "node_modules/@funnelsgrove/payments": {
902
- "version": "0.1.53",
903
- "resolved": "https://registry.npmjs.org/@funnelsgrove/payments/-/payments-0.1.53.tgz",
904
- "integrity": "sha512-eaiaE8kcZnuZ1rrCIjnWzHNWFGjKYWtL4E9siOcSpDcz9QnnQndn/HFs0qEojTPgwdDEb17LW6WvQx/xmd5AxQ==",
902
+ "version": "0.1.55",
903
+ "resolved": "https://registry.npmjs.org/@funnelsgrove/payments/-/payments-0.1.55.tgz",
904
+ "integrity": "sha512-zrlnyPwUsqSYkaDYASBkB3bzNVSzS0+4glKC2+ai/+fIi4SZqEOAEo51WxR3jt0s5dAX2nFdX08r/YlvY7XqyA==",
905
905
  "dependencies": {
906
906
  "@funnelsgrove/analytics": "^0.1.28",
907
907
  "@funnelsgrove/runtime": "^0.1.54",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@funnelsgrove/analytics": "^0.1.37",
16
- "@funnelsgrove/payments": "^0.1.53",
16
+ "@funnelsgrove/payments": "^0.1.55",
17
17
  "@funnelsgrove/runtime": "^0.1.60",
18
18
  "@stripe/react-stripe-js": "^5.6.0",
19
19
  "@stripe/stripe-js": "^8.7.0",