feat: time-aware Super Contexte synthesis

- knowledge.py: classify trades by maturity before building synthesis
  prompt; only mature trades (≥35% elapsed) contribute to P&L stats
  and conclusions; immature trades listed for transparency only
- Add 6h staleness gate on POST /synthesize (force=true to override)
- System prompt now includes hard timing rule: GPT-4o must not revise
  existing conclusions because of newly-added immature trades
- useApi.ts: useSynthesizeKnowledge accepts force boolean param
- SuperContexte.tsx: shows amber notice with age when skipped + offers
  "Force quand même" button; success banner uses new response shape

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-16 23:57:46 +02:00
parent 9075762dd5
commit 22687dfd03
3 changed files with 118 additions and 33 deletions

View File

@@ -526,11 +526,14 @@ export const useKnowledgeEntries = () =>
export const useSynthesizeKnowledge = () => {
const qc = useQueryClient()
return useMutation({
mutationFn: () => api.post('/knowledge/synthesize').then(r => r.data),
onSuccess: () => {
qc.invalidateQueries({ queryKey: ['knowledge-state'] })
qc.invalidateQueries({ queryKey: ['knowledge-history'] })
qc.invalidateQueries({ queryKey: ['knowledge-entries'] })
mutationFn: (force: boolean = false) =>
api.post(`/knowledge/synthesize${force ? '?force=true' : ''}`).then(r => r.data),
onSuccess: (_data) => {
if (!_data?.skipped) {
qc.invalidateQueries({ queryKey: ['knowledge-state'] })
qc.invalidateQueries({ queryKey: ['knowledge-history'] })
qc.invalidateQueries({ queryKey: ['knowledge-entries'] })
}
},
})
}

View File

@@ -187,9 +187,14 @@ export default function SuperContexte() {
const byCategory = entriesData?.by_category || {}
const totalEntries = entriesData?.total || 0
const handleSynthesize = () => {
synthesize.mutate(undefined, {
onSuccess: () => setSelectedHistoryId(null),
const synthResult = synthesize.data as any
const isSkipped = synthResult?.skipped === true
const handleSynthesize = (force = false) => {
synthesize.mutate(force, {
onSuccess: (data: any) => {
if (!data?.skipped) setSelectedHistoryId(null)
},
})
}
@@ -223,7 +228,7 @@ export default function SuperContexte() {
<Clock className="w-4 h-4" />
</button>
<button
onClick={handleSynthesize}
onClick={() => handleSynthesize()}
disabled={synthesize.isPending}
className="flex items-center gap-2 px-4 py-2 rounded-lg bg-violet-600 hover:bg-violet-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors text-sm font-medium"
>
@@ -290,15 +295,37 @@ export default function SuperContexte() {
</div>
)}
{synthesize.isSuccess && (
{synthesize.isSuccess && isSkipped && (
<div className="border border-amber-500/30 bg-amber-500/5 rounded-xl p-4 flex items-start gap-3">
<Clock className="w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5" />
<div className="flex-1 text-sm">
<span className="text-amber-300 font-medium">Synthèse non relancée. </span>
<span className="text-slate-400">
Dernière synthèse il y a {synthResult?.age_hours}h (moins de 6h).
Les trades immatures n'apportent pas encore d'information fiable inutile de recalculer.
</span>
<div className="mt-2">
<button
onClick={() => handleSynthesize(true)}
disabled={synthesize.isPending}
className="text-xs px-3 py-1.5 rounded-lg border border-amber-500/40 text-amber-400 hover:bg-amber-500/10 transition-colors"
>
Forcer quand même la synthèse
</button>
</div>
</div>
</div>
)}
{synthesize.isSuccess && !isSkipped && (
<div className="border border-emerald-500/30 bg-emerald-500/5 rounded-xl p-4 flex items-center gap-3">
<CheckCircle className="w-5 h-5 text-emerald-400 flex-shrink-0" />
<div className="text-sm">
<span className="text-emerald-300 font-medium">Synthèse complète. </span>
<span className="text-slate-400">
{(synthesize.data as any)?.kb_entries_added ?? 0} entrées KB ajoutées ·{' '}
{(synthesize.data as any)?.sources?.reports ?? 0} rapports ·{' '}
{(synthesize.data as any)?.sources?.trades ?? 0} trades analysés.
{synthResult?.kb_entries_added ?? 0} entrées KB ajoutées ·{' '}
{synthResult?.sources?.reports ?? 0} rapports ·{' '}
{synthResult?.sources?.trades ?? 0} trades analysés.
</span>
</div>
</div>