World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
A memory waits in its own words (#735)
WaylandYang3bdd753ca296
diff --git a/crates/utopia-core/src/models.rs b/crates/utopia-core/src/models.rsindex b4d38a66..aa8fa8f9 100644--- a/crates/utopia-core/src/models.rs+++ b/crates/utopia-core/src/models.rs@@ -1417,6 +1417,18 @@ pub struct PendingFactView {/// 网页端对话记的记忆这一位是空的——那时「谁说的」就是那个人本人pub proposed_token_name: Option<String>,pub created_at: DateTime<Utc>,+ /// 文档自己的关系短语(0044)。Some = 这是一条开放陈述:点头后按 `layer = 'open'`+ /// 落进 `facts`,短语照写、没有谓词、不写 `valid_*`;None = 老的带本体形状+ pub phrase: Option<String>,+ /// 开放陈述按文档角色词记的属性:`[{"role": "amount", "value": "$2 million"} |+ /// {"role": "to", "entity_id": "<uuid>"}]`。只在 `phrase` 非空时有意义+ pub qualifiers: Option<serde_json::Value>,+ /// 陈述提到的时间词,**照抄,永远不是日期**(0045):+ /// `[{"text": "March 4, 2011", "char_start": 143}]`,偏移是 `chunks.text` 里的字符偏移+ pub time_words: Option<serde_json::Value>,+ /// 引文在 `chunks.text` 里的字符偏移(不是字节),服务端搜文本算出;NULL = 没定位到+ pub quote_start: Option<i32>,+ pub quote_end: Option<i32>,}/// 一句记忆是谁提的。diff --git a/crates/utopia-server/src/extraction.rs b/crates/utopia-server/src/extraction.rsindex f7a8931e..647251c5 100644--- a/crates/utopia-server/src/extraction.rs+++ b/crates/utopia-server/src/extraction.rs@@ -942,12 +942,13 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:utopia_store::documents::set_graph_status(&state.pool, document_id, "extracting").await?;state.emit_document(doc.kb_id, document_id);// **开放图谱**(0044 第 1 刀,#729):开关开着的库只写文档自己的话,本体不进提示词。- // 记忆日志不走这条路——那里的事实要等人点头(0015),而待确认表里没有短语这一列- if kb.open_extraction- && !utopia_store::memory::is_memory_document(&state.pool, document_id).await?- {- return crate::extraction_open::run_open(state, &doc, &kb, &settings, &client, my_epoch)- .await;+ // 记忆日志也走这条路,只是它的陈述先进待确认表等人点头(0015),点头时才落成开放陈述+ if kb.open_extraction {+ let await_nod = utopia_store::memory::is_memory_document(&state.pool, document_id).await?;+ return crate::extraction_open::run_open(+ state, &doc, &kb, &settings, &client, my_epoch, proposer, await_nod,+ )+ .await;}let etypes = utopia_store::graph::entity_types(&state.pool, doc.kb_id).await?;// 这一轮落过的事实(新建或重复观察):结尾对它们跑一遍签名检查@@ -1568,6 +1569,10 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:chunk_id: chunk.id,proposed_by: proposer.user_id,proposed_token: proposer.token_id,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,},).await?@@ -1780,6 +1785,10 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:chunk_id: chunk.id,proposed_by: proposer.user_id,proposed_token: proposer.token_id,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,},).await?@@ -2001,6 +2010,10 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:chunk_id: chunk.id,proposed_by: proposer.user_id,proposed_token: proposer.token_id,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,},).await?@@ -2376,6 +2389,10 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:chunk_id: chunk.id,proposed_by: proposer.user_id,proposed_token: proposer.token_id,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,},).await?@@ -2571,6 +2588,10 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:chunk_id: chunk.id,proposed_by: proposer.user_id,proposed_token: proposer.token_id,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,},).await?diff --git a/crates/utopia-server/src/extraction_open.rs b/crates/utopia-server/src/extraction_open.rsindex f7b3ea5f..92436221 100644--- a/crates/utopia-server/src/extraction_open.rs+++ b/crates/utopia-server/src/extraction_open.rs@@ -25,9 +25,11 @@ use crate::extraction::{};use crate::state::AppState;use std::collections::{HashMap, HashSet};-use utopia_core::models::{Document, KnowledgeBase, LlmSettings};+use utopia_core::models::{Document, KnowledgeBase, LlmSettings, Proposer};use utopia_store::extraction_drops::reason;use utopia_store::graph::FactObject;+use utopia_store::graph::Validity;+use utopia_store::pending::{Outcome, Proposal};use uuid::Uuid;/// 文档日期只在它来自内容或来源系统时才算证据日期(与 `temporal::DATED_AT` 同一口径)。@@ -74,6 +76,9 @@ fn name_key(name: &str) -> String {.to_lowercase()}+/// `await_nod`:这是记忆日志(0015)——陈述不直接落库,原样进待确认表,人点头时才成为开放陈述。+/// `proposer`:那句话是谁、经哪枚令牌说的(0026),随待确认项一起记+#[allow(clippy::too_many_arguments)]pub(crate) async fn run_open(state: &AppState,doc: &Document,@@ -81,6 +86,8 @@ pub(crate) async fn run_open(settings: &LlmSettings,client: &utopia_llm::LlmClient,my_epoch: i32,+ proposer: Proposer,+ await_nod: bool,) -> anyhow::Result<()> {let pool = &state.pool;let document_id = doc.id;@@ -89,7 +96,13 @@ pub(crate) async fn run_open(let _ = utopia_store::extraction_drops::clear_for_document(pool, document_id).await;let attested_at = dated_at(doc);let chunks = utopia_store::documents::chunks_for_extraction(pool, document_id).await?;- let opening_chunk = utopia_store::documents::opening_chunk(pool, document_id).await?;+ // 记忆日志一句一块,前一句不是后一句的开头,不附(与老路同一条规矩)+ let opening_chunk = if await_nod {+ None+ } else {+ utopia_store::documents::opening_chunk(pool, document_id).await?+ };+ let mut pending_count = 0usize;// 本文档已认下的**有名字的**实体,按首次出现排序,送进后续分块的提示词;// 陈述按名字指它们。被描述的东西不进清单:「一家医院」在下一块里指的未必是同一家@@ -212,8 +225,9 @@ pub(crate) async fn run_open(if !kind.is_empty() {let _ = utopia_store::resolution::set_specific_type(pool, id, kind).await;}- // 名字就在这一块原文里时,给名字事实补出处(0041)- if span_in_quote(name, &chunk.text) {+ // 名字就在这一块原文里时,给名字事实补出处(0041)。记忆日志里的不补:+ // 那一句算不算出处,要等人点头(0018)+ if !await_nod && span_in_quote(name, &chunk.text) {let _ = utopia_store::names::record(pool,kb_id,@@ -354,56 +368,21 @@ pub(crate) async fn run_open(// 开放陈述没有模型自报的置信度:它说的是「文档这么说了」。看图描述出来的块// 照旧压上限(0040 决定 4)let confidence = origin_ceiling(&chunk.origin, 1.0);- let (fact_id, _created) = utopia_store::graph::insert_open_statement(- pool,- kb_id,- subject,- phrase,- fact_object,- attested_at,- confidence,- )- .await?;- // 表层谓词也写短语:今天的读路径都从 `fact_surface_predicate` 取名字- utopia_store::graph::add_evidence_located(- pool,- fact_id,- chunk.id,- quote.map(|(q, _)| q),- Some(phrase),- quote.and_then(|(_, span)| span),- )- .await?;+ // 限定和时间词先算好:直接落库和等人点头两条路用同一份。// 限定:值是清单上某个东西的名字就挂实体,否则挂文字+ let mut qualifiers: Vec<(&str, Option<serde_json::Value>, Option<Uuid>)> = Vec::new();for (role, text) in &s.qualifiers {let (role, text) = (role.trim(), text.trim());if role.is_empty() || text.is_empty() {continue;}match resolve_name(text) {- Some(id) => {- utopia_store::graph::add_statement_qualifier(- pool,- fact_id,- role,- None,- Some(id),- )- .await?- }- None => {- utopia_store::graph::add_statement_qualifier(- pool,- fact_id,- role,- Some(&serde_json::json!(text)),- None,- )- .await?- }+ Some(id) => qualifiers.push((role, None, Some(id))),+ None => qualifiers.push((role, Some(serde_json::json!(text)), None)),}}// 时间词:起与止各是一条提及,必须原样在这条陈述的引文里+ let mut time_words: Vec<(&str, i32)> = Vec::new();for words in [s.when.as_deref(), s.ended.as_deref()].into_iter().flatten()@@ -411,12 +390,7 @@ pub(crate) async fn run_open(.filter(|w| !w.is_empty()){match locate_time(&chunk.text, quote, words) {- Some(start) => {- utopia_store::time_mentions::record(- pool, kb_id, fact_id, chunk.id, words, start,- )- .await?;- }+ Some(start) => time_words.push((words, start)),None => {drop_signal(state,@@ -430,11 +404,98 @@ pub(crate) async fn run_open(}}}+ if await_nod {+ // 记忆日志:一切原样进待确认表(0015),人点头时 `pending::confirm` 才把它+ // 落成开放陈述——同样的短语、限定、时间词、引文偏移+ let (object_id, object_value) = match fact_object {+ FactObject::Entity(id) => (Some(id), None),+ FactObject::Value(v) => (None, Some(v)),+ };+ let qualifiers_json = serde_json::Value::Array(+ qualifiers+ .iter()+ .map(|(role, value, entity)| match entity {+ Some(id) => serde_json::json!({ "role": role, "entity_id": id }),+ None => serde_json::json!({ "role": role, "value": value }),+ })+ .collect(),+ );+ let time_json = serde_json::Value::Array(+ time_words+ .iter()+ .map(|(text, start)| serde_json::json!({ "text": text, "char_start": start }))+ .collect(),+ );+ let outcome = utopia_store::pending::propose(+ pool,+ Proposal {+ kb_id,+ subject_id: subject,+ predicate_id: None,+ object_id,+ object_value,+ proposed_predicate: Some(phrase),+ validity: Validity {+ attested_at,+ ..Default::default()+ },+ confidence,+ chunk_id: chunk.id,+ proposed_by: proposer.user_id,+ proposed_token: proposer.token_id,+ phrase: Some(phrase),+ qualifiers: Some(&qualifiers_json),+ time_words: Some(&time_json),+ quote_span: quote.and_then(|(_, span)| span),+ },+ )+ .await?;+ if let Outcome::Proposed(_) = outcome {+ pending_count += 1;+ }+ statement_count += 1;+ continue;+ }+ let (fact_id, _created) = utopia_store::graph::insert_open_statement(+ pool,+ kb_id,+ subject,+ phrase,+ fact_object,+ attested_at,+ confidence,+ )+ .await?;+ // 表层谓词也写短语:今天的读路径都从 `fact_surface_predicate` 取名字+ utopia_store::graph::add_evidence_located(+ pool,+ fact_id,+ chunk.id,+ quote.map(|(q, _)| q),+ Some(phrase),+ quote.and_then(|(_, span)| span),+ )+ .await?;+ for (role, value, entity) in &qualifiers {+ utopia_store::graph::add_statement_qualifier(+ pool,+ fact_id,+ role,+ value.as_ref(),+ *entity,+ )+ .await?;+ }+ for (words, start) in &time_words {+ utopia_store::time_mentions::record(pool, kb_id, fact_id, chunk.id, words, *start)+ .await?;+ }statement_count += 1;}// ---- 别名(0041 决定 2):服务端只核对名字确实在这一块原文里 ----- for n in &extraction.names {+ // 记忆日志里的别名不记:那一句算不算出处要等人点头(0018)+ for n in extraction.names.iter().filter(|_| !await_nod) {let name = n.name.trim();if name.is_empty() {continue;@@ -521,6 +582,12 @@ pub(crate) async fn run_open(utopia_store::documents::set_graph_status(pool, document_id, "done").await?;state.emit_document(kb_id, document_id);state.emit_graph(kb_id);+ // 队列里多了东西才叫醒人:Review 的计数与对话里那张确认卡都靠这一声+ if pending_count > 0 {+ tracing::info!(%document_id, pending_count, "记忆抽出的陈述进了待确认队列");+ state.emit_pending(kb_id);+ state.emit_review(kb_id);+ }// 灰区对进了审核队列 → 治理 / 裁决任务,同库已排着的不重复。// 不排类型消解、不排自动扩本体:开放图谱里没有类也没有关系可扩,那是对齐的事diff --git a/crates/utopia-store/src/pending.rs b/crates/utopia-store/src/pending.rsindex 0c746fe5..eae5ebe0 100644--- a/crates/utopia-store/src/pending.rs+++ b/crates/utopia-store/src/pending.rs@@ -10,13 +10,18 @@//! 方向对了。0013 的 `derived_facts` 是同一个判断。//!//! **只拦交互式的单条写入。** 批量摄入仍旧乐观写入 + 事后审阅——那条路不经这里。+//!+//! **两种形状**(0044 第一刀,迁移 0062):`phrase` 为空是老的带本体形状(谓词、算出来的+//! `valid_*`),点头走 `insert_fact` + 时态对账;`phrase` 非空是一条开放陈述——文档自己+//! 的关系短语、按角色词记的属性、照抄的时间词、引文在块里的位置——点头走+//! `insert_open_statement`,不问本体、不碰世界轴。use sqlx::PgPool;use utopia_core::models::PendingFactView;use utopia_core::{AppError, AppResult};use uuid::Uuid;-use crate::graph::Validity;+use crate::graph::{FactObject, Validity};/// 抽取器交过来的一条提议。字段与 `insert_fact` / `insert_value_fact` 对齐,/// 多出 `proposed_predicate`(模型原话)、`chunk_id`(那句记忆)、`proposed_by`(谁说的)。@@ -34,6 +39,18 @@ pub struct Proposal<'a> {pub proposed_by: Option<Uuid>,/// 经 MCP 提的话,是哪一枚令牌说的(0026)。网页端对话为空pub proposed_token: Option<Uuid>,+ /// Some = 一条开放陈述(0044):文档自己的关系短语,照写。点头后落成+ /// `facts.layer = 'open'`,没有谓词、不写 `valid_*`。None = 老的带本体形状+ pub phrase: Option<&'a str>,+ /// 按文档角色词记的属性:`[{"role": "amount", "value": "$2 million"} |+ /// {"role": "to", "entity_id": "<uuid>"}]`。只在 `phrase` 非空时有意义+ pub qualifiers: Option<&'a serde_json::Value>,+ /// 陈述提到的时间词,照抄、永远不是日期:`[{"text": "March 4, 2011", "char_start": 143}]`,+ /// 偏移是 `chunks.text` 里的字符偏移。只在 `phrase` 非空时有意义+ pub time_words: Option<&'a serde_json::Value>,+ /// 引文在 `chunks.text` 里的字符偏移 `(start, end)`,服务端搜文本算出、从不取模型+ /// 报的数;没定位到传 None。只在 `phrase` 非空时有意义+ pub quote_span: Option<(i32, i32)>,}/// 提议的去向。三种「没提」都不是错误——重抽一句记忆会再次算出同样的三元组,@@ -50,22 +67,55 @@ pub enum Outcome {}pub async fn propose(pool: &PgPool, p: Proposal<'_>) -> AppResult<Outcome> {- let asserted: Option<(i32,)> = sqlx::query_as(- "SELECT 1 FROM facts- WHERE kb_id = $1 AND subject_id = $2- AND predicate_id IS NOT DISTINCT FROM $3- AND object_id IS NOT DISTINCT FROM $4- AND object_value IS NOT DISTINCT FROM $5- AND invalidated_at IS NULL- LIMIT 1",- )- .bind(p.kb_id)- .bind(p.subject_id)- .bind(p.predicate_id)- .bind(p.object_id)- .bind(p.object_value)- .fetch_optional(pool)- .await?;+ // 开放陈述的短语照写但去掉首尾空白——`insert_open_statement` 也这么做,空短语在这里+ // 就挡下,别让一条点头时才会失败的行进队列+ let phrase = p.phrase.map(str::trim);+ if phrase == Some("") {+ return Err(AppError::invalid(+ "phrase_missing",+ "an open statement keeps the document's relation phrase",+ ));+ }+ // 「图上已经有」:开放陈述在活着的开放行里按 (主语, 短语, 宾语) 找;带本体的形状+ // 照旧按 (主语, 谓词, 宾语)+ let asserted: Option<(i32,)> = match phrase {+ Some(phrase) => {+ sqlx::query_as(+ "SELECT 1 FROM facts+ WHERE kb_id = $1 AND subject_id = $2+ AND layer = 'open' AND phrase = $3+ AND object_id IS NOT DISTINCT FROM $4+ AND object_value IS NOT DISTINCT FROM $5+ AND invalidated_at IS NULL+ LIMIT 1",+ )+ .bind(p.kb_id)+ .bind(p.subject_id)+ .bind(phrase)+ .bind(p.object_id)+ .bind(p.object_value)+ .fetch_optional(pool)+ .await?+ }+ None => {+ sqlx::query_as(+ "SELECT 1 FROM facts+ WHERE kb_id = $1 AND subject_id = $2+ AND predicate_id IS NOT DISTINCT FROM $3+ AND object_id IS NOT DISTINCT FROM $4+ AND object_value IS NOT DISTINCT FROM $5+ AND invalidated_at IS NULL+ LIMIT 1",+ )+ .bind(p.kb_id)+ .bind(p.subject_id)+ .bind(p.predicate_id)+ .bind(p.object_id)+ .bind(p.object_value)+ .fetch_optional(pool)+ .await?+ }+ };if asserted.is_some() {return Ok(Outcome::AlreadyAsserted);}@@ -75,6 +125,7 @@ pub async fn propose(pool: &PgPool, p: Proposal<'_>) -> AppResult<Outcome> {AND predicate_id IS NOT DISTINCT FROM $3AND object_id IS NOT DISTINCT FROM $4AND object_value IS NOT DISTINCT FROM $5+ AND phrase IS NOT DISTINCT FROM $6LIMIT 1",).bind(p.kb_id)@@ -82,26 +133,30 @@ pub async fn propose(pool: &PgPool, p: Proposal<'_>) -> AppResult<Outcome> {.bind(p.predicate_id).bind(p.object_id).bind(p.object_value)+ .bind(phrase).fetch_optional(pool).await?;if pending.is_some() {return Ok(Outcome::AlreadyPending);}- // 拒绝记录只按 (主语, 谓词, 宾语实体) 查。**字面值事实不查**:`rejected_facts`+ // 拒绝记录只按 (主语, 谓词 / 短语, 宾语实体) 查。**字面值事实不查**:`rejected_facts`// 没有 object_value 列,按 (主语, 谓词) 挡会把「薪水 28000 被拒」扩大成- // 「薪水这个属性永远不再提」。宁可多问一次,不替人拒掉一个新值+ // 「薪水这个属性永远不再提」。宁可多问一次,不替人拒掉一个新值。+ // 短语进了键:同一对实体之间换一个短语是另一句话,不被上一句的拒绝连累if let Some(object_id) = p.object_id {let rejected: Option<(i32,)> = sqlx::query_as("SELECT 1 FROM rejected_factsWHERE kb_id = $1 AND subject_id = $2AND predicate_id IS NOT DISTINCT FROM $3AND object_id = $4+ AND phrase IS NOT DISTINCT FROM $5LIMIT 1",).bind(p.kb_id).bind(p.subject_id).bind(p.predicate_id).bind(object_id)+ .bind(phrase).fetch_optional(pool).await?;if rejected.is_some() {@@ -113,8 +168,10 @@ pub async fn propose(pool: &PgPool, p: Proposal<'_>) -> AppResult<Outcome> {"INSERT INTO pending_facts(id, kb_id, subject_id, predicate_id, object_id, object_value, proposed_predicate,valid_from, valid_from_precision, valid_to, valid_to_precision,- confidence, chunk_id, proposed_by, proposed_token)- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",+ confidence, chunk_id, proposed_by, proposed_token,+ phrase, qualifiers, time_words, quote_start, quote_end)+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15,+ $16, $17, $18, $19, $20)",).bind(id).bind(p.kb_id)@@ -131,6 +188,11 @@ pub async fn propose(pool: &PgPool, p: Proposal<'_>) -> AppResult<Outcome> {.bind(p.chunk_id).bind(p.proposed_by).bind(p.proposed_token)+ .bind(phrase)+ .bind(p.qualifiers)+ .bind(p.time_words)+ .bind(p.quote_span.map(|(start, _)| start))+ .bind(p.quote_span.map(|(_, end)| end)).execute(pool).await?;Ok(Outcome::Proposed(id))@@ -144,7 +206,8 @@ const VIEW_SELECT: &str = "\p.valid_from, p.valid_from_precision, p.valid_to, p.valid_to_precision,p.confidence, p.chunk_id, c.text AS quote,p.proposed_by, u.display_name AS proposed_by_name,- t.name AS proposed_token_name, p.created_at+ t.name AS proposed_token_name, p.created_at,+ p.phrase, p.qualifiers, p.time_words, p.quote_start, p.quote_endFROM pending_facts pJOIN entities s ON s.id = p.subject_idLEFT JOIN relation_types r ON r.id = p.predicate_id@@ -199,8 +262,11 @@ fn snapshot(v: &PendingFactView) -> serde_json::Value {"subject": v.subject_name,"predicate": v.predicate_label,"proposed_predicate": v.proposed_predicate,+ "phrase": v.phrase,"object": v.object_name,"object_value": v.object_value,+ "qualifiers": v.qualifiers,+ "time_words": v.time_words,"valid_from": v.valid_from,"valid_to": v.valid_to,"confidence": v.confidence,@@ -213,7 +279,7 @@ pub struct Confirmed {pub fact_id: Uuid,/// false = 图上已有同一条活事实,这次只补了证据pub created: bool,- /// 时态对账拿不准、进了 `fact_conflicts` 的条数+ /// 时态对账拿不准、进了 `fact_conflicts` 的条数。开放陈述不对账,恒为 0pub conflicts: u32,pub snapshot: serde_json::Value,}@@ -226,6 +292,9 @@ pub struct Confirmed {/// 只会补证据、不会落第二条,删行在最后——幂等靡有余悸。pub async fn confirm(pool: &PgPool, kb_id: Uuid, id: Uuid) -> AppResult<Confirmed> {let v = get(pool, kb_id, id).await?;+ if let Some(phrase) = v.phrase.clone() {+ return confirm_open(pool, kb_id, &v, &phrase).await;+ }// 锚点是那句记忆所在文档的日期(0022)——与抽取那条路同一个来源。没起点的// 事实从有证据的那一刻起成立,而证据就是这句话let attested_at: Option<chrono::DateTime<chrono::Utc>> = sqlx::query_scalar(@@ -268,12 +337,7 @@ pub async fn confirm(pool: &PgPool, kb_id: Uuid, id: Uuid) -> AppResult<Confirme).await?}- (None, None) => {- return Err(AppError::invalid(- "pending_fact_has_no_object",- "a pending fact must have an object entity or a literal value",- ))- }+ (None, None) => return Err(no_object()),};// 证据指回那句记忆。引句就是整句——一条 episode 本来就只有一句crate::graph::add_evidence(@@ -337,8 +401,143 @@ pub async fn confirm(pool: &PgPool, kb_id: Uuid, id: Uuid) -> AppResult<Confirme})}+/// 人对一条开放陈述点头(0044):按开放抽取那条路进账本——`insert_open_statement`、+/// 带偏移的证据、角色词属性、时间词——然后从队列里拿掉。+///+/// **不问本体、不做时态对账。** 开放陈述没有谓词,`relation_types` 上没有它的+/// functional / temporal 可查;它提到的时间是照抄的字,在世界轴上还没有位置,+/// 没有 `valid_*` 可以拿去闭合谁。把字读成日期、再对账,是 0045 后面几刀的事。+///+/// 与带本体的那条路一样不包事务:`insert_open_statement` 按 (主语, 短语, 宾语) 在活着的+/// 开放行里去重,证据、属性、时间词都是 ON CONFLICT 幂等的,中途断掉再点一次不会落第二行。+async fn confirm_open(+ pool: &PgPool,+ kb_id: Uuid,+ v: &PendingFactView,+ phrase: &str,+) -> AppResult<Confirmed> {+ // 记录轴的锚点只认文档自己说的日期(#714):`doc_time_source` 是 content / source+ // 才取 `doc_time`,上传时间与文件 mtime 不算。记忆文档是 'none',于是这里为空,+ // `insert_open_statement` 落成此刻——人此刻说的话,人就是证据+ let attested_at: Option<chrono::DateTime<chrono::Utc>> = sqlx::query_scalar(+ "SELECT d.doc_time FROM chunks c JOIN documents d ON d.id = c.document_id+ WHERE c.id = $1 AND d.doc_time_source IN ('content', 'source')",+ )+ .bind(v.chunk_id)+ .fetch_optional(pool)+ .await?+ .flatten();+ let object = match (v.object_id, v.object_value.as_ref()) {+ (Some(object_id), _) => FactObject::Entity(object_id),+ (None, Some(value)) => FactObject::Value(value),+ (None, None) => return Err(no_object()),+ };+ let (fact_id, created) = crate::graph::insert_open_statement(+ pool,+ kb_id,+ v.subject_id,+ phrase,+ object,+ attested_at,+ v.confidence,+ )+ .await?;+ // 证据指回那句记忆,带着引文在块里的位置;`proposed_predicate = phrase`,于是所有+ // 已经容得下空谓词的读路径不改一字就按短语显示它。+ // 引文是**那句话**,不是整块:待确认项上的 quote 是块的全文(带时间戳前缀),+ // 有偏移时按偏移截出这一句,偏移才和引文说同一件事(证据表的 quote 只留 120 字)+ let span = v.quote_start.zip(v.quote_end);+ let sentence: String = match span {+ Some((start, end)) if start >= 0 && end > start => v+ .quote+ .chars()+ .skip(start as usize)+ .take((end - start) as usize)+ .collect(),+ _ => v.quote.clone(),+ };+ crate::graph::add_evidence_located(+ pool,+ fact_id,+ v.chunk_id,+ Some(&sentence),+ Some(phrase),+ span,+ )+ .await?;+ for q in json_items(v.qualifiers.as_ref()) {+ let role = q+ .get("role")+ .and_then(serde_json::Value::as_str)+ .ok_or_else(|| {+ AppError::invalid(+ "qualifier_role",+ "a statement qualifier needs the document's role word",+ )+ })?;+ // 带 entity_id 的指向一个实体;否则 value 就是文档里的那个值,原样落成 JSON+ let entity_id = q+ .get("entity_id")+ .and_then(serde_json::Value::as_str)+ .map(Uuid::parse_str)+ .transpose()+ .map_err(|_| {+ AppError::invalid(+ "qualifier_entity",+ "a statement qualifier's entity_id must be a uuid",+ )+ })?;+ let value = if entity_id.is_some() {+ None+ } else {+ q.get("value")+ };+ crate::graph::add_statement_qualifier(pool, fact_id, role, value, entity_id).await?;+ }+ for t in json_items(v.time_words.as_ref()) {+ let (Some(text), Some(char_start)) = (+ t.get("text").and_then(serde_json::Value::as_str),+ t.get("char_start")+ .and_then(serde_json::Value::as_i64)+ .and_then(|n| i32::try_from(n).ok()),+ ) else {+ return Err(AppError::invalid(+ "time_word_shape",+ "a time word is the document's text and its char offset in the chunk",+ ));+ };+ crate::time_mentions::record(pool, kb_id, fact_id, v.chunk_id, text, char_start).await?;+ }+ sqlx::query("DELETE FROM pending_facts WHERE id = $1")+ .bind(v.id)+ .execute(pool)+ .await?;+ Ok(Confirmed {+ fact_id,+ created,+ conflicts: 0,+ snapshot: snapshot(v),+ })+}++fn no_object() -> AppError {+ AppError::invalid(+ "pending_fact_has_no_object",+ "a pending fact must have an object entity or a literal value",+ )+}++/// 一列 JSON 对象;不是数组(或没有)就是空+fn json_items(v: Option<&serde_json::Value>) -> impl Iterator<Item = &serde_json::Value> {+ v.and_then(serde_json::Value::as_array)+ .map(Vec::as_slice)+ .unwrap_or_default()+ .iter()+}+/// 人拒绝:记进 `rejected_facts`(下一轮重抽先查它),从队列里拿掉。/// 那句记忆本身留着——人确实说过那句话,只是没抽出可用的事实。+/// 开放陈述连短语一起记:拒的是「这句话」,不是这一对实体之间的一切pub async fn reject(pool: &PgPool,kb_id: Uuid,@@ -347,14 +546,15 @@ pub async fn reject() -> AppResult<serde_json::Value> {let v = get(pool, kb_id, id).await?;sqlx::query(- "INSERT INTO rejected_facts (kb_id, subject_id, predicate_id, object_id, rejected_by)- VALUES ($1, $2, $3, $4, $5)",+ "INSERT INTO rejected_facts (kb_id, subject_id, predicate_id, object_id, rejected_by, phrase)+ VALUES ($1, $2, $3, $4, $5, $6)",).bind(kb_id).bind(v.subject_id).bind(v.predicate_id).bind(v.object_id).bind(rejected_by)+ .bind(&v.phrase).execute(pool).await?;sqlx::query("DELETE FROM pending_facts WHERE id = $1")diff --git a/crates/utopia-store/tests/a_fact_awaits_a_nod.rs b/crates/utopia-store/tests/a_fact_awaits_a_nod.rsindex a5c27c05..f72f3842 100644--- a/crates/utopia-store/tests/a_fact_awaits_a_nod.rs+++ b/crates/utopia-store/tests/a_fact_awaits_a_nod.rs@@ -124,6 +124,10 @@ async fn a_remembered_fact_waits_for_a_nod() -> anyhow::Result<()> {chunk_id: f.chunk,proposed_by: None,proposed_token: None,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,},)};diff --git a/crates/utopia-store/tests/a_pending_statement_keeps_the_documents_words.rs b/crates/utopia-store/tests/a_pending_statement_keeps_the_documents_words.rsnew file mode 100644index 00000000..48724131--- /dev/null+++ b/crates/utopia-store/tests/a_pending_statement_keeps_the_documents_words.rs@@ -0,0 +1,283 @@+//! 等人点头的一条陈述也留着文档自己的字(0044 第一刀的记忆侧,迁移 0062)——打在真库上。+//!+//! 对话里说「Acme 把总部搬到了深圳」,抽出来的不再是一条带本体谓词的三元组,而是一条+//! 开放陈述:短语照写、角色词属性、照抄的时间词、引文在块里的位置。它先在+//! `pending_facts` 里等着;人点头之后按 `insert_open_statement` 那条路进账本——+//! `layer = 'open'`、没有谓词、不写 `valid_*`、证据带偏移、属性与时间词各归各表;+//! 摇头之后挡的是**这句话**(短语进了键),同一对实体之间换一句话照样能提。+//!+//! 没有 `UTOPIA_DATABASE_URL` 时跳过而不是失败。自建自拆,绝不碰已有的库。++use sqlx::PgPool;+use utopia_store::pending::{self, Outcome, Proposal};+use uuid::Uuid;++const SENTENCE: &str = "Acme moved its headquarters to Shenzhen on 2026-03-15.";+const PHRASE: &str = "moved its headquarters to";+const TIME_WORDS: &str = "on 2026-03-15";++struct Fixture {+ /// 夹具建的 org,收尾时从它删起(级联)+ org: Uuid,+ kb: Uuid,+ acme: Uuid,+ shenzhen: Uuid,+ chunk: Uuid,+ /// 那句记忆入库后的全文——带 `[YYYY-MM-DD HH:MM] ` 前缀,偏移按它算+ text: String,+}++async fn fixture(pool: &PgPool) -> anyhow::Result<Fixture> {+ let (org, ws, kb) = (Uuid::now_v7(), Uuid::now_v7(), Uuid::now_v7());+ sqlx::query("INSERT INTO organizations (id, name) VALUES ($1, 'pending-words-test')")+ .bind(org)+ .execute(pool)+ .await?;+ sqlx::query("INSERT INTO workspaces (id, org_id, name) VALUES ($1, $2, 'pending-words-test')")+ .bind(ws)+ .bind(org)+ .execute(pool)+ .await?;+ sqlx::query(+ "INSERT INTO knowledge_bases (id, workspace_id, name) VALUES ($1, $2, 'pending-words-test')",+ )+ .bind(kb)+ .bind(ws)+ .execute(pool)+ .await?;+ let (acme, shenzhen) = (Uuid::now_v7(), Uuid::now_v7());+ for (id, name) in [(acme, "Acme"), (shenzhen, "Shenzhen")] {+ sqlx::query("INSERT INTO entities (id, kb_id, canonical_name) VALUES ($1, $2, $3)")+ .bind(id)+ .bind(kb)+ .bind(name)+ .execute(pool)+ .await?;+ }+ // 那句记忆,走产品自己的路落成 chunk+ let (_doc, chunk) =+ utopia_store::memory::append_episode(pool, kb, SENTENCE, chrono::Utc::now()).await?;+ let text: String = sqlx::query_scalar("SELECT text FROM chunks WHERE id = $1")+ .bind(chunk)+ .fetch_one(pool)+ .await?;+ Ok(Fixture {+ org,+ kb,+ acme,+ shenzhen,+ chunk,+ text,+ })+}++/// 引文在块里的字符偏移:服务端搜文本算出来的那个数——从入库后的文本算,不从字面量算+fn span_of(text: &str, quote: &str) -> (i32, i32) {+ let start = text.find(quote).expect("quote is in the chunk");+ let chars_before = text[..start].chars().count() as i32;+ (chars_before, chars_before + quote.chars().count() as i32)+}++async fn live_facts(pool: &PgPool, kb: Uuid) -> anyhow::Result<i64> {+ let (n,): (i64,) =+ sqlx::query_as("SELECT count(*) FROM facts WHERE kb_id = $1 AND invalidated_at IS NULL")+ .bind(kb)+ .fetch_one(pool)+ .await?;+ Ok(n)+}++#[tokio::test]+async fn a_pending_statement_keeps_the_documents_words() -> anyhow::Result<()> {+ let Some(url) = utopia_store::test_db::url() else {+ return Ok(());+ };+ let pool = PgPool::connect(&url).await?;+ let f = fixture(&pool).await?;++ let run = async {+ let (quote_start, quote_end) = span_of(&f.text, SENTENCE);+ let (time_start, _) = span_of(&f.text, TIME_WORDS);+ assert!(quote_start > 0, "入库的文本带时间戳前缀,偏移不能从 0 起");+ let qualifiers = serde_json::json!([{ "role": "on", "value": "2026-03-15" }]);+ let time_words = serde_json::json!([{ "text": TIME_WORDS, "char_start": time_start }]);+ let propose = |phrase: &'static str| {+ pending::propose(+ &pool,+ Proposal {+ kb_id: f.kb,+ subject_id: f.acme,+ predicate_id: None,+ object_id: Some(f.shenzhen),+ object_value: None,+ proposed_predicate: Some(phrase),+ validity: utopia_store::graph::Validity::default(),+ confidence: 0.9,+ chunk_id: f.chunk,+ proposed_by: None,+ proposed_token: None,+ phrase: Some(phrase),+ qualifiers: Some(&qualifiers),+ time_words: Some(&time_words),+ quote_span: Some((quote_start, quote_end)),+ },+ )+ };++ // 1. 提议不上图;队列里的那一条带着文档自己的字+ let first = propose(PHRASE).await?;+ assert!(matches!(first, Outcome::Proposed(_)), "第一次该进队列");+ assert_eq!(live_facts(&pool, f.kb).await?, 0, "提议阶段图上不能有活边");+ let queued = pending::for_chunk(&pool, f.kb, f.chunk).await?;+ assert_eq!(queued.len(), 1);+ let q = &queued[0];+ assert_eq!(q.subject_name, "Acme");+ assert_eq!(q.object_name.as_deref(), Some("Shenzhen"));+ assert_eq!(q.phrase.as_deref(), Some(PHRASE));+ assert!(q.predicate_id.is_none(), "开放陈述没有谓词");+ assert_eq!(q.qualifiers.as_ref(), Some(&qualifiers));+ assert_eq!(q.time_words.as_ref(), Some(&time_words));+ assert_eq!(+ (q.quote_start, q.quote_end),+ (Some(quote_start), Some(quote_end))+ );+ assert_eq!(q.quote, f.text, "原句要跟着提议一起给人看");++ // 2. 同一句重抽不重复提+ assert_eq!(propose(PHRASE).await?, Outcome::AlreadyPending);++ // 3. 点头:按开放陈述进账本+ let Outcome::Proposed(id) = first else {+ unreachable!()+ };+ let done = pending::confirm(&pool, f.kb, id).await?;+ assert!(done.created, "确认该落一条新事实");+ assert_eq!(done.conflicts, 0, "开放陈述不做时态对账");+ assert_eq!(done.snapshot["phrase"], PHRASE);+ assert_eq!(done.snapshot["qualifiers"], qualifiers);+ assert_eq!(live_facts(&pool, f.kb).await?, 1);++ #[derive(sqlx::FromRow)]+ struct Row {+ layer: String,+ phrase: Option<String>,+ predicate_id: Option<Uuid>,+ object_id: Option<Uuid>,+ valid_from: Option<chrono::DateTime<chrono::Utc>>,+ valid_to: Option<chrono::DateTime<chrono::Utc>>,+ attested_from: Option<chrono::DateTime<chrono::Utc>>,+ }+ let row: Row = sqlx::query_as(+ "SELECT layer, phrase, predicate_id, object_id, valid_from, valid_to, attested_from+ FROM facts WHERE id = $1",+ )+ .bind(done.fact_id)+ .fetch_one(&pool)+ .await?;+ assert_eq!(row.layer, "open");+ assert_eq!(row.phrase.as_deref(), Some(PHRASE));+ assert!(row.predicate_id.is_none(), "开放陈述没有谓词");+ assert_eq!(row.object_id, Some(f.shenzhen));+ assert!(+ row.valid_from.is_none() && row.valid_to.is_none(),+ "开放陈述在世界轴上还没有位置"+ );+ assert!(+ row.attested_from.is_some(),+ "记录轴总是有:记忆文档没有文档日期,落成此刻"+ );++ // 证据指回那句记忆,带着引文在块里的位置+ let (ev_chunk, ev_proposed, ev_start, ev_end): (+ Uuid,+ Option<String>,+ Option<i32>,+ Option<i32>,+ ) = sqlx::query_as(+ "SELECT chunk_id, proposed_predicate, quote_start, quote_end+ FROM fact_evidence WHERE fact_id = $1",+ )+ .bind(done.fact_id)+ .fetch_one(&pool)+ .await?;+ assert_eq!(ev_chunk, f.chunk, "证据要指回那句记忆");+ assert_eq!(ev_proposed.as_deref(), Some(PHRASE), "表层谓词就是短语");+ assert_eq!((ev_start, ev_end), (Some(quote_start), Some(quote_end)));+ // 引文就是偏移截出的那句话,不是整块(整块带时间戳前缀,还会被截到 120 字)+ let (ev_quote, at_span): (Option<String>, String) = sqlx::query_as(+ "SELECT fe.quote, substr(c.text, fe.quote_start + 1, fe.quote_end - fe.quote_start)+ FROM fact_evidence fe JOIN chunks c ON c.id = fe.chunk_id WHERE fe.fact_id = $1",+ )+ .bind(done.fact_id)+ .fetch_one(&pool)+ .await?;+ assert_eq!(+ ev_quote.as_deref(),+ Some(at_span.as_str()),+ "证据引文要和偏移截出的字一样"+ );+ assert_eq!(ev_quote.as_deref(), Some(SENTENCE));++ // 角色词属性按文档的角色词落+ let qualifier_rows: Vec<(String, Option<serde_json::Value>, Option<Uuid>)> =+ sqlx::query_as(+ "SELECT role, value, entity_id FROM statement_qualifiers WHERE fact_id = $1",+ )+ .bind(done.fact_id)+ .fetch_all(&pool)+ .await?;+ assert_eq!(qualifier_rows.len(), 1);+ assert_eq!(qualifier_rows[0].0, "on");+ assert_eq!(qualifier_rows[0].1, Some(serde_json::json!("2026-03-15")));+ assert!(qualifier_rows[0].2.is_none());++ // 时间词照抄,偏移在块里能复原出那几个字+ let mentions: Vec<(String, i32, String)> = sqlx::query_as(+ "SELECT m.text, m.char_start, substr(c.text, m.char_start + 1, length(m.text))+ FROM time_mentions m JOIN chunks c ON c.id = m.chunk_id+ WHERE m.fact_id = $1",+ )+ .bind(done.fact_id)+ .fetch_all(&pool)+ .await?;+ assert_eq!(mentions.len(), 1);+ assert_eq!(mentions[0].0, TIME_WORDS);+ assert_eq!(mentions[0].1, time_start);+ assert_eq!(mentions[0].2, TIME_WORDS, "偏移指回的就是块里的那几个字");++ assert!(+ pending::for_chunk(&pool, f.kb, f.chunk).await?.is_empty(),+ "点头后队列清空"+ );++ // 4. 图上已有的不再问+ assert_eq!(propose(PHRASE).await?, Outcome::AlreadyAsserted);++ // 5. 摇头挡的是这句话:短语进了拒绝记录;同一对实体之间换一句话照样能提+ let Outcome::Proposed(bad) = propose("closed its office in").await? else {+ panic!("换一个短语该是新提议");+ };+ pending::reject(&pool, f.kb, bad, None).await?;+ let rejected: Vec<Option<String>> =+ sqlx::query_scalar("SELECT phrase FROM rejected_facts WHERE kb_id = $1")+ .bind(f.kb)+ .fetch_all(&pool)+ .await?;+ assert_eq!(rejected, vec![Some("closed its office in".to_string())]);+ assert_eq!(propose("closed its office in").await?, Outcome::Rejected);+ assert!(+ matches!(propose("opened a lab in").await?, Outcome::Proposed(_)),+ "拒绝只挡那一句话,不挡这一对实体之间的一切"+ );+ assert_eq!(live_facts(&pool, f.kb).await?, 1, "拒绝不碰图");+ Ok::<_, anyhow::Error>(())+ }+ .await;++ // 删掉夹具自己建的 org,级联带走工作区、知识库与其余一切+ sqlx::query("DELETE FROM organizations WHERE id = $1")+ .bind(f.org)+ .execute(&pool)+ .await?;+ run+}diff --git a/crates/utopia-store/tests/an_agent_can_record.rs b/crates/utopia-store/tests/an_agent_can_record.rsindex 99cf08d3..38926743 100644--- a/crates/utopia-store/tests/an_agent_can_record.rs+++ b/crates/utopia-store/tests/an_agent_can_record.rs@@ -118,6 +118,10 @@ async fn seed(pool: &PgPool) -> anyhow::Result<Fixture> {chunk_id: chunk,proposed_by: Some(user),proposed_token,+ phrase: None,+ qualifiers: None,+ time_words: None,+ quote_span: None,};async move {match utopia_store::pending::propose(pool, p).await? {diff --git a/migrations/0062_a_pending_statement_keeps_the_documents_words.sql b/migrations/0062_a_pending_statement_keeps_the_documents_words.sqlnew file mode 100644index 00000000..1f85969e--- /dev/null+++ b/migrations/0062_a_pending_statement_keeps_the_documents_words.sql@@ -0,0 +1,25 @@+-- 等人点头的一条陈述也留着文档自己的字(0044 第一刀的记忆侧,接 0061)。+--+-- 记忆文档(对话里的「记住……」,0015/0018)不直接写事实:抽出来的陈述先在+-- `pending_facts` 里等人点头。那张表只认带本体的形状——`predicate_id`、+-- `proposed_predicate`、算出来的 `valid_*`。抽取只写开放图谱之后(0061),一条+-- 待确认的行必须能装下一条开放陈述,人点头时它才能按开放陈述落进 `facts`:+-- 照写的短语、按文档角色词记的属性、照抄的时间词、引文在块里的位置。+--+-- 全部可空、纯增量:老的带本体形状的行一列不动。`phrase` 非空就是开放陈述,其余+-- 四列只在它非空时有意义。时间词照抄、从不是日期(0045);偏移由服务端搜文本算出,+-- 从不取模型报的数。+ALTER TABLE pending_facts+ -- 文档自己的关系短语(开放陈述);老的带本体形状为 NULL+ ADD COLUMN phrase TEXT,+ -- [{"role": "amount", "value": "$2 million"} | {"role": "to", "entity_id": "<uuid>"}]+ ADD COLUMN qualifiers JSONB,+ -- [{"text": "March 4, 2011", "char_start": 143}] 照抄的字,永远不是日期+ ADD COLUMN time_words JSONB,+ -- 引文在 chunks.text 里的字符偏移(不是字节),服务端算出;NULL = 没定位到+ ADD COLUMN quote_start INT,+ ADD COLUMN quote_end INT;++-- 拒绝过的开放陈述按 (主语, 短语, 宾语) 挡,不按 (主语, 谓词, 宾语):+-- 同一对实体之间换一个短语是另一句话,不该被上一句的拒绝连累+ALTER TABLE rejected_facts ADD COLUMN phrase TEXT;diff --git a/web/src/api.ts b/web/src/api.tsindex a518841f..a193ae77 100644--- a/web/src/api.ts+++ b/web/src/api.ts@@ -752,6 +752,12 @@ export interface PendingFactItem {/** 本体里的关系名;为空时显示 `proposed_predicate`(斜体,标明是原话) */predicate_label: string | null;proposed_predicate: string | null;+ /** 开放陈述(0044):文档自己的关系短语;有它就没有 predicate,那不是缺陷 */+ phrase: string | null;+ /** 按文档角色词记的限定:值或实体 */+ qualifiers: { role: string; value?: unknown; entity_id?: string; entity_name?: string }[] | null;+ /** 照抄的时间词,不是算出来的日期 */+ time_words: { text: string; char_start: number }[] | null;object_id: string | null;object_name: string | null;object_value: { value?: unknown; unit?: string; summary?: string } | null;diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex 17c365f9..ba0421cc 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -1996,6 +1996,7 @@ export const en = {"the sentence is kept, the facts wait for your nod. Confirm to add with the sentence as evidence; " +"reject and it will not be proposed again.",pendingNoPredicate: "The ontology has no relation for this; the word is the model's own.",+ pendingOwnWords: "In the document's own words; binding to the ontology comes with alignment.",pendingNoPredicateChip: "no relation in ontology",pendingSaidBy: (name: string) => `said by ${name}`,/* 同一个人可以挂着好几个 agent,只写人名分不出是哪一个记的 */diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.tsindex 6337c6a7..6b5c03ce 100644--- a/web/src/i18n/zh.ts+++ b/web/src/i18n/zh.ts@@ -1740,6 +1740,7 @@ export const zh: Strings = {"从你让助手记住的话里抽出的事实。这里的东西都还没进图:那句话已经存下,事实等你点头。" +"确认后以那句话为证据进账本;驳回后不会再被提议。",pendingNoPredicate: "本体里没有这个关系,这个词是模型自己的说法。",+ pendingOwnWords: "文档自己的话;对到本体上是对齐那一步的事。",pendingNoPredicateChip: "本体里没有这个关系",pendingSaidBy: (name: string) => `${name} 说的`,pendingSaidVia: (name: string, agent: string) => `${name} 说的 · 经 ${agent}`,diff --git a/web/src/pages/PendingFacts.tsx b/web/src/pages/PendingFacts.tsxindex b5ac488b..7e2f55f2 100644--- a/web/src/pages/PendingFacts.tsx+++ b/web/src/pages/PendingFacts.tsx@@ -52,7 +52,14 @@ export function PendingFactRow({}) {const from = ym(fact.valid_from);const to = ym(fact.valid_to);- const range = from || to ? `${from ?? "…"} → ${to ?? S.review.ongoing}` : null;+ // 开放陈述(0044)带的是照抄的时间词,不是算出来的区间:有词就显示词+ const timeWords = (fact.time_words ?? []).map((t) => t.text).join(" · ");+ const range = timeWords+ ? timeWords+ : from || to+ ? `${from ?? "…"} → ${to ?? S.review.ongoing}`+ : null;+ const qualifiers = fact.qualifiers ?? [];return (<div className="glass rounded-panel p-4">{/* 原句先出。它是人自己说的,判断的依据就是它 */}@@ -63,6 +70,11 @@ export function PendingFactRow({—{" "}{fact.predicate_label ? (<span>{fact.predicate_label}</span>+ ) : fact.phrase ? (+ /* 开放陈述:文档自己的话,斜体标明它是原话而不是词表里的词(0044) */+ <span className="italic text-ink-2" title={S.review.pendingOwnWords}>+ {fact.phrase}+ </span>) : (/* 本体里没有这个关系:显示原话,斜体标明它不是词表里的词(0010) */<span@@ -76,12 +88,22 @@ export function PendingFactRow({</span><span className="text-body font-medium text-ink">{objectText(fact)}</span>{range && <span className="text-small text-ink-2">({range})</span>}- {!fact.predicate_label && (+ {!fact.predicate_label && !fact.phrase && (<Status tone="warn" className="ml-auto shrink-0">{S.review.pendingNoPredicateChip}</Status>)}</div>+ {qualifiers.length > 0 && (+ /* 限定按文档的角色词挂着(0044):金额、对象、比较基准 */+ <div className="mt-2 flex flex-wrap gap-1">+ {qualifiers.map((q) => (+ <span key={q.role} className="rounded-full bg-surface-2 px-2 py-1 text-fine text-ink-2">+ {q.role}: {q.entity_name ?? String(q.value ?? "")}+ </span>+ ))}+ </div>+ )}{/* 与审阅页其余六种卡同一副页脚(CARD_ACTIONS):动作在左,「谁说的」推到右边 */}<div className={CARD_ACTIONS}>{canDecide && (