Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

W7: the journal shows the newest cached grade_takes verdict per prediction (W6), with judge_measured

garrytan16948de682c5
diff --git a/docs/designs/FORECAST_JOURNAL.md b/docs/designs/FORECAST_JOURNAL.md
index b0419907e0..183b5964c2 100644
--- a/docs/designs/FORECAST_JOURNAL.md
+++ b/docs/designs/FORECAST_JOURNAL.md
@@ -58,7 +58,7 @@ A recorded time is certified only where `coverageAt` certifies that instant, whi
- its state: `resolved`, `overdue`, `open` or `undated`;
- its resolution: quality, `resolved_by` and `resolved_source`.
-It filters by `--holder`, `--about <slug-prefix>`, `--state`, `--since`, `--until` and `--source-id`, and `--limit` caps the list. The totals always count every match, so the unresolved denominator survives any filter on state or limit. A thin client refuses it as host-bound. There is no MCP op. The grade verdict cached by `gbrain takes grades` (W6, #6882) joins the entry once W6 lands.
+It filters by `--holder`, `--about <slug-prefix>`, `--state`, `--since`, `--until` and `--source-id`, and `--limit` caps the list. The totals always count every match, so the unresolved denominator survives any filter on state or limit. A thin client refuses it as host-bound. There is no MCP op. Each entry also carries `grade`: the newest verdict `grade_takes` cached for the take (W6, the one `gbrain takes grades` lists), applied or not, with `judge_measured` saying whether the W6 eval measured its judge and prompt.
## Slice 3: `takes_scorecard {group_by}`
diff --git a/src/commands/takes.ts b/src/commands/takes.ts
index be9179cb57..1d61787e44 100644
--- a/src/commands/takes.ts
+++ b/src/commands/takes.ts
@@ -942,7 +942,8 @@ async function cmdJournal(engine: BrainEngine, args: string[]): Promise<void> {
const horizon = e.horizon ? `${e.horizon.date} (${e.horizon.basis})` : 'none';
const weight = e.weight === null ? '' : ` w=${e.weight.toFixed(2)}`;
const resolution = e.resolution ? ` resolved ${e.resolution.quality}${e.resolution.resolved_at ? ` ${e.resolution.resolved_at.slice(0, 10)}` : ''}${e.resolution.resolved_by ? ` by ${e.resolution.resolved_by}` : ''}` : '';
- console.log(`\n[${e.state}] ${e.page_slug}#${e.row_num} ${e.holder}${weight} predicted ${predicted} horizon ${horizon}${resolution}\n ${e.claim}`);
+ const grade = e.grade ? ` grade ${e.grade.verdict} @ ${e.grade.confidence.toFixed(2)}${e.grade.applied ? ' applied' : ''}${e.grade.judge_measured ? '' : ' (judge not measured)'}` : '';
+ console.log(`\n[${e.state}] ${e.page_slug}#${e.row_num} ${e.holder}${weight} predicted ${predicted} horizon ${horizon}${resolution}${grade}\n ${e.claim}`);
}
if (journal.entries.length < (state ? t[state as 'resolved'] : t.predictions)) console.log(`\nShowing ${journal.entries.length}; the totals count every match.`);
}
diff --git a/src/core/forecast-journal.ts b/src/core/forecast-journal.ts
index c54a8f348b..7eb082b11c 100644
--- a/src/core/forecast-journal.ts
+++ b/src/core/forecast-journal.ts
@@ -20,6 +20,7 @@
import type { BrainEngine } from './engine.ts';
import { coverageAt, coverageIntervals } from './belief/coverage-report.ts';
import { takeClaimHash } from './belief/keys.ts';
+import { gradeJudgeMeasured } from './cycle/grade-takes-measured.ts';
import { readTakeHorizons, type HorizonBasis } from './takes-horizon.ts';
export type JournalState = 'resolved' | 'overdue' | 'open' | 'undated';
@@ -30,6 +31,8 @@ export interface JournalEntry {
horizon: { date: string; basis: HorizonBasis; current: true } | null;
state: JournalState;
resolution: { quality: string; resolved_at: string | null; resolved_by: string | null; resolved_source: string | null } | null;
+ /** The newest cached grade_takes verdict (W6), applied or not; judge_measured says whether the W6 eval measured its judge and prompt. */
+ grade: { verdict: string; confidence: number; applied: boolean; judge_model_id: string; judge_measured: boolean; graded_at: string } | null;
}
export interface JournalTotals { predictions: number; resolved: number; unresolved: number; open: number; overdue: number; undated: number; certified_prediction_times: number }
export interface JournalQuery {
@@ -138,6 +141,13 @@ export async function readForecastJournal(engine: BrainEngine, q: JournalQuery =
const rows = await readPredictions(engine, q);
const horizons = await readTakeHorizons(engine, rows.map(r => Number(r.id)));
const recorded = await recordedPredictionTimes(engine, rows);
+ const grades = new Map((await engine.executeRaw<{ take_id: number | string; verdict: string; confidence: number | string; applied: boolean; judge_model_id: string; prompt_version: string; graded_at: string | Date }>(
+ `SELECT DISTINCT ON (take_id) take_id, verdict, confidence, applied, judge_model_id, prompt_version, graded_at
+ FROM take_grade_cache WHERE take_id = ANY($1::bigint[]) ORDER BY take_id, graded_at DESC`,
+ [rows.map(r => Number(r.id))])).map(g => [Number(g.take_id), {
+ verdict: g.verdict, confidence: Number(g.confidence), applied: g.applied, judge_model_id: g.judge_model_id,
+ judge_measured: gradeJudgeMeasured(g.judge_model_id, g.prompt_version), graded_at: iso(g.graded_at)!,
+ }]));
const all: JournalEntry[] = rows.map(r => {
const h = horizons.get(Number(r.id));
const horizon = h?.current ? { date: h.horizon_date, basis: h.basis, current: true as const } : null;
@@ -148,6 +158,7 @@ export async function readForecastJournal(engine: BrainEngine, q: JournalQuery =
take_id: Number(r.id), source_id: r.source_id, page_slug: r.page_slug, row_num: r.row_num, claim: r.claim, kind: r.kind, holder: r.holder,
weight: r.weight == null ? null : Number(r.weight), prediction, horizon, state,
resolution: r.resolved_quality ? { quality: r.resolved_quality, resolved_at: iso(r.resolved_at), resolved_by: r.resolved_by, resolved_source: r.resolved_source } : null,
+ grade: grades.get(Number(r.id)) ?? null,
};
});
const count = (s: JournalState) => all.filter(e => e.state === s).length;
diff --git a/test/forecast-journal-cli.test.ts b/test/forecast-journal-cli.test.ts
index 5f32680a8e..4fce6fffa7 100644
--- a/test/forecast-journal-cli.test.ts
+++ b/test/forecast-journal-cli.test.ts
@@ -72,8 +72,11 @@ describe('gbrain takes journal', () => {
expect([overdue.entries.length, overdue.totals.predictions]).toEqual([1, 4]);
});
- test('the text form labels uncertified prediction times and prints the denominator', async () => {
+ test('the text form labels uncertified prediction times, prints the denominator and the newest cached grade', async () => {
+ await engine.executeRaw(`INSERT INTO take_grade_cache (take_id, prompt_version, judge_model_id, evidence_signature, verdict, confidence)
+ SELECT id, 'hybrid-evidence-v2', 'openai:some-unmeasured-model', 'sig', 'incorrect', 0.97 FROM takes WHERE claim LIKE 'Bluefin-example%'`);
const text = await capture(() => runTakes(engine, ['journal']));
+ expect(text).toContain('grade incorrect @ 0.97 (judge not measured)');
expect(text).toContain('4 predictions: 2 resolved, 2 unresolved (1 overdue, 1 open, 0 undated)');
expect(text).toContain('[overdue]');
expect(text).toContain('2023-06 (since_date, uncertified)');
diff --git a/test/forecast-journal.test.ts b/test/forecast-journal.test.ts
index bbc6aa1d12..daa596d263 100644
--- a/test/forecast-journal.test.ts
+++ b/test/forecast-journal.test.ts
@@ -45,6 +45,11 @@ for (const engineCase of testBackends().map(beliefEngineCase)) {
await b.put('companies/dune-example', takesPage([{ claim: 'Dune-example has the strongest team in its market', who: 'bob-example', since: '2024-02' }]));
await resolve(b, 'Acme-example will reach $5M ARR by the end of 2024', 'correct');
await scanStatedHorizons(b.engine, { apply: true, sourceId: b.sourceId });
+ const bluefinId = (await b.engine.executeRaw<{ id: number }>(`SELECT id FROM takes WHERE claim LIKE 'Bluefin-example%'`))[0]!.id;
+ for (const [model, at, verdict, confidence] of [['anthropic:claude-opus-5-5', '2026-10-01T00:00:00Z', 'unresolvable', 0.4], ['openai:some-unmeasured-model', '2026-10-10T00:00:00Z', 'incorrect', 0.97]] as const) {
+ await b.engine.executeRaw(`INSERT INTO take_grade_cache (take_id, prompt_version, judge_model_id, evidence_signature, graded_at, verdict, confidence)
+ VALUES ($1, 'hybrid-evidence-v2', $2, 'sig', $3::timestamptz, $4, $5)`, [bluefinId, model, at, verdict, confidence]);
+ }
const j = await readForecastJournal(b.engine, { sourceId: b.sourceId, asOf: AS_OF });
expect(j.totals).toEqual({ predictions: 4, resolved: 1, unresolved: 3, open: 1, overdue: 1, undated: 1, certified_prediction_times: 0 });
@@ -53,7 +58,9 @@ for (const engineCase of testBackends().map(beliefEngineCase)) {
horizon: { date: '2024-12-31', basis: 'stated', current: true },
resolution: { quality: 'correct', resolved_by: 'owner', resolved_source: 'notes/2025-03-01-update' },
prediction: { at: '2023-02', basis: 'since_date', certified: false } });
- expect(by['companies/bluefin-example']).toMatchObject({ state: 'overdue', horizon: { date: '2025-06-30' }, resolution: null });
+ expect(by['companies/bluefin-example']).toMatchObject({ state: 'overdue', horizon: { date: '2025-06-30' }, resolution: null,
+ grade: { verdict: 'incorrect', confidence: 0.97, applied: false, judge_model_id: 'openai:some-unmeasured-model', judge_measured: false, graded_at: '2026-10-10T00:00:00.000Z' } });
+ expect(by['companies/acme-example']!.grade).toBeNull();
expect(by['companies/cobalt-example']).toMatchObject({ state: 'open', horizon: { date: '2030-12-31' } });
expect(by['companies/dune-example']).toMatchObject({ state: 'undated', horizon: null });