Skip to content

World's first open-source enterprise world model.

Render nested proof trees in the entity panel (#477 cut 3) (#790)

Royce9d565285ca67
diff --git a/web/src/api.ts b/web/src/api.ts
index 6c265721..6d63cc32 100644
--- a/web/src/api.ts
+++ b/web/src/api.ts
@@ -433,7 +433,12 @@ export interface BlockedDerivation {
premises: string[];
}
-/** 证明的一步:一条断言前提,带它的证据。前提一律是断言,所以证明是链不是树 */
+/** 证明的一步:一条前提,连同它的证据(0002 R2)。
+ *
+ * 那一步自己的前提在 `premises` 里再往下一层。所以证明是一棵树,
+ * 深度与推理同一条上限。断言那一步 `premises` 是空的——它的叶子是
+ * `evidence` 里的原句,不必再往下问
+ */
export interface ProofStep {
seq: number;
fact_id: string;
@@ -449,6 +454,8 @@ export interface ProofStep {
/** 这条前提后来被撤了;派生随之失效,证明仍要读得出当时靠的是什么 */
retracted: boolean;
evidence: Evidence[];
+ /** 这一步自己的前提(0030):按 seq 展开的子证明。叶子的 premises 为空 */
+ premises: ProofStep[];
}
export interface Proof {
diff --git a/web/src/pages/Graph.tsx b/web/src/pages/Graph.tsx
index b6d2fef9..5d152fa6 100644
--- a/web/src/pages/Graph.tsx
+++ b/web/src/pages/Graph.tsx
@@ -2520,68 +2520,88 @@ function ProofChain({ kbId, d }: { kbId: string; d: DerivedFact }) {
);
}
-/** 证明的步,落了地的与没落地的派生共用:前提是同一种东西 */
+/** 证明的步,落了地的与没落地的派生共用:前提是同一种东西。
+ *
+ * 递归:每一步的 `premises` 是它的子证明,在自己的 `<li>` 里再嵌一个
+ * `<ol>`。深度的视觉上限由服务器决定(0030 推理的同一道闸),不在
+ * 客户端重画——叶子那一步 `premises` 为空,递归停在这里
+ */
function ProofSteps({ kbId, steps }: { kbId: string; steps: ProofStep[] }) {
return (
<ol className="space-y-2">
- {steps.map((st) => (
- <li key={st.fact_id} className="text-fine">
- <div className="flex items-baseline gap-2 flex-wrap">
- <span className="u-num text-fine text-ink-2 shrink-0">
- {S.graph.proofStep(st.seq + 1)}
- </span>
- <span className={st.retracted ? "text-ink-2 line-through" : "text-ink-2"}>
- {st.subject}
- <span className="text-ink-2"> — {st.predicate ?? "?"} → </span>
- {st.object ?? "?"}
- </span>
- {st.retracted && (
- <Chip tone="warn" className="text-fine">{S.graph.proofRetracted}</Chip>
- )}
- </div>
- <div className="mt-1 space-y-1 pl-2">
- {st.evidence.map((ev) => (
- <Link
- key={ev.chunk_id}
- to="/kb/$kbId/doc/$docId"
- params={{ kbId, docId: ev.document_id }}
- search={{ chunk: ev.chunk_id }}
- className="u-hover-ink block text-ink-2"
- >
- <div className="line-clamp-2 italic">
- {ev.quote ? `“${ev.quote}”` : S.graph.noQuote}
- </div>
- <div className="mt-1 text-ink-2">
- {S.graph.sectionRef(ev.filename, ev.seq + 1)}
- {ev.stale && (
- <span
- className="ml-2 u-num text-fine text-ink-2"
- title={S.graph.staleEvidenceHint}
- >
- {S.graph.fromVersion(ev.doc_version)}
- </span>
- )}
- {ev.document_deleted && (
- <span
- className="ml-2 text-fine text-contest"
- title={S.graph.sourceDeletedHint}
- >
- {S.graph.sourceDeleted}
- </span>
- )}
- </div>
- </Link>
- ))}
- {st.evidence.length === 0 && (
- <p className="text-ink-2">{S.graph.noEvidence}</p>
- )}
- </div>
- </li>
- ))}
+ {steps.map((st) => <ProofStepRow key={st.fact_id} kbId={kbId} step={st} />)}
</ol>
);
}
+/** 单条证明步:它的「子证明」在 `step.premises` 里再渲染一次 ProofSteps。
+ *
+ * 拆出来是为了让递归有界——这一个组件自己只画一层,premises 是再调
+ * 一次顶层组件(同一份渲染逻辑,不另写一份),靠 `premises` 数组
+ * 自然终止。深度的递归深度上限由服务器(0030),不在客户端画
+ */
+function ProofStepRow({ kbId, step }: { kbId: string; step: ProofStep }) {
+ return (
+ <li className="text-fine">
+ <div className="flex items-baseline gap-2 flex-wrap">
+ <span className="u-num text-fine text-ink-2 shrink-0">
+ {S.graph.proofStep(step.seq + 1)}
+ </span>
+ <span className={step.retracted ? "text-ink-2 line-through" : "text-ink-2"}>
+ {step.subject}
+ <span className="text-ink-2"> — {step.predicate ?? "?"} → </span>
+ {step.object ?? "?"}
+ </span>
+ {step.retracted && (
+ <Chip tone="warn" className="text-fine">{S.graph.proofRetracted}</Chip>
+ )}
+ </div>
+ <div className="mt-1 space-y-1 pl-2">
+ {step.evidence.map((ev) => (
+ <Link
+ key={ev.chunk_id}
+ to="/kb/$kbId/doc/$docId"
+ params={{ kbId, docId: ev.document_id }}
+ search={{ chunk: ev.chunk_id }}
+ className="u-hover-ink block text-ink-2"
+ >
+ <div className="line-clamp-2 italic">
+ {ev.quote ? `“${ev.quote}”` : S.graph.noQuote}
+ </div>
+ <div className="mt-1 text-ink-2">
+ {S.graph.sectionRef(ev.filename, ev.seq + 1)}
+ {ev.stale && (
+ <span
+ className="ml-2 u-num text-fine text-ink-2"
+ title={S.graph.staleEvidenceHint}
+ >
+ {S.graph.fromVersion(ev.doc_version)}
+ </span>
+ )}
+ {ev.document_deleted && (
+ <span
+ className="ml-2 text-fine text-contest"
+ title={S.graph.sourceDeletedHint}
+ >
+ {S.graph.sourceDeleted}
+ </span>
+ )}
+ </div>
+ </Link>
+ ))}
+ {step.evidence.length === 0 && (
+ <p className="text-ink-2">{S.graph.noEvidence}</p>
+ )}
+ </div>
+ {step.premises.length > 0 && (
+ <div className="mt-1 ml-4 border-l border-edge pl-3">
+ <ProofSteps kbId={kbId} steps={step.premises} />
+ </div>
+ )}
+ </li>
+ );
+}
+
/** 没落地的派生(0017 §3):像 DerivedRow 一样的一行,多一句「挡住它的是谁」,
* 展开是它的证明链——人在这里看到「引擎本可以画这条边,是什么拦住了它」 */
function BlockedRow({