feat: finish remaining EK plan — bookstore chain, closure, 100-unit corpus

Make examples/executable-knowledge runnable on both backends, bind same-module
Type.member paths, add closure digests to locks/impact, and gate 100 corpus
units plus CLI smoke so S4–S6 leftover items have reviewable evidence.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-10-23 23:34:21 +08:00
1 parent 8a6d09d582
commit 352bc0d2c5
12 files changed
+377 -64

No files matched your search

+12
View File
@@ -138,11 +138,23 @@ fn collect_module_tree(
.map(|u| (u.bind.clone(), u.path.clone()))
.collect();
let start = flat.len();
let mut exports = HashMap::new();
for fun in &module.functions {
let id = collect_fun(fun, None, flat, &path_index, &uses, scope);
export_tree(&mut exports, &[], id, flat);
}
// Same-module BoundCall paths (`Type.member`) must be visible to siblings.
for (rel, idx) in &exports {
path_index.insert(rel.clone(), *idx);
}
for f in &mut flat[start..] {
if f.scope == scope {
for (rel, idx) in &exports {
f.path_index.insert(rel.clone(), *idx);
}
}
}
exports
}
+26 -8
View File
@@ -157,17 +157,35 @@ pub fn resolve_for_exec<'a>(
}
if let Some(path) = &call.path {
if path.len() == 2 && module.import_modules.contains_key(&path[0]) {
if module.import_modules.contains_key(&path[0]) {
return resolve_import_path(module, path);
}
if path.len() == 2 {
// Possible local-variable method; caller checks env.
return ExecTarget::Dynamic {
reason: DynamicReason::MethodReceiver,
name: call_display(call),
};
// Same-module definition-tree path (`Type.member` / nested), BoundCall.
if path.len() >= 2 {
match walk_path(module, path) {
Ok(fun) => return ExecTarget::Local(fun),
Err(_) if path.len() == 2 => {
// Possible local-variable method; caller checks env.
return ExecTarget::Dynamic {
reason: DynamicReason::MethodReceiver,
name: call_display(call),
};
}
Err(message) => {
return ExecTarget::Unresolved {
message,
span_hint: None,
};
}
}
}
return resolve_import_path(module, path);
return ExecTarget::Unresolved {
message: format!(
"library path `{}`: need at least `lib.member`",
path.join(".")
),
span_hint: None,
};
}
if let Some(u) = module.uses.iter().find(|u| u.bind == call.callee) {
+44 -2
View File
@@ -157,6 +157,8 @@ pub struct ArtifactHashes {
pub implementation: Digest,
pub evidence: Digest,
pub artifact: Digest,
/// Transitive dependency closure over call edges (G08).
pub closure: Digest,
}
#[derive(Debug, Clone)]
@@ -325,6 +327,7 @@ pub fn compile_project(options: &CompileOptions) -> Result<Compilation> {
}
}
close_effect_dependencies(&mut artifacts);
close_closure_digests(&mut artifacts);
artifacts.sort_by(|a, b| a.artifact_id.0.cmp(&b.artifact_id.0));
refs.sort_by(|a, b| a.id.cmp(&b.id));
steps.sort_by(|a, b| a.id.0.cmp(&b.id.0));
@@ -717,10 +720,12 @@ fn semantic_artifact(
dependencies.sort_by(|a, b| a.0.cmp(&b.0));
dependencies.dedup();
let artifact = digest(format!("{}:{}:{}", interface.0, implementation.0, evidence.0));
// Placeholder; replaced by `close_closure_digests` after the full graph exists.
let closure = artifact.clone();
SemanticArtifact {
artifact_id, symbol_id, display_name, kind, callable, source, signature, contract,
effects, dependencies, provenance, applicability, hashes: ArtifactHashes {
interface, implementation, evidence, artifact,
interface, implementation, evidence, artifact, closure,
},
verification: VerificationRecord {
parse: "passed".into(), resolve: "passed".into(), contract: "unchecked".into(),
@@ -1007,6 +1012,43 @@ fn direct_effects(calls: &[(usize, CallExpr, u32)]) -> EffectSet {
/// Propagate callee effects along local `dependencies` edges until fixpoint.
/// Empty effect sets become `pure` only after closure (no unknown remains).
/// Fixpoint closure digest: own artifact hash + sorted dependency closure hashes (G08).
fn close_closure_digests(artifacts: &mut [SemanticArtifact]) {
let n = artifacts.len();
let index: BTreeMap<String, usize> = artifacts
.iter()
.enumerate()
.map(|(i, a)| (a.artifact_id.0.clone(), i))
.collect();
for _ in 0..n.saturating_add(1) {
let mut changed = false;
let snap: Vec<String> = artifacts
.iter()
.map(|a| a.hashes.closure.0.clone())
.collect();
for artifact in artifacts.iter_mut() {
let mut parts = vec![artifact.hashes.artifact.0.clone()];
for dep in &artifact.dependencies {
if let Some(&i) = index.get(&dep.0) {
parts.push(snap[i].clone());
} else {
parts.push(dep.0.clone());
}
}
parts.sort();
parts.dedup();
let next = digest(parts.join("|"));
if next.0 != artifact.hashes.closure.0 {
artifact.hashes.closure = next;
changed = true;
}
}
if !changed {
break;
}
}
}
fn close_effect_dependencies(artifacts: &mut [SemanticArtifact]) {
let index: BTreeMap<String, usize> = artifacts
.iter()
@@ -1085,7 +1127,7 @@ impl SemanticProject {
}
pub fn artifact_json(artifact: &SemanticArtifact) -> Value {
json!({"schema_version": SCHEMA_VERSION, "artifact_id": artifact.artifact_id.0, "symbol_id": artifact.symbol_id.as_ref().map(SymbolId::as_str), "display_name": artifact.display_name, "kind": artifact.kind, "callable": artifact.callable, "source": {"file": artifact.source.file, "line": artifact.source.line, "end_line": artifact.source.end_line}, "signature": artifact.signature.as_ref().map(|s| json!({"receiver":s.receiver,"params":s.params.iter().map(|p|json!({"name":p.name,"type":p.ty,"required":p.required,"default_digest":p.default_digest.as_ref().map(|d|&d.0),"unit":p.unit})).collect::<Vec<_>>(),"returns":s.returns,"effects":s.effects.values()})), "contract":{"params":artifact.contract.params,"returns":artifact.contract.returns,"fields":artifact.contract.fields}, "effects":artifact.effects.values(), "dependencies":artifact.dependencies.iter().map(|d|&d.0).collect::<Vec<_>>(), "provenance":artifact.provenance.iter().map(|p|json!({"uri":p.uri,"locator":p.locator,"content_digest":p.content_digest.as_ref().map(|d|&d.0),"relation":p.relation})).collect::<Vec<_>>(), "applicability":artifact.applicability, "hashes":{"interface":artifact.hashes.interface.0,"implementation":artifact.hashes.implementation.0,"evidence":artifact.hashes.evidence.0,"artifact":artifact.hashes.artifact.0}, "verification":{"parse":artifact.verification.parse,"resolve":artifact.verification.resolve,"contract":artifact.verification.contract,"execution":artifact.verification.execution,"tests":artifact.verification.tests,"evidence":artifact.verification.evidence,"domain":artifact.verification.domain,"methods":artifact.verification.methods}, "lifecycle":artifact.lifecycle})
json!({"schema_version": SCHEMA_VERSION, "artifact_id": artifact.artifact_id.0, "symbol_id": artifact.symbol_id.as_ref().map(SymbolId::as_str), "display_name": artifact.display_name, "kind": artifact.kind, "callable": artifact.callable, "source": {"file": artifact.source.file, "line": artifact.source.line, "end_line": artifact.source.end_line}, "signature": artifact.signature.as_ref().map(|s| json!({"receiver":s.receiver,"params":s.params.iter().map(|p|json!({"name":p.name,"type":p.ty,"required":p.required,"default_digest":p.default_digest.as_ref().map(|d|&d.0),"unit":p.unit})).collect::<Vec<_>>(),"returns":s.returns,"effects":s.effects.values()})), "contract":{"params":artifact.contract.params,"returns":artifact.contract.returns,"fields":artifact.contract.fields}, "effects":artifact.effects.values(), "dependencies":artifact.dependencies.iter().map(|d|&d.0).collect::<Vec<_>>(), "provenance":artifact.provenance.iter().map(|p|json!({"uri":p.uri,"locator":p.locator,"content_digest":p.content_digest.as_ref().map(|d|&d.0),"relation":p.relation})).collect::<Vec<_>>(), "applicability":artifact.applicability, "hashes":{"interface":artifact.hashes.interface.0,"implementation":artifact.hashes.implementation.0,"evidence":artifact.hashes.evidence.0,"artifact":artifact.hashes.artifact.0,"closure":artifact.hashes.closure.0}, "verification":{"parse":artifact.verification.parse,"resolve":artifact.verification.resolve,"contract":artifact.verification.contract,"execution":artifact.verification.execution,"tests":artifact.verification.tests,"evidence":artifact.verification.evidence,"domain":artifact.verification.domain,"methods":artifact.verification.methods}, "lifecycle":artifact.lifecycle})
}
fn ref_json(reference: &KnowledgeRef) -> Value { json!({"id":reference.id,"label":reference.label,"context":reference.context,"source":{"file":reference.source.file,"line":reference.source.line,"end_line":reference.source.end_line},"resolution":reference.resolution,"target":reference.target.as_ref().map(SymbolId::as_str)}) }
fn step_json(step: &KnowledgeStep) -> Value { json!({"id":step.id.0,"reference":step.reference,"kind":step.kind,"calls":step.calls.iter().map(SymbolId::as_str).collect::<Vec<_>>(),"effects":step.effects.values(),"source":{"file":step.source.file,"line":step.source.line,"end_line":step.source.end_line}}) }
+8 -1
View File
@@ -74,7 +74,7 @@ pub fn check_links_lock(out_dir: &Path, project: &SemanticProject) -> Result<Loc
None => report.missing.push(id.clone()),
Some(found) => {
let mut drifted = Vec::new();
for key in ["interface", "implementation", "evidence", "artifact"] {
for key in ["interface", "implementation", "evidence", "artifact", "closure"] {
let want = entry.get(key).and_then(Value::as_str);
let got = found.get(key).and_then(Value::as_str);
if want != got {
@@ -119,6 +119,11 @@ pub fn impact(project: &SemanticProject, query: &str) -> Value {
|| artifact.symbol_id.as_ref().is_some_and(|id| id.as_str() == query)
|| artifact.display_name == query
|| artifact.source.file == query
|| artifact.source.file.ends_with(query)
|| std::path::Path::new(&artifact.source.file)
.file_stem()
.and_then(|s| s.to_str())
.is_some_and(|stem| stem == query || query.ends_with(stem))
|| artifact.artifact_id.0.ends_with(query)
{
seeds.insert(artifact.artifact_id.0.clone());
@@ -182,6 +187,7 @@ fn artifact_lock_entries(project: &SemanticProject) -> BTreeMap<String, Value> {
"implementation": artifact.hashes.implementation.0,
"evidence": artifact.hashes.evidence.0,
"artifact": artifact.hashes.artifact.0,
"closure": artifact.hashes.closure.0,
}),
)
})
@@ -196,6 +202,7 @@ fn lock_json(project: &SemanticProject) -> Value {
"implementation": artifact.hashes.implementation.0,
"evidence": artifact.hashes.evidence.0,
"artifact": artifact.hashes.artifact.0,
"closure": artifact.hashes.closure.0,
"dependencies": artifact.dependencies.iter().map(|item| &item.0).collect::<Vec<_>>(),
}));
}