dsh-shiori 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/index.js CHANGED
@@ -60,6 +60,7 @@ window.__ModuleLoader__.load({
60
60
  ".dshi_badge{border:1px solid var(--dshi-gold-ink,#c98a1b);color:var(--dshi-gold-ink,#c98a1b);border-radius:999px;padding:0 8px;font-size:10px;white-space:nowrap}" +
61
61
  ".dshi_badgeWarn{border-color:var(--dsw-alias-state-error-primary,#f85149);color:var(--dsw-alias-state-error-primary,#f85149)}" +
62
62
  ".dshi_badgeDim{border-color:var(--dsw-alias-border-l2,#dce2eb);color:var(--dsw-alias-label-tertiary)}" +
63
+ ".dshi_badgeStale{border-color:var(--dshi-warn);color:var(--dshi-warn)}" +
63
64
  ".dshi_btn{border:1px solid var(--dsw-alias-border-l2,#dce2eb);background:var(--dsw-alias-bg-layer-3,#fff);color:var(--dsw-alias-label-primary);border-radius:8px;padding:5px 12px;font:inherit;font-size:12px;cursor:pointer}" +
64
65
  ".dshi_btn:hover:not(:disabled){border-color:var(--dshi-accent-a,#e5484d)}" +
65
66
  ".dshi_btn:disabled{opacity:.5;cursor:default}" +
@@ -167,7 +168,26 @@ window.__ModuleLoader__.load({
167
168
  ".dshi_roBanner{border:1px solid var(--dshi-warn);background:rgba(180,83,9,.10);color:var(--dshi-warn);border-radius:8px;padding:8px 12px;font-size:12px;line-height:1.5;word-break:break-word}" +
168
169
  ".dshi_roHint{font-size:11px;color:var(--dshi-warn);border:1px solid var(--dshi-warn);border-radius:8px;padding:4px 8px;word-break:break-word}" +
169
170
  ".dshi_tlScan{font-size:11px;color:var(--dshi-warn)}" +
170
- ".dshi_tlDedupe{border-color:var(--dshi-l3);color:var(--dshi-l3)}";
171
+ ".dshi_tlDedupe{border-color:var(--dshi-l3);color:var(--dshi-l3)}" +
172
+ // U5 整理与遗忘页:筛选条(chips)、搜索框、kind 分组组头、就地预览 diff 区。
173
+ // 只引用 --dshi-* token;diff 区最小高度 240px、可滚动、字号不小于 12px。
174
+ ".dshi_filterBar{display:flex;align-items:center;gap:var(--dshi-space-xs);flex-wrap:wrap}" +
175
+ ".dshi_filterChip{border:1px solid var(--dsw-alias-border-l2,#dce2eb);background:var(--dshi-bg-card);color:var(--dshi-text-dim);border-radius:var(--dshi-radius-pill);padding:2px 10px;font:inherit;font-size:var(--dshi-font-xs);cursor:pointer}" +
176
+ ".dshi_filterChip:hover{color:var(--dshi-text)}" +
177
+ ".dshi_filterChipOn{border-color:transparent;background:linear-gradient(135deg,var(--dshi-accent-a),var(--dshi-accent-b));color:#fff;font-weight:600}" +
178
+ ".dshi_searchInput{flex:1;min-width:160px;max-width:240px}" +
179
+ ".dshi_groupHead{display:flex;align-items:center;gap:var(--dshi-space-xs);cursor:pointer;border:none;background:none;padding:2px 0;font:inherit;font-size:var(--dshi-font-sm);font-weight:600;color:var(--dshi-text);text-align:left}" +
180
+ ".dshi_groupHead:hover{color:var(--dshi-accent)}" +
181
+ ".dshi_groupCount{font-size:var(--dshi-font-xs);font-weight:400;color:var(--dshi-text-dim)}" +
182
+ ".dshi_diffBox{display:flex;flex-direction:column;gap:var(--dshi-space-sm);min-height:240px;max-height:480px;overflow:auto;border:var(--dshi-stroke);border-radius:var(--dshi-radius-sm);padding:var(--dshi-space-sm)}" +
183
+ ".dshi_diffBox .dshi_pre{font-size:var(--dshi-font-sm)}" +
184
+ ".dshi_kindGroup{display:flex;flex-direction:column;gap:var(--dshi-space-xs)}" +
185
+ ".dshi_advanced{display:flex;flex-direction:column;gap:var(--dshi-space-xs);margin-top:var(--dshi-space-xs)}" +
186
+ // U5-e:过期候选——行内徽章(warn 色沿用 --dshi-warn)、顶部提示条与重析按钮
187
+ //(底色沿用 dshi_roBanner 的 rgba(180,83,9,.10),不引入新色系)。
188
+ ".dshi_staleBar{display:flex;align-items:center;gap:var(--dshi-space-xs);flex-wrap:wrap;border:1px solid var(--dshi-warn);background:rgba(180,83,9,.10);color:var(--dshi-warn);border-radius:var(--dshi-radius-sm);padding:var(--dshi-space-xs) var(--dshi-space-sm);font-size:var(--dshi-font-sm)}" +
189
+ ".dshi_staleBarBtn{border:1px solid var(--dshi-warn);background:none;color:var(--dshi-warn);font:inherit;font-size:var(--dshi-font-xs);border-radius:var(--dshi-radius-sm);padding:2px 10px;cursor:pointer}" +
190
+ ".dshi_staleBarBtn:disabled{opacity:.5;cursor:default}";
171
191
  function ensureStyle() {
172
192
  try {
173
193
  if (document.getElementById("dsh-shiori-style")) return;
@@ -777,7 +797,14 @@ window.__ModuleLoader__.load({
777
797
 
778
798
  function ErrorBox(error) {
779
799
  if (!error) return null;
780
- return h("div", { className: "dshi_error" }, (error.code ? "[" + error.code + "] " : "") + (error.message || String(error)));
800
+ // U5:人话提示在盒子正文;服务端原始错误收进默认折叠的 details(排查用),
801
+ // 不再把原始大红字直接顶出来。detail 由 candidateActionError 等映射层携带。
802
+ var detail = error.detail !== undefined && error.detail !== null ? String(error.detail) : null;
803
+ return h("div", { className: "dshi_error" },
804
+ (error.code ? "[" + error.code + "] " : "") + (error.message || String(error)),
805
+ detail ? h("details", { className: "dshi_details" },
806
+ h("summary", { className: "dshi_hint" }, "原始错误信息"),
807
+ h("pre", { className: "dshi_pre" }, detail)) : null);
781
808
  }
782
809
 
783
810
  // U3 水位三档具名常量:ratio < WATER_WARN_RATIO 正常、达到 WATER_WARN_RATIO 警示、
@@ -1903,21 +1930,25 @@ window.__ModuleLoader__.load({
1903
1930
  if (after.length === before.length) return "合并后正文与原正文相同(没有任何变化),服务端会拒绝。";
1904
1931
  return null;
1905
1932
  }
1906
- // Q-B:候选/计划脏数据的人话错误(保留原 code,便于排查)。
1933
+ // Q-B:候选/计划脏数据的人话错误(保留原 code 便于排查)。
1934
+ // U5:服务端原文不再拼进 message 顶大红字——放 detail 字段,ErrorBox 收进
1935
+ // 默认折叠的 details。映射口径:候选已变化 → 请点「分析整理候选」重新分析;
1936
+ // REVISION_CONFLICT → 队列已更新请重新分析(不要重试旧预览);NOT_FOUND → 该候选已不存在。
1937
+ // 注意:「刷新」按钮只重读队列快照、不会重新分析,文案一律指向「分析整理候选」。
1907
1938
  function candidateActionError(error) {
1908
1939
  var code = error && error.code ? String(error.code) : "";
1909
1940
  var detail = (error && error.message) || String(error);
1910
1941
  if (code === "NOT_FOUND") {
1911
- return { code: code, message: "该候选或计划已过期:源卡可能已被合并 / 归档,或计划已不存在。请点「刷新」重新分析后再试。(原始信息:" + detail + ")" };
1942
+ return { code: code, message: "该候选已不存在:该候选或计划已过期(源卡可能已被合并 / 归档,或计划已不存在)。请点「分析整理候选」重新分析后再试。", detail: detail };
1912
1943
  }
1913
1944
  if (code === "INVALID_INPUT") {
1914
- return { code: code, message: "服务端拒绝了这次操作:数据可能已过期(请点「刷新」重新分析),或参数未通过服务端校验。(原始信息:" + detail + ")" };
1945
+ return { code: code, message: "服务端拒绝了这次操作:候选内容可能已变化,请点「分析整理候选」重新分析后再试;若在高级区手写 proposal,请检查它是否符合协议形状。", detail: detail };
1915
1946
  }
1916
1947
  if (code === "REVISION_CONFLICT") {
1917
- return { code: code, message: "revision 冲突:该计划可能已被执行,或主题 / 队列在此期间被修改。请刷新后重新预览,不要重试旧预览。(原始信息:" + detail + ")" };
1948
+ return { code: code, message: "revision 冲突:队列已更新,请点「分析整理候选」重新分析后再试,不要重试旧预览(该计划可能已被执行,或主题 / 队列在此期间被修改)。", detail: detail };
1918
1949
  }
1919
1950
  if (code === "UNSUPPORTED") {
1920
- return { code: code, message: "服务端不支持该操作(例如 legacy 主题只读,不能作为合并目标)。(原始信息:" + detail + ")" };
1951
+ return { code: code, message: "服务端不支持该操作(例如 legacy 主题只读,不能作为合并目标)。", detail: detail };
1921
1952
  }
1922
1953
  return error;
1923
1954
  }
@@ -1941,8 +1972,70 @@ window.__ModuleLoader__.load({
1941
1972
  // 未知 kind / status 保留原文,绝不吞掉服务端新增的分类。
1942
1973
  var CANDIDATE_KIND_LABELS = { cluster: "集群", isolated: "孤立卡", link: "可建链接" };
1943
1974
  var CANDIDATE_STATUS_LABELS = { pending: "待处理", reviewed: "已阅", dismissed: "已忽略" };
1975
+ // U5:候选分组(渲染顺序即组顺序;kind 缺失 / 未知归入「其他」)与状态筛选条。
1976
+ // 筛选只是前端视图(协议仍发 decision=reviewed / dismissed),「已阅」分组可切回。
1977
+ var CANDIDATE_FILTERS = [["all", "全部"], ["pending", "待处理"], ["reviewed", "已阅"], ["dismissed", "已忽略"]];
1978
+ var CANDIDATE_KIND_GROUPS = [
1979
+ { kind: "cluster", label: "集群" },
1980
+ { kind: "link", label: "可建链接" },
1981
+ { kind: "isolated", label: "孤立卡" },
1982
+ { kind: "other", label: "其他" }
1983
+ ];
1944
1984
  var PLAN_STATE_LABELS = { open: "待执行", executed: "已执行", superseded: "已作废" };
1945
1985
  var PLAN_KIND_LABELS = { organize: "整理", forgetting: "遗忘" };
1986
+ // U5b:预览卡标题按 plan.kind(link / merge-topic / thin-core)翻成人话;
1987
+ // 未知 kind 原样显示,绝不吞掉、不崩。
1988
+ var PLAN_PREVIEW_TITLES = { "link": "连起来", "merge-topic": "合并进主题", "thin-core": "core 瘦身" };
1989
+ function planPreviewTitle(kind) {
1990
+ var text = String(kind ?? "");
1991
+ return PLAN_PREVIEW_TITLES[text] ?? text;
1992
+ }
1993
+ // U5b:候选行「理由」小字——把 evidence 翻成人话(纯展示)。evidence 缺失 /
1994
+ // 形状不对 / 未知 kind 返回 null:调用方不渲染该行,行本身绝不消失、绝不抛错。
1995
+ // 词条一律按纯文本拼接(React 文本节点,无 HTML 注入面)。
1996
+ function candidateReasonOf(candidate) {
1997
+ var kind = candidate && candidate.kind !== undefined && candidate.kind !== null ? String(candidate.kind) : "";
1998
+ var evidence = candidate && candidate.evidence
1999
+ && typeof candidate.evidence === "object" && !Array.isArray(candidate.evidence)
2000
+ ? candidate.evidence : null;
2001
+ if (evidence === null) return null;
2002
+ // 字段缺失按「空」处理;字段存在但不是数组按「形状不对」处理(返回 null)。
2003
+ var wordList = function (value) {
2004
+ if (value === undefined || value === null) return [];
2005
+ if (!Array.isArray(value)) return null;
2006
+ return value
2007
+ .filter(function (t) { return t !== null && t !== undefined && String(t) !== ""; })
2008
+ .map(function (t) { return String(t); });
2009
+ };
2010
+ var quoteList = function (words) {
2011
+ return words.map(function (w) { return "「" + w + "」"; }).join("");
2012
+ };
2013
+ if (kind === "link") {
2014
+ var entities = wordList(evidence.sharedEntities);
2015
+ var triggers = wordList(evidence.sharedTriggers);
2016
+ if (entities === null || triggers === null) return null;
2017
+ var parts = [];
2018
+ if (entities.length > 0) parts.push("两张卡都提到实体" + quoteList(entities));
2019
+ if (triggers.length > 0) parts.push("都带触发词" + quoteList(triggers));
2020
+ return parts.length > 0 ? parts.join(";") : "两张卡有共同关键词";
2021
+ }
2022
+ if (kind === "cluster") {
2023
+ var sources = candidate && Array.isArray(candidate.sources) ? candidate.sources : null;
2024
+ var field = evidence.field;
2025
+ var term = evidence.sharedTerm;
2026
+ if (sources === null || (field !== "entities" && field !== "triggers")) return null;
2027
+ if (term === undefined || term === null || String(term) === "") return null;
2028
+ var noun = field === "triggers" ? "触发词" : "实体";
2029
+ return sources.length + " 张卡都共享" + noun + "「" + String(term) + "」,可以合并成一个主题";
2030
+ }
2031
+ if (kind === "isolated") {
2032
+ var retired = wordList(evidence.ignoredRetiredTargets);
2033
+ if (retired === null) return null;
2034
+ var base = "这张卡没有和任何卡相连";
2035
+ return retired.length > 0 ? base + "(另有 " + retired.length + " 条指向已退休卡的旧连线)" : base;
2036
+ }
2037
+ return null;
2038
+ }
1946
2039
  function candidateKindLabel(kind) {
1947
2040
  var text = String(kind ?? "");
1948
2041
  return CANDIDATE_KIND_LABELS[text] ?? text;
@@ -2028,6 +2121,10 @@ window.__ModuleLoader__.load({
2028
2121
  // 文本框手写必然失败,应走「合并进主题」一键流程。
2029
2122
  function proposalSkeleton(candidate) {
2030
2123
  var sources = candidate && Array.isArray(candidate.sources) ? candidate.sources : [];
2124
+ // 孤立卡只有一张源卡,没有可连的第二张——second 会退化成占位符
2125
+ // "<另一张卡 id>",服务端 validateSparkIdLocal 必拒(INVALID_INPUT)。
2126
+ // 少于 2 个源时返回 null,由调用方本地拦截,不发必然失败的 RPC。
2127
+ if (sources.length < 2) return null;
2031
2128
  var first = sources[0] && sources[0].id ? String(sources[0].id) : "<源卡 id>";
2032
2129
  var second = sources[1] && sources[1].id ? String(sources[1].id) : "<另一张卡 id>";
2033
2130
  return JSON.stringify({ kind: "link", links: [{ id: first, after: [{ target: second, rel: "related" }] }] }, null, 2);
@@ -2080,6 +2177,26 @@ window.__ModuleLoader__.load({
2080
2177
  var titlesState = useState({});
2081
2178
  var titles = titlesState[0];
2082
2179
  var setTitles = titlesState[1];
2180
+ // ── U5 追加(全部排在既有 hook 之后,老测试的 states[0..6] 布局不变)──────
2181
+ // filter:状态筛选(pending 默认——「稍后再说」后该行立即离开当前分组);
2182
+ // search:纯前端搜索(标题 / 短 id);collapsedKinds:kind 分组折叠表
2183
+ // (孤立卡默认折叠;计划卡里已执行/已作废分组用原生 details 折叠,不需要状态);
2184
+ // advancedOpen / advancedCandidate:高级手动 proposal 调试区(默认折叠)。
2185
+ var filterState = useState("pending");
2186
+ var filter = filterState[0];
2187
+ var setFilter = filterState[1];
2188
+ var searchState = useState("");
2189
+ var search = searchState[0];
2190
+ var setSearch = searchState[1];
2191
+ var collapsedKindsState = useState({ isolated: true });
2192
+ var collapsedKinds = collapsedKindsState[0];
2193
+ var setCollapsedKinds = collapsedKindsState[1];
2194
+ var advancedOpenState = useState(false);
2195
+ var advancedOpen = advancedOpenState[0];
2196
+ var setAdvancedOpen = advancedOpenState[1];
2197
+ var advancedCandidateState = useState("");
2198
+ var advancedCandidate = advancedCandidateState[0];
2199
+ var setAdvancedCandidate = advancedCandidateState[1];
2083
2200
  // F7:只读态(另一实例在写)——analyze / review / preview / execute 与合并
2084
2201
  // 流程全部置灰(服务端 assertHostWritable 同口径),页内黄字说明原因。
2085
2202
  var ro = props.readOnly === true;
@@ -2113,6 +2230,9 @@ window.__ModuleLoader__.load({
2113
2230
  var loaded = queueRevision !== null;
2114
2231
  // DTO 守卫:items / plans 只按数组渲染(对象形态不调 .length/.map)。
2115
2232
  var items = Array.isArray(data && data.items) ? data.items : [];
2233
+ // U5-e:顶层 staleCount(全量口径,不受当前筛选 / 搜索影响)——>0 时顶部
2234
+ // 显示提示条;旧服务端不带回该字段时按 0 处理(提示条不渲染)。
2235
+ var staleCount = data && typeof data.staleCount === "number" ? data.staleCount : 0;
2116
2236
  var plans = Array.isArray(data && data.plans) ? data.plans : [];
2117
2237
 
2118
2238
  var load = async function () {
@@ -2190,51 +2310,78 @@ window.__ModuleLoader__.load({
2190
2310
  setBusy(false);
2191
2311
  }
2192
2312
  };
2193
- var doPreviewOrganize = function (candidateId) {
2194
- // B-Q2:空 proposal(默认态)不发送——按候选 kind 预填:link 候选给带真实
2195
- // 源卡 id 的骨架;cluster 候选指引走「合并进主题」(merge-topic 需服务端
2196
- // 签发的 revision token,文本框手写必然失败)。
2197
- var candidate = null;
2313
+ // U5:行内候选查找(真机 queueDto 与旧扁平形状都兼容,queueItemCandidate 统一入口)。
2314
+ var findCandidateById = function (candidateId) {
2198
2315
  for (var i = 0; i < items.length; i++) {
2199
2316
  var c = queueItemCandidate(items[i]);
2200
- if (c && c.id !== undefined && c.id !== null && String(c.id) === String(candidateId)) {
2201
- candidate = c;
2202
- break;
2203
- }
2317
+ if (c && c.id !== undefined && c.id !== null && String(c.id) === String(candidateId)) return c;
2204
2318
  }
2205
- var text = String(proposal ?? "");
2206
- if (text.trim() === "") {
2319
+ return null;
2320
+ };
2321
+ // U5:发送 organize 预览并就地钉定 targetId——预览确认卡渲染在该候选行正下方
2322
+ // (复用合并卡的就地展开写法),不再依赖底部共享状态。
2323
+ var sendOrganizePreview = function (candidateId, parsed) {
2324
+ setPreviewError(null);
2325
+ var origin = mark();
2326
+ guardPreview(async function () {
2327
+ var result = await props.dsh.call("previewPlan", props.sessionId, withRevision({ kind: "organize", candidateId: candidateId, proposal: parsed, operationId: newId() }));
2328
+ if (isStale(origin)) return;
2329
+ setPreview({ sessionId: props.sessionId, plan: result, queueRevision: queueRevision, targetId: String(candidateId) });
2330
+ });
2331
+ };
2332
+ var doPreviewOrganize = function (candidateId) {
2333
+ // U5 根因修复:底部共享 proposal 文本框已删除。此前它是全局单一 state——
2334
+ // 点 A 行先预填骨架再点 B 行时文本框非空,B 行的 candidateId 配了 A 行的
2335
+ // 骨架 → 服务端校验失败报 INVALID_INPUT。现在点行按钮直接按该候选生成
2336
+ // 骨架并发送 previewPlan,不再需要人编辑 JSON;手写入口收进高级调试区。
2337
+ var candidate = findCandidateById(candidateId);
2338
+ var skeleton = proposalSkeleton(candidate);
2339
+ var parsed = null;
2340
+ try {
2341
+ parsed = skeleton === null ? null : JSON.parse(skeleton);
2342
+ } catch (e) {
2343
+ parsed = null;
2344
+ }
2345
+ // Q-B:死 payload(如骨架异常)在本地拦下,不发必然失败的 RPC。
2346
+ // 孤立卡(单源候选)没有第二张卡可连,骨架为 null——本来就不该有这个入口。
2347
+ var problem;
2348
+ if (skeleton === null) {
2349
+ problem = "这张卡还没有和任何卡相连,没有可预览的整理计划";
2350
+ } else if (parsed === null) {
2351
+ problem = "proposal 骨架生成失败(候选数据异常),请刷新后重试。";
2352
+ } else {
2353
+ problem = validateOrganizeProposalLocal(parsed);
2354
+ }
2355
+ if (problem) {
2207
2356
  setPreview(null);
2208
- if (candidate && String(candidate.kind) === "cluster") {
2209
- setPreviewError({ code: "ui/use-merge-flow", message: "cluster 候选请使用「合并进主题」一键流程(自动选/建主题并带服务端签发的 revision token);手动 merge-topic 需要真实 token,不在文本框手写。" });
2210
- return;
2211
- }
2212
- setProposal(proposalSkeleton(candidate));
2213
- setPreviewError({ code: "ui/proposal-prefilled", message: "已按该候选预填 link 骨架(源卡 id 来自候选)。请确认 target 是另一张真实卡 id 后,再点「preview organize」发送。" });
2357
+ setPreviewError({ code: "ui/invalid-proposal", message: problem });
2358
+ return;
2359
+ }
2360
+ sendOrganizePreview(candidateId, parsed);
2361
+ };
2362
+ // U5:高级调试区手写 proposal(原 B-Q2 口径:本地校验 → 发送)。
2363
+ var doPreviewManual = function () {
2364
+ var manualId = String(advancedCandidate ?? "").trim();
2365
+ if (!manualId) {
2366
+ setPreview(null);
2367
+ setPreviewError({ code: "ui/invalid-proposal", message: "请先填要预览的候选完整 id(从候选行的 title 或「原始数据」里复制)。" });
2214
2368
  return;
2215
2369
  }
2216
2370
  var parsed;
2217
2371
  try {
2218
- parsed = JSON.parse(text);
2372
+ parsed = JSON.parse(String(proposal ?? ""));
2219
2373
  } catch (e) {
2220
2374
  setPreview(null);
2221
2375
  setPreviewError({ code: "ui/invalid-json", message: "proposal JSON 解析失败:" + e.message });
2222
2376
  return;
2223
2377
  }
2224
- // Q-B:死 payload(如空 links)在本地拦下,不发必然失败的 RPC。
2225
2378
  var problem = validateOrganizeProposalLocal(parsed);
2226
2379
  if (problem) {
2227
2380
  setPreview(null);
2228
2381
  setPreviewError({ code: "ui/invalid-proposal", message: problem });
2229
2382
  return;
2230
2383
  }
2231
- setPreviewError(null);
2232
- var origin = mark();
2233
- guardPreview(async function () {
2234
- var result = await props.dsh.call("previewPlan", props.sessionId, withRevision({ kind: "organize", candidateId: candidateId, proposal: parsed, operationId: newId() }));
2235
- if (isStale(origin)) return;
2236
- setPreview({ sessionId: props.sessionId, plan: result });
2237
- });
2384
+ sendOrganizePreview(manualId, parsed);
2238
2385
  };
2239
2386
  var doPreviewForgetting = function (planId) {
2240
2387
  setPreviewError(null);
@@ -2242,7 +2389,7 @@ window.__ModuleLoader__.load({
2242
2389
  guardPreview(async function () {
2243
2390
  var result = await props.dsh.call("previewPlan", props.sessionId, { kind: "forgetting", planId: planId });
2244
2391
  if (isStale(origin)) return;
2245
- setPreview({ sessionId: props.sessionId, plan: result });
2392
+ setPreview({ sessionId: props.sessionId, plan: result, targetId: String(planId) });
2246
2393
  });
2247
2394
  };
2248
2395
  // R4:确认执行前校验 preview 钉住的来源会话与当前会话一致,不一致拒绝发送
@@ -2470,133 +2617,385 @@ window.__ModuleLoader__.load({
2470
2617
  h("button", { className: "dshi_btn dshi_btnPrimary", disabled: busy || ro, onClick: doMergePreview }, "预览 diff(previewPlan)"))) : null
2471
2618
  ));
2472
2619
  };
2620
+ // ── U5:筛选 / 搜索 / kind 分组 / 就地预览(纯前端推导,协议与守卫不变)───
2621
+ // 候选人话标题:集群说共享词 + 卡数,链接说「A ↔ B」,孤立卡直接给源卡标题;
2622
+ // 都没有时退化成短 id(titles 拉不到图谱时为空对象)。
2623
+ var candidateTitleOf = function (candidate) {
2624
+ var sourceIds = candidate && Array.isArray(candidate.sources)
2625
+ ? candidate.sources.map(function (s) { return String(s && s.id); }).filter(Boolean) : [];
2626
+ var sourceTitles = sourceIds.map(function (id) { return titles[id] || shortId(id); });
2627
+ var evidence = candidate && candidate.evidence && typeof candidate.evidence === "object" ? candidate.evidence : {};
2628
+ var candidateKind = candidate && candidate.kind ? String(candidate.kind) : "";
2629
+ if (candidateKind === "cluster") {
2630
+ var sharedTerm = evidence.sharedTerm || evidence.field;
2631
+ return sharedTerm
2632
+ ? "合并「" + String(sharedTerm) + "」相关的 " + sourceIds.length + " 张卡"
2633
+ : "合并 " + sourceIds.length + " 张卡";
2634
+ }
2635
+ if (candidateKind === "link" && sourceTitles.length >= 2) return "连接:" + sourceTitles.join(" ↔ ");
2636
+ if (sourceTitles.length === 1) return sourceTitles[0];
2637
+ if (sourceTitles.length > 1) return sourceTitles.join("、");
2638
+ return null;
2639
+ };
2640
+ // ── U5b:预览卡正文翻人话(纯展示,协议与守卫不动)─────────────────────
2641
+ // 展示名:优先 titles 里的卡标题,拉不到退化成短 id。
2642
+ var displayIdOf = function (id) {
2643
+ var text = String(id ?? "");
2644
+ return titles[text] || shortId(text);
2645
+ };
2646
+ // link diff 的 newText / oldText 是 after / before 边表 JSON({target,rel}[]),
2647
+ // 新增边 = after 里 before 没有的那一条;解析失败 / 形状不对返回 null,由调用方走兜底句。
2648
+ var parseLinkEdgeFromDiff = function (entry) {
2649
+ try {
2650
+ var after = JSON.parse(String((entry && entry.newText) ?? ""));
2651
+ if (!Array.isArray(after)) return null;
2652
+ var before = [];
2653
+ try {
2654
+ var parsedBefore = JSON.parse(String((entry && entry.oldText) ?? ""));
2655
+ if (Array.isArray(parsedBefore)) before = parsedBefore;
2656
+ } catch (e2) { before = []; }
2657
+ var edgeKey = function (l) {
2658
+ var rel = l && l.rel !== undefined && l.rel !== null ? String(l.rel) : "";
2659
+ return String((l && l.target) ?? "") + "\u0000" + rel;
2660
+ };
2661
+ var beforeKeys = new Set(before.map(edgeKey));
2662
+ for (var i = 0; i < after.length; i++) {
2663
+ var edge = after[i];
2664
+ if (!edge || typeof edge !== "object" || edge.target === undefined || edge.target === null) continue;
2665
+ if (!beforeKeys.has(edgeKey(edge))) return { target: String(edge.target), rel: edge.rel === undefined ? null : edge.rel };
2666
+ }
2667
+ // 没有可识别的新增边:退回第一条可读边(previewPlan 已拒绝零新增草案,正常到不了)。
2668
+ for (var j = 0; j < after.length; j++) {
2669
+ var fallback = after[j];
2670
+ if (fallback && typeof fallback === "object" && fallback.target !== undefined && fallback.target !== null) {
2671
+ return { target: String(fallback.target), rel: fallback.rel === undefined ? null : fallback.rel };
2672
+ }
2673
+ }
2674
+ return null;
2675
+ } catch (e) { return null; }
2676
+ };
2677
+ // 预览正文按 plan.kind 翻人话;未知 kind 返回空数组(原始 diff 都在「原始信息」里)。
2678
+ var previewBodyLines = function (plan) {
2679
+ var kind = plan && plan.kind !== undefined && plan.kind !== null ? String(plan.kind) : "";
2680
+ var diff = plan && Array.isArray(plan.diff) ? plan.diff : [];
2681
+ var first = diff.length > 0 && diff[0] && typeof diff[0] === "object" ? diff[0] : null;
2682
+ var lines = [];
2683
+ if (kind === "link") {
2684
+ var sourceId = first && typeof first.path === "string" && first.path.indexOf("spark:") === 0
2685
+ ? first.path.slice("spark:".length) : null;
2686
+ var edge = first !== null ? parseLinkEdgeFromDiff(first) : null;
2687
+ if (sourceId !== null && sourceId !== "" && edge !== null) {
2688
+ var relText = edge.rel === null || edge.rel === "related" ? "相关" : String(edge.rel);
2689
+ lines.push("把『" + displayIdOf(sourceId) + "』关联到『" + displayIdOf(edge.target) + "』");
2690
+ lines.push("关系:" + relText);
2691
+ } else {
2692
+ lines.push("给两张卡新增一条连线(明细见下方「原始信息」)");
2693
+ }
2694
+ lines.push("执行后两张卡的内容都不变,只多一条连线;连错了到卡片详情里删掉这条连线即可。");
2695
+ return lines;
2696
+ }
2697
+ if (kind === "merge-topic") {
2698
+ var topicKey = null;
2699
+ for (var k = 0; k < diff.length; k++) {
2700
+ var entryPath = diff[k] && typeof diff[k].path === "string" ? diff[k].path : "";
2701
+ if (entryPath.indexOf("topic:") === 0) { topicKey = entryPath.slice("topic:".length); break; }
2702
+ }
2703
+ var sparkCount = diff.filter(function (entry) {
2704
+ return entry && typeof entry.path === "string" && entry.path.indexOf("spark:") === 0;
2705
+ }).length;
2706
+ if (sparkCount === 0 && plan && typeof plan.changedItems === "number" && plan.changedItems > 0) {
2707
+ sparkCount = plan.changedItems - 1;
2708
+ }
2709
+ if (topicKey !== null && topicKey !== "") {
2710
+ lines.push(sparkCount > 0
2711
+ ? "把 " + sparkCount + " 张卡合并进主题『" + topicKey + "』"
2712
+ : "把源卡合并进主题『" + topicKey + "』");
2713
+ } else {
2714
+ lines.push("把源卡合并进一个主题(明细见下方「原始信息」)");
2715
+ }
2716
+ lines.push("合并后源卡会退休,这一步不可撤销。");
2717
+ return lines;
2718
+ }
2719
+ if (kind === "thin-core") {
2720
+ if (first !== null) {
2721
+ lines.push("core 正文 " + String((first.oldText) ?? "").length + " → " + String((first.newText) ?? "").length + " 字");
2722
+ } else {
2723
+ lines.push("core 正文将瘦身(长度变化见下方「原始信息」)");
2724
+ }
2725
+ return lines;
2726
+ }
2727
+ return lines;
2728
+ };
2729
+ var statusOfItem = function (item) {
2730
+ return item && item.status ? String(item.status) : "pending";
2731
+ };
2732
+ var searchQuery = String(search ?? "").trim().toLowerCase();
2733
+ var rowVisible = function (item, candidate) {
2734
+ if (filter !== "all" && statusOfItem(item) !== filter) return false;
2735
+ if (searchQuery) {
2736
+ var id = candidate && candidate.id !== undefined && candidate.id !== null ? String(candidate.id) : "";
2737
+ var hay = ((candidateTitleOf(candidate) || "") + " " + id + " " + (id ? shortId(id) : "")).toLowerCase();
2738
+ if (hay.indexOf(searchQuery) === -1) return false;
2739
+ }
2740
+ return true;
2741
+ };
2742
+ var statusCounts = { all: items.length, pending: 0, reviewed: 0, dismissed: 0 };
2743
+ items.forEach(function (item) {
2744
+ var status = statusOfItem(item);
2745
+ if (status === "pending" || status === "reviewed" || status === "dismissed") statusCounts[status] += 1;
2746
+ });
2747
+ var toggleKindGroup = function (kind) {
2748
+ var next = assign({}, collapsedKinds);
2749
+ next[kind] = !(next[kind] === true);
2750
+ setCollapsedKinds(next);
2751
+ };
2752
+ // 预览钉定的目标(候选 id 或计划 id):有 targetId 且目标行可见 → 就地展开在
2753
+ // 该行正下方;targetId 缺失(旧状态 / 手动注入)或目标行已消失 → 回落到底部卡。
2754
+ var previewTargetId = preview && preview.targetId !== undefined && preview.targetId !== null
2755
+ ? String(preview.targetId) : null;
2756
+ var previewTargetVisible = false;
2757
+ if (previewTargetId !== null) {
2758
+ previewTargetVisible = items.some(function (item) {
2759
+ var c = queueItemCandidate(item);
2760
+ return c && c.id !== undefined && c.id !== null && String(c.id) === previewTargetId;
2761
+ }) || plans.some(function (p) {
2762
+ var pid = p && p.planId !== undefined && p.planId !== null
2763
+ ? String(p.planId)
2764
+ : (p && p.id !== undefined && p.id !== null ? String(p.id) : null);
2765
+ return pid !== null && pid === previewTargetId;
2766
+ });
2767
+ }
2768
+ var showBottomPreview = preview !== null && preview.sessionId === props.sessionId
2769
+ && (previewTargetId === null || !previewTargetVisible);
2770
+ // 就地预览确认卡:U5b 起标题 / 正文翻人话(planPreviewTitle / previewBodyLines),
2771
+ // planId / planDigest / summary / 原始 diff 收进默认折叠的「原始信息」details
2772
+ // (link 的 JSON 不再默认铺开);确认按钮文案按 kind 区分(link 不用 danger 红)。
2773
+ // doExecute 与 queueRevision / executed / superseded 守卫一字不动。
2774
+ var renderPreviewCard = function (key) {
2775
+ if (!preview || preview.sessionId !== props.sessionId) return null;
2776
+ var plan = preview.plan;
2777
+ var planKind = plan && plan.kind !== undefined && plan.kind !== null ? String(plan.kind) : "";
2778
+ var planIdText = plan && plan.planId !== undefined && plan.planId !== null ? String(plan.planId) : "";
2779
+ var planDigestText = plan && plan.planDigest !== undefined && plan.planDigest !== null ? String(plan.planDigest) : "";
2780
+ var bodyLines = previewBodyLines(plan);
2781
+ // Q-B:预览对应的计划若已在 plans 列表里标记 executed / superseded,执行按钮禁用
2782
+ var rowLocked = (function () {
2783
+ var row = plans.find(function (p) { return String(p && p.planId) === String(plan && plan.planId); });
2784
+ return Boolean(row && (row.executed === true || row.superseded === true));
2785
+ })();
2786
+ var confirmLabel = planKind === "link" ? "就这么连起来"
2787
+ : planKind === "merge-topic" ? "确认合并(不可撤销)"
2788
+ : planKind === "thin-core" ? "确认瘦身"
2789
+ : "确认执行";
2790
+ return h("div", { key: key, className: "dshi_itemMerge", style: { minWidth: 0 } },
2791
+ h("div", { className: "dshi_confirm", style: { marginLeft: 12 } },
2792
+ h("div", { className: "dshi_cardTitle" }, planPreviewTitle(planKind)),
2793
+ bodyLines.map(function (line, index) {
2794
+ return h("div", { key: index, className: "dshi_hint" }, line);
2795
+ }),
2796
+ // 未知 kind:翻不了人话,summary(服务端原始摘要)兜底展示,不空屏。
2797
+ bodyLines.length === 0 && plan && plan.summary ? h("div", { className: "dshi_hint" }, String(plan.summary)) : null,
2798
+ rowLocked ? h("div", { className: "dshi_hint" }, "该计划已执行或已被新预览作废(plans 列表标记),执行按钮已禁用。") : null,
2799
+ // planId / planDigest / summary / 原始 diff:默认折叠,点开才见。
2800
+ h("details", { className: "dshi_details" },
2801
+ h("summary", { className: "dshi_hint" }, "原始信息"),
2802
+ planIdText !== "" ? h("div", { className: "dshi_hint dshi_mono" }, "planId " + planIdText) : null,
2803
+ planDigestText !== "" ? h("div", { className: "dshi_hint dshi_mono" }, "planDigest " + planDigestText) : null,
2804
+ plan && plan.summary ? h("div", { className: "dshi_hint" }, String(plan.summary)) : null,
2805
+ Array.isArray(plan && plan.diff) && plan.diff.length > 0 ? h("div", { className: "dshi_diffBox" }, plan.diff.map(function (entry, index) {
2806
+ return h("div", { key: index, className: "dshi_item" },
2807
+ h("div", { className: "dshi_mono" }, String((entry && entry.path) ?? index)),
2808
+ h("div", { className: "dshi_hint" }, "old"),
2809
+ h("pre", { className: "dshi_pre" }, String((entry && entry.oldText) ?? "")),
2810
+ h("div", { className: "dshi_hint" }, "new"),
2811
+ h("pre", { className: "dshi_pre" }, String((entry && entry.newText) ?? "")));
2812
+ })) : h("div", { className: "dshi_hint" }, "(无 diff 条目)")),
2813
+ h("div", { className: "dshi_row" },
2814
+ h("button", {
2815
+ className: planKind === "link" ? "dshi_btn dshi_btnPrimary" : "dshi_btn dshi_btnDanger",
2816
+ disabled: busy || ro || rowLocked,
2817
+ onClick: doExecute
2818
+ }, confirmLabel),
2819
+ h("button", { className: "dshi_btn", disabled: busy, onClick: function () { setPreview(null); } }, "取消"))));
2820
+ };
2821
+ var renderCandidateRow = function (item, index, candidate) {
2822
+ var businessId = candidate && candidate.id !== undefined && candidate.id !== null
2823
+ ? String(candidate.id) : null;
2824
+ var key = businessId !== null ? businessId : String(index);
2825
+ var isCluster = candidate ? String(candidate.kind ?? "") === "cluster" : false;
2826
+ // 孤立卡只有一张源卡,没有可连的第二张——「预览整理计划」必然失败
2827
+ // (骨架占位符被服务端拒),入口不渲染,只保留「稍后再说」「忽略」。
2828
+ var isIsolated = candidate ? String(candidate.kind ?? "") === "isolated" : false;
2829
+ var rowDisabled = actionsDisabled || businessId === null;
2830
+ var mergeForThisRow = Boolean(merge) && businessId !== null && String(merge.candidateId) === businessId;
2831
+ var previewForThisRow = previewTargetId !== null && businessId !== null && previewTargetId === businessId;
2832
+ var candidateTitle = candidateTitleOf(candidate);
2833
+ // U5b:标题下「理由」小字——evidence 缺失 / 形状不对 / 未知 kind 时为 null,
2834
+ // 不渲染该行(行本身绝不消失),不抛错。
2835
+ var candidateReason = candidateReasonOf(candidate);
2836
+ // U5-e:过期候选就地标注——队列是快照,源卡在面板外被改动后 revision 前进,
2837
+ // 服务端在队列 item 上投影 stale 布尔(旧扁平形状兼容读 candidate.stale)。
2838
+ // stale 行置灰「预览整理计划」与「合并进主题」(两条入口最后都走 previewPlan
2839
+ // 的 revision 校验,必然失败);「稍后再说」「忽略」只改 status 不校验
2840
+ // revision,保持可用。
2841
+ var staleRow = item.stale === true || Boolean(candidate && candidate.stale === true);
2842
+ var row = h("div", { key: key, className: "dshi_item" },
2843
+ h("div", { className: "dshi_itemHead" },
2844
+ h("span", null, candidateTitle || "(未识别的卡片)"),
2845
+ h("span", { className: "dshi_mono" }, businessId !== null ? shortId(businessId) : "(缺少 candidate.id)"),
2846
+ candidate && candidate.kind ? h("span", { className: "dshi_badgeDim dshi_badge" }, candidateKindLabel(candidate.kind)) : null,
2847
+ item.status ? h("span", { className: "dshi_badge" }, candidateStatusLabel(item.status)) : null,
2848
+ staleRow ? h("span", { className: "dshi_badge dshi_badgeStale", title: "该候选绑定的卡片版本与分析时不一致" }, "卡片已改") : null,
2849
+ // U5 改名:「稍后再说」(协议仍发 decision=reviewed)——只是收起来,
2850
+ // 不删除任何记忆;点击后该行立即离开「待处理」分组,可在「已阅」分组切回来。
2851
+ h("button", { className: "dshi_btn", disabled: rowDisabled, title: "只是收起来,不会删除任何记忆", onClick: function () { doReview(businessId, "reviewed"); } }, "稍后再说"),
2852
+ h("button", { className: "dshi_btn", disabled: rowDisabled, title: "把候选状态置为 dismissed", onClick: function () { doReview(businessId, "dismissed"); } }, "忽略"),
2853
+ isIsolated ? null : h("button", {
2854
+ className: "dshi_btn",
2855
+ disabled: rowDisabled || staleRow,
2856
+ title: staleRow ? "这条候选绑定的卡片在你上次分析之后被改过,重新分析后才能预览" : undefined,
2857
+ onClick: function () { doPreviewOrganize(businessId); }
2858
+ }, "预览整理计划"),
2859
+ // Q-A:cluster 候选一键进入「合并进主题」流程(选/建主题 → 自动 proposal
2860
+ // → preview diff → 确认执行),不再要求手写 proposal JSON。
2861
+ // U5-e(rework a1):合并流程最后同样走 previewPlan 的 revision 校验,
2862
+ // stale 行一并置灰(否则过期 cluster 从这个后门还是吃到同一颗冲突)。
2863
+ isCluster ? h("button", {
2864
+ className: "dshi_btn dshi_btnPrimary",
2865
+ disabled: rowDisabled || staleRow,
2866
+ title: staleRow ? "这条候选绑定的卡片在你上次分析之后被改过,重新分析后才能合并" : undefined,
2867
+ onClick: function () { openMerge(businessId); }
2868
+ }, "合并进主题") : null),
2869
+ candidateReason !== null ? h("div", { className: "dshi_hint" }, "理由:" + candidateReason) : null,
2870
+ staleRow ? h("div", { className: "dshi_hint" }, "这条候选绑定的卡片在你上次分析之后被改过,重新分析后才能用") : null,
2871
+ // 原始 JSON 默认折叠:details 不写 open,铺满屏幕的长串移出主视线。
2872
+ h("details", { className: "dshi_details" },
2873
+ h("summary", { className: "dshi_hint" }, "原始数据(JSON)"),
2874
+ h("pre", { className: "dshi_pre" }, stableStringify(item))));
2875
+ var extra = [];
2876
+ if (mergeForThisRow) extra.push(renderMergeCard(businessId));
2877
+ if (previewForThisRow) extra.push(renderPreviewCard("preview-" + key));
2878
+ return extra.length > 0 ? [row].concat(extra) : row;
2879
+ };
2880
+ var renderKindGroup = function (group) {
2881
+ var rows = [];
2882
+ items.forEach(function (item, index) {
2883
+ var candidate = queueItemCandidate(item);
2884
+ var kindKey = candidate && candidate.kind ? String(candidate.kind) : "other";
2885
+ // U5:「其他」组兜底收下一切未知 kind(服务端未来新增分类时行不消失,
2886
+ // 徽章保留原文);三个已知组仍用严格相等。
2887
+ if (group.kind === "other") {
2888
+ if (kindKey === "cluster" || kindKey === "link" || kindKey === "isolated") return;
2889
+ } else if (kindKey !== group.kind) {
2890
+ return;
2891
+ }
2892
+ if (!rowVisible(item, candidate)) return;
2893
+ rows.push(renderCandidateRow(item, index, candidate));
2894
+ });
2895
+ var collapsed = collapsedKinds[group.kind] === true;
2896
+ return h("div", { key: group.kind, className: "dshi_kindGroup" },
2897
+ h("button", { type: "button", className: "dshi_groupHead", title: collapsed ? "展开" : "收起", onClick: function () { toggleKindGroup(group.kind); } },
2898
+ h("span", null, (collapsed ? "▸ " : "▾ ") + group.label),
2899
+ h("span", { className: "dshi_groupCount" }, "(" + rows.length + ")")),
2900
+ collapsed || rows.length === 0 ? null : h("div", { className: "dshi_items" }, rows));
2901
+ };
2902
+ var renderPlanRow = function (plan, index) {
2903
+ // 与候选行同一原则:下标只用作渲染 key,planId 缺失时禁用动作而非发下标。
2904
+ var businessPlanId = plan && plan.planId !== undefined && plan.planId !== null
2905
+ ? String(plan.planId)
2906
+ : (plan && plan.id !== undefined && plan.id !== null ? String(plan.id) : null);
2907
+ var planId = businessPlanId !== null ? businessPlanId : String(index);
2908
+ // Q-B:区分 open / executed / superseded(planStore list 投影的布尔;
2909
+ // superseded = 新预览作废旧 open 计划,P 侧 state.mjs 投影提供)。
2910
+ // operationId 仅在 DTO 提供时显示(当前投影只含 executed/superseded 布尔,向前兼容)。
2911
+ var executed = plan.executed === true;
2912
+ var superseded = plan.superseded === true;
2913
+ var executedWith = plan.executedWith ?? plan.operationId;
2914
+ var isForgetting = plan.kind === undefined || String(plan.kind) === "forgetting";
2915
+ var previewForThisPlan = previewTargetId !== null && businessPlanId !== null && previewTargetId === businessPlanId;
2916
+ var row = h("div", { key: planId, className: "dshi_item" },
2917
+ h("div", { className: "dshi_itemHead" },
2918
+ h("span", { className: "dshi_mono" }, businessPlanId !== null ? businessPlanId : "(缺少 planId)"),
2919
+ plan.kind ? h("span", { className: "dshi_badgeDim dshi_badge" }, planKindLabel(plan.kind)) : null,
2920
+ executed ? h("span", { className: "dshi_badge dshi_badgeWarn" }, planStateLabel("executed"))
2921
+ : superseded ? h("span", { className: "dshi_badge dshi_badgeWarn" }, planStateLabel("superseded"))
2922
+ : h("span", { className: "dshi_badgeDim dshi_badge" }, planStateLabel("open")),
2923
+ executedWith !== undefined && executedWith !== null ? h("span", { className: "dshi_hint dshi_mono" }, "op " + String(executedWith)) : null,
2924
+ executed || !isForgetting ? null
2925
+ : h("button", { className: "dshi_btn", disabled: actionsDisabled || businessPlanId === null || superseded, onClick: function () { doPreviewForgetting(businessPlanId); } }, "预览遗忘计划")),
2926
+ executed ? h("div", { className: "dshi_hint" }, "该计划已执行:不可再次预览 / 执行;如需再次整理请重新 analyze。")
2927
+ : superseded ? h("div", { className: "dshi_hint" }, "该计划已被新预览作废(superseded):不可再预览 / 执行(服务端会拒绝并报 REVISION_CONFLICT),请使用最新计划。")
2928
+ : (!isForgetting ? h("div", { className: "dshi_hint" }, "organize 计划请从对应候选的「预览 / 合并进主题」流程执行。") : null),
2929
+ h("details", { className: "dshi_details" },
2930
+ h("summary", { className: "dshi_hint" }, "原始数据(JSON)"),
2931
+ h("pre", { className: "dshi_pre" }, stableStringify(plan))));
2932
+ return previewForThisPlan ? [row, renderPreviewCard("preview-" + planId)] : row;
2933
+ };
2934
+ // U5:open 计划直接列出;executed / superseded 收进默认折叠的分组(数量在组头)。
2935
+ var activePlans = plans.filter(function (p) { return !(p && (p.executed === true || p.superseded === true)); });
2936
+ var archivedPlans = plans.filter(function (p) { return Boolean(p && (p.executed === true || p.superseded === true)); });
2473
2937
  return h("div", null,
2474
2938
  h("div", { className: "dshi_row", style: { marginBottom: 8 } },
2475
2939
  h("span", { className: "dshi_cardTitle" }, "整理 / 遗忘:候选审阅与执行"),
2476
- h("button", { className: "dshi_btn", onClick: load, disabled: busy }, "刷新"),
2940
+ h("button", { className: "dshi_btn", title: "只重新读取队列快照,不会重新分析;要重新分析请点「分析整理候选」", onClick: load, disabled: busy }, "刷新"),
2477
2941
  h("button", { className: "dshi_btn", title: "找出该合并进主题、该建链接、该单独成卡的卡(只读分析,不改数据)", onClick: function () { doAnalyze("organize"); }, disabled: actionsDisabled }, "分析整理候选"),
2478
2942
  h("button", { className: "dshi_btn", title: "按衰减分数找出该归档的旧卡(只读分析)", onClick: function () { doAnalyze("forgetting"); }, disabled: actionsDisabled }, "分析遗忘候选"),
2479
2943
  loaded ? h("span", { className: "dshi_badgeDim dshi_badge" }, "queueRevision " + queueRevision) : null),
2944
+ // U5-e:过期候选顶部提示条——staleCount 是全量口径(不随筛选 / 搜索变化),
2945
+ // 当前视图里没有可见的过期行时仍然显示。「重新分析」复用 doAnalyze("organize")
2946
+ // (与「分析整理候选」同一路径),不新造 RPC。
2947
+ staleCount > 0 ? h("div", { className: "dshi_staleBar" },
2948
+ h("span", null, "有 " + staleCount + " 条候选在你的卡片被改动之后过期了,重新分析后才会更新"),
2949
+ h("button", {
2950
+ className: "dshi_staleBarBtn",
2951
+ title: "重新分析整理候选,过期候选会随之更新",
2952
+ disabled: actionsDisabled,
2953
+ onClick: function () { doAnalyze("organize"); }
2954
+ }, "重新分析")) : null,
2480
2955
  ErrorBox(error),
2481
2956
  ro ? h("div", { className: "dshi_roHint" }, READONLY_HINT_TEXT) : null,
2482
2957
  data ? h(fragment, null,
2483
2958
  h("div", { className: "dshi_card" },
2484
2959
  h("div", { className: "dshi_cardTitle" }, "候选(" + items.length + ")"),
2485
- h("div", { className: "dshi_hint" }, "候选由「分析整理候选 / 分析遗忘候选」生成:集群(≥8 张共享实体或触发词的卡)可直接「合并进主题」,孤立卡只能用内置预览,可建链接用「预览整理计划」。"),
2486
- items.length === 0 ? h("div", { className: "dshi_hint" }, "(空)") : h("div", { className: "dshi_items" }, items.map(function (item, index) {
2487
- // 真机 queueDto:id/kind 在 item.candidate 里(queueItemCandidate 兼容旧扁平形状)。
2488
- // 下标只用作渲染 key;没有业务 id 的行禁用全部动作,不把下标当 candidateId 发 RPC。
2489
- var candidate = queueItemCandidate(item);
2490
- var businessId = candidate && candidate.id !== undefined && candidate.id !== null
2491
- ? String(candidate.id) : null;
2492
- var key = businessId !== null ? businessId : String(index);
2493
- var isCluster = candidate ? String(candidate.kind ?? "") === "cluster" : false;
2494
- var rowDisabled = actionsDisabled || businessId === null;
2495
- // 就地展开:只有被点击的那一行才在自身正下方渲染合并卡(同一 dshi_items 容器内)。
2496
- var mergeForThisRow = Boolean(merge) && businessId !== null && String(merge.candidateId) === businessId;
2497
- // 有了 id→标题映射就把候选翻译成人话:集群说共享词 + 卡数,
2498
- // 链接说「A ↔ B」,孤立卡直接给源卡标题;都没有时退化成短 id。
2499
- var sourceIds = candidate && Array.isArray(candidate.sources)
2500
- ? candidate.sources.map(function (s) { return String(s && s.id); }).filter(Boolean) : [];
2501
- var sourceTitles = sourceIds.map(function (id) { return titles[id] || shortId(id); });
2502
- var evidence = candidate && candidate.evidence && typeof candidate.evidence === "object" ? candidate.evidence : {};
2503
- var candidateKind = candidate && candidate.kind ? String(candidate.kind) : "";
2504
- var candidateTitle = null;
2505
- if (candidateKind === "cluster") {
2506
- var sharedTerm = evidence.sharedTerm || evidence.field;
2507
- candidateTitle = sharedTerm
2508
- ? "合并「" + String(sharedTerm) + "」相关的 " + sourceIds.length + " 张卡"
2509
- : "合并 " + sourceIds.length + " 张卡";
2510
- } else if (candidateKind === "link" && sourceTitles.length >= 2) {
2511
- candidateTitle = "连接:" + sourceTitles.join(" ↔ ");
2512
- } else if (sourceTitles.length === 1) {
2513
- candidateTitle = sourceTitles[0];
2514
- } else if (sourceTitles.length > 1) {
2515
- candidateTitle = sourceTitles.join("、");
2516
- }
2517
- var row = h("div", { key: key, className: "dshi_item" },
2518
- h("div", { className: "dshi_itemHead" },
2519
- h("span", null, candidateTitle || "(未识别的卡片)"),
2520
- h("span", { className: "dshi_mono" }, businessId !== null ? shortId(businessId) : "(缺少 candidate.id)"),
2521
- candidate && candidate.kind ? h("span", { className: "dshi_badgeDim dshi_badge" }, candidateKindLabel(candidate.kind)) : null,
2522
- item.status ? h("span", { className: "dshi_badge" }, candidateStatusLabel(item.status)) : null,
2523
- h("button", { className: "dshi_btn", disabled: rowDisabled, title: "把候选状态置为 reviewed", onClick: function () { doReview(businessId, "reviewed"); } }, "标记已阅"),
2524
- h("button", { className: "dshi_btn", disabled: rowDisabled, title: "把候选状态置为 dismissed", onClick: function () { doReview(businessId, "dismissed"); } }, "忽略"),
2525
- h("button", { className: "dshi_btn", disabled: rowDisabled, onClick: function () { doPreviewOrganize(businessId); } }, "预览整理计划"),
2526
- // Q-A:cluster 候选一键进入「合并进主题」流程(选/建主题 → 自动 proposal
2527
- // → preview diff → 确认执行),不再要求手写 proposal JSON。
2528
- isCluster ? h("button", { className: "dshi_btn dshi_btnPrimary", disabled: rowDisabled, onClick: function () { openMerge(businessId); } }, "合并进主题") : null),
2529
- // 原始 JSON 默认折叠:details 不写 open,铺满屏幕的长串移出主视线。
2530
- h("details", { className: "dshi_details" },
2531
- h("summary", { className: "dshi_hint" }, "原始数据(JSON)"),
2532
- h("pre", { className: "dshi_pre" }, stableStringify(item))));
2533
- return mergeForThisRow ? [row, renderMergeCard(businessId)] : row;
2534
- })),
2535
- h("div", { className: "dshi_cardTitle", style: { marginTop: 6 } }, "计划(" + plans.length + ")"),
2960
+ h("div", { className: "dshi_hint" }, "候选由「分析整理候选 / 分析遗忘候选」生成:集群(≥8 张共享实体或触发词的卡)可「合并进主题」,可建链接的候选可「预览整理计划」,孤立卡没有可连的第二张卡,只能「稍后再说」或「忽略」。"),
2961
+ // U5:筛选条(状态 chips,含各分组计数)+ 纯前端搜索框(按标题或短 id 过滤)。
2962
+ h("div", { className: "dshi_filterBar" },
2963
+ CANDIDATE_FILTERS.map(function (f) {
2964
+ return h("button", { key: f[0], className: "dshi_filterChip" + (filter === f[0] ? " dshi_filterChipOn" : ""), onClick: function () { setFilter(f[0]); } }, f[1] + "(" + statusCounts[f[0]] + ")");
2965
+ }),
2966
+ h("input", { className: "dshi_input dshi_searchInput", placeholder: "搜索:按标题或短 id 过滤", value: search, onChange: function (event) { setSearch(event.target.value); } })),
2967
+ // U5:按 kind 分组折叠(组头显示数量,点组头展开 / 收起;孤立卡默认折叠)。
2968
+ items.length === 0 ? h("div", { className: "dshi_hint" }, "(空)") : CANDIDATE_KIND_GROUPS.map(function (group) {
2969
+ return renderKindGroup(group);
2970
+ }),
2971
+ // U5:底部共享 proposal 文本框已删除(INVALID_INPUT 根因);调试用手写入口
2972
+ // 收进默认折叠的高级区。
2973
+ h("div", { className: "dshi_advanced" },
2974
+ h("button", { type: "button", className: "dshi_groupHead", onClick: function () { setAdvancedOpen(!advancedOpen); } }, (advancedOpen ? "▾ " : "▸ ") + "高级:手动编辑 proposal"),
2975
+ advancedOpen ? h("div", { className: "dshi_fieldRow" },
2976
+ h("div", { className: "dshi_hint" }, "调试用:正常流程请点候选行「预览整理计划」(自动按该候选生成骨架并发送 previewPlan,不需要手写 JSON)。"),
2977
+ h("label", { className: "dshi_label" }, "候选 id(完整 id,从候选行 title 或「原始数据」里复制)",
2978
+ h("input", { className: "dshi_input", value: advancedCandidate, onChange: function (event) { setAdvancedCandidate(event.target.value); } })),
2979
+ h("label", { className: "dshi_label" }, "proposal(buildDraft 形状,服务端严格校验;留空不发送)",
2980
+ h("textarea", { className: "dshi_textarea", value: proposal, placeholder: "留空=未填写(不发送)。按协议手写 link / merge-topic 形状。", onChange: function (event) { setProposal(event.target.value); } })),
2981
+ h("div", { className: "dshi_row" },
2982
+ h("button", { className: "dshi_btn", disabled: busy || ro || !loaded, onClick: doPreviewManual }, "发送预览(手动 proposal)"))) : null)),
2983
+ // U5:计划列表独立成卡(不再挤在候选卡底部);已执行 / 已作废默认折叠。
2984
+ h("div", { className: "dshi_card" },
2985
+ h("div", { className: "dshi_cardTitle" }, "计划(" + plans.length + ")"),
2536
2986
  h("div", { className: "dshi_hint" }, "计划=预览(previewPlan)生成的待执行变更,含 diff 与 planDigest;确认执行后标为「已执行」,被新预览作废的标为「已作废」。整理类计划请从对应候选的「预览整理计划 / 合并进主题」发起,遗忘类计划可用行内「预览遗忘计划」。"),
2537
- plans.length === 0 ? h("div", { className: "dshi_hint" }, "(空)") : h("div", { className: "dshi_items" }, plans.map(function (plan, index) {
2538
- // 与候选行同一原则:下标只用作渲染 key,planId 缺失时禁用动作而非发下标。
2539
- var businessPlanId = plan && plan.planId !== undefined && plan.planId !== null
2540
- ? String(plan.planId)
2541
- : (plan && plan.id !== undefined && plan.id !== null ? String(plan.id) : null);
2542
- var planId = businessPlanId !== null ? businessPlanId : String(index);
2543
- // Q-B:区分 open / executed / superseded(planStore list 投影的布尔;
2544
- // superseded = 新预览作废旧 open 计划,P 侧 state.mjs 投影提供)。
2545
- // operationId 仅在 DTO 提供时显示(当前投影只含 executed/superseded 布尔,向前兼容)。
2546
- var executed = plan.executed === true;
2547
- var superseded = plan.superseded === true;
2548
- var executedWith = plan.executedWith ?? plan.operationId;
2549
- var isForgetting = plan.kind === undefined || String(plan.kind) === "forgetting";
2550
- return h("div", { key: planId, className: "dshi_item" },
2551
- h("div", { className: "dshi_itemHead" },
2552
- h("span", { className: "dshi_mono" }, businessPlanId !== null ? businessPlanId : "(缺少 planId)"),
2553
- plan.kind ? h("span", { className: "dshi_badgeDim dshi_badge" }, planKindLabel(plan.kind)) : null,
2554
- executed ? h("span", { className: "dshi_badge dshi_badgeWarn" }, planStateLabel("executed"))
2555
- : superseded ? h("span", { className: "dshi_badge dshi_badgeWarn" }, planStateLabel("superseded"))
2556
- : h("span", { className: "dshi_badgeDim dshi_badge" }, planStateLabel("open")),
2557
- executedWith !== undefined && executedWith !== null ? h("span", { className: "dshi_hint dshi_mono" }, "op " + String(executedWith)) : null,
2558
- executed || !isForgetting ? null
2559
- : h("button", { className: "dshi_btn", disabled: actionsDisabled || businessPlanId === null || superseded, onClick: function () { doPreviewForgetting(businessPlanId); } }, "预览遗忘计划")),
2560
- executed ? h("div", { className: "dshi_hint" }, "该计划已执行:不可再次预览 / 执行;如需再次整理请重新 analyze。")
2561
- : superseded ? h("div", { className: "dshi_hint" }, "该计划已被新预览作废(superseded):不可再预览 / 执行(服务端会拒绝并报 REVISION_CONFLICT),请使用最新计划。")
2562
- : (!isForgetting ? h("div", { className: "dshi_hint" }, "organize 计划请从对应候选的「预览 / 合并进主题」流程执行。") : null),
2563
- h("details", { className: "dshi_details" },
2564
- h("summary", { className: "dshi_hint" }, "原始数据(JSON)"),
2565
- h("pre", { className: "dshi_pre" }, stableStringify(plan))));
2566
- })),
2567
- h("label", { className: "dshi_label", style: { marginTop: 6 } }, "organize proposal(buildDraft 形状,服务端严格校验;默认留空——点候选行「preview organize」按候选预填骨架,cluster 候选推荐直接用「合并进主题」)",
2568
- h("textarea", { className: "dshi_textarea", value: proposal, placeholder: "留空=未填写(不发送)。点候选行「preview organize」自动预填;或按协议手写 link / merge-topic 形状。", onChange: function (event) { setProposal(event.target.value); } }))),
2987
+ plans.length === 0 ? h("div", { className: "dshi_hint" }, "(空)") : null,
2988
+ activePlans.length > 0 ? h("div", { className: "dshi_items" }, activePlans.map(renderPlanRow)) : null,
2989
+ // U5:已执行 / 已作废默认折叠——原生 details(不写 open),行仍在 DOM 里,
2990
+ // 点开即可切回来查看;组头带数量。
2991
+ archivedPlans.length > 0 ? h("details", { className: "dshi_details" },
2992
+ h("summary", { className: "dshi_groupHead" },
2993
+ h("span", null, "已执行 / 已作废"),
2994
+ h("span", { className: "dshi_groupCount" }, "(" + archivedPlans.length + ")")),
2995
+ h("div", { className: "dshi_items" }, archivedPlans.map(renderPlanRow))) : null),
2569
2996
  ) : null,
2570
2997
  previewError ? ErrorBox(previewError) : null,
2571
- preview && preview.sessionId === props.sessionId ? h("div", { className: "dshi_confirm" },
2572
- h("div", { className: "dshi_cardTitle" }, "PlanView 预览(" + String(preview.plan.kind) + ")",
2573
- h("span", { className: "dshi_mono" }, String(preview.plan.planId)),
2574
- h("span", { className: "dshi_badgeDim dshi_badge" }, String(preview.plan.planDigest))),
2575
- preview.plan.summary ? h("div", { className: "dshi_hint" }, String(preview.plan.summary)) : null,
2576
- Array.isArray(preview.plan.diff) && preview.plan.diff.length > 0 ? preview.plan.diff.map(function (entry, index) {
2577
- return h("div", { key: index, className: "dshi_item" },
2578
- h("div", { className: "dshi_mono" }, String(entry.path ?? index)),
2579
- h("div", { className: "dshi_hint" }, "old"),
2580
- h("pre", { className: "dshi_pre" }, String(entry.oldText ?? "")),
2581
- h("div", { className: "dshi_hint" }, "new"),
2582
- h("pre", { className: "dshi_pre" }, String(entry.newText ?? "")));
2583
- }) : h("div", { className: "dshi_hint" }, "(无 diff 条目)"),
2584
- // Q-B:预览对应的计划若已在 plans 列表里标记 executed / superseded,执行按钮禁用
2585
- (function () {
2586
- var row = plans.find(function (p) { return String(p && p.planId) === String(preview.plan && preview.plan.planId); });
2587
- return row && (row.executed === true || row.superseded === true);
2588
- })() ? h("div", { className: "dshi_hint" }, "该计划已执行或已被新预览作废(plans 列表标记),执行按钮已禁用。") : null,
2589
- h("div", { className: "dshi_row" },
2590
- h("button", {
2591
- className: "dshi_btn dshi_btnDanger",
2592
- disabled: busy || ro || (function () {
2593
- var row = plans.find(function (p) { return String(p && p.planId) === String(preview.plan && preview.plan.planId); });
2594
- return Boolean(row && (row.executed === true || row.superseded === true));
2595
- })(),
2596
- onClick: doExecute
2597
- }, "确认执行(不可撤销)"),
2598
- h("button", { className: "dshi_btn", disabled: busy, onClick: function () { setPreview(null); } }, "取消")))
2599
- : null);
2998
+ showBottomPreview ? renderPreviewCard("preview-bottom") : null);
2600
2999
  }
2601
3000
 
2602
3001
  // ── L3:主题(topic)记忆管理 ────────────────────────────────────────────
@@ -3531,7 +3930,8 @@ window.__ModuleLoader__.load({
3531
3930
  { id: "timeline", label: "最近变更" },
3532
3931
  { id: "memory", label: "记忆 L0/L1" },
3533
3932
  { id: "graph", label: "图谱" },
3534
- { id: "candidates", label: "候选 / 计划" },
3933
+ // U5 改名:候选审阅 + 计划执行合称「整理与遗忘」(tab id 仍为 candidates,协议不变)。
3934
+ { id: "candidates", label: "整理与遗忘" },
3535
3935
  { id: "topics", label: "L3/topic 记忆管理" },
3536
3936
  { id: "flashbacks", label: "闪回命中" },
3537
3937
  { id: "budgets", label: "预算配置" }