feat: candidate location + evidence status and document-structure index contract (#14/#12) #15
No files matched your search
@@ -50,6 +50,7 @@ must not be claimed as passing.
|
||||
| Compile command incl. digest-based incremental facts reuse and conservative re-analysis bound | implemented | `tests/compile.rs` |
|
||||
| Check command (sources, references, database structure/currentness) | implemented | `tests/compile.rs`, `tests/query.rs` |
|
||||
| Exact / lexical / fuzzy / graph query, weighted RRF, bounded expansion | implemented | `src/query/*` tests, `tests/query.rs` |
|
||||
| Candidate location + evidence status (module/unit/anchor/span/digest, current/stale, `nature: unspecified`) | implemented | `tests/query.rs`, `spec/knowledge.md` §3.1.1/§4.1 |
|
||||
| Document / execution / hybrid slices with 32 KiB budget | implemented | `tests/query.rs`, `src/query/slice.rs` |
|
||||
| OKF v0.3 metadata recognition, reserved roles, concept aliases, `check --okf` conformance | implemented | `tests/okf.rs` |
|
||||
| Explicit OpenAI-compatible semantic channel with all-or-nothing indexing | implemented | `tests/embedding.rs` (local mock protocol server) |
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
# Knowledge candidate 3bd9336 — candidate location, evidence status and structure index contract
|
||||
|
||||
Date: 2026-11-30.
|
||||
Repository: `cflmy/marqdo-knowledge`.
|
||||
Candidate commit: `3bd93363a14243ebc954b382a8a7c41d9bdecc96`
|
||||
(branch `codex/issue-14-13-location-and-index-contract`).
|
||||
Issues: [marqdo-knowledge#14](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/14)
|
||||
(P1 slice), [#12](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/12),
|
||||
[#13](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/13),
|
||||
[#7](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/7),
|
||||
[#11](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/11).
|
||||
Parent tickets: `marqdo#55` §14, `marqdo#56` §2/§4.
|
||||
|
||||
Executed host: Linux x86_64, glibc 2.43, `rustc 1.100.0 (0ef1bc386
|
||||
2026-11-09)`, Python 3.14.4.
|
||||
|
||||
## 1. Input identity
|
||||
|
||||
* Core CLI: `marqdo` 3.0.0-rc.6 built from CLI candidate
|
||||
`0f87f856dba28e34bbd2743d23b8f9b1fe96424a` (CLI PR `#27`; merged after this
|
||||
record — regression condition: re-run with the merged CLI SHA/published rc.6
|
||||
archive).
|
||||
* Bundle: `marqdo-stdlib 0.2.0`,
|
||||
tree digest `sha256:db905508dde89763b9d43b47fc5d52c6a1d5445a91f3c86a550ced43e8aac9d7`.
|
||||
* Document-structure contract used as design input:
|
||||
`marqdo-cli/spec/document-structure.md` at the same CLI candidate.
|
||||
* The published rc.6 归档 (`8dc0b006…`) was **not** downloaded here; the
|
||||
upstream tracking issue #11 remains `UNVERIFIED` for the public artifact.
|
||||
|
||||
## 2. Source gates
|
||||
|
||||
| Command | Result |
|
||||
|---|---|
|
||||
| `cargo fmt --all -- --check` | PASS |
|
||||
| `cargo clippy --workspace --all-targets --locked -- -D warnings` | PASS |
|
||||
| `cargo test --workspace --locked` | PASS: 140 passed, 0 failed |
|
||||
| `MARQDO_BIN=<candidate> sh scripts/ci.sh core` | PASS (real-ClI .mq.md tests + workspace tests + example check) |
|
||||
| `MARQDO_BIN=<candidate> sh scripts/ci.sh release` | PASS: archive `marqdo-knowledge-0.1.0-beta.3-x86_64-unknown-linux-gnu.tar.gz`, sha256 `aeb8288279881542ef1fcd0cf1ebf2e5bc80b9ab0b864d36e7cb28e33f26f007`, smoke `OK` |
|
||||
|
||||
Release smoke payload (`dist/RELEASE_INFO.json` smoke summary):
|
||||
|
||||
```json
|
||||
{"archive": "marqdo-knowledge-0.1.0-beta.3-x86_64-unknown-linux-gnu.tar.gz",
|
||||
"archive_sha256": "aeb8288279881542ef1fcd0cf1ebf2e5bc80b9ab0b864d36e7cb28e33f26f007",
|
||||
"core": "marqdo 3.0.0-rc.6", "database": "current", "documents": 5,
|
||||
"query_hits": 4, "schema": "marqdo.knowledge.smoke", "schema_version": 1,
|
||||
"source_sha": "3bd93363a14243ebc954b382a8a7c41d9bdecc96",
|
||||
"version": "0.1.0-beta.3"}
|
||||
```
|
||||
|
||||
This is a local candidate archive, not a published release.
|
||||
|
||||
## 3. Delivered contract (P1 of #14 + #12)
|
||||
|
||||
Every query hit now returns two additive optional objects (schema_version stays
|
||||
1; consumers ignore unknown fields):
|
||||
|
||||
* `location`: `module_id`, `unit_id`, `unit_kind`, `anchors[]`, `path[]`,
|
||||
`level`, `mode`, `nature`, exact `span`. Built from public Analysis
|
||||
`units[]`/`anchors[]` (or this tool's plain-Markdown heading facts); upstream
|
||||
identity stays `null` when the document has none and is never fabricated.
|
||||
* `evidence`: `status` (`current`/`stale`), `source_digest`,
|
||||
`snapshot_digest`. `status` follows the database input manifest; a snapshot
|
||||
query reports `stale`.
|
||||
* `nature` is always `unspecified` for now: the current public inputs do not
|
||||
declare normative/explanatory/experimental/historical status, and Knowledge
|
||||
does not invent metadata syntax.
|
||||
* `related[].relation` keeps `contains/references/imports/calls`; a Markdown
|
||||
link remains a `references` edge and never becomes an import or execution
|
||||
dependency.
|
||||
|
||||
`spec/knowledge.md` §3.1.1 documents the candidate/evidence contract and §4.1
|
||||
documents the document-structure index semantics (entry vs navigation,
|
||||
units/anchors/spans, link≠import≠call, `index.mq.md`, nature,
|
||||
candidate→exact-read boundary). `tests/query.rs` asserts the fields on a real
|
||||
compiled project (`hits_return_a_stable_location_and_evidence_status`).
|
||||
|
||||
The `graph` unit-node metadata now records `module_id`, `unit_kind`, `anchors`
|
||||
and `nature` so query assembly needs no second parse and no extra source read.
|
||||
|
||||
## 4. Issue mapping
|
||||
|
||||
| Issue item | This candidate |
|
||||
|---|---|
|
||||
| #14 P1 index semantics contract | spec §4.1 |
|
||||
| #14 P1 candidate location/evidence schema | spec §3.1.1 + query JSON + test |
|
||||
| #14 §2 entry/navigation distinction | `entry_module_id` documented; no directory scan; navigation is not executable |
|
||||
| #14 §3 relation separation | existing edge vocabulary documented; no link→import upgrade |
|
||||
| #14 §4 nature/authority | `nature: unspecified`, never inferred |
|
||||
| #14 §5 candidate→exact read | `location` carries module/unit/anchor/span/digest; body reading stays CLI public capability |
|
||||
| #12 exact refs + freshness | `location` + `evidence.status/current` |
|
||||
| #13 release evidence | release lane PASS above (local candidate) |
|
||||
| #7 immutable release transaction | existing package/verify entry exercised; recommendation: close after candidate CI |
|
||||
| #11 rc.6 upstream | local candidate only; published artifact `UNVERIFIED` |
|
||||
|
||||
## 5. Not verified / limits
|
||||
|
||||
* macOS/Windows native lanes: **UNVERIFIED** (no runner).
|
||||
* Published rc.6 archive consumption (#11): **UNVERIFIED**; requires the
|
||||
published asset and CI-image refresh.
|
||||
* Retrieval quality metrics (Recall/MRR/RSS), real-model semantic quality:
|
||||
**UNVERIFIED** (unchanged from beta.3 STATUS).
|
||||
* Formal release/tag for this candidate: **not created**; publication needs
|
||||
maintainer approval after same-SHA CI.
|
||||
* #14 P2/P3 (navigation/authority annotation coverage, cold-start evaluation)
|
||||
remain open; this candidate only lands P1 + the #12 contract.
|
||||
@@ -110,6 +110,52 @@ current Analysis passed static checking; it is interface information, not
|
||||
execution permission. Every `snippet` is an exact source slice; external nodes
|
||||
carry no fabricated path, span or snippet.
|
||||
|
||||
### 3.1.1 Candidate location and evidence (additive)
|
||||
|
||||
Every hit may carry two optional objects. They are additive within
|
||||
`schema_version: 1`: consumers must ignore unknown fields and must not treat
|
||||
their absence as an error (older databases predate them).
|
||||
|
||||
```json
|
||||
"location": {
|
||||
"module_id": "root:demo@0.1.0::index.mq.md",
|
||||
"unit_id": "root:demo@0.1.0::index.mq.md#力学/计算力",
|
||||
"unit_kind": "function",
|
||||
"anchors": ["计算力"],
|
||||
"path": ["力学", "计算力"],
|
||||
"level": 2,
|
||||
"mode": "exec",
|
||||
"nature": "unspecified",
|
||||
"span": {"start": 100, "end": 180}
|
||||
},
|
||||
"evidence": {
|
||||
"status": "current",
|
||||
"source_digest": "sha256:...",
|
||||
"snapshot_digest": "sha256:..."
|
||||
}
|
||||
```
|
||||
|
||||
* `location` is the document-structure identity from the public Analysis
|
||||
projection (`units[].id/path/level/mode`, `anchors[]`) or from this tool's own
|
||||
plain-Markdown heading projection. `unit_id`/`module_id` stay `null` when the
|
||||
document has no Analysis module identity; they are never fabricated.
|
||||
`anchors` are navigation names, not identities or execution rights.
|
||||
* `nature` is the authority/nature marker from `marqdo#55` §5. It is
|
||||
`"unspecified"` unless an existing public input (document structure or OKF
|
||||
metadata) declares a nature. Knowledge never guesses normative, explanatory,
|
||||
experimental or historical status and never adds metadata syntax.
|
||||
* `evidence.status` is `current` only when the database input manifest still
|
||||
matches the source snapshot. A `--snapshot` query or a stale database reports
|
||||
`stale`; the result envelope's `current` flag is authoritative for the whole
|
||||
result.
|
||||
* `source`/`source.span` remain the exact snippet location; `location` is the
|
||||
structured candidate address. Neither is a second knowledge body: the
|
||||
authoritative text is always the source file, read through the CLI's public
|
||||
capability.
|
||||
* `related[].relation` keeps the public vocabulary (`contains`, `references`,
|
||||
`imports`, `calls`). A Markdown link is a `references` relation and is never
|
||||
rewritten into an import or execution dependency.
|
||||
|
||||
### 3.2 Error
|
||||
|
||||
```json
|
||||
@@ -147,6 +193,29 @@ link semantics; `check --okf` additionally applies OKF bundle-root absolute
|
||||
link semantics and reports conformance/notice diagnostics. OKF never executes an
|
||||
executor or attester and never upgrades trust.
|
||||
|
||||
## 4.1 Document-structure index semantics
|
||||
|
||||
The index reuses the current document structure; it does not define a second
|
||||
one. The mapping from public facts to indexed objects is:
|
||||
|
||||
| Public fact | Indexed as | Notes |
|
||||
|---|---|---|
|
||||
| `project.entry_module_id`, `project.root_id` | document metadata `analysis` | Entry is a project fact. `index.mq.md` is an ordinary document; the index never scans directories or treats navigation content as an entry. |
|
||||
| `units[]` heading tree | `namespace`/`section`/`function` nodes | Metadata `path`, `level`, `mode`, `unit_kind`, `unit_id`, `anchors`; root is the document node. |
|
||||
| `anchors[]` | node metadata `anchors` | Navigation names, unique by construction; the CLI numbers slug collisions. They are not identities. |
|
||||
| `source_digest`, `span` | documents/node spans | Every snippet is an exact UTF-8 byte slice of the recorded source; Analysis inputs are digest-checked before indexing. |
|
||||
| `references[]` | `references` edges (origin `document`) | States are preserved verbatim (`resolved`/`not_loaded`/`missing`/`ambiguous`/`external`/`outside_scope`/`invalid`). A link is knowledge navigation, never an import or execution edge. |
|
||||
| `imports[]` | `imports` edges (origin `analysis`) | Only explicit imports create module dependencies. |
|
||||
| `calls[]` | `calls` edges (origin `analysis`) | Static call graph; unresolved/dynamic calls stay explicitly unresolved. |
|
||||
| `resources[]` | resource nodes | Inert formula/code payloads; no execution. |
|
||||
| structure / OKF metadata | `nature` in the candidate location | `unspecified` when the inputs do not declare a nature. |
|
||||
|
||||
Consequences: an entry/navigation document and a knowledge unit are distinct
|
||||
concepts; a resolved link does not make its target executable; and a candidate
|
||||
never claims a normative nature that the public inputs did not state. Exact
|
||||
reading of the located span remains the CLI's public capability; this tool does
|
||||
not keep an authoritative copy of the body.
|
||||
|
||||
## 5. Analysis input
|
||||
|
||||
Marqdo program semantics come only from the core CLI:
|
||||
|
||||
@@ -200,6 +200,21 @@ pub fn build(
|
||||
},
|
||||
);
|
||||
|
||||
// Navigation anchors are a separate namespace from unit identity
|
||||
// (spec/document-structure.md §2, marqdo#55 §7): index them next to the
|
||||
// unit so query candidates can return a stable location without
|
||||
// re-parsing the source.
|
||||
let mut anchors_by_unit: BTreeMap<usize, Vec<String>> = BTreeMap::new();
|
||||
for anchor in &document.anchors {
|
||||
anchors_by_unit
|
||||
.entry(anchor.unit)
|
||||
.or_default()
|
||||
.push(anchor.anchor.clone());
|
||||
}
|
||||
let module_id = document
|
||||
.analysis
|
||||
.as_ref()
|
||||
.map(|analysis| analysis.module_id.clone());
|
||||
let mut unit_nodes: Vec<NodeKey> = Vec::with_capacity(document.units.len());
|
||||
for (index, unit) in document.units.iter().enumerate() {
|
||||
if index == 0 {
|
||||
@@ -212,12 +227,24 @@ pub fn build(
|
||||
.iter()
|
||||
.find(|function| function.unit == index);
|
||||
let span = Some(unit.span);
|
||||
let anchors = anchors_by_unit.get(&index).cloned().unwrap_or_default();
|
||||
let unit_kind = match unit.kind {
|
||||
crate::document::UnitKind::Root => "root",
|
||||
crate::document::UnitKind::Namespace => "namespace",
|
||||
crate::document::UnitKind::Function => "function",
|
||||
crate::document::UnitKind::Knowledge => "knowledge",
|
||||
crate::document::UnitKind::Section => "section",
|
||||
};
|
||||
let metadata = match function {
|
||||
Some(function) => serde_json::json!({
|
||||
"mode": unit.mode,
|
||||
"level": unit.level,
|
||||
"path": unit.path,
|
||||
"unit_id": unit.unit_id,
|
||||
"unit_kind": unit_kind,
|
||||
"anchors": anchors,
|
||||
"module_id": module_id,
|
||||
"nature": "unspecified",
|
||||
"function_id": function.function_id,
|
||||
"local_name": function.local_name,
|
||||
"namespace": function.namespace,
|
||||
@@ -236,6 +263,10 @@ pub fn build(
|
||||
"level": unit.level,
|
||||
"path": unit.path,
|
||||
"unit_id": unit.unit_id,
|
||||
"unit_kind": unit_kind,
|
||||
"anchors": anchors,
|
||||
"module_id": module_id,
|
||||
"nature": "unspecified",
|
||||
}),
|
||||
};
|
||||
let semantic_digest = function.map(|function| {
|
||||
|
||||
@@ -203,6 +203,8 @@ struct Hit {
|
||||
matches: Vec<search::MatchReason>,
|
||||
score: f64,
|
||||
callable: Option<serde_json::Value>,
|
||||
location: Option<serde_json::Value>,
|
||||
evidence: serde_json::Value,
|
||||
related: Vec<serde_json::Value>,
|
||||
}
|
||||
|
||||
@@ -633,6 +635,32 @@ impl<'a> Engine<'a> {
|
||||
}));
|
||||
}
|
||||
}
|
||||
// Stable candidate location: the document-structure identity a
|
||||
// consumer can address without re-parsing (unit id, anchors, path,
|
||||
// mode, exact source span). `nature` is `unspecified` because the
|
||||
// current public inputs (Markdown structure / OKF) do not declare
|
||||
// normative authority; Knowledge never guesses it (issue #14).
|
||||
let location = node.metadata.get("path").map(|path| {
|
||||
serde_json::json!({
|
||||
"module_id": node.metadata.get("module_id"),
|
||||
"unit_id": node.metadata.get("unit_id"),
|
||||
"unit_kind": node.metadata.get("unit_kind"),
|
||||
"anchors": node.metadata.get("anchors").cloned().unwrap_or_else(|| serde_json::json!([])),
|
||||
"path": path,
|
||||
"level": node.metadata.get("level"),
|
||||
"mode": node.metadata.get("mode"),
|
||||
"nature": node.metadata.get("nature"),
|
||||
"span": node.span.map(|span| serde_json::json!({
|
||||
"start": span.start,
|
||||
"end": span.end,
|
||||
})),
|
||||
})
|
||||
});
|
||||
let evidence = serde_json::json!({
|
||||
"status": if self.current { "current" } else { "stale" },
|
||||
"source_digest": source_digest,
|
||||
"snapshot_digest": self.snapshot_digest,
|
||||
});
|
||||
Ok(Hit {
|
||||
id: node.key.clone(),
|
||||
kind: node.kind,
|
||||
@@ -649,6 +677,8 @@ impl<'a> Engine<'a> {
|
||||
matches: final_hit.matches.clone(),
|
||||
score: (final_hit.score * 1_000_000.0).round() / 1_000_000.0,
|
||||
callable,
|
||||
location,
|
||||
evidence,
|
||||
related,
|
||||
})
|
||||
}
|
||||
@@ -694,6 +724,10 @@ impl<'a> Engine<'a> {
|
||||
if let Some(callable) = &hit.callable {
|
||||
object.insert("callable".into(), callable.clone());
|
||||
}
|
||||
if let Some(location) = &hit.location {
|
||||
object.insert("location".into(), location.clone());
|
||||
}
|
||||
object.insert("evidence".into(), hit.evidence.clone());
|
||||
value
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -91,6 +91,39 @@ fn lexical_channel_finds_two_character_chinese() {
|
||||
assert!(source.contains(hits[0]["snippet"].as_str().unwrap()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hits_return_a_stable_location_and_evidence_status() {
|
||||
// Candidate location contract (issue #14/#12): a hit must carry the exact
|
||||
// document-structure identity and source evidence, without re-parsing.
|
||||
let root = sample_project();
|
||||
let value = run(&root, query_args(&root, "牛顿"));
|
||||
let hit = value["hits"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|hit| hit["location"]["path"].is_array())
|
||||
.expect("a unit hit with a location");
|
||||
let location = &hit["location"];
|
||||
assert!(!location["path"].as_array().unwrap().is_empty());
|
||||
assert!(location["unit_kind"].is_string());
|
||||
assert!(location["mode"].is_string());
|
||||
assert_eq!(location["nature"], "unspecified");
|
||||
assert!(location["span"]["start"].as_u64().is_some());
|
||||
assert!(hit["source"]["path"].is_string());
|
||||
let evidence = &hit["evidence"];
|
||||
assert_eq!(evidence["status"], "current");
|
||||
assert!(evidence["source_digest"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.starts_with("sha256:"));
|
||||
assert!(evidence["snapshot_digest"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.starts_with("sha256:"));
|
||||
assert_eq!(value["schema"], "marqdo.knowledge.result");
|
||||
assert_eq!(value["schema_version"], 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fuzzy_channel_recalls_a_typo_query() {
|
||||
let root = sample_project();
|
||||
|
||||
Reference in new issue
Block a user