Skip to content

Commit dca2a44

Browse files
authored
Merge pull request #2807 from divakantpandey/fix/2787-pi-extension-string-enum
fix(cli): emit string enums as Type.String({ enum }) in Pi adapter (#2787)
2 parents e425666 + 323e88f commit dca2a44

2 files changed

Lines changed: 41 additions & 21 deletions

File tree

‎src/cli/client_adapter.c‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,38 +148,36 @@ static void append_typebox_type(adapter_sb_t *sb, yyjson_val *val, const char *d
148148

149149
if (type_str && strcmp(type_str, "string") == 0 && enum_val && yyjson_is_arr(enum_val) &&
150150
yyjson_arr_size(enum_val) > 0) {
151-
sb_append(sb, "Type.Union([");
152151
size_t enum_idx = 0;
153152
size_t enum_max = yyjson_arr_size(enum_val);
154-
bool first_enum = true;
153+
size_t valid_count = 0;
155154
for (enum_idx = 0; enum_idx < enum_max; enum_idx++) {
156-
yyjson_val *enum_item = yyjson_arr_get(enum_val, enum_idx);
157-
const char *enum_str = yyjson_get_str(enum_item);
158-
if (!enum_str) {
159-
continue;
155+
if (yyjson_get_str(yyjson_arr_get(enum_val, enum_idx))) {
156+
valid_count++;
160157
}
161-
if (!first_enum) {
162-
sb_append(sb, ", ");
163-
}
164-
first_enum = false;
165-
sb_append(sb, "Type.Literal(");
166-
sb_append_js_string(sb, enum_str);
167-
sb_append(sb, ")");
168158
}
169-
if (first_enum) {
170-
sb_append(sb, "Type.String()");
171-
} else {
159+
if (valid_count > 0) {
160+
sb_append(sb, "Type.String({ enum: [");
161+
bool first_enum = true;
162+
for (enum_idx = 0; enum_idx < enum_max; enum_idx++) {
163+
const char *enum_str = yyjson_get_str(yyjson_arr_get(enum_val, enum_idx));
164+
if (!enum_str) {
165+
continue;
166+
}
167+
if (!first_enum) {
168+
sb_append(sb, ", ");
169+
}
170+
first_enum = false;
171+
sb_append_js_string(sb, enum_str);
172+
}
172173
sb_append(sb, "]");
173174
if (include_description && description) {
174-
sb_append(sb, ", { description: ");
175+
sb_append(sb, ", description: ");
175176
sb_append_js_string(sb, description);
176-
sb_append(sb, " }");
177177
}
178-
sb_append(sb, ")");
178+
sb_append(sb, " })");
179179
return;
180180
}
181-
sb_append(sb, ")");
182-
return;
183181
}
184182

185183
const char *typebox_name = "Any";

‎tests/test_agent_clients.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,10 @@ TEST(client_adapter_pi_emits_parameters_and_execute) {
11771177
/* TypeBox parameters schema is embedded with Type.Object syntax. */
11781178
ASSERT_NOT_NULL(strstr(js, "Type.Object("));
11791179
ASSERT_NOT_NULL(strstr(js, "Type.String("));
1180+
/* #2787: String enums must use Type.String({ enum: [...] }) without anyOf/const */
1181+
ASSERT_NOT_NULL(strstr(js, "Type.String({ enum: ["));
1182+
ASSERT_NULL(strstr(js, "Type.Union([Type.Literal"));
1183+
ASSERT_NULL(strstr(js, "Type.Literal("));
11801184
/* A numeric registry property must remain numeric in the generated schema. */
11811185
ASSERT_NOT_NULL(strstr(js, "depth: Type.Optional(Type.Integer("));
11821186
/* TypeBox import should be present. */
@@ -1244,6 +1248,23 @@ TEST(client_adapter_pi_wraps_result_and_honors_abort) {
12441248
PASS();
12451249
}
12461250

1251+
/* #2787: Pi extension must emit string enums as Type.String({ enum: [...] })
1252+
* rather than Type.Union([Type.Literal(...)]) which TypeBox serializes as
1253+
* anyOf/const, breaking Gemini / Antigravity function declaration validation. */
1254+
TEST(client_adapter_pi_emits_string_enum_issue2787) {
1255+
char *js = cbm_client_adapter_pi("/usr/local/bin/codebase-memory-mcp");
1256+
ASSERT_NOT_NULL(js);
1257+
ASSERT_NULL(strstr(js, "Type.Union([Type.Literal"));
1258+
ASSERT_NULL(strstr(js, "Type.Literal("));
1259+
ASSERT_NOT_NULL(strstr(js, "Type.String({ enum: ["));
1260+
ASSERT_NOT_NULL(strstr(js, "'full'"));
1261+
ASSERT_NOT_NULL(strstr(js, "'moderate'"));
1262+
ASSERT_NOT_NULL(strstr(js, "'fast'"));
1263+
ASSERT_NOT_NULL(strstr(js, "'cross-repo-intelligence'"));
1264+
free(js);
1265+
PASS();
1266+
}
1267+
12471268
/* #616 rejected `"` in its path template but not `\`, so a Windows home like
12481269
* C:\Users\urs\bin produced `\u` — an invalid unicode escape — and the whole
12491270
* auto-loaded plugin failed to parse. A broken plugin in an auto-load directory
@@ -1405,6 +1426,7 @@ SUITE(agent_clients) {
14051426
RUN_TEST(client_adapter_pi_emits_parameters_and_execute);
14061427
RUN_TEST(client_adapter_pi_sends_arguments_over_stdin_issue1834);
14071428
RUN_TEST(client_adapter_pi_wraps_result_and_honors_abort);
1429+
RUN_TEST(client_adapter_pi_emits_string_enum_issue2787);
14081430
RUN_TEST(client_adapter_escapes_windows_paths_and_quotes);
14091431
RUN_TEST(client_adapter_opencode_sends_the_required_hook_event);
14101432
RUN_TEST(client_adapter_opencode_covers_lifecycle_read_and_compaction);

0 commit comments

Comments
 (0)