Eight sub-phases per docs/ticket-analyzer-phase2-spec.md:
2.1 Schema (migration 070): analyzer_stage_executions table; source_snapshot,
aggregate_fingerprint, fingerprint_generated_at columns on analyzer_analyses.
model_traces marked LEGACY (kept for back-compat).
2.2 Every pipeline stage records a row to analyzer_stage_executions, success
or failure. Worker persists a status='failed' analyzer_analyses row when
the pipeline throws so partial stage records have a parent. Pipeline
exposes raw triage/sonnet/opus responses for downstream stages.
2.3 Stage 3 prompt updated with markdown formatting rules + banned filler
phrases. Added react-markdown + remark-gfm + @tailwindcss/typography.
New <AnalysisMarkdown> component replaces <ProseText>; coerces stray
headers to bold paragraphs.
2.4 Stage 6 fingerprint (Haiku) runs after persistence, failure-tolerant.
scripts/backfill-fingerprints.ts reconstructs Stage 6 input from the
legacy model_traces blob.
2.5 Browse UI rebuild at /analyzer/tickets: multi-select for client/issue/
queue/status/priority/assignee, sticky filter bar, active-filter chips,
bulk selection persisted via localStorage, "Analyze N selected" +
"Generate aggregate report" actions. New <MultiSelect> primitive.
Staleness uses last_activity_date > completed_at heuristic per spec C.1.
2.6 Aggregate reports (migration 071): runner is fire-and-forget, persists
SQL distributions immediately so UI shows partial state during the
Sonnet reduce call. Three endpoints, three pages (/analyzer/reports[/new
/:id]). IT Glue context fetcher capped at 200 doc titles.
2.7 Cost guards (migration 072): per-request $5 confirmation, soft-warn at
$20/day, hard-block at $50/day with ANALYZER_DAILY_COST_OVERRIDE_USERS
override. Every gating decision audited.
2.8 Runbook + build notes updated.
128 vitest tests passing, tsc clean. Migrations 070/071/072 idempotent
(IF NOT EXISTS). model_traces double-write retained — drop in a future
migration once aggregate reports have soaked.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
146 lines
4.3 KiB
TypeScript
146 lines
4.3 KiB
TypeScript
'use client';
|
|
|
|
import { useMemo, useState } from 'react';
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from '@/components/ui/popover';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { ChevronDown, Search, X } from 'lucide-react';
|
|
|
|
export interface MultiSelectOption {
|
|
value: string;
|
|
label: string;
|
|
}
|
|
|
|
interface Props {
|
|
options: MultiSelectOption[];
|
|
value: string[];
|
|
onChange: (next: string[]) => void;
|
|
placeholder?: string;
|
|
searchPlaceholder?: string;
|
|
className?: string;
|
|
/** Hide the search box when option count is below this threshold. */
|
|
searchThreshold?: number;
|
|
/** Optional max-height for the option list (px). */
|
|
maxListHeight?: number;
|
|
}
|
|
|
|
export function MultiSelect({
|
|
options,
|
|
value,
|
|
onChange,
|
|
placeholder = 'Any',
|
|
searchPlaceholder = 'Search…',
|
|
className = '',
|
|
searchThreshold = 8,
|
|
maxListHeight = 300,
|
|
}: Props) {
|
|
const [open, setOpen] = useState(false);
|
|
const [search, setSearch] = useState('');
|
|
|
|
const valueSet = useMemo(() => new Set(value), [value]);
|
|
|
|
const filtered = useMemo(() => {
|
|
const s = search.trim().toLowerCase();
|
|
if (!s) return options;
|
|
return options.filter((o) => o.label.toLowerCase().includes(s));
|
|
}, [options, search]);
|
|
|
|
const selectedLabels = useMemo(() => {
|
|
if (value.length === 0) return null;
|
|
if (value.length === 1) {
|
|
return options.find((o) => o.value === value[0])?.label ?? value[0];
|
|
}
|
|
return `${value.length} selected`;
|
|
}, [value, options]);
|
|
|
|
function toggle(optValue: string) {
|
|
if (valueSet.has(optValue)) {
|
|
onChange(value.filter((v) => v !== optValue));
|
|
} else {
|
|
onChange([...value, optValue]);
|
|
}
|
|
}
|
|
|
|
function clear(e: React.MouseEvent) {
|
|
e.stopPropagation();
|
|
onChange([]);
|
|
}
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
className={`justify-between font-normal ${className}`}
|
|
>
|
|
<span className="truncate">
|
|
{selectedLabels ?? (
|
|
<span className="text-muted-foreground">{placeholder}</span>
|
|
)}
|
|
</span>
|
|
<span className="flex items-center gap-1 shrink-0 ml-2">
|
|
{value.length > 0 && (
|
|
<Badge
|
|
variant="secondary"
|
|
className="h-5 px-1.5 text-xs hover:bg-destructive hover:text-destructive-foreground"
|
|
onClick={clear}
|
|
>
|
|
<X className="w-3 h-3" />
|
|
</Badge>
|
|
)}
|
|
<ChevronDown className="w-4 h-4 opacity-50" />
|
|
</span>
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent
|
|
className="p-0 w-[var(--radix-popover-trigger-width)] min-w-[260px]"
|
|
align="start"
|
|
>
|
|
{options.length >= searchThreshold && (
|
|
<div className="p-2 border-b">
|
|
<div className="relative">
|
|
<Search className="w-4 h-4 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
|
<Input
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
placeholder={searchPlaceholder}
|
|
className="pl-8 h-8"
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div
|
|
className="overflow-y-auto py-1"
|
|
style={{ maxHeight: maxListHeight }}
|
|
>
|
|
{filtered.length === 0 ? (
|
|
<div className="px-3 py-6 text-sm text-muted-foreground text-center">
|
|
No matches
|
|
</div>
|
|
) : (
|
|
filtered.map((opt) => {
|
|
const checked = valueSet.has(opt.value);
|
|
return (
|
|
<button
|
|
key={opt.value}
|
|
type="button"
|
|
onClick={() => toggle(opt.value)}
|
|
className="flex items-center gap-2 w-full px-3 py-1.5 text-sm hover:bg-accent text-left"
|
|
>
|
|
<Checkbox checked={checked} className="pointer-events-none" />
|
|
<span className="truncate">{opt.label}</span>
|
|
</button>
|
|
);
|
|
})
|
|
)}
|
|
</div>
|
|
</PopoverContent>
|
|
</Popover>
|
|
);
|
|
}
|