mobbdev 1.0.205 → 1.0.207

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.
@@ -2,7 +2,7 @@ import * as Yargs from 'yargs';
2
2
  import z from 'zod';
3
3
 
4
4
  declare const PromptItemZ: z.ZodObject<{
5
- type: z.ZodEnum<["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]>;
5
+ type: z.ZodEnum<["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION", "AI_THINKING"]>;
6
6
  attachedFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
7
7
  relativePath: z.ZodString;
8
8
  startLine: z.ZodOptional<z.ZodNumber>;
@@ -35,18 +35,26 @@ declare const PromptItemZ: z.ZodObject<{
35
35
  name: string;
36
36
  parameters: string;
37
37
  result: string;
38
- rawArguments?: string | undefined;
39
38
  accepted?: boolean | undefined;
39
+ rawArguments?: string | undefined;
40
40
  }, {
41
41
  name: string;
42
42
  parameters: string;
43
43
  result: string;
44
- rawArguments?: string | undefined;
45
44
  accepted?: boolean | undefined;
45
+ rawArguments?: string | undefined;
46
46
  }>>;
47
47
  }, "strip", z.ZodTypeAny, {
48
- type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
48
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION" | "AI_THINKING";
49
+ tool?: {
50
+ name: string;
51
+ parameters: string;
52
+ result: string;
53
+ accepted?: boolean | undefined;
54
+ rawArguments?: string | undefined;
55
+ } | undefined;
49
56
  date?: Date | undefined;
57
+ text?: string | undefined;
50
58
  attachedFiles?: {
51
59
  relativePath: string;
52
60
  startLine?: number | undefined;
@@ -55,17 +63,17 @@ declare const PromptItemZ: z.ZodObject<{
55
63
  inputCount: number;
56
64
  outputCount: number;
57
65
  } | undefined;
58
- text?: string | undefined;
66
+ }, {
67
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION" | "AI_THINKING";
59
68
  tool?: {
60
69
  name: string;
61
70
  parameters: string;
62
71
  result: string;
63
- rawArguments?: string | undefined;
64
72
  accepted?: boolean | undefined;
73
+ rawArguments?: string | undefined;
65
74
  } | undefined;
66
- }, {
67
- type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
68
75
  date?: Date | undefined;
76
+ text?: string | undefined;
69
77
  attachedFiles?: {
70
78
  relativePath: string;
71
79
  startLine?: number | undefined;
@@ -74,18 +82,10 @@ declare const PromptItemZ: z.ZodObject<{
74
82
  inputCount: number;
75
83
  outputCount: number;
76
84
  } | undefined;
77
- text?: string | undefined;
78
- tool?: {
79
- name: string;
80
- parameters: string;
81
- result: string;
82
- rawArguments?: string | undefined;
83
- accepted?: boolean | undefined;
84
- } | undefined;
85
85
  }>;
86
86
  type PromptItem = z.infer<typeof PromptItemZ>;
87
87
  declare const PromptItemArrayZ: z.ZodArray<z.ZodObject<{
88
- type: z.ZodEnum<["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]>;
88
+ type: z.ZodEnum<["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION", "AI_THINKING"]>;
89
89
  attachedFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
90
90
  relativePath: z.ZodString;
91
91
  startLine: z.ZodOptional<z.ZodNumber>;
@@ -118,18 +118,26 @@ declare const PromptItemArrayZ: z.ZodArray<z.ZodObject<{
118
118
  name: string;
119
119
  parameters: string;
120
120
  result: string;
121
- rawArguments?: string | undefined;
122
121
  accepted?: boolean | undefined;
122
+ rawArguments?: string | undefined;
123
123
  }, {
124
124
  name: string;
125
125
  parameters: string;
126
126
  result: string;
127
- rawArguments?: string | undefined;
128
127
  accepted?: boolean | undefined;
128
+ rawArguments?: string | undefined;
129
129
  }>>;
130
130
  }, "strip", z.ZodTypeAny, {
131
- type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
131
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION" | "AI_THINKING";
132
+ tool?: {
133
+ name: string;
134
+ parameters: string;
135
+ result: string;
136
+ accepted?: boolean | undefined;
137
+ rawArguments?: string | undefined;
138
+ } | undefined;
132
139
  date?: Date | undefined;
140
+ text?: string | undefined;
133
141
  attachedFiles?: {
134
142
  relativePath: string;
135
143
  startLine?: number | undefined;
@@ -138,17 +146,17 @@ declare const PromptItemArrayZ: z.ZodArray<z.ZodObject<{
138
146
  inputCount: number;
139
147
  outputCount: number;
140
148
  } | undefined;
141
- text?: string | undefined;
149
+ }, {
150
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION" | "AI_THINKING";
142
151
  tool?: {
143
152
  name: string;
144
153
  parameters: string;
145
154
  result: string;
146
- rawArguments?: string | undefined;
147
155
  accepted?: boolean | undefined;
156
+ rawArguments?: string | undefined;
148
157
  } | undefined;
149
- }, {
150
- type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
151
158
  date?: Date | undefined;
159
+ text?: string | undefined;
152
160
  attachedFiles?: {
153
161
  relativePath: string;
154
162
  startLine?: number | undefined;
@@ -157,14 +165,6 @@ declare const PromptItemArrayZ: z.ZodArray<z.ZodObject<{
157
165
  inputCount: number;
158
166
  outputCount: number;
159
167
  } | undefined;
160
- text?: string | undefined;
161
- tool?: {
162
- name: string;
163
- parameters: string;
164
- result: string;
165
- rawArguments?: string | undefined;
166
- accepted?: boolean | undefined;
167
- } | undefined;
168
168
  }>, "many">;
169
169
  type PromptItemArray = z.infer<typeof PromptItemArrayZ>;
170
170
  type UploadAiBlameOptions = {
@@ -5563,7 +5563,7 @@ async function createAuthenticatedMcpGQLClient({
5563
5563
 
5564
5564
  // src/args/commands/upload_ai_blame.ts
5565
5565
  var PromptItemZ = z27.object({
5566
- type: z27.enum(["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]),
5566
+ type: z27.enum(["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION", "AI_THINKING"]),
5567
5567
  attachedFiles: z27.array(
5568
5568
  z27.object({
5569
5569
  relativePath: z27.string(),
package/dist/index.mjs CHANGED
@@ -7354,6 +7354,7 @@ var GET_BLAME_DOCUMENT = `
7354
7354
  blame(path: $path) {
7355
7355
  ranges {
7356
7356
  commit {
7357
+ oid
7357
7358
  author {
7358
7359
  user {
7359
7360
  name
@@ -7368,7 +7369,7 @@ var GET_BLAME_DOCUMENT = `
7368
7369
  }
7369
7370
  }
7370
7371
  }
7371
-
7372
+
7372
7373
  }
7373
7374
  }
7374
7375
  }
@@ -7776,6 +7777,7 @@ function getGithubSdk(params = {}) {
7776
7777
  (range) => ({
7777
7778
  startingLine: range.startingLine,
7778
7779
  endingLine: range.endingLine,
7780
+ commitSha: range.commit.oid,
7779
7781
  email: range.commit.author.user?.email || "",
7780
7782
  name: range.commit.author.user?.name || "",
7781
7783
  login: range.commit.author.user?.login || ""
@@ -7925,6 +7927,14 @@ function getGithubSdk(params = {}) {
7925
7927
  direction: "desc",
7926
7928
  per_page: 100
7927
7929
  });
7930
+ },
7931
+ async listPRFiles(params2) {
7932
+ return octokit.rest.pulls.listFiles({
7933
+ owner: params2.owner,
7934
+ repo: params2.repo,
7935
+ pull_number: params2.pull_number,
7936
+ per_page: 100
7937
+ });
7928
7938
  }
7929
7939
  };
7930
7940
  }
@@ -8207,24 +8217,21 @@ var GithubSCMLib = class extends SCMLib {
8207
8217
  this._validateAccessTokenAndUrl();
8208
8218
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
8209
8219
  const prNumber = Number(submitRequestId);
8210
- const prRes = await this.githubSdk.getPr({
8211
- owner,
8212
- repo,
8213
- pull_number: prNumber
8214
- });
8215
- const prDiff = await this.getPrDiff({ pull_number: prNumber });
8216
- const commitsRes = await this.githubSdk.getPrCommits({
8217
- owner,
8218
- repo,
8219
- pull_number: prNumber
8220
- });
8221
- const commits = [];
8222
- for (const commit of commitsRes.data) {
8223
- const commitDiff = await this.getCommitDiff(commit.sha);
8224
- commits.push(commitDiff);
8225
- }
8220
+ const [prRes, commitsRes, filesRes] = await Promise.all([
8221
+ this.githubSdk.getPr({ owner, repo, pull_number: prNumber }),
8222
+ this.githubSdk.getPrCommits({ owner, repo, pull_number: prNumber }),
8223
+ this.githubSdk.listPRFiles({ owner, repo, pull_number: prNumber })
8224
+ ]);
8226
8225
  const pr = prRes.data;
8227
- const diffLines = this._calculateDiffLineAttributions(prDiff, commits);
8226
+ const prDiff = await this.getPrDiff({ pull_number: prNumber });
8227
+ const commits = await Promise.all(
8228
+ commitsRes.data.map((commit) => this.getCommitDiff(commit.sha))
8229
+ );
8230
+ const diffLines = await this._attributeLinesViaBlame(
8231
+ pr.head.ref,
8232
+ filesRes.data,
8233
+ commits
8234
+ );
8228
8235
  return {
8229
8236
  diff: prDiff,
8230
8237
  createdAt: new Date(pr.created_at),
@@ -8344,18 +8351,15 @@ var GithubSCMLib = class extends SCMLib {
8344
8351
  return { added: 0, removed: 0 };
8345
8352
  }
8346
8353
  }
8347
- _calculateDiffLineAttributions(prDiff, commits) {
8348
- const attributions = [];
8349
- const prDiffLines = prDiff.split("\n");
8350
- let currentFile = "";
8354
+ /**
8355
+ * Optimized helper to parse added line numbers from a unified diff patch
8356
+ * Single-pass parsing for minimal CPU usage
8357
+ */
8358
+ _parseAddedLinesFromPatch(patch) {
8359
+ const addedLines = [];
8360
+ const lines = patch.split("\n");
8351
8361
  let currentLineNumber = 0;
8352
- for (const line of prDiffLines) {
8353
- if (line.startsWith("+++")) {
8354
- const match = line.match(/^\+\+\+ b\/(.+)$/);
8355
- currentFile = match?.[1] || "";
8356
- currentLineNumber = 0;
8357
- continue;
8358
- }
8362
+ for (const line of lines) {
8359
8363
  if (line.startsWith("@@")) {
8360
8364
  const match = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)/);
8361
8365
  if (match?.[1]) {
@@ -8364,122 +8368,57 @@ var GithubSCMLib = class extends SCMLib {
8364
8368
  continue;
8365
8369
  }
8366
8370
  if (line.startsWith("+") && !line.startsWith("+++")) {
8367
- const commitSha = this._findCommitForLine(
8368
- currentFile,
8369
- currentLineNumber,
8370
- line.substring(1),
8371
- // Remove the '+' prefix
8372
- commits
8373
- );
8374
- if (commitSha && currentFile) {
8375
- attributions.push({
8376
- file: currentFile,
8377
- line: currentLineNumber,
8378
- commitSha
8379
- });
8380
- }
8371
+ addedLines.push(currentLineNumber);
8381
8372
  currentLineNumber++;
8382
8373
  } else if (!line.startsWith("-")) {
8383
8374
  currentLineNumber++;
8384
8375
  }
8385
8376
  }
8386
- return attributions;
8377
+ return addedLines;
8387
8378
  }
8388
- _findCommitForLine(file, lineNumber, lineContent, commits) {
8389
- const normalizedContent = lineContent.trim();
8390
- for (let i = commits.length - 1; i >= 0; i--) {
8391
- const commit = commits[i];
8392
- if (!commit) {
8393
- continue;
8394
- }
8395
- const commitLines = commit.diff.split("\n");
8396
- let commitCurrentFile = "";
8397
- for (const commitLine of commitLines) {
8398
- if (commitLine.startsWith("+++")) {
8399
- const match = commitLine.match(/^\+\+\+ b\/(.+)$/);
8400
- commitCurrentFile = match?.[1] || "";
8401
- continue;
8402
- }
8403
- if (commitLine.startsWith("@@")) {
8379
+ /**
8380
+ * Attribute lines in a single file to their commits using blame
8381
+ */
8382
+ async _attributeFileLines(file, headRef, prCommitShas) {
8383
+ try {
8384
+ const blame = await this.getRepoBlameRanges(headRef, file.filename);
8385
+ const addedLines = this._parseAddedLinesFromPatch(file.patch);
8386
+ const addedLinesSet = new Set(addedLines);
8387
+ const fileAttributions = [];
8388
+ for (const blameRange of blame) {
8389
+ if (!prCommitShas.has(blameRange.commitSha)) {
8404
8390
  continue;
8405
8391
  }
8406
- if (commitCurrentFile === file && commitLine.startsWith("+") && !commitLine.startsWith("+++")) {
8407
- const commitLineContent = commitLine.substring(1).trim();
8408
- if (commitLineContent === normalizedContent) {
8409
- return commit.commitSha;
8392
+ for (let lineNum = blameRange.startingLine; lineNum <= blameRange.endingLine; lineNum++) {
8393
+ if (addedLinesSet.has(lineNum)) {
8394
+ fileAttributions.push({
8395
+ file: file.filename,
8396
+ line: lineNum,
8397
+ commitSha: blameRange.commitSha
8398
+ });
8410
8399
  }
8411
8400
  }
8412
8401
  }
8402
+ return fileAttributions;
8403
+ } catch (error) {
8404
+ return [];
8413
8405
  }
8414
- for (let i = commits.length - 1; i >= 0; i--) {
8415
- const commit = commits[i];
8416
- if (!commit) {
8417
- continue;
8418
- }
8419
- const addedLinesInFile = this._getAddedLinesFromCommit(commit, file);
8420
- for (const { lineNum, content } of addedLinesInFile) {
8421
- if (Math.abs(lineNum - lineNumber) <= 10 && this._contentSimilarity(content, normalizedContent) > 0.9) {
8422
- return commit.commitSha;
8423
- }
8424
- }
8425
- }
8426
- const lastCommit = commits[commits.length - 1];
8427
- return lastCommit ? lastCommit.commitSha : null;
8428
- }
8429
- _getAddedLinesFromCommit(commit, targetFile) {
8430
- const addedLines = [];
8431
- const commitLines = commit.diff.split("\n");
8432
- let currentFile = "";
8433
- let currentLineNumber = 0;
8434
- for (const line of commitLines) {
8435
- if (line.startsWith("+++")) {
8436
- const match = line.match(/^\+\+\+ b\/(.+)$/);
8437
- currentFile = match?.[1] || "";
8438
- currentLineNumber = 0;
8439
- continue;
8440
- }
8441
- if (line.startsWith("@@")) {
8442
- const match = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)/);
8443
- if (match?.[1]) {
8444
- currentLineNumber = parseInt(match[1], 10);
8445
- }
8446
- continue;
8447
- }
8448
- if (currentFile === targetFile && line.startsWith("+") && !line.startsWith("+++")) {
8449
- addedLines.push({
8450
- lineNum: currentLineNumber,
8451
- content: line.substring(1).trim()
8452
- });
8453
- currentLineNumber++;
8454
- } else if (!line.startsWith("-")) {
8455
- if (currentFile === targetFile) {
8456
- currentLineNumber++;
8457
- }
8458
- }
8459
- }
8460
- return addedLines;
8461
8406
  }
8462
- _contentSimilarity(content1, content2) {
8463
- if (content1 === content2) {
8464
- return 1;
8465
- }
8466
- const normalized1 = content1.replace(/\s+/g, " ");
8467
- const normalized2 = content2.replace(/\s+/g, " ");
8468
- if (normalized1 === normalized2) {
8469
- return 0.95;
8470
- }
8471
- const longer = normalized1.length > normalized2.length ? normalized1 : normalized2;
8472
- const shorter = normalized1.length > normalized2.length ? normalized2 : normalized1;
8473
- if (longer.length === 0) {
8474
- return 1;
8475
- }
8476
- if (longer.includes(shorter)) {
8477
- return shorter.length / longer.length;
8478
- }
8479
- const set1 = new Set(normalized1.split(""));
8480
- const set2 = new Set(normalized2.split(""));
8481
- const intersection = new Set([...set1].filter((x) => set2.has(x)));
8482
- return intersection.size / Math.max(set1.size, set2.size);
8407
+ /**
8408
+ * Optimized helper to attribute PR lines to commits using blame API
8409
+ * Parallel blame queries for minimal API call time
8410
+ */
8411
+ async _attributeLinesViaBlame(headRef, changedFiles, prCommits) {
8412
+ const prCommitShas = new Set(prCommits.map((c) => c.commitSha));
8413
+ const filesWithAdditions = changedFiles.filter(
8414
+ (file) => file.patch?.includes("\n+")
8415
+ );
8416
+ const attributions = await Promise.all(
8417
+ filesWithAdditions.map(
8418
+ (file) => this._attributeFileLines(file, headRef, prCommitShas)
8419
+ )
8420
+ );
8421
+ return attributions.flat();
8483
8422
  }
8484
8423
  };
8485
8424
 
@@ -8828,6 +8767,7 @@ async function getGitlabBlameRanges({ ref, gitlabUrl, path: path17 }, options) {
8828
8767
  return {
8829
8768
  startingLine: oldLineNumber,
8830
8769
  endingLine: lineNumber - 1,
8770
+ commitSha: range.commit.id,
8831
8771
  login: range.commit.author_email,
8832
8772
  email: range.commit.author_email,
8833
8773
  name: range.commit.author_name
@@ -19232,7 +19172,7 @@ import chalk10 from "chalk";
19232
19172
  import { withFile } from "tmp-promise";
19233
19173
  import z38 from "zod";
19234
19174
  var PromptItemZ = z38.object({
19235
- type: z38.enum(["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]),
19175
+ type: z38.enum(["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION", "AI_THINKING"]),
19236
19176
  attachedFiles: z38.array(
19237
19177
  z38.object({
19238
19178
  relativePath: z38.string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "1.0.205",
3
+ "version": "1.0.207",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "repository": "git+https://github.com/mobb-dev/bugsy.git",
6
6
  "main": "dist/index.mjs",