@idlekit/core 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/adapters/runtime.d.ts +51 -0
- package/dist/adapters/runtime.js +16 -0
- package/dist/adapters/runtime.js.map +1 -0
- package/dist/engine/breakEternity.d.ts +11 -0
- package/dist/engine/breakEternity.js +11 -0
- package/dist/engine/breakEternity.js.map +1 -1
- package/dist/engine/breakInfinity.d.ts +7 -0
- package/dist/engine/breakInfinity.js +7 -0
- package/dist/engine/breakInfinity.js.map +1 -1
- package/dist/engine/types.d.ts +7 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/ltv/telemetryLoop.d.ts +203 -0
- package/dist/ltv/telemetryLoop.js +389 -0
- package/dist/ltv/telemetryLoop.js.map +1 -0
- package/dist/models/exponential.d.ts +95 -0
- package/dist/models/exponential.js +200 -0
- package/dist/models/exponential.js.map +1 -0
- package/dist/models/index.d.ts +12 -0
- package/dist/models/index.js +18 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/jsonSchema.d.ts +13 -0
- package/dist/models/jsonSchema.js +30 -0
- package/dist/models/jsonSchema.js.map +1 -0
- package/dist/models/ledger.d.ts +26 -0
- package/dist/models/ledger.js +63 -0
- package/dist/models/ledger.js.map +1 -0
- package/dist/models/multiCurrency.d.ts +70 -0
- package/dist/models/multiCurrency.js +343 -0
- package/dist/models/multiCurrency.js.map +1 -0
- package/dist/models/prestige.d.ts +123 -0
- package/dist/models/prestige.js +183 -0
- package/dist/models/prestige.js.map +1 -0
- package/dist/models/productionChain.d.ts +114 -0
- package/dist/models/productionChain.js +447 -0
- package/dist/models/productionChain.js.map +1 -0
- package/dist/models/shared.d.ts +59 -0
- package/dist/models/shared.js +144 -0
- package/dist/models/shared.js.map +1 -0
- package/dist/money/types.d.ts +7 -0
- package/dist/notation/formatMoney.d.ts +7 -0
- package/dist/notation/formatMoney.js +7 -0
- package/dist/notation/formatMoney.js.map +1 -1
- package/dist/notation/parseMoney.d.ts +7 -0
- package/dist/notation/parseMoney.js +7 -0
- package/dist/notation/parseMoney.js.map +1 -1
- package/dist/notation/suffixer.d.ts +7 -0
- package/dist/notation/suffixer.js +7 -0
- package/dist/notation/suffixer.js.map +1 -1
- package/dist/notation/visibilityTracker.d.ts +7 -0
- package/dist/notation/visibilityTracker.js +7 -0
- package/dist/notation/visibilityTracker.js.map +1 -1
- package/dist/policy/emitter.d.ts +7 -0
- package/dist/policy/emitter.js +7 -0
- package/dist/policy/emitter.js.map +1 -1
- package/dist/policy/tickMoney.d.ts +7 -0
- package/dist/policy/tickMoney.js +7 -0
- package/dist/policy/tickMoney.js.map +1 -1
- package/dist/policy/types.d.ts +7 -0
- package/dist/report/chart.d.ts +196 -0
- package/dist/report/chart.js +275 -0
- package/dist/report/chart.js.map +1 -0
- package/dist/report/chartSvg.d.ts +9 -0
- package/dist/report/chartSvg.js +465 -0
- package/dist/report/chartSvg.js.map +1 -0
- package/dist/serde/moneyState.d.ts +7 -0
- package/dist/serde/moneyState.js +7 -0
- package/dist/serde/moneyState.js.map +1 -1
- package/dist/sim/analysis/designSpace.d.ts +23 -0
- package/dist/sim/analysis/designSpace.js +66 -0
- package/dist/sim/analysis/designSpace.js.map +1 -0
- package/dist/sim/analysis/globalSensitivity.d.ts +70 -0
- package/dist/sim/analysis/globalSensitivity.js +207 -0
- package/dist/sim/analysis/globalSensitivity.js.map +1 -0
- package/dist/sim/analysis/parameterSearch.d.ts +44 -0
- package/dist/sim/analysis/parameterSearch.js +172 -0
- package/dist/sim/analysis/parameterSearch.js.map +1 -0
- package/dist/sim/analysis/prestigeCycle.d.ts +1 -1
- package/dist/sim/analysis/prestigeCycle.js +7 -1
- package/dist/sim/analysis/prestigeCycle.js.map +1 -1
- package/dist/sim/analysis/resetInsights.d.ts +68 -0
- package/dist/sim/analysis/resetInsights.js +129 -0
- package/dist/sim/analysis/resetInsights.js.map +1 -0
- package/dist/sim/analysis/sampleStats.d.ts +34 -0
- package/dist/sim/analysis/sampleStats.js +97 -0
- package/dist/sim/analysis/sampleStats.js.map +1 -0
- package/dist/sim/monteCarlo.d.ts +7 -1
- package/dist/sim/monteCarlo.js +8 -0
- package/dist/sim/monteCarlo.js.map +1 -1
- package/dist/sim/random.d.ts +9 -0
- package/dist/sim/random.js +10 -1
- package/dist/sim/random.js.map +1 -1
- package/dist/sim/session.d.ts +2 -0
- package/dist/sim/session.js +15 -4
- package/dist/sim/session.js.map +1 -1
- package/dist/sim/sessionOffline.d.ts +4 -0
- package/dist/sim/sessionOffline.js +1 -0
- package/dist/sim/sessionOffline.js.map +1 -1
- package/dist/sim/stochastic.d.ts +82 -0
- package/dist/sim/stochastic.js +174 -0
- package/dist/sim/stochastic.js.map +1 -0
- package/dist/sim/timedWork.d.ts +10 -0
- package/dist/sim/timedWork.js +25 -0
- package/dist/sim/timedWork.js.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -85,6 +85,21 @@ cohort size or unobserved retention. `assertCohortObservation` validates seriali
|
|
|
85
85
|
See [the complete SDK example](https://github.com/imjlk/idlekit/blob/main/examples/telemetry/cohort-sdk.ts)
|
|
86
86
|
and [the cohort export guide](https://github.com/imjlk/idlekit/blob/main/docs/player-telemetry.md).
|
|
87
87
|
|
|
88
|
+
## Work that pays on completion
|
|
89
|
+
|
|
90
|
+
Use `advanceTimedWork(state, from, to, hooks)` in a model's `evolve` for
|
|
91
|
+
deliveries, crafting or expeditions. A start action pays its usual cost and saves
|
|
92
|
+
a deadline in `state.vars`. The hooks read that deadline, accrue each intervening
|
|
93
|
+
interval and apply a reward to the state at completion. A deadline equal to the
|
|
94
|
+
end of a tick pays on that tick. An overdue job pays at the beginning of the
|
|
95
|
+
resumed interval. The completion callback clears the slot or schedules a later
|
|
96
|
+
deadline, so one coarse tick can finish several stages.
|
|
97
|
+
|
|
98
|
+
Keep the deadline and payload in the saved state. Choose the same clock for the
|
|
99
|
+
deadline and the interval. For work that pauses offline, advance it only while
|
|
100
|
+
active and use an active-play clock. Use the normal wallet income hook or the
|
|
101
|
+
interval callback for a given income stream so it is credited once.
|
|
102
|
+
|
|
88
103
|
## Game-specific offline settlement
|
|
89
104
|
|
|
90
105
|
`simulateSessionPattern({ scenario, pattern, prepareOffline })` optionally calls a synchronous
|
|
@@ -93,6 +108,22 @@ and [the cohort export guide](https://github.com/imjlk/idlekit/blob/main/docs/pl
|
|
|
93
108
|
preserved in the snapshots; treat the shared engine, context and model as immutable.
|
|
94
109
|
Use the explicit wall timestamps for expiry checks after earlier capped gaps.
|
|
95
110
|
|
|
111
|
+
`nextActiveBlock` is a snapshot of the scheduled block that follows this absence. It is
|
|
112
|
+
`null` for the final gap up to the simulation horizon. Use it to select a return-only
|
|
113
|
+
settlement policy. A goal or `until` can stop before that scheduled return. Count observed
|
|
114
|
+
returns from an offline segment followed by an active segment in the completed run.
|
|
115
|
+
|
|
116
|
+
`session.summary.activeDays` counts days with positive simulated play, measured from
|
|
117
|
+
the start of the schedule. Use it as the denominator for revenue per active player-day.
|
|
118
|
+
Multiple visits in one day count once. A visit from 23:59 to 00:00 counts one day.
|
|
119
|
+
A visit with active ticks on both sides of midnight counts both days. When
|
|
120
|
+
`maxSteps` cuts a visit short, only the portion that was simulated contributes.
|
|
121
|
+
|
|
122
|
+
Use `simulateMonteCarlo({ scenario, draws, seed, sessionPattern, createOfflinePreparer, metrics })`
|
|
123
|
+
to run the same policy across seeds. The factory receives the fresh scenario, draw index
|
|
124
|
+
and derived seed once per draw. Keep counters such as a daily claim allowance in the
|
|
125
|
+
returned callback's closure. This keeps one draw's claims independent of the next draw.
|
|
126
|
+
|
|
96
127
|
Return any of `model`, `stepSec` and `policy`. They apply only to this gap; omission inherits
|
|
97
128
|
the scenario setting. `policy` replaces cap/decay, so `{}` removes both. The session's action
|
|
98
129
|
policy stays in `scenario.run.offline.actions`; a callback cannot override it. A replacement
|
|
@@ -181,6 +212,10 @@ console.log(
|
|
|
181
212
|
);
|
|
182
213
|
```
|
|
183
214
|
|
|
215
|
+
## Money primitives
|
|
216
|
+
|
|
217
|
+
Engines, `Money`/`MoneyState`, `tickMoney`, notation, and money serde are implemented in `@idlekit/money`. `@idlekit/core` re-exports them for compatibility, so the example above can import `createNumberEngine` from core. These re-exports stay in v1 but are scheduled for deprecation; prefer `@idlekit/money` in new code that only needs money primitives. `breakEternityEngine` is a placeholder that throws on every call and is not implemented in v1.
|
|
218
|
+
|
|
184
219
|
## Runtime
|
|
185
220
|
|
|
186
221
|
For the duration of an in-memory `runScenario` or `applyOfflineSeconds` result, import `runElapsedSec` from `@idlekit/core` and read `runElapsedSec(run)`. It uses `run.stop.elapsedSec`, the sum of tick seconds. `state.t` is the absolute reward timestamp; at a large starting timestamp, `run.end.t - run.start.t` can round differently. For example, ten 0.1-second ticks starting at `1e15` simulate about one second while the timestamps differ by 1.25 seconds. Results without a stop record fall back to that timestamp difference. A step-budget stop can shorten an individual run before the requested duration; check `run.stop?.reason` or use `assertHorizonReached(run, label)` when the full horizon is required.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime verification adapter contract.
|
|
3
|
+
*
|
|
4
|
+
* A game keeps its own income and cost functions (a TS runtime, a server
|
|
5
|
+
* module, or a port of engine code). A plugin wraps them in this shape so
|
|
6
|
+
* `idk verify runtime` can evaluate them on the same states the idlekit
|
|
7
|
+
* simulation visits and report where the two disagree.
|
|
8
|
+
*
|
|
9
|
+
* The adapter only reads plain numbers. It never receives engine values,
|
|
10
|
+
* so it does not depend on the selected money engine.
|
|
11
|
+
*/
|
|
12
|
+
/** A plain snapshot of one simulated state, handed to the runtime functions. */
|
|
13
|
+
export type RuntimeProbeState = Readonly<{
|
|
14
|
+
/** Simulation clock in seconds. */
|
|
15
|
+
t: number;
|
|
16
|
+
/** Zero-based index of the probe in the verification run. */
|
|
17
|
+
sample: number;
|
|
18
|
+
/** Wallet amount as a JavaScript number. */
|
|
19
|
+
wallet: number;
|
|
20
|
+
/** Scenario `vars`, copied. For the built-in `linear` model this is `{ owned }`. */
|
|
21
|
+
vars: Readonly<Record<string, unknown>>;
|
|
22
|
+
prestigeCount: number;
|
|
23
|
+
prestigeMultiplier: number;
|
|
24
|
+
/** The seed of the verification run. Runtime randomness must derive from it. */
|
|
25
|
+
seed: number;
|
|
26
|
+
}>;
|
|
27
|
+
/** A runtime value: a finite number or a decimal or scientific amount string. `null` means unavailable. */
|
|
28
|
+
export type RuntimeAmount = number | string | null;
|
|
29
|
+
export type RuntimeInitContext = Readonly<{
|
|
30
|
+
/** Deterministic seed of the idlekit run. Engine-side random generators must be seeded from it. */
|
|
31
|
+
seed: number;
|
|
32
|
+
scenarioId?: string;
|
|
33
|
+
/** `scenario.model.params`, unchanged. */
|
|
34
|
+
modelParams: unknown;
|
|
35
|
+
}>;
|
|
36
|
+
export type RuntimeEconomyAdapter = Readonly<{
|
|
37
|
+
id: string;
|
|
38
|
+
version?: number;
|
|
39
|
+
description?: string;
|
|
40
|
+
/** Called once before the first probe of each verification run. */
|
|
41
|
+
init?: (ctx: RuntimeInitContext) => void;
|
|
42
|
+
/** Income per second at this state, in the scenario unit, after multipliers. */
|
|
43
|
+
incomePerSec: (state: RuntimeProbeState) => RuntimeAmount;
|
|
44
|
+
/**
|
|
45
|
+
* Price of one application of each action at this state, keyed by idlekit action id
|
|
46
|
+
* (for example `buy.generator`). An action id that is absent is not compared.
|
|
47
|
+
*/
|
|
48
|
+
actionCosts?: (state: RuntimeProbeState) => Readonly<Record<string, RuntimeAmount>>;
|
|
49
|
+
}>;
|
|
50
|
+
/** Identity helper that keeps the adapter literal typed. */
|
|
51
|
+
export declare function defineRuntimeAdapter<const A extends RuntimeEconomyAdapter>(adapter: A): A;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime verification adapter contract.
|
|
3
|
+
*
|
|
4
|
+
* A game keeps its own income and cost functions (a TS runtime, a server
|
|
5
|
+
* module, or a port of engine code). A plugin wraps them in this shape so
|
|
6
|
+
* `idk verify runtime` can evaluate them on the same states the idlekit
|
|
7
|
+
* simulation visits and report where the two disagree.
|
|
8
|
+
*
|
|
9
|
+
* The adapter only reads plain numbers. It never receives engine values,
|
|
10
|
+
* so it does not depend on the selected money engine.
|
|
11
|
+
*/
|
|
12
|
+
/** Identity helper that keeps the adapter literal typed. */
|
|
13
|
+
export function defineRuntimeAdapter(adapter) {
|
|
14
|
+
return adapter;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/adapters/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA4CH,4DAA4D;AAC5D,MAAM,UAAU,oBAAoB,CAAwC,OAAU;IACpF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility re-export from `@idlekit/money`; the implementation lives there.
|
|
3
|
+
* `@idlekit/money` is the canonical import path for money primitives. New code
|
|
4
|
+
* that only needs money primitives should import from `@idlekit/money` directly.
|
|
5
|
+
* These re-exports are kept for the v1 compatibility contract and are scheduled
|
|
6
|
+
* for deprecation; they will not be removed within v1.
|
|
7
|
+
*
|
|
8
|
+
* `breakEternityEngine` is NOT implemented: every method throws
|
|
9
|
+
* `BREAK_ETERNITY_EXPERIMENTAL_MESSAGE`. It is exported only to keep the public
|
|
10
|
+
* surface stable. Use `breakInfinityEngine` or a custom `Engine` adapter.
|
|
11
|
+
*/
|
|
1
12
|
export { BREAK_ETERNITY_EXPERIMENTAL_MESSAGE, breakEternityEngine, createBreakEternityEngine, } from "@idlekit/money";
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility re-export from `@idlekit/money`; the implementation lives there.
|
|
3
|
+
* `@idlekit/money` is the canonical import path for money primitives. New code
|
|
4
|
+
* that only needs money primitives should import from `@idlekit/money` directly.
|
|
5
|
+
* These re-exports are kept for the v1 compatibility contract and are scheduled
|
|
6
|
+
* for deprecation; they will not be removed within v1.
|
|
7
|
+
*
|
|
8
|
+
* `breakEternityEngine` is NOT implemented: every method throws
|
|
9
|
+
* `BREAK_ETERNITY_EXPERIMENTAL_MESSAGE`. It is exported only to keep the public
|
|
10
|
+
* surface stable. Use `breakInfinityEngine` or a custom `Engine` adapter.
|
|
11
|
+
*/
|
|
1
12
|
export { BREAK_ETERNITY_EXPERIMENTAL_MESSAGE, breakEternityEngine, createBreakEternityEngine, } from "@idlekit/money";
|
|
2
13
|
//# sourceMappingURL=breakEternity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakEternity.js","sourceRoot":"","sources":["../../src/engine/breakEternity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"breakEternity.js","sourceRoot":"","sources":["../../src/engine/breakEternity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,mCAAmC,EACnC,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility re-export from `@idlekit/money`; the implementation lives there.
|
|
3
|
+
* `@idlekit/money` is the canonical import path for money primitives. New code
|
|
4
|
+
* that only needs money primitives should import from `@idlekit/money` directly.
|
|
5
|
+
* These re-exports are kept for the v1 compatibility contract and are scheduled
|
|
6
|
+
* for deprecation; they will not be removed within v1.
|
|
7
|
+
*/
|
|
1
8
|
export { Decimal, breakInfinityEngine, createBreakInfinityEngine, createNumberEngine, type BreakInfinityEngineOptions, type NumberEngineOptions, } from "@idlekit/money";
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility re-export from `@idlekit/money`; the implementation lives there.
|
|
3
|
+
* `@idlekit/money` is the canonical import path for money primitives. New code
|
|
4
|
+
* that only needs money primitives should import from `@idlekit/money` directly.
|
|
5
|
+
* These re-exports are kept for the v1 compatibility contract and are scheduled
|
|
6
|
+
* for deprecation; they will not be removed within v1.
|
|
7
|
+
*/
|
|
1
8
|
export { Decimal, breakInfinityEngine, createBreakInfinityEngine, createNumberEngine, } from "@idlekit/money";
|
|
2
9
|
//# sourceMappingURL=breakInfinity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakInfinity.js","sourceRoot":"","sources":["../../src/engine/breakInfinity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,GAGnB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"breakInfinity.js","sourceRoot":"","sources":["../../src/engine/breakInfinity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,GAGnB,MAAM,gBAAgB,CAAC"}
|
package/dist/engine/types.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility re-export from `@idlekit/money`; the implementation lives there.
|
|
3
|
+
* `@idlekit/money` is the canonical import path for money primitives. New code
|
|
4
|
+
* that only needs money primitives should import from `@idlekit/money` directly.
|
|
5
|
+
* These re-exports are kept for the v1 compatibility contract and are scheduled
|
|
6
|
+
* for deprecation; they will not be removed within v1.
|
|
7
|
+
*/
|
|
1
8
|
export type { Engine } from "@idlekit/money";
|
package/dist/index.d.ts
CHANGED
|
@@ -20,11 +20,13 @@ export * from "./scenario/migrate";
|
|
|
20
20
|
export * from "./scenario/compile";
|
|
21
21
|
export * from "./sim/types";
|
|
22
22
|
export * from "./sim/simulator";
|
|
23
|
+
export * from "./sim/timedWork";
|
|
23
24
|
export * from "./sim/advance";
|
|
24
25
|
export * from "./sim/step";
|
|
25
26
|
export * from "./sim/stepTypes";
|
|
26
27
|
export * from "./sim/offline";
|
|
27
28
|
export * from "./sim/random";
|
|
29
|
+
export * from "./sim/stochastic";
|
|
28
30
|
export * from "./sim/session";
|
|
29
31
|
export * from "./sim/monteCarlo";
|
|
30
32
|
export * from "./sim/executionBackend";
|
|
@@ -55,6 +57,11 @@ export * from "./sim/analysis/prestigeCycle";
|
|
|
55
57
|
export * from "./sim/analysis/resetCycle";
|
|
56
58
|
export * from "./sim/analysis/resetOptimization";
|
|
57
59
|
export * from "./sim/analysis/distribution";
|
|
60
|
+
export * from "./sim/analysis/sampleStats";
|
|
61
|
+
export * from "./sim/analysis/designSpace";
|
|
62
|
+
export * from "./sim/analysis/globalSensitivity";
|
|
63
|
+
export * from "./sim/analysis/parameterSearch";
|
|
64
|
+
export * from "./sim/analysis/resetInsights";
|
|
58
65
|
export * from "./sim/analysis/experiment";
|
|
59
66
|
export * from "./sim/analysis/sensitivity";
|
|
60
67
|
export * from "./sim/analysis/growth";
|
|
@@ -70,8 +77,13 @@ export * from "./sim/analysis/checks";
|
|
|
70
77
|
export * from "./sim/analysis/judge";
|
|
71
78
|
export * from "./sim/analysis/flow";
|
|
72
79
|
export * from "./sim/analysis/jevAdvisory";
|
|
80
|
+
export * from "./models/index";
|
|
73
81
|
export * from "./report/timeline";
|
|
74
82
|
export * from "./report/compare";
|
|
83
|
+
export * from "./report/chart";
|
|
84
|
+
export * from "./report/chartSvg";
|
|
75
85
|
export * from "./utils/deepClone";
|
|
76
86
|
export * from "./ltv/public";
|
|
77
87
|
export * from "./ltv/cohort";
|
|
88
|
+
export * from "./ltv/telemetryLoop";
|
|
89
|
+
export * from "./adapters/runtime";
|
package/dist/index.js
CHANGED
|
@@ -20,11 +20,13 @@ export * from "./scenario/migrate";
|
|
|
20
20
|
export * from "./scenario/compile";
|
|
21
21
|
export * from "./sim/types";
|
|
22
22
|
export * from "./sim/simulator";
|
|
23
|
+
export * from "./sim/timedWork";
|
|
23
24
|
export * from "./sim/advance";
|
|
24
25
|
export * from "./sim/step";
|
|
25
26
|
export * from "./sim/stepTypes";
|
|
26
27
|
export * from "./sim/offline";
|
|
27
28
|
export * from "./sim/random";
|
|
29
|
+
export * from "./sim/stochastic";
|
|
28
30
|
export * from "./sim/session";
|
|
29
31
|
export * from "./sim/monteCarlo";
|
|
30
32
|
export * from "./sim/executionBackend";
|
|
@@ -55,6 +57,11 @@ export * from "./sim/analysis/prestigeCycle";
|
|
|
55
57
|
export * from "./sim/analysis/resetCycle";
|
|
56
58
|
export * from "./sim/analysis/resetOptimization";
|
|
57
59
|
export * from "./sim/analysis/distribution";
|
|
60
|
+
export * from "./sim/analysis/sampleStats";
|
|
61
|
+
export * from "./sim/analysis/designSpace";
|
|
62
|
+
export * from "./sim/analysis/globalSensitivity";
|
|
63
|
+
export * from "./sim/analysis/parameterSearch";
|
|
64
|
+
export * from "./sim/analysis/resetInsights";
|
|
58
65
|
export * from "./sim/analysis/experiment";
|
|
59
66
|
export * from "./sim/analysis/sensitivity";
|
|
60
67
|
export * from "./sim/analysis/growth";
|
|
@@ -70,9 +77,14 @@ export * from "./sim/analysis/checks";
|
|
|
70
77
|
export * from "./sim/analysis/judge";
|
|
71
78
|
export * from "./sim/analysis/flow";
|
|
72
79
|
export * from "./sim/analysis/jevAdvisory";
|
|
80
|
+
export * from "./models/index";
|
|
73
81
|
export * from "./report/timeline";
|
|
74
82
|
export * from "./report/compare";
|
|
83
|
+
export * from "./report/chart";
|
|
84
|
+
export * from "./report/chartSvg";
|
|
75
85
|
export * from "./utils/deepClone";
|
|
76
86
|
export * from "./ltv/public";
|
|
77
87
|
export * from "./ltv/cohort";
|
|
88
|
+
export * from "./ltv/telemetryLoop";
|
|
89
|
+
export * from "./adapters/runtime";
|
|
78
90
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,gBAAgB,CAAC;AAE/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAElC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { ScenarioV1 } from "../scenario/types";
|
|
2
|
+
import { type CohortActivityRow, type CohortObservation, type RetentionAssumptions, type RetentionKey, type RetentionPatchPlan } from "./cohort";
|
|
3
|
+
/**
|
|
4
|
+
* Telemetry feedback loop: a standardized batch of complete install cohorts,
|
|
5
|
+
* multi-cohort comparison, drift checks, experiment planning and a patch plan
|
|
6
|
+
* that keeps the scenario diff explicit. Everything runs on local values.
|
|
7
|
+
*/
|
|
8
|
+
export declare const COHORT_BATCH_SCHEMA_VERSION: 1;
|
|
9
|
+
/** One complete install cohort in a batch. Rows follow the `observeCohort` export contract. */
|
|
10
|
+
export type CohortBatchEntry = Readonly<{
|
|
11
|
+
id: string;
|
|
12
|
+
/** Optional experiment group or scenario variant label. */
|
|
13
|
+
variant?: string;
|
|
14
|
+
/** Optional ISO calendar date (YYYY-MM-DD) shared by every install in the cohort. */
|
|
15
|
+
installDate?: string;
|
|
16
|
+
observedThroughDay: number;
|
|
17
|
+
rows: readonly CohortActivityRow[];
|
|
18
|
+
}>;
|
|
19
|
+
export type CohortBatch = Readonly<{
|
|
20
|
+
schemaVersion: typeof COHORT_BATCH_SCHEMA_VERSION;
|
|
21
|
+
cohorts: readonly CohortBatchEntry[];
|
|
22
|
+
}>;
|
|
23
|
+
export type ObservedCohort = Readonly<{
|
|
24
|
+
id: string;
|
|
25
|
+
variant: string | null;
|
|
26
|
+
installDate: string | null;
|
|
27
|
+
rows: number;
|
|
28
|
+
observation: CohortObservation;
|
|
29
|
+
}>;
|
|
30
|
+
export type CohortBatchIssue = Readonly<{
|
|
31
|
+
path: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}>;
|
|
34
|
+
export type CohortBatchValidation = Readonly<{
|
|
35
|
+
ok: true;
|
|
36
|
+
issues: readonly [];
|
|
37
|
+
cohorts: readonly ObservedCohort[];
|
|
38
|
+
}> | Readonly<{
|
|
39
|
+
ok: false;
|
|
40
|
+
issues: readonly CohortBatchIssue[];
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Validate a standardized cohort batch and observe every cohort. All issues are
|
|
44
|
+
* collected with a JSON path, so a batch export can be fixed in one pass.
|
|
45
|
+
* Revenue fields must be present on every row of a cohort or on none of them.
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateCohortBatch(input: unknown): CohortBatchValidation;
|
|
48
|
+
/** Observe every cohort in a batch, or throw one RangeError listing each issue path. */
|
|
49
|
+
export declare function observeCohortBatch(input: unknown): readonly ObservedCohort[];
|
|
50
|
+
/** Standard normal CDF. */
|
|
51
|
+
export declare function standardNormalCdf(x: number): number;
|
|
52
|
+
/** Standard normal quantile (Acklam's rational approximation, relative error < 1.2e-9). */
|
|
53
|
+
export declare function standardNormalQuantile(p: number): number;
|
|
54
|
+
export type SignificanceHint = Readonly<{
|
|
55
|
+
test: "two-proportion-z";
|
|
56
|
+
alpha: number;
|
|
57
|
+
z: number | null;
|
|
58
|
+
pValue: number | null;
|
|
59
|
+
/**
|
|
60
|
+
* `insufficient-sample` when an expected success or failure count is below 5.
|
|
61
|
+
* A hint describes this pair only: repeated looks or many pairs inflate false positives.
|
|
62
|
+
*/
|
|
63
|
+
verdict: "significant" | "not-significant" | "insufficient-sample";
|
|
64
|
+
}>;
|
|
65
|
+
/** Pooled two-proportion z-test hint for retained/installed counts. */
|
|
66
|
+
export declare function twoProportionSignificance(a: Readonly<{
|
|
67
|
+
users: number;
|
|
68
|
+
activeUsers: number;
|
|
69
|
+
}>, b: Readonly<{
|
|
70
|
+
users: number;
|
|
71
|
+
activeUsers: number;
|
|
72
|
+
}>, alpha?: number): SignificanceHint;
|
|
73
|
+
export type CohortComparisonCell = Readonly<{
|
|
74
|
+
cohortId: string;
|
|
75
|
+
variant: string | null;
|
|
76
|
+
status: "observed" | "not-observed";
|
|
77
|
+
users: number;
|
|
78
|
+
activeUsers: number | null;
|
|
79
|
+
rate: number | null;
|
|
80
|
+
interval95: Readonly<{
|
|
81
|
+
min: number;
|
|
82
|
+
max: number;
|
|
83
|
+
}> | null;
|
|
84
|
+
differenceFromBaselinePercentagePoints: number | null;
|
|
85
|
+
differenceFromAssumptionPercentagePoints: number | null;
|
|
86
|
+
significance: SignificanceHint | null;
|
|
87
|
+
}>;
|
|
88
|
+
export type CohortComparisonDay = Readonly<{
|
|
89
|
+
day: number;
|
|
90
|
+
assumption: number | null;
|
|
91
|
+
observedCohorts: number;
|
|
92
|
+
/** Max minus min observed rate across cohorts, in percentage points; null below two observed cohorts. */
|
|
93
|
+
spreadPercentagePoints: number | null;
|
|
94
|
+
cohorts: readonly CohortComparisonCell[];
|
|
95
|
+
}>;
|
|
96
|
+
export type MultiCohortComparison = Readonly<{
|
|
97
|
+
baseline: string;
|
|
98
|
+
alpha: number;
|
|
99
|
+
/** Number of non-baseline cohorts compared per day; consider alpha / comparisons for a family-wise bound. */
|
|
100
|
+
comparisons: number;
|
|
101
|
+
days: readonly CohortComparisonDay[];
|
|
102
|
+
notes: readonly string[];
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Compare exact-day retention across cohorts. The baseline cohort (first by default)
|
|
106
|
+
* anchors the difference and the significance hint of every other cohort.
|
|
107
|
+
*/
|
|
108
|
+
export declare function compareCohorts(cohorts: readonly ObservedCohort[], options?: Readonly<{
|
|
109
|
+
baseline?: string;
|
|
110
|
+
assumptions?: RetentionAssumptions;
|
|
111
|
+
alpha?: number;
|
|
112
|
+
}>): MultiCohortComparison;
|
|
113
|
+
export type RetentionDriftFinding = Readonly<{
|
|
114
|
+
day: number;
|
|
115
|
+
assumption: number;
|
|
116
|
+
observed: number;
|
|
117
|
+
differencePercentagePoints: number;
|
|
118
|
+
interval95: Readonly<{
|
|
119
|
+
min: number;
|
|
120
|
+
max: number;
|
|
121
|
+
}>;
|
|
122
|
+
/** The assumption lies outside the cohort's Wilson 95% interval. */
|
|
123
|
+
assumptionOutsideInterval: boolean;
|
|
124
|
+
drift: boolean;
|
|
125
|
+
}>;
|
|
126
|
+
export type RetentionDriftReport = Readonly<{
|
|
127
|
+
status: "drift" | "within-threshold" | "no-comparable-days";
|
|
128
|
+
thresholdPercentagePoints: number;
|
|
129
|
+
requireIntervalExclusion: boolean;
|
|
130
|
+
findings: readonly RetentionDriftFinding[];
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Compare observed anchors with explicit assumptions. A day drifts when the absolute
|
|
134
|
+
* difference reaches the threshold and, by default, the assumption also lies outside
|
|
135
|
+
* the Wilson 95% interval (so a small cohort's noise alone does not alert).
|
|
136
|
+
*/
|
|
137
|
+
export declare function detectRetentionDrift(observation: CohortObservation, assumptions: RetentionAssumptions, options?: Readonly<{
|
|
138
|
+
thresholdPercentagePoints?: number;
|
|
139
|
+
requireIntervalExclusion?: boolean;
|
|
140
|
+
}>): RetentionDriftReport;
|
|
141
|
+
export type ExperimentGroupInput = Readonly<{
|
|
142
|
+
id: string;
|
|
143
|
+
scenario?: string;
|
|
144
|
+
retention?: number;
|
|
145
|
+
}>;
|
|
146
|
+
export type RetentionExperimentPlan = Readonly<{
|
|
147
|
+
retentionDay: number;
|
|
148
|
+
baselineRate: number;
|
|
149
|
+
minimumDetectableEffectPercentagePoints: number;
|
|
150
|
+
targetRate: number;
|
|
151
|
+
alpha: number;
|
|
152
|
+
/** alpha divided by the number of comparisons against the control group. */
|
|
153
|
+
adjustedAlpha: number;
|
|
154
|
+
power: number;
|
|
155
|
+
usersPerGroup: number;
|
|
156
|
+
totalUsers: number;
|
|
157
|
+
groups: readonly Readonly<{
|
|
158
|
+
id: string;
|
|
159
|
+
scenario: string | null;
|
|
160
|
+
role: "control" | "treatment";
|
|
161
|
+
assumedRetention: number | null;
|
|
162
|
+
requiredUsers: number;
|
|
163
|
+
}>[];
|
|
164
|
+
observationWindow: Readonly<{
|
|
165
|
+
observedThroughDay: number;
|
|
166
|
+
enrollmentDays: number | null;
|
|
167
|
+
/** Enrollment plus the retention day plus one export day, when daily installs are known. */
|
|
168
|
+
earliestReadoutDay: number | null;
|
|
169
|
+
}>;
|
|
170
|
+
recommendations: readonly string[];
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Size a retention experiment for a two-sided pooled two-proportion test with equal
|
|
174
|
+
* allocation. Each treatment group is compared with the first (control) group, with
|
|
175
|
+
* a Bonferroni-adjusted alpha. The plan does not replace an experiment platform.
|
|
176
|
+
*/
|
|
177
|
+
export declare function planRetentionExperiment(args: Readonly<{
|
|
178
|
+
groups: readonly ExperimentGroupInput[];
|
|
179
|
+
retentionDay: number;
|
|
180
|
+
baselineRate?: number;
|
|
181
|
+
minimumDetectableEffectPercentagePoints?: number;
|
|
182
|
+
alpha?: number;
|
|
183
|
+
power?: number;
|
|
184
|
+
dailyInstalls?: number;
|
|
185
|
+
}>): RetentionExperimentPlan;
|
|
186
|
+
/** Deterministic, uniform group assignment for a local pseudonymous user ID. */
|
|
187
|
+
export declare function assignExperimentGroup(userId: string, experimentId: string, groupIds: readonly string[]): string;
|
|
188
|
+
export type RetentionChange = Readonly<{
|
|
189
|
+
key: RetentionKey;
|
|
190
|
+
before: number | null;
|
|
191
|
+
after: number | null;
|
|
192
|
+
}>;
|
|
193
|
+
export type RetentionUpdatePlan = Readonly<{
|
|
194
|
+
plan: RetentionPatchPlan;
|
|
195
|
+
/** Validated patched copy of the scenario; absent unless the plan is ready. */
|
|
196
|
+
scenario?: ScenarioV1;
|
|
197
|
+
changes: readonly RetentionChange[];
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Plan, apply and validate a retention patch in one step. The input scenario is
|
|
201
|
+
* never modified. Non-ready plans return no scenario and keep their warnings.
|
|
202
|
+
*/
|
|
203
|
+
export declare function planScenarioRetentionUpdate(scenario: ScenarioV1, observation: CohortObservation): RetentionUpdatePlan;
|