Files
PaperClipAI/ui/src/api/decisionTraining.ts
T
DottaandPaperclip 051ae4d102 feat: restore decision training library and inspector (#9779)
## Thinking Path

> - Paperclip is the open source control plane people use to manage
AI-agent companies and supervise governed work.
> - Decisions capture high-value operator judgment, and the
decision-training foundation merged in #9702 freezes that evidence for
later evaluation and learning.
> - Operators still need the UI from the closed stacked PR #9718 to
intentionally capture examples and inspect the resulting dataset.
> - GitHub automatically closed #9718 when its stacked base branch was
deleted after #9702 merged, leaving the server foundation on `master`
without the corresponding UI.
> - This pull request restores the final UI and its still-required
supporting API fields directly on current `master`, while excluding the
obsolete migration and duplicated server-foundation diffs.
> - The benefit is a reviewable replacement PR that preserves the
completed decision-training workflow without replaying stale stack
history.

## Linked Issues or Issue Description

- Refs #9718
- Refs #9702

## What Changed

- Restored the top-level `/training` library and record inspector with
search, filters, JSONL export, notes editing, and evidence tabs.
- Restored the Decisions-row training affordance and capture drawer,
including preview, provenance, deletion, cache refresh, and approval
consistency behavior.
- Restored the shared types and focused server support needed by the UI
without reintroducing decision-training migrations or the already-merged
server foundation.
- Restored focused UI and attention-service tests from the final #9718
state.
- Credit to the authors and reviewers of #9718; this recovery
transplants their final reviewed delta after the stacked base deletion.

## Verification

- `pnpm exec vitest run ui/src/pages/Training.test.tsx
ui/src/components/DecisionTrainingDrawer.test.tsx
ui/src/components/AttentionQueueRow.test.tsx
server/src/__tests__/attention-service.test.ts
server/src/__tests__/decision-training.test.ts` — 5 files, 48 tests
passed.
- `pnpm --filter @paperclipai/shared typecheck` — passed.
- `pnpm --filter @paperclipai/server typecheck` — passed.
- `pnpm --filter @paperclipai/ui typecheck` — passed.
- `pnpm exec vitest run server/src/__tests__/openapi-routes.test.ts` — 3
tests passed; confirms exact route/OpenAPI parity for the restored
preview endpoint.
- `pnpm check:token-gates` — the restored files are clean; the
repository-wide command currently reports five pre-existing false
positives where comments reference GitHub issue `#9627` as if it were a
color literal.

## Risks

- Low migration risk: this PR contains no database migrations and is
based directly on current `master`.
- The main behavioral risk is cache invalidation across Decisions and
Training views; focused tests cover capture, update, deletion, row
state, and approval refresh behavior.
- The token-gate baseline remains red on unrelated `#9627` comment
references; this PR does not modify those files.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- OpenAI Codex, GPT-5.3-Codex, reasoning with repository/tool access and
code execution. Context window not exposed by the runtime.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-07-17 13:27:32 -05:00

55 lines
2.0 KiB
TypeScript

import type {
DecisionTrainingExample,
DecisionTrainingPreview,
DecisionTrainingSourceKind,
} from "@paperclipai/shared";
import { api, type RequestOptions } from "./client";
export interface DecisionTrainingListItem {
example: DecisionTrainingExample;
issueTitle: string;
issueIdentifier: string;
}
export interface DecisionTrainingFilters {
project?: string;
kind?: DecisionTrainingSourceKind;
author?: string;
q?: string;
}
/** The durable (source + issue) target a training example anchors to. */
export interface DecisionTrainingTarget {
sourceKind: DecisionTrainingSourceKind;
sourceId: string;
issueId: string;
}
export const decisionTrainingApi = {
list: (companyId: string, filters: DecisionTrainingFilters = {}, options?: RequestOptions) => {
const params = new URLSearchParams();
if (filters.project) params.set("project", filters.project);
if (filters.kind) params.set("kind", filters.kind);
if (filters.author) params.set("author", filters.author);
if (filters.q) params.set("q", filters.q);
const query = params.toString();
return api.get<DecisionTrainingListItem[]>(
`/companies/${companyId}/decision-training${query ? `?${query}` : ""}`,
options,
);
},
get: (id: string, options?: RequestOptions) =>
api.get<DecisionTrainingExample>(`/decision-training/${id}`, options),
/**
* Preview the state a new example would freeze, without persisting it. Powers
* the create drawer's "state frozen with this example" panel.
*/
preview: (companyId: string, target: DecisionTrainingTarget) =>
api.post<DecisionTrainingPreview>(`/companies/${companyId}/decision-training/preview`, target),
create: (companyId: string, input: DecisionTrainingTarget & { notes: string }) =>
api.post<DecisionTrainingExample>(`/companies/${companyId}/decision-training`, input),
updateNotes: (id: string, notes: string) =>
api.patch<DecisionTrainingExample>(`/decision-training/${id}`, { notes }),
delete: (id: string) => api.delete<void>(`/decision-training/${id}`),
};