@morphllm/morphsdk 0.2.162 → 0.2.163
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/dist/{chunk-YBKT2UOK.js → chunk-2KDJKRZG.js} +2 -2
- package/dist/chunk-5AM23TC7.js +42 -0
- package/dist/chunk-5AM23TC7.js.map +1 -0
- package/dist/{chunk-UETFIUIG.js → chunk-5BMWOPYW.js} +2 -2
- package/dist/{chunk-UKT3CKC7.js → chunk-5FYJMU6H.js} +2 -2
- package/dist/{chunk-DRTPCCEI.js → chunk-6PFGM4CM.js} +2 -2
- package/dist/{chunk-YRHM3RCQ.js → chunk-6YOSNPHS.js} +2 -2
- package/dist/{chunk-XUV5B27P.js → chunk-6YTCBLRI.js} +2 -2
- package/dist/{chunk-VQSLLYKE.js → chunk-COUYHTIO.js} +2 -2
- package/dist/{chunk-Y4NYT5L6.js → chunk-CUMC7Z5R.js} +11 -26
- package/dist/chunk-CUMC7Z5R.js.map +1 -0
- package/dist/{chunk-4Q6VFODP.js → chunk-EJBWDGTH.js} +2 -2
- package/dist/{chunk-UZX7SY33.js → chunk-FNCPPCPV.js} +2 -2
- package/dist/{chunk-4GQNYJBB.js → chunk-FQXUOZBX.js} +9 -12
- package/dist/chunk-FQXUOZBX.js.map +1 -0
- package/dist/{chunk-DXMNKPB6.js → chunk-HBH56DLN.js} +2 -2
- package/dist/{chunk-JVKGSMEF.js → chunk-HFN3YCF4.js} +2 -2
- package/dist/{chunk-NKUGRAYU.js → chunk-HMGC7FLZ.js} +2 -2
- package/dist/{chunk-4U5JFT6X.js → chunk-KHR4CZMX.js} +24 -17
- package/dist/{chunk-4U5JFT6X.js.map → chunk-KHR4CZMX.js.map} +1 -1
- package/dist/{chunk-OGMHU4PJ.js → chunk-LSHQISAX.js} +9 -2
- package/dist/chunk-LSHQISAX.js.map +1 -0
- package/dist/{chunk-ZG3YLRR5.js → chunk-LST7MZOZ.js} +7 -2
- package/dist/chunk-LST7MZOZ.js.map +1 -0
- package/dist/{chunk-5XTA7GCY.js → chunk-LW5EAPZ6.js} +2 -2
- package/dist/{chunk-UVRC4LKZ.js → chunk-NNATBEOF.js} +2 -2
- package/dist/{chunk-CNFHKQ42.js → chunk-OKFW4KGU.js} +2 -2
- package/dist/{chunk-PWGBAVQ5.js → chunk-QXGOEDZD.js} +2 -2
- package/dist/{chunk-OOE2TKKY.js → chunk-SELI567A.js} +12 -21
- package/dist/chunk-SELI567A.js.map +1 -0
- package/dist/{chunk-LECHLXI4.js → chunk-VMNEYCFP.js} +17 -6
- package/dist/chunk-VMNEYCFP.js.map +1 -0
- package/dist/{chunk-LZQBVEY2.js → chunk-WM6SBI4B.js} +35 -27
- package/dist/chunk-WM6SBI4B.js.map +1 -0
- package/dist/{chunk-7QMX45QD.js → chunk-ZMCDGAGF.js} +33 -6
- package/dist/chunk-ZMCDGAGF.js.map +1 -0
- package/dist/client.cjs +184 -115
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +23 -22
- package/dist/edge.cjs +82 -50
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +5 -4
- package/dist/index.cjs +186 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -22
- package/dist/modelrouter/core.cjs +50 -25
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +4 -3
- package/dist/modelrouter/index.cjs +50 -25
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +4 -3
- package/dist/subagents/anthropic.cjs +85 -12
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +5 -4
- package/dist/subagents/vercel.cjs +85 -12
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +5 -4
- package/dist/tools/browser/anthropic.cjs +47 -9
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +6 -5
- package/dist/tools/browser/core.cjs +50 -19
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +5 -4
- package/dist/tools/browser/index.cjs +50 -19
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +8 -7
- package/dist/tools/browser/index.js.map +1 -1
- package/dist/tools/browser/openai.cjs +47 -9
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +6 -5
- package/dist/tools/browser/profiles/core.cjs +6 -1
- package/dist/tools/browser/profiles/core.cjs.map +1 -1
- package/dist/tools/browser/profiles/core.js +3 -3
- package/dist/tools/browser/profiles/index.cjs +6 -1
- package/dist/tools/browser/profiles/index.cjs.map +1 -1
- package/dist/tools/browser/profiles/index.js +3 -3
- package/dist/tools/browser/vercel.cjs +47 -9
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +6 -5
- package/dist/tools/codebase_search/anthropic.cjs +48 -11
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +5 -4
- package/dist/tools/codebase_search/core.cjs +48 -11
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +4 -3
- package/dist/tools/codebase_search/index.cjs +48 -11
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +7 -6
- package/dist/tools/codebase_search/openai.cjs +48 -11
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +5 -4
- package/dist/tools/codebase_search/vercel.cjs +48 -11
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +5 -4
- package/dist/tools/fastapply/anthropic.cjs +94 -31
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +5 -4
- package/dist/tools/fastapply/apply.cjs +74 -26
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +3 -2
- package/dist/tools/fastapply/core.cjs +94 -31
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +4 -3
- package/dist/tools/fastapply/index.cjs +94 -31
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +7 -6
- package/dist/tools/fastapply/openai.cjs +94 -31
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +5 -4
- package/dist/tools/fastapply/vercel.cjs +94 -31
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +5 -4
- package/dist/tools/index.cjs +94 -31
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +7 -6
- package/dist/tools/utils/resilience.cjs +6 -1
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/runner.cjs +74 -5
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +3 -2
- package/dist/tools/warp_grep/anthropic.cjs +85 -12
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +5 -4
- package/dist/tools/warp_grep/client.cjs +85 -12
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +4 -3
- package/dist/tools/warp_grep/gemini.cjs +85 -12
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +4 -3
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/index.cjs +85 -12
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +4 -3
- package/dist/tools/warp_grep/openai.cjs +85 -12
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +5 -4
- package/dist/tools/warp_grep/vercel.cjs +85 -12
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.js +5 -4
- package/dist/version.cjs +6 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
- package/dist/chunk-4GQNYJBB.js.map +0 -1
- package/dist/chunk-7QMX45QD.js.map +0 -1
- package/dist/chunk-LECHLXI4.js.map +0 -1
- package/dist/chunk-LZQBVEY2.js.map +0 -1
- package/dist/chunk-OGMHU4PJ.js.map +0 -1
- package/dist/chunk-OOE2TKKY.js.map +0 -1
- package/dist/chunk-Y4NYT5L6.js.map +0 -1
- package/dist/chunk-ZG3YLRR5.js.map +0 -1
- package/dist/{chunk-YBKT2UOK.js.map → chunk-2KDJKRZG.js.map} +0 -0
- package/dist/{chunk-UETFIUIG.js.map → chunk-5BMWOPYW.js.map} +0 -0
- package/dist/{chunk-UKT3CKC7.js.map → chunk-5FYJMU6H.js.map} +0 -0
- package/dist/{chunk-DRTPCCEI.js.map → chunk-6PFGM4CM.js.map} +0 -0
- package/dist/{chunk-YRHM3RCQ.js.map → chunk-6YOSNPHS.js.map} +0 -0
- package/dist/{chunk-XUV5B27P.js.map → chunk-6YTCBLRI.js.map} +0 -0
- package/dist/{chunk-VQSLLYKE.js.map → chunk-COUYHTIO.js.map} +0 -0
- package/dist/{chunk-4Q6VFODP.js.map → chunk-EJBWDGTH.js.map} +0 -0
- package/dist/{chunk-UZX7SY33.js.map → chunk-FNCPPCPV.js.map} +0 -0
- package/dist/{chunk-DXMNKPB6.js.map → chunk-HBH56DLN.js.map} +0 -0
- package/dist/{chunk-JVKGSMEF.js.map → chunk-HFN3YCF4.js.map} +0 -0
- package/dist/{chunk-NKUGRAYU.js.map → chunk-HMGC7FLZ.js.map} +0 -0
- package/dist/{chunk-5XTA7GCY.js.map → chunk-LW5EAPZ6.js.map} +0 -0
- package/dist/{chunk-UVRC4LKZ.js.map → chunk-NNATBEOF.js.map} +0 -0
- package/dist/{chunk-CNFHKQ42.js.map → chunk-OKFW4KGU.js.map} +0 -0
- package/dist/{chunk-PWGBAVQ5.js.map → chunk-QXGOEDZD.js.map} +0 -0
- package/dist/{client-PkB7g9SA.d.ts → client-DsAAqupx.d.ts} +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ var init_package = __esm({
|
|
|
36
36
|
"package.json"() {
|
|
37
37
|
package_default = {
|
|
38
38
|
name: "@morphllm/morphsdk",
|
|
39
|
-
version: "0.2.
|
|
39
|
+
version: "0.2.163",
|
|
40
40
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
41
41
|
type: "module",
|
|
42
42
|
main: "./dist/index.cjs",
|
|
@@ -48,6 +48,11 @@ var init_package = __esm({
|
|
|
48
48
|
import: "./dist/index.js",
|
|
49
49
|
require: "./dist/index.cjs"
|
|
50
50
|
},
|
|
51
|
+
"./logger": {
|
|
52
|
+
types: "./dist/logger.d.ts",
|
|
53
|
+
import: "./dist/logger.js",
|
|
54
|
+
require: "./dist/logger.cjs"
|
|
55
|
+
},
|
|
51
56
|
"./edge": {
|
|
52
57
|
types: "./dist/edge.d.ts",
|
|
53
58
|
import: "./dist/edge.js",
|
|
@@ -283,6 +288,50 @@ var init_version = __esm({
|
|
|
283
288
|
}
|
|
284
289
|
});
|
|
285
290
|
|
|
291
|
+
// logger.ts
|
|
292
|
+
var import_fs, MorphLogger, logger;
|
|
293
|
+
var init_logger = __esm({
|
|
294
|
+
"logger.ts"() {
|
|
295
|
+
"use strict";
|
|
296
|
+
import_fs = require("fs");
|
|
297
|
+
MorphLogger = class {
|
|
298
|
+
enabled;
|
|
299
|
+
fileStream;
|
|
300
|
+
constructor() {
|
|
301
|
+
this.enabled = process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE;
|
|
302
|
+
const f = process.env.MORPH_LOG_FILE;
|
|
303
|
+
this.fileStream = f ? (0, import_fs.createWriteStream)(f, { flags: "a" }) : null;
|
|
304
|
+
}
|
|
305
|
+
debug(component, msg, data) {
|
|
306
|
+
this._log("debug", component, msg, data);
|
|
307
|
+
}
|
|
308
|
+
info(component, msg, data) {
|
|
309
|
+
this._log("info", component, msg, data);
|
|
310
|
+
}
|
|
311
|
+
warn(component, msg, data) {
|
|
312
|
+
this._log("warn", component, msg, data);
|
|
313
|
+
}
|
|
314
|
+
error(component, msg, data) {
|
|
315
|
+
this._log("error", component, msg, data);
|
|
316
|
+
}
|
|
317
|
+
enable() {
|
|
318
|
+
this.enabled = true;
|
|
319
|
+
}
|
|
320
|
+
get isEnabled() {
|
|
321
|
+
return this.enabled;
|
|
322
|
+
}
|
|
323
|
+
_log(level, component, msg, data) {
|
|
324
|
+
if (level !== "error" && !this.enabled) return;
|
|
325
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
326
|
+
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
327
|
+
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
328
|
+
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
logger = new MorphLogger();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
286
335
|
// tools/fastapply/apply.ts
|
|
287
336
|
var apply_exports = {};
|
|
288
337
|
__export(apply_exports, {
|
|
@@ -335,11 +384,14 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
335
384
|
const message = `<instruction>${instructions}</instruction>
|
|
336
385
|
<code>${originalCode}</code>
|
|
337
386
|
<update>${codeEdit}</update>`;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
387
|
+
logger.debug("FastApply", "http_request", {
|
|
388
|
+
url: `${apiUrl}/v1/chat/completions`,
|
|
389
|
+
model,
|
|
390
|
+
filepath,
|
|
391
|
+
instruction_len: instructions.length,
|
|
392
|
+
original_len: originalCode.length,
|
|
393
|
+
code_edit_len: codeEdit.length
|
|
394
|
+
});
|
|
343
395
|
const startTime = Date.now();
|
|
344
396
|
const client = new import_openai.default({
|
|
345
397
|
apiKey,
|
|
@@ -348,30 +400,32 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
348
400
|
maxRetries: config.retryConfig?.maxRetries ?? 3,
|
|
349
401
|
defaultHeaders: { "X-Morph-SDK-Version": SDK_VERSION }
|
|
350
402
|
});
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
403
|
+
try {
|
|
404
|
+
const completion = await client.chat.completions.create({
|
|
405
|
+
model,
|
|
406
|
+
messages: [{ role: "user", content: message }]
|
|
407
|
+
});
|
|
408
|
+
const content = completion.choices[0]?.message?.content;
|
|
409
|
+
if (!content) {
|
|
410
|
+
throw new Error("Morph API returned empty response");
|
|
411
|
+
}
|
|
412
|
+
const elapsed = Date.now() - startTime;
|
|
413
|
+
logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.id, content_len: content.length, latency_ms: elapsed });
|
|
414
|
+
return { content, completionId: completion.id };
|
|
415
|
+
} catch (error) {
|
|
416
|
+
const elapsed = Date.now() - startTime;
|
|
417
|
+
logger.error("FastApply", "http_error", {
|
|
418
|
+
status: error?.status || error?.response?.status,
|
|
419
|
+
error: error?.message,
|
|
420
|
+
latency_ms: elapsed
|
|
421
|
+
});
|
|
422
|
+
throw error;
|
|
365
423
|
}
|
|
366
|
-
return { content, completionId: completion.id };
|
|
367
424
|
}
|
|
368
425
|
async function applyEdit(input, config = {}) {
|
|
369
|
-
const debug = config.debug || false;
|
|
370
426
|
const filepath = input.filepath || "file";
|
|
371
427
|
try {
|
|
372
|
-
|
|
373
|
-
console.log(`[FastApply] Applying edit to code (${input.originalCode.length} chars)`);
|
|
374
|
-
}
|
|
428
|
+
logger.debug("FastApply", "apply_edit_start", { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });
|
|
375
429
|
const instruction = input.instruction ?? input.instructions ?? "";
|
|
376
430
|
const { content: mergedCode, completionId } = await callMorphAPI(
|
|
377
431
|
input.originalCode,
|
|
@@ -391,7 +445,7 @@ async function applyEdit(input, config = {}) {
|
|
|
391
445
|
};
|
|
392
446
|
} catch (error) {
|
|
393
447
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
394
|
-
|
|
448
|
+
logger.error("FastApply", "apply_edit_error", { error: errorMessage });
|
|
395
449
|
return {
|
|
396
450
|
success: false,
|
|
397
451
|
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
@@ -406,6 +460,7 @@ var init_apply = __esm({
|
|
|
406
460
|
import_diff = require("diff");
|
|
407
461
|
import_openai = __toESM(require("openai"), 1);
|
|
408
462
|
init_version();
|
|
463
|
+
init_logger();
|
|
409
464
|
DEFAULT_API_URL = "https://api.morphllm.com";
|
|
410
465
|
DEFAULT_TIMEOUT = 3e4;
|
|
411
466
|
}
|
|
@@ -601,7 +656,7 @@ function toRepoRelative(repoRoot, absPath) {
|
|
|
601
656
|
}
|
|
602
657
|
function isSymlink(p) {
|
|
603
658
|
try {
|
|
604
|
-
const st =
|
|
659
|
+
const st = import_fs2.default.lstatSync(p);
|
|
605
660
|
return st.isSymbolicLink();
|
|
606
661
|
} catch {
|
|
607
662
|
return false;
|
|
@@ -624,13 +679,13 @@ function fixPathRepetition(fullPath) {
|
|
|
624
679
|
}
|
|
625
680
|
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
626
681
|
try {
|
|
627
|
-
const st =
|
|
682
|
+
const st = import_fs2.default.statSync(filePath);
|
|
628
683
|
if (!st.isFile()) return false;
|
|
629
684
|
if (st.size > maxBytes) return false;
|
|
630
|
-
const fd =
|
|
685
|
+
const fd = import_fs2.default.openSync(filePath, "r");
|
|
631
686
|
const buf = Buffer.alloc(512);
|
|
632
|
-
const read =
|
|
633
|
-
|
|
687
|
+
const read = import_fs2.default.readSync(fd, buf, 0, buf.length, 0);
|
|
688
|
+
import_fs2.default.closeSync(fd);
|
|
634
689
|
for (let i = 0; i < read; i++) {
|
|
635
690
|
const c = buf[i];
|
|
636
691
|
if (c === 0) return false;
|
|
@@ -640,11 +695,11 @@ function isTextualFile(filePath, maxBytes = 2e6) {
|
|
|
640
695
|
return false;
|
|
641
696
|
}
|
|
642
697
|
}
|
|
643
|
-
var
|
|
698
|
+
var import_fs2, import_path5;
|
|
644
699
|
var init_paths = __esm({
|
|
645
700
|
"tools/warp_grep/utils/paths.ts"() {
|
|
646
701
|
"use strict";
|
|
647
|
-
|
|
702
|
+
import_fs2 = __toESM(require("fs"), 1);
|
|
648
703
|
import_path5 = __toESM(require("path"), 1);
|
|
649
704
|
}
|
|
650
705
|
});
|
|
@@ -1027,8 +1082,12 @@ __export(index_exports, {
|
|
|
1027
1082
|
module.exports = __toCommonJS(index_exports);
|
|
1028
1083
|
init_version();
|
|
1029
1084
|
|
|
1085
|
+
// client.ts
|
|
1086
|
+
init_logger();
|
|
1087
|
+
|
|
1030
1088
|
// tools/fastapply/core.ts
|
|
1031
1089
|
var import_path = require("path");
|
|
1090
|
+
init_logger();
|
|
1032
1091
|
init_apply();
|
|
1033
1092
|
var DEFAULT_CONFIG = {
|
|
1034
1093
|
morphApiUrl: "https://api.morphllm.com",
|
|
@@ -1089,9 +1148,10 @@ var FastApplyClient = class {
|
|
|
1089
1148
|
async function executeEditFile(input, config = {}) {
|
|
1090
1149
|
const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;
|
|
1091
1150
|
const fullPath = (0, import_path.resolve)((0, import_path.join)(baseDir, input.target_filepath));
|
|
1092
|
-
|
|
1151
|
+
logger.debug("FastApply", "execute_start", { target_filepath: input.target_filepath, baseDir, autoWrite: config.autoWrite !== false });
|
|
1093
1152
|
const relativePath = (0, import_path.relative)(baseDir, fullPath);
|
|
1094
1153
|
if (relativePath.startsWith("..") || fullPath === baseDir) {
|
|
1154
|
+
logger.warn("FastApply", "security_check_failed", { target_filepath: input.target_filepath, relative: relativePath });
|
|
1095
1155
|
return {
|
|
1096
1156
|
success: false,
|
|
1097
1157
|
filepath: input.target_filepath,
|
|
@@ -1099,27 +1159,33 @@ async function executeEditFile(input, config = {}) {
|
|
|
1099
1159
|
error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`
|
|
1100
1160
|
};
|
|
1101
1161
|
}
|
|
1162
|
+
logger.debug("FastApply", "security_check", { resolved: fullPath, relative: relativePath });
|
|
1102
1163
|
try {
|
|
1103
|
-
if (debug) console.log(`[FastApply] Reading file: ${input.target_filepath}`);
|
|
1104
1164
|
const { readFile, writeFile } = await import("fs/promises");
|
|
1105
1165
|
const { callMorphAPI: callMorphAPI2, generateUdiff: generateUdiff2, countChanges: countChanges2 } = await Promise.resolve().then(() => (init_apply(), apply_exports));
|
|
1106
1166
|
let originalCode = "";
|
|
1167
|
+
let fileExists = true;
|
|
1107
1168
|
try {
|
|
1108
1169
|
originalCode = await readFile(fullPath, "utf-8");
|
|
1170
|
+
logger.debug("FastApply", "file_read", { path: fullPath, exists: true, size_bytes: originalCode.length });
|
|
1109
1171
|
} catch (error) {
|
|
1110
1172
|
if (error.code !== "ENOENT") {
|
|
1111
1173
|
throw error;
|
|
1112
1174
|
}
|
|
1113
|
-
|
|
1175
|
+
fileExists = false;
|
|
1176
|
+
logger.debug("FastApply", "file_read", { path: fullPath, exists: false });
|
|
1114
1177
|
}
|
|
1115
1178
|
const instruction = input.instruction ?? input.instructions ?? "";
|
|
1179
|
+
logger.debug("FastApply", "api_call", { instruction_len: instruction.length, code_edit_len: input.code_edit.length, original_len: originalCode.length });
|
|
1116
1180
|
const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, instruction, input.target_filepath, config);
|
|
1181
|
+
logger.debug("FastApply", "api_response", { completion_id: completionId, merged_len: mergedCode.length });
|
|
1117
1182
|
const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
|
|
1118
1183
|
if (config.autoWrite !== false) {
|
|
1119
1184
|
await writeFile(fullPath, mergedCode, "utf-8");
|
|
1120
|
-
|
|
1185
|
+
logger.debug("FastApply", "file_write", { path: fullPath, size_bytes: mergedCode.length });
|
|
1121
1186
|
}
|
|
1122
1187
|
const changes = countChanges2(originalCode, mergedCode);
|
|
1188
|
+
logger.debug("FastApply", "changes", { added: changes.linesAdded, removed: changes.linesRemoved, modified: changes.linesModified });
|
|
1123
1189
|
return {
|
|
1124
1190
|
success: true,
|
|
1125
1191
|
filepath: input.target_filepath,
|
|
@@ -1129,7 +1195,7 @@ async function executeEditFile(input, config = {}) {
|
|
|
1129
1195
|
};
|
|
1130
1196
|
} catch (error) {
|
|
1131
1197
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1132
|
-
|
|
1198
|
+
logger.error("FastApply", "execute_error", { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : void 0 });
|
|
1133
1199
|
return {
|
|
1134
1200
|
success: false,
|
|
1135
1201
|
filepath: input.target_filepath,
|
|
@@ -1216,6 +1282,7 @@ function sleep(ms) {
|
|
|
1216
1282
|
}
|
|
1217
1283
|
|
|
1218
1284
|
// tools/codebase_search/core.ts
|
|
1285
|
+
init_logger();
|
|
1219
1286
|
var CodebaseSearchClient = class {
|
|
1220
1287
|
config;
|
|
1221
1288
|
constructor(config = {}) {
|
|
@@ -1253,11 +1320,7 @@ async function executeCodebaseSearch(input, config) {
|
|
|
1253
1320
|
}
|
|
1254
1321
|
const searchUrl = config.searchUrl || process.env.MORPH_SEARCH_URL || "https://repos.morphllm.com";
|
|
1255
1322
|
const timeout = config.timeout || 3e4;
|
|
1256
|
-
|
|
1257
|
-
if (debug) {
|
|
1258
|
-
console.log(`[CodebaseSearch] Query: "${input.query.slice(0, 60)}..." repo=${config.repoId}`);
|
|
1259
|
-
console.log(`[CodebaseSearch] URL: ${searchUrl}/v1/codebase_search`);
|
|
1260
|
-
}
|
|
1323
|
+
logger.debug("CodebaseSearch", "request", { query: input.query.slice(0, 100), repo_id: config.repoId, url: `${searchUrl}/v1/codebase_search` });
|
|
1261
1324
|
const startTime = Date.now();
|
|
1262
1325
|
try {
|
|
1263
1326
|
const fetchPromise = fetchWithRetry(
|
|
@@ -1281,7 +1344,7 @@ async function executeCodebaseSearch(input, config) {
|
|
|
1281
1344
|
const response = await withTimeout(fetchPromise, timeout, `Codebase search timed out after ${timeout}ms`);
|
|
1282
1345
|
if (!response.ok) {
|
|
1283
1346
|
const errorText = await response.text();
|
|
1284
|
-
|
|
1347
|
+
logger.error("CodebaseSearch", "response_error", { status: response.status, error: errorText, latency_ms: Date.now() - startTime });
|
|
1285
1348
|
return {
|
|
1286
1349
|
success: false,
|
|
1287
1350
|
results: [],
|
|
@@ -1291,16 +1354,14 @@ async function executeCodebaseSearch(input, config) {
|
|
|
1291
1354
|
}
|
|
1292
1355
|
const data = await response.json();
|
|
1293
1356
|
const elapsed = Date.now() - startTime;
|
|
1294
|
-
|
|
1295
|
-
console.log(`[CodebaseSearch] \u2705 ${data.results?.length || 0} results in ${elapsed}ms`);
|
|
1296
|
-
}
|
|
1357
|
+
logger.debug("CodebaseSearch", "response", { results_count: data.results?.length || 0, latency_ms: elapsed });
|
|
1297
1358
|
return {
|
|
1298
1359
|
success: true,
|
|
1299
1360
|
results: data.results || [],
|
|
1300
1361
|
stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed }
|
|
1301
1362
|
};
|
|
1302
1363
|
} catch (error) {
|
|
1303
|
-
|
|
1364
|
+
logger.error("CodebaseSearch", "exception", { error: error instanceof Error ? error.message : String(error), latency_ms: Date.now() - startTime });
|
|
1304
1365
|
return {
|
|
1305
1366
|
success: false,
|
|
1306
1367
|
results: [],
|
|
@@ -1310,6 +1371,9 @@ async function executeCodebaseSearch(input, config) {
|
|
|
1310
1371
|
}
|
|
1311
1372
|
}
|
|
1312
1373
|
|
|
1374
|
+
// tools/browser/core.ts
|
|
1375
|
+
init_logger();
|
|
1376
|
+
|
|
1313
1377
|
// tools/browser/live.ts
|
|
1314
1378
|
var LIVE_PRESETS = {
|
|
1315
1379
|
/** Read-only monitoring (no interaction) */
|
|
@@ -2006,11 +2070,7 @@ var BrowserClient = class {
|
|
|
2006
2070
|
if (!hasTask && !hasDiff) {
|
|
2007
2071
|
throw new Error('Browser task requires either "task" (natural language) or "diff" (PR-review planning)');
|
|
2008
2072
|
}
|
|
2009
|
-
|
|
2010
|
-
const preview = (input.task ?? "").slice(0, 60);
|
|
2011
|
-
console.log(`[Browser] createTask: "${preview}..." url=${input.url || "none"}`);
|
|
2012
|
-
console.log(`[Browser] Calling async endpoint: ${apiUrl}/browser-task/async`);
|
|
2013
|
-
}
|
|
2073
|
+
logger.debug("Browser", "create_task", { task: (input.task ?? "").slice(0, 100), url: input.url, endpoint: `${apiUrl}/browser-task/async` });
|
|
2014
2074
|
const headers = { "Content-Type": "application/json" };
|
|
2015
2075
|
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2016
2076
|
const response = await fetch(`${apiUrl}/browser-task/async`, {
|
|
@@ -2040,14 +2100,11 @@ var BrowserClient = class {
|
|
|
2040
2100
|
});
|
|
2041
2101
|
if (!response.ok) {
|
|
2042
2102
|
const errorText = await response.text().catch(() => response.statusText);
|
|
2043
|
-
|
|
2103
|
+
logger.error("Browser", "create_task_error", { status: response.status, error: errorText });
|
|
2044
2104
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2045
2105
|
}
|
|
2046
2106
|
const result = mapTaskResult(await response.json());
|
|
2047
|
-
|
|
2048
|
-
const debugUrl = result.debugUrl;
|
|
2049
|
-
console.log(`[Browser] \u2705 Task created: recordingId=${result.recordingId ?? "none"} debugUrl=${debugUrl ? "available" : "none"}`);
|
|
2050
|
-
}
|
|
2107
|
+
logger.debug("Browser", "task_created", { recording_id: result.recordingId, task_id: result.taskId, debug_url: !!result.debugUrl });
|
|
2051
2108
|
if ("schema" in input) {
|
|
2052
2109
|
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
2053
2110
|
} else {
|
|
@@ -2107,10 +2164,7 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
2107
2164
|
error: "maxSteps must be between 1 and 50. Use more steps for complex multi-page flows."
|
|
2108
2165
|
};
|
|
2109
2166
|
}
|
|
2110
|
-
|
|
2111
|
-
console.log(`[Browser] Task: "${input.task.slice(0, 60)}..." url=${input.url || "none"} maxSteps=${input.maxSteps ?? 10}`);
|
|
2112
|
-
console.log(`[Browser] Recording: ${input.recordVideo ? "yes" : "no"} | Calling ${apiUrl}/browser-task`);
|
|
2113
|
-
}
|
|
2167
|
+
logger.debug("Browser", "execute_start", { task: input.task.slice(0, 100), url: input.url, max_steps: input.maxSteps ?? 10, record_video: input.recordVideo ?? false });
|
|
2114
2168
|
const startTime = Date.now();
|
|
2115
2169
|
try {
|
|
2116
2170
|
const headers = { "Content-Type": "application/json" };
|
|
@@ -2149,14 +2203,12 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
2149
2203
|
);
|
|
2150
2204
|
if (!response.ok) {
|
|
2151
2205
|
const errorText = await response.text().catch(() => response.statusText);
|
|
2152
|
-
|
|
2206
|
+
logger.error("Browser", "execute_error", { status: response.status, error: errorText });
|
|
2153
2207
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2154
2208
|
}
|
|
2155
2209
|
const result = mapTaskResult(await response.json());
|
|
2156
2210
|
const elapsed = Date.now() - startTime;
|
|
2157
|
-
|
|
2158
|
-
console.log(`[Browser] \u2705 ${result.success ? "Success" : "Failed"} in ${elapsed}ms | steps=${result.stepsTaken ?? 0} recordingId=${result.recordingId ?? "none"}`);
|
|
2159
|
-
}
|
|
2211
|
+
logger.debug("Browser", "execute_complete", { success: result.success, latency_ms: elapsed, steps: result.stepsTaken ?? 0, recording_id: result.recordingId });
|
|
2160
2212
|
return result;
|
|
2161
2213
|
} catch (error) {
|
|
2162
2214
|
if (error instanceof Error) {
|
|
@@ -2867,6 +2919,7 @@ function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS
|
|
|
2867
2919
|
var import_openai2 = __toESM(require("openai"), 1);
|
|
2868
2920
|
init_version();
|
|
2869
2921
|
var import_path4 = __toESM(require("path"), 1);
|
|
2922
|
+
init_logger();
|
|
2870
2923
|
var DEFAULT_API_URL3 = "https://api.morphllm.com";
|
|
2871
2924
|
var TOOL_SPECS = [
|
|
2872
2925
|
{
|
|
@@ -2989,6 +3042,8 @@ async function callModel(messages, model, options = {}) {
|
|
|
2989
3042
|
defaultHeaders: { "X-Morph-SDK-Version": SDK_VERSION }
|
|
2990
3043
|
});
|
|
2991
3044
|
const MAX_EMPTY_RETRIES = 1;
|
|
3045
|
+
logger.debug("WarpGrep", "model_call", { url: baseURL, model, message_count: messages.length });
|
|
3046
|
+
const callStartTime = Date.now();
|
|
2992
3047
|
for (let attempt = 0; attempt <= MAX_EMPTY_RETRIES; attempt++) {
|
|
2993
3048
|
let data;
|
|
2994
3049
|
try {
|
|
@@ -3001,10 +3056,16 @@ async function callModel(messages, model, options = {}) {
|
|
|
3001
3056
|
...options.search_type ? { search_type: options.search_type } : {}
|
|
3002
3057
|
});
|
|
3003
3058
|
} catch (error) {
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3059
|
+
const callLatencyMs = Date.now() - callStartTime;
|
|
3060
|
+
if (error instanceof import_openai2.default.APIError) {
|
|
3061
|
+
logger.error("WarpGrep", "model_call_error", { status: error.status, error: error.message, latency_ms: callLatencyMs });
|
|
3062
|
+
if (error.status === 404) {
|
|
3063
|
+
const defaultMsg = "The endpoint you are trying to call is likely deprecated. Please update with: npm cache clean --force && npx -y @morphllm/morphmcp@latest or visit: https://morphllm.com/mcp";
|
|
3064
|
+
const errorText = error.message?.trim();
|
|
3065
|
+
throw new Error(errorText || defaultMsg);
|
|
3066
|
+
}
|
|
3067
|
+
} else {
|
|
3068
|
+
logger.error("WarpGrep", "model_call_error", { status: void 0, error: error instanceof Error ? error.message : String(error), latency_ms: callLatencyMs });
|
|
3008
3069
|
}
|
|
3009
3070
|
throw error;
|
|
3010
3071
|
}
|
|
@@ -3023,6 +3084,7 @@ async function callModel(messages, model, options = {}) {
|
|
|
3023
3084
|
function: { name: tc.function.name, arguments: tc.function.arguments }
|
|
3024
3085
|
}));
|
|
3025
3086
|
if (message.content || toolCalls.length > 0) {
|
|
3087
|
+
logger.debug("WarpGrep", "model_call_complete", { latency_ms: Date.now() - callStartTime, tool_calls_count: toolCalls.length, finish_reason: choice?.finish_reason ?? "unknown" });
|
|
3026
3088
|
return { content: message.content ?? null, tool_calls: toolCalls };
|
|
3027
3089
|
}
|
|
3028
3090
|
if (attempt === MAX_EMPTY_RETRIES) {
|
|
@@ -3093,9 +3155,11 @@ async function* runWarpGrepStreaming(config) {
|
|
|
3093
3155
|
const model = config.model || DEFAULT_MODEL;
|
|
3094
3156
|
const messages = [];
|
|
3095
3157
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
3158
|
+
logger.debug("WarpGrep", "session_start", { search_term: config.searchTerm, model, max_turns: maxTurns });
|
|
3096
3159
|
const initialStateStart = Date.now();
|
|
3097
3160
|
const initialState = await buildInitialState(repoRoot, config.searchTerm, config.provider, { search_type: config.search_type });
|
|
3098
3161
|
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
3162
|
+
logger.debug("WarpGrep", "initial_state", { system_prompt_len: initialState.length, user_message_len: initialState.length });
|
|
3099
3163
|
messages.push({ role: "user", content: initialState });
|
|
3100
3164
|
const provider = config.provider;
|
|
3101
3165
|
const errors = [];
|
|
@@ -3103,7 +3167,13 @@ async function* runWarpGrepStreaming(config) {
|
|
|
3103
3167
|
let terminationReason = "terminated";
|
|
3104
3168
|
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
3105
3169
|
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
3170
|
+
logger.debug("WarpGrep", "turn_start", { turn, message_count: messages.length });
|
|
3171
|
+
const beforeChars = messages.reduce((sum, m) => sum + (typeof m.content === "string" ? m.content.length : 0), 0);
|
|
3106
3172
|
enforceContextLimit(messages);
|
|
3173
|
+
const afterChars = messages.reduce((sum, m) => sum + (typeof m.content === "string" ? m.content.length : 0), 0);
|
|
3174
|
+
if (afterChars < beforeChars) {
|
|
3175
|
+
logger.debug("WarpGrep", "context_truncated", { before_chars: beforeChars, after_chars: afterChars });
|
|
3176
|
+
}
|
|
3107
3177
|
const modelCallStart = Date.now();
|
|
3108
3178
|
const response = await callModel(messages, model, {
|
|
3109
3179
|
morphApiKey: config.morphApiKey,
|
|
@@ -3114,6 +3184,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
3114
3184
|
}).catch((e) => {
|
|
3115
3185
|
const errMsg = e instanceof Error ? e.message : String(e);
|
|
3116
3186
|
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
3187
|
+
logger.error("WarpGrep", "error", { turn, error: errMsg, phase: "model_call" });
|
|
3117
3188
|
errors.push({ message: errMsg });
|
|
3118
3189
|
return null;
|
|
3119
3190
|
});
|
|
@@ -3123,6 +3194,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
3123
3194
|
break;
|
|
3124
3195
|
}
|
|
3125
3196
|
const toolCalls = response.tool_calls;
|
|
3197
|
+
logger.debug("WarpGrep", "model_response", { turn, tool_calls: toolCalls.map((tc) => tc.function.name), latency_ms: turnMetrics.morph_api_ms });
|
|
3126
3198
|
messages.push({
|
|
3127
3199
|
role: "assistant",
|
|
3128
3200
|
content: response.content,
|
|
@@ -3149,6 +3221,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
3149
3221
|
const files = parseFinishFiles(filesStr);
|
|
3150
3222
|
finishMeta = { files };
|
|
3151
3223
|
terminationReason = "completed";
|
|
3224
|
+
logger.debug("WarpGrep", "finish", { turns: turn, files: files.map((f) => f.path) });
|
|
3152
3225
|
if (files.length === 0) {
|
|
3153
3226
|
const payload2 = filesStr || "No relevant code found.";
|
|
3154
3227
|
timings.turns.push(turnMetrics);
|
|
@@ -3167,7 +3240,11 @@ async function* runWarpGrepStreaming(config) {
|
|
|
3167
3240
|
const results = await Promise.all(
|
|
3168
3241
|
toolCalls.map(async (tc) => {
|
|
3169
3242
|
const args = safeParseJSON(tc.function.arguments);
|
|
3243
|
+
const argsSummary = Object.fromEntries(Object.entries(args).map(([k, v]) => [k, typeof v === "string" && v.length > 100 ? v.slice(0, 100) + "..." : v]));
|
|
3244
|
+
logger.debug("WarpGrep", "tool_exec", { turn, tool: tc.function.name, args_summary: argsSummary });
|
|
3245
|
+
const toolStart = Date.now();
|
|
3170
3246
|
const output = await executeTool(provider, tc.function.name, args, repoRoot).catch((err) => String(err));
|
|
3247
|
+
logger.debug("WarpGrep", "tool_result", { turn, tool: tc.function.name, result_len: output.length, latency_ms: Date.now() - toolStart });
|
|
3171
3248
|
return { tool_call_id: tc.id, content: output };
|
|
3172
3249
|
})
|
|
3173
3250
|
);
|
|
@@ -3236,6 +3313,9 @@ async function runWarpGrep(config) {
|
|
|
3236
3313
|
return result.value;
|
|
3237
3314
|
}
|
|
3238
3315
|
|
|
3316
|
+
// tools/warp_grep/client.ts
|
|
3317
|
+
init_logger();
|
|
3318
|
+
|
|
3239
3319
|
// tools/warp_grep/providers/remote.ts
|
|
3240
3320
|
init_config();
|
|
3241
3321
|
var SKIP_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -3675,12 +3755,16 @@ var WarpGrepClient = class {
|
|
|
3675
3755
|
async _resolveGitHubRepo(input) {
|
|
3676
3756
|
const { owner, repo } = parseGitHubUrl(input.github);
|
|
3677
3757
|
const baseUrl = this.config.codeSearchUrl || DEFAULT_CODE_SEARCH_URL;
|
|
3758
|
+
logger.debug("WarpGrep", "github_resolve", { owner_repo: `${owner}/${repo}`, branch: input.branch });
|
|
3759
|
+
const resolveStart = Date.now();
|
|
3678
3760
|
const importRes = await fetch(`${baseUrl}/api/code-search/get-or-create?url=${encodeURIComponent(`${owner}/${repo}`)}`);
|
|
3679
3761
|
if (!importRes.ok) {
|
|
3680
3762
|
const text = await importRes.text().catch(() => importRes.statusText);
|
|
3763
|
+
logger.error("WarpGrep", "github_resolve_failed", { owner_repo: `${owner}/${repo}`, status: importRes.status, error: text });
|
|
3681
3764
|
throw new Error(`Failed to import repo ${owner}/${repo}: ${text}`);
|
|
3682
3765
|
}
|
|
3683
3766
|
const { repoId, defaultBranch } = await importRes.json();
|
|
3767
|
+
logger.debug("WarpGrep", "github_repo_fetched", { repo_id: repoId, default_branch: defaultBranch, latency_ms: Date.now() - resolveStart });
|
|
3684
3768
|
return {
|
|
3685
3769
|
repo,
|
|
3686
3770
|
remoteCommands: createCodeStorageHttpCommands({ baseUrl, repoId, branch: input.branch || defaultBranch })
|
|
@@ -4221,7 +4305,7 @@ var GitHubClient = class {
|
|
|
4221
4305
|
// git/client.ts
|
|
4222
4306
|
var import_isomorphic_git = __toESM(require("isomorphic-git"), 1);
|
|
4223
4307
|
var import_node = __toESM(require("isomorphic-git/http/node"), 1);
|
|
4224
|
-
var
|
|
4308
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
4225
4309
|
var DEFAULT_PROXY_URL = "https://repos.morphllm.com";
|
|
4226
4310
|
var MorphGit = class {
|
|
4227
4311
|
apiKey;
|
|
@@ -4278,12 +4362,12 @@ var MorphGit = class {
|
|
|
4278
4362
|
throw new Error(`Failed to create repository: ${error}`);
|
|
4279
4363
|
}
|
|
4280
4364
|
await import_isomorphic_git.default.init({
|
|
4281
|
-
fs:
|
|
4365
|
+
fs: import_fs3.default,
|
|
4282
4366
|
dir,
|
|
4283
4367
|
defaultBranch
|
|
4284
4368
|
});
|
|
4285
4369
|
await import_isomorphic_git.default.addRemote({
|
|
4286
|
-
fs:
|
|
4370
|
+
fs: import_fs3.default,
|
|
4287
4371
|
dir,
|
|
4288
4372
|
remote: "origin",
|
|
4289
4373
|
url: `${this.proxyUrl}/v1/repos/${repoId}`
|
|
@@ -4304,7 +4388,7 @@ var MorphGit = class {
|
|
|
4304
4388
|
async clone(options) {
|
|
4305
4389
|
const { repoId, dir, branch = "main", depth, singleBranch = true } = options;
|
|
4306
4390
|
await import_isomorphic_git.default.clone({
|
|
4307
|
-
fs:
|
|
4391
|
+
fs: import_fs3.default,
|
|
4308
4392
|
http: import_node.default,
|
|
4309
4393
|
dir,
|
|
4310
4394
|
url: `${this.proxyUrl}/v1/repos/${repoId}`,
|
|
@@ -4333,9 +4417,9 @@ var MorphGit = class {
|
|
|
4333
4417
|
'branch is required for push operations. Specify the branch explicitly: { dir: "./my-project", branch: "main" }'
|
|
4334
4418
|
);
|
|
4335
4419
|
}
|
|
4336
|
-
const commitHash = await import_isomorphic_git.default.resolveRef({ fs:
|
|
4420
|
+
const commitHash = await import_isomorphic_git.default.resolveRef({ fs: import_fs3.default, dir, ref: "HEAD" });
|
|
4337
4421
|
let repoId;
|
|
4338
|
-
const remotes = await import_isomorphic_git.default.listRemotes({ fs:
|
|
4422
|
+
const remotes = await import_isomorphic_git.default.listRemotes({ fs: import_fs3.default, dir });
|
|
4339
4423
|
const originRemote = remotes.find((r) => r.remote === remote);
|
|
4340
4424
|
if (originRemote) {
|
|
4341
4425
|
const match = originRemote.url.match(/\/repos\/([^\/]+)$/);
|
|
@@ -4344,7 +4428,7 @@ var MorphGit = class {
|
|
|
4344
4428
|
}
|
|
4345
4429
|
}
|
|
4346
4430
|
await import_isomorphic_git.default.push({
|
|
4347
|
-
fs:
|
|
4431
|
+
fs: import_fs3.default,
|
|
4348
4432
|
http: import_node.default,
|
|
4349
4433
|
dir,
|
|
4350
4434
|
remote,
|
|
@@ -4399,7 +4483,7 @@ var MorphGit = class {
|
|
|
4399
4483
|
);
|
|
4400
4484
|
}
|
|
4401
4485
|
await import_isomorphic_git.default.pull({
|
|
4402
|
-
fs:
|
|
4486
|
+
fs: import_fs3.default,
|
|
4403
4487
|
http: import_node.default,
|
|
4404
4488
|
dir,
|
|
4405
4489
|
remote,
|
|
@@ -4468,7 +4552,7 @@ var MorphGit = class {
|
|
|
4468
4552
|
async add(options) {
|
|
4469
4553
|
const { dir, filepath } = options;
|
|
4470
4554
|
await import_isomorphic_git.default.add({
|
|
4471
|
-
fs:
|
|
4555
|
+
fs: import_fs3.default,
|
|
4472
4556
|
dir,
|
|
4473
4557
|
filepath
|
|
4474
4558
|
});
|
|
@@ -4487,7 +4571,7 @@ var MorphGit = class {
|
|
|
4487
4571
|
async remove(options) {
|
|
4488
4572
|
const { dir, filepath } = options;
|
|
4489
4573
|
await import_isomorphic_git.default.remove({
|
|
4490
|
-
fs:
|
|
4574
|
+
fs: import_fs3.default,
|
|
4491
4575
|
dir,
|
|
4492
4576
|
filepath
|
|
4493
4577
|
});
|
|
@@ -4520,7 +4604,7 @@ var MorphGit = class {
|
|
|
4520
4604
|
email: "sdk@morphllm.com"
|
|
4521
4605
|
};
|
|
4522
4606
|
const sha = await import_isomorphic_git.default.commit({
|
|
4523
|
-
fs:
|
|
4607
|
+
fs: import_fs3.default,
|
|
4524
4608
|
dir,
|
|
4525
4609
|
message,
|
|
4526
4610
|
author: commitAuthor
|
|
@@ -4533,7 +4617,7 @@ var MorphGit = class {
|
|
|
4533
4617
|
_version: 1
|
|
4534
4618
|
};
|
|
4535
4619
|
await import_isomorphic_git.default.addNote({
|
|
4536
|
-
fs:
|
|
4620
|
+
fs: import_fs3.default,
|
|
4537
4621
|
dir,
|
|
4538
4622
|
ref: "refs/notes/morph-metadata",
|
|
4539
4623
|
oid: sha,
|
|
@@ -4561,7 +4645,7 @@ var MorphGit = class {
|
|
|
4561
4645
|
throw new Error("filepath is required for status check");
|
|
4562
4646
|
}
|
|
4563
4647
|
const status = await import_isomorphic_git.default.status({
|
|
4564
|
-
fs:
|
|
4648
|
+
fs: import_fs3.default,
|
|
4565
4649
|
dir,
|
|
4566
4650
|
filepath
|
|
4567
4651
|
});
|
|
@@ -4581,7 +4665,7 @@ var MorphGit = class {
|
|
|
4581
4665
|
async log(options) {
|
|
4582
4666
|
const { dir, depth, ref } = options;
|
|
4583
4667
|
const commits = await import_isomorphic_git.default.log({
|
|
4584
|
-
fs:
|
|
4668
|
+
fs: import_fs3.default,
|
|
4585
4669
|
dir,
|
|
4586
4670
|
depth,
|
|
4587
4671
|
ref
|
|
@@ -4602,7 +4686,7 @@ var MorphGit = class {
|
|
|
4602
4686
|
async checkout(options) {
|
|
4603
4687
|
const { dir, ref } = options;
|
|
4604
4688
|
await import_isomorphic_git.default.checkout({
|
|
4605
|
-
fs:
|
|
4689
|
+
fs: import_fs3.default,
|
|
4606
4690
|
dir,
|
|
4607
4691
|
ref
|
|
4608
4692
|
});
|
|
@@ -4622,7 +4706,7 @@ var MorphGit = class {
|
|
|
4622
4706
|
async branch(options) {
|
|
4623
4707
|
const { dir, name, checkout = false } = options;
|
|
4624
4708
|
await import_isomorphic_git.default.branch({
|
|
4625
|
-
fs:
|
|
4709
|
+
fs: import_fs3.default,
|
|
4626
4710
|
dir,
|
|
4627
4711
|
ref: name,
|
|
4628
4712
|
checkout
|
|
@@ -4641,7 +4725,7 @@ var MorphGit = class {
|
|
|
4641
4725
|
async listBranches(options) {
|
|
4642
4726
|
const { dir } = options;
|
|
4643
4727
|
const branches = await import_isomorphic_git.default.listBranches({
|
|
4644
|
-
fs:
|
|
4728
|
+
fs: import_fs3.default,
|
|
4645
4729
|
dir
|
|
4646
4730
|
});
|
|
4647
4731
|
return branches;
|
|
@@ -4659,7 +4743,7 @@ var MorphGit = class {
|
|
|
4659
4743
|
async currentBranch(options) {
|
|
4660
4744
|
const { dir } = options;
|
|
4661
4745
|
const branch = await import_isomorphic_git.default.currentBranch({
|
|
4662
|
-
fs:
|
|
4746
|
+
fs: import_fs3.default,
|
|
4663
4747
|
dir
|
|
4664
4748
|
});
|
|
4665
4749
|
return branch || void 0;
|
|
@@ -4677,7 +4761,7 @@ var MorphGit = class {
|
|
|
4677
4761
|
async statusMatrix(options) {
|
|
4678
4762
|
const { dir } = options;
|
|
4679
4763
|
const matrix = await import_isomorphic_git.default.statusMatrix({
|
|
4680
|
-
fs:
|
|
4764
|
+
fs: import_fs3.default,
|
|
4681
4765
|
dir
|
|
4682
4766
|
});
|
|
4683
4767
|
return matrix.map(([filepath, HEADStatus, workdirStatus, stageStatus]) => {
|
|
@@ -4719,7 +4803,7 @@ var MorphGit = class {
|
|
|
4719
4803
|
async resolveRef(options) {
|
|
4720
4804
|
const { dir, ref } = options;
|
|
4721
4805
|
const oid = await import_isomorphic_git.default.resolveRef({
|
|
4722
|
-
fs:
|
|
4806
|
+
fs: import_fs3.default,
|
|
4723
4807
|
dir,
|
|
4724
4808
|
ref
|
|
4725
4809
|
});
|
|
@@ -4745,7 +4829,7 @@ var MorphGit = class {
|
|
|
4745
4829
|
async getCommitMetadata(options) {
|
|
4746
4830
|
try {
|
|
4747
4831
|
const note = await import_isomorphic_git.default.readNote({
|
|
4748
|
-
fs:
|
|
4832
|
+
fs: import_fs3.default,
|
|
4749
4833
|
dir: options.dir,
|
|
4750
4834
|
ref: "refs/notes/morph-metadata",
|
|
4751
4835
|
oid: options.commitSha
|
|
@@ -4763,6 +4847,7 @@ var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
|
|
|
4763
4847
|
var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
|
|
4764
4848
|
|
|
4765
4849
|
// modelrouter/core.ts
|
|
4850
|
+
init_logger();
|
|
4766
4851
|
var DEFAULT_CONFIG3 = {
|
|
4767
4852
|
apiUrl: "https://api.morphllm.com",
|
|
4768
4853
|
timeout: 5e3,
|
|
@@ -4798,12 +4883,7 @@ var BaseRouter = class {
|
|
|
4798
4883
|
input: input.input,
|
|
4799
4884
|
mode
|
|
4800
4885
|
};
|
|
4801
|
-
|
|
4802
|
-
console.log(`[ModelRouter] Requesting ${this.provider} model selection:`, {
|
|
4803
|
-
mode,
|
|
4804
|
-
inputLength: input.input.length
|
|
4805
|
-
});
|
|
4806
|
-
}
|
|
4886
|
+
logger.debug("ModelRouter", "request", { provider: this.provider, mode, input_len: input.input.length, url });
|
|
4807
4887
|
try {
|
|
4808
4888
|
const fetchPromise = fetchWithRetry(
|
|
4809
4889
|
url,
|
|
@@ -4832,14 +4912,10 @@ var BaseRouter = class {
|
|
|
4832
4912
|
const result = {
|
|
4833
4913
|
model: apiResult.model
|
|
4834
4914
|
};
|
|
4835
|
-
|
|
4836
|
-
console.log(`[ModelRouter] Selected model: ${apiResult.model}, Confidence: ${apiResult.confidence?.toFixed(3)}`);
|
|
4837
|
-
}
|
|
4915
|
+
logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model, confidence: apiResult.confidence });
|
|
4838
4916
|
return result;
|
|
4839
4917
|
} catch (error) {
|
|
4840
|
-
|
|
4841
|
-
console.error(`[ModelRouter] Error selecting model:`, error);
|
|
4842
|
-
}
|
|
4918
|
+
logger.error("ModelRouter", "error", { provider: this.provider, error: error instanceof Error ? error.message : String(error) });
|
|
4843
4919
|
throw error;
|
|
4844
4920
|
}
|
|
4845
4921
|
}
|
|
@@ -4909,12 +4985,7 @@ var RawRouter = class extends BaseRouter {
|
|
|
4909
4985
|
input: input.input,
|
|
4910
4986
|
mode
|
|
4911
4987
|
};
|
|
4912
|
-
|
|
4913
|
-
console.log(`[RawRouter] Requesting raw difficulty classification:`, {
|
|
4914
|
-
mode,
|
|
4915
|
-
inputLength: input.input.length
|
|
4916
|
-
});
|
|
4917
|
-
}
|
|
4988
|
+
logger.debug("RawRouter", "request", { mode, input_len: input.input.length, url });
|
|
4918
4989
|
try {
|
|
4919
4990
|
const fetchPromise = fetchWithRetry(
|
|
4920
4991
|
url,
|
|
@@ -4949,14 +5020,10 @@ var RawRouter = class extends BaseRouter {
|
|
|
4949
5020
|
const result = {
|
|
4950
5021
|
difficulty
|
|
4951
5022
|
};
|
|
4952
|
-
|
|
4953
|
-
console.log(`[RawRouter] Classified as: ${difficulty}`);
|
|
4954
|
-
}
|
|
5023
|
+
logger.debug("RawRouter", "classified", { difficulty });
|
|
4955
5024
|
return result;
|
|
4956
5025
|
} catch (error) {
|
|
4957
|
-
|
|
4958
|
-
console.error(`[RawRouter] Error classifying:`, error);
|
|
4959
|
-
}
|
|
5026
|
+
logger.error("RawRouter", "error", { error: error instanceof Error ? error.message : String(error) });
|
|
4960
5027
|
throw error;
|
|
4961
5028
|
}
|
|
4962
5029
|
}
|
|
@@ -6382,6 +6449,10 @@ var MorphClient = class {
|
|
|
6382
6449
|
*/
|
|
6383
6450
|
constructor(config = {}) {
|
|
6384
6451
|
this.config = config;
|
|
6452
|
+
if (config.debug) {
|
|
6453
|
+
logger.enable();
|
|
6454
|
+
}
|
|
6455
|
+
logger.debug("MorphClient", "initialized", { debug: !!config.debug, timeout: config.timeout });
|
|
6385
6456
|
this.fastApply = new FastApplyClient({
|
|
6386
6457
|
apiKey: config.apiKey,
|
|
6387
6458
|
debug: config.debug,
|