feat: show the conversation evidence behind each learning trajectory

Reviewers were asked to include or exclude learning trajectories while
only seeing metadata — credit class, confidence, status. The decisions
and their redacted context turns were already captured and stored, but
no endpoint returned them, so the evidence was unreachable from the UI.

Add GET /api/learning/trajectories/:id and an expandable row on the
learning page that fetches on demand.

Also widen SentMessageSchema to accept matrixEventId, imageOutcomeCredit
and imageOutcomeAt. The learning loop added these to SentMessageRecord
and they flow out of /api/messages, but the strict contract rejected
them, breaking the dashboard.

Enable generation with shadow mode off so eligible examples reach reply
prompts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jamie BruntonandClaude Opus 5 committed 2026-08-12 08:23:22 +01:00
1 parent 687abab82b
commit 142378df33
25 files changed
+836 -28

No files matched your search

+42 -1
View File
@@ -1,7 +1,7 @@
import express from 'express';
import type { AddressInfo } from 'node:net';
import { afterEach, describe, expect, it } from 'vitest';
import { StatsResponseSchema } from '../../packages/api-contracts/src/index.js';
import { MessagesResponseSchema, StatsResponseSchema } from '../../packages/api-contracts/src/index.js';
import type { WebContext } from '../../src/web/context.js';
import { createStatsRouter } from '../../src/web/routes/stats.js';
@@ -95,3 +95,44 @@ describe('stats route account status', () => {
expect(stats.accounts[1]?.invitationCooldown).not.toHaveProperty('setAt');
});
});
describe('messages route contract', () => {
it('accepts the attribution fields the learning loop adds to sent messages', async () => {
const context = {
services: {},
repos: {
messages: {
getRecent: () => [{
id: 1,
postId: 'p1',
recipient: 'someone',
subject: 'hey',
message: 'hello there',
sentAt: 1_700_000_000_000,
gotResponse: true,
gotImage: true,
responseCheckedAt: 1_700_000_100_000,
strategyId: null,
chatRoomId: '!room:reddit.com',
// Added by the conversation learning loop; must not break the dashboard.
matrixEventId: '$opener1',
imageOutcomeCredit: 'human-created-success',
imageOutcomeAt: 1_700_000_200_000,
}],
},
},
activity: { recent: () => [], totalProcessed: () => 0 },
getBotRunning: () => true,
getBotMode: () => 'running',
getMessagesThisHour: () => 0,
} as unknown as WebContext;
const app = express().use('/api', createStatsRouter(context));
const response = await request(app, '/api/messages');
const messages = MessagesResponseSchema.parse(await response.json());
expect(messages[0]?.matrixEventId).toBe('$opener1');
expect(messages[0]?.imageOutcomeCredit).toBe('human-created-success');
expect(messages[0]?.imageOutcomeAt).toBe(1_700_000_200_000);
});
});