release: bump to 2.1.2 (EK production chain + View V0–V3 bar)
Ship evidence/closure invalidation, verify/adjudicate, reuse_execute and agent bind/publish gates, document.extract, KnowledgePresentation + SSE page_token, and upload max_bytes with the 45-test offline gate. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0b80ff8e50
commit
dc853fb580
38 files changed
+3045
-298
No files matched your search
@@ -501,6 +501,175 @@ pub fn eng_reuse(args: &Value) -> Result<Value, String> {
|
||||
Ok(pf)
|
||||
}
|
||||
|
||||
/// M04: discover → inspect → bind → execute → record (actual reuse, not n-gram REUSE).
|
||||
///
|
||||
/// Requires host_query `mlsp`. Returns trace with artifact_id, digests, inputs, result.
|
||||
/// Does **not** promote skills — callers pass `candidate_only=true` to skip learn/promote.
|
||||
pub fn eng_bind_execute(args: &Value) -> Result<Value, String> {
|
||||
let project = args
|
||||
.get("project")
|
||||
.or_else(|| args.get("root"))
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or(".");
|
||||
let policy = args
|
||||
.get("policy")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("pure");
|
||||
let inputs = args.get("inputs").cloned().unwrap_or(json!({}));
|
||||
let query = if let Some(q) = args.get("artifact_id").or_else(|| args.get("query")).and_then(|v| v.as_str()) {
|
||||
q.to_string()
|
||||
} else {
|
||||
// Fall back to first bind_target from eng_reuse.
|
||||
let reuse = eng_reuse(args)?;
|
||||
let targets = reuse
|
||||
.get("bind_targets")
|
||||
.and_then(|v| v.as_array())
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
targets
|
||||
.first()
|
||||
.and_then(|t| t.get("query").and_then(|q| q.as_str()))
|
||||
.ok_or_else(|| {
|
||||
"eng_bind_execute: no artifact_id/query and eng_reuse returned no bind_targets"
|
||||
.to_string()
|
||||
})?
|
||||
.to_string()
|
||||
};
|
||||
|
||||
let inspect = crate::host_query_json_args(
|
||||
"mlsp",
|
||||
&json!({"method":"artifact.inspect","params":{"project":project,"artifact_id":&query}}),
|
||||
)?;
|
||||
if inspect.get("ok") != Some(&json!(true)) {
|
||||
return Ok(json!({
|
||||
"ok": false,
|
||||
"stage": "inspect",
|
||||
"error": inspect.get("error").cloned().unwrap_or(json!("inspect failed")),
|
||||
"query": query,
|
||||
}));
|
||||
}
|
||||
let artifact_id = inspect["result"]["artifact_id"]
|
||||
.as_str()
|
||||
.unwrap_or(&query)
|
||||
.to_string();
|
||||
|
||||
let bound = crate::host_query_json_args(
|
||||
"mlsp",
|
||||
&json!({"method":"artifact.bind","params":{"project":project,"artifact_id":&artifact_id,"policy":policy}}),
|
||||
)?;
|
||||
if bound.get("ok") != Some(&json!(true)) {
|
||||
return Ok(json!({
|
||||
"ok": false,
|
||||
"stage": "bind",
|
||||
"error": bound.get("error").cloned().unwrap_or(json!("bind failed")),
|
||||
"artifact_id": artifact_id,
|
||||
"discovery_only": false,
|
||||
}));
|
||||
}
|
||||
let handle = bound["result"]["handle"].clone();
|
||||
|
||||
let executed = crate::host_query_json_args(
|
||||
"mlsp",
|
||||
&json!({"method":"artifact.execute","params":{"handle":&handle,"inputs":inputs}}),
|
||||
)?;
|
||||
if executed.get("ok") != Some(&json!(true)) {
|
||||
return Ok(json!({
|
||||
"ok": false,
|
||||
"stage": "execute",
|
||||
"error": executed.get("error").cloned().unwrap_or(json!("execute failed")),
|
||||
"artifact_id": artifact_id,
|
||||
"handle": handle,
|
||||
}));
|
||||
}
|
||||
|
||||
// Record only after successful bind+execute (actual reuse).
|
||||
let _ = eng_record(&json!({
|
||||
"decision": "REUSE",
|
||||
"root": project,
|
||||
"marqdo_dir": args.get("marqdo_dir"),
|
||||
}));
|
||||
|
||||
Ok(json!({
|
||||
"ok": true,
|
||||
"stage": "executed",
|
||||
"discovery_only": false,
|
||||
"bind_required": false,
|
||||
"actual_reuse": true,
|
||||
"artifact_id": artifact_id,
|
||||
"symbol_id": handle.get("symbol_id"),
|
||||
"digest": handle.get("digest"),
|
||||
"evidence_digest": handle.get("evidence_digest"),
|
||||
"closure_digest": handle.get("closure_digest"),
|
||||
"policy": policy,
|
||||
"inputs": inputs,
|
||||
"result": executed.get("result"),
|
||||
"candidate_only": args.get("candidate_only").and_then(|v| v.as_bool()).unwrap_or(false),
|
||||
"trace": {
|
||||
"artifact_id": artifact_id,
|
||||
"symbol_id": handle.get("symbol_id"),
|
||||
"digest": handle.get("digest"),
|
||||
"inputs": inputs,
|
||||
"stdout": executed["result"]["stdout"],
|
||||
"value": executed["result"]["result"],
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
/// Gate promote/learn: when `candidate_only` or may_bind=false, refuse promotion.
|
||||
pub fn eng_publish_gate(args: &Value) -> Result<Value, String> {
|
||||
let candidate_only = matches!(args.get("candidate_only"), Some(Value::Bool(true)));
|
||||
let product_ok = !matches!(args.get("product_gate_ok"), Some(Value::Bool(false)));
|
||||
let project = args
|
||||
.get("project")
|
||||
.or_else(|| args.get("root"))
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or(".");
|
||||
let policy = args
|
||||
.get("policy")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("business");
|
||||
let artifact = args
|
||||
.get("artifact_id")
|
||||
.or_else(|| args.get("query"))
|
||||
.and_then(|v| v.as_str());
|
||||
|
||||
if candidate_only {
|
||||
return Ok(json!({
|
||||
"ok": true,
|
||||
"may_promote": false,
|
||||
"reason": "candidate_only — framework must not promote",
|
||||
}));
|
||||
}
|
||||
if !product_ok {
|
||||
return Ok(json!({
|
||||
"ok": true,
|
||||
"may_promote": false,
|
||||
"reason": "product gate failed — framework must not promote",
|
||||
}));
|
||||
}
|
||||
if let Some(id) = artifact {
|
||||
let adj = crate::host_query_json_args(
|
||||
"mlsp",
|
||||
&json!({"method":"artifact.verify","params":{"project":project,"artifact_id":id,"policy":policy}}),
|
||||
)?;
|
||||
let may_bind = adj
|
||||
.pointer("/result/may_bind")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
return Ok(json!({
|
||||
"ok": true,
|
||||
"may_promote": may_bind,
|
||||
"verification": adj.get("result"),
|
||||
"reason": if may_bind { "verification allows bind" } else { "verification denied bind" },
|
||||
}));
|
||||
}
|
||||
Ok(json!({
|
||||
"ok": true,
|
||||
"may_promote": product_ok,
|
||||
"reason": "no artifact_id; deferred to product_gate_ok",
|
||||
}))
|
||||
}
|
||||
|
||||
/// `agent_eng_record` — append reuse metrics under `.marqdo/agent/episodes`.
|
||||
pub fn eng_record(args: &Value) -> Result<Value, String> {
|
||||
let decision = arg_text(args, "decision")?;
|
||||
|
||||
@@ -831,6 +831,8 @@ kb_ffi!(agent_resume_clear, resume::resume_clear, "agent_resume_clear");
|
||||
kb_ffi!(agent_resume_list, resume::resume_list, "agent_resume_list");
|
||||
kb_ffi!(agent_eng_preflight, eng::eng_preflight, "agent_eng_preflight");
|
||||
kb_ffi!(agent_eng_reuse, eng::eng_reuse, "agent_eng_reuse");
|
||||
kb_ffi!(agent_eng_bind_execute, eng::eng_bind_execute, "agent_eng_bind_execute");
|
||||
kb_ffi!(agent_eng_publish_gate, eng::eng_publish_gate, "agent_eng_publish_gate");
|
||||
kb_ffi!(agent_eng_record, eng::eng_record, "agent_eng_record");
|
||||
|
||||
#[no_mangle]
|
||||
@@ -900,6 +902,8 @@ pub unsafe extern "C" fn marqdo_plugin_init(host: *const MarqdoHostApi) -> c_int
|
||||
("agent_maybe_compile_policy", "memory_dir,min_evidence", agent_maybe_compile_policy),
|
||||
("agent_eng_preflight", "task", agent_eng_preflight),
|
||||
("agent_eng_reuse", "task", agent_eng_reuse),
|
||||
("agent_eng_bind_execute", "project,query,policy", agent_eng_bind_execute),
|
||||
("agent_eng_publish_gate", "project,artifact_id,candidate_only", agent_eng_publish_gate),
|
||||
("agent_eng_record", "decision", agent_eng_record),
|
||||
("sandbox_open", "", sandbox::sandbox_open),
|
||||
("sandbox_write", "", sandbox::sandbox_write),
|
||||
|
||||
@@ -81,7 +81,16 @@ func (st *state) handleUpload(w http.ResponseWriter, r *http.Request, routePath
|
||||
_, hadCookie := session.IDFromCookie(r.Header.Get("Cookie"))
|
||||
sid, _, setCookie := resolveSession(r)
|
||||
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||
// M01: hard-limit request body before multipart parse (32MiB was only in-memory
|
||||
// form budget, not a request total). Cap at configured MaxBytes + 1MiB overhead.
|
||||
maxBody := int64(cfg.MaxBytes)
|
||||
if maxBody <= 0 {
|
||||
maxBody = 32 << 20
|
||||
}
|
||||
overhead := int64(1 << 20)
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxBody+overhead)
|
||||
|
||||
if err := r.ParseMultipartForm(maxBody + overhead); err != nil {
|
||||
jsonErr(w, http.StatusBadRequest, fmt.Sprintf("multipart: %v", err))
|
||||
return
|
||||
}
|
||||
@@ -109,11 +118,20 @@ func (st *state) handleUpload(w http.ResponseWriter, r *http.Request, routePath
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
b, err := io.ReadAll(f)
|
||||
// Stream-capped read: never buffer more than MaxBytes.
|
||||
lim := maxBody
|
||||
if lim <= 0 {
|
||||
lim = 32 << 20
|
||||
}
|
||||
b, err := io.ReadAll(io.LimitReader(f, lim+1))
|
||||
if err != nil {
|
||||
jsonErr(w, http.StatusBadRequest, fmt.Sprintf("read file: %v", err))
|
||||
return
|
||||
}
|
||||
if int64(len(b)) > lim {
|
||||
jsonErr(w, http.StatusRequestEntityTooLarge, "file exceeds max_bytes")
|
||||
return
|
||||
}
|
||||
fileBytes = b
|
||||
} else {
|
||||
// Fallback: walk File map keys.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package httpx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHandleUploadRejectsOversizedBeforeFullBuffer(t *testing.T) {
|
||||
st := &state{
|
||||
uploadRoutes: map[string]any{
|
||||
"/upload": map[string]any{
|
||||
"field": "file",
|
||||
"storage_url": "memory://t",
|
||||
"prefix": "u",
|
||||
"max_bytes": float64(64),
|
||||
},
|
||||
},
|
||||
}
|
||||
cfg := parseUploadRoute(st.uploadRoutes["/upload"])
|
||||
var body bytes.Buffer
|
||||
w := multipart.NewWriter(&body)
|
||||
part, err := w.CreateFormFile("file", "big.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := part.Write([]byte(strings.Repeat("x", 200))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = w.Close()
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/upload", &body)
|
||||
req.Header.Set("Content-Type", w.FormDataContentType())
|
||||
rr := httptest.NewRecorder()
|
||||
st.handleUpload(rr, req, "/upload", cfg)
|
||||
if rr.Code == http.StatusOK {
|
||||
t.Fatalf("expected reject for oversized upload, got %d body=%s", rr.Code, rr.Body.String())
|
||||
}
|
||||
if rr.Code != http.StatusRequestEntityTooLarge && rr.Code != http.StatusBadRequest {
|
||||
t.Fatalf("expected 413 or 400, got %d body=%s", rr.Code, rr.Body.String())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user