feat: ε-greedy v1 as active policy; dwell-time reward inference; offline sim framework
- Promote egreedy-v1 to active serving policy (ADR-0007): /score/egreedy + /reward/egreedy
replaces linucb-v1 endpoints after offline sim shows +10.7% mean reward (−0.548 vs −0.606)
- Replace explicit helpful/not_helpful feedback with dwell-time inferred reward (inferReward):
dismiss=−1.0, snooze=+0.1, done<15s=−0.3, done 15s–2min=+1.0, done 2–10min=+0.6, done>10min=+0.3
- Add ml/serving ε-greedy endpoints: /score/egreedy, /reward/egreedy, /stats/egreedy/{user_id}
with d=7 feature vector (base 5 + sin/cos day-of-week encoding)
- Add offline simulation framework (ml/experiments/sim): rule/LLM/claude-code judges,
two-phase score+reward, synthetic personas, task generator; results stored in sim_runs/sim_events
- Add /admin/simulations page: start runs, live-poll status, reward curve SVG, action/persona tables
- Fix egreedy day_of_week training skew: reward endpoint now uses actual dow instead of hardcoded 0
- Fix runner.py proxy bypass: httpx.Client(trust_env=False) for localhost ML calls
- Add dwellMs to TipFeedbackEvent contract and bus.test.ts fixture
- Schema: sim_runs, sim_events tables; tip_feedback gains dwell_ms, reward_milli columns
- ADR-0006: admin console framework; ADR-0007: egreedy-v1 policy selection rationale
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,10 +12,14 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"type-check": "tsc --noEmit",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.3"
|
||||
"@vitest/coverage-v8": "^4.1.4",
|
||||
"typescript": "^5.7.3",
|
||||
"vitest": "^4.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
40
packages/shared-types/src/__tests__/tip.test.ts
Normal file
40
packages/shared-types/src/__tests__/tip.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import type { Tip, TipFeedback, RecommendResponse } from '../index.js';
|
||||
|
||||
describe('Tip type contract', () => {
|
||||
it('accepts a valid Tip object', () => {
|
||||
const tip: Tip = {
|
||||
id: 'todoist:123',
|
||||
content: 'Finish the report',
|
||||
source: 'todoist',
|
||||
sourceId: '123',
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
expect(tip.source).toBe('todoist');
|
||||
});
|
||||
|
||||
it('accepts advice source without sourceId', () => {
|
||||
const tip: Tip = {
|
||||
id: 'advice:abc',
|
||||
content: 'Take a break',
|
||||
source: 'advice',
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
expect(tip.sourceId).toBeUndefined();
|
||||
});
|
||||
|
||||
it('RecommendResponse wraps a Tip', () => {
|
||||
const res: RecommendResponse = {
|
||||
tip: { id: 'x', content: 'Do it', source: 'todoist', createdAt: '' },
|
||||
};
|
||||
expect(res.tip.id).toBe('x');
|
||||
});
|
||||
|
||||
it('TipFeedback allows valid actions', () => {
|
||||
const actions: TipFeedback['action'][] = ['done', 'dismiss', 'snooze'];
|
||||
for (const action of actions) {
|
||||
const fb: TipFeedback = { action };
|
||||
expect(fb.action).toBe(action);
|
||||
}
|
||||
});
|
||||
});
|
||||
9
packages/shared-types/vitest.config.ts
Normal file
9
packages/shared-types/vitest.config.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
exclude: ['dist/**', 'node_modules/**'],
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user