feat(knowledge): land Engineering Knowledge Compiler (EKC) from 008

Give agents Engineering First Information before codegen: L0–L4 catalog,
reuse/preflight (REUSE→ADAPT→CREATE), graph, and CLI surfaces so large
repos stop reinventing existing capabilities.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-28 16:44:39 +08:00
1 parent 2e425c3010
commit 56ab52356f
43 files changed
+8434 -19

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
---
type: Decision
id: ADR-022
title: Cache is not persistence
status: accepted
applies_to:
- config.resolve
---
# Cache is not persistence
## Decision
Redis is only used for ephemeral cache.
## Reason
The application must remain correct when Redis is unavailable.
## Consequence
Do not introduce Redis as the source of truth.
+12
View File
@@ -0,0 +1,12 @@
---
type: AntiPattern
id: AP-001
title: Do not parse JWT manually
status: stable
---
# Do not parse JWT manually
Never decode JWT directly in application code.
Use the shared auth capability instead.
+14
View File
@@ -0,0 +1,14 @@
---
type: Constraint
id: C-014
title: Centralized config resolution
status: stable
applies_to:
- config.resolve
---
# Database and config access
All configuration resolution must go through `resolve_config`.
Direct ad-hoc config parsing in handlers is prohibited.
+32
View File
@@ -0,0 +1,32 @@
---
title: Resolve configuration
capability: config.resolve
status: stable
---
Config resolution capability for Engineering Knowledge demos.
Use when: The caller needs the final normalized configuration.
Do not use when: Only raw configuration should be inspected.
# config
## resolve_config
+ `path`
`defaults` =
| host | port |
|------|------|
| localhost | 8080 |
* defaults
## merge_config
+ `base`
+ `overlay`
Merge overlay keys onto base configuration map.
* overlay
+23
View File
@@ -0,0 +1,23 @@
---
type: Failure
id: F-019
title: Do not cache authorization by user only
task: add_cache_layer
status: resolved
applies_to:
- config.resolve
---
# Do not cache authorization result
## Failed approach
Caching permission checks by user only.
## Failure
Permissions changed during role update.
## Correct approach
Cache by user_id, resource_id, and permission_version.
@@ -0,0 +1,31 @@
---
title: Normalize settings (near-duplicate)
status: stable
---
Near-duplicate of resolve_config for duplicate detection demos.
Use when: Caller wants normalized settings map.
# settings
## normalize_settings
+ `path`
Normalize settings from a path with host/port defaults.
`defaults` =
| host | port |
|------|------|
| localhost | 8080 |
* defaults
## merge_settings
+ `base`
+ `overlay`
Merge overlay onto base settings — semantically close to merge_config.
* overlay
+33
View File
@@ -0,0 +1,33 @@
---
title: eng preflight offline
import plugin:lib/plugin.mq.md
import agent:ext/ai/agent.mq.md
import json:lib/json.mq.md
---
Offline Engineering Knowledge gate against `tests/engineering/.marqdo`
(seed with `marqdo knowledge tests/engineering -o tests/engineering/.marqdo`).
# main
**p = > plugin.native_path name="agent"**
1. `p`
> plugin.load path=`p`
2. *
**out = "skip"**
*out*
**pf = > agent_eng_preflight task="resolve configuration" marqdo_dir="tests/engineering/.marqdo"**
**status = > json.get value=`pf` key="status"**
**dec = > json.get value=`pf` key="decision"**
**out = "eng-preflight-unexpected"**
1. `status` == "missing_knowledge"
**out = "eng-preflight-skip-no-graph"**
2. `dec` == "REUSE"
**out = "eng-preflight-ok"**
3. `dec` == "ADAPT"
**out = "eng-preflight-ok"**
4. *
**out = "eng-preflight-unexpected"**
*out*
+162
View File
@@ -1167,6 +1167,7 @@ fn catalog_writes_yaml() {
"tests",
"-o",
dir.to_str().unwrap(),
"--no-knowledge",
]);
assert_eq!(code, 0, "{stderr}");
let yaml = std::fs::read_to_string(dir.join("catalog.yaml")).unwrap();
@@ -1189,6 +1190,166 @@ fn catalog_writes_yaml() {
);
}
#[test]
fn knowledge_compile_engineering_fixture() {
let dir = tempfile_dir("mq-ekc");
let (code, _, stderr) = run(&[
"knowledge",
"tests/engineering",
"-o",
dir.to_str().unwrap(),
]);
assert_eq!(code, 0, "{stderr}");
assert!(dir.join("catalog/repository.mq.md").exists());
assert!(dir.join("graph/graph.json").exists());
assert!(dir.join("graph/edges.json").exists());
assert!(dir.join("engineering.yaml").exists());
assert!(dir.join("index.mq.md").exists());
let eng = std::fs::read_to_string(dir.join("engineering.yaml")).unwrap();
assert!(eng.contains("type: Marqdo Engineering Knowledge"), "{eng}");
assert!(eng.contains("capabilities:"), "{eng}");
assert!(
dir.join("knowledge/decisions").exists()
|| dir.join("knowledge/constraints").exists(),
"L4 knowledge dirs"
);
let caps: Vec<_> = std::fs::read_dir(dir.join("catalog/capabilities"))
.unwrap()
.flatten()
.collect();
assert!(!caps.is_empty(), "expected capability pages");
}
#[test]
fn knowledge_reuse_prefers_existing_capability() {
let dir = tempfile_dir("mq-reuse");
let (code, stdout, stderr) = run(&[
"reuse",
"resolve configuration",
"tests/engineering",
"-o",
dir.to_str().unwrap(),
"--json",
]);
assert_eq!(code, 0, "{stderr}");
assert!(
stdout.contains("\"decision\":\"REUSE\"") || stdout.contains("\"decision\": \"REUSE\""),
"expected REUSE: {stdout}"
);
assert!(stdout.contains("create_allowed"), "{stdout}");
assert!(
stdout.contains("false") || stdout.contains("\"create_allowed\":false"),
"create should not be required: {stdout}"
);
}
#[test]
fn knowledge_find_surfaces_negative_knowledge() {
let dir = tempfile_dir("mq-find");
let (code, stdout, stderr) = run(&[
"find",
"JWT",
"tests/engineering",
"-o",
dir.to_str().unwrap(),
"--json",
]);
assert_eq!(code, 0, "{stderr}");
assert!(
stdout.contains("AntiPattern") || stdout.contains("JWT") || stdout.contains("parse"),
"expected JWT anti-pattern hit: {stdout}"
);
}
#[test]
fn knowledge_duplicate_detects_merge_pair() {
let dir = tempfile_dir("mq-dup");
let (code, stdout, stderr) = run(&[
"duplicate",
"tests/engineering",
"-o",
dir.to_str().unwrap(),
"--threshold",
"0.75",
"--json",
]);
assert_eq!(code, 0, "{stderr}");
assert!(
stdout.contains("merge_config") && stdout.contains("merge_settings"),
"expected merge_* duplicate pair: {stdout}"
);
}
#[test]
fn knowledge_verify_and_conflicts_and_stale() {
let dir = tempfile_dir("mq-verify");
for cmd in ["verify", "conflicts", "stale"] {
let (code, stdout, stderr) = run(&[
cmd,
"tests/engineering",
"-o",
dir.to_str().unwrap(),
"--json",
]);
assert_eq!(code, 0, "{cmd}: {stderr}");
assert!(!stdout.is_empty(), "{cmd} empty stdout");
}
}
#[test]
fn knowledge_impact_lists_capabilities() {
let dir = tempfile_dir("mq-impact");
let (code, stdout, stderr) = run(&[
"impact",
"config_resolve.mq.md",
"--root",
"tests/engineering",
"-o",
dir.to_str().unwrap(),
"--json",
]);
assert_eq!(code, 0, "{stderr}");
assert!(
stdout.contains("config.resolve") || stdout.contains("capabilities"),
"{stdout}"
);
}
#[test]
fn knowledge_preflight_writes_context_pack() {
let dir = tempfile_dir("mq-pf");
let (code, stdout, stderr) = run(&[
"knowledge",
"tests/engineering",
"preflight",
"resolve configuration",
"-o",
dir.to_str().unwrap(),
"--json",
]);
assert_eq!(code, 0, "{stderr}\n{stdout}");
assert!(stdout.contains("create_allowed"), "{stdout}");
let ctx = dir.join("agent/contexts");
assert!(ctx.exists(), "contexts dir missing");
let packs: Vec<_> = std::fs::read_dir(&ctx).unwrap().flatten().collect();
assert!(!packs.is_empty(), "expected context pack");
}
#[test]
fn catalog_hooks_knowledge_by_default() {
let dir = tempfile_dir("mq-cat-ekc");
let (code, _, stderr) = run(&[
"catalog",
"tests/engineering",
"-o",
dir.to_str().unwrap(),
]);
assert_eq!(code, 0, "{stderr}");
assert!(dir.join("catalog.yaml").exists());
assert!(dir.join("engineering.yaml").exists());
assert!(dir.join("graph/graph.json").exists());
}
#[test]
fn ext_mq_md_never_calls_host() {
// Hard rule: ext/**/*.mq.md must not invoke host_* (use lib/* or plugin names).
@@ -1243,6 +1404,7 @@ fn catalog_includes_agent_kb_concepts() {
"tests/ext",
"-o",
dir.to_str().unwrap(),
"--no-knowledge",
]);
assert_eq!(code, 0, "{stderr}");
let yaml = std::fs::read_to_string(dir.join("catalog.yaml")).unwrap();