MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / render_json

Function render_json

atomic-cli/src/commands/vault/context.rs:931–974  ·  view source on GitHub ↗

Render a single-call envelope containing both injectable text and exact memory exposure metadata for run provenance.

(
    items: &[MemoryItem],
    md: &str,
    request: &Context,
    limit: usize,
)

Source from the content-addressed store, hash-verified

929/// Render a single-call envelope containing both injectable text and exact
930/// memory exposure metadata for run provenance.
931pub(crate) fn render_json(
932 items: &[MemoryItem],
933 md: &str,
934 request: &Context,
935 limit: usize,
936) -> String {
937 let values: Vec<serde_json::Value> = items
938 .iter()
939 .map(|item| {
940 serde_json::json!({
941 "memory_id": item.memory_id,
942 "kg_node_id": item.kg_node_id,
943 "revision_hash": item.revision_hash,
944 "content_hash": item.content_hash,
945 "path": item.path,
946 "name": item.name,
947 "kind": item.kind,
948 "status": item.status,
949 "score": (item.score * 1000.0).round() / 1000.0,
950 "why_matched": item.why_matched,
951 "body": item.body,
952 "preview": preview(&item.body),
953 "updated_at": item.updated_at,
954 "introduced_by": item.introduced_by,
955 "recorded": item.introduced_by != 0,
956 "truncated": item.truncated,
957 })
958 })
959 .collect();
960 let envelope = serde_json::json!({
961 "schema_version": JSON_SCHEMA_VERSION,
962 "context_markdown": md,
963 "retrieval": {
964 "query": &request.query,
965 "intent": &request.intent,
966 "files": &request.files,
967 "limit": limit,
968 "budget_chars": request.budget_chars,
969 "ranker_version": RANKER_VERSION,
970 },
971 "memories": values,
972 });
973 serde_json::to_string_pretty(&envelope).unwrap_or_else(|_| "{}".to_string())
974}
975
976fn prompt_metadata(value: &str) -> String {
977 value

Callers 2

test_render_json_shapeFunction · 0.85
test_render_json_emptyFunction · 0.85

Calls 2

collectMethod · 0.45
iterMethod · 0.45

Tested by 2

test_render_json_shapeFunction · 0.68
test_render_json_emptyFunction · 0.68