mobbdev 1.0.203 → 1.0.205

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.
@@ -1,5 +1,172 @@
1
1
  import * as Yargs from 'yargs';
2
+ import z from 'zod';
2
3
 
4
+ declare const PromptItemZ: z.ZodObject<{
5
+ type: z.ZodEnum<["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]>;
6
+ attachedFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
7
+ relativePath: z.ZodString;
8
+ startLine: z.ZodOptional<z.ZodNumber>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ relativePath: string;
11
+ startLine?: number | undefined;
12
+ }, {
13
+ relativePath: string;
14
+ startLine?: number | undefined;
15
+ }>, "many">>;
16
+ tokens: z.ZodOptional<z.ZodObject<{
17
+ inputCount: z.ZodNumber;
18
+ outputCount: z.ZodNumber;
19
+ }, "strip", z.ZodTypeAny, {
20
+ inputCount: number;
21
+ outputCount: number;
22
+ }, {
23
+ inputCount: number;
24
+ outputCount: number;
25
+ }>>;
26
+ text: z.ZodOptional<z.ZodString>;
27
+ date: z.ZodOptional<z.ZodDate>;
28
+ tool: z.ZodOptional<z.ZodObject<{
29
+ name: z.ZodString;
30
+ parameters: z.ZodString;
31
+ result: z.ZodString;
32
+ rawArguments: z.ZodOptional<z.ZodString>;
33
+ accepted: z.ZodOptional<z.ZodBoolean>;
34
+ }, "strip", z.ZodTypeAny, {
35
+ name: string;
36
+ parameters: string;
37
+ result: string;
38
+ rawArguments?: string | undefined;
39
+ accepted?: boolean | undefined;
40
+ }, {
41
+ name: string;
42
+ parameters: string;
43
+ result: string;
44
+ rawArguments?: string | undefined;
45
+ accepted?: boolean | undefined;
46
+ }>>;
47
+ }, "strip", z.ZodTypeAny, {
48
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
49
+ date?: Date | undefined;
50
+ attachedFiles?: {
51
+ relativePath: string;
52
+ startLine?: number | undefined;
53
+ }[] | undefined;
54
+ tokens?: {
55
+ inputCount: number;
56
+ outputCount: number;
57
+ } | undefined;
58
+ text?: string | undefined;
59
+ tool?: {
60
+ name: string;
61
+ parameters: string;
62
+ result: string;
63
+ rawArguments?: string | undefined;
64
+ accepted?: boolean | undefined;
65
+ } | undefined;
66
+ }, {
67
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
68
+ date?: Date | undefined;
69
+ attachedFiles?: {
70
+ relativePath: string;
71
+ startLine?: number | undefined;
72
+ }[] | undefined;
73
+ tokens?: {
74
+ inputCount: number;
75
+ outputCount: number;
76
+ } | 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
+ }>;
86
+ type PromptItem = z.infer<typeof PromptItemZ>;
87
+ declare const PromptItemArrayZ: z.ZodArray<z.ZodObject<{
88
+ type: z.ZodEnum<["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]>;
89
+ attachedFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
90
+ relativePath: z.ZodString;
91
+ startLine: z.ZodOptional<z.ZodNumber>;
92
+ }, "strip", z.ZodTypeAny, {
93
+ relativePath: string;
94
+ startLine?: number | undefined;
95
+ }, {
96
+ relativePath: string;
97
+ startLine?: number | undefined;
98
+ }>, "many">>;
99
+ tokens: z.ZodOptional<z.ZodObject<{
100
+ inputCount: z.ZodNumber;
101
+ outputCount: z.ZodNumber;
102
+ }, "strip", z.ZodTypeAny, {
103
+ inputCount: number;
104
+ outputCount: number;
105
+ }, {
106
+ inputCount: number;
107
+ outputCount: number;
108
+ }>>;
109
+ text: z.ZodOptional<z.ZodString>;
110
+ date: z.ZodOptional<z.ZodDate>;
111
+ tool: z.ZodOptional<z.ZodObject<{
112
+ name: z.ZodString;
113
+ parameters: z.ZodString;
114
+ result: z.ZodString;
115
+ rawArguments: z.ZodOptional<z.ZodString>;
116
+ accepted: z.ZodOptional<z.ZodBoolean>;
117
+ }, "strip", z.ZodTypeAny, {
118
+ name: string;
119
+ parameters: string;
120
+ result: string;
121
+ rawArguments?: string | undefined;
122
+ accepted?: boolean | undefined;
123
+ }, {
124
+ name: string;
125
+ parameters: string;
126
+ result: string;
127
+ rawArguments?: string | undefined;
128
+ accepted?: boolean | undefined;
129
+ }>>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
132
+ date?: Date | undefined;
133
+ attachedFiles?: {
134
+ relativePath: string;
135
+ startLine?: number | undefined;
136
+ }[] | undefined;
137
+ tokens?: {
138
+ inputCount: number;
139
+ outputCount: number;
140
+ } | undefined;
141
+ text?: string | undefined;
142
+ tool?: {
143
+ name: string;
144
+ parameters: string;
145
+ result: string;
146
+ rawArguments?: string | undefined;
147
+ accepted?: boolean | undefined;
148
+ } | undefined;
149
+ }, {
150
+ type: "USER_PROMPT" | "AI_RESPONSE" | "TOOL_EXECUTION";
151
+ date?: Date | undefined;
152
+ attachedFiles?: {
153
+ relativePath: string;
154
+ startLine?: number | undefined;
155
+ }[] | undefined;
156
+ tokens?: {
157
+ inputCount: number;
158
+ outputCount: number;
159
+ } | 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
+ }>, "many">;
169
+ type PromptItemArray = z.infer<typeof PromptItemArrayZ>;
3
170
  type UploadAiBlameOptions = {
4
171
  prompt: string[];
5
172
  inference: string[];
@@ -10,6 +177,13 @@ type UploadAiBlameOptions = {
10
177
  'tool-name'?: string[];
11
178
  };
12
179
  declare function uploadAiBlameBuilder(args: Yargs.Argv<unknown>): Yargs.Argv<UploadAiBlameOptions>;
13
- declare function uploadAiBlameHandler(args: UploadAiBlameOptions): Promise<void>;
180
+ declare function uploadAiBlameHandlerFromExtension(args: {
181
+ prompts: PromptItemArray;
182
+ inference: string;
183
+ model: string;
184
+ tool: string;
185
+ responseTime: string;
186
+ }): Promise<void>;
187
+ declare function uploadAiBlameHandler(args: UploadAiBlameOptions, exitOnError?: boolean): Promise<void>;
14
188
 
15
- export { type UploadAiBlameOptions, uploadAiBlameBuilder, uploadAiBlameHandler };
189
+ export { type PromptItem, type PromptItemArray, type UploadAiBlameOptions, uploadAiBlameBuilder, uploadAiBlameHandler, uploadAiBlameHandlerFromExtension };
@@ -92,62 +92,16 @@ var init_GitService = __esm({
92
92
  });
93
93
 
94
94
  // src/args/commands/upload_ai_blame.ts
95
- import fs5 from "fs/promises";
95
+ import fsPromises2 from "fs/promises";
96
96
  import path6 from "path";
97
97
  import chalk2 from "chalk";
98
+ import { withFile } from "tmp-promise";
99
+ import z27 from "zod";
98
100
 
99
101
  // src/features/analysis/upload-file.ts
100
102
  import Debug7 from "debug";
101
103
  import fetch3, { File, fileFrom, FormData } from "node-fetch";
102
104
 
103
- // src/utils/dirname.ts
104
- import fs from "fs";
105
- import path from "path";
106
- import { fileURLToPath } from "url";
107
- function getModuleRootDir() {
108
- let manifestDir = getDirName();
109
- for (let i = 0; i < 10; i++) {
110
- const manifestPath = path.join(manifestDir, "package.json");
111
- if (fs.existsSync(manifestPath)) {
112
- return manifestDir;
113
- }
114
- manifestDir = path.join(manifestDir, "..");
115
- }
116
- throw new Error("Cannot locate package.json file");
117
- }
118
- function getDirName() {
119
- return path.dirname(fileURLToPath(import.meta.url));
120
- }
121
-
122
- // src/utils/keypress.ts
123
- import readline from "readline";
124
-
125
- // src/utils/spinner.ts
126
- import {
127
- createSpinner as _createSpinner
128
- } from "nanospinner";
129
-
130
- // src/utils/check_node_version.ts
131
- import fs2 from "fs";
132
- import path2 from "path";
133
- import semver from "semver";
134
- function getPackageJson() {
135
- return JSON.parse(
136
- fs2.readFileSync(path2.join(getModuleRootDir(), "package.json"), "utf8")
137
- );
138
- }
139
- var packageJson = getPackageJson();
140
- if (!semver.satisfies(process.version, packageJson.engines.node)) {
141
- console.error(
142
- `
143
- \u26A0\uFE0F ${packageJson.name} requires node version ${packageJson.engines.node}, but running ${process.version}.`
144
- );
145
- process.exit(1);
146
- }
147
-
148
- // src/utils/index.ts
149
- var sleep = (ms = 2e3) => new Promise((r) => setTimeout(r, ms));
150
-
151
105
  // src/features/analysis/graphql/gql.ts
152
106
  import fetchOrig from "cross-fetch";
153
107
  import Debug6 from "debug";
@@ -157,7 +111,7 @@ import { HttpsProxyAgent as HttpsProxyAgent2 } from "https-proxy-agent";
157
111
  import { v4 as uuidv4 } from "uuid";
158
112
 
159
113
  // src/constants.ts
160
- import path3 from "path";
114
+ import path2 from "path";
161
115
  import chalk from "chalk";
162
116
  import Debug from "debug";
163
117
  import * as dotenv from "dotenv";
@@ -2098,9 +2052,48 @@ var ScmType = /* @__PURE__ */ ((ScmType2) => {
2098
2052
  return ScmType2;
2099
2053
  })(ScmType || {});
2100
2054
 
2055
+ // src/utils/dirname.ts
2056
+ import fs from "fs";
2057
+ import path from "path";
2058
+ import { fileURLToPath } from "url";
2059
+ function getModuleRootDir() {
2060
+ let manifestDir = getDirName();
2061
+ for (let i = 0; i < 10; i++) {
2062
+ const manifestPath = path.join(manifestDir, "package.json");
2063
+ if (fs.existsSync(manifestPath)) {
2064
+ return manifestDir;
2065
+ }
2066
+ manifestDir = path.join(manifestDir, "..");
2067
+ }
2068
+ throw new Error("Cannot locate package.json file");
2069
+ }
2070
+ function getDirName() {
2071
+ if (typeof __filename !== "undefined") {
2072
+ return path.dirname(__filename);
2073
+ } else {
2074
+ try {
2075
+ const getImportMetaUrl = new Function("return import.meta.url");
2076
+ const importMetaUrl = getImportMetaUrl();
2077
+ return path.dirname(fileURLToPath(importMetaUrl));
2078
+ } catch (e) {
2079
+ try {
2080
+ const err = new Error();
2081
+ const stack = err.stack || "";
2082
+ const match = stack.match(/file:\/\/[^\s)]+/);
2083
+ if (match) {
2084
+ const fileUrl = match[0];
2085
+ return path.dirname(fileURLToPath(fileUrl));
2086
+ }
2087
+ } catch {
2088
+ }
2089
+ throw new Error("Unable to determine directory name in this environment");
2090
+ }
2091
+ }
2092
+ }
2093
+
2101
2094
  // src/constants.ts
2102
2095
  var debug = Debug("mobbdev:constants");
2103
- dotenv.config({ path: path3.join(getModuleRootDir(), ".env") });
2096
+ dotenv.config({ path: path2.join(getModuleRootDir(), ".env") });
2104
2097
  var scmFriendlyText = {
2105
2098
  ["Ado" /* Ado */]: "Azure DevOps",
2106
2099
  ["Bitbucket" /* Bitbucket */]: "Bitbucket",
@@ -2184,6 +2177,35 @@ var FailedToGetApiTokenError = class extends Error {
2184
2177
  }
2185
2178
  };
2186
2179
 
2180
+ // src/utils/keypress.ts
2181
+ import readline from "readline";
2182
+
2183
+ // src/utils/spinner.ts
2184
+ import {
2185
+ createSpinner as _createSpinner
2186
+ } from "nanospinner";
2187
+
2188
+ // src/utils/check_node_version.ts
2189
+ import fs2 from "fs";
2190
+ import path3 from "path";
2191
+ import semver from "semver";
2192
+ function getPackageJson() {
2193
+ return JSON.parse(
2194
+ fs2.readFileSync(path3.join(getModuleRootDir(), "package.json"), "utf8")
2195
+ );
2196
+ }
2197
+ var packageJson = getPackageJson();
2198
+ if (!semver.satisfies(process.version, packageJson.engines.node)) {
2199
+ console.error(
2200
+ `
2201
+ \u26A0\uFE0F ${packageJson.name} requires node version ${packageJson.engines.node}, but running ${process.version}.`
2202
+ );
2203
+ process.exit(1);
2204
+ }
2205
+
2206
+ // src/utils/index.ts
2207
+ var sleep = (ms = 2e3) => new Promise((r) => setTimeout(r, ms));
2208
+
2187
2209
  // src/features/analysis/scm/utils/index.ts
2188
2210
  import { z as z15 } from "zod";
2189
2211
 
@@ -4314,7 +4336,11 @@ function createWSClient(options) {
4314
4336
  );
4315
4337
  const CustomWebSocket = class extends WebSocket {
4316
4338
  constructor(address, protocols) {
4317
- super(address, protocols, proxy ? { agent: proxy } : void 0);
4339
+ super(
4340
+ address,
4341
+ protocols,
4342
+ proxy ? { agent: proxy } : void 0
4343
+ );
4318
4344
  }
4319
4345
  };
4320
4346
  return createClient({
@@ -4809,8 +4835,8 @@ var GetLatestReportByRepoUrlResponseSchema = z26.object({
4809
4835
  });
4810
4836
 
4811
4837
  // src/mcp/services/ConfigStoreService.ts
4812
- init_configs();
4813
4838
  import Configstore2 from "configstore";
4839
+ init_configs();
4814
4840
  function createConfigStore(defaultValues = { apiToken: "" }) {
4815
4841
  const API_URL2 = process.env["API_URL"] || MCP_DEFAULT_API_URL;
4816
4842
  let domain = "";
@@ -4834,8 +4860,8 @@ var configStore = getConfigStore();
4834
4860
  // src/mcp/services/McpAuthService.ts
4835
4861
  import crypto from "crypto";
4836
4862
  import os from "os";
4837
- init_configs();
4838
4863
  import open from "open";
4864
+ init_configs();
4839
4865
  var McpAuthService = class {
4840
4866
  constructor(client) {
4841
4867
  __publicField(this, "client");
@@ -5536,6 +5562,29 @@ async function createAuthenticatedMcpGQLClient({
5536
5562
  }
5537
5563
 
5538
5564
  // src/args/commands/upload_ai_blame.ts
5565
+ var PromptItemZ = z27.object({
5566
+ type: z27.enum(["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]),
5567
+ attachedFiles: z27.array(
5568
+ z27.object({
5569
+ relativePath: z27.string(),
5570
+ startLine: z27.number().optional()
5571
+ })
5572
+ ).optional(),
5573
+ tokens: z27.object({
5574
+ inputCount: z27.number(),
5575
+ outputCount: z27.number()
5576
+ }).optional(),
5577
+ text: z27.string().optional(),
5578
+ date: z27.date().optional(),
5579
+ tool: z27.object({
5580
+ name: z27.string(),
5581
+ parameters: z27.string(),
5582
+ result: z27.string(),
5583
+ rawArguments: z27.string().optional(),
5584
+ accepted: z27.boolean().optional()
5585
+ }).optional()
5586
+ });
5587
+ var PromptItemArrayZ = z27.array(PromptItemZ);
5539
5588
  function uploadAiBlameBuilder(args) {
5540
5589
  return args.option("prompt", {
5541
5590
  type: "string",
@@ -5565,17 +5614,44 @@ function uploadAiBlameBuilder(args) {
5565
5614
  describe: chalk2.bold("Tool/IDE name(s) (optional, one per session)")
5566
5615
  }).strict();
5567
5616
  }
5568
- async function uploadAiBlameHandler(args) {
5617
+ async function uploadAiBlameHandlerFromExtension(args) {
5618
+ const uploadArgs = {
5619
+ prompt: [],
5620
+ inference: [],
5621
+ model: [],
5622
+ toolName: [],
5623
+ aiResponseAt: []
5624
+ };
5625
+ await withFile(async (promptFile) => {
5626
+ await fsPromises2.writeFile(
5627
+ promptFile.path,
5628
+ JSON.stringify(args.prompts, null, 2),
5629
+ "utf-8"
5630
+ );
5631
+ uploadArgs.prompt.push(promptFile.path);
5632
+ await withFile(async (inferenceFile) => {
5633
+ await fsPromises2.writeFile(inferenceFile.path, args.inference, "utf-8");
5634
+ uploadArgs.inference.push(inferenceFile.path);
5635
+ uploadArgs.model.push(args.model);
5636
+ uploadArgs.toolName.push(args.tool);
5637
+ uploadArgs.aiResponseAt.push(args.responseTime);
5638
+ await uploadAiBlameHandler(uploadArgs, false);
5639
+ });
5640
+ });
5641
+ }
5642
+ async function uploadAiBlameHandler(args, exitOnError = true) {
5569
5643
  const prompts = args.prompt || [];
5570
5644
  const inferences = args.inference || [];
5571
5645
  const models = args.model || [];
5572
5646
  const tools = args.toolName || args["tool-name"] || [];
5573
5647
  const responseTimes = args.aiResponseAt || args["ai-response-at"] || [];
5574
5648
  if (prompts.length !== inferences.length) {
5575
- console.error(
5576
- chalk2.red("prompt and inference must have the same number of entries")
5577
- );
5578
- process.exit(1);
5649
+ const errorMsg = "prompt and inference must have the same number of entries";
5650
+ console.error(chalk2.red(errorMsg));
5651
+ if (exitOnError) {
5652
+ process.exit(1);
5653
+ }
5654
+ throw new Error(errorMsg);
5579
5655
  }
5580
5656
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
5581
5657
  const sessions = [];
@@ -5583,10 +5659,17 @@ async function uploadAiBlameHandler(args) {
5583
5659
  const promptPath = String(prompts[i]);
5584
5660
  const inferencePath = String(inferences[i]);
5585
5661
  try {
5586
- await Promise.all([fs5.access(promptPath), fs5.access(inferencePath)]);
5662
+ await Promise.all([
5663
+ fsPromises2.access(promptPath),
5664
+ fsPromises2.access(inferencePath)
5665
+ ]);
5587
5666
  } catch {
5588
- console.error(chalk2.red(`File not found for session ${i + 1}`));
5589
- process.exit(1);
5667
+ const errorMsg = `File not found for session ${i + 1}`;
5668
+ console.error(chalk2.red(errorMsg));
5669
+ if (exitOnError) {
5670
+ process.exit(1);
5671
+ }
5672
+ throw new Error(errorMsg);
5590
5673
  }
5591
5674
  sessions.push({
5592
5675
  promptFileName: path6.basename(promptPath),
@@ -5600,10 +5683,12 @@ async function uploadAiBlameHandler(args) {
5600
5683
  const initRes = await gqlClient.uploadAIBlameInferencesInitRaw({ sessions });
5601
5684
  const uploadSessions = initRes.uploadAIBlameInferencesInit?.uploadSessions ?? [];
5602
5685
  if (uploadSessions.length !== sessions.length) {
5603
- console.error(
5604
- chalk2.red("Init failed to return expected number of sessions")
5605
- );
5606
- process.exit(1);
5686
+ const errorMsg = "Init failed to return expected number of sessions";
5687
+ console.error(chalk2.red(errorMsg));
5688
+ if (exitOnError) {
5689
+ process.exit(1);
5690
+ }
5691
+ throw new Error(errorMsg);
5607
5692
  }
5608
5693
  for (let i = 0; i < uploadSessions.length; i++) {
5609
5694
  const us = uploadSessions[i];
@@ -5638,16 +5723,17 @@ async function uploadAiBlameHandler(args) {
5638
5723
  });
5639
5724
  const status = finRes?.finalizeAIBlameInferencesUpload?.status;
5640
5725
  if (status !== "OK") {
5641
- console.error(
5642
- chalk2.red(
5643
- `Finalize failed: ${finRes?.finalizeAIBlameInferencesUpload?.error || "unknown error"}`
5644
- )
5645
- );
5646
- process.exit(1);
5726
+ const errorMsg = finRes?.finalizeAIBlameInferencesUpload?.error || "unknown error";
5727
+ console.error(chalk2.red(errorMsg));
5728
+ if (exitOnError) {
5729
+ process.exit(1);
5730
+ }
5731
+ throw new Error(errorMsg);
5647
5732
  }
5648
5733
  console.log(chalk2.green("AI Blame uploads finalized successfully"));
5649
5734
  }
5650
5735
  export {
5651
5736
  uploadAiBlameBuilder,
5652
- uploadAiBlameHandler
5737
+ uploadAiBlameHandler,
5738
+ uploadAiBlameHandlerFromExtension
5653
5739
  };