Skip to content

Commit f0e0dc8

Browse files
authored
feat: Add a MCP server under the mcp subcommand (#279)
1 parent d2f2a52 commit f0e0dc8

24 files changed

+2872
-64
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ flow complements existing CLI tools by adding multi-project organization, built-
4343
- **Flexible execution** - Serial, parallel, conditional, and interactive workflows
4444
- **Workflow generation** - Create projects and workflows from reusable templates
4545
- **Composable workflows** - Reference and chain workflows within and across projects
46+
- **Platform integrations** - GitHub Actions, AI assistants (MCP), and more
4647

4748
<p align="center"><img src="docs/_media/demo.gif" alt="flow" width="1600"/></p>
4849

cmd/internal/mcp.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package internal
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/flowexec/flow/internal/context"
7+
"github.com/flowexec/flow/internal/logger"
8+
"github.com/flowexec/flow/internal/mcp"
9+
)
10+
11+
func RegisterMCPCmd(ctx *context.Context, rootCmd *cobra.Command) {
12+
subCmd := &cobra.Command{
13+
Use: "mcp",
14+
Short: "Start Model Context Provider (MCP) server for AI assistant integration",
15+
Long: "Start a Model Context Protocol server that enables AI assistants to interact with your flow executables, " +
16+
"workspaces, and configurations through natural language. AI assistants can discover, validate, and execute " +
17+
"flow workflows, making your automation platform accessible through conversational interfaces/clients.\n\n" +
18+
"This server used stdio for transport. For more information on MCP, see https://modelcontextprotocol.io",
19+
Args: cobra.NoArgs,
20+
Run: func(cmd *cobra.Command, args []string) { mcpFunc(ctx, cmd, args) },
21+
}
22+
rootCmd.AddCommand(subCmd)
23+
}
24+
25+
func mcpFunc(_ *context.Context, _ *cobra.Command, _ []string) {
26+
server := mcp.NewServer(&mcp.FlowCLIExecutor{})
27+
if err := server.Run(); err != nil {
28+
logger.Log().FatalErr(err)
29+
}
30+
}

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ func RegisterSubCommands(ctx *context.Context, rootCmd *cobra.Command) {
8282
internal.RegisterTemplateCmd(ctx, rootCmd)
8383
internal.RegisterLogsCmd(ctx, rootCmd)
8484
internal.RegisterSyncCmd(ctx, rootCmd)
85+
internal.RegisterMCPCmd(ctx, rootCmd)
8586
}

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and cross-project composition. Go beyond task running to workflow management tha
2626
- **Cross-Project Composition**: Reference and share workflows between different projects
2727
- **Visual Workflow Browser**: Discover and run workflows with powerful filtering and search
2828
- **Flexible Configuration**: YAML-based definitions with arguments, secrets, and conditional logic
29+
- **Platform Integrations**: GitHub Actions, AI assistants (MCP), and more
2930

3031
**Ready to organize your automation?**[Install flow](installation.md)[Quick start guide](quickstart.md)
3132

docs/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ See https://flowexec.io for more information.
2323
* [flow config](flow_config.md) - Update flow configuration values.
2424
* [flow exec](flow_exec.md) - Execute any executable by reference.
2525
* [flow logs](flow_logs.md) - View execution history and logs.
26+
* [flow mcp](flow_mcp.md) - Start Model Context Provider (MCP) server for AI assistant integration
2627
* [flow secret](flow_secret.md) - Manage secrets stored in a vault.
2728
* [flow sync](flow_sync.md) - Refresh workspace cache and discover new executables.
2829
* [flow template](flow_template.md) - Manage flowfile templates.

docs/cli/flow_mcp.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## flow mcp
2+
3+
Start Model Context Provider (MCP) server for AI assistant integration
4+
5+
### Synopsis
6+
7+
Start a Model Context Protocol server that enables AI assistants to interact with your flow executables, workspaces, and configurations through natural language. AI assistants can discover, validate, and execute flow workflows, making your automation platform accessible through conversational interfaces/clients.
8+
9+
This server used stdio for transport. For more information on MCP, see https://modelcontextprotocol.io
10+
11+
```
12+
flow mcp [flags]
13+
```
14+
15+
### Options
16+
17+
```
18+
-h, --help help for mcp
19+
```
20+
21+
### Options inherited from parent commands
22+
23+
```
24+
-L, --log-level string Log verbosity level (debug, info, fatal) (default "info")
25+
--sync Sync flow cache and workspaces
26+
```
27+
28+
### SEE ALSO
29+
30+
* [flow](flow.md) - flow is a command line interface designed to make managing and running development workflows easier.
31+

docs/guide/integrations.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
# Integrations
22

3-
flow integrates with popular CI/CD platforms and containerized environments to bring your automation anywhere.
3+
flow integrates with popular CI/CD platforms, AI assistants, and containerized environments to bring your automation anywhere.
44

5-
## GitHub Actions
5+
6+
## AI Assistant Integration
7+
8+
### Model Context Protocol (MCP) <!-- {docsify-ignore} -->
9+
10+
Connect flow to AI assistants through the local Model Context Protocol server for natural language workflow management.
11+
The flow MCP server enables AI assistants to discover, understand, and execute your flow workflows through conversational interfaces.
12+
13+
#### Basic Usage <!-- {docsify-ignore} -->
14+
15+
Add the MCP server command to your favorite MCP client:
16+
17+
```shell
18+
flow mcp
19+
```
20+
21+
The server uses stdio transport and provides AI assistants with:
22+
23+
**Available Tools:**
24+
- `get_info` - Get flow information, schemas, and current context
25+
- `execute` - Execute flow workflows
26+
- `list_workspaces` - List all registered workspaces
27+
- `get_workspace` - Get details about a specific workspace
28+
- `switch_workspace` - Change the current workspace
29+
- `list_executables` - List and filter executables across workspaces
30+
- `get_executable` - Get detailed information about an executable
31+
- `get_execution_logs` - Retrieve recent execution logs
32+
- `sync_executables` - Sync workspace and executable state
33+
34+
**Available Prompts:**
35+
- `generate_executable` - Generate flow executable configurations
36+
- `generate_project_executables` - Generate complete project automation sets
37+
- `debug_executable` - Debug failing executables
38+
- `migrate_automation` - Convert existing automation to flow
39+
- `explain_flow` - Explain flow concepts and usage
40+
41+
> [!NOTE]
42+
> **Learn more about MCP**: Visit the [Model Context Protocol](https://modelcontextprotocol.io) documentation for client setup and integration details.
43+
44+
## CI/CD & Deployment <!-- {docsify-ignore} -->
45+
46+
### GitHub Actions
647

748
Execute flow workflows directly in your GitHub Actions pipelines with the official action.
849

@@ -22,7 +63,7 @@ jobs:
2263
2364
> **Complete documentation**: Visit the [Flow Execute Action](https://github.com/marketplace/actions/flow-execute) on GitHub Marketplace.
2465
25-
## Docker
66+
### Docker
2667
2768
Run flow in containerized environments for CI/CD pipelines or isolated execution.
2869

go.mod

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/flowexec/vault v0.1.2
1515
github.com/gen2brain/beeep v0.11.1
1616
github.com/jahvon/glamour v0.8.1-patch3
17+
github.com/mark3labs/mcp-go v0.36.0
1718
github.com/mattn/go-runewidth v0.0.16
1819
github.com/muesli/termenv v0.16.0
1920
github.com/onsi/ginkgo/v2 v2.23.4
@@ -41,6 +42,8 @@ require (
4142
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
4243
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
4344
github.com/aymerick/douceur v0.2.0 // indirect
45+
github.com/bahlo/generic-list-go v0.2.0 // indirect
46+
github.com/buger/jsonparser v1.1.1 // indirect
4447
github.com/catppuccin/go v0.3.0 // indirect
4548
github.com/charmbracelet/colorprofile v0.3.1 // indirect
4649
github.com/charmbracelet/huh v0.7.0 // indirect
@@ -66,8 +69,10 @@ require (
6669
github.com/gorilla/css v1.0.1 // indirect
6770
github.com/huandu/xstrings v1.5.0 // indirect
6871
github.com/inconshreveable/mousetrap v1.1.0 // indirect
72+
github.com/invopop/jsonschema v0.13.0 // indirect
6973
github.com/jackmordaunt/icns/v3 v3.0.1 // indirect
7074
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
75+
github.com/mailru/easyjson v0.7.7 // indirect
7176
github.com/mattn/go-isatty v0.0.20 // indirect
7277
github.com/mattn/go-localereader v0.0.1 // indirect
7378
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
@@ -85,15 +90,17 @@ require (
8590
github.com/sergeymakinen/go-bmp v1.0.0 // indirect
8691
github.com/sergeymakinen/go-ico v1.0.0-beta.0 // indirect
8792
github.com/shopspring/decimal v1.4.0 // indirect
88-
github.com/spf13/cast v1.7.0 // indirect
93+
github.com/spf13/cast v1.7.1 // indirect
8994
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
95+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
9096
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
97+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
9198
github.com/yuin/goldmark v1.7.4 // indirect
9299
github.com/yuin/goldmark-emoji v1.0.3 // indirect
93100
go.uber.org/automaxprocs v1.6.0 // indirect
94-
golang.org/x/net v0.40.0 // indirect
101+
golang.org/x/net v0.41.0 // indirect
95102
golang.org/x/sys v0.33.0 // indirect
96103
golang.org/x/term v0.32.0 // indirect
97104
golang.org/x/text v0.26.0 // indirect
98-
golang.org/x/tools v0.33.0 // indirect
105+
golang.org/x/tools v0.34.0 // indirect
99106
)

go.sum

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
2828
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
2929
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
3030
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
31+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
32+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
33+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
34+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
3135
github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY=
3236
github.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
3337
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
@@ -113,10 +117,13 @@ github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI
113117
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
114118
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
115119
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
120+
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
121+
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
116122
github.com/jackmordaunt/icns/v3 v3.0.1 h1:xxot6aNuGrU+lNgxz5I5H0qSeCjNKp8uTXB1j8D4S3o=
117123
github.com/jackmordaunt/icns/v3 v3.0.1/go.mod h1:5sHL59nqTd2ynTnowxB/MDQFhKNqkK8X687uKNygaSQ=
118124
github.com/jahvon/glamour v0.8.1-patch3 h1:LfyMACZavV8yxK4UsPENNQQOqafWuq4ZdLuEAP2ZLE8=
119125
github.com/jahvon/glamour v0.8.1-patch3/go.mod h1:30MVJwG3rcEHrN277NrA4DKzndSL9lBtEmpcfOygwCQ=
126+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
120127
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
121128
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
122129
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -125,6 +132,10 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
125132
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
126133
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
127134
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
135+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
136+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
137+
github.com/mark3labs/mcp-go v0.36.0 h1:rIZaijrRYPeSbJG8/qNDe0hWlGrCJ7FWHNMz2SQpTis=
138+
github.com/mark3labs/mcp-go v0.36.0/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
128139
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
129140
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
130141
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
@@ -180,8 +191,8 @@ github.com/sergeymakinen/go-ico v1.0.0-beta.0 h1:m5qKH7uPKLdrygMWxbamVn+tl2HfiA3
180191
github.com/sergeymakinen/go-ico v1.0.0-beta.0/go.mod h1:wQ47mTczswBO5F0NoDt7O0IXgnV4Xy3ojrroMQzyhUk=
181192
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
182193
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
183-
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
184-
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
194+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
195+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
185196
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
186197
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
187198
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
@@ -196,8 +207,12 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
196207
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
197208
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
198209
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
210+
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
211+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
199212
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
200213
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
214+
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
215+
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
201216
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
202217
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
203218
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
@@ -213,8 +228,8 @@ golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
213228
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
214229
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI=
215230
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ=
216-
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
217-
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
231+
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
232+
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
218233
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
219234
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
220235
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -226,8 +241,8 @@ golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
226241
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
227242
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
228243
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
229-
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
230-
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
244+
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
245+
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
231246
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
232247
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
233248
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/context/context.go

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"runtime"
9-
"strings"
108

119
"github.com/flowexec/tuikit"
1210
"github.com/flowexec/tuikit/themes"
@@ -67,13 +65,7 @@ func NewContext(ctx context.Context, stdIn, stdOut *os.File) *Context {
6765
}
6866

6967
workspaceCache := cache.NewWorkspaceCache()
70-
if workspaceCache == nil {
71-
panic("workspace cache initialization error")
72-
}
7368
executableCache := cache.NewExecutableCache(workspaceCache)
74-
if executableCache == nil {
75-
panic("executable cache initialization error")
76-
}
7769

7870
ctxx, cancel := context.WithCancel(ctx)
7971
c := &Context{
@@ -189,43 +181,11 @@ func ExpandRef(ctx *Context, ref executable.Ref) executable.Ref {
189181
}
190182

191183
func currentWorkspace(cfg *config.Config) (*workspace.Workspace, error) {
192-
var ws, wsPath string
193-
mode := cfg.WorkspaceMode
194-
195-
switch mode {
196-
case config.ConfigWorkspaceModeDynamic:
197-
wd, err := os.Getwd()
198-
if err != nil {
199-
return nil, err
200-
}
201-
if runtime.GOOS == "darwin" {
202-
// On macOS, paths that start with /tmp (and some other system directories)
203-
// are actually symbolic links to paths under /private. The OS may return
204-
// either form of the path - e.g., both "/tmp/file" and "/private/tmp/file"
205-
// refer to the same location. We strip the "/private" prefix for consistent
206-
// path comparison, while preserving the original paths for filesystem operations.
207-
wd = strings.TrimPrefix(wd, "/private")
208-
}
209-
210-
for wsName, path := range cfg.Workspaces {
211-
rel, err := filepath.Rel(filepath.Clean(path), filepath.Clean(wd))
212-
if err != nil {
213-
return nil, err
214-
}
215-
if !strings.HasPrefix(rel, "..") {
216-
ws = wsName
217-
wsPath = path
218-
break
219-
}
220-
}
221-
fallthrough
222-
case config.ConfigWorkspaceModeFixed:
223-
if ws != "" && wsPath != "" {
224-
break
225-
}
226-
ws = cfg.CurrentWorkspace
227-
wsPath = cfg.Workspaces[ws]
184+
ws, err := cfg.CurrentWorkspaceName()
185+
if err != nil {
186+
return nil, err
228187
}
188+
wsPath := cfg.Workspaces[ws]
229189
if ws == "" || wsPath == "" {
230190
return nil, fmt.Errorf("current workspace not found")
231191
}

0 commit comments

Comments
 (0)