From a810d795d538a1b16c9dfbbd5e12e56b433cec01 Mon Sep 17 00:00:00 2001 From: Vladimir Glafirov Date: Tue, 13 Jan 2026 23:39:45 +0100 Subject: [PATCH 1/2] docs: update GitLab integration to use GitLab Duo provider Replace Anthropic provider with native GitLab Duo integration: - Configure GitLab Duo provider with CI_JOB_TOKEN authentication - Add @gitlab/opencode-gitlab-plugin for GitLab API tools - Remove all custom CI/CD variables (ANTHROPIC_API_KEY, GITLAB_HOST, GITLAB_TOKEN_OPENCODE) - Use GitLab predefined variables (CI_JOB_TOKEN, CI_SERVER_HOST, CI_PROJECT_PATH) - Remove glab CLI dependency - plugin provides direct API access - Add 'Using GitLab Tools' section with practical examples - Update documentation link to opencode-gitlab-plugin - Simplify setup - zero custom configuration required The configuration now uses only GitLab's built-in CI/CD variables and provides native integration with GitLab Duo for AI-powered assistance. --- packages/web/src/content/docs/gitlab.mdx | 106 ++++++++++++++++------- 1 file changed, 74 insertions(+), 32 deletions(-) diff --git a/packages/web/src/content/docs/gitlab.mdx b/packages/web/src/content/docs/gitlab.mdx index 6358019a4a1..4997c0c4d1c 100644 --- a/packages/web/src/content/docs/gitlab.mdx +++ b/packages/web/src/content/docs/gitlab.mdx @@ -3,9 +3,7 @@ title: GitLab description: Use OpenCode in GitLab issues and merge requests. --- -OpenCode integrates with your GitLab workflow through your GitLab CI/CD pipeline or with GitLab Duo. - -In both cases, OpenCode will run on your GitLab runners. +OpenCode integrates with your GitLab workflow through CI/CD pipelines. OpenCode runs on your GitLab runners and uses GitLab Duo for AI-powered assistance. --- @@ -62,51 +60,74 @@ Mention `@opencode` in a comment, and OpenCode will execute tasks within your Gi ### Setup -OpenCode runs in your GitLab CI/CD pipeline, here's what you'll need to set it up: +OpenCode runs in your GitLab CI/CD pipeline using the GitLab Duo provider for AI models. :::tip Check out the [**GitLab docs**](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/) for up to date instructions. ::: -1. Configure your GitLab environment -2. Set up CI/CD -3. Get an AI model provider API key +#### GitLab Duo Provider + +OpenCode uses GitLab Duo's agentic chat models powered by Anthropic Claude: + +- **duo-chat-haiku-4-5** - Fast responses for quick tasks +- **duo-chat-sonnet-4-5** - Balanced performance (recommended) +- **duo-chat-opus-4-5** - Most capable for complex analysis + +No separate API key needed - OpenCode uses your GitLab token to access GitLab Duo. + +The configuration includes the **GitLab plugin** which provides comprehensive repository management tools: + +- Merge request operations (create, review, approve, merge) +- Issue management (create, update, comment, close) +- Pipeline and CI/CD operations (view jobs, retry, artifacts) +- Repository operations (commits, branches, files) + +--- + +#### Setup Steps + +1. Ensure your project has access to [GitLab Duo](https://docs.gitlab.com/ee/user/ai_features/) +2. Configure your GitLab environment +3. Set up CI/CD 4. Create a service account -5. Configure CI/CD variables -6. Create a flow config file, here's an example: +5. Create a flow config file using the example below -
+:::note +OpenCode uses GitLab's predefined CI/CD variables (`CI_JOB_TOKEN`, `CI_SERVER_HOST`, `CI_PROJECT_PATH`) - no additional configuration or API keys are required. +::: - Flow configuration +
+ Flow configuration example ```yaml image: node:22-slim commands: - echo "Installing opencode" - npm install --global opencode-ai - - echo "Installing glab" - - export GITLAB_TOKEN=$GITLAB_TOKEN_OPENCODE - - apt-get update --quiet && apt-get install --yes curl wget gpg git && rm --recursive --force /var/lib/apt/lists/* - - curl --silent --show-error --location "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash - - apt-get install --yes glab - - echo "Configuring glab" - - echo $GITLAB_HOST - - echo "Creating OpenCode auth configuration" + - echo "Installing git" + - apt-get update --quiet && apt-get install --yes git && rm --recursive --force /var/lib/apt/lists/* + - echo "Creating OpenCode configuration" - mkdir --parents ~/.local/share/opencode - | cat > ~/.local/share/opencode/auth.json << EOF { - "anthropic": { + "gitlab": { "type": "api", - "key": "$ANTHROPIC_API_KEY" + "key": "$CI_JOB_TOKEN" } } EOF + - | + cat > opencode.json << EOF + { + "model": "gitlab/duo-chat-sonnet-4-5", + "plugin": ["@gitlab/opencode-gitlab-plugin"] + } + EOF - echo "Configuring git" - git config --global user.email "opencode@gitlab.com" - git config --global user.name "OpenCode" - - echo "Testing glab" - - glab issue list - echo "Running OpenCode" - | opencode run " @@ -120,9 +141,8 @@ Check out the [**GitLab docs**](https://docs.gitlab.com/user/duo_agent_platform/ Be thorough in your analysis and provide clear explanations. - Please use the glab CLI to access data from GitLab. The glab CLI has already been authenticated. You can run the corresponding commands. - - If you are asked to summarize an MR or issue or asked to provide more information then please post back a note to the MR/Issue so that the user can see it. + Use the built-in GitLab tools to interact with the repository (merge requests, issues, pipelines, etc.). + If you are asked to summarize an MR or issue, add a comment with your findings directly to it. You don't need to commit or push up changes, those will be done automatically based on the file changes you make. " @@ -138,21 +158,43 @@ Check out the [**GitLab docs**](https://docs.gitlab.com/user/duo_agent_platform/ echo "Committing changes to branch: $CI_WORKLOAD_REF" git commit --message "Codex changes" echo "Pushing changes up to $CI_WORKLOAD_REF" - git push https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/gl-demo-ultimate-dev-ai-epic-17570/test-java-project.git $CI_WORKLOAD_REF + git push https://gitlab-ci-token:$CI_JOB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git $CI_WORKLOAD_REF echo "Changes successfully pushed" fi else echo "No git changes detected, skipping push" fi - variables: - - ANTHROPIC_API_KEY - - GITLAB_TOKEN_OPENCODE - - GITLAB_HOST ```
-You can refer to the [GitLab CLI agents docs](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/) for detailed instructions. +For more information about the GitLab plugin and available tools, see the [opencode-gitlab-plugin documentation](https://gitlab.com/gitlab-org/editor-extensions/opencode-gitlab-plugin). + +--- + +#### Using GitLab Tools + +With the GitLab plugin enabled, OpenCode can directly interact with your GitLab instance using built-in tools. You don't need to use the `glab` CLI - OpenCode will automatically use the appropriate GitLab API tools. + +Here are some examples of what you can ask OpenCode to do: + +- **Work with merge requests**: "Get the details of merge request !123", "List all open merge requests", "Approve this merge request" +- **Manage issues**: "Create an issue for the bug in authentication.js", "List all open issues with label 'bug'", "Add a comment to issue #456" +- **Check pipelines**: "Show me the latest pipeline status", "Get the failed jobs from pipeline 789", "Retry the failed jobs" +- **Repository operations**: "Get the content of src/config.js", "List all branches", "Show me the last 10 commits" + +**Example prompt:** + +``` +Review merge request !42 and check if: +1. All tests are passing in the pipeline +2. There are any security concerns +3. The code follows our style guidelines + +Then add a comment with your findings. +``` + +OpenCode will automatically use the appropriate tools (`gitlab_get_merge_request`, `gitlab_get_mr_pipelines`, `gitlab_create_mr_note`) to complete this task. --- From 3c56e463fba908a846d4c00d94eb67326ce479ea Mon Sep 17 00:00:00 2001 From: Vladimir Glafirov Date: Wed, 14 Jan 2026 11:14:23 +0100 Subject: [PATCH 2/2] fix: let gitlab-ai-provider map anthropic model --- bun.lock | 4 ++-- packages/opencode/package.json | 2 +- packages/opencode/src/provider/provider.ts | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/bun.lock b/bun.lock index bdaef9db3f0..225baa53a91 100644 --- a/bun.lock +++ b/bun.lock @@ -276,7 +276,7 @@ "@ai-sdk/vercel": "1.0.31", "@ai-sdk/xai": "2.0.51", "@clack/prompts": "1.0.0-alpha.1", - "@gitlab/gitlab-ai-provider": "3.1.0", + "@gitlab/gitlab-ai-provider": "3.1.1", "@hono/standard-validator": "0.1.5", "@hono/zod-validator": "catalog:", "@modelcontextprotocol/sdk": "1.25.2", @@ -911,7 +911,7 @@ "@fontsource/inter": ["@fontsource/inter@5.2.8", "", {}, "sha512-P6r5WnJoKiNVV+zvW2xM13gNdFhAEpQ9dQJHt3naLvfg+LkF2ldgSLiF4T41lf1SQCM9QmkqPTn4TH568IRagg=="], - "@gitlab/gitlab-ai-provider": ["@gitlab/gitlab-ai-provider@3.1.0", "", { "dependencies": { "@anthropic-ai/sdk": "^0.71.0", "@anycable/core": "^0.9.2", "graphql-request": "^6.1.0", "isomorphic-ws": "^5.0.0", "socket.io-client": "^4.8.1", "vscode-jsonrpc": "^8.2.1", "zod": "^3.25.76" }, "peerDependencies": { "@ai-sdk/provider": ">=2.0.0", "@ai-sdk/provider-utils": ">=3.0.0" } }, "sha512-S0MVXsogrwbOboA/8L0CY5sBXg2HrrO8gdeUeHd9yLZDPsggFD0FzcSuzO5vBO6geUOpruRa8Hqrbb6WWu7Frw=="], + "@gitlab/gitlab-ai-provider": ["@gitlab/gitlab-ai-provider@3.1.1", "", { "dependencies": { "@anthropic-ai/sdk": "^0.71.0", "@anycable/core": "^0.9.2", "graphql-request": "^6.1.0", "isomorphic-ws": "^5.0.0", "socket.io-client": "^4.8.1", "vscode-jsonrpc": "^8.2.1", "zod": "^3.25.76" }, "peerDependencies": { "@ai-sdk/provider": ">=2.0.0", "@ai-sdk/provider-utils": ">=3.0.0" } }, "sha512-7AtFrCflq2NzC99bj7YaqbQDCZyaScM1+L4ujllV5syiRTFE239Uhnd/yEkPXa7sUAnNRfN3CWusCkQ2zK/q9g=="], "@graphql-typed-document-node/core": ["@graphql-typed-document-node/core@3.2.0", "", { "peerDependencies": { "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" } }, "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ=="], diff --git a/packages/opencode/package.json b/packages/opencode/package.json index cfe68f01097..4eb3a9af490 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -70,7 +70,7 @@ "@ai-sdk/vercel": "1.0.31", "@ai-sdk/xai": "2.0.51", "@clack/prompts": "1.0.0-alpha.1", - "@gitlab/gitlab-ai-provider": "3.1.0", + "@gitlab/gitlab-ai-provider": "3.1.1", "@hono/standard-validator": "0.1.5", "@hono/zod-validator": "catalog:", "@modelcontextprotocol/sdk": "1.25.2", diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index d87e0db2e66..5374d76ee2e 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -416,10 +416,8 @@ export namespace Provider { ...(providerConfig?.options?.featureFlags || {}), }, }, - async getModel(sdk: ReturnType, modelID: string, options?: { anthropicModel?: string }) { - const anthropicModel = options?.anthropicModel + async getModel(sdk: ReturnType, modelID: string) { return sdk.agenticChat(modelID, { - anthropicModel, featureFlags: { duo_agent_platform_agentic_chat: true, duo_agent_platform: true,