opencode-gitlab-dap 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # opencode-gitlab-dap
2
2
 
3
- An [opencode](https://opencode.ai) plugin that discovers GitLab foundational and custom agents
4
- from the [GitLab AI Catalog](https://docs.gitlab.com/ee/user/ai_catalog/) and injects them as
5
- native agents into the opencode agent picker.
3
+ An [opencode](https://opencode.ai) plugin for the [GitLab Duo Agent Platform (DAP)](https://docs.gitlab.com/user/duo_agent_platform/).
4
+ Discovers agents and flows from the GitLab AI Catalog, injects them into opencode,
5
+ and provides tools for managing and executing DAP workflows.
6
6
 
7
7
  ## Requirements
8
8
 
9
9
  - opencode with the `gitlab` provider configured and Duo Workflow (DWS) enabled
10
10
  - GitLab OAuth or PAT authentication (via `opencode-gitlab-auth` or manual config)
11
- - GitLab project with AI Catalog agents enabled
12
- - `gitlab-ai-provider` >= 6.2.0 (peer dependency, bundled with opencode's gitlab provider)
11
+ - GitLab project with AI Catalog agents/flows enabled
12
+ - `gitlab-ai-provider` >= 6.3.0 (peer dependency, bundled with opencode's gitlab provider)
13
+ - `@opencode-ai/plugin` >= 1.2.24
13
14
 
14
15
  ## Install
15
16
 
@@ -27,102 +28,152 @@ Or add to your `~/.config/opencode/opencode.json`:
27
28
 
28
29
  No further configuration needed. The plugin reads GitLab auth and model cache automatically.
29
30
 
30
- ## How it works
31
+ ## Features
31
32
 
32
- On every opencode startup the plugin:
33
+ ### Agent & Flow Discovery
33
34
 
34
- 1. Reads the GitLab auth token from `~/.local/share/opencode/auth.json`
35
- 2. Reads the already-cached GitLab workflow model from `gitlab-ai-provider`'s model cache (no extra network call)
36
- 3. Queries two GitLab GraphQL APIs in parallel:
37
- - `aiFoundationalChatAgents` — project-scoped foundational agents (Planner, Data Analyst, Security Analyst, GitLab Duo, etc.)
38
- - `aiCatalogConfiguredItems` — custom agents explicitly enabled for the project
39
- 4. Injects all discovered agents into opencode's config via the `config` hook — they appear in the `/agents` dialog and the Tab agent picker
40
- 5. Each agent runs through GitLab Duo Agent Platform (DWS), with tool actions executed locally by opencode
35
+ On startup, the plugin discovers all agents and flows enabled for your project:
41
36
 
42
- ## Agent types
37
+ - **Foundational agents** (Planner, Data Analyst, Security Analyst, etc.) via `aiFoundationalChatAgents`
38
+ - **Custom agents** and **flows** via `aiCatalogConfiguredItems`
39
+ - Agents appear in `/agents` dialog and Tab agent picker
40
+ - Flows appear in the `@` mention menu as subagents
43
41
 
44
- ### Foundational agents
42
+ ### Flow Execution via `@` Menu
45
43
 
46
- Built-in GitLab agents available based on your project's Duo Workflow license:
44
+ Type `@Flow Name` followed by your goal to execute a flow:
47
45
 
48
- | Agent | Description |
49
- | ---------------- | ------------------------------- |
50
- | GitLab Duo | General-purpose agentic chat |
51
- | Planner | Issue and project planning |
52
- | Data Analyst | GitLab data analysis (GLQL) |
53
- | Security Analyst | Security vulnerability analysis |
46
+ ```
47
+ @Fix CI/CD Pipeline fix the failing pipeline for MR !12
48
+ ```
54
49
 
55
- These are fetched via `aiFoundationalChatAgents` and are scoped to what's enabled for your project.
50
+ The plugin:
56
51
 
57
- ### Custom agents
52
+ 1. Intercepts the `@` mention via `chat.message` hook
53
+ 2. Dispatches a subagent that fetches the flow definition
54
+ 3. Gathers required inputs using available GitLab tools
55
+ 4. Executes the flow via `POST /api/v4/ai/duo_workflows/workflows`
56
+ 5. Monitors workflow status until it starts running
57
+ 6. Reports the workflow URL for tracking in GitLab UI
58
58
 
59
- User-defined agents created in the [GitLab AI Catalog](https://docs.gitlab.com/ee/user/ai_catalog/).
60
- Custom agents must be explicitly enabled for the project to appear.
59
+ ### 13 DAP Tools
61
60
 
62
- Custom agents run with their full `flowConfig` (system prompt, tools, routing) sent directly to DWS.
63
- Their sessions are linked to the correct agent page in the GitLab UI (`/automate/agents/<id>/`).
61
+ | Tool | Description |
62
+ | ------------------------------ | ------------------------------------------ |
63
+ | `gitlab_list_agents` | Search agents in the global AI Catalog |
64
+ | `gitlab_get_agent` | Get agent details by ID |
65
+ | `gitlab_list_project_agents` | List agents enabled for a project |
66
+ | `gitlab_enable_project_agent` | Enable an agent in a project |
67
+ | `gitlab_disable_project_agent` | Disable an agent in a project |
68
+ | `gitlab_list_flows` | Search flows in the global AI Catalog |
69
+ | `gitlab_get_flow` | Get flow details by ID |
70
+ | `gitlab_list_project_flows` | List flows enabled for a project |
71
+ | `gitlab_enable_project_flow` | Enable a flow in a project |
72
+ | `gitlab_disable_project_flow` | Disable a flow in a project |
73
+ | `gitlab_execute_project_flow` | Execute a flow via DWS REST API |
74
+ | `gitlab_get_flow_definition` | Get flow YAML config (inputs, components) |
75
+ | `gitlab_get_workflow_status` | Monitor workflow execution status and logs |
64
76
 
65
- ## Agent picker UX
77
+ ### Dynamic Refresh
66
78
 
67
- Agents appear in:
79
+ After enabling or disabling an agent/flow, the plugin automatically refreshes the
80
+ agent list. Restart opencode to update the `@` menu.
68
81
 
69
- - **`/agents` slash command** — shows all agents with `[GitLab Foundational Agent]` or `[GitLab Custom Agent]` labels
70
- - **Tab agent switcher** — switch the active agent for the current session
71
- - **Session header** — shows the active agent name
82
+ ### Vendored Foundational Flow Configs
72
83
 
73
- ## Self-hosted GitLab
84
+ Foundational flow definitions (from `gitlab-org/modelops/applied-ml/code-suggestions/ai-assist`)
85
+ are vendored and embedded at build time. This provides flow input schemas for
86
+ foundational flows whose configs are not available via the GitLab API.
74
87
 
75
- For OAuth-based auth, the `enterpriseUrl` from `opencode-gitlab-auth` is used automatically.
88
+ ## Agent Types
76
89
 
77
- For PAT-based auth on self-hosted instances, set:
90
+ ### Foundational Agents
78
91
 
79
- ```bash
80
- export GITLAB_INSTANCE_URL=https://your-instance.com
81
- ```
92
+ Built-in GitLab agents. Appear in `/agents` with `[GitLab Foundational Agent]` label.
82
93
 
83
- ## Logging
94
+ ### Custom Agents
84
95
 
85
- The plugin writes debug logs to:
96
+ User-defined agents from the AI Catalog. Appear in `/agents` with `[GitLab Custom Agent]` label.
86
97
 
87
- ```
88
- ~/.local/share/opencode/log/gitlab-dap.log
89
- ```
98
+ ### Flows (Foundational & Custom)
90
99
 
91
- Useful for debugging agent discovery issues.
100
+ Multi-step workflows. Appear in `@` menu with `[GitLab Flow]` label. Executed via subagent dispatch.
92
101
 
93
- ## Architecture
102
+ ### External Agents
94
103
 
95
- ```
96
- Plugin init
97
- └─ readAuth() reads ~/.local/share/opencode/auth.json
98
- └─ GitLabModelCache reads ~/.cache/opencode/gitlab-workflow-model-cache.json
99
- └─ fetchCatalogAgents()
100
- ├─ aiFoundationalChatAgents (GraphQL) foundational agents
101
- └─ aiCatalogConfiguredItems (GraphQL) → custom agents
102
- └─ aiCatalogAgentFlowConfig (GraphQL) per-agent flow config YAML
103
- └─ config hook mutates cfg.agent in-place
104
- └─ Agent.Service reads the same config object agents appear in picker
105
-
106
- Per prompt (via gitlab-ai-provider):
107
- └─ providerOptions.gitlab.workflowDefinition → DWS workflow type
108
- └─ providerOptions.gitlab.flowConfig → custom agent flow config
109
- └─ providerOptions.gitlab.aiCatalogItemVersionId → links session in GitLab UI
104
+ Third-party agents (Claude Code, Codex, etc.) are excluded — they work via CI/CD triggers,
105
+ not through opencode.
106
+
107
+ ## Flow Definition Lookup
108
+
109
+ The plugin uses a 3-tier strategy to fetch flow YAML configs:
110
+
111
+ | Tier | Source | Used For |
112
+ | ---- | ----------------------------------------------- | ------------------ |
113
+ | 1 | Vendored configs (`vendor/foundational-flows/`) | Foundational flows |
114
+ | 2 | `FlowVersion.definition` GraphQL field | Custom flows |
115
+ | 3 | `aiCatalogAgentFlowConfig` GraphQL query | Custom agents |
116
+
117
+ ## Self-Hosted GitLab
118
+
119
+ For OAuth-based auth, the `enterpriseUrl` from `opencode-gitlab-auth` is used automatically.
120
+
121
+ For PAT-based auth:
122
+
123
+ ```bash
124
+ export GITLAB_INSTANCE_URL=https://your-instance.com
110
125
  ```
111
126
 
112
127
  ## Development
113
128
 
114
129
  ```bash
115
- # Install dependencies
116
- bun install
130
+ npm install
131
+ npm test # Run tests (48 tests)
132
+ npm run build # Build (auto-runs vendor:generate)
133
+ npm run type-check
134
+ ```
135
+
136
+ ### Vendor Scripts
117
137
 
118
- # Run tests
119
- npm test
138
+ ```bash
139
+ npm run vendor:update # Fetch flow configs from gitlab.com API
140
+ npm run vendor:generate # Generate TypeScript from vendored YAMLs
141
+ npm run vendor # Both: update + generate
142
+ ```
120
143
 
121
- # Build dist
144
+ To update vendored configs when DWS releases new flow versions:
145
+
146
+ ```bash
147
+ npm run vendor
122
148
  npm run build
149
+ git add vendor/ src/generated/
150
+ git commit -m "chore: update vendored foundational flow definitions"
151
+ ```
123
152
 
124
- # Type check
125
- npm run type-check
153
+ ## Architecture
154
+
155
+ ```
156
+ Plugin init
157
+ ├─ readAuth() reads ~/.local/share/opencode/auth.json
158
+ ├─ GitLabModelCache reads model cache (no network call)
159
+ ├─ fetchCatalogAgents()
160
+ │ ├─ aiFoundationalChatAgents (GraphQL) → foundational agents
161
+ │ └─ aiCatalogConfiguredItems (GraphQL) → custom agents + flows
162
+ │ └─ aiCatalogAgentFlowConfig (GraphQL) → flow config YAML
163
+ ├─ config hook injects agents (primary) + flows (subagent)
164
+ ├─ chat.message hook intercepts @flow mentions → subagent dispatch
165
+ └─ tool hook 13 DAP tools
166
+
167
+ Flow execution (@FlowName):
168
+ ├─ chat.message hook replaces AgentPart with subagent instructions
169
+ ├─ Primary agent dispatches Task subagent
170
+ ├─ Subagent Step 1 gitlab_get_flow_definition → read inputs
171
+ ├─ Subagent Step 2 GitLab tools → gather input values
172
+ ├─ Subagent Step 3 gitlab_execute_project_flow → POST to DWS
173
+ └─ Subagent Step 4 gitlab_get_workflow_status → confirm started
174
+
175
+ Enable/disable:
176
+ └─ refreshAgents() clears cache, re-fetches, updates cfg.agent
126
177
  ```
127
178
 
128
179
  ## License