feat(research): retain exact experiment and report citations in findings
This commit is contained in:
parent
46a4f13acd
commit
06039d17ba
36 changed files with 4170 additions and 253 deletions
|
|
@ -2,8 +2,11 @@ import { useEffect, useRef, useState } from 'react';
|
|||
import { Link, useParams } from 'react-router-dom';
|
||||
import type { ChronologicalValidationActionReceipt } from '@stock-bot/stock-config/chronological-validation';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { chronologicalFindingSource } from '@/features/research/components/findingSources';
|
||||
import { useUnsavedWarning } from '@/features/strategies/components/useUnsavedWarning';
|
||||
import { ExperimentCounts } from './components/ExperimentCounts';
|
||||
import { RegimeEvidenceUnavailable } from './components/RegimeEvidenceUnavailable';
|
||||
import { SourceFindingAction } from './components/SourceFindingAction';
|
||||
import { ValidationEvidence } from './components/ValidationEvidence';
|
||||
import {
|
||||
chronologicalValidationDurableApi,
|
||||
|
|
@ -24,6 +27,7 @@ type Intent =
|
|||
key: string;
|
||||
};
|
||||
function ValidationDetail({ validationId }: { validationId: string }) {
|
||||
const [findingDirty, setFindingDirty] = useState(false);
|
||||
const alive = useRef(false),
|
||||
pending = useRef(false),
|
||||
reading = useRef(true),
|
||||
|
|
@ -195,6 +199,22 @@ function ValidationDetail({ validationId }: { validationId: string }) {
|
|||
<div
|
||||
className="h-full overflow-auto p-1 space-y-4"
|
||||
onClickCapture={event => {
|
||||
const findingLink = (event.target as HTMLElement).closest('a');
|
||||
if (
|
||||
findingLink &&
|
||||
(!findingLink.target || findingLink.target === '_self') &&
|
||||
findingDirty &&
|
||||
!event.ctrlKey &&
|
||||
!event.metaKey &&
|
||||
!event.shiftKey &&
|
||||
!window.confirm(
|
||||
'Leave this finding draft? The previous request may already have saved if its response was lost. Inspect saved records before submitting again.'
|
||||
)
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (
|
||||
(event.target as HTMLElement).closest('a') &&
|
||||
captured.current &&
|
||||
|
|
@ -270,6 +290,15 @@ function ValidationDetail({ validationId }: { validationId: string }) {
|
|||
)}
|
||||
{validation && (
|
||||
<>
|
||||
<RegimeEvidenceUnavailable />
|
||||
{!validation.report && (
|
||||
<SourceFindingAction
|
||||
source={null}
|
||||
disabled
|
||||
onDirtyChange={setFindingDirty}
|
||||
unavailable="Save the complete report before linking its evidence to a research finding."
|
||||
/>
|
||||
)}
|
||||
<p className="font-semibold">
|
||||
{validation.report
|
||||
? 'Execution complete · report saved'
|
||||
|
|
@ -481,6 +510,13 @@ function ValidationDetail({ validationId }: { validationId: string }) {
|
|||
{validation.report && (
|
||||
<section aria-label="Saved validation report" className="space-y-3">
|
||||
<h2 className="font-semibold">Saved validation report</h2>
|
||||
<SourceFindingAction
|
||||
key={validation.report.reportHash}
|
||||
source={chronologicalFindingSource(validation)}
|
||||
disabled={loading || busy || Boolean(intent)}
|
||||
onDirtyChange={setFindingDirty}
|
||||
unavailable="A sealed report is required to cite this source."
|
||||
/>
|
||||
<p className="break-all text-xs">
|
||||
Report {validation.report.id} · {validation.report.reportHash} ·{' '}
|
||||
{validation.report.createdAt} · {validation.report.principal}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|||
import { Link, useParams } from 'react-router-dom';
|
||||
import type { ExperimentTrial } from '@stock-bot/stock-config/experiments';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { experimentFindingSource } from '@/features/research/components/findingSources';
|
||||
import { useUnsavedWarning } from '@/features/strategies/components/useUnsavedWarning';
|
||||
import { ExperimentCounts } from './components/ExperimentCounts';
|
||||
import { ExperimentInputs } from './components/ExperimentInputs';
|
||||
import { ExperimentTrialRecovery } from './components/ExperimentTrialRecovery';
|
||||
import { RegimeEvidenceUnavailable } from './components/RegimeEvidenceUnavailable';
|
||||
import { SourceFindingAction } from './components/SourceFindingAction';
|
||||
import { metricText } from './components/trialMetricText';
|
||||
import {
|
||||
experimentApi,
|
||||
|
|
@ -17,6 +20,7 @@ export function ExperimentDetailPage() {
|
|||
return <ExperimentDetailView key={experimentId} experimentId={experimentId} />;
|
||||
}
|
||||
function ExperimentDetailView({ experimentId }: { experimentId: string }) {
|
||||
const [findingDirty, setFindingDirty] = useState(false);
|
||||
const alive = useRef(false);
|
||||
const pending = useRef(false);
|
||||
const reading = useRef(true);
|
||||
|
|
@ -135,6 +139,22 @@ function ExperimentDetailView({ experimentId }: { experimentId: string }) {
|
|||
<div
|
||||
className="h-full overflow-auto space-y-5 p-1"
|
||||
onClickCapture={event => {
|
||||
const findingLink = (event.target as HTMLElement).closest('a');
|
||||
if (
|
||||
findingLink &&
|
||||
(!findingLink.target || findingLink.target === '_self') &&
|
||||
findingDirty &&
|
||||
!event.ctrlKey &&
|
||||
!event.metaKey &&
|
||||
!event.shiftKey &&
|
||||
!window.confirm(
|
||||
'Leave this finding draft? The previous request may already have saved if its response was lost. Inspect saved records before submitting again.'
|
||||
)
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (
|
||||
(event.target as HTMLElement).closest('a') &&
|
||||
retryIntents.length > 0 &&
|
||||
|
|
@ -181,6 +201,14 @@ function ExperimentDetailView({ experimentId }: { experimentId: string }) {
|
|||
{experiment && (
|
||||
<>
|
||||
<ExperimentCounts experiment={experiment} />
|
||||
<RegimeEvidenceUnavailable />
|
||||
<SourceFindingAction
|
||||
key={`experiment:${experiment.id}:${experiment.previewHash}`}
|
||||
source={experimentFindingSource(experiment)}
|
||||
disabled={loading || mutating || retryIntents.length > 0}
|
||||
onDirtyChange={setFindingDirty}
|
||||
unavailable="Only explicitly standalone experiments can be cited here. Use the saved chronological or walk-forward report for validation evidence."
|
||||
/>
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<Link
|
||||
className="text-primary-500 text-sm"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ import { useEffect, useRef, useState } from 'react';
|
|||
import { Link, useParams } from 'react-router-dom';
|
||||
import type { WalkForwardReceipt } from '@stock-bot/stock-config/walk-forward';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { walkForwardFindingSource } from '@/features/research/components/findingSources';
|
||||
import { useUnsavedWarning } from '@/features/strategies/components/useUnsavedWarning';
|
||||
import { RegimeEvidenceUnavailable } from './components/RegimeEvidenceUnavailable';
|
||||
import { SourceFindingAction } from './components/SourceFindingAction';
|
||||
import { ValidationEvidence } from './components/ValidationEvidence';
|
||||
import {
|
||||
walkForwardApi,
|
||||
|
|
@ -16,6 +19,7 @@ export function WalkForwardDetailPage() {
|
|||
}
|
||||
type Intent = { id: string; body: { previewHash: string }; key: string };
|
||||
function WalkForwardDetail({ walkForwardId }: { walkForwardId: string }) {
|
||||
const [findingDirty, setFindingDirty] = useState(false);
|
||||
const alive = useRef(false),
|
||||
pending = useRef(false),
|
||||
reading = useRef(true),
|
||||
|
|
@ -170,6 +174,22 @@ function WalkForwardDetail({ walkForwardId }: { walkForwardId: string }) {
|
|||
<div
|
||||
className="h-full overflow-auto p-1 space-y-4"
|
||||
onClickCapture={event => {
|
||||
const findingLink = (event.target as HTMLElement).closest('a');
|
||||
if (
|
||||
findingLink &&
|
||||
(!findingLink.target || findingLink.target === '_self') &&
|
||||
findingDirty &&
|
||||
!event.ctrlKey &&
|
||||
!event.metaKey &&
|
||||
!event.shiftKey &&
|
||||
!window.confirm(
|
||||
'Leave this finding draft? The previous request may already have saved if its response was lost. Inspect saved records before submitting again.'
|
||||
)
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (
|
||||
(event.target as HTMLElement).closest('a') &&
|
||||
captured.current &&
|
||||
|
|
@ -239,6 +259,15 @@ function WalkForwardDetail({ walkForwardId }: { walkForwardId: string }) {
|
|||
)}
|
||||
{value && (
|
||||
<>
|
||||
<RegimeEvidenceUnavailable />
|
||||
{!value.report && (
|
||||
<SourceFindingAction
|
||||
source={null}
|
||||
disabled
|
||||
onDirtyChange={setFindingDirty}
|
||||
unavailable="Save the complete report before linking its evidence to a research finding."
|
||||
/>
|
||||
)}
|
||||
<p className="font-semibold">
|
||||
{value.report
|
||||
? 'Execution complete · walk-forward report saved'
|
||||
|
|
@ -348,6 +377,13 @@ function WalkForwardDetail({ walkForwardId }: { walkForwardId: string }) {
|
|||
{value.report && (
|
||||
<section aria-label="Saved walk-forward report" className="space-y-3">
|
||||
<h2 className="font-semibold">Saved walk-forward report</h2>
|
||||
<SourceFindingAction
|
||||
key={value.report.reportHash}
|
||||
source={walkForwardFindingSource(value)}
|
||||
disabled={loading || busy || Boolean(intent)}
|
||||
onDirtyChange={setFindingDirty}
|
||||
unavailable="A sealed report is required to cite this source."
|
||||
/>
|
||||
<p className="break-all">
|
||||
Report {value.report.id} · {value.report.createdAt} · Hash {value.report.reportHash}
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
export function RegimeEvidenceUnavailable() {
|
||||
return (
|
||||
<section aria-label="Regime evidence" className="text-sm space-y-1">
|
||||
<h2 className="font-semibold">Regime evidence unavailable</h2>
|
||||
<p>
|
||||
No versioned as-of regime annotations were retained for these results. Regime sample counts,
|
||||
unclassified samples and window coverage are unavailable.
|
||||
</p>
|
||||
<p>
|
||||
Strategy names, parameters and current market classifications do not establish historical
|
||||
regime evidence.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
import { useState } from 'react';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import type { FindingDraftSource } from '@/features/research/components/findingSources';
|
||||
import { SaveSourceFindingDialog } from '@/features/research/components/SaveFindingDialog';
|
||||
|
||||
export function SourceFindingAction({
|
||||
source,
|
||||
unavailable,
|
||||
disabled,
|
||||
onDirtyChange,
|
||||
}: {
|
||||
source: FindingDraftSource | null;
|
||||
unavailable: string;
|
||||
disabled?: boolean;
|
||||
onDirtyChange: (dirty: boolean) => void;
|
||||
}) {
|
||||
const [snapshot, setSnapshot] = useState<FindingDraftSource | null>(null);
|
||||
const eligible = source?.runs.some(run => run.metrics.length);
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={disabled || !eligible}
|
||||
onClick={() => {
|
||||
if (source && eligible) {
|
||||
setSnapshot(structuredClone(source));
|
||||
}
|
||||
}}
|
||||
>
|
||||
Save research finding
|
||||
</Button>
|
||||
{!eligible && (
|
||||
<p className="text-sm">
|
||||
{source
|
||||
? 'No completed, comparable measurements are available to cite yet.'
|
||||
: unavailable}
|
||||
</p>
|
||||
)}
|
||||
{snapshot && (
|
||||
<SaveSourceFindingDialog
|
||||
source={snapshot}
|
||||
onClose={() => setSnapshot(null)}
|
||||
onDirtyChange={onDirtyChange}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -144,7 +144,11 @@ const trial = candidate.extend({
|
|||
unavailable: z.record(z.string()).nullable(),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
const detail = summary.extend({ preview, trials: z.array(trial).max(MAX_EXPERIMENT_TRIALS) });
|
||||
const detail = summary.extend({
|
||||
standalone: z.boolean().optional(),
|
||||
preview,
|
||||
trials: z.array(trial).max(MAX_EXPERIMENT_TRIALS),
|
||||
});
|
||||
const retryReceipt = z.object({
|
||||
id: z.string().uuid(),
|
||||
experimentId: z.string().uuid(),
|
||||
|
|
@ -219,6 +223,7 @@ const costPreview = preview
|
|||
.strict();
|
||||
const costDetail = summary.extend({
|
||||
kind: z.literal('cost-sensitivity'),
|
||||
standalone: z.boolean().optional(),
|
||||
preview: z.unknown(),
|
||||
trials: z.array(trial.extend({ costs: costScenarioSchema })).max(MAX_EXPERIMENT_TRIALS),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue