Skip to content

Commit d689a0d

Browse files
authored
Drop workspace provider and sandbox indirection. Use Filer for IO. (#3975)
## Changes <!-- Brief summary of your changes that is easy to understand --> ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> ## Tests <!-- How have you tested the changes? --> <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent ecc9d54 commit d689a0d

File tree

27 files changed

+132
-2618
lines changed

27 files changed

+132
-2618
lines changed

experimental/apps-mcp/lib/errors/errors.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ const (
2929
CodeConfigMissing = -32101
3030
CodeConfigWorkDir = -32102
3131

32-
// Sandbox errors (-32110 to -32119)
33-
CodeSandboxFailed = -32110
34-
CodeSandboxNotFound = -32111
35-
CodeSandboxExec = -32112
36-
CodeSandboxDocker = -32113
37-
3832
// Databricks errors (-32120 to -32129)
3933
CodeDatabricksAuth = -32120
4034
CodeDatabricksQuery = -32121
@@ -186,20 +180,6 @@ func ConfigWorkDir(message string) *Error {
186180
return NewWithCode(CodeConfigWorkDir, message)
187181
}
188182

189-
// Sandbox error helpers
190-
191-
// SandboxFailed creates an error for sandbox operation failures.
192-
func SandboxFailed(operation, message string) *Error {
193-
err := NewWithCode(CodeSandboxFailed, fmt.Sprintf("sandbox %s failed: %s", operation, message))
194-
return err.WithDetail("operation", operation)
195-
}
196-
197-
// SandboxDocker creates an error for Docker-related issues.
198-
func SandboxDocker(message string) *Error {
199-
err := NewWithCode(CodeSandboxDocker, message)
200-
return WithSuggestion(err, "Ensure Docker is running: docker info")
201-
}
202-
203183
// Databricks error helpers
204184

205185
// DatabricksAuth creates an error for authentication failures.

experimental/apps-mcp/lib/fileutil/atomic.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

experimental/apps-mcp/lib/fileutil/atomic_test.go

Lines changed: 0 additions & 133 deletions
This file was deleted.

experimental/apps-mcp/lib/prompts/initialization_message.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Your session in Databricks MCP has been successfully initialized. Here are the g
33
## Project State Management:
44
This project uses a state file (`.edda_state`) managed by edda MCP to enforce the correct workflow order:
55
1. **Scaffolded**: `scaffold_data_app` creates project structure from template (starts in this state)
6-
2. **Validated**: `validate_data_app` runs build + tests in sandbox, computes BLAKE3 checksum of package.json and all core source files
6+
2. **Validated**: `validate_data_app` runs build + tests, computes BLAKE3 checksum of package.json and all core source files
77
3. **Deployed**: `deploy_databricks_app` deploys to Databricks Apps, but ONLY if checksum hasn't changed since validation
88

99
Re-validation is allowed (Deployed → Validated) to update the checksum after intentional changes. The databricks_mcp tools enforce these state transitions and prevent invalid state changes.

experimental/apps-mcp/lib/providers/deployment/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (p *Provider) deployDatabricksApp(ctx context.Context, args *DeployDatabric
129129
}, nil
130130
}
131131

132-
projectState, err := io.LoadState(workPath)
132+
projectState, err := io.LoadState(ctx, workPath)
133133
if err != nil {
134134
return &DeployResult{
135135
Success: false,
@@ -155,7 +155,7 @@ func (p *Provider) deployDatabricksApp(ctx context.Context, args *DeployDatabric
155155
}, nil
156156
}
157157

158-
checksumValid, err := io.VerifyChecksum(workPath, expectedChecksum)
158+
checksumValid, err := io.VerifyChecksum(ctx, workPath, expectedChecksum)
159159
if err != nil {
160160
return &DeployResult{
161161
Success: false,
@@ -248,7 +248,7 @@ func (p *Provider) deployDatabricksApp(ctx context.Context, args *DeployDatabric
248248
}, nil
249249
}
250250

251-
if err := io.SaveState(workPath, deployedState); err != nil {
251+
if err := io.SaveState(ctx, workPath, deployedState); err != nil {
252252
log.Warnf(ctx, "Failed to save deployed state: error=%v", err)
253253
}
254254

experimental/apps-mcp/lib/providers/io/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (p *Provider) RegisterTools(server *mcpsdk.Server) error {
9090
mcpsdk.AddTool(server,
9191
&mcpsdk.Tool{
9292
Name: "validate_data_app",
93-
Description: "Validate a project by copying files to a sandbox and running validation checks. Project should be scaffolded first. Returns validation result with success status and details.",
93+
Description: "Validate a project by running validation checks. Project should be scaffolded first. Returns validation result with success status and details.",
9494
},
9595
func(ctx context.Context, req *mcpsdk.CallToolRequest, args ValidateInput) (*mcpsdk.CallToolResult, any, error) {
9696
log.Debugf(ctx, "validate_data_app called: work_dir=%s", args.WorkDir)

experimental/apps-mcp/lib/providers/io/scaffold.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
7-
"os"
8+
"io/fs"
89
"path/filepath"
910

1011
"github.com/databricks/cli/experimental/apps-mcp/lib/templates"
12+
"github.com/databricks/cli/libs/filer"
1113
"github.com/databricks/cli/libs/log"
1214
)
1315

@@ -33,14 +35,19 @@ func (p *Provider) Scaffold(ctx context.Context, args *ScaffoldArgs) (*ScaffoldR
3335
return nil, fmt.Errorf("invalid work directory: %w", err)
3436
}
3537

38+
f, err := filer.NewLocalClient(workDir)
39+
if err != nil {
40+
return nil, fmt.Errorf("failed to create filer: %w", err)
41+
}
42+
3643
// Check if directory exists
37-
if stat, err := os.Stat(workDir); err == nil {
44+
if stat, err := f.Stat(ctx, "."); err == nil {
3845
if !stat.IsDir() {
3946
return nil, errors.New("work_dir exists but is not a directory")
4047
}
4148

4249
// Check if empty
43-
entries, err := os.ReadDir(workDir)
50+
entries, err := f.ReadDir(ctx, ".")
4451
if err != nil {
4552
return nil, err
4653
}
@@ -51,14 +58,20 @@ func (p *Provider) Scaffold(ctx context.Context, args *ScaffoldArgs) (*ScaffoldR
5158

5259
// Clear directory if force_rewrite
5360
if args.ForceRewrite {
54-
if err := os.RemoveAll(workDir); err != nil {
55-
return nil, fmt.Errorf("failed to clear directory: %w", err)
61+
for _, entry := range entries {
62+
if err := f.Delete(ctx, entry.Name(), filer.DeleteRecursively); err != nil {
63+
return nil, fmt.Errorf("failed to delete %s: %w", entry.Name(), err)
64+
}
5665
}
5766
}
67+
} else if !errors.Is(err, fs.ErrNotExist) {
68+
// Some other error
69+
// filer.FileDoesNotExistError implements Is(fs.ErrNotExist)
70+
return nil, fmt.Errorf("failed to check work directory: %w", err)
5871
}
5972

6073
// Create directory
61-
if err := os.MkdirAll(workDir, 0o755); err != nil {
74+
if err := f.Mkdir(ctx, "."); err != nil {
6275
return nil, fmt.Errorf("failed to create directory: %w", err)
6376
}
6477

@@ -72,15 +85,8 @@ func (p *Provider) Scaffold(ctx context.Context, args *ScaffoldArgs) (*ScaffoldR
7285
// Copy files
7386
filesCopied := 0
7487
for path, content := range files {
75-
targetPath := filepath.Join(workDir, path)
76-
77-
// Create parent directories
78-
if err := os.MkdirAll(filepath.Dir(targetPath), 0o755); err != nil {
79-
return nil, fmt.Errorf("failed to create directory for %s: %w", path, err)
80-
}
81-
82-
// Write file
83-
if err := os.WriteFile(targetPath, []byte(content), 0o644); err != nil {
88+
// filer.Write handles creating parent directories if requested
89+
if err := f.Write(ctx, path, bytes.NewReader([]byte(content)), filer.CreateParentDirectories); err != nil {
8490
return nil, fmt.Errorf("failed to write %s: %w", path, err)
8591
}
8692

0 commit comments

Comments
 (0)