From fb9d506dd67e9db9734478012c190aa5e900ba18 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Apr 2026 18:40:55 -0400 Subject: [PATCH] Run kubeoc attach in agent workspace --- cmd/kubeoc/agent.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/kubeoc/agent.go b/cmd/kubeoc/agent.go index 953d3a29..d26cb5f5 100644 --- a/cmd/kubeoc/agent.go +++ b/cmd/kubeoc/agent.go @@ -305,8 +305,12 @@ func runAgentAttachServiceProxy(ctx context.Context, namespace, agentName string heartbeatCancel := startConnectionHeartbeat(ctx, k8sClient, namespace, agentName) defer heartbeatCancel() - // Launch opencode attach - attachCmd := exec.CommandContext(ctx, "opencode", "attach", localURL) //nolint:gosec // args are not user-controlled + // Launch opencode attach from the Agent workspace directory when configured. + attachArgs := []string{"attach", localURL} + if agent.Spec.WorkspaceDir != "" { + attachArgs = append(attachArgs, "--dir", agent.Spec.WorkspaceDir) + } + attachCmd := exec.CommandContext(ctx, "opencode", attachArgs...) //nolint:gosec // args are not user-controlled attachCmd.Stdin = os.Stdin attachCmd.Stdout = os.Stdout attachCmd.Stderr = os.Stderr @@ -411,7 +415,11 @@ func runAgentAttachPortForward(ctx context.Context, namespace, agentName string, heartbeatCancel := startConnectionHeartbeat(ctx, k8sClient, namespace, agentName) defer heartbeatCancel() - attachCmd := exec.CommandContext(ctx, "opencode", "attach", localURL) //nolint:gosec // args are not user-controlled + attachArgs := []string{"attach", localURL} + if agent.Spec.WorkspaceDir != "" { + attachArgs = append(attachArgs, "--dir", agent.Spec.WorkspaceDir) + } + attachCmd := exec.CommandContext(ctx, "opencode", attachArgs...) //nolint:gosec // args are not user-controlled attachCmd.Stdin = os.Stdin attachCmd.Stdout = os.Stdout attachCmd.Stderr = os.Stderr