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

Function application_index_status

src/daemon/application.c:2873–2928  ·  view source on GitHub ↗

index_repository(status: true) (#2144). A live job reports queued, running * or cancelling; otherwise the last recorded outcome. A project with neither a * job record nor a database is an error; one indexed before this daemon * generation reports idle and points at index_status for graph freshness. */

Source from the content-addressed store, hash-verified

2871 * job record nor a database is an error; one indexed before this daemon
2872 * generation reports idle and points at index_status for graph freshness. */
2873static char *application_index_status(void *context, const char *project) {
2874 cbm_daemon_application_session_t *session = context;
2875 if (!session || !project) {
2876 return NULL;
2877 }
2878 cbm_daemon_application_t *application = session->application;
2879 bool db_exists = application_regular_db_exists(project);
2880 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
2881 yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL;
2882 if (!root) {
2883 yyjson_mut_doc_free(doc);
2884 return NULL;
2885 }
2886 yyjson_mut_doc_set_root(doc, root);
2887 yyjson_mut_obj_add_strcpy(doc, root, "project", project);
2888 cbm_mutex_lock(&application->mutex);
2889 cbm_daemon_application_job_t *job = application_find_active_job_locked(application, project);
2890 cbm_daemon_application_index_record_t *record =
2891 application_index_record_find_locked(application, project);
2892 bool known = job || record || db_exists;
2893 if (job) {
2894 yyjson_mut_obj_add_str(doc, root, "state",
2895 job->cancel_requested ? "cancelling"
2896 : job->worker_started ? "running"
2897 : "queued");
2898 } else if (record) {
2899 yyjson_mut_obj_add_str(doc, root, "state", record->state);
2900 } else {
2901 yyjson_mut_obj_add_str(doc, root, "state", "idle");
2902 yyjson_mut_obj_add_str(doc, root, "detail",
2903 "no index job has run for this project in this daemon generation; "
2904 "index_status describes the published graph");
2905 }
2906 if (record) {
2907 application_status_add_record(doc, root, record);
2908 }
2909 if (job && !job->cancel_requested) {
2910 yyjson_mut_obj_add_str(doc, root, "poll",
2911 "call again with status: true until state is succeeded, failed or "
2912 "cancelled");
2913 }
2914 cbm_mutex_unlock(&application->mutex);
2915 char *json = known ? yyjson_mut_write(doc, 0, NULL) : NULL;
2916 yyjson_mut_doc_free(doc);
2917 if (!known) {
2918 char message[APPLICATION_PATH_CAP];
2919 (void)snprintf(message, sizeof(message),
2920 "no index job or index is known for project '%s'; start one with "
2921 "index_repository(repo_path=..., async: true)",
2922 project);
2923 return cbm_mcp_text_result(message, true);
2924 }
2925 char *result = cbm_mcp_text_result(json ? json : "{}", false);
2926 safe_free(json);
2927 return result;
2928}
2929
2930static cbm_daemon_runtime_application_session_t *application_session_open(

Callers

nothing calls this directly

Calls 7

cbm_mutex_lockFunction · 0.85
cbm_mutex_unlockFunction · 0.85
cbm_mcp_text_resultFunction · 0.85

Tested by

no test coverage detected