hippo-memory 2.2.0 → 2.3.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 +3 -9
- package/dist/eval/eval-stats.d.ts +14 -3
- package/dist/eval/eval-stats.js +5 -4
- package/dist/eval/repository-t.d.ts +62 -0
- package/dist/eval/repository-t.js +290 -0
- package/dist/hooks/hook-blocks.js +2 -7
- package/dist/util/version.d.ts +1 -1
- package/dist/util/version.js +1 -1
- package/dist-ui/assets/index-CHlkKdFC.js +33 -0
- package/dist-ui/assets/react-BZPdts19.js +17 -0
- package/dist-ui/index.html +2 -2
- package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
- package/extensions/openclaw-plugin/package.json +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist-ui/assets/index-DPN7cP19.js +0 -33
- package/dist-ui/assets/react-CEUiQZj-.js +0 -17
package/README.md
CHANGED
|
@@ -826,14 +826,14 @@ hippo hook install opencode # patches AGENTS.md + installs the opencode TS
|
|
|
826
826
|
|
|
827
827
|
This adds a `<!-- hippo:start -->` ... `<!-- hippo:end -->` block that tells the agent to:
|
|
828
828
|
1. Run `hippo context --auto --budget 1500` at the start of a task. In Claude Code and Codex, whose prompt hook already injects pinned rules and matching memories, only if no hippo memory block has appeared in the session
|
|
829
|
-
2.
|
|
829
|
+
2. Everywhere but Claude Code, whose hooks store failed tool calls: run `hippo remember "<description of what went wrong>" --error` the moment it finds out why something failed, never as a closing step
|
|
830
830
|
3. Everywhere but Claude Code, whose own auto memory does this job: run a plain `hippo remember` the moment it learns something that should outlive the session, leaving out secrets and personal details
|
|
831
831
|
4. Capture a short summary with `hippo capture --stdin` when the session ends, but only where no hook captures the session: Cursor, OpenClaw, OpenCode, Pi, and Codex without its wrapper
|
|
832
832
|
|
|
833
833
|
The block asks for nothing a hook already does, because each extra tool call re-reads the whole context. Re-running `hippo init` swaps a block an older hippo wrote for the current one, as long as nobody edited it. It leaves an edited block alone and says so, and never touches text outside the markers.
|
|
834
834
|
|
|
835
835
|
For Claude Code, it also adds 7 hook entries to `~/.claude/settings.json`:
|
|
836
|
-
- a `SessionEnd` hook that runs `hippo sleep` and then `hippo capture` when the session exits. Capture matches the last 20 user and 10 assistant messages of the transcript against word patterns for decisions, rules, errors and preferences. It uses no model and does not read earlier turns, so
|
|
836
|
+
- a `SessionEnd` hook that runs `hippo sleep` and then `hippo capture` when the session exits. Capture matches the last 20 user and 10 assistant messages of the transcript against word patterns for decisions, rules, errors and preferences. It uses no model and does not read earlier turns, so a correction older than that window needs a `hippo remember` by hand.
|
|
837
837
|
- a `SessionStart` hook that prints the previous session's consolidation log on stderr, where `claude --debug` shows it. When the last sleep failed or a compaction summary was set aside, it shows you one line that points to `hippo doctor`.
|
|
838
838
|
- a `UserPromptSubmit` hook that runs `hippo context --pinned-only --include-recent 5 --format additional-context` every turn. It re-injects pinned memories (`hippo remember <text> --pin`) plus up to 5 memories that share words with your prompt. When nothing matches, it adds only the pinned ones. Since 1.55.0 this replaces the 5 newest memories, which cut the median block from 847 to 533 tokens in our eval. `{"pinnedInject":{"promptRecall":false}}` brings back the 5 newest, so fresh same-session lessons appear on the next prompt whatever you ask. The block is rendered without live strength percentages, so it stays byte-identical while its memories do not change, and it is sent only when it changed since the session's last prompt: an unchanged block is skipped, resent every 10 skips (`pinnedInject.refreshTurns`, `0` never resends) and resent after compaction. The prompt-matched memories go in a separate block that is never skipped, so they are sent on every prompt they match. `{"pinnedInject":{"skipUnchanged":false}}` sends the pinned block every turn as before. Opt out entirely with `{"pinnedInject":{"enabled":false}}` in `.hippo/config.json`.
|
|
839
839
|
- a `PreCompact` hook that runs `hippo pre-compact` before the transcript gets summarized. It records the compaction in the store, saves a working-state snapshot (task/summary/next step) so mid-session compaction can't drop it, and asks the summariser to end its summary with a "Memories for hippo" list: the lessons, decisions and corrections from the session that should outlive it. The `SessionEnd` hook still owns extracting durable memories from the transcript.
|
|
@@ -865,14 +865,8 @@ block has appeared in this session, run this at the start of a task:
|
|
|
865
865
|
hippo context --auto --budget 1500
|
|
866
866
|
```
|
|
867
867
|
|
|
868
|
-
When you find out why something failed, record it right then, while you
|
|
869
|
-
work, never as a closing step:
|
|
870
|
-
```bash
|
|
871
|
-
hippo remember "<what went wrong and why>" --error
|
|
872
|
-
```
|
|
873
|
-
|
|
874
868
|
The installed hooks store failed tool calls and capture the session when it
|
|
875
|
-
ends, so there is nothing to run
|
|
869
|
+
ends, so there is nothing to record or run by hand.
|
|
876
870
|
````
|
|
877
871
|
|
|
878
872
|
### MCP Server
|
|
@@ -104,14 +104,20 @@ export declare function passHatK(runsByTask: boolean[][], k: number): number;
|
|
|
104
104
|
export type Family<T> = readonly T[];
|
|
105
105
|
/** One repository's families; a task with no lesson is a family of one. */
|
|
106
106
|
export type Repository<T> = readonly Family<T>[];
|
|
107
|
-
/** An {@link Estimate} with a two-sided p-value from
|
|
107
|
+
/** An {@link Estimate} with a two-sided p-value, from bootstrap resamples or from a t test over repositories. */
|
|
108
108
|
export interface TestedEstimate extends Estimate {
|
|
109
|
-
/** 2 x min(share <= null, share >= null), capped at 1
|
|
109
|
+
/** Bootstrap: 2 x min(share <= null, share >= null) of the resamples, capped at 1. t test: the two-sided Student t p.
|
|
110
|
+
* NaN with fewer than two repositories. */
|
|
110
111
|
readonly p: number;
|
|
111
|
-
/** Non-finite resamples, dropped; `iterations + dropped` is the number requested. */
|
|
112
|
+
/** Non-finite resamples, dropped; `iterations + dropped` is the number requested. Both are 0 for a t test. */
|
|
112
113
|
readonly dropped: number;
|
|
113
114
|
/** The null the p-value tested against; {@link verdict} reads its sides from here. */
|
|
114
115
|
readonly nullValue: number;
|
|
116
|
+
/** Degrees of freedom of a t test (a fixed-repository test gives a fractional Satterthwaite value);
|
|
117
|
+
* absent on a bootstrap. */
|
|
118
|
+
readonly df?: number;
|
|
119
|
+
/** Standard error of a t test; absent on a bootstrap. */
|
|
120
|
+
readonly se?: number;
|
|
115
121
|
}
|
|
116
122
|
/** Options for {@link twoLevelBootstrap}. */
|
|
117
123
|
export interface TwoLevelOpts extends BootstrapOpts {
|
|
@@ -119,7 +125,12 @@ export interface TwoLevelOpts extends BootstrapOpts {
|
|
|
119
125
|
readonly iterations?: number;
|
|
120
126
|
/** Value the p-value tests against: 0 for differences, 1 for ratios. Default 0. */
|
|
121
127
|
readonly nullValue?: number;
|
|
128
|
+
/** Keep every repository in place and resample families inside each: the stratified twin of a
|
|
129
|
+
* fixed-repository t test. Default false. */
|
|
130
|
+
readonly fixedRepositories?: boolean;
|
|
122
131
|
}
|
|
132
|
+
/** The result with nothing to test: estimate, bounds and p all NaN. */
|
|
133
|
+
export declare function notANumber(nullValue: number, dropped: number): TestedEstimate;
|
|
123
134
|
/** Resamples repositories, then families inside each; only the repository draw carries a shared-store fault.
|
|
124
135
|
* The statistic never uses the PRNG, so a second call on one seed draws the same resamples. */
|
|
125
136
|
export declare function twoLevelBootstrap<T>(repos: readonly Repository<T>[], statistic: (units: readonly T[]) => number, opts?: TwoLevelOpts): TestedEstimate;
|
package/dist/eval/eval-stats.js
CHANGED
|
@@ -168,14 +168,15 @@ export function passHatK(runsByTask, k) {
|
|
|
168
168
|
return Number.NaN;
|
|
169
169
|
return eligible.filter((r) => r.slice(0, k).every(Boolean)).length / eligible.length;
|
|
170
170
|
}
|
|
171
|
-
|
|
171
|
+
/** The result with nothing to test: estimate, bounds and p all NaN. */
|
|
172
|
+
export function notANumber(nullValue, dropped) {
|
|
172
173
|
const nan = Number.NaN;
|
|
173
174
|
return { estimate: nan, low: nan, high: nan, p: nan, iterations: 0, dropped, nullValue };
|
|
174
175
|
}
|
|
175
|
-
function resampleUnits(repos, rand) {
|
|
176
|
+
function resampleUnits(repos, rand, fixedRepositories) {
|
|
176
177
|
const units = [];
|
|
177
178
|
for (let i = 0; i < repos.length; i++) {
|
|
178
|
-
const repo = repos[Math.floor(rand() * repos.length)];
|
|
179
|
+
const repo = fixedRepositories ? repos[i] : repos[Math.floor(rand() * repos.length)];
|
|
179
180
|
for (let j = 0; j < repo.length; j++) {
|
|
180
181
|
for (const unit of repo[Math.floor(rand() * repo.length)])
|
|
181
182
|
units.push(unit);
|
|
@@ -209,7 +210,7 @@ export function twoLevelBootstrap(repos, statistic, opts = {}) {
|
|
|
209
210
|
const rand = seededRandom(opts.seed ?? 1);
|
|
210
211
|
const samples = [];
|
|
211
212
|
for (let b = 0; b < requested; b++) {
|
|
212
|
-
const value = statistic(resampleUnits(kept, rand));
|
|
213
|
+
const value = statistic(resampleUnits(kept, rand, opts.fixedRepositories ?? false));
|
|
213
214
|
if (Number.isFinite(value))
|
|
214
215
|
samples.push(value);
|
|
215
216
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Student t tests for the built-in memory eval. The repositories are fixed and the family is the unit
|
|
2
|
+
* (Amendment 2): a variance-components t over family-by-seed tables with Satterthwaite df, plus the older
|
|
3
|
+
* one-value-per-repository tests (G-1 df).
|
|
4
|
+
* The t distribution is written here because the package carries no statistics library. */
|
|
5
|
+
import { type TestedEstimate } from './eval-stats.js';
|
|
6
|
+
/** log Gamma(z) for z >= 0.5, by the Lanczos series (g 7, nine terms). */
|
|
7
|
+
export declare function lnGamma(z: number): number;
|
|
8
|
+
/** Regularized incomplete beta I_x(a, b). */
|
|
9
|
+
export declare function incompleteBeta(x: number, a: number, b: number): number;
|
|
10
|
+
/** Student t cumulative distribution P(T <= t) with `df` degrees of freedom. */
|
|
11
|
+
export declare function studentTCdf(t: number, df: number): number;
|
|
12
|
+
/** Student t quantile: the t with P(T <= t) = p, found by bisection on the CDF. */
|
|
13
|
+
export declare function studentTQuantile(p: number, df: number): number;
|
|
14
|
+
/** One-sample t test on per-repository values: the mean, se = sd / sqrt(G), G-1 degrees of freedom.
|
|
15
|
+
* Fewer than two repositories give the not-a-number result. */
|
|
16
|
+
export declare function repositoryT(values: readonly number[], nullValue?: number): TestedEstimate;
|
|
17
|
+
/** One unit of a family-by-seed table; units that share a (repo, family, seed) cell are averaged. */
|
|
18
|
+
export interface FamilyUnit {
|
|
19
|
+
readonly repo: string;
|
|
20
|
+
readonly family: string;
|
|
21
|
+
readonly seed: number;
|
|
22
|
+
readonly value: number;
|
|
23
|
+
}
|
|
24
|
+
/** Mean squares pooled over the fitted repositories of a family-by-seed fit, weighted by df, with the mean
|
|
25
|
+
* seeds per family (`sBar`) and families per seed (`kBar`) that turn them into variance components;
|
|
26
|
+
* `repos` lists every repository. */
|
|
27
|
+
export interface PooledComponents {
|
|
28
|
+
readonly repos: readonly {
|
|
29
|
+
readonly k: number;
|
|
30
|
+
readonly s: number;
|
|
31
|
+
readonly n: number;
|
|
32
|
+
}[];
|
|
33
|
+
readonly F: number;
|
|
34
|
+
readonly Q: number;
|
|
35
|
+
readonly E: number;
|
|
36
|
+
readonly dfF: number;
|
|
37
|
+
readonly dfQ: number;
|
|
38
|
+
readonly dfE: number;
|
|
39
|
+
readonly sBar: number;
|
|
40
|
+
readonly kBar: number;
|
|
41
|
+
}
|
|
42
|
+
/** The pooled mean squares the fixed-repository t test reads, for one repository or more; null when none can be fitted.
|
|
43
|
+
* The seed rule and the sizer take their spreads from here, so they cannot drift from the test. */
|
|
44
|
+
export declare function pooledComponents(units: readonly FamilyUnit[]): PooledComponents | null;
|
|
45
|
+
/** Mean of the repository estimates with repositories held fixed: the spread is family and seed variation inside each
|
|
46
|
+
* (additive model y = mu + a_f + b_s), pooled over fitted repositories (two or more families and seeds in
|
|
47
|
+
* one connected block, one residual df); a thinner or split one adds its mean and borrows the pooled spread.
|
|
48
|
+
* Fewer than two repositories or none fitted: NaN. */
|
|
49
|
+
export declare function fixedRepositoryT(units: readonly FamilyUnit[], nullValue?: number): TestedEstimate;
|
|
50
|
+
/** One (repo, family, seed) cell's summed treatment and control values. */
|
|
51
|
+
export interface RatioCell {
|
|
52
|
+
readonly repo: string;
|
|
53
|
+
readonly family: string;
|
|
54
|
+
readonly seed: number;
|
|
55
|
+
readonly t: number;
|
|
56
|
+
readonly c: number;
|
|
57
|
+
}
|
|
58
|
+
/** The pooled ratio sum(t) / sum(c) against 1; its spread is fixedRepositoryT on the residuals (t - R c) / mean(c).
|
|
59
|
+
* The interval is on the log scale (`se` too): with skewed costs the symmetric R +- t se passed 5.2-5.6% at a true
|
|
60
|
+
* 1.10, over the 5% bar, and the log form passed 3.2-4.7%. */
|
|
61
|
+
export declare function fixedRepositoryRatioT(cells: readonly RatioCell[]): TestedEstimate;
|
|
62
|
+
//# sourceMappingURL=repository-t.d.ts.map
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/** Student t tests for the built-in memory eval. The repositories are fixed and the family is the unit
|
|
2
|
+
* (Amendment 2): a variance-components t over family-by-seed tables with Satterthwaite df, plus the older
|
|
3
|
+
* one-value-per-repository tests (G-1 df).
|
|
4
|
+
* The t distribution is written here because the package carries no statistics library. */
|
|
5
|
+
import { notANumber } from './eval-stats.js';
|
|
6
|
+
const ALPHA = 0.05;
|
|
7
|
+
// Equal repository values can leave float noise in the spread; at this size it reads as no spread at all.
|
|
8
|
+
const FLAT = 1e-12;
|
|
9
|
+
const LANCZOS = [
|
|
10
|
+
0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059,
|
|
11
|
+
12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7,
|
|
12
|
+
];
|
|
13
|
+
/** log Gamma(z) for z >= 0.5, by the Lanczos series (g 7, nine terms). */
|
|
14
|
+
export function lnGamma(z) {
|
|
15
|
+
const x = z - 1;
|
|
16
|
+
let a = LANCZOS[0];
|
|
17
|
+
for (let i = 1; i < LANCZOS.length; i++)
|
|
18
|
+
a += LANCZOS[i] / (x + i);
|
|
19
|
+
const t = x + 7.5;
|
|
20
|
+
return 0.5 * Math.log(2 * Math.PI) + (x + 0.5) * Math.log(t) - t + Math.log(a);
|
|
21
|
+
}
|
|
22
|
+
// Modified Lentz on the incomplete beta continued fraction; it converges fast where x < (a + 1) / (a + b + 2).
|
|
23
|
+
function betaFraction(a, b, x) {
|
|
24
|
+
const tiny = 1e-300;
|
|
25
|
+
const nonZero = (v) => (Math.abs(v) < tiny ? tiny : v);
|
|
26
|
+
let c = 1;
|
|
27
|
+
let d = 1 / nonZero(1 - ((a + b) * x) / (a + 1));
|
|
28
|
+
let h = d;
|
|
29
|
+
for (let m = 1; m <= 1000; m++) {
|
|
30
|
+
const m2 = 2 * m;
|
|
31
|
+
const even = (m * (b - m) * x) / ((a - 1 + m2) * (a + m2));
|
|
32
|
+
d = 1 / nonZero(1 + even * d);
|
|
33
|
+
c = nonZero(1 + even / c);
|
|
34
|
+
h *= d * c;
|
|
35
|
+
const odd = (-(a + m) * (a + b + m) * x) / ((a + m2) * (a + 1 + m2));
|
|
36
|
+
d = 1 / nonZero(1 + odd * d);
|
|
37
|
+
c = nonZero(1 + odd / c);
|
|
38
|
+
h *= d * c;
|
|
39
|
+
if (Math.abs(d * c - 1) < 1e-15)
|
|
40
|
+
return h;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`incomplete beta did not converge at a ${a}, b ${b}, x ${x}`);
|
|
43
|
+
}
|
|
44
|
+
/** Regularized incomplete beta I_x(a, b). */
|
|
45
|
+
export function incompleteBeta(x, a, b) {
|
|
46
|
+
if (x <= 0)
|
|
47
|
+
return 0;
|
|
48
|
+
if (x >= 1)
|
|
49
|
+
return 1;
|
|
50
|
+
const front = Math.exp(lnGamma(a + b) - lnGamma(a) - lnGamma(b) + a * Math.log(x) + b * Math.log(1 - x));
|
|
51
|
+
return x < (a + 1) / (a + b + 2) ? (front * betaFraction(a, b, x)) / a : 1 - (front * betaFraction(b, a, 1 - x)) / b;
|
|
52
|
+
}
|
|
53
|
+
// Two-sided tail P(|T| >= |t|), from the beta form so a small p never loses digits to 1 - cdf.
|
|
54
|
+
const twoSidedTail = (t, df) => incompleteBeta(df / (df + t * t), df / 2, 0.5);
|
|
55
|
+
/** Student t cumulative distribution P(T <= t) with `df` degrees of freedom. */
|
|
56
|
+
export function studentTCdf(t, df) {
|
|
57
|
+
const tail = twoSidedTail(t, df) / 2;
|
|
58
|
+
return t > 0 ? 1 - tail : tail;
|
|
59
|
+
}
|
|
60
|
+
/** Student t quantile: the t with P(T <= t) = p, found by bisection on the CDF. */
|
|
61
|
+
export function studentTQuantile(p, df) {
|
|
62
|
+
if (!(p > 0 && p < 1) || !(df > 0)) {
|
|
63
|
+
throw new RangeError(`studentTQuantile needs 0 < p < 1 and df > 0, got p ${p}, df ${df}`);
|
|
64
|
+
}
|
|
65
|
+
if (p < 0.5)
|
|
66
|
+
return -studentTQuantile(1 - p, df);
|
|
67
|
+
let hi = 1;
|
|
68
|
+
while (studentTCdf(hi, df) < p)
|
|
69
|
+
hi *= 2;
|
|
70
|
+
let lo = 0;
|
|
71
|
+
for (let i = 0; i < 200 && hi - lo > 1e-15 * hi; i++) {
|
|
72
|
+
const mid = (lo + hi) / 2;
|
|
73
|
+
if (studentTCdf(mid, df) < p)
|
|
74
|
+
lo = mid;
|
|
75
|
+
else
|
|
76
|
+
hi = mid;
|
|
77
|
+
}
|
|
78
|
+
return (lo + hi) / 2;
|
|
79
|
+
}
|
|
80
|
+
const critical = new Map();
|
|
81
|
+
// The sizer asks for the same few df thousands of times; Satterthwaite df are fractional, so the key is df to
|
|
82
|
+
// three decimals and the quantile is taken at that rounded df, or the cache would never hit.
|
|
83
|
+
function criticalValue(df) {
|
|
84
|
+
const key = Math.round(df * 1000) / 1000;
|
|
85
|
+
let q = critical.get(key);
|
|
86
|
+
if (q === undefined) {
|
|
87
|
+
q = studentTQuantile(1 - ALPHA / 2, key);
|
|
88
|
+
critical.set(key, q);
|
|
89
|
+
}
|
|
90
|
+
return q;
|
|
91
|
+
}
|
|
92
|
+
const sum = (xs) => xs.reduce((s, x) => s + x, 0);
|
|
93
|
+
/** A 95% t interval and a two-sided p against `nullValue`.
|
|
94
|
+
* With no spread the interval is the estimate itself, and p is 1 on the null and 0 off it. */
|
|
95
|
+
function tResult(estimate, se, df, nullValue) {
|
|
96
|
+
if (!Number.isFinite(estimate) || !Number.isFinite(se))
|
|
97
|
+
return notANumber(nullValue, 0);
|
|
98
|
+
const base = { estimate, iterations: 0, dropped: 0, nullValue, df };
|
|
99
|
+
if (se <= FLAT * Math.max(1, Math.abs(estimate))) {
|
|
100
|
+
const onNull = Math.abs(estimate - nullValue) <= FLAT * Math.max(1, Math.abs(nullValue));
|
|
101
|
+
return { ...base, low: estimate, high: estimate, p: onNull ? 1 : 0, se: 0 };
|
|
102
|
+
}
|
|
103
|
+
const half = criticalValue(df) * se;
|
|
104
|
+
return { ...base, low: estimate - half, high: estimate + half, p: twoSidedTail((estimate - nullValue) / se, df), se };
|
|
105
|
+
}
|
|
106
|
+
/** One-sample t test on per-repository values: the mean, se = sd / sqrt(G), G-1 degrees of freedom.
|
|
107
|
+
* Fewer than two repositories give the not-a-number result. */
|
|
108
|
+
export function repositoryT(values, nullValue = 0) {
|
|
109
|
+
const g = values.length;
|
|
110
|
+
if (g < 2)
|
|
111
|
+
return notANumber(nullValue, 0);
|
|
112
|
+
const mean = sum(values) / g;
|
|
113
|
+
const sd = Math.sqrt(sum(values.map((v) => (v - mean) ** 2)) / (g - 1));
|
|
114
|
+
return tResult(mean, sd / Math.sqrt(g), g - 1, nullValue);
|
|
115
|
+
}
|
|
116
|
+
const MAX_PASSES = 1000;
|
|
117
|
+
const CONVERGED = 1e-12;
|
|
118
|
+
function tableOf(units) {
|
|
119
|
+
const families = new Map();
|
|
120
|
+
const seeds = new Map();
|
|
121
|
+
const sums = new Map();
|
|
122
|
+
const indexOf = (ids, key) => {
|
|
123
|
+
if (!ids.has(key))
|
|
124
|
+
ids.set(key, ids.size);
|
|
125
|
+
return ids.get(key);
|
|
126
|
+
};
|
|
127
|
+
for (const u of units) {
|
|
128
|
+
const [f, s] = [indexOf(families, u.family), indexOf(seeds, u.seed)];
|
|
129
|
+
const cell = sums.get(`${f}/${s}`) ?? { f, s, total: 0, count: 0 };
|
|
130
|
+
cell.total += u.value;
|
|
131
|
+
cell.count++;
|
|
132
|
+
sums.set(`${f}/${s}`, cell);
|
|
133
|
+
}
|
|
134
|
+
const cells = [...sums.values()].map((c) => ({ f: c.f, s: c.s, y: c.total / c.count }));
|
|
135
|
+
return { cells, k: families.size, s: seeds.size };
|
|
136
|
+
}
|
|
137
|
+
function levelMeans(cells, size, level, value) {
|
|
138
|
+
const total = Array.from({ length: size }, () => 0);
|
|
139
|
+
const count = Array.from({ length: size }, () => 0);
|
|
140
|
+
for (const c of cells) {
|
|
141
|
+
total[level(c)] += value(c);
|
|
142
|
+
count[level(c)]++;
|
|
143
|
+
}
|
|
144
|
+
return total.map((x, i) => x / count[i]);
|
|
145
|
+
}
|
|
146
|
+
// Writes the centred effects into `effects` and returns the shift, which belongs to the intercept.
|
|
147
|
+
function centreInto(effects, raw) {
|
|
148
|
+
const shift = sum(raw) / raw.length;
|
|
149
|
+
raw.forEach((x, i) => {
|
|
150
|
+
effects[i] = x - shift;
|
|
151
|
+
});
|
|
152
|
+
return shift;
|
|
153
|
+
}
|
|
154
|
+
/** Residual sum of squares about the level means of one factor: the fit with the other factor left out. */
|
|
155
|
+
function rssAbout(cells, size, level) {
|
|
156
|
+
const means = levelMeans(cells, size, level, (c) => c.y);
|
|
157
|
+
return sum(cells.map((c) => (c.y - means[level(c)]) ** 2));
|
|
158
|
+
}
|
|
159
|
+
/** Least squares for y = mu + a_f + b_s on the cells present, by alternating means with a and b centred each pass. */
|
|
160
|
+
function additiveFit(repo, t) {
|
|
161
|
+
const a = Array.from({ length: t.k }, () => 0);
|
|
162
|
+
const b = Array.from({ length: t.s }, () => 0);
|
|
163
|
+
let mu = sum(t.cells.map((c) => c.y)) / t.cells.length;
|
|
164
|
+
for (let pass = 0; pass < MAX_PASSES; pass++) {
|
|
165
|
+
const before = [mu, ...a, ...b];
|
|
166
|
+
const shiftA = centreInto(a, levelMeans(t.cells, t.k, (c) => c.f, (c) => c.y - mu - b[c.s]));
|
|
167
|
+
mu += shiftA;
|
|
168
|
+
const shiftB = centreInto(b, levelMeans(t.cells, t.s, (c) => c.s, (c) => c.y - mu - a[c.f]));
|
|
169
|
+
mu += shiftB;
|
|
170
|
+
mu = sum(t.cells.map((c) => c.y - a[c.f] - b[c.s])) / t.cells.length;
|
|
171
|
+
const change = Math.max(...[mu, ...a, ...b].map((x, i) => Math.abs(x - before[i])));
|
|
172
|
+
if (change < CONVERGED)
|
|
173
|
+
return { mu, rss: sum(t.cells.map((c) => (c.y - mu - a[c.f] - b[c.s]) ** 2)) };
|
|
174
|
+
}
|
|
175
|
+
throw new Error(`additive fit for repository ${repo} did not converge in ${MAX_PASSES} passes`);
|
|
176
|
+
}
|
|
177
|
+
// Union-find over the family-seed graph: n - k - s + 1 counts residual df only when the present cells form one block.
|
|
178
|
+
function isConnected(t) {
|
|
179
|
+
const parent = Array.from({ length: t.k + t.s }, (_, i) => i);
|
|
180
|
+
const root = (i) => {
|
|
181
|
+
while (parent[i] !== i)
|
|
182
|
+
i = parent[i] = parent[parent[i]];
|
|
183
|
+
return i;
|
|
184
|
+
};
|
|
185
|
+
for (const c of t.cells)
|
|
186
|
+
parent[root(c.f)] = root(t.k + c.s);
|
|
187
|
+
return new Set(parent.map((_, i) => root(i))).size === 1;
|
|
188
|
+
}
|
|
189
|
+
function fitRepo(repo, units) {
|
|
190
|
+
const t = tableOf(units);
|
|
191
|
+
const n = t.cells.length;
|
|
192
|
+
const dfE = n - t.k - t.s + 1;
|
|
193
|
+
const base = { k: t.k, s: t.s, n };
|
|
194
|
+
if (t.k < 2 || t.s < 2 || dfE < 1 || !isConnected(t)) {
|
|
195
|
+
return { ...base, est: sum(t.cells.map((c) => c.y)) / n, ms: null };
|
|
196
|
+
}
|
|
197
|
+
const { mu, rss } = additiveFit(repo, t);
|
|
198
|
+
const [dfF, dfQ] = [t.k - 1, t.s - 1];
|
|
199
|
+
// Clamped: both reduced fits nest the additive one, so a negative difference is float noise.
|
|
200
|
+
const ssF = Math.max(0, rssAbout(t.cells, t.s, (c) => c.s) - rss);
|
|
201
|
+
const ssQ = Math.max(0, rssAbout(t.cells, t.k, (c) => c.f) - rss);
|
|
202
|
+
return { ...base, est: mu, ms: { F: ssF / dfF, Q: ssQ / dfQ, E: rss / dfE, dfF, dfQ, dfE } };
|
|
203
|
+
}
|
|
204
|
+
const weighted = (rs, value, df) => sum(rs.map((r) => value(r) * df(r))) / sum(rs.map(df));
|
|
205
|
+
function poolMeanSquares(fitted) {
|
|
206
|
+
return {
|
|
207
|
+
F: weighted(fitted, (r) => r.ms.F, (r) => r.ms.dfF),
|
|
208
|
+
Q: weighted(fitted, (r) => r.ms.Q, (r) => r.ms.dfQ),
|
|
209
|
+
E: weighted(fitted, (r) => r.ms.E, (r) => r.ms.dfE),
|
|
210
|
+
dfF: sum(fitted.map((r) => r.ms.dfF)),
|
|
211
|
+
dfQ: sum(fitted.map((r) => r.ms.dfQ)),
|
|
212
|
+
dfE: sum(fitted.map((r) => r.ms.dfE)),
|
|
213
|
+
sBar: weighted(fitted, (r) => r.n / r.k, (r) => r.ms.dfF),
|
|
214
|
+
kBar: weighted(fitted, (r) => r.n / r.s, (r) => r.ms.dfQ),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function fitAll(units) {
|
|
218
|
+
const byRepo = new Map();
|
|
219
|
+
for (const u of units) {
|
|
220
|
+
const list = byRepo.get(u.repo);
|
|
221
|
+
if (list)
|
|
222
|
+
list.push(u);
|
|
223
|
+
else
|
|
224
|
+
byRepo.set(u.repo, [u]);
|
|
225
|
+
}
|
|
226
|
+
const repos = [...byRepo].map(([repo, us]) => fitRepo(repo, us));
|
|
227
|
+
return { repos, fitted: repos.filter((r) => r.ms !== null) };
|
|
228
|
+
}
|
|
229
|
+
/** The pooled mean squares the fixed-repository t test reads, for one repository or more; null when none can be fitted.
|
|
230
|
+
* The seed rule and the sizer take their spreads from here, so they cannot drift from the test. */
|
|
231
|
+
export function pooledComponents(units) {
|
|
232
|
+
const { repos, fitted } = fitAll(units);
|
|
233
|
+
if (fitted.length === 0)
|
|
234
|
+
return null;
|
|
235
|
+
return { repos: repos.map(({ k, s, n }) => ({ k, s, n })), ...poolMeanSquares(fitted) };
|
|
236
|
+
}
|
|
237
|
+
// Variance of the mean of the G repository estimates, with Satterthwaite df. Every repository adds its own
|
|
238
|
+
// coefficients (fitted or not); the mean squares are pooled over the fitted ones, weighted by df.
|
|
239
|
+
function varianceOf(repos, fitted) {
|
|
240
|
+
const g = repos.length;
|
|
241
|
+
const { F, Q, E, dfF, dfQ, dfE, sBar, kBar } = poolMeanSquares(fitted);
|
|
242
|
+
const useQ = Q > E;
|
|
243
|
+
let [cF, cQ, cE] = [0, 0, 0];
|
|
244
|
+
for (const r of repos) {
|
|
245
|
+
const family = 1 / (sBar * r.k);
|
|
246
|
+
cF += family;
|
|
247
|
+
cE += 1 / r.n - family;
|
|
248
|
+
if (useQ) {
|
|
249
|
+
const seed = 1 / (kBar * r.s);
|
|
250
|
+
cQ += seed;
|
|
251
|
+
cE -= seed;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const terms = [[(cF * F) / (g * g), dfF], [(cQ * Q) / (g * g), dfQ], [(cE * E) / (g * g), dfE]]
|
|
255
|
+
.filter(([x]) => x !== 0);
|
|
256
|
+
const v = sum(terms.map(([x]) => x));
|
|
257
|
+
if (v > 0)
|
|
258
|
+
return { v, df: (v * v) / sum(terms.map(([x, d]) => (x * x) / d)) };
|
|
259
|
+
return { v: (cF * F) / (g * g), df: dfF };
|
|
260
|
+
}
|
|
261
|
+
/** Mean of the repository estimates with repositories held fixed: the spread is family and seed variation inside each
|
|
262
|
+
* (additive model y = mu + a_f + b_s), pooled over fitted repositories (two or more families and seeds in
|
|
263
|
+
* one connected block, one residual df); a thinner or split one adds its mean and borrows the pooled spread.
|
|
264
|
+
* Fewer than two repositories or none fitted: NaN. */
|
|
265
|
+
export function fixedRepositoryT(units, nullValue = 0) {
|
|
266
|
+
if (units.some((u) => !Number.isFinite(u.value)))
|
|
267
|
+
return notANumber(nullValue, 0);
|
|
268
|
+
const { repos, fitted } = fitAll(units);
|
|
269
|
+
if (repos.length < 2 || fitted.length === 0)
|
|
270
|
+
return notANumber(nullValue, 0);
|
|
271
|
+
const { v, df } = varianceOf(repos, fitted);
|
|
272
|
+
return tResult(sum(repos.map((r) => r.est)) / repos.length, Math.sqrt(v), df, nullValue);
|
|
273
|
+
}
|
|
274
|
+
/** The pooled ratio sum(t) / sum(c) against 1; its spread is fixedRepositoryT on the residuals (t - R c) / mean(c).
|
|
275
|
+
* The interval is on the log scale (`se` too): with skewed costs the symmetric R +- t se passed 5.2-5.6% at a true
|
|
276
|
+
* 1.10, over the 5% bar, and the log form passed 3.2-4.7%. */
|
|
277
|
+
export function fixedRepositoryRatioT(cells) {
|
|
278
|
+
const [totalT, totalC] = [sum(cells.map((x) => x.t)), sum(cells.map((x) => x.c))];
|
|
279
|
+
if (!(totalT > 0 && totalC > 0))
|
|
280
|
+
return notANumber(1, 0);
|
|
281
|
+
const ratio = totalT / totalC;
|
|
282
|
+
const cBar = totalC / cells.length;
|
|
283
|
+
const residuals = cells.map(({ repo, family, seed, t, c }) => ({ repo, family, seed, value: (t - ratio * c) / cBar }));
|
|
284
|
+
const { se, df } = fixedRepositoryT(residuals, 0);
|
|
285
|
+
if (se === undefined || df === undefined || !Number.isFinite(se))
|
|
286
|
+
return notANumber(1, 0);
|
|
287
|
+
const log = tResult(Math.log(ratio), se / ratio, df, 0);
|
|
288
|
+
return { ...log, estimate: ratio, low: Math.exp(log.low), high: Math.exp(log.high), nullValue: 1 };
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=repository-t.js.map
|
|
@@ -59,14 +59,8 @@ block has appeared in this session, run this at the start of a task:
|
|
|
59
59
|
hippo context --auto --budget 1500
|
|
60
60
|
\`\`\`
|
|
61
61
|
|
|
62
|
-
When you find out why something failed, record it right then, while you
|
|
63
|
-
work, never as a closing step:
|
|
64
|
-
\`\`\`bash
|
|
65
|
-
hippo remember "<what went wrong and why>" --error
|
|
66
|
-
\`\`\`
|
|
67
|
-
|
|
68
62
|
The installed hooks store failed tool calls and capture the session when it
|
|
69
|
-
ends, so there is nothing to run
|
|
63
|
+
ends, so there is nothing to record or run by hand.
|
|
70
64
|
`.trim(),
|
|
71
65
|
},
|
|
72
66
|
'codex': {
|
|
@@ -112,6 +106,7 @@ hippo capture --stdin <<< '<decisions, errors, lessons: 2-5 bullets>'
|
|
|
112
106
|
// when a block changes.
|
|
113
107
|
const SHIPPED_HOOK_HASHES = new Map([
|
|
114
108
|
['c80e760208aed70f6094757736b9a2f496ba5c30d88bc2a7ae3e128b403dcc6b', 'claude-code'],
|
|
109
|
+
['75937be6b7fdc2b87bcb08b7fec56757808075db129d99eff3e9f769f80a7781', 'claude-code'],
|
|
115
110
|
['f1e5815a4b7205c43e2db792215df1943e7853635a1e0f4561b150a41b756451', 'codex'],
|
|
116
111
|
['c04e48f2896a4fee9ae98f8f832e2d26a3910269df3beb5bcd6baee3cd9db68e', 'claude-code'],
|
|
117
112
|
['e6b12bd8983c032e5ca8e95a97aeff4178a5a05026d10acad5b2e1b25d5656dd', 'claude-code'],
|
package/dist/util/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Single source of truth for the package version, written by scripts/sync-version.mjs; never edit by hand. Read by the
|
|
3
3
|
* db rollback guard, /health, MCP.
|
|
4
4
|
* A constant, not a runtime package.json read: the published bundle may lack package.json on a path ESM can resolve. */
|
|
5
|
-
export declare const PACKAGE_VERSION = "2.
|
|
5
|
+
export declare const PACKAGE_VERSION = "2.3.0";
|
|
6
6
|
/** The floor a store takes on its first expiring key: the first release with schema
|
|
7
7
|
* v53, set by hand in that release; scripts/check-expiring-keys-floor.mjs gates it. */
|
|
8
8
|
export declare const EXPIRING_KEYS_MIN_BINARY = "1.64.0";
|
package/dist/util/version.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Single source of truth for the package version, written by scripts/sync-version.mjs; never edit by hand. Read by the
|
|
3
3
|
* db rollback guard, /health, MCP.
|
|
4
4
|
* A constant, not a runtime package.json read: the published bundle may lack package.json on a path ESM can resolve. */
|
|
5
|
-
export const PACKAGE_VERSION = '2.
|
|
5
|
+
export const PACKAGE_VERSION = '2.3.0';
|
|
6
6
|
/** The floor a store takes on its first expiring key: the first release with schema
|
|
7
7
|
* v53, set by hand in that release; scripts/check-expiring-keys-floor.mjs gates it. */
|
|
8
8
|
export const EXPIRING_KEYS_MIN_BINARY = '1.64.0';
|