Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
feat(ui): who can help — authorship as evidence, never a scoreboard
Martin Vogelc6105c5d066e
diff --git a/src/ui/atlas.h b/src/ui/atlas.hindex ebdae86c1..a330a0357 100644--- a/src/ui/atlas.h+++ b/src/ui/atlas.h@@ -51,6 +51,12 @@ void cbm_atlas_metrics_cache_clear(void);* Returns {"available":false} JSON when the project has no git history. */char *cbm_atlas_file_history_json(cbm_store_t *store, const char *project, const char *file_path);+/* Who can help with one file: people with recorded history, each with+ * their evidence (commits here, repo-wide breadth, last-touched where the+ * retained newest commits prove it). Evidence framing only — never a+ * performance surface. */+char *cbm_atlas_who_json(cbm_store_t *store, const char *project, const char *file_path);+/* Per-symbol rationale evidence: `git log -L start,end:file` (bounded,* on-demand) with the forge base URL for commit/#ref links. */char *cbm_atlas_symbol_history_json(cbm_store_t *store, const char *project, const char *file_path,diff --git a/src/ui/atlas_metrics.c b/src/ui/atlas_metrics.cindex 09458ef76..9bf884aa2 100644--- a/src/ui/atlas_metrics.c+++ b/src/ui/atlas_metrics.c@@ -761,6 +761,133 @@ char *cbm_atlas_metrics_json(cbm_store_t *store, const char *project) {return json;}+/* ── Who can help: authorship as evidence, never as a scoreboard ──+ *+ * The most-sought information type in the developer-questions literature+ * is "who knows this code". This answers it for one file from the same+ * bounded churn scan the dashboard uses: people with recorded history+ * here, each with their evidence — commits in this file, share of the+ * file's year, breadth across the repo, and last-touched when it falls+ * inside the retained newest commits. Deliberate constraints: no+ * cross-person performance framing, no percentages without their+ * absolute pair, and absence of a last-seen date is stated honestly+ * (the scan retains only the newest commits per file). */++enum { WHO_PEOPLE_CAP = 8 };++typedef struct {+ const char *name; /* borrowed from the commit array */+ long long commits_here;+ long long files_repo_wide;+ long long last_seen; /* 0 = not in the retained newest commits */+} who_person_t;++typedef struct {+ who_person_t people[WHO_PEOPLE_CAP];+ int count;+} who_scan_t;++static void who_collect_iter(const char *name, void *value, void *userdata) {+ who_scan_t *scan = userdata;+ long long commits = (long long)(intptr_t)value;+ int pos = scan->count < WHO_PEOPLE_CAP ? scan->count : WHO_PEOPLE_CAP;+ while (pos > 0 && scan->people[pos - 1].commits_here < commits)+ pos--;+ if (pos >= WHO_PEOPLE_CAP)+ return;+ if (scan->count < WHO_PEOPLE_CAP)+ scan->count++;+ for (int i = scan->count - 1; i > pos; i--)+ scan->people[i] = scan->people[i - 1];+ scan->people[pos] = (who_person_t){.name = name, .commits_here = commits};+}++typedef struct {+ who_scan_t *scan;+} who_breadth_ctx_t;++static void who_breadth_iter(const char *file, void *value, void *userdata) {+ (void)file;+ who_breadth_ctx_t *ctx = userdata;+ const mx_file_stat_t *stat = value;+ if (!stat || !stat->authors)+ return;+ for (int i = 0; i < ctx->scan->count; i++)+ if (cbm_ht_get(stat->authors, ctx->scan->people[i].name))+ ctx->scan->people[i].files_repo_wide++;+}++char *cbm_atlas_who_json(cbm_store_t *store, const char *project, const char *file_path) {+ if (!store || !project || !file_path)+ return NULL;+ char stamp[128];+ char root_path[CBM_SZ_1K];+ mx_project_stamp(store, project, stamp, sizeof(stamp), root_path, sizeof(root_path));+ char key[1280];+ snprintf(key, sizeof(key), "%s|%s", project, stamp);++ pthread_mutex_lock(&g_hist_mu);+ bool fresh = g_hist_cache.valid && strcmp(g_hist_cache.key, key) == 0;+ pthread_mutex_unlock(&g_hist_mu);+ if (!fresh) {+ char *metrics = cbm_atlas_metrics_json(store, project);+ free(metrics);+ }++ yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);+ yyjson_mut_val *root = yyjson_mut_obj(doc);+ yyjson_mut_doc_set_root(doc, root);+ yyjson_mut_obj_add_str(doc, root, "window", "1y");++ pthread_mutex_lock(&g_hist_mu);+ fresh = g_hist_cache.valid && strcmp(g_hist_cache.key, key) == 0;+ const mx_file_stat_t *stat = fresh && g_hist_cache.churn.counts+ ? cbm_ht_get(g_hist_cache.churn.counts, file_path)+ : NULL;+ if (!fresh || !g_hist_cache.churn.counts || g_hist_cache.churn.commit_count == 0) {+ yyjson_mut_obj_add_bool(doc, root, "available", false);+ } else if (!stat || !stat->authors || stat->count <= 0) {+ yyjson_mut_obj_add_bool(doc, root, "available", true);+ yyjson_mut_obj_add_int(doc, root, "commits_1y", stat ? stat->count : 0);+ yyjson_mut_obj_add_val(doc, root, "people", yyjson_mut_arr(doc));+ yyjson_mut_obj_add_int(doc, root, "people_total", 0);+ } else {+ who_scan_t scan = {0};+ cbm_ht_foreach(stat->authors, who_collect_iter, &scan);+ mx_owner_scan_t totals = {0};+ cbm_ht_foreach(stat->authors, mx_owner_iter, &totals);+ who_breadth_ctx_t breadth = {.scan = &scan};+ cbm_ht_foreach(g_hist_cache.churn.counts, who_breadth_iter, &breadth);+ /* Last-touched, where the retained newest commits can prove it. */+ for (int r = 0; r < stat->recent_count; r++) {+ const mx_commit_t *commit = &g_hist_cache.churn.commits[stat->recent[r]];+ for (int i = 0; i < scan.count; i++)+ if (scan.people[i].last_seen == 0 &&+ strcmp(scan.people[i].name, commit->author) == 0)+ scan.people[i].last_seen = commit->time;+ }+ yyjson_mut_obj_add_bool(doc, root, "available", true);+ yyjson_mut_obj_add_int(doc, root, "commits_1y", stat->count);+ yyjson_mut_val *people = yyjson_mut_arr(doc);+ for (int i = 0; i < scan.count; i++) {+ yyjson_mut_val *person = yyjson_mut_obj(doc);+ yyjson_mut_obj_add_strcpy(doc, person, "name", scan.people[i].name);+ yyjson_mut_obj_add_int(doc, person, "commits_here", scan.people[i].commits_here);+ yyjson_mut_obj_add_int(doc, person, "files_repo_wide", scan.people[i].files_repo_wide);+ if (scan.people[i].last_seen > 0)+ yyjson_mut_obj_add_int(doc, person, "last_seen", scan.people[i].last_seen);+ yyjson_mut_arr_append(people, person);+ }+ yyjson_mut_obj_add_val(doc, root, "people", people);+ yyjson_mut_obj_add_int(doc, root, "people_total", totals.distinct);+ }+ pthread_mutex_unlock(&g_hist_mu);++ char *json = yyjson_mut_write(doc, 0, NULL);+ yyjson_mut_doc_free(doc);+ return json;+}+/* ── Rationale evidence: forge base URL + per-symbol history ────── *//* Normalize the origin remote to a browsable https base ("" if none):diff --git a/src/ui/http_server.c b/src/ui/http_server.cindex 3e310b793..2a8a7f5a2 100644--- a/src/ui/http_server.c+++ b/src/ui/http_server.c@@ -2025,6 +2025,25 @@ char *cbm_atlas_attach_observed(cbm_store_t *store, const char *project, char *jreturn out;}+/* GET /api/who?project=X&file=PATH — who can help with this file:+ * authorship as evidence from the cached churn scan. */+static void handle_atlas_who(cbm_http_conn_t *c, const cbm_http_req_t *req) {+ char project[256] = {0};+ cbm_store_t *store = atlas_open_project(c, req, project, sizeof(project));+ if (!store)+ return;+ char file[1024] = {0};+ cbm_http_query_param(req->query, "file", file, (int)sizeof(file));+ if (!file[0]) {+ cbm_store_close(store);+ cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"missing file parameter\"}");+ return;+ }+ char *json = cbm_atlas_who_json(store, project, file);+ cbm_store_close(store);+ atlas_reply_json(c, json, 500, "{\"error\":\"who failed\"}");+}+/* GET /api/symbol-history?project=X&file=PATH&start=N&end=N — per-symbol* git history (log -L over the symbol's line range), on demand. */static void handle_atlas_symbol_history(cbm_http_conn_t *c, const cbm_http_req_t *req) {@@ -2553,6 +2572,12 @@ static void dispatch_request(cbm_http_server_t *srv, cbm_http_conn_t *c,return;}+ /* GET /api/who → who can help with one file (authorship evidence) */+ if (is_get && cbm_http_path_match(req->path, "/api/who*")) {+ handle_atlas_who(c, req);+ return;+ }+/* GET /api/symbol → CBM Atlas symbol bundle */if (is_get && cbm_http_path_match(req->path, "/api/symbol*")) {handle_atlas_symbol(c, req);diff --git a/tests/test_ui.c b/tests/test_ui.cindex 558a5c254..5a8d794db 100644--- a/tests/test_ui.c+++ b/tests/test_ui.c@@ -1930,6 +1930,109 @@ TEST(atlas_attach_observed_marks_hops) {PASS();}+/* Who can help: authorship as evidence from the churn scan — commits in+ * this file, repo-wide breadth, last-touched where the retained newest+ * commits prove it. Real throwaway git repo; environments without git+ * pass through, like the feature itself. */+TEST(atlas_who_reports_authorship_evidence) {+#ifdef _WIN32+ if (system("git --version >NUL 2>&1") != 0)+#else+ if (system("git --version >/dev/null 2>&1") != 0)+#endif+ PASS();++ char tmpl[256] = "/tmp/cbm_who_XXXXXX";+ char *root = cbm_mkdtemp(tmpl);+ ASSERT_NOT_NULL(root);+ char dir[1024];+ snprintf(dir, sizeof(dir), "%s/src", root);+ cbm_mkdir_p(dir, 0755);+ static const char *const files[2] = {"src/a.c", "src/b.c"};+ for (int i = 0; i < 2; i++) {+ char path[1024];+ snprintf(path, sizeof(path), "%s/%s", root, files[i]);+ FILE *fp = cbm_fopen(path, "wb");+ ASSERT_NOT_NULL(fp);+ fputs("int x;\n", fp);+ fclose(fp);+ }+ char cmd[2048];+ snprintf(cmd, sizeof(cmd),+ "git -C \"%s\" init -q && git -C \"%s\" add . && "+ "git -C \"%s\" -c user.name=Alice -c [email protected] commit -qm seed",+ root, root, root);+ if (system(cmd) != 0) {+ (void)th_rmtree(root);+ PASS();+ }+ /* Bob touches a.c, then Alice touches a.c again — a.c ends with three+ * commits (Alice 2, Bob 1), b.c with one (Alice). */+ char touch[1024];+ snprintf(touch, sizeof(touch), "%s/src/a.c", root);+ FILE *fp = cbm_fopen(touch, "ab");+ ASSERT_NOT_NULL(fp);+ fputs("int y;\n", fp);+ fclose(fp);+ snprintf(cmd, sizeof(cmd),+ "git -C \"%s\" add . && "+ "git -C \"%s\" -c user.name=Bob -c [email protected] commit -qm bob",+ root, root);+ ASSERT_EQ(system(cmd), 0);+ fp = cbm_fopen(touch, "ab");+ ASSERT_NOT_NULL(fp);+ fputs("int z;\n", fp);+ fclose(fp);+ snprintf(cmd, sizeof(cmd),+ "git -C \"%s\" add . && "+ "git -C \"%s\" -c user.name=Alice -c [email protected] commit -qm alice2",+ root, root);+ ASSERT_EQ(system(cmd), 0);++ cbm_atlas_metrics_cache_clear();+ cbm_store_t *store = cbm_store_open_memory();+ ASSERT_NOT_NULL(store);+ cbm_store_upsert_project(store, "who-test", root);++ char *json = cbm_atlas_who_json(store, "who-test", "src/a.c");+ ASSERT_NOT_NULL(json);+ yyjson_doc *doc = yyjson_read(json, strlen(json), 0);+ ASSERT_NOT_NULL(doc);+ yyjson_val *jroot = yyjson_doc_get_root(doc);+ ASSERT_TRUE(yyjson_get_bool(yyjson_obj_get(jroot, "available")));+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(jroot, "commits_1y")), 3);+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(jroot, "people_total")), 2);+ yyjson_val *people = yyjson_obj_get(jroot, "people");+ ASSERT_EQ((int)yyjson_arr_size(people), 2);+ yyjson_val *first = yyjson_arr_get(people, 0);+ ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(first, "name")), "Alice");+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(first, "commits_here")), 2);+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(first, "files_repo_wide")), 2);+ ASSERT_GT(yyjson_get_int(yyjson_obj_get(first, "last_seen")), 0);+ yyjson_val *second = yyjson_arr_get(people, 1);+ ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(second, "name")), "Bob");+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(second, "commits_here")), 1);+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(second, "files_repo_wide")), 1);+ yyjson_doc_free(doc);+ free(json);++ /* A file with no recorded commits answers honestly, not with an error. */+ json = cbm_atlas_who_json(store, "who-test", "src/never.c");+ ASSERT_NOT_NULL(json);+ doc = yyjson_read(json, strlen(json), 0);+ jroot = yyjson_doc_get_root(doc);+ ASSERT_TRUE(yyjson_get_bool(yyjson_obj_get(jroot, "available")));+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(jroot, "commits_1y")), 0);+ ASSERT_EQ((int)yyjson_arr_size(yyjson_obj_get(jroot, "people")), 0);+ yyjson_doc_free(doc);+ free(json);++ cbm_store_close(store);+ cbm_atlas_metrics_cache_clear();+ (void)th_rmtree(root);+ PASS();+}+/* Per-symbol history: `git log -L` over the symbol's line range, with the* forge base URL normalized for the UI's commit/#ref links. Runs against a* real throwaway git repo; environments without git pass through (the@@ -2168,6 +2271,7 @@ SUITE(ui) {RUN_TEST(atlas_blast_buckets_files_by_region);RUN_TEST(atlas_handout_is_selfcontained_and_escaped);RUN_TEST(atlas_attach_observed_marks_hops);+ RUN_TEST(atlas_who_reports_authorship_evidence);RUN_TEST(atlas_symbol_history_log_l_and_remote);RUN_TEST(atlas_why_extracts_guard_chains);}