Skip to content

Use agent workspace for kubeoc attach#3

Merged
ianrossi merged 1 commit intomainfrom
issue/11-kubeoc-attach-dir
Apr 8, 2026
Merged

Use agent workspace for kubeoc attach#3
ianrossi merged 1 commit intomainfrom
issue/11-kubeoc-attach-dir

Conversation

@ianrossi
Copy link
Copy Markdown

@ianrossi ianrossi commented Apr 8, 2026

Follow-up for QuantifAI Berlin auth rollout.

kubeoc agent attach now passes --dir <agent.spec.workspaceDir> to opencode attach so the TUI opens in the configured remote workspace instead of the caller's local cwd.

Copilot AI review requested due to automatic review settings April 8, 2026 22:41
@ianrossi ianrossi merged commit 69bf1d3 into main Apr 8, 2026
7 checks passed
@ianrossi ianrossi deleted the issue/11-kubeoc-attach-dir branch April 8, 2026 22:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates kubeoc agent attach to open the OpenCode TUI in the Agent’s configured workspace directory by passing --dir <workspaceDir> to opencode attach.

Changes:

  • Build opencode attach argument list dynamically and append --dir when agent.spec.workspaceDir is set (service-proxy mode).
  • Apply the same --dir behavior in the legacy kubectl port-forward attach mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/kubeoc/agent.go
Comment on lines +308 to +311
// 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)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkspaceDir can be inherited via agent.spec.templateRef (AgentTemplate). This code only checks agent.Spec.WorkspaceDir, so attach won’t pass --dir when WorkspaceDir is set on the template (effective workspace differs from what the controller uses). Consider resolving the merged config (e.g., controller.ResolveAgentConfigFromTemplate) and using the resulting workspaceDir instead of reading Agent.Spec directly.

Suggested change
// 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)
// Resolve the effective Agent configuration so template-inherited fields such as
// WorkspaceDir are handled consistently with the controller.
resolvedAgentConfig, err := controller.ResolveAgentConfigFromTemplate(ctx, k8sClient, &agent)
if err != nil {
return fmt.Errorf("resolve agent config for attach: %w", err)
}
// Launch opencode attach from the effective Agent workspace directory when configured.
attachArgs := []string{"attach", localURL}
if resolvedAgentConfig.WorkspaceDir != "" {
attachArgs = append(attachArgs, "--dir", resolvedAgentConfig.WorkspaceDir)

Copilot uses AI. Check for mistakes.
Comment thread cmd/kubeoc/agent.go
if agent.Spec.WorkspaceDir != "" {
attachArgs = append(attachArgs, "--dir", agent.Spec.WorkspaceDir)
}
attachCmd := exec.CommandContext(ctx, "opencode", attachArgs...) //nolint:gosec // args are not user-controlled
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gosec suppression rationale (“args are not user-controlled”) is no longer accurate: localURL is derived from CLI input (localPort), and WorkspaceDir comes from a cluster CR. Please either update the suppression comment to reflect the actual trust boundary/validation (e.g., WorkspaceDir is validated to an absolute path), or add explicit validation and drop the nolint if possible.

Copilot uses AI. Check for mistakes.
Comment thread cmd/kubeoc/agent.go
Comment on lines +418 to +421
attachArgs := []string{"attach", localURL}
if agent.Spec.WorkspaceDir != "" {
attachArgs = append(attachArgs, "--dir", agent.Spec.WorkspaceDir)
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: WorkspaceDir may be inherited via agent.spec.templateRef, but this block only reads agent.Spec.WorkspaceDir. To ensure attach opens in the actual configured workspace, resolve the merged workspaceDir from the template when TemplateRef is set.

Copilot uses AI. Check for mistakes.
Comment thread cmd/kubeoc/agent.go
if agent.Spec.WorkspaceDir != "" {
attachArgs = append(attachArgs, "--dir", agent.Spec.WorkspaceDir)
}
attachCmd := exec.CommandContext(ctx, "opencode", attachArgs...) //nolint:gosec // args are not user-controlled
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same gosec issue here: the suppression comment claims args are not user-controlled, but localURL is influenced by CLI input and WorkspaceDir is sourced from a CR. Update the suppression rationale and/or validate inputs before exec.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants