Skip to content

Commit 5b6a30d

Browse files
authored
Merge pull request DeusData#1933 from Chewji9875/fix/opencode-hook-args-and-subagent-permissions
fix(opencode): pass input args to augment hook and allow tool search in subagents
2 parents cc6743e + 8d46d25 commit 5b6a30d

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎src/cli/agent_profiles.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,17 @@ static bool render_profile_text(profile_buffer_t *buffer, cbm_graph_profile_dial
547547
}
548548
return true;
549549
case CBM_GRAPH_DIALECT_OPENCODE:
550+
if (!profile_buffer_append(buffer, "---\ndescription: ") ||
551+
!profile_buffer_append(buffer, description) ||
552+
!profile_buffer_append(
553+
buffer, "\nmode: subagent\npermission:\n \"*\": deny\n read: allow\n grep: "
554+
"allow\n glob: allow\n tool_search: allow\n tool_search_regex: "
555+
"allow\n") ||
556+
(direct && !append_permission_mcp_tools(buffer, dialect, tier)) ||
557+
!profile_buffer_append(buffer, "---\n") || !profile_buffer_append(buffer, prompt)) {
558+
return false;
559+
}
560+
return true;
550561
case CBM_GRAPH_DIALECT_KILO:
551562
if (!profile_buffer_append(buffer, "---\ndescription: ") ||
552563
!profile_buffer_append(buffer, description) ||

‎src/cli/client_adapter.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ char *cbm_client_adapter_opencode(const char *binary_path) {
315315
" seen.add(sid);\n"
316316
" pieces.push(await lifecycle());\n"
317317
" }\n"
318-
" const args = output?.args ?? {};\n"
318+
" const args = input?.args ?? {};\n"
319319
" const search =\n"
320320
" input?.tool === 'grep' ? 'Grep' : input?.tool === 'glob' ? 'Glob' : null;\n"
321321
" if (search) {\n"

‎tests/test_agent_clients.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ TEST(client_adapter_opencode_sends_the_required_hook_event) {
12831283
ASSERT_NOT_NULL(js);
12841284
ASSERT_NOT_NULL(strstr(js, "hook_event_name: 'PreToolUse'"));
12851285
ASSERT_NOT_NULL(strstr(js, "tool.execute.after"));
1286+
ASSERT_NOT_NULL(strstr(js, "const args = input?.args ?? {};"));
1287+
ASSERT_NOT_NULL(strstr(js, "tool_input: args"));
1288+
ASSERT_NULL(strstr(js, "output?.args"));
12861289
/* OpenCode reaches the tools over MCP already; this adapter must not
12871290
* register any, or we reintroduce the second tool surface. */
12881291
ASSERT_NULL(strstr(js, "registerTool"));

‎tests/test_agent_profiles.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,24 @@ TEST(agent_profiles_omp_direct_has_prefixed_tools_and_handoff_excludes_mcp) {
360360
PASS();
361361
}
362362

363+
TEST(agent_profiles_opencode_allows_tool_search_and_subagent_permissions) {
364+
char *direct = cbm_render_graph_profile(CBM_GRAPH_DIALECT_OPENCODE, CBM_GRAPH_TIER_VERIFY,
365+
CBM_GRAPH_ACCESS_DIRECT, NULL);
366+
ASSERT_NOT_NULL(direct);
367+
ASSERT_NOT_NULL(strstr(direct, "mode: subagent\n"));
368+
ASSERT_NOT_NULL(strstr(direct, " \"*\": deny\n"));
369+
ASSERT_NOT_NULL(strstr(direct, " read: allow\n"));
370+
ASSERT_NOT_NULL(strstr(direct, " grep: allow\n"));
371+
ASSERT_NOT_NULL(strstr(direct, " glob: allow\n"));
372+
ASSERT_NOT_NULL(strstr(direct, " tool_search: allow\n"));
373+
ASSERT_NOT_NULL(strstr(direct, " tool_search_regex: allow\n"));
374+
ASSERT_NOT_NULL(strstr(direct, " \"codebase-memory-mcp_search_graph\": allow\n"));
375+
ASSERT_NOT_NULL(strstr(direct, " \"codebase-memory-mcp_check_index_coverage\": allow\n"));
376+
ASSERT_NULL(strstr(direct, "delete_project"));
377+
free(direct);
378+
PASS();
379+
}
380+
363381
SUITE(agent_profiles) {
364382
RUN_TEST(agent_profiles_stable_tier_identity);
365383
RUN_TEST(agent_profiles_direct_dialects_are_coverage_aware_and_read_only);
@@ -371,6 +389,7 @@ SUITE(agent_profiles) {
371389
RUN_TEST(agent_profiles_codex_declares_transport_and_escapes_binary_path);
372390
RUN_TEST(agent_profiles_vibe_uses_matching_prompt_identifier_and_contract);
373391
RUN_TEST(agent_profiles_omp_direct_has_prefixed_tools_and_handoff_excludes_mcp);
392+
RUN_TEST(agent_profiles_opencode_allows_tool_search_and_subagent_permissions);
374393
RUN_TEST(agent_profiles_grok_uses_dispatcher_ids_and_named_inheritance);
375394
RUN_TEST(agent_profiles_render_deterministically_and_reject_invalid_inputs);
376395
}

0 commit comments

Comments
 (0)