Skip to content

Commit 410cd9a

Browse files
committed
fix(cli): respect OMP agent directory and preserve instructions
Signed-off-by: DavidHLP <lysf15520112973@163.com>
1 parent f518eae commit 410cd9a

6 files changed

Lines changed: 417 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ overwrite user-modified agents.
490490
| Pochi | Detected | `~/.pochi/config.jsonc` (`mcp`) | `README.pochi.md`, skill, and three `readFile`-only parent-handoff agents |
491491
| Pi | Detected | — | `~/.pi/agent/AGENTS.md` + skill; MCP/subagents require an explicit reviewed extension |
492492
| IBM Bob IDE | Conditional | Existing `~/.bob/mcp.json` | Shared rule + IDE skill; no invented hook or agent |
493-
| Oh My Pi (omp) | Detected | `~/.omp/agent/mcp.json` | `AGENTS.md`, skill, three direct-MCP graph-tool subagents (Scout/Verify/Auditor) |
493+
| Oh My Pi (omp) | Detected | Effective agent directory (`OMP_PROFILE` / `PI_CODING_AGENT_DIR`; default `~/.omp/agent/mcp.json`) | Skill and three direct-MCP graph-tool subagents (Scout/Verify/Auditor); preserves user `AGENTS.md` |
494494
| Sourcegraph Cody | Explicit opt-in | Existing `$CBM_CODY_CONFIG_PATH` | MCP only |
495495

496496
### Sessions, compaction, and subagents

‎src/cli/agent_clients.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ static const cbm_agent_client_profile_t agent_profiles[CBM_AGENT_CLIENT_COUNT] =
7474
{CBM_AGENT_CLIENT_SOURCEGRAPH_CODY, "sourcegraph-cody", "Sourcegraph Cody", CBM_AGENT_OPT_IN,
7575
CBM_AGENT_CAP_MCP, NULL, agent_install_callback, agent_remove_callback},
7676
{CBM_AGENT_CLIENT_OMP, "omp", "Oh My Pi (omp)", CBM_AGENT_STABLE,
77-
CBM_AGENT_CAP_MCP | CBM_AGENT_CAP_INSTRUCTIONS | CBM_AGENT_CAP_SKILL | CBM_AGENT_CAP_AGENT,
78-
"omp", agent_install_callback, agent_remove_callback},
77+
CBM_AGENT_CAP_MCP | CBM_AGENT_CAP_SKILL | CBM_AGENT_CAP_AGENT, "omp",
78+
agent_install_callback, agent_remove_callback},
7979
};
8080

8181
size_t cbm_agent_client_count(void) {
@@ -585,6 +585,10 @@ int cbm_agent_client_resolve_path(cbm_agent_client_id_t id,
585585
case CBM_AGENT_CLIENT_POCHI:
586586
return agent_join_path(path_out, path_out_size, options->home_dir, ".pochi/config.jsonc");
587587
case CBM_AGENT_CLIENT_OMP:
588+
if (options->omp_agent_dir && options->omp_agent_dir[0]) {
589+
int written = snprintf(path_out, path_out_size, "%s/mcp.json", options->omp_agent_dir);
590+
return written >= 0 && (size_t)written < path_out_size ? 0 : -1;
591+
}
588592
return agent_join_path(path_out, path_out_size, options->home_dir, ".omp/agent/mcp.json");
589593
case CBM_AGENT_CLIENT_PI:
590594
return 1;
@@ -652,6 +656,10 @@ static int agent_client_marker_path(cbm_agent_client_id_t id,
652656
case CBM_AGENT_CLIENT_POCHI:
653657
return agent_join_path(path_out, path_out_size, options->home_dir, ".pochi");
654658
case CBM_AGENT_CLIENT_OMP:
659+
if (options->omp_agent_dir && options->omp_agent_dir[0]) {
660+
int written = snprintf(path_out, path_out_size, "%s", options->omp_agent_dir);
661+
return written >= 0 && (size_t)written < path_out_size ? 0 : 1;
662+
}
655663
return agent_join_path(path_out, path_out_size, options->home_dir, ".omp/agent");
656664
case CBM_AGENT_CLIENT_PI:
657665
return agent_join_path(path_out, path_out_size, options->home_dir, ".pi/agent");

‎src/cli/agent_clients.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef struct {
7676
const char *trae_config_path;
7777
const char *roo_config_path;
7878
const char *cody_config_path;
79+
const char *omp_agent_dir;
7980
bool is_windows;
8081
cbm_agent_probe_fn path_exists;
8182
cbm_agent_probe_fn command_exists;

‎src/cli/cli.c‎

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8109,6 +8109,29 @@ static void install_copilot_durable_context(const char *home, const char *binary
81098109
}
81108110
}
81118111

8112+
static bool cbm_omp_agent_dir(const char *home_dir, char *out, size_t out_sz) {
8113+
char profile_buf[CLI_BUF_256];
8114+
const char *profile = cbm_safe_getenv("OMP_PROFILE", profile_buf, sizeof(profile_buf), NULL);
8115+
if (profile && profile[0]) {
8116+
for (const unsigned char *p = (const unsigned char *)profile; *p; p++) {
8117+
if (!isalnum(*p) && *p != '-' && *p != '_') {
8118+
return false;
8119+
}
8120+
}
8121+
int written = snprintf(out, out_sz, "%s/.omp/profiles/%s/agent", home_dir, profile);
8122+
return written > 0 && (size_t)written < out_sz;
8123+
}
8124+
8125+
char agent_dir_buf[CLI_BUF_1K];
8126+
const char *agent_dir =
8127+
cbm_safe_getenv("PI_CODING_AGENT_DIR", agent_dir_buf, sizeof(agent_dir_buf), NULL);
8128+
if (agent_dir && agent_dir[0]) {
8129+
return cbm_expand_user_path(home_dir, agent_dir, out, out_sz);
8130+
}
8131+
int written = snprintf(out, out_sz, "%s/.omp/agent", home_dir);
8132+
return written > 0 && (size_t)written < out_sz;
8133+
}
8134+
81128135
typedef struct {
81138136
cbm_agent_client_resolve_options_t options;
81148137
char xdg_config_home[CLI_BUF_1K];
@@ -8119,6 +8142,7 @@ typedef struct {
81198142
char trae_config_path[CLI_BUF_1K];
81208143
char roo_config_path[CLI_BUF_1K];
81218144
char cody_config_path[CLI_BUF_1K];
8145+
char omp_agent_dir[CLI_BUF_1K];
81228146
} cbm_agent_registry_context_t;
81238147

81248148
static const char *cbm_agent_registry_env_path(const char *env_name, const char *home,
@@ -8170,6 +8194,9 @@ static void cbm_init_agent_registry_context(const char *home,
81708194
registry->options.cody_config_path =
81718195
cbm_agent_registry_env_path("CBM_CODY_CONFIG_PATH", home, registry->cody_config_path,
81728196
sizeof(registry->cody_config_path));
8197+
if (cbm_omp_agent_dir(home, registry->omp_agent_dir, sizeof(registry->omp_agent_dir))) {
8198+
registry->options.omp_agent_dir = registry->omp_agent_dir;
8199+
}
81738200
#ifdef _WIN32
81748201
registry->options.is_windows = true;
81758202
#else
@@ -8535,14 +8562,26 @@ static void install_pochi_durable_context(const char *home, bool force, bool dry
85358562
dry_run);
85368563
}
85378564

8538-
static void install_omp_durable_context(const char *home, bool force, bool dry_run) {
8539-
char instructions_path[CLI_BUF_1K];
8565+
static void install_omp_durable_context(const cbm_agent_registry_context_t *registry,
8566+
bool force, bool dry_run) {
8567+
const char *agent_dir = registry->options.omp_agent_dir
8568+
&& registry->options.omp_agent_dir[0]
8569+
? registry->options.omp_agent_dir
8570+
: NULL;
8571+
char resolved_dir[CLI_BUF_1K];
8572+
if (!agent_dir) {
8573+
int written = snprintf(resolved_dir, sizeof(resolved_dir), "%s/.omp/agent",
8574+
registry->options.home_dir);
8575+
if (written < 0 || (size_t)written >= sizeof(resolved_dir)) {
8576+
record_agent_config_error(false, "Oh My Pi (omp)", "context_resolve", "omp");
8577+
return;
8578+
}
8579+
agent_dir = resolved_dir;
8580+
}
85408581
char skills_dir[CLI_BUF_1K];
85418582
char agent_path[CLI_BUF_1K];
8542-
snprintf(instructions_path, sizeof(instructions_path), "%s/.omp/agent/AGENTS.md", home);
8543-
snprintf(skills_dir, sizeof(skills_dir), "%s/.omp/agent/skills", home);
8544-
snprintf(agent_path, sizeof(agent_path), "%s/.omp/agent/agents/codebase-memory.md", home);
8545-
install_managed_agent_instructions("Oh My Pi (omp)", instructions_path, dry_run);
8583+
snprintf(skills_dir, sizeof(skills_dir), "%s/skills", agent_dir);
8584+
snprintf(agent_path, sizeof(agent_path), "%s/agents/codebase-memory.md", agent_dir);
85468585
install_agent_skill("Oh My Pi (omp)", skills_dir, force, dry_run);
85478586
install_tiered_agent_profiles(
85488587
(cbm_tiered_profile_set_t){
@@ -8623,7 +8662,7 @@ static void install_agent_client_registry(const char *home, const char *binary_p
86238662
} else if (profile->id == CBM_AGENT_CLIENT_PI) {
86248663
install_pi_durable_context(home, binary_path, force, dry_run);
86258664
} else if (profile->id == CBM_AGENT_CLIENT_OMP) {
8626-
install_omp_durable_context(home, force, dry_run);
8665+
install_omp_durable_context(&registry, force, dry_run);
86278666
}
86288667
}
86298668
}
@@ -10838,14 +10877,26 @@ static void uninstall_pochi_durable_context(const char *home, bool dry_run) {
1083810877
dry_run);
1083910878
}
1084010879

10841-
static void uninstall_omp_durable_context(const char *home, bool dry_run) {
10842-
char instructions_path[CLI_BUF_1K];
10880+
static void uninstall_omp_durable_context(const cbm_agent_registry_context_t *registry,
10881+
bool dry_run) {
10882+
const char *agent_dir = registry->options.omp_agent_dir
10883+
&& registry->options.omp_agent_dir[0]
10884+
? registry->options.omp_agent_dir
10885+
: NULL;
10886+
char resolved_dir[CLI_BUF_1K];
10887+
if (!agent_dir) {
10888+
int written = snprintf(resolved_dir, sizeof(resolved_dir), "%s/.omp/agent",
10889+
registry->options.home_dir);
10890+
if (written < 0 || (size_t)written >= sizeof(resolved_dir)) {
10891+
record_agent_config_error(true, "Oh My Pi (omp)", "context_resolve", "omp");
10892+
return;
10893+
}
10894+
agent_dir = resolved_dir;
10895+
}
1084310896
char skills_dir[CLI_BUF_1K];
1084410897
char agent_path[CLI_BUF_1K];
10845-
snprintf(instructions_path, sizeof(instructions_path), "%s/.omp/agent/AGENTS.md", home);
10846-
snprintf(skills_dir, sizeof(skills_dir), "%s/.omp/agent/skills", home);
10847-
snprintf(agent_path, sizeof(agent_path), "%s/.omp/agent/agents/codebase-memory.md", home);
10848-
uninstall_managed_agent_instructions("Oh My Pi (omp)", instructions_path, dry_run);
10898+
snprintf(skills_dir, sizeof(skills_dir), "%s/skills", agent_dir);
10899+
snprintf(agent_path, sizeof(agent_path), "%s/agents/codebase-memory.md", agent_dir);
1084910900
uninstall_agent_skill("Oh My Pi (omp)", skills_dir, dry_run);
1085010901
uninstall_tiered_agent_profiles(
1085110902
(cbm_tiered_profile_set_t){
@@ -10917,7 +10968,7 @@ static void uninstall_agent_client_registry(const char *home, bool dry_run) {
1091710968
} else if (profile->id == CBM_AGENT_CLIENT_PI) {
1091810969
uninstall_pi_durable_context(home, dry_run);
1091910970
} else if (profile->id == CBM_AGENT_CLIENT_OMP) {
10920-
uninstall_omp_durable_context(home, dry_run);
10971+
uninstall_omp_durable_context(&registry, dry_run);
1092110972
}
1092210973
}
1092310974
}

‎tests/test_agent_clients.c‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static cbm_agent_client_resolve_options_t agent_options(agent_probe_t *probe) {
4949
.trae_config_path = NULL,
5050
.roo_config_path = NULL,
5151
.cody_config_path = NULL,
52+
.omp_agent_dir = NULL,
5253
.is_windows = false,
5354
.path_exists = agent_path_exists,
5455
.command_exists = agent_command_exists,
@@ -182,7 +183,7 @@ TEST(agent_clients_registry_is_stable_and_callback_driven) {
182183
CBM_AGENT_CAP_MCP | CBM_AGENT_CAP_INSTRUCTIONS | CBM_AGENT_CAP_SKILL | CBM_AGENT_CAP_AGENT,
183184
CBM_AGENT_CAP_INSTRUCTIONS | CBM_AGENT_CAP_SKILL,
184185
CBM_AGENT_CAP_MCP,
185-
CBM_AGENT_CAP_MCP | CBM_AGENT_CAP_INSTRUCTIONS | CBM_AGENT_CAP_SKILL | CBM_AGENT_CAP_AGENT,
186+
CBM_AGENT_CAP_MCP | CBM_AGENT_CAP_SKILL | CBM_AGENT_CAP_AGENT,
186187
};
187188
ASSERT_EQ(cbm_agent_client_count(), CBM_AGENT_CLIENT_COUNT);
188189
ASSERT_EQ(CBM_AGENT_CLIENT_COUNT, sizeof(expected) / sizeof(expected[0]));
@@ -934,6 +935,45 @@ TEST(agent_clients_refuse_foreign_and_preserve_modified_entries) {
934935
PASS();
935936
}
936937

938+
TEST(agent_clients_omp_resolves_to_injected_agent_dir_when_provided) {
939+
agent_probe_t probe = {0};
940+
cbm_agent_client_resolve_options_t options = agent_options(&probe);
941+
char resolved[512];
942+
943+
/* Default (no env) keeps the documented ~/.omp/agent path. */
944+
ASSERT_EQ(cbm_agent_client_resolve_path(CBM_AGENT_CLIENT_OMP, &options, resolved,
945+
sizeof(resolved)),
946+
0);
947+
ASSERT_STR_EQ(resolved, "/home/tester/.omp/agent/mcp.json");
948+
949+
/* Named profile directory takes precedence over the home-relative default. */
950+
options.omp_agent_dir = "/home/tester/.omp/profiles/work/agent";
951+
ASSERT_EQ(cbm_agent_client_resolve_path(CBM_AGENT_CLIENT_OMP, &options, resolved,
952+
sizeof(resolved)),
953+
0);
954+
ASSERT_STR_EQ(resolved, "/home/tester/.omp/profiles/work/agent/mcp.json");
955+
956+
/* PI_CODING_AGENT_DIR relocations also flow through the resolved option. */
957+
options.omp_agent_dir = "/srv/omp-shared/agent";
958+
ASSERT_EQ(cbm_agent_client_resolve_path(CBM_AGENT_CLIENT_OMP, &options, resolved,
959+
sizeof(resolved)),
960+
0);
961+
ASSERT_STR_EQ(resolved, "/srv/omp-shared/agent/mcp.json");
962+
PASS();
963+
}
964+
965+
TEST(agent_clients_omp_profile_does_not_register_global_instructions_capability) {
966+
const cbm_agent_client_profile_t *profile =
967+
cbm_agent_client_by_id(CBM_AGENT_CLIENT_OMP);
968+
ASSERT_NOT_NULL(profile);
969+
ASSERT_EQ(profile->capabilities & CBM_AGENT_CAP_INSTRUCTIONS, 0U);
970+
ASSERT_NEQ(profile->capabilities & CBM_AGENT_CAP_MCP, 0U);
971+
ASSERT_NEQ(profile->capabilities & CBM_AGENT_CAP_SKILL, 0U);
972+
ASSERT_NEQ(profile->capabilities & CBM_AGENT_CAP_AGENT, 0U);
973+
PASS();
974+
}
975+
976+
937977
TEST(agent_clients_remove_only_canonical_and_missing_is_noop) {
938978
char *dir = NULL;
939979
char *path = agent_fixture("{\"keep\":true}\n", &dir);
@@ -1243,6 +1283,8 @@ SUITE(agent_clients) {
12431283
RUN_TEST(agent_clients_json_schemas_are_exact_and_policy_neutral);
12441284
RUN_TEST(agent_clients_new_standard_json_profiles_preserve_foreign_entries);
12451285
RUN_TEST(agent_clients_refuse_foreign_and_preserve_modified_entries);
1286+
RUN_TEST(agent_clients_omp_resolves_to_injected_agent_dir_when_provided);
1287+
RUN_TEST(agent_clients_omp_profile_does_not_register_global_instructions_capability);
12461288
RUN_TEST(agent_clients_remove_only_canonical_and_missing_is_noop);
12471289
RUN_TEST(agent_clients_registry_callbacks_apply_the_selected_schema);
12481290
RUN_TEST(agent_clients_malformed_json_fails_byte_identically);

0 commit comments

Comments
 (0)