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

19 lines
3.3 KiB
Markdown

# RP25 — Reopen retained research artifacts through the typed AI client
Parent E12. Priority P2 / Medium workflow gap. Complexity S. Dependencies A03, RP23. Owner continuation authorizes implementation and commits; all seven conditional tasks remain deferred.
Verified baseline: `ResearchClient.saveFinding` creates a finding but exposes no artifact/history reads. RP23's authenticated workflow therefore reopens it with a raw transport call. The existing API already provides `GET /analysis-artifacts/:id` and `GET /analysis-artifacts/:id/revisions`, with completed-result evidence resolution and authenticated research read access. Immutable revision IDs already exist.
Scope: add `artifact(id, signal?)` and `artifactRevisions(id, signal?)` to the existing client. Decode retained artifact/revision identity, authorship, source, evidence, units and availability. Reading supports operator/service/agent authorship, human/AI/unknown origin, notes, canonical evidence and qualified legacy evidence. Keep the strict AI/canonical creation response contract intact. Validate requested artifact/parent identities and unique history revision IDs/ordinals; do not silently substitute latest for a requested historical revision. No new endpoint, schema migration, financial calculation or generic client framework.
Affected files: `scripts/research-client.ts`, `scripts/test/research-client.test.ts`, `test/postgres/ai-research-workflow.test.ts`, existing README usage. The caller chooses an exact saved revision ID from the returned verified history; this task does not implement automatic cycle resume or non-idempotent replay.
Acceptance and tests:
- A saved finding can be reopened and its original immutable revision selected after a subsequent human revision. Preserve original AI authorship, source and exact server-resolved evidence; expose the new revision's actual authorship without relabeling either narrative validated.
- Notes with no evidence and legacy references with explicit limitations remain readable. Canonical/legacy metric identities, availability, units and result/engine labels remain coherent. Invalid artifact IDs fail before transport; wrong returned artifact/parent, malformed envelopes/evidence and duplicate revision identities fail as read errors without retries or writes.
- Both methods use authenticated GET only, preserve the existing abort/deadline/HTTP-error behavior and never admit jobs. Existing strict creation and cycle/journal tests remain green.
- Extend the actual disposable PostgreSQL/native workflow by reusing completed runs and findings. Reopen via the new methods, create a fixture-only human revision with existing service behavior, retrieve exact old/new revisions, compare evidence and show unchanged run counts. Revoked credentials must fail reads. No real study records are edited.
- Run focused client/cycle and complete tooling tests, authored/application types, contracts, scoped lint/formatting, secrets and the actual PostgreSQL AI workflow. No native/web rebuild or browser change is required for this client-only addition.
Definition of done: reproduce the missing client capability, implement the two existing API reads, review canonical versus legacy and read versus creation boundaries, pass relevant checks, document exact-revision usage, update task state and commit. No new architecture decision is needed.