MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / atlas_flow_attach_guards

Function atlas_flow_attach_guards

src/ui/http_server.c:2769–2840  ·  view source on GitHub ↗

Attach guard chains to a flow-detail JSON (guards=1): each step's call * site is (steps[step.parent] → step); the guard chain is extracted in the * parent's file. Best-effort, same contract as the trace variant. */

Source from the content-addressed store, hash-verified

2767 * site is (steps[step.parent] → step); the guard chain is extracted in the
2768 * parent's file. Best-effort, same contract as the trace variant. */
2769static char *atlas_flow_attach_guards(cbm_store_t *store, const char *project, char *json) {
2770 yyjson_doc *doc = yyjson_read(json, strlen(json), 0);
2771 if (!doc)
2772 return json;
2773 yyjson_val *steps = yyjson_obj_get(yyjson_doc_get_root(doc), "steps");
2774 size_t count = steps ? yyjson_arr_size(steps) : 0;
2775 if (count < 2) {
2776 yyjson_doc_free(doc);
2777 return json;
2778 }
2779 yyjson_mut_doc *mut = yyjson_doc_mut_copy(doc, cbm_json_writer_allocator());
2780 yyjson_doc_free(doc);
2781 if (!mut)
2782 return json;
2783 yyjson_mut_val *msteps = yyjson_mut_obj_get(yyjson_mut_doc_get_root(mut), "steps");
2784 struct sqlite3 *db = cbm_store_get_db(store);
2785 for (size_t i = 1; i < count && db; i++) {
2786 yyjson_mut_val *step = yyjson_mut_arr_get(msteps, i);
2787 int64_t parent_index = yyjson_mut_get_int(yyjson_mut_obj_get(step, "parent"));
2788 if (parent_index < 0 || (size_t)parent_index >= count)
2789 continue;
2790 yyjson_mut_val *parent = yyjson_mut_arr_get(msteps, (size_t)parent_index);
2791 int64_t from_id = yyjson_mut_get_int(yyjson_mut_obj_get(parent, "id"));
2792 int64_t to_id = yyjson_mut_get_int(yyjson_mut_obj_get(step, "id"));
2793 const char *from_file = yyjson_mut_get_str(yyjson_mut_obj_get(parent, "file_path"));
2794 if (!from_file)
2795 continue;
2796 sqlite3_stmt *st = NULL;
2797 int line = -1;
2798 if (sqlite3_prepare_v2(db,
2799 "SELECT properties FROM edges WHERE project=?1 AND "
2800 "source_id=?2 AND target_id=?3 AND type='CALLS' LIMIT 1",
2801 -1, &st, NULL) == SQLITE_OK) {
2802 sqlite3_bind_text(st, 1, project, -1, SQLITE_STATIC);
2803 sqlite3_bind_int64(st, 2, from_id);
2804 sqlite3_bind_int64(st, 3, to_id);
2805 if (sqlite3_step(st) == SQLITE_ROW) {
2806 const char *props = (const char *)sqlite3_column_text(st, 0);
2807 if (props) {
2808 yyjson_doc *pd = yyjson_read(props, strlen(props), 0);
2809 if (pd) {
2810 line = (int)yyjson_get_int(yyjson_obj_get(yyjson_doc_get_root(pd), "line"));
2811 yyjson_doc_free(pd);
2812 }
2813 }
2814 }
2815 sqlite3_finalize(st);
2816 }
2817 if (line <= 0)
2818 continue;
2819 char *gj = cbm_atlas_callsite_guards_json(store, project, from_file, line);
2820 if (!gj)
2821 continue;
2822 yyjson_doc *gd = yyjson_read(gj, strlen(gj), 0);
2823 cbm_free(CBM_MEM_CLASS_OTHER, gj);
2824 if (!gd)
2825 continue;
2826 yyjson_val *garr = yyjson_obj_get(yyjson_doc_get_root(gd), "guards");

Callers 1

handle_atlas_flowFunction · 0.85

Calls 4

cbm_store_get_dbFunction · 0.85
cbm_freeFunction · 0.85

Tested by

no test coverage detected