feat(view): project KnowledgeStep kinds into DocumentView nodes
Strengthen F09 read-model coverage so observe/derive/call/iterate steps appear alongside artifact cards without executing the document. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
af0bda2e40
commit
69c4e74872
2 files changed
+79
-23
No files matched your search
@@ -146,7 +146,12 @@ pub fn build_document_view(req: &DocumentViewRequest) -> Result<Value, Value> {
|
|||||||
json!([])
|
json!([])
|
||||||
};
|
};
|
||||||
let nodes = if wants("nodes") {
|
let nodes = if wants("nodes") {
|
||||||
nodes_from_presentation(&presentation, &req.node_id)
|
nodes_from_presentation_and_steps(
|
||||||
|
&presentation,
|
||||||
|
&compilation.semantics,
|
||||||
|
&rel,
|
||||||
|
&req.node_id,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
json!([])
|
json!([])
|
||||||
};
|
};
|
||||||
@@ -350,27 +355,67 @@ fn outline_from_presentation(p: &KnowledgePresentation) -> Value {
|
|||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nodes_from_presentation(p: &KnowledgePresentation, filter: &Option<String>) -> Value {
|
fn nodes_from_presentation_and_steps(
|
||||||
json!(p
|
p: &KnowledgePresentation,
|
||||||
.nodes
|
project: &crate::sema::SemanticProject,
|
||||||
.iter()
|
rel: &str,
|
||||||
.filter(|n| filter.as_ref().map(|f| &n.node_id == f || n.artifact_id.as_ref() == Some(f)).unwrap_or(true))
|
filter: &Option<String>,
|
||||||
.map(|n| json!({
|
) -> Value {
|
||||||
"id": n.node_id,
|
let mut out = Vec::new();
|
||||||
"parent_id": Value::Null,
|
for n in &p.nodes {
|
||||||
"kind": n.kind,
|
if filter
|
||||||
"label": n.display_name,
|
.as_ref()
|
||||||
"order": n.source_line,
|
.map(|f| &n.node_id == f || n.artifact_id.as_ref() == Some(f))
|
||||||
"source_span": {"file": n.source_file, "line": n.source_line},
|
.unwrap_or(true)
|
||||||
"artifact_id": n.artifact_id,
|
{
|
||||||
"ref_ids": [],
|
out.push(json!({
|
||||||
"children": [],
|
"id": n.node_id,
|
||||||
"evidence": n.evidence,
|
"parent_id": Value::Null,
|
||||||
"effects": n.effects,
|
"kind": n.kind,
|
||||||
"dependencies": n.dependencies,
|
"label": n.display_name,
|
||||||
"signature": n.signature,
|
"order": n.source_line,
|
||||||
}))
|
"source_span": {"file": n.source_file, "line": n.source_line},
|
||||||
.collect::<Vec<_>>())
|
"artifact_id": n.artifact_id,
|
||||||
|
"ref_ids": [],
|
||||||
|
"children": [],
|
||||||
|
"evidence": n.evidence,
|
||||||
|
"effects": n.effects,
|
||||||
|
"dependencies": n.dependencies,
|
||||||
|
"signature": n.signature,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// F09: project KnowledgeStep kinds (observe/derive/call/iterate/…) into the read model.
|
||||||
|
for step in &project.steps {
|
||||||
|
if step.source.file != rel {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let id = step.id.0.clone();
|
||||||
|
if filter
|
||||||
|
.as_ref()
|
||||||
|
.map(|f| &id == f || &step.reference == f)
|
||||||
|
.unwrap_or(true)
|
||||||
|
{
|
||||||
|
out.push(json!({
|
||||||
|
"id": id,
|
||||||
|
"parent_id": Value::Null,
|
||||||
|
"kind": step.kind,
|
||||||
|
"label": step.reference,
|
||||||
|
"order": step.source.line,
|
||||||
|
"source_span": {
|
||||||
|
"file": step.source.file,
|
||||||
|
"line": step.source.line,
|
||||||
|
"end_line": step.source.end_line
|
||||||
|
},
|
||||||
|
"artifact_id": Value::Null,
|
||||||
|
"ref_ids": step.calls.iter().map(|c| c.as_str()).collect::<Vec<_>>(),
|
||||||
|
"children": [],
|
||||||
|
"evidence": "unverified",
|
||||||
|
"effects": step.effects.values(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json!(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refs_from_project(project: &crate::sema::SemanticProject, rel: &str) -> Value {
|
fn refs_from_project(project: &crate::sema::SemanticProject, rel: &str) -> Value {
|
||||||
|
|||||||
@@ -508,7 +508,18 @@ fn m03_f09_step_kinds_baseline_projects_nodes() {
|
|||||||
"expected heading outline: {outline:?}"
|
"expected heading outline: {outline:?}"
|
||||||
);
|
);
|
||||||
let nodes = resp["result"]["nodes"].as_array().unwrap();
|
let nodes = resp["result"]["nodes"].as_array().unwrap();
|
||||||
assert!(!nodes.is_empty(), "expected at least one semantic node: {nodes:?}");
|
assert!(nodes.len() >= 2, "expected artifact+step nodes: {nodes:?}");
|
||||||
|
let kinds: std::collections::HashSet<&str> = nodes
|
||||||
|
.iter()
|
||||||
|
.filter_map(|n| n["kind"].as_str())
|
||||||
|
.collect();
|
||||||
|
assert!(
|
||||||
|
kinds.iter().any(|k| matches!(
|
||||||
|
*k,
|
||||||
|
"observe" | "derive" | "call" | "iterate" | "narrate" | "type" | "function"
|
||||||
|
)),
|
||||||
|
"expected step/artifact kinds in read model: {kinds:?}"
|
||||||
|
);
|
||||||
// Evidence statuses must not be silently upgraded to verified by the read path.
|
// Evidence statuses must not be silently upgraded to verified by the read path.
|
||||||
for n in nodes {
|
for n in nodes {
|
||||||
if let Some(ev) = n.get("evidence").and_then(|v| v.as_str()) {
|
if let Some(ev) = n.get("evidence").and_then(|v| v.as_str()) {
|
||||||
|
|||||||
Reference in new issue
Block a user