Skip to content

OpenShell SDK Migration [Spec + Impl] - #7

Merged
rhuss merged 4 commits into
mainfrom
075-openshell-sdk-migration
Jun 30, 2026
Merged

rhuss merged 4 commits into
mainfrom
075-openshell-sdk-migration

Conversation

@rhuss

@rhuss rhuss commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implementation of OpenShell SDK Migration.

Replace cc-deck's OpenShell CLI wrapper (os/exec + output parsing) with the OpenShell Go SDK (github.com/rhuss/openshell-sdk-go). All sandbox lifecycle operations (create, attach, delete, exec, upload, download, provider management) now use gRPC via the SDK directly, eliminating the openshell CLI binary as a runtime dependency.

The git channel (ext::openshell transport) still requires the CLI binary for git push/fetch operations.

Artifacts

  • Spec: specs/075-openshell-sdk-migration/spec.md
  • Plan: specs/075-openshell-sdk-migration/plan.md
  • Tasks: specs/075-openshell-sdk-migration/tasks.md

Assisted-By: 🤖 Claude Code


Open in Devin Review

Summary by CodeRabbit

  • New Features
    • Workspace operations now use the OpenShell SDK directly (gRPC), reducing reliance on the CLI for most flows.
    • Improved file transfer and session execution via SDK-backed streams and interactive sessions.
    • Session view sorting now prioritizes most recently active items within each tier.
  • Bug Fixes
    • More reliable status handling for provisioning, missing sandboxes, and delete-in-progress states.
    • More consistent, structured error handling across workspace actions.
  • Documentation
    • Added/updated SDK migration spec, plan, research notes, and review/checklists.

rhuss added 3 commits June 30, 2026 03:45
Assisted-By: 🤖 Claude Code
Assisted-By: 🤖 Claude Code
Assisted-By: 🤖 Claude Code
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ddb59caa-aa04-428c-bb2b-d1c1ec9bf3dd

📥 Commits

Reviewing files that changed from the base of the PR and between ed89e9c and 134eee7.

⛔ Files ignored due to path filters (1)
  • cc-deck/go.sum is excluded by !**/*.sum
📒 Files selected for processing (24)
  • README.md
  • brainstorm/idea-inbox.md
  • cc-deck/CLAUDE.md
  • cc-deck/go.mod
  • cc-deck/internal/credential/transport.go
  • cc-deck/internal/credential/transport_test.go
  • cc-deck/internal/openshell/client.go
  • cc-deck/internal/openshell/client_test.go
  • cc-deck/internal/openshell/credentials.go
  • cc-deck/internal/openshell/credentials_test.go
  • cc-deck/internal/openshell/iface.go
  • cc-deck/internal/ws/channel_openshell.go
  • cc-deck/internal/ws/openshell.go
  • cc-deck/internal/ws/openshell_test.go
  • cc-deck/internal/ws/terminal_stub.go
  • cc-deck/internal/ws/terminal_unix.go
  • specs/075-openshell-sdk-migration/REVIEW-CODE.md
  • specs/075-openshell-sdk-migration/checklists/requirements.md
  • specs/075-openshell-sdk-migration/data-model.md
  • specs/075-openshell-sdk-migration/plan.md
  • specs/075-openshell-sdk-migration/research.md
  • specs/075-openshell-sdk-migration/review-findings.md
  • specs/075-openshell-sdk-migration/spec.md
  • specs/075-openshell-sdk-migration/tasks.md

📝 Walkthrough

Walkthrough

Replaces the cc-deck OpenShell CLI wrapper with the github.com/rhuss/openshell-sdk-go v1 gRPC client. The migration removes the custom Client interface and CLI parsing code, adds GatewayConfig.ToSDKConfig(), updates workspace lifecycle/exec/attach/file-transfer calls to typed SDK APIs, revises credential helpers to use SDK sub-clients, and adds terminal resize support. Supporting migration documentation, specs, review reports, and brainstorm notes are also added. Separately, the Zellij plugin's virtual sort is updated to order by tier then most-recent activity timestamp.

Changes

OpenShell SDK Migration

Layer / File(s) Summary
Migration docs, planning, and brainstorm
brainstorm/00-overview.md, brainstorm/27-openshell-sdk-migration.md, brainstorm/idea-inbox.md, cc-deck/CLAUDE.md, README.md, cc-deck/go.mod, specs/075-openshell-sdk-migration/*
Adds the migration spec, plan, research, tasks, review reports, checklist, brainstorm entry, idea-inbox triage items, README SDK note, and plan path reference update. Also adds go.mod entries for openshell-sdk-go v0.2.2, golang.org/x/term, and bumped gRPC/protobuf/OTel indirect dependencies.
SDK foundation: factory and GatewayConfig mapping
cc-deck/internal/openshell/iface.go, cc-deck/internal/openshell/client.go, cc-deck/internal/openshell/client_test.go
Removes the exported Client interface and CLI subprocess/ANSI parsing code. Adds NewSDKClient factory returning v1.ClientInterface, adds GatewayConfig.ToSDKConfig() with TLS and insecure-mode handling, and replaces old client tests with NewSDKClient/ToSDKConfig tests including interface conformance assertions.
Credential injection and transport interface
cc-deck/internal/openshell/credentials.go, cc-deck/internal/openshell/credentials_test.go, cc-deck/internal/credential/transport.go, cc-deck/internal/credential/transport_test.go
Updates InjectEnvVars and UploadFileCredential to accept v1.ClientInterface, switching to client.Exec().Run and client.Files().Upload. Rewrites the OpenShellClient transport interface to ExecRun/FileUpload. Updates all mocks and test assertions to match the new signatures.
Workspace lifecycle, exec, and attach
cc-deck/internal/ws/openshell.go, cc-deck/internal/ws/terminal_unix.go, cc-deck/internal/ws/terminal_stub.go
Migrates OpenShellWorkspace fields to v1.ClientInterface plus gatewayAddr. Refactors attachState from PID to active+cancel. Updates Status, Create, Stop, Delete, KillSession, Attach, Exec, and ExecOutput to SDK typed calls. Adds loadSDKPolicy, resolveSandboxCommand, Unix SIGWINCH resize watcher, and Windows stub.
Channel file transfer and workspace tests
cc-deck/internal/ws/channel_openshell.go, cc-deck/internal/ws/openshell_test.go
Switches Push/Pull/PushBytes to Files() sub-client with temp-file upload replacing CLI exec. Updates workspace tests to use SDK fake client, phase override wrappers, boolean attach state, and adds TestStatusMapping_Deleting, TestStatusMapping_NotFound, and TestCreate_HappyPath.

Zellij Sort Update

Layer / File(s) Summary
Tier and recency ordering
cc-zellij-plugin/src/controller/actions.rs
handle_sort now collects (pane_id, tier, last_event_ts) tuples and sorts by tier ascending then descending last_event_ts, replacing the prior tab-index-then-tier order.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 Hop hop, the CLI is gone,
gRPC now carries every song!
No more parsing ANSI lines,
SDK sub-clients draw the signs.
The rabbit cheers—clean code at last,
the subprocess days are in the past! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: migrating OpenShell usage to the SDK and including spec/implementation updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 075-openshell-sdk-migration

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3496496758: check ExecResult.ExitCode in credential injection
- Comment #3496496766: update plan.md PushBytes to match temp-file implementation
- Comment #3496496768: update spec.md PushBytes assumption to match implementation

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Migrates cc-deck’s OpenShell integration from a CLI wrapper (os/exec + output parsing) to the OpenShell Go SDK (github.com/rhuss/openshell-sdk-go), updating workspace lifecycle, file transfer, credential injection, and tests to use the SDK’s typed clients and fake client. This also adds a full spec/plan/task set for the migration and tweaks zellij sidebar sorting to prioritize recency within tiers.

Changes:

  • Replace OpenShell CLI subprocess wrapper with SDK-backed v1.ClientInterface usage across workspace lifecycle + data channel operations.
  • Update credential injection + unit tests to use SDK Exec/Files clients (and fake client where possible).
  • Add migration spec artifacts and update README/CLAUDE.md references; adjust zellij plugin sorting behavior.

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
specs/075-openshell-sdk-migration/tasks.md Task breakdown for the SDK migration work.
specs/075-openshell-sdk-migration/spec.md Feature spec, acceptance scenarios, requirements, and success criteria.
specs/075-openshell-sdk-migration/review-findings.md Captures review findings and resolutions for the migration.
specs/075-openshell-sdk-migration/REVIEW-CODE.md Automated review/compliance report for the migration.
specs/075-openshell-sdk-migration/research.md Research notes on mapping types/APIs and testing constraints.
specs/075-openshell-sdk-migration/plan.md Implementation plan and structure/risk notes.
specs/075-openshell-sdk-migration/data-model.md Type mapping between prior wrapper types and SDK types.
specs/075-openshell-sdk-migration/checklists/requirements.md Spec-quality checklist for the migration spec.
README.md Documents SDK usage and (currently) local dev setup guidance.
cc-zellij-plugin/src/controller/actions.rs Changes session sorting to order by activity tier then recency.
cc-deck/internal/ws/openshell.go Workspace lifecycle migrated to SDK (sandboxes/providers/exec) + WaitReady usage.
cc-deck/internal/ws/openshell_test.go Workspace tests updated to use SDK fake client and phase override wrapper.
cc-deck/internal/ws/channel_openshell.go Data channel migrated to SDK Files client; PushBytes now uses temp-file + upload.
cc-deck/internal/openshell/iface.go Replaces old custom Client interface with NewSDKClient factory.
cc-deck/internal/openshell/credentials.go Credential env-var/file injection updated to SDK Exec/Files clients.
cc-deck/internal/openshell/credentials_test.go Updates credential tests to use SDK client interfaces/mocks.
cc-deck/internal/openshell/client.go Removes CLI wrapper implementation; keeps GatewayConfig and adds SDK config mapping.
cc-deck/internal/openshell/client_test.go Tests updated for NewSDKClient and GatewayConfig.ToSDKConfig().
cc-deck/internal/credential/transport.go Credential transport interface and implementation updated for SDK-style operations.
cc-deck/internal/credential/transport_test.go Updates mocks/tests for new credential transport interface.
cc-deck/go.mod Adds SDK dependency and grpc/genproto indirects; includes a local-path replace directive.
cc-deck/go.sum Adds checksums for new transitive dependencies.
cc-deck/CLAUDE.md Updates referenced plan document path to the new spec/plan.
brainstorm/27-openshell-sdk-migration.md Brainstorm doc for the SDK migration approach and rationale.
brainstorm/00-overview.md Updates brainstorm index/overview with the new thread.
Comments suppressed due to low confidence (1)

cc-deck/internal/openshell/credentials.go:318

  • InjectEnvVars builds export lines using %q, which wraps values in double quotes. Double-quoted values still allow command substitution (e.g. $(...) / backticks), so a value containing those characters would execute code when the shell sources .bashrc/.zshrc. Also, the function currently always returns nil even if every injection attempt fails, so callers can't detect a complete failure.
func InjectEnvVars(ctx context.Context, client v1.ClientInterface, sandboxID string, vars map[string]string) error {
	for k, v := range vars {
		exportLine := fmt.Sprintf("export %s=%q", k, v)
		for _, rcFile := range []string{".bashrc", ".zshrc"} {
			cmd := []string{"bash", "-c", fmt.Sprintf("echo %q >> /sandbox/%s", exportLine, rcFile)}
			result, err := client.Exec().Run(ctx, sandboxID, cmd)
			if err != nil {
				log.Printf("WARNING: failed to set %s in %s: %v", k, rcFile, err)
			} else if result != nil && result.ExitCode != 0 {
				log.Printf("WARNING: failed to set %s in %s: exit code %d", k, rcFile, result.ExitCode)
			}
		}
	}
	return nil

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

Comment thread cc-deck/go.mod Outdated
sigs.k8s.io/yaml v1.6.0 // indirect
)

replace github.com/rhuss/openshell-sdk-go => ../../openshell-sdk-go
Comment thread README.md Outdated
Comment on lines +453 to +457
For local development, `cc-deck/go.mod` contains a `replace` directive pointing to the local SDK checkout:

```
replace github.com/rhuss/openshell-sdk-go => ../../openshell-sdk-go
```
Comment thread cc-deck/internal/ws/openshell.go Resolved
rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3496585380: add remotePath validation to PushBytes

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3496656187: propagate stream errors and exit codes from Exec()

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3496716156: route stderr chunks to os.Stderr in streaming exec

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

@rhuss
rhuss requested a review from Copilot June 30, 2026 10:24
rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3496998666: use errors.Is(streamErr, io.EOF) instead of string comparison

Assisted-By: 🤖 Claude Code

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3498025432: fail sandbox creation if policy loading fails
- Comment #3498019275: split sandbox command string for args support
- Comment #3498025450: pass cancellable context to Interactive()
- Comment #3498019319: set w.attach to nil after normal detach
- Comment #3498025422: fix markdown heading levels in idea-inbox

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3498088741: fix misplaced doc comment on resolveSandboxCommand

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jun 30, 2026
Applied fixes from bot review comments:
- Comment #3498148823: map L7 allow rules in policy conversion

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Replace cc-deck's OpenShell CLI wrapper (os/exec + output parsing) with
the OpenShell Go SDK (github.com/rhuss/openshell-sdk-go v0.2.2). All
sandbox lifecycle operations now use gRPC via the SDK directly.

Key changes:
- Remove cliClient, execCLI, parseSandboxName, parseSandboxState, stripANSI
- Use SDK sub-clients: Sandboxes(), Providers(), Exec(), Files()
- Implement attach I/O forwarding via InteractiveSession with terminal
  raw mode, SIGWINCH handling, and bidirectional io.Copy
- Pass initial security policy as structured SandboxPolicy type
- Map L7 allow rules in policy conversion
- Populate FromExisting provider credentials from detected env vars
- Use plaintext gRPC (TLS.Insecure) for non-TLS gateway connections
- Route stderr chunks to os.Stderr in streaming exec
- Propagate stream errors and exit codes

The git channel (ext::openshell transport) still requires the CLI binary.

Assisted-By: 🤖 Claude Code
@rhuss
rhuss force-pushed the 075-openshell-sdk-migration branch from ed89e9c to 134eee7 Compare June 30, 2026 19:34
@rhuss
rhuss merged commit 7ecbac8 into main Jun 30, 2026
10 of 12 checks passed
@rhuss
rhuss deleted the 075-openshell-sdk-migration branch June 30, 2026 19:34

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment on lines 136 to +138
if extractErr != nil {
return cfg, fmt.Errorf("extracting policy from image %s: %w\n\nTo provide the policy file manually, use the --policy flag", cfg.Image, extractErr)
log.Printf("WARNING: could not extract policy from image %s: %v", cfg.Image, extractErr)
return cfg, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚩 OCI extraction failure downgraded from hard error to warning

At cc-deck/internal/ws/openshell.go:136-138, when OCI policy extraction fails, the old code returned a hard error with a suggestion to use --policy. The new code logs a WARNING and returns (cfg, nil) — meaning sandbox creation proceeds without a policy. This is a significant behavioral change: previously, if you had an image but no explicit policy and the image couldn't be reached, creation would fail loudly. Now it silently proceeds without a policy, which could result in a sandbox with no security policy applied. The test at cc-deck/internal/ws/openshell_test.go:514-518 confirms this is intentional. Whether this is correct depends on whether the SDK/gateway has a default policy — if the gateway rejects sandbox creation without a policy, this will fail later with a less helpful error.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

2 participants