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

Function cbm_openclaw_workspace_path

src/cli/cli.c:2893–2951  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2891}
2892
2893static bool cbm_openclaw_workspace_path(const char *home_dir, const char *config_path, char *out,
2894 size_t out_sz) {
2895 char internal_home[CLI_BUF_1K];
2896 if (!cbm_openclaw_internal_home(home_dir, internal_home, sizeof(internal_home))) {
2897 return false;
2898 }
2899 static const char *const defaults_path[] = {"agents", "defaults"};
2900 char *configured = NULL;
2901 int lookup =
2902 cbm_json_like_get_string_at_path(config_path, defaults_path, 2U, "workspace", &configured);
2903 if (lookup == 0) {
2904 bool ok = cbm_expand_user_path(internal_home, configured, out, out_sz);
2905 free(configured);
2906 return ok;
2907 }
2908 free(configured);
2909 if (lookup < 0) {
2910 return false;
2911 }
2912
2913 /* OpenClaw supports $include in its JSON5 config. Resolving and merging an
2914 * arbitrary include graph is outside the installer's safe mutation scope;
2915 * never guess the default workspace when an include may define it. */
2916 static const char *const root_path[] = {NULL};
2917 char *include_value = NULL;
2918 int include_lookup =
2919 cbm_json_like_get_string_at_path(config_path, root_path, 0U, "$include", &include_value);
2920 free(include_value);
2921 if (include_lookup != 1) {
2922 return false;
2923 }
2924
2925 char env_buf[CLI_BUF_1K];
2926 const char *workspace =
2927 cbm_safe_getenv("OPENCLAW_WORKSPACE_DIR", env_buf, sizeof(env_buf), NULL);
2928 if (workspace && workspace[0]) {
2929 return cbm_expand_user_path(internal_home, workspace, out, out_sz);
2930 }
2931
2932 char profile_buf[CLI_BUF_256];
2933 const char *profile =
2934 cbm_safe_getenv("OPENCLAW_PROFILE", profile_buf, sizeof(profile_buf), NULL);
2935 const char *suffix = "";
2936 char profile_suffix[CLI_BUF_256] = {0};
2937 if (profile && profile[0] && strcmp(profile, "default") != 0) {
2938 for (const unsigned char *p = (const unsigned char *)profile; *p; p++) {
2939 if (!isalnum(*p) && *p != '-' && *p != '_') {
2940 return false;
2941 }
2942 }
2943 int suffix_len = snprintf(profile_suffix, sizeof(profile_suffix), "-%s", profile);
2944 if (suffix_len < 0 || (size_t)suffix_len >= sizeof(profile_suffix)) {
2945 return false;
2946 }
2947 suffix = profile_suffix;
2948 }
2949 int written = snprintf(out, out_sz, "%s/.openclaw/workspace%s", internal_home, suffix);
2950 return written > 0 && (size_t)written < out_sz;

Callers 2

uninstall_editor_agentsFunction · 0.85

Calls 4

cbm_expand_user_pathFunction · 0.85
cbm_safe_getenvFunction · 0.85

Tested by

no test coverage detected