plugin-git-manager 1.2.12 → 1.2.13

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.
@@ -25,10 +25,11 @@ const REVIEW_QUEUE_REDIS_CONNECTION = 'plugin-git-manager.review.queue';
25
25
  interface TriggerArgs {
26
26
  flowId?: number | null;
27
27
  repositoryId: number;
28
- targetType: 'mr' | 'commit' | 'branch';
28
+ targetType: 'mr' | 'commit' | 'branch' | 'folder';
29
29
  mrIid?: number | null;
30
30
  commitSha?: string | null;
31
31
  branch?: string | null;
32
+ folderPath?: string | null;
32
33
  headSha?: string | null;
33
34
  extraInstructions?: string;
34
35
  triggeredBy?: 'manual' | 'poll';
@@ -47,10 +48,11 @@ interface ReviewFlowSnapshot {
47
48
  interface ReviewQueueMessage {
48
49
  reviewId: number;
49
50
  repositoryId: number;
50
- targetType: 'mr' | 'commit' | 'branch';
51
+ targetType: 'mr' | 'commit' | 'branch' | 'folder';
51
52
  mrIid?: number | null;
52
53
  commitSha?: string | null;
53
54
  branch?: string | null;
55
+ folderPath?: string | null;
54
56
  headSha?: string | null;
55
57
  aiEmployeeUsername: string;
56
58
  extraInstructions?: string;
@@ -90,6 +92,9 @@ function getActionParams(ctx: Context) {
90
92
  function targetKey(args: TriggerArgs): string {
91
93
  if (args.targetType === 'mr') return `${args.repositoryId}:mr:${args.mrIid}`;
92
94
  if (args.targetType === 'commit') return `${args.repositoryId}:commit:${args.commitSha}`;
95
+ if (args.targetType === 'folder') {
96
+ return `${args.repositoryId}:folder:${args.branch || 'HEAD'}:${args.folderPath || '/'}`;
97
+ }
93
98
  return `${args.repositoryId}:branch:${args.branch}`;
94
99
  }
95
100
 
@@ -107,14 +112,18 @@ async function withTriggerLock<T>(app: Application, key: string, fn: () => Promi
107
112
  */
108
113
  export async function triggerReview(ctx: Context, next: () => Promise<void>) {
109
114
  const params = getActionParams(ctx);
110
- const { flowId, repositoryId, targetType, mrIid, commitSha, branch, extraInstructions } = params;
115
+ const { flowId, repositoryId, targetType, mrIid, commitSha, branch, folderPath, extraInstructions } = params;
111
116
 
112
117
  if (!repositoryId) ctx.throw(400, 'repositoryId is required');
113
118
  if (!targetType) ctx.throw(400, 'targetType is required');
114
- if (!['mr', 'commit', 'branch'].includes(targetType)) ctx.throw(400, 'invalid targetType');
119
+ if (!['mr', 'commit', 'branch', 'folder'].includes(targetType)) ctx.throw(400, 'invalid targetType');
115
120
  if (targetType === 'mr' && !mrIid) ctx.throw(400, 'mrIid is required for MR review');
116
121
  if (targetType === 'commit' && !commitSha) ctx.throw(400, 'commitSha is required for commit review');
117
122
  if (targetType === 'branch' && !branch) ctx.throw(400, 'branch is required for branch review');
123
+ if (targetType === 'folder') {
124
+ if (typeof folderPath !== 'string') ctx.throw(400, 'folderPath is required for folder review');
125
+ if (folderPath.includes('..')) ctx.throw(400, 'Invalid folder path');
126
+ }
118
127
 
119
128
  const userId = (ctx as any).state?.currentUser?.id;
120
129
  try {
@@ -125,6 +134,7 @@ export async function triggerReview(ctx: Context, next: () => Promise<void>) {
125
134
  mrIid: mrIid != null ? Number(mrIid) : null,
126
135
  commitSha: commitSha || null,
127
136
  branch: branch || null,
137
+ folderPath: targetType === 'folder' ? folderPath : null,
128
138
  extraInstructions,
129
139
  triggeredBy: 'manual',
130
140
  userId,
@@ -194,6 +204,10 @@ async function triggerReviewInternalLocked(app: Application, args: TriggerArgs):
194
204
  if (args.targetType === 'mr') targetFilter.mrIid = args.mrIid;
195
205
  else if (args.targetType === 'commit') targetFilter.commitSha = args.commitSha;
196
206
  else if (args.targetType === 'branch') targetFilter.branch = args.branch;
207
+ else if (args.targetType === 'folder') {
208
+ targetFilter.folderPath = args.folderPath ?? '';
209
+ targetFilter.branch = args.branch || null;
210
+ }
197
211
 
198
212
  const existing = await reviewsRepo.findOne({ filter: targetFilter });
199
213
  // Preserve a poller-tracked latestSha if we don't have a fresher one.
@@ -205,6 +219,7 @@ async function triggerReviewInternalLocked(app: Application, args: TriggerArgs):
205
219
  mrIid: args.targetType === 'mr' ? args.mrIid : null,
206
220
  commitSha: args.targetType === 'commit' ? args.commitSha : null,
207
221
  branch: args.branch || null,
222
+ folderPath: args.targetType === 'folder' ? args.folderPath ?? '' : null,
208
223
  headSha: headSha,
209
224
  latestSha: headSha || existingLatestSha || null,
210
225
  triggeredBy: args.triggeredBy || 'manual',
@@ -254,6 +269,7 @@ async function triggerReviewInternalLocked(app: Application, args: TriggerArgs):
254
269
  mrIid: args.targetType === 'mr' ? args.mrIid : null,
255
270
  commitSha: args.targetType === 'commit' ? args.commitSha : null,
256
271
  branch: args.branch || undefined,
272
+ folderPath: args.targetType === 'folder' ? args.folderPath ?? '' : null,
257
273
  headSha,
258
274
  aiEmployeeUsername,
259
275
  extraInstructions: args.extraInstructions,
@@ -485,14 +501,15 @@ function toNullableNumber(value: any): number | null {
485
501
 
486
502
  function createReviewQueueMessageFromReview(review: any): ReviewQueueMessage {
487
503
  const metadata = getQueuedReviewMetadata(review);
488
- const targetType = review.get('targetType') as 'mr' | 'commit' | 'branch';
504
+ const targetType = review.get('targetType') as 'mr' | 'commit' | 'branch' | 'folder';
489
505
  return {
490
506
  reviewId: Number(review.get('id')),
491
507
  repositoryId: Number(review.get('repositoryId')),
492
508
  targetType,
493
509
  mrIid: targetType === 'mr' ? toNullableNumber(review.get('mrIid')) : null,
494
510
  commitSha: targetType === 'commit' ? (review.get('commitSha') as string | null) : null,
495
- branch: targetType === 'branch' ? (review.get('branch') as string | null) : null,
511
+ branch: targetType === 'branch' || targetType === 'folder' ? (review.get('branch') as string | null) : null,
512
+ folderPath: targetType === 'folder' ? (review.get('folderPath') as string | null) ?? '' : null,
496
513
  headSha: review.get('headSha') as string | null,
497
514
  aiEmployeeUsername: metadata.aiEmployeeUsername || '',
498
515
  extraInstructions: metadata.extraInstructions || undefined,
@@ -584,7 +601,7 @@ async function processQueuedReview(app: Application, message: ReviewQueueMessage
584
601
  }
585
602
 
586
603
  const metadata = getQueuedReviewMetadata(review);
587
- const targetType = (message.targetType || review.get('targetType')) as 'mr' | 'commit' | 'branch';
604
+ const targetType = (message.targetType || review.get('targetType')) as 'mr' | 'commit' | 'branch' | 'folder';
588
605
 
589
606
  try {
590
607
  const repo = await db.getRepository('gitRepositories').findOne({
@@ -609,6 +626,8 @@ async function processQueuedReview(app: Application, message: ReviewQueueMessage
609
626
  mrIid: targetType === 'mr' ? message.mrIid ?? toNullableNumber(review.get('mrIid')) : null,
610
627
  commitSha: targetType === 'commit' ? message.commitSha || (review.get('commitSha') as string) : null,
611
628
  branch: message.branch || (review.get('branch') as string | undefined),
629
+ folderPath:
630
+ targetType === 'folder' ? message.folderPath ?? (review.get('folderPath') as string | null) ?? '' : null,
612
631
  headSha: message.headSha || (review.get('headSha') as string | null),
613
632
  aiEmployeeUsername,
614
633
  extraInstructions: message.extraInstructions ?? metadata.extraInstructions ?? undefined,
@@ -699,6 +718,7 @@ interface RunReviewArgs {
699
718
  mrIid: number | null;
700
719
  commitSha: string | null;
701
720
  branch?: string;
721
+ folderPath?: string | null;
702
722
  headSha?: string | null;
703
723
  aiEmployeeUsername: string;
704
724
  extraInstructions?: string;
@@ -973,6 +993,28 @@ function buildReviewPrompt(args: RunReviewArgs): string {
973
993
  args.commitSha
974
994
  } to fetch the diff.`,
975
995
  );
996
+ } else if (args.targetType === 'folder') {
997
+ const folderLabel = args.folderPath || '/';
998
+ const ref = args.branch || 'HEAD';
999
+ lines.push(
1000
+ `Target: Folder \`${folderLabel}\` at ref \`${ref}\` — review the FULL current code inside this folder (not a diff).`,
1001
+ );
1002
+ lines.push(
1003
+ 'The repository may contain multiple projects; only review files inside this folder and its subfolders.',
1004
+ );
1005
+ lines.push(
1006
+ `First call \`git_list_files\` with repositoryId=${args.repo.get('id')}, treePath="${
1007
+ args.folderPath || ''
1008
+ }", ref="${ref}", recursive=true to enumerate all files.`,
1009
+ );
1010
+ lines.push(
1011
+ `Then read each file worth reviewing with \`git_get_file_content\` (repositoryId=${args.repo.get(
1012
+ 'id',
1013
+ )}, ref="${ref}").`,
1014
+ );
1015
+ lines.push(
1016
+ 'Prioritize source code and configuration files; skip binaries, images, lock files, and generated/vendored code. If the listing is truncated, focus on the most important files.',
1017
+ );
976
1018
  } else {
977
1019
  lines.push(`Target: Branch ${args.branch}.`);
978
1020
  lines.push(
@@ -1172,6 +1214,8 @@ function getFlowPostMode(flow: any): ReviewPostMode {
1172
1214
  function getInitialPostStatus(flow: any, targetType: string): string {
1173
1215
  const postMode = getFlowPostMode(flow);
1174
1216
  if (postMode === 'disabled') return 'skipped';
1217
+ // Folder reviews have no MR to post to.
1218
+ if (targetType === 'folder') return 'skipped';
1175
1219
  if (postMode === 'auto' && targetType !== 'mr') return 'skipped';
1176
1220
  return 'pending_approval';
1177
1221
  }
@@ -42,10 +42,7 @@ export function registerGitReviewAiTools(app: Application) {
42
42
  }
43
43
  const acl = ctx.app?.acl;
44
44
  if (!acl?.can) return; // ACL not available — fail-open is acceptable for legacy contexts
45
- const role =
46
- ctx?.state?.currentRole ||
47
- (Array.isArray(user.roles) && user.roles[0]?.name) ||
48
- null;
45
+ const role = ctx?.state?.currentRole || (Array.isArray(user.roles) && user.roles[0]?.name) || null;
49
46
  if (!role) {
50
47
  const err: any = new Error('AI tool requires a resolvable role on the current user');
51
48
  err.status = 403;
@@ -243,6 +240,37 @@ export function registerGitReviewAiTools(app: Application) {
243
240
  return body?.data ?? body;
244
241
  },
245
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
+ },
246
274
  {
247
275
  scope: 'GENERAL',
248
276
  execution: 'backend',
@@ -45,6 +45,7 @@ export default defineCollection({
45
45
  { value: 'mr', label: 'Merge Request' },
46
46
  { value: 'commit', label: 'Commit' },
47
47
  { value: 'branch', label: 'Branch' },
48
+ { value: 'folder', label: 'Folder' },
48
49
  ],
49
50
  },
50
51
  },
@@ -66,6 +67,12 @@ export default defineCollection({
66
67
  interface: 'input',
67
68
  uiSchema: { title: 'Branch', type: 'string', 'x-component': 'Input' },
68
69
  },
70
+ {
71
+ type: 'string',
72
+ name: 'folderPath',
73
+ interface: 'input',
74
+ uiSchema: { title: 'Folder Path', type: 'string', 'x-component': 'Input' },
75
+ },
69
76
  {
70
77
  type: 'string',
71
78
  name: 'headSha',