feat(server): W4-A integration endpoints and contract gaps

- POST /acquisition-plans: manual submit via download.plan -> download.submit
  (same authorization/audit/idempotency path as the agent), slotId or entityId
- read-only /media-assets, /asset-locations, /asset-unit-coverage, /path-bindings,
  /reconcile-runs, /server-mappings, /artifacts, GET /title-aliases/{id};
  unimplemented write endpoints removed from api.ts; registry test now checks both directions
- candidate evaluation upsert per (slot, source_release) + migration 0022 dedupe/unique index
- organization records expose downloadTaskId (+ list filter); inventory adds
  subscribed/candidateReasons; feed sources expose derived possibleGap
- GET /events?after=&limit= JSON replay page for API key callers (same sse_event table)
- preference tag revision history from audit_event; subscriptions/identities/aliases
  lists carry mediaEntityTitle; subscription q/mediaKind search; slot subscriptionId
  filter + currentAsset summary; policy preview samples carry title/reasons
- DecisionSummary, IdentityRevisionList, ReleaseIdentityResult, PolicyPreviewSummary exported from contracts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-27 21:10:02 +08:00
1 parent ea4c384664
commit d3ab54f2bd
34 files changed
+1083 -123

No files matched your search

+7 -5
View File
@@ -72,14 +72,16 @@ export function useFetchFeedNow() {
}
/**
* 疑似缺口:Feed 窗口与上次零重叠时服务端发 feed.gap_suspected 并排补漏。
* 列表字段里没有显式标记,这里按 cursor 里的 gapSuspectedAt(若服务端写入)或"距上次成功超过 3 个周期"推断,并标"疑似"。
* 疑似缺口:服务端在 Feed 窗口与上次零重叠时写 possibleGap 并排站点补漏;下一次抓取衔接上后清空。
* 没有服务端标记但"距上次成功超过 3 个周期"时,只作推断提示(标"可能")。
*/
export function feedGapHint(f: FeedSource, now = Date.now()): string | null {
const gapAt = typeof f.cursor.gapSuspectedAt === "string" ? f.cursor.gapSuspectedAt : null;
if (gapAt) return `疑似缺口(${new Date(gapAt).toLocaleString("zh-CN", { hour12: false })} 检测,已排补漏)`;
if (f.possibleGap) {
const at = new Date(f.possibleGap.detectedAt).toLocaleString("zh-CN", { hour12: false });
return `疑似缺口(${at} 检测,${f.possibleGap.backfillQueued ? "已排补漏" : "Feed 未关联站点,无法自动补漏"})`;
}
if (!f.enabled || !f.lastSuccessAt) return null;
const gapMs = now - new Date(f.lastSuccessAt).getTime();
if (gapMs > f.pollIntervalSec * 1000 * 3) return "距上次成功已超过 3 个周期,可能漏项(疑似)";
if (gapMs > f.pollIntervalSec * 1000 * 3) return "距上次成功已超过 3 个周期,可能漏项";
return null;
}
+29 -2
View File
@@ -16,11 +16,29 @@ export function useInventory(entityIds: string[]) {
}
/** 叠加标记:只来自本地身份/Slot/任务,不从网页标题猜确定事实 */
export type OverlayFlag = { key: string; label: string; tone: "success" | "warning" | "neutral" };
export type OverlayFlag = { key: string; label: string; tone: "success" | "warning" | "neutral"; title?: string };
export function inventoryFlags(entry: InventoryEntry | undefined, releaseResolution?: string | null): OverlayFlag[] {
const DECISION_FLAG: Record<string, { label: string; tone: OverlayFlag["tone"] }> = {
accept: { label: "已选中", tone: "success" },
upgrade: { label: "可升级", tone: "success" },
reject: { label: "未选", tone: "warning" },
unknown_field: { label: "字段未知", tone: "warning" },
skipped: { label: "被跳过", tone: "neutral" },
};
/** 该资源在各 Slot 上的最近一次评估(服务端每个 (Slot, 资源) 只保留一条) */
export function releaseCandidates(entry: InventoryEntry | undefined, releaseId: string) {
return entry?.candidateReasons.filter((c) => c.sourceReleaseId === releaseId) ?? [];
}
export function inventoryFlags(
entry: InventoryEntry | undefined,
releaseResolution?: string | null,
releaseId?: string,
): OverlayFlag[] {
if (!entry) return [];
const flags: OverlayFlag[] = [];
if (entry.subscribed) flags.push({ key: "sub", label: "已订阅", tone: "neutral" });
const available = entry.versions.filter((v) => v.available);
if (available.length) {
const res = [...new Set(available.map((v) => v.resolution ?? "未知分辨率"))].join(" / ");
@@ -35,6 +53,15 @@ export function inventoryFlags(entry: InventoryEntry | undefined, releaseResolut
if (entry.downloading.length) {
flags.push({ key: "dl", label: `下载中 ${entry.downloading.length}`, tone: "neutral" });
}
for (const c of releaseId ? releaseCandidates(entry, releaseId) : []) {
const d = DECISION_FLAG[c.decision] ?? { label: c.decision, tone: "neutral" as const };
flags.push({
key: `cand-${c.slotId}`,
label: `${c.slotName}:${d.label}`,
tone: d.tone,
title: c.reasons.join(";"),
});
}
if (releaseResolution && releaseResolution === "resolved" && flags.length === 0) {
flags.push({ key: "tracked", label: "已识别,无版本目标", tone: "neutral" });
}
@@ -26,6 +26,10 @@ export function SlotCard({
const hard = summarizeHard(slot.hardConditions, slot.fallback);
const soft = summarizeSoft(slot.softPreferences);
const upgrade = summarizeUpgrade(slot.upgradeThreshold);
// 服务端按 (Slot, 来源资源) 只保留最新一次评估;这里再按资源去重兜底(列表已按评估时间新→旧)
const latest = candidates.filter(
(c, i) => candidates.findIndex((x) => x.sourceReleaseId === c.sourceReleaseId) === i,
);
return (
<article className="min-w-0 rounded-xl border border-border/80 bg-foreground/[0.02] p-4">
<header className="flex flex-wrap items-center gap-2">
@@ -70,12 +74,12 @@ export function SlotCard({
<dd className="text-caption break-words text-foreground">{currentAsset ?? "无"}</dd>
</div>
</dl>
{candidates.length ? (
{latest.length ? (
<div className="mt-3 border-t border-border/60 pt-3">
<p className="mb-2 text-meta text-muted-foreground">最近候选 · 为什么选 / 不选</p>
<p className="mb-2 text-meta text-muted-foreground">最近候选 · 为什么选 / 不选(每个资源显示最近一次评估)</p>
<ul className="space-y-2">
{candidates.map((c) => (
<li key={`${c.sourceReleaseId}-${c.evaluatedAt}`} className="min-w-0">
{latest.map((c) => (
<li key={c.sourceReleaseId} className="min-w-0">
<div className="flex flex-wrap items-center gap-2">
<Tone v={CANDIDATE_DECISION[c.decision]} />
<span className="min-w-0 font-mono text-meta break-all text-foreground">{c.title}</span>
@@ -92,7 +96,7 @@ export function SlotCard({
{c.reasons.length ? (
<p className="mt-1 text-meta break-words text-muted-foreground">{c.reasons.join(";")}</p>
) : null}
<p className="text-micro text-muted-foreground tabular-nums">{formatDateTime(c.evaluatedAt)}</p>
<p className="text-micro text-muted-foreground tabular-nums">评估于 {formatDateTime(c.evaluatedAt)}</p>
</li>
))}
</ul>
@@ -65,7 +65,8 @@ function LocalInventory({ release, entry }: { release: WorkbenchRelease; entry:
) : (
<>
<p className="text-meta text-muted-foreground">
{slots.length ? `${slots.length} 个版本目标(已订阅)` : "没有版本目标(未订阅)"}
{slots.length ? `${slots.length} 个版本目标` : "没有版本目标"}
{entry ? (entry.subscribed ? " · 已订阅" : " · 未订阅") : ""}
</p>
{candidates.length ? (
<ul className="space-y-2">
@@ -73,7 +74,7 @@ function LocalInventory({ release, entry }: { release: WorkbenchRelease; entry:
const d = DECISION_LABEL[c.decision];
const slot = slots.find((s) => s.id === c.slotId);
return (
<li key={`${c.slotId}-${c.evaluatedAt}`} className="rounded-lg border border-border/70 px-3 py-2">
<li key={c.slotId} className="rounded-lg border border-border/70 px-3 py-2">
<div className="flex flex-wrap items-center gap-2 text-caption">
<StatusBadge tone={d.tone}>{d.label}</StatusBadge>
<span className="text-foreground">{slot ? `目标 ${slot.name}` : "版本目标"}</span>
@@ -44,7 +44,7 @@ export function InventoryOverlay({
: "未识别到本地作品";
return <span className="text-meta text-muted-foreground">{label}</span>;
}
const flags = inventoryFlags(entry, release.resolutionStatus);
const flags = inventoryFlags(entry, release.resolutionStatus, release.id);
return (
<span className="flex min-w-0 flex-wrap items-center gap-1.5">
<span className="truncate text-meta text-foreground">
@@ -53,11 +53,17 @@ export function InventoryOverlay({
</span>
{loading ? <span className="text-meta text-muted-foreground">库存加载中…</span> : null}
{!loading && entry && flags.length === 0 ? <StatusBadge>本地无版本</StatusBadge> : null}
{flags.map((f) => (
<StatusBadge key={f.key} tone={f.tone}>
{f.label}
</StatusBadge>
))}
{flags.map((f) =>
f.title ? (
<span key={f.key} title={f.title}>
<StatusBadge tone={f.tone}>{f.label}</StatusBadge>
</span>
) : (
<StatusBadge key={f.key} tone={f.tone}>
{f.label}
</StatusBadge>
),
)}
</span>
);
}
+5 -1
View File
@@ -114,7 +114,11 @@ export default function SourcesPage() {
return (
<div className="flex flex-col items-start gap-1">
<StatusBadge tone={HEALTH[f.healthStatus].tone}>{HEALTH[f.healthStatus].label}</StatusBadge>
{gap ? <StatusBadge tone="warning">疑似缺口</StatusBadge> : null}
{gap ? (
<span title={gap}>
<StatusBadge tone="warning">{f.possibleGap ? "疑似缺口" : "可能漏项"}</StatusBadge>
</span>
) : null}
</div>
);
},