duoops 0.1.6 → 0.1.9
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 +0 -55
- package/dist/commands/ask.d.ts +4 -1
- package/dist/commands/ask.js +35 -4
- package/dist/commands/config.d.ts +10 -0
- package/dist/commands/config.js +47 -0
- package/dist/commands/portal.js +7 -5
- package/dist/lib/ai/agent.d.ts +6 -2
- package/dist/lib/ai/agent.js +50 -57
- package/dist/lib/ai/prompt-library.d.ts +13 -0
- package/dist/lib/ai/prompt-library.js +335 -0
- package/dist/lib/ai/tools/gitlab.d.ts +4 -0
- package/dist/lib/ai/tools/gitlab.js +162 -11
- package/dist/lib/ai/tools/measure.js +7 -3
- package/dist/lib/ai/tools/types.d.ts +3 -0
- package/dist/lib/ai/tools/types.js +1 -0
- package/dist/portal/assets/MetricsDashboard-Bnj-jtu6.js +27 -0
- package/dist/portal/assets/index-B1SGDQNX.css +1 -0
- package/dist/portal/assets/index-Bk8OVV7a.js +106 -0
- package/dist/portal/assets/{index-B6bzT1Vv.js → index-C54ZhVUo.js} +1 -1
- package/dist/portal/index.html +2 -2
- package/oclif.manifest.json +47 -3
- package/package.json +1 -1
- package/templates/duoops-measure-component.yml +7 -4
- package/dist/portal/assets/MetricsDashboard-DIsoz4Sl.js +0 -71
- package/dist/portal/assets/index-BP8FwWqA.css +0 -1
- package/dist/portal/assets/index-DkVG3jel.js +0 -70
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitLab Duo Prompt Library
|
|
3
|
+
* Source: https://about.gitlab.com/gitlab-duo/prompt-library/
|
|
4
|
+
*/
|
|
5
|
+
export const PROMPT_LIBRARY = [
|
|
6
|
+
{
|
|
7
|
+
category: 'Code Understanding',
|
|
8
|
+
complexity: 'Beginner',
|
|
9
|
+
description: 'Analyze code dependencies and potential impacts before modifying unfamiliar code sections. Essential for preventing breaking changes during refactoring.',
|
|
10
|
+
title: 'Understand Code Before Making Changes',
|
|
11
|
+
tool: 'GitLab Duo',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
category: 'Code Understanding',
|
|
15
|
+
complexity: 'Beginner',
|
|
16
|
+
description: 'Quickly locate all call sites for any method or function across your entire codebase. Invaluable when planning refactoring work.',
|
|
17
|
+
title: 'Trace Function Usage Across Codebase',
|
|
18
|
+
tool: 'GitLab Duo',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
category: 'Code Understanding',
|
|
22
|
+
complexity: 'Beginner',
|
|
23
|
+
description: 'Get clear explanations of complex code or merge requests without manual investigation. Perfect for code reviews and onboarding.',
|
|
24
|
+
title: 'Explain Unfamiliar Code or MR',
|
|
25
|
+
tool: 'GitLab Duo',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
category: 'Code Understanding',
|
|
29
|
+
complexity: 'Beginner',
|
|
30
|
+
description: 'Navigate call graphs to understand how functions interconnect throughout your codebase. Reveals hidden dependencies instantly.',
|
|
31
|
+
title: 'Find Where Functions Are Called',
|
|
32
|
+
tool: 'GitLab Duo',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
category: 'Code Understanding',
|
|
36
|
+
complexity: 'Beginner',
|
|
37
|
+
description: 'Catch up on long-running MRs or issues by getting a summary of key decisions, changes, and action items.',
|
|
38
|
+
title: 'Summarize Recent Changes to MR/Issue',
|
|
39
|
+
tool: 'GitLab Duo',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
category: 'Code Understanding',
|
|
43
|
+
complexity: 'Beginner',
|
|
44
|
+
description: 'Find relevant code sections in unfamiliar projects without knowing the structure. Accelerates exploration of new codebases.',
|
|
45
|
+
title: 'Navigate Large Codebase Quickly',
|
|
46
|
+
tool: 'GitLab Duo',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
category: 'Code Understanding',
|
|
50
|
+
complexity: 'Advanced',
|
|
51
|
+
description: 'Map out class hierarchies and identify which methods are overridden. Critical for understanding object-oriented architectures.',
|
|
52
|
+
title: 'Understand Class Hierarchy and Inheritance',
|
|
53
|
+
tool: 'GitLab Duo',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
category: 'Code Understanding',
|
|
57
|
+
complexity: 'Beginner',
|
|
58
|
+
description: 'Discover how specific patterns are implemented in your existing codebase. Learn from your team\'s established conventions.',
|
|
59
|
+
title: 'Find Code Examples of Patterns',
|
|
60
|
+
tool: 'GitLab Duo',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
category: 'Code Understanding',
|
|
64
|
+
complexity: 'Advanced',
|
|
65
|
+
description: 'Follow data as it moves through multiple components, tracking each transformation step. Essential for debugging data issues.',
|
|
66
|
+
title: 'Understand Data Flow Through System',
|
|
67
|
+
tool: 'GitLab Duo',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
category: 'Code Understanding',
|
|
71
|
+
complexity: 'Advanced',
|
|
72
|
+
description: 'Understand complex database schemas, relationships, and optimization opportunities. Identify performance bottlenecks in your data model.',
|
|
73
|
+
title: 'Analyze Database Schema and Relationships',
|
|
74
|
+
tool: 'GitLab Duo',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
category: 'Code Understanding',
|
|
78
|
+
complexity: 'Beginner',
|
|
79
|
+
description: 'Visualize how different components depend on each other. Understand the blast radius of potential changes.',
|
|
80
|
+
title: 'Map Component Dependencies',
|
|
81
|
+
tool: 'GitLab Duo',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
category: 'Code Understanding',
|
|
85
|
+
complexity: 'Beginner',
|
|
86
|
+
description: 'Decode configuration files and environment setup requirements. Speeds up onboarding and project switching.',
|
|
87
|
+
title: 'Understand Configuration and Environment Setup',
|
|
88
|
+
tool: 'GitLab Duo',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
category: 'Code Understanding',
|
|
92
|
+
complexity: 'Beginner',
|
|
93
|
+
description: 'Document how your system integrates with internal and external APIs. Prevents breaking changes in integrations.',
|
|
94
|
+
title: 'Analyze API Contracts and Integrations',
|
|
95
|
+
tool: 'GitLab Duo',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
category: 'Code Understanding',
|
|
99
|
+
complexity: 'Beginner',
|
|
100
|
+
description: 'Find similar code patterns that could be consolidated into shared utilities. Reduce maintenance burden through DRY principles.',
|
|
101
|
+
title: 'Identify Code Duplication Opportunities',
|
|
102
|
+
tool: 'GitLab Duo',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
category: 'Code Understanding',
|
|
106
|
+
complexity: 'Beginner',
|
|
107
|
+
description: 'Learn how errors are handled throughout your application. Identify inconsistencies and gaps in error handling.',
|
|
108
|
+
title: 'Understand Error Handling Patterns',
|
|
109
|
+
tool: 'GitLab Duo',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
category: 'Code Understanding',
|
|
113
|
+
complexity: 'Beginner',
|
|
114
|
+
description: 'Map authentication flows and permission checks across your system. Essential for security audits and debugging access issues.',
|
|
115
|
+
title: 'Trace Authentication and Authorization Flow',
|
|
116
|
+
tool: 'GitLab Duo',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
category: 'Code Understanding',
|
|
120
|
+
complexity: 'Beginner',
|
|
121
|
+
description: 'Understand asynchronous code, promises, and concurrent operations. Identify potential race conditions before they cause bugs.',
|
|
122
|
+
title: 'Understand Async Operations and Concurrency',
|
|
123
|
+
tool: 'GitLab Duo',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
category: 'Code Review',
|
|
127
|
+
complexity: 'Beginner',
|
|
128
|
+
description: 'Catch logical errors and edge cases that syntax checkers miss. Go beyond linting to find real bugs.',
|
|
129
|
+
title: 'Review MR for Logical Errors',
|
|
130
|
+
tool: 'GitLab Duo',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
category: 'Code Review',
|
|
134
|
+
complexity: 'Beginner',
|
|
135
|
+
description: 'Receive actionable feedback on code quality, performance, and maintainability. Elevate your team\'s coding standards.',
|
|
136
|
+
title: 'Suggest Code Improvements in MR',
|
|
137
|
+
tool: 'GitLab Duo',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
category: 'Code Review',
|
|
141
|
+
complexity: 'Beginner',
|
|
142
|
+
description: 'Ensure code follows team conventions and style guides. Consistent enforcement without tedious manual checks.',
|
|
143
|
+
title: 'Check MR Against Coding Standards',
|
|
144
|
+
tool: 'GitLab Duo',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
category: 'Code Review',
|
|
148
|
+
complexity: 'Intermediate',
|
|
149
|
+
description: 'Identify security vulnerabilities during code review. Catch SQL injection, XSS, and other risks early.',
|
|
150
|
+
title: 'Identify Security Issues in MR',
|
|
151
|
+
tool: 'GitLab Duo',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
category: 'Code Review',
|
|
155
|
+
complexity: 'Beginner',
|
|
156
|
+
description: 'Evaluate if an MR includes adequate tests for new functionality. Identify gaps before they reach production.',
|
|
157
|
+
title: 'Assess MR Test Coverage',
|
|
158
|
+
tool: 'GitLab Duo',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
category: 'Code Review',
|
|
162
|
+
complexity: 'Beginner',
|
|
163
|
+
description: 'Assess how proposed changes will affect system performance. Catch complexity issues and bottlenecks early.',
|
|
164
|
+
title: 'Explain MR Impact on Performance',
|
|
165
|
+
tool: 'GitLab Duo',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
category: 'Code Review',
|
|
169
|
+
complexity: 'Beginner',
|
|
170
|
+
description: 'Auto-generate comprehensive MR descriptions including what changed, testing steps, and related issues.',
|
|
171
|
+
title: 'Generate MR Description',
|
|
172
|
+
tool: 'GitLab Duo',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
category: 'Code Review',
|
|
176
|
+
complexity: 'Beginner',
|
|
177
|
+
description: 'Detect if changes break existing APIs, contracts, or functionality. Prevent downstream breakages.',
|
|
178
|
+
title: 'Identify Breaking Changes in MR',
|
|
179
|
+
tool: 'GitLab Duo',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
category: 'Documentation',
|
|
183
|
+
complexity: 'Beginner',
|
|
184
|
+
description: 'Automatically compile release notes from merged MRs. Group changes by type: features, fixes, breaking changes.',
|
|
185
|
+
title: 'Generate Release Notes from MRs',
|
|
186
|
+
tool: 'GitLab Duo',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
category: 'Documentation',
|
|
190
|
+
complexity: 'Beginner',
|
|
191
|
+
description: 'Convert support tickets into properly formatted, labeled issues. Streamline your support-to-development workflow.',
|
|
192
|
+
title: 'Create Issue from Support Ticket',
|
|
193
|
+
tool: 'GitLab Duo',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
category: 'Code Quality',
|
|
197
|
+
complexity: 'Beginner',
|
|
198
|
+
description: 'Improve code readability with better names, simplified logic, and clearer structure. Make code self-documenting.',
|
|
199
|
+
title: 'Refactor for Better Readability',
|
|
200
|
+
tool: 'GitLab Duo',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
category: 'Code Quality',
|
|
204
|
+
complexity: 'Beginner',
|
|
205
|
+
description: 'Update legacy code to use current language features and best practices. Modernize without breaking functionality.',
|
|
206
|
+
title: 'Modernize Legacy Code',
|
|
207
|
+
tool: 'GitLab Duo',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
category: 'Code Quality',
|
|
211
|
+
complexity: 'Advanced',
|
|
212
|
+
description: 'Break down complex functions into testable, maintainable components. Reduce cognitive load for future developers.',
|
|
213
|
+
title: 'Reduce Code Complexity',
|
|
214
|
+
tool: 'GitLab Duo',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
category: 'Code Quality',
|
|
218
|
+
complexity: 'Beginner',
|
|
219
|
+
description: 'Find and safely remove unused code, deprecated methods, and commented-out blocks. Keep your codebase lean.',
|
|
220
|
+
title: 'Remove Dead Code',
|
|
221
|
+
tool: 'GitLab Duo',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
category: 'Code Quality',
|
|
225
|
+
complexity: 'Beginner',
|
|
226
|
+
description: 'Improve algorithmic efficiency while maintaining correctness. Optimize hot paths for performance gains.',
|
|
227
|
+
title: 'Optimize Algorithm Performance',
|
|
228
|
+
tool: 'GitLab Duo',
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
category: 'Code Quality',
|
|
232
|
+
complexity: 'Advanced',
|
|
233
|
+
description: 'Identify and consolidate duplicate code into reusable components. Apply DRY principles systematically.',
|
|
234
|
+
title: 'Consolidate Duplicate Code',
|
|
235
|
+
tool: 'GitLab Duo',
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
category: 'Planning & Architecture',
|
|
239
|
+
complexity: 'Intermediate',
|
|
240
|
+
description: 'Define architecture, components, and integration points for new features. Start projects with solid foundations.',
|
|
241
|
+
title: 'Design New Feature Architecture',
|
|
242
|
+
tool: 'GitLab Duo',
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
category: 'Testing',
|
|
246
|
+
complexity: 'Beginner',
|
|
247
|
+
description: 'Generate comprehensive unit tests covering happy paths, edge cases, and error conditions automatically.',
|
|
248
|
+
title: 'Generate Unit Tests',
|
|
249
|
+
tool: 'GitLab Duo',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
category: 'Testing',
|
|
253
|
+
complexity: 'Beginner',
|
|
254
|
+
description: 'Create realistic test datasets including valid records, edge cases, and boundary conditions.',
|
|
255
|
+
title: 'Generate Test Data',
|
|
256
|
+
tool: 'GitLab Duo',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
category: 'Testing',
|
|
260
|
+
complexity: 'Beginner',
|
|
261
|
+
description: 'Understand why tests fail, identify root causes, and determine if the code or test needs fixing.',
|
|
262
|
+
title: 'Explain Test Failures',
|
|
263
|
+
tool: 'GitLab Duo',
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
category: 'Debugging',
|
|
267
|
+
complexity: 'Beginner',
|
|
268
|
+
description: 'Diagnose CI/CD failures quickly with root cause analysis and fix suggestions.',
|
|
269
|
+
title: 'Debug Failing Pipeline',
|
|
270
|
+
tool: 'GitLab Duo',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
category: 'Debugging',
|
|
274
|
+
complexity: 'Beginner',
|
|
275
|
+
description: 'Rapidly diagnose production incidents with systematic troubleshooting guidance.',
|
|
276
|
+
title: 'Troubleshoot Production Issue',
|
|
277
|
+
tool: 'GitLab Duo',
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
category: 'Debugging',
|
|
281
|
+
complexity: 'Advanced',
|
|
282
|
+
description: 'Parse complex stack traces to identify error origins and suggest fixes.',
|
|
283
|
+
title: 'Analyze Stack Trace',
|
|
284
|
+
tool: 'GitLab Duo',
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
category: 'Debugging',
|
|
288
|
+
complexity: 'Beginner',
|
|
289
|
+
description: 'Trace bugs from symptoms to root causes. Find where problems actually originate.',
|
|
290
|
+
title: 'Find Root Cause of Bug',
|
|
291
|
+
tool: 'GitLab Duo',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
category: 'Security',
|
|
295
|
+
complexity: 'Intermediate',
|
|
296
|
+
description: 'Triage security scan results by real risk vs false positives. Prioritize remediation effectively.',
|
|
297
|
+
title: 'Analyze Security Scan Results',
|
|
298
|
+
tool: 'Duo Security Analyst',
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
category: 'Security',
|
|
302
|
+
complexity: 'Intermediate',
|
|
303
|
+
description: 'Proactive security review for injection vulnerabilities, auth flaws, and data exposure risks.',
|
|
304
|
+
title: 'Review Code for Security Issues',
|
|
305
|
+
tool: 'Duo Security Analyst',
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
category: 'DevOps',
|
|
309
|
+
complexity: 'Intermediate',
|
|
310
|
+
description: 'Optimize CI/CD pipelines for speed, security, and reliability. Apply GitLab best practices.',
|
|
311
|
+
title: 'Implement CI/CD Best Practices',
|
|
312
|
+
tool: 'GitLab Duo',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
category: 'Collaboration',
|
|
316
|
+
complexity: 'Beginner',
|
|
317
|
+
description: 'Think through approaches collaboratively. Get challenged on tradeoffs and edge cases you might miss.',
|
|
318
|
+
title: 'AI Pairing Partner for Exploring Approaches',
|
|
319
|
+
tool: 'GitLab Duo',
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
category: 'Collaboration',
|
|
323
|
+
complexity: 'Beginner',
|
|
324
|
+
description: 'Explain problems systematically to reveal solutions. Always-available rubber duck debugging partner.',
|
|
325
|
+
title: 'Rubber Duck Debugging with AI',
|
|
326
|
+
tool: 'GitLab Duo',
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
category: 'Code Understanding',
|
|
330
|
+
complexity: 'Advanced',
|
|
331
|
+
description: 'Explore unfamiliar codebases conversationally. Understand architecture and key dependencies interactively.',
|
|
332
|
+
title: 'Exploratory Code Understanding',
|
|
333
|
+
tool: 'GitLab Duo',
|
|
334
|
+
},
|
|
335
|
+
];
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export declare const gitlabTools: {
|
|
2
2
|
get_job_logs: import("ai").Tool<unknown, unknown>;
|
|
3
|
+
get_pipeline_details: import("ai").Tool<unknown, unknown>;
|
|
4
|
+
get_project: import("ai").Tool<unknown, unknown>;
|
|
5
|
+
list_jobs: import("ai").Tool<unknown, unknown>;
|
|
3
6
|
list_pipelines: import("ai").Tool<unknown, unknown>;
|
|
7
|
+
search_projects: import("ai").Tool<unknown, unknown>;
|
|
4
8
|
};
|
|
@@ -1,25 +1,44 @@
|
|
|
1
1
|
import { generateText, tool } from 'ai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { configManager } from '../../config.js';
|
|
3
4
|
import { createGitlabClient } from '../../gitlab/client.js';
|
|
4
5
|
import { createModel } from '../model.js';
|
|
5
6
|
/* eslint-disable camelcase */
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
8
|
const getJobLogsSchema = z.object({
|
|
7
9
|
jobId: z.number().describe('GitLab Job ID'),
|
|
8
|
-
projectId: z.string().describe('GitLab Project ID'),
|
|
9
10
|
});
|
|
10
11
|
const listPipelinesSchema = z.object({
|
|
11
12
|
limit: z.number().default(5).optional(),
|
|
12
|
-
|
|
13
|
+
status: z.string().optional().describe('Filter by status (e.g. success, failed, running)'),
|
|
14
|
+
});
|
|
15
|
+
const getPipelineDetailsSchema = z.object({
|
|
16
|
+
pipelineId: z.number().describe('GitLab Pipeline ID'),
|
|
17
|
+
});
|
|
18
|
+
const listJobsSchema = z.object({
|
|
19
|
+
limit: z.number().default(20).optional(),
|
|
20
|
+
pipelineId: z.number().optional().describe('Filter by Pipeline ID'),
|
|
21
|
+
scope: z.enum(['created', 'pending', 'running', 'failed', 'success', 'canceled', 'skipped', 'manual']).optional(),
|
|
22
|
+
});
|
|
23
|
+
const searchProjectsSchema = z.object({
|
|
24
|
+
query: z.string().describe('Search query (project name or path)'),
|
|
25
|
+
});
|
|
26
|
+
const getProjectSchema = z.object({
|
|
27
|
+
projectPathOrId: z.string().optional().describe('GitLab Project Path (group/project) or ID'),
|
|
13
28
|
});
|
|
14
29
|
export const gitlabTools = {
|
|
15
30
|
get_job_logs: tool({
|
|
16
31
|
description: 'Get the logs of a specific job to debug failures. If logs are long, it uses a subagent to summarize them.',
|
|
17
|
-
|
|
18
|
-
async execute(args) {
|
|
32
|
+
async execute(args, options) {
|
|
19
33
|
try {
|
|
34
|
+
const projectId = options?.projectId || configManager.get().defaultProjectId;
|
|
35
|
+
const jobId = args.jobId || args.job_id;
|
|
36
|
+
if (!projectId)
|
|
37
|
+
throw new Error('Project ID is required (argument or default config)');
|
|
38
|
+
if (!jobId)
|
|
39
|
+
throw new Error('Job ID is required');
|
|
20
40
|
const client = createGitlabClient();
|
|
21
|
-
|
|
22
|
-
const trace = await client.Jobs.showTrace(args.projectId, args.jobId);
|
|
41
|
+
const trace = await client.Jobs.showLog(projectId, jobId);
|
|
23
42
|
const logText = typeof trace === 'string' ? trace : JSON.stringify(trace);
|
|
24
43
|
// If logs are short, return directly
|
|
25
44
|
if (logText.length < 5000) {
|
|
@@ -51,15 +70,113 @@ ${content}`
|
|
|
51
70
|
}
|
|
52
71
|
},
|
|
53
72
|
parameters: getJobLogsSchema,
|
|
54
|
-
|
|
73
|
+
}),
|
|
74
|
+
get_pipeline_details: tool({
|
|
75
|
+
description: 'Get detailed information about a specific pipeline, including its jobs and status.',
|
|
76
|
+
async execute(args, options) {
|
|
77
|
+
try {
|
|
78
|
+
const projectId = options?.projectId || configManager.get().defaultProjectId;
|
|
79
|
+
const pipelineId = args.pipelineId || args.pipeline_id;
|
|
80
|
+
if (!projectId)
|
|
81
|
+
throw new Error('Project ID is required (argument or default config)');
|
|
82
|
+
if (!pipelineId)
|
|
83
|
+
throw new Error('Pipeline ID is required');
|
|
84
|
+
const client = createGitlabClient();
|
|
85
|
+
const pipeline = await client.Pipelines.show(projectId, pipelineId);
|
|
86
|
+
const jobs = await client.Pipelines.showJobs(projectId, pipelineId);
|
|
87
|
+
return {
|
|
88
|
+
jobs: jobs.map((j) => ({
|
|
89
|
+
id: j.id,
|
|
90
|
+
name: j.name,
|
|
91
|
+
stage: j.stage,
|
|
92
|
+
status: j.status,
|
|
93
|
+
})),
|
|
94
|
+
pipeline: {
|
|
95
|
+
created_at: pipeline.created_at,
|
|
96
|
+
duration: pipeline.duration,
|
|
97
|
+
id: pipeline.id,
|
|
98
|
+
ref: pipeline.ref,
|
|
99
|
+
status: pipeline.status,
|
|
100
|
+
web_url: pipeline.web_url,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return { error: String(error) };
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
parameters: getPipelineDetailsSchema,
|
|
109
|
+
}),
|
|
110
|
+
get_project: tool({
|
|
111
|
+
description: 'Get details of a specific project by its path (e.g. "group/project") or ID to find its numeric ID.',
|
|
112
|
+
async execute(args, options) {
|
|
113
|
+
try {
|
|
114
|
+
const projectPathOrId = options?.projectId || args.projectPathOrId || configManager.get().defaultProjectId;
|
|
115
|
+
if (!projectPathOrId)
|
|
116
|
+
throw new Error('Project Path or ID is required (argument or default config)');
|
|
117
|
+
const client = createGitlabClient();
|
|
118
|
+
const project = await client.Projects.show(projectPathOrId);
|
|
119
|
+
return {
|
|
120
|
+
project: {
|
|
121
|
+
description: project.description,
|
|
122
|
+
id: project.id,
|
|
123
|
+
name: project.name,
|
|
124
|
+
path_with_namespace: project.path_with_namespace,
|
|
125
|
+
web_url: project.web_url,
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
return { error: `Failed to find project "${args.projectPathOrId || options?.projectId || 'unknown'}": ${String(error)}` };
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
parameters: getProjectSchema,
|
|
134
|
+
}),
|
|
135
|
+
list_jobs: tool({
|
|
136
|
+
description: 'List jobs for a project, optionally filtered by pipeline or status scope.',
|
|
137
|
+
async execute(args, options) {
|
|
138
|
+
try {
|
|
139
|
+
const projectId = options?.projectId || configManager.get().defaultProjectId;
|
|
140
|
+
const pipelineId = args.pipelineId || args.pipeline_id;
|
|
141
|
+
if (!projectId)
|
|
142
|
+
throw new Error('Project ID is required (argument or default config)');
|
|
143
|
+
const client = createGitlabClient();
|
|
144
|
+
const queryOptions = { perPage: args.limit };
|
|
145
|
+
if (args.scope)
|
|
146
|
+
queryOptions.scope = args.scope;
|
|
147
|
+
const jobs = pipelineId
|
|
148
|
+
? await client.Pipelines.showJobs(projectId, pipelineId, queryOptions)
|
|
149
|
+
: await client.Jobs.all(projectId, queryOptions);
|
|
150
|
+
return {
|
|
151
|
+
jobs: jobs.map((j) => ({
|
|
152
|
+
created_at: j.created_at,
|
|
153
|
+
id: j.id,
|
|
154
|
+
name: j.name,
|
|
155
|
+
pipeline: { id: j.pipeline.id },
|
|
156
|
+
stage: j.stage,
|
|
157
|
+
status: j.status,
|
|
158
|
+
web_url: j.web_url,
|
|
159
|
+
})),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
return { error: String(error) };
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
parameters: listJobsSchema,
|
|
55
167
|
}),
|
|
56
168
|
list_pipelines: tool({
|
|
57
169
|
description: 'List recent pipelines for a project to check status',
|
|
58
|
-
|
|
59
|
-
async execute(args) {
|
|
170
|
+
async execute(args, options) {
|
|
60
171
|
try {
|
|
172
|
+
const projectId = options?.projectId || configManager.get().defaultProjectId;
|
|
173
|
+
if (!projectId)
|
|
174
|
+
throw new Error('Project ID is required (argument or default config)');
|
|
61
175
|
const client = createGitlabClient();
|
|
62
|
-
const
|
|
176
|
+
const queryOptions = { perPage: args.limit };
|
|
177
|
+
if (args.status)
|
|
178
|
+
queryOptions.status = args.status;
|
|
179
|
+
const pipelines = await client.Pipelines.all(projectId, queryOptions);
|
|
63
180
|
return {
|
|
64
181
|
pipelines: pipelines.map((p) => ({
|
|
65
182
|
created_at: p.created_at,
|
|
@@ -75,7 +192,41 @@ ${content}`
|
|
|
75
192
|
}
|
|
76
193
|
},
|
|
77
194
|
parameters: listPipelinesSchema,
|
|
78
|
-
|
|
195
|
+
}),
|
|
196
|
+
search_projects: tool({
|
|
197
|
+
description: 'Search for a GitLab project by name or path to find its ID.',
|
|
198
|
+
async execute(args) {
|
|
199
|
+
try {
|
|
200
|
+
const client = createGitlabClient();
|
|
201
|
+
// search() is good for name but less precise than path.
|
|
202
|
+
// It's often useful for discovering projects.
|
|
203
|
+
// In some GitBeaker versions, this might be Projects.search(query) or Projects.all({search: query})
|
|
204
|
+
// We will try Projects.search(query) first, fallback to all({search}) if fails
|
|
205
|
+
let projects;
|
|
206
|
+
try {
|
|
207
|
+
projects = await client.Projects.search(args.query);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
projects = await client.Projects.all({ search: args.query });
|
|
211
|
+
}
|
|
212
|
+
if (!Array.isArray(projects)) {
|
|
213
|
+
projects = [projects];
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
projects: projects.map((p) => ({
|
|
217
|
+
description: p.description,
|
|
218
|
+
id: p.id,
|
|
219
|
+
name: p.name,
|
|
220
|
+
path_with_namespace: p.path_with_namespace,
|
|
221
|
+
web_url: p.web_url,
|
|
222
|
+
})),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
return { error: String(error) };
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
parameters: searchProjectsSchema,
|
|
79
230
|
}),
|
|
80
231
|
};
|
|
81
232
|
/* eslint-enable camelcase */
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { tool } from 'ai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { configManager } from '../../config.js';
|
|
3
4
|
import { fetchCarbonMetrics } from '../../measure/bigquery-service.js';
|
|
4
5
|
/* eslint-disable camelcase */
|
|
5
6
|
const getCarbonMetricsSchema = z.object({
|
|
6
7
|
limit: z.number().default(10).optional(),
|
|
7
|
-
projectId: z.string().describe('GitLab Project ID (numeric)'),
|
|
8
8
|
});
|
|
9
9
|
export const measureTools = {
|
|
10
10
|
get_carbon_metrics: tool({
|
|
11
11
|
description: 'Query carbon emissions for a project from BigQuery',
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
async execute(args) {
|
|
13
|
+
async execute(args, options) {
|
|
14
14
|
try {
|
|
15
|
-
const
|
|
15
|
+
const projectId = options?.projectId || configManager.get().defaultProjectId;
|
|
16
|
+
if (!projectId) {
|
|
17
|
+
return { error: 'Project ID is required. Please select a project in the portal or configure a default project.' };
|
|
18
|
+
}
|
|
19
|
+
const metrics = await fetchCarbonMetrics(projectId, args.limit);
|
|
16
20
|
return { metrics };
|
|
17
21
|
}
|
|
18
22
|
catch (error) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|