stock-bot/docs/development/backlog/tasks/R03.md

4.9 KiB

R03 — Add projects, hypotheses and evidence-linked findings APIs

Parent epic: E6. Priority/severity: P1 / High. Relative complexity: M. Recommended specialization: Full-stack research product.

Scheduling source of truth: manifest entry R03. No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.

Evidence and root cause

Intended behavior and implementation scope

Add minimal project/hypothesis/note/finding metadata with human/AI authorship and immutable evidence references. Findings refer to runId + metricsVersion + metricPath (and optional immutable artifact ID); the API derives displayed measured values from retained results instead of maintaining another metric truth/validation subsystem. Narrative conclusions may be wrong and must remain distinguishable from referenced measurements.

Exclusions

No general workflow framework, browser IDE, multi-tenant identity platform or second simulator.

Likely files and ownership

  • database/postgres/init/ (new migration)
  • apps/stock/web-api/src/routes/ (research endpoints)
  • apps/stock/web-api/src/services/ (research service)
  • libs/core/types/src/research.ts (new)

Write locks: sql-migrations, research-api. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

Implementation requires R01, R10 integrated.

Architecture decisions: ADR-006. Agents may not independently amend their policies.

Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.

Acceptance criteria

  • AI-created hypotheses/notes are labelled unvalidated until explicit validation evidence/review exists.
  • Evidence references must resolve to retained run/artifact and known metric version/path; dangling references reject. No new simulator or narrative fact-checking subsystem.
  • Archiving metadata does not delete cited runs; narrative changes create a revision while underlying results remain immutable.

Mandatory tests

  • hypothesis_vs_evidence, evidence_fk_integrity, authorship_audit, cited_metric_matches_run.
  • Migration upgrade fixture retains existing runs/results.

Apply the relevant quality gates; submit exact commands, outcomes and skipped checks. Named cases above are required regression scenarios, not claims that those tests already exist.

Regression risks and rollback

Schema/API backward compatibility, historical provenance and UI state regression. Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.

Web/API contract and user states

  • API: /api/v2/research-projects, /hypotheses, /analysis-artifacts with explicit evidence references and archive actions.
  • Backend/data dependencies: New metadata tables; reuse existing run/result IDs and strategy/version IDs.
  • Loading/error/empty behavior: Typed404/409/422, empty evidence lists and explicit unvalidated state; R04 supplies UI.
  • User-facing completion is demonstrated by the acceptance criteria and interaction tests above; a backend-only implementation is insufficient where a UI is in scope.

Handoff

Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.