plugin-git-manager 1.2.26 → 1.2.28

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.
Files changed (108) hide show
  1. package/README.md +133 -108
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.js +1 -1
  6. package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
  7. package/dist/client/900.a48beac7e2ebee7d.js +10 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
  10. package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
  11. package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
  12. package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
  13. package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
  14. package/dist/client-v2/index.js +1 -1
  15. package/dist/externalVersion.js +9 -8
  16. package/dist/locale/en-US.json +307 -297
  17. package/dist/locale/vi-VN.json +295 -292
  18. package/dist/locale/zh-CN.json +61 -51
  19. package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
  20. package/dist/node_modules/simple-git/package.json +1 -1
  21. package/dist/node_modules/zod/index.cjs +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/actions/git-actions.js +90 -36
  24. package/dist/server/actions/gitlab-api.js +4 -2
  25. package/dist/server/actions/poller.js +5 -2
  26. package/dist/server/actions/review.js +20 -10
  27. package/dist/server/plugin.js +6 -4
  28. package/dist/server/poller.js +46 -45
  29. package/dist/server/request-method-policy.js +75 -0
  30. package/dist/server/services/registry-content-service.js +23 -10
  31. package/dist/server/utils/get-repo-account.js +3 -2
  32. package/dist/server/utils/url-security.js +24 -0
  33. package/package.json +61 -43
  34. package/server.d.ts +2 -2
  35. package/server.js +1 -1
  36. package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
  37. package/src/client/ai-context.tsx +114 -114
  38. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  39. package/src/client/components/CommitHistory.tsx +374 -374
  40. package/src/client/components/FileExplorer.tsx +386 -386
  41. package/src/client/components/GitAccounts.tsx +179 -179
  42. package/src/client/components/GitManagerSettings.tsx +160 -160
  43. package/src/client/components/GitOperations.tsx +220 -220
  44. package/src/client/components/LLMModelSelect.tsx +63 -63
  45. package/src/client/components/LLMServiceSelect.tsx +58 -58
  46. package/src/client/components/MarkdownView.tsx +80 -80
  47. package/src/client/components/MergeRequests.tsx +790 -790
  48. package/src/client/components/PollingStatus.tsx +225 -225
  49. package/src/client/components/RepositoryConfig.tsx +335 -335
  50. package/src/client/components/RepositoryPermissions.tsx +123 -123
  51. package/src/client/components/ReviewFlows.tsx +303 -303
  52. package/src/client/components/ReviewHistory.tsx +566 -566
  53. package/src/client/components/RunReviewButton.tsx +63 -55
  54. package/src/client/context/GitManagerContext.tsx +92 -92
  55. package/src/client/index.tsx +91 -82
  56. package/src/client/locale.ts +9 -9
  57. package/src/client/promptTemplates.ts +31 -31
  58. package/src/client-v2/ai-context.tsx +99 -0
  59. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  60. package/src/client-v2/index.tsx +1 -1
  61. package/src/client-v2/locale.ts +8 -8
  62. package/src/client-v2/plugin.tsx +67 -39
  63. package/src/index.ts +2 -2
  64. package/src/locale/en-US.json +307 -297
  65. package/src/locale/vi-VN.json +295 -292
  66. package/src/locale/zh-CN.json +61 -51
  67. package/src/server/__tests__/git-actions.test.ts +24 -24
  68. package/src/server/__tests__/git-security.test.ts +170 -0
  69. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  70. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  71. package/src/server/__tests__/poller.test.ts +37 -37
  72. package/src/server/__tests__/repository-access.test.ts +752 -752
  73. package/src/server/__tests__/review.test.ts +137 -137
  74. package/src/server/__tests__/role-permissions.test.ts +147 -147
  75. package/src/server/__tests__/smoke.test.ts +139 -17
  76. package/src/server/__tests__/subtree.test.ts +85 -85
  77. package/src/server/actions/git-actions.ts +540 -480
  78. package/src/server/actions/gitlab-api.ts +422 -411
  79. package/src/server/actions/poller.ts +39 -27
  80. package/src/server/actions/review.ts +1388 -1369
  81. package/src/server/actions/role-permissions.ts +321 -321
  82. package/src/server/actions/subtree.ts +508 -508
  83. package/src/server/ai-tools.ts +319 -319
  84. package/src/server/collections/gitAccounts.ts +56 -56
  85. package/src/server/collections/gitCodeReviews.ts +199 -199
  86. package/src/server/collections/gitRepositories.ts +87 -87
  87. package/src/server/collections/gitReviewFlows.ts +108 -108
  88. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  89. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  90. package/src/server/index.ts +2 -2
  91. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  92. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  93. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  94. package/src/server/plugin.ts +372 -361
  95. package/src/server/poller.ts +351 -352
  96. package/src/server/repository-access.ts +773 -773
  97. package/src/server/request-method-policy.ts +55 -0
  98. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  99. package/src/server/services/registry-content-service.ts +33 -11
  100. package/src/server/utils/__tests__/redact.test.ts +56 -56
  101. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  102. package/src/server/utils/get-repo-account.ts +51 -41
  103. package/src/server/utils/gitlab-url.ts +38 -38
  104. package/src/server/utils/redact.ts +87 -87
  105. package/src/server/utils/url-security.ts +128 -95
  106. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  107. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  108. package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
@@ -1,319 +1,319 @@
1
- import { z } from 'zod';
2
- import type { Application } from '@nocobase/server';
3
- import * as gitlabApi from './actions/gitlab-api';
4
- import * as gitActions from './actions/git-actions';
5
-
6
- /**
7
- * Register AI tools that allow an AI employee to inspect git repositories,
8
- * merge requests, commits, and file content during a review session.
9
- *
10
- * Each tool is invoked by the AI runtime; the `invoke` callback constructs a
11
- * synthetic `ctx.action.params` payload then delegates to the existing
12
- * resource action implementation.
13
- */
14
- export function registerGitReviewAiTools(app: Application) {
15
- const aiManager = (app as any).aiManager;
16
- if (!aiManager?.toolsManager?.registerTools) {
17
- app.log?.warn?.('plugin-git-manager: AIManager.toolsManager not available; skipping AI tool registration');
18
- return;
19
- }
20
-
21
- /**
22
- * Enforce that the AI session has an authenticated user and that this user
23
- * is permitted to invoke the underlying resource:action. Without this check,
24
- * a prompt-injected AI could pass an arbitrary `repositoryId` to the tools
25
- * and read any repository's MRs / commits / file content regardless of the
26
- * caller's ACL.
27
- */
28
- const enforceAcl = (ctx: any, resource: string, action: string, params: any) => {
29
- if (ctx.isBackgroundReview) {
30
- if (params.repositoryId && params.repositoryId !== ctx.reviewTargetRepositoryId) {
31
- const err: any = new Error('Permission denied: AI cannot access other repositories');
32
- err.status = 403;
33
- throw err;
34
- }
35
- return; // Authorized for this specific repository in background context
36
- }
37
- const user = ctx?.state?.currentUser;
38
- if (!user?.id) {
39
- const err: any = new Error('AI tool requires an authenticated user context');
40
- err.status = 401;
41
- throw err;
42
- }
43
- const acl = ctx.app?.acl;
44
- if (!acl?.can) return; // ACL not available — fail-open is acceptable for legacy contexts
45
- const role = ctx?.state?.currentRole || (Array.isArray(user.roles) && user.roles[0]?.name) || null;
46
- if (!role) {
47
- const err: any = new Error('AI tool requires a resolvable role on the current user');
48
- err.status = 403;
49
- throw err;
50
- }
51
- const allowed = acl.can({ role, resource, action });
52
- if (!allowed) {
53
- const err: any = new Error(`Permission denied: ${resource}:${action}`);
54
- err.status = 403;
55
- throw err;
56
- }
57
- };
58
-
59
- const sanitizeForDb = (obj: any): any => {
60
- if (typeof obj === 'string') {
61
- // Remove null bytes \u0000 which crash Postgres jsonb/text fields
62
- // eslint-disable-next-line no-control-regex
63
- return obj.replace(/\u0000/g, '');
64
- }
65
- if (Array.isArray(obj)) {
66
- return obj.map(sanitizeForDb);
67
- }
68
- if (obj && typeof obj === 'object') {
69
- const sanitized: any = {};
70
- for (const [key, value] of Object.entries(obj)) {
71
- sanitized[key] = sanitizeForDb(value);
72
- }
73
- return sanitized;
74
- }
75
- return obj;
76
- };
77
-
78
- const runResourceAction = async (
79
- ctx: any,
80
- handler: (ctx: any, next: () => Promise<void>) => Promise<void>,
81
- params: Record<string, any>,
82
- gate: { resource: string; action: string },
83
- ) => {
84
- enforceAcl(ctx, gate.resource, gate.action, params);
85
- const synthCtx: any = {
86
- ...ctx,
87
- app: ctx.app,
88
- db: ctx.db,
89
- action: { params },
90
- request: { ...(ctx.request || {}), body: ctx.request?.body || {} },
91
- throw: (status: number, message: string) => {
92
- const err: any = new Error(message);
93
- err.status = status;
94
- throw err;
95
- },
96
- };
97
- await handler(synthCtx, async () => undefined);
98
- return sanitizeForDb(synthCtx.body);
99
- };
100
-
101
- aiManager.toolsManager.registerTools([
102
- {
103
- scope: 'GENERAL',
104
- execution: 'backend',
105
- defaultPermission: 'ALLOW',
106
- silence: false,
107
- introduction: { title: 'Git: Get merge request' },
108
- definition: {
109
- name: 'git_get_merge_request',
110
- description:
111
- 'Get full details of a GitLab merge request including its file-level diffs. Use this to inspect the code changes that need review.',
112
- schema: z.object({
113
- repositoryId: z.number().describe('The numeric ID of the gitRepositories record'),
114
- mrIid: z.number().describe('The GitLab merge request internal ID (iid)'),
115
- }),
116
- },
117
- invoke: async (ctx: any, args: any) => {
118
- const body = await runResourceAction(ctx, gitlabApi.mergeRequestDetail, args, {
119
- resource: 'gitManager',
120
- action: 'mergeRequestDetail',
121
- });
122
- return body?.data ?? body;
123
- },
124
- },
125
- {
126
- scope: 'GENERAL',
127
- execution: 'backend',
128
- defaultPermission: 'ALLOW',
129
- silence: false,
130
- introduction: { title: 'Git: List merge requests' },
131
- definition: {
132
- name: 'git_list_merge_requests',
133
- description: 'List GitLab merge requests for a repository, with optional state and search filters.',
134
- schema: z.object({
135
- repositoryId: z.number(),
136
- state: z.enum(['opened', 'closed', 'merged', 'all']).optional(),
137
- search: z.string().optional(),
138
- page: z.number().optional(),
139
- perPage: z.number().optional(),
140
- }),
141
- },
142
- invoke: async (ctx: any, args: any) => {
143
- const body = await runResourceAction(ctx, gitlabApi.mergeRequests, args, {
144
- resource: 'gitManager',
145
- action: 'mergeRequests',
146
- });
147
- return body?.data ?? body;
148
- },
149
- },
150
- {
151
- scope: 'GENERAL',
152
- execution: 'backend',
153
- defaultPermission: 'ALLOW',
154
- silence: false,
155
- introduction: { title: 'Git: Get merge request notes' },
156
- definition: {
157
- name: 'git_get_merge_request_notes',
158
- description: 'Get existing comments / notes on a merge request to avoid duplicating feedback.',
159
- schema: z.object({
160
- repositoryId: z.number(),
161
- mrIid: z.number(),
162
- }),
163
- },
164
- invoke: async (ctx: any, args: any) => {
165
- const body = await runResourceAction(ctx, gitlabApi.mergeRequestNotes, args, {
166
- resource: 'gitManager',
167
- action: 'mergeRequestNotes',
168
- });
169
- return body?.data ?? body;
170
- },
171
- },
172
- {
173
- scope: 'GENERAL',
174
- execution: 'backend',
175
- defaultPermission: 'ALLOW',
176
- silence: false,
177
- introduction: { title: 'Git: Get commit detail' },
178
- definition: {
179
- name: 'git_get_commit',
180
- description: 'Get details and diff of a specific commit in a cloned repository.',
181
- schema: z.object({
182
- repositoryId: z.number(),
183
- commitHash: z.string().describe('Full or short commit SHA'),
184
- }),
185
- },
186
- invoke: async (ctx: any, args: any) => {
187
- const body = await runResourceAction(ctx, gitActions.commitDetail, args, {
188
- resource: 'gitManager',
189
- action: 'commitDetail',
190
- });
191
- return body?.data ?? body;
192
- },
193
- },
194
- {
195
- scope: 'GENERAL',
196
- execution: 'backend',
197
- defaultPermission: 'ALLOW',
198
- silence: false,
199
- introduction: { title: 'Git: Get diff' },
200
- definition: {
201
- name: 'git_get_diff',
202
- description:
203
- 'Get the diff between two refs (branches/commits) in a cloned repository, or the diff of a single commit when only commitHash is given.',
204
- schema: z.object({
205
- repositoryId: z.number(),
206
- commitHash: z.string().optional(),
207
- compareHash: z.string().optional(),
208
- file: z.string().optional().describe('Optional file path to scope the diff'),
209
- }),
210
- },
211
- invoke: async (ctx: any, args: any) => {
212
- const body = await runResourceAction(ctx, gitActions.diff, args, {
213
- resource: 'gitManager',
214
- action: 'diff',
215
- });
216
- return body?.data ?? body;
217
- },
218
- },
219
- {
220
- scope: 'GENERAL',
221
- execution: 'backend',
222
- defaultPermission: 'ALLOW',
223
- silence: false,
224
- introduction: { title: 'Git: Get file content' },
225
- definition: {
226
- name: 'git_get_file_content',
227
- description:
228
- 'Read the content of a single file in a cloned repository at a given ref. Useful when reviewing changes in surrounding context.',
229
- schema: z.object({
230
- repositoryId: z.number(),
231
- filePath: z.string(),
232
- ref: z.string().optional(),
233
- }),
234
- },
235
- invoke: async (ctx: any, args: any) => {
236
- const body = await runResourceAction(ctx, gitActions.fileContent, args, {
237
- resource: 'gitManager',
238
- action: 'fileContent',
239
- });
240
- return body?.data ?? body;
241
- },
242
- },
243
- {
244
- scope: 'GENERAL',
245
- execution: 'backend',
246
- defaultPermission: 'ALLOW',
247
- silence: false,
248
- introduction: { title: 'Git: List files' },
249
- definition: {
250
- name: 'git_list_files',
251
- description:
252
- 'List files and folders of a cloned repository at a given ref. Set recursive=true with a treePath to enumerate every file under a folder, e.g. when reviewing the full code of a folder.',
253
- schema: z.object({
254
- repositoryId: z.number(),
255
- treePath: z.string().optional().describe('Folder path relative to repo root; omit for the root'),
256
- ref: z.string().optional().describe('Branch, tag or commit SHA; defaults to HEAD'),
257
- recursive: z.boolean().optional().describe('true to list all files under treePath recursively'),
258
- }),
259
- },
260
- invoke: async (ctx: any, args: any) => {
261
- const body = await runResourceAction(ctx, gitActions.fileTree, args, {
262
- resource: 'gitManager',
263
- action: 'fileTree',
264
- });
265
- const files = (body?.data ?? body ?? []) as unknown[];
266
- const list = Array.isArray(files) ? files : [];
267
- const MAX_ENTRIES = 500;
268
- if (list.length > MAX_ENTRIES) {
269
- return { files: list.slice(0, MAX_ENTRIES), totalCount: list.length, truncated: true };
270
- }
271
- return { files: list, totalCount: list.length, truncated: false };
272
- },
273
- },
274
- {
275
- scope: 'GENERAL',
276
- execution: 'backend',
277
- defaultPermission: 'ALLOW',
278
- silence: false,
279
- introduction: { title: 'Git: List branches' },
280
- definition: {
281
- name: 'git_list_branches',
282
- description: 'List branches available in a cloned repository.',
283
- schema: z.object({ repositoryId: z.number() }),
284
- },
285
- invoke: async (ctx: any, args: any) => {
286
- const body = await runResourceAction(ctx, gitActions.branches, args, {
287
- resource: 'gitManager',
288
- action: 'branches',
289
- });
290
- return body?.data ?? body;
291
- },
292
- },
293
- {
294
- scope: 'GENERAL',
295
- execution: 'backend',
296
- defaultPermission: 'ALLOW',
297
- silence: false,
298
- introduction: { title: 'Git: List recent commits' },
299
- definition: {
300
- name: 'git_list_commits',
301
- description: 'List recent commits in a cloned repository, optionally scoped to a single file.',
302
- schema: z.object({
303
- repositoryId: z.number(),
304
- maxCount: z.number().optional(),
305
- file: z.string().optional(),
306
- }),
307
- },
308
- invoke: async (ctx: any, args: any) => {
309
- const body = await runResourceAction(ctx, gitActions.log, args, {
310
- resource: 'gitManager',
311
- action: 'log',
312
- });
313
- return body?.data ?? body;
314
- },
315
- },
316
- ]);
317
-
318
- app.log?.info?.('plugin-git-manager: registered git_* AI tools for code review');
319
- }
1
+ import { z } from 'zod';
2
+ import type { Application } from '@nocobase/server';
3
+ import * as gitlabApi from './actions/gitlab-api';
4
+ import * as gitActions from './actions/git-actions';
5
+
6
+ /**
7
+ * Register AI tools that allow an AI employee to inspect git repositories,
8
+ * merge requests, commits, and file content during a review session.
9
+ *
10
+ * Each tool is invoked by the AI runtime; the `invoke` callback constructs a
11
+ * synthetic `ctx.action.params` payload then delegates to the existing
12
+ * resource action implementation.
13
+ */
14
+ export function registerGitReviewAiTools(app: Application) {
15
+ const aiManager = (app as any).aiManager;
16
+ if (!aiManager?.toolsManager?.registerTools) {
17
+ app.log?.warn?.('plugin-git-manager: AIManager.toolsManager not available; skipping AI tool registration');
18
+ return;
19
+ }
20
+
21
+ /**
22
+ * Enforce that the AI session has an authenticated user and that this user
23
+ * is permitted to invoke the underlying resource:action. Without this check,
24
+ * a prompt-injected AI could pass an arbitrary `repositoryId` to the tools
25
+ * and read any repository's MRs / commits / file content regardless of the
26
+ * caller's ACL.
27
+ */
28
+ const enforceAcl = (ctx: any, resource: string, action: string, params: any) => {
29
+ if (ctx.isBackgroundReview) {
30
+ if (params.repositoryId && params.repositoryId !== ctx.reviewTargetRepositoryId) {
31
+ const err: any = new Error('Permission denied: AI cannot access other repositories');
32
+ err.status = 403;
33
+ throw err;
34
+ }
35
+ return; // Authorized for this specific repository in background context
36
+ }
37
+ const user = ctx?.state?.currentUser;
38
+ if (!user?.id) {
39
+ const err: any = new Error('AI tool requires an authenticated user context');
40
+ err.status = 401;
41
+ throw err;
42
+ }
43
+ const acl = ctx.app?.acl;
44
+ if (!acl?.can) return; // ACL not available — fail-open is acceptable for legacy contexts
45
+ const role = ctx?.state?.currentRole || (Array.isArray(user.roles) && user.roles[0]?.name) || null;
46
+ if (!role) {
47
+ const err: any = new Error('AI tool requires a resolvable role on the current user');
48
+ err.status = 403;
49
+ throw err;
50
+ }
51
+ const allowed = acl.can({ role, resource, action });
52
+ if (!allowed) {
53
+ const err: any = new Error(`Permission denied: ${resource}:${action}`);
54
+ err.status = 403;
55
+ throw err;
56
+ }
57
+ };
58
+
59
+ const sanitizeForDb = (obj: any): any => {
60
+ if (typeof obj === 'string') {
61
+ // Remove null bytes \u0000 which crash Postgres jsonb/text fields
62
+ // eslint-disable-next-line no-control-regex
63
+ return obj.replace(/\u0000/g, '');
64
+ }
65
+ if (Array.isArray(obj)) {
66
+ return obj.map(sanitizeForDb);
67
+ }
68
+ if (obj && typeof obj === 'object') {
69
+ const sanitized: any = {};
70
+ for (const [key, value] of Object.entries(obj)) {
71
+ sanitized[key] = sanitizeForDb(value);
72
+ }
73
+ return sanitized;
74
+ }
75
+ return obj;
76
+ };
77
+
78
+ const runResourceAction = async (
79
+ ctx: any,
80
+ handler: (ctx: any, next: () => Promise<void>) => Promise<void>,
81
+ params: Record<string, any>,
82
+ gate: { resource: string; action: string },
83
+ ) => {
84
+ enforceAcl(ctx, gate.resource, gate.action, params);
85
+ const synthCtx: any = {
86
+ ...ctx,
87
+ app: ctx.app,
88
+ db: ctx.db,
89
+ action: { params },
90
+ request: { ...(ctx.request || {}), body: ctx.request?.body || {} },
91
+ throw: (status: number, message: string) => {
92
+ const err: any = new Error(message);
93
+ err.status = status;
94
+ throw err;
95
+ },
96
+ };
97
+ await handler(synthCtx, async () => undefined);
98
+ return sanitizeForDb(synthCtx.body);
99
+ };
100
+
101
+ aiManager.toolsManager.registerTools([
102
+ {
103
+ scope: 'GENERAL',
104
+ execution: 'backend',
105
+ defaultPermission: 'ALLOW',
106
+ silence: false,
107
+ introduction: { title: 'Git: Get merge request' },
108
+ definition: {
109
+ name: 'git_get_merge_request',
110
+ description:
111
+ 'Get full details of a GitLab merge request including its file-level diffs. Use this to inspect the code changes that need review.',
112
+ schema: z.object({
113
+ repositoryId: z.number().describe('The numeric ID of the gitRepositories record'),
114
+ mrIid: z.number().describe('The GitLab merge request internal ID (iid)'),
115
+ }),
116
+ },
117
+ invoke: async (ctx: any, args: any) => {
118
+ const body = await runResourceAction(ctx, gitlabApi.mergeRequestDetail, args, {
119
+ resource: 'gitManager',
120
+ action: 'mergeRequestDetail',
121
+ });
122
+ return body?.data ?? body;
123
+ },
124
+ },
125
+ {
126
+ scope: 'GENERAL',
127
+ execution: 'backend',
128
+ defaultPermission: 'ALLOW',
129
+ silence: false,
130
+ introduction: { title: 'Git: List merge requests' },
131
+ definition: {
132
+ name: 'git_list_merge_requests',
133
+ description: 'List GitLab merge requests for a repository, with optional state and search filters.',
134
+ schema: z.object({
135
+ repositoryId: z.number(),
136
+ state: z.enum(['opened', 'closed', 'merged', 'all']).optional(),
137
+ search: z.string().optional(),
138
+ page: z.number().optional(),
139
+ perPage: z.number().optional(),
140
+ }),
141
+ },
142
+ invoke: async (ctx: any, args: any) => {
143
+ const body = await runResourceAction(ctx, gitlabApi.mergeRequests, args, {
144
+ resource: 'gitManager',
145
+ action: 'mergeRequests',
146
+ });
147
+ return body?.data ?? body;
148
+ },
149
+ },
150
+ {
151
+ scope: 'GENERAL',
152
+ execution: 'backend',
153
+ defaultPermission: 'ALLOW',
154
+ silence: false,
155
+ introduction: { title: 'Git: Get merge request notes' },
156
+ definition: {
157
+ name: 'git_get_merge_request_notes',
158
+ description: 'Get existing comments / notes on a merge request to avoid duplicating feedback.',
159
+ schema: z.object({
160
+ repositoryId: z.number(),
161
+ mrIid: z.number(),
162
+ }),
163
+ },
164
+ invoke: async (ctx: any, args: any) => {
165
+ const body = await runResourceAction(ctx, gitlabApi.mergeRequestNotes, args, {
166
+ resource: 'gitManager',
167
+ action: 'mergeRequestNotes',
168
+ });
169
+ return body?.data ?? body;
170
+ },
171
+ },
172
+ {
173
+ scope: 'GENERAL',
174
+ execution: 'backend',
175
+ defaultPermission: 'ALLOW',
176
+ silence: false,
177
+ introduction: { title: 'Git: Get commit detail' },
178
+ definition: {
179
+ name: 'git_get_commit',
180
+ description: 'Get details and diff of a specific commit in a cloned repository.',
181
+ schema: z.object({
182
+ repositoryId: z.number(),
183
+ commitHash: z.string().describe('Full or short commit SHA'),
184
+ }),
185
+ },
186
+ invoke: async (ctx: any, args: any) => {
187
+ const body = await runResourceAction(ctx, gitActions.commitDetail, args, {
188
+ resource: 'gitManager',
189
+ action: 'commitDetail',
190
+ });
191
+ return body?.data ?? body;
192
+ },
193
+ },
194
+ {
195
+ scope: 'GENERAL',
196
+ execution: 'backend',
197
+ defaultPermission: 'ALLOW',
198
+ silence: false,
199
+ introduction: { title: 'Git: Get diff' },
200
+ definition: {
201
+ name: 'git_get_diff',
202
+ description:
203
+ 'Get the diff between two refs (branches/commits) in a cloned repository, or the diff of a single commit when only commitHash is given.',
204
+ schema: z.object({
205
+ repositoryId: z.number(),
206
+ commitHash: z.string().optional(),
207
+ compareHash: z.string().optional(),
208
+ file: z.string().optional().describe('Optional file path to scope the diff'),
209
+ }),
210
+ },
211
+ invoke: async (ctx: any, args: any) => {
212
+ const body = await runResourceAction(ctx, gitActions.diff, args, {
213
+ resource: 'gitManager',
214
+ action: 'diff',
215
+ });
216
+ return body?.data ?? body;
217
+ },
218
+ },
219
+ {
220
+ scope: 'GENERAL',
221
+ execution: 'backend',
222
+ defaultPermission: 'ALLOW',
223
+ silence: false,
224
+ introduction: { title: 'Git: Get file content' },
225
+ definition: {
226
+ name: 'git_get_file_content',
227
+ description:
228
+ 'Read the content of a single file in a cloned repository at a given ref. Useful when reviewing changes in surrounding context.',
229
+ schema: z.object({
230
+ repositoryId: z.number(),
231
+ filePath: z.string(),
232
+ ref: z.string().optional(),
233
+ }),
234
+ },
235
+ invoke: async (ctx: any, args: any) => {
236
+ const body = await runResourceAction(ctx, gitActions.fileContent, args, {
237
+ resource: 'gitManager',
238
+ action: 'fileContent',
239
+ });
240
+ return body?.data ?? body;
241
+ },
242
+ },
243
+ {
244
+ scope: 'GENERAL',
245
+ execution: 'backend',
246
+ defaultPermission: 'ALLOW',
247
+ silence: false,
248
+ introduction: { title: 'Git: List files' },
249
+ definition: {
250
+ name: 'git_list_files',
251
+ description:
252
+ 'List files and folders of a cloned repository at a given ref. Set recursive=true with a treePath to enumerate every file under a folder, e.g. when reviewing the full code of a folder.',
253
+ schema: z.object({
254
+ repositoryId: z.number(),
255
+ treePath: z.string().optional().describe('Folder path relative to repo root; omit for the root'),
256
+ ref: z.string().optional().describe('Branch, tag or commit SHA; defaults to HEAD'),
257
+ recursive: z.boolean().optional().describe('true to list all files under treePath recursively'),
258
+ }),
259
+ },
260
+ invoke: async (ctx: any, args: any) => {
261
+ const body = await runResourceAction(ctx, gitActions.fileTree, args, {
262
+ resource: 'gitManager',
263
+ action: 'fileTree',
264
+ });
265
+ const files = (body?.data ?? body ?? []) as unknown[];
266
+ const list = Array.isArray(files) ? files : [];
267
+ const MAX_ENTRIES = 500;
268
+ if (list.length > MAX_ENTRIES) {
269
+ return { files: list.slice(0, MAX_ENTRIES), totalCount: list.length, truncated: true };
270
+ }
271
+ return { files: list, totalCount: list.length, truncated: false };
272
+ },
273
+ },
274
+ {
275
+ scope: 'GENERAL',
276
+ execution: 'backend',
277
+ defaultPermission: 'ALLOW',
278
+ silence: false,
279
+ introduction: { title: 'Git: List branches' },
280
+ definition: {
281
+ name: 'git_list_branches',
282
+ description: 'List branches available in a cloned repository.',
283
+ schema: z.object({ repositoryId: z.number() }),
284
+ },
285
+ invoke: async (ctx: any, args: any) => {
286
+ const body = await runResourceAction(ctx, gitActions.branches, args, {
287
+ resource: 'gitManager',
288
+ action: 'branches',
289
+ });
290
+ return body?.data ?? body;
291
+ },
292
+ },
293
+ {
294
+ scope: 'GENERAL',
295
+ execution: 'backend',
296
+ defaultPermission: 'ALLOW',
297
+ silence: false,
298
+ introduction: { title: 'Git: List recent commits' },
299
+ definition: {
300
+ name: 'git_list_commits',
301
+ description: 'List recent commits in a cloned repository, optionally scoped to a single file.',
302
+ schema: z.object({
303
+ repositoryId: z.number(),
304
+ maxCount: z.number().optional(),
305
+ file: z.string().optional(),
306
+ }),
307
+ },
308
+ invoke: async (ctx: any, args: any) => {
309
+ const body = await runResourceAction(ctx, gitActions.log, args, {
310
+ resource: 'gitManager',
311
+ action: 'log',
312
+ });
313
+ return body?.data ?? body;
314
+ },
315
+ },
316
+ ]);
317
+
318
+ app.log?.info?.('plugin-git-manager: registered git_* AI tools for code review');
319
+ }