khive-request
Transport-agnostic parser for khive's verb-dispatch request DSL. Parses function-call
syntax, JSON, and (in the future) LNDL / pipe / bash-style syntaxes into a single
ParsedRequest AST that any transport (MCP, HTTP, CLI) can execute.
Usage
use ;
// Single op
let req = parse_request?;
assert_eq!;
// Parallel batch
let req = parse_request?;
assert_eq!;
// Chain — `$prev` resolves against the immediately preceding op's result
let req = parse_request?;
assert_eq!;
for op in &req.ops
JSON form ([{"tool": "...", "args": {...}}, ...]) is also accepted and always parses
to ExecutionMode::Parallel — it has no chain syntax, so a literal $prev in JSON
form is a parse error (DslError::PrevRefInJsonForm).
Result types
ParsedRequest { ops: Vec<ParsedOp>, mode: ExecutionMode }ParsedOp { tool: String, args: BTreeMap<String, ArgValue> }ArgValue—Value(serde_json::Value)for concrete JSON,PrevRef { path }for a$prev/$prev.field.pathback-reference, orArray/Objectcontainers that hold furtherArgValues (a pure-JSON array or object with no embedded$prevfolds straight toValue).ArgValue::resolve_prev/resolve_allresolve references against a preceding op's result.DslError— a typed enum (TooManyOps,UnexpectedChar,InvalidIdentifier,PrevRefOutsideChain,WriteKeyConflict,ReservedEnvelopeArg, …), surfaced asinvalid_paramsat the MCP boundary.
Semantics
MAX_OPS(100) caps operations per request; exceeding it isDslError::TooManyOps.$previs chain-only. A$prevreference outside|chain mode, or anywhere in JSON form, is rejected at parse time rather than deferred to a runtime lookup miss.- Write-key conflict detection (
write_keys_for_op_pub) is a preflight check over a parallel batch: two ops that target the same UUID viaupdate/delete(id),merge(into_id/from_id), orlink(source_id/target_id) reject the whole batch before any op dispatches, rather than racing. RESERVED_ENVELOPE_ARGS(presentation,presentation_per_op) are envelope-level fields; passing them inside a verb's own argument list is rejected (DslError::ReservedEnvelopeArg).- Mixing
,and|at the top level is rejected (DslError::MixedSeparators), as is a dotted verb name with more than one level, e.g.a.b.c(UnsupportedVerbNesting) — only single-levelpack.verbnames are supported.
Where this sits
khive-request depends only on serde/serde_json and has no dependency on
khive-runtime or any pack — it is pure syntax, consumed only at the transport
dispatch boundary:
types -> score -> storage -> db -> query -> runtime -> pack-* -> mcp
^
khive-request parses
the `request` tool's
input string here
khive-mcp's request tool calls parse_request, then routes each ParsedOp
through the runtime's VerbRegistry::dispatch. The DSL shape and grammar are
specified in
ADR-016.
License
Apache-2.0.