-
Notifications
You must be signed in to change notification settings - Fork 76
feat(host-bash): add target_client_id parameter to tool schema and executor #29314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,15 @@ import { existsSync } from "node:fs"; | |
| import { homedir } from "node:os"; | ||
| import { isAbsolute } from "node:path"; | ||
|
|
||
| import { supportsHostProxy } from "../../channels/types.js"; | ||
| import { getConfig } from "../../config/loader.js"; | ||
| import { isCesShellLockdownEnabled } from "../../credential-execution/feature-gates.js"; | ||
| import { HostBashProxy } from "../../daemon/host-bash-proxy.js"; | ||
| import { RiskLevel } from "../../permissions/types.js"; | ||
| import type { ToolDefinition } from "../../providers/types.js"; | ||
| import { isUntrustedTrustClass } from "../../runtime/actor-trust-resolver.js"; | ||
| import { wakeAgentForOpportunity } from "../../runtime/agent-wake.js"; | ||
| import { assistantEventHub } from "../../runtime/assistant-event-hub.js"; | ||
| import { redactSecrets } from "../../security/secret-scanner.js"; | ||
| import { getLogger } from "../../util/logger.js"; | ||
| import { | ||
|
|
@@ -131,6 +133,11 @@ class HostShellTool implements Tool { | |
| description: | ||
| "Run the command in the background on the host machine. The tool returns immediately with a background tool ID. When the process exits, its output is delivered to the conversation as a wake.", | ||
| }, | ||
| target_client_id: { | ||
| type: "string", | ||
| description: | ||
| "ID of the specific client to execute this command on. Required when multiple clients support host_bash; omit when only one client is connected. Obtain IDs from `assistant clients list --capability host_bash`.", | ||
| }, | ||
| }, | ||
| required: ["command", "activity"], | ||
| }, | ||
|
|
@@ -173,6 +180,11 @@ class HostShellTool implements Tool { | |
| } | ||
| const background = input.background === true; | ||
|
|
||
| const targetClientId = | ||
| typeof input.target_client_id === "string" | ||
| ? input.target_client_id | ||
| : undefined; | ||
|
|
||
| const config = getConfig(); | ||
| const { shellDefaultTimeoutSec, shellMaxTimeoutSec } = config.timeouts; | ||
|
|
||
|
|
@@ -190,6 +202,35 @@ class HostShellTool implements Tool { | |
| isCesShellLockdownEnabled(config) && | ||
| isUntrustedTrustClass(context.trustClass); | ||
|
|
||
| // Guard: non-host-proxy interfaces need an explicit target when multiple | ||
| // capable clients are connected to avoid ambiguous untargeted broadcasts. | ||
| const transportInterface = context.transportInterface; | ||
| if ( | ||
| targetClientId == null && | ||
| transportInterface != null && | ||
| !supportsHostProxy(transportInterface) && | ||
| assistantEventHub.listClientsByCapability("host_bash").length > 1 | ||
| ) { | ||
| return { | ||
| content: `Error: multiple clients support host_bash. Specify which client to use with \`target_client_id\`. Run \`assistant clients list --capability host_bash\` to see client IDs and labels.`, | ||
| isError: true, | ||
| }; | ||
| } | ||
|
|
||
| // Guard: non-host-proxy interfaces with no capable clients connected. | ||
| if ( | ||
| targetClientId == null && | ||
| transportInterface != null && | ||
| !supportsHostProxy(transportInterface) && | ||
| !HostBashProxy.instance.isAvailable() | ||
|
Comment on lines
+222
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new non-desktop guard only fires when Useful? React with 👍 / 👎. |
||
| ) { | ||
| return { | ||
| content: | ||
| "Error: no client with host_bash capability is connected. Connect a macOS client to use host_bash from a non-desktop interface.", | ||
| isError: true, | ||
| }; | ||
| } | ||
|
|
||
| // Proxy to connected client for execution on the user's machine | ||
| // when a capable client is available (managed/cloud-hosted mode). | ||
| if (HostBashProxy.instance.isAvailable()) { | ||
|
Comment on lines
234
to
236
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Explicit When a user specifies Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
@@ -227,6 +268,7 @@ class HostShellTool implements Tool { | |
| working_dir: rawWorkingDir as string | undefined, | ||
| timeout_seconds: normalizedTimeout, | ||
| env: proxyEnv, | ||
| targetClientId, | ||
| }, | ||
| context.conversationId, | ||
| abortController.signal, | ||
|
|
@@ -273,6 +315,7 @@ class HostShellTool implements Tool { | |
| working_dir: rawWorkingDir as string | undefined, | ||
| timeout_seconds: normalizedTimeout, | ||
| env: proxyEnv, | ||
| targetClientId, | ||
| }, | ||
| context.conversationId, | ||
| context.signal, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 Test coverage does not exercise targetClientId with unavailable proxy
The test file at
assistant/src/__tests__/host-shell-tool.test.tscovers proxy delegation when proxy is available (line 743+), input validation before proxying (lines 770+, 789+), and local fallback when proxy is unavailable (line 810+). However, there is no test for the scenario wheretarget_client_idis specified but the proxy is not available — which is the gap that enables the bug. Adding such a test would catch the silent local execution.Was this helpful? React with 👍 or 👎 to provide feedback.