@morphllm/morphsdk 0.2.193 → 0.2.194
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-PI5TUSCU.js → chunk-2JKIWBME.js} +2 -2
- package/dist/{chunk-PPABZ2FR.js → chunk-2THF6MNE.js} +2 -2
- package/dist/{chunk-Z5Y5WBGI.js → chunk-33WVJLIT.js} +2 -2
- package/dist/{chunk-5JZHQGFA.js → chunk-74LJOCDW.js} +2 -2
- package/dist/{chunk-BMO22JIM.js → chunk-7KAW6EUG.js} +21 -21
- package/dist/{chunk-FLWWY5IP.js → chunk-A2SC5ZOG.js} +2 -2
- package/dist/{chunk-FLWWY5IP.js.map → chunk-A2SC5ZOG.js.map} +1 -1
- package/dist/{chunk-F3FIVK6A.js → chunk-C225GOV2.js} +2 -2
- package/dist/{chunk-OQZOP2PQ.js → chunk-CKSINYRF.js} +2 -2
- package/dist/{chunk-362NSH77.js → chunk-DL4EUMBV.js} +2 -2
- package/dist/{chunk-N4LGEYGW.js → chunk-EM7BMNSS.js} +2 -2
- package/dist/{chunk-HQ3N3YAO.js → chunk-FM2L35XC.js} +2 -2
- package/dist/{chunk-ONP3JVU3.js → chunk-GRYLQ2HM.js} +2 -2
- package/dist/{chunk-YTQSM7JP.js → chunk-GWXMT3S2.js} +9 -6
- package/dist/chunk-GWXMT3S2.js.map +1 -0
- package/dist/{chunk-3EVXYGJU.js → chunk-JIHDKRQW.js} +2 -2
- package/dist/chunk-KGHHK42W.js +399 -0
- package/dist/chunk-KGHHK42W.js.map +1 -0
- package/dist/{chunk-LATNDSMS.js → chunk-MFAIFUFK.js} +2 -2
- package/dist/{chunk-VLZ6PNAD.js → chunk-OPNTDMHH.js} +4 -4
- package/dist/{chunk-SOZM3BG3.js → chunk-PDSLRLYI.js} +3 -3
- package/dist/{chunk-MHWNJR5B.js → chunk-POUBLP4R.js} +4 -4
- package/dist/{chunk-23KRET2F.js → chunk-PPNJY7P3.js} +3 -3
- package/dist/{chunk-GXQXQMVG.js → chunk-PUTYJ2ET.js} +4 -4
- package/dist/{chunk-UXSK2O6V.js → chunk-QJSGHJ7D.js} +2 -2
- package/dist/{chunk-UEHQJLKC.js → chunk-S3V22W7M.js} +2 -2
- package/dist/{chunk-3GYCTQ3B.js → chunk-SU5FOI4R.js} +2 -2
- package/dist/{chunk-KGA3RGUQ.js → chunk-TAQLWNIF.js} +2 -2
- package/dist/{chunk-A7T7RKSW.js → chunk-TT37PYOQ.js} +2 -2
- package/dist/{chunk-TW3IQ357.js → chunk-U74U4ZFN.js} +2 -2
- package/dist/{chunk-ZWJUC7YK.js → chunk-UDZBOMRA.js} +3 -3
- package/dist/{chunk-WLTBLDXJ.js → chunk-VYDKGM7F.js} +9 -9
- package/dist/{chunk-EQI6CRLJ.js → chunk-WP44GN6A.js} +2 -2
- package/dist/{chunk-6HVOMKED.js → chunk-WXUMJSGG.js} +2 -2
- package/dist/{chunk-2BFAHP3U.js → chunk-XQR2U3LP.js} +3 -3
- package/dist/client.cjs +237 -26
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +29 -29
- package/dist/core/client.cjs +1 -1
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +1 -1
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +225 -23
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +9 -7
- package/dist/git/client.cjs +1 -1
- package/dist/git/client.cjs.map +1 -1
- package/dist/git/client.js +5 -5
- package/dist/git/index.cjs +1 -1
- package/dist/git/index.cjs.map +1 -1
- package/dist/git/index.js +5 -5
- package/dist/index.cjs +239 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -31
- package/dist/modelrouter/core.cjs +1 -1
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +1 -1
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +1 -1
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +10 -10
- package/dist/subagents/vercel.cjs +1 -1
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +10 -10
- package/dist/tools/browser/anthropic.cjs +1 -1
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +7 -7
- package/dist/tools/browser/core.cjs +1 -1
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +6 -6
- package/dist/tools/browser/index.cjs +1 -1
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +9 -9
- package/dist/tools/browser/openai.cjs +1 -1
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +7 -7
- package/dist/tools/browser/profiles/core.cjs +1 -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 +1 -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 +1 -1
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +7 -7
- package/dist/tools/codebase_search/anthropic.cjs +1 -1
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +6 -6
- package/dist/tools/codebase_search/core.cjs +1 -1
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +5 -5
- package/dist/tools/codebase_search/index.cjs +1 -1
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +8 -8
- package/dist/tools/codebase_search/openai.cjs +1 -1
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +6 -6
- package/dist/tools/codebase_search/vercel.cjs +1 -1
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +6 -6
- package/dist/tools/compact/core.cjs +1 -1
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +1 -1
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +237 -26
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +225 -23
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.d.ts +8 -1
- package/dist/tools/fastapply/apply.js +4 -2
- package/dist/tools/fastapply/core.cjs +239 -26
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.d.ts +1 -1
- package/dist/tools/fastapply/core.js +8 -6
- package/dist/tools/fastapply/index.cjs +239 -26
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.d.ts +1 -1
- package/dist/tools/fastapply/index.js +11 -9
- package/dist/tools/fastapply/openai.cjs +237 -26
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/types.cjs.map +1 -1
- package/dist/tools/fastapply/types.d.ts +10 -2
- package/dist/tools/fastapply/vercel.cjs +237 -26
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +239 -26
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +11 -9
- package/dist/tools/reflex/core.cjs +1 -1
- package/dist/tools/reflex/core.cjs.map +1 -1
- package/dist/tools/reflex/core.js +5 -5
- package/dist/tools/reflex/index.cjs +1 -1
- package/dist/tools/reflex/index.cjs.map +1 -1
- package/dist/tools/reflex/index.js +5 -5
- package/dist/tools/utils/resilience.cjs +1 -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 +1 -1
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/anthropic.cjs +1 -1
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +10 -10
- package/dist/tools/warp_grep/client.cjs +1 -1
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +9 -9
- package/dist/tools/warp_grep/gemini.cjs +1 -1
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +9 -9
- package/dist/tools/warp_grep/harness.js +2 -2
- package/dist/tools/warp_grep/index.cjs +1 -1
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +14 -14
- package/dist/tools/warp_grep/openai.cjs +1 -1
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +10 -10
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/vercel.cjs +1 -1
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +10 -10
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-VPDOBYJE.js +0 -196
- package/dist/chunk-VPDOBYJE.js.map +0 -1
- package/dist/chunk-YTQSM7JP.js.map +0 -1
- /package/dist/{chunk-PI5TUSCU.js.map → chunk-2JKIWBME.js.map} +0 -0
- /package/dist/{chunk-PPABZ2FR.js.map → chunk-2THF6MNE.js.map} +0 -0
- /package/dist/{chunk-Z5Y5WBGI.js.map → chunk-33WVJLIT.js.map} +0 -0
- /package/dist/{chunk-5JZHQGFA.js.map → chunk-74LJOCDW.js.map} +0 -0
- /package/dist/{chunk-BMO22JIM.js.map → chunk-7KAW6EUG.js.map} +0 -0
- /package/dist/{chunk-F3FIVK6A.js.map → chunk-C225GOV2.js.map} +0 -0
- /package/dist/{chunk-OQZOP2PQ.js.map → chunk-CKSINYRF.js.map} +0 -0
- /package/dist/{chunk-362NSH77.js.map → chunk-DL4EUMBV.js.map} +0 -0
- /package/dist/{chunk-N4LGEYGW.js.map → chunk-EM7BMNSS.js.map} +0 -0
- /package/dist/{chunk-HQ3N3YAO.js.map → chunk-FM2L35XC.js.map} +0 -0
- /package/dist/{chunk-ONP3JVU3.js.map → chunk-GRYLQ2HM.js.map} +0 -0
- /package/dist/{chunk-3EVXYGJU.js.map → chunk-JIHDKRQW.js.map} +0 -0
- /package/dist/{chunk-LATNDSMS.js.map → chunk-MFAIFUFK.js.map} +0 -0
- /package/dist/{chunk-VLZ6PNAD.js.map → chunk-OPNTDMHH.js.map} +0 -0
- /package/dist/{chunk-SOZM3BG3.js.map → chunk-PDSLRLYI.js.map} +0 -0
- /package/dist/{chunk-MHWNJR5B.js.map → chunk-POUBLP4R.js.map} +0 -0
- /package/dist/{chunk-23KRET2F.js.map → chunk-PPNJY7P3.js.map} +0 -0
- /package/dist/{chunk-GXQXQMVG.js.map → chunk-PUTYJ2ET.js.map} +0 -0
- /package/dist/{chunk-UXSK2O6V.js.map → chunk-QJSGHJ7D.js.map} +0 -0
- /package/dist/{chunk-UEHQJLKC.js.map → chunk-S3V22W7M.js.map} +0 -0
- /package/dist/{chunk-3GYCTQ3B.js.map → chunk-SU5FOI4R.js.map} +0 -0
- /package/dist/{chunk-KGA3RGUQ.js.map → chunk-TAQLWNIF.js.map} +0 -0
- /package/dist/{chunk-A7T7RKSW.js.map → chunk-TT37PYOQ.js.map} +0 -0
- /package/dist/{chunk-TW3IQ357.js.map → chunk-U74U4ZFN.js.map} +0 -0
- /package/dist/{chunk-ZWJUC7YK.js.map → chunk-UDZBOMRA.js.map} +0 -0
- /package/dist/{chunk-WLTBLDXJ.js.map → chunk-VYDKGM7F.js.map} +0 -0
- /package/dist/{chunk-EQI6CRLJ.js.map → chunk-WP44GN6A.js.map} +0 -0
- /package/dist/{chunk-6HVOMKED.js.map → chunk-WXUMJSGG.js.map} +0 -0
- /package/dist/{chunk-2BFAHP3U.js.map → chunk-XQR2U3LP.js.map} +0 -0
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.194",
|
|
40
40
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
41
41
|
type: "module",
|
|
42
42
|
main: "./dist/index.cjs",
|
|
@@ -366,9 +366,185 @@ var init_logger = __esm({
|
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
|
|
369
|
+
// tools/fastapply/anchors.ts
|
|
370
|
+
function escapeRegExp(value) {
|
|
371
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
372
|
+
}
|
|
373
|
+
function findNamespace(values) {
|
|
374
|
+
for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
|
|
375
|
+
const prefix = `\u27EAM${namespace}:`;
|
|
376
|
+
if (values.every((value) => !value.includes(prefix))) {
|
|
377
|
+
return namespace;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
throw new Error("Unable to allocate a Fast Apply anchor namespace");
|
|
381
|
+
}
|
|
382
|
+
function htmlLabel(token) {
|
|
383
|
+
if (!token.startsWith("<")) return "text";
|
|
384
|
+
const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
|
|
385
|
+
return (match?.[1] ?? "tag").toLowerCase();
|
|
386
|
+
}
|
|
387
|
+
function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
|
|
388
|
+
return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
|
|
389
|
+
value: token,
|
|
390
|
+
label: htmlLabel(token),
|
|
391
|
+
anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
function sourceUnits(originalCode, editContext) {
|
|
395
|
+
const trimmed = originalCode.trimStart().toLowerCase();
|
|
396
|
+
const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
|
|
397
|
+
if (looksLikeHtml) {
|
|
398
|
+
const contextWords = new Set(
|
|
399
|
+
editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
|
|
400
|
+
);
|
|
401
|
+
return htmlTokenUnits(originalCode, contextWords);
|
|
402
|
+
}
|
|
403
|
+
const parts = originalCode.split(/(\r\n|\n|\r)/);
|
|
404
|
+
const units = [];
|
|
405
|
+
for (let index = 0; index < parts.length; index += 2) {
|
|
406
|
+
const line = parts[index] ?? "";
|
|
407
|
+
const lineEnding = parts[index + 1] ?? "";
|
|
408
|
+
units.push({
|
|
409
|
+
value: line,
|
|
410
|
+
label: "line",
|
|
411
|
+
anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
|
|
412
|
+
});
|
|
413
|
+
if (lineEnding) {
|
|
414
|
+
units.push({ value: lineEnding, anchorable: false });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return units;
|
|
418
|
+
}
|
|
419
|
+
function copyCount(value) {
|
|
420
|
+
const words = {
|
|
421
|
+
one: 1,
|
|
422
|
+
two: 2,
|
|
423
|
+
three: 3,
|
|
424
|
+
four: 4,
|
|
425
|
+
five: 5,
|
|
426
|
+
six: 6,
|
|
427
|
+
seven: 7,
|
|
428
|
+
eight: 8,
|
|
429
|
+
nine: 9,
|
|
430
|
+
ten: 10
|
|
431
|
+
};
|
|
432
|
+
return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
|
|
433
|
+
}
|
|
434
|
+
function structuralExpectation(originalCode, editContext) {
|
|
435
|
+
const context = editContext.join(" ");
|
|
436
|
+
const match = context.match(
|
|
437
|
+
/(?:for every|for each|each)\s+([a-z][\w:-]*)[\s\S]{0,120}?add\s+(one|two|three|four|five|six|seven|eight|nine|ten|\d+)\s+identical cop(?:y|ies)/i
|
|
438
|
+
);
|
|
439
|
+
if (!match) return void 0;
|
|
440
|
+
const tag = match[1].toLowerCase();
|
|
441
|
+
const addedCopies = copyCount(match[2]);
|
|
442
|
+
if (addedCopies === void 0) return void 0;
|
|
443
|
+
const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
|
|
444
|
+
const originalCount = originalCode.match(tagPattern)?.length ?? 0;
|
|
445
|
+
if (originalCount === 0) return void 0;
|
|
446
|
+
return { tag, expectedCount: originalCount * (addedCopies + 1) };
|
|
447
|
+
}
|
|
448
|
+
function createAnchorCompactionPlan(originalCode, collisionValues = []) {
|
|
449
|
+
const namespace = findNamespace([originalCode, ...collisionValues]);
|
|
450
|
+
const expectation = structuralExpectation(originalCode, collisionValues);
|
|
451
|
+
const markerPrefix = `\u27EAM${namespace}:`;
|
|
452
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
453
|
+
const values = [];
|
|
454
|
+
const markers = [];
|
|
455
|
+
let anchorCount = 0;
|
|
456
|
+
let skeleton = "";
|
|
457
|
+
for (const unit of sourceUnits(originalCode, collisionValues)) {
|
|
458
|
+
if (!unit.anchorable) {
|
|
459
|
+
skeleton += unit.value;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
let id = definitions.get(unit.value);
|
|
463
|
+
if (id === void 0) {
|
|
464
|
+
id = values.length;
|
|
465
|
+
definitions.set(unit.value, id);
|
|
466
|
+
values.push(unit.value);
|
|
467
|
+
markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
|
|
468
|
+
}
|
|
469
|
+
skeleton += markers[id];
|
|
470
|
+
anchorCount++;
|
|
471
|
+
}
|
|
472
|
+
if (anchorCount === 0 || skeleton.length >= originalCode.length) {
|
|
473
|
+
return void 0;
|
|
474
|
+
}
|
|
475
|
+
const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
|
|
476
|
+
const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
|
|
477
|
+
const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
|
|
478
|
+
const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
|
|
479
|
+
const code = [
|
|
480
|
+
definitionsBegin,
|
|
481
|
+
serializedDefinitions,
|
|
482
|
+
definitionsEnd,
|
|
483
|
+
codeBegin,
|
|
484
|
+
skeleton
|
|
485
|
+
].join("\n");
|
|
486
|
+
const instructionSuffix = `
|
|
487
|
+
|
|
488
|
+
LARGE-FILE ANCHOR PROTOCOL:
|
|
489
|
+
The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
|
|
490
|
+
Each ${markerPrefix}N:kind\u27EB placeholder represents the exact source fragment in its matching JSON-string definition. The kind suffix describes its HTML tag, text, or source line.
|
|
491
|
+
Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
|
|
492
|
+
Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
|
|
493
|
+
To modify an anchored fragment, output the modified source instead of its placeholder.
|
|
494
|
+
Do not invent or alter placeholder IDs.`;
|
|
495
|
+
const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
|
|
496
|
+
return {
|
|
497
|
+
code,
|
|
498
|
+
instructionSuffix,
|
|
499
|
+
anchorCount,
|
|
500
|
+
uniqueAnchorCount: values.length,
|
|
501
|
+
hasStructuralValidation: expectation !== void 0,
|
|
502
|
+
expand(content) {
|
|
503
|
+
const codeBeginIndex = content.lastIndexOf(codeBegin);
|
|
504
|
+
const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
|
|
505
|
+
const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
|
|
506
|
+
const id = Number(idText);
|
|
507
|
+
const value = values[id];
|
|
508
|
+
return value === void 0 || markers[id] !== marker ? marker : value;
|
|
509
|
+
});
|
|
510
|
+
if (expanded.includes(markerPrefix)) {
|
|
511
|
+
throw new FastApplyAnchorIntegrityError();
|
|
512
|
+
}
|
|
513
|
+
if (expectation) {
|
|
514
|
+
const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
|
|
515
|
+
const actualCount = expanded.match(tagPattern)?.length ?? 0;
|
|
516
|
+
if (actualCount !== expectation.expectedCount) {
|
|
517
|
+
throw new FastApplyAnchorIntegrityError();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return expanded;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
var DEFAULT_MIN_ANCHOR_LINE_LENGTH, DEFAULT_ANCHOR_COMPACTION_THRESHOLD, FastApplyAnchorIntegrityError;
|
|
525
|
+
var init_anchors = __esm({
|
|
526
|
+
"tools/fastapply/anchors.ts"() {
|
|
527
|
+
"use strict";
|
|
528
|
+
DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
|
|
529
|
+
DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
|
|
530
|
+
FastApplyAnchorIntegrityError = class extends Error {
|
|
531
|
+
code = "anchor_integrity_failed";
|
|
532
|
+
completionId;
|
|
533
|
+
constructor(completionId) {
|
|
534
|
+
super(
|
|
535
|
+
"Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
|
|
536
|
+
);
|
|
537
|
+
this.name = "FastApplyAnchorIntegrityError";
|
|
538
|
+
this.completionId = completionId;
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
369
544
|
// tools/fastapply/apply.ts
|
|
370
545
|
var apply_exports = {};
|
|
371
546
|
__export(apply_exports, {
|
|
547
|
+
FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
|
|
372
548
|
FastApplyContextLengthError: () => FastApplyContextLengthError,
|
|
373
549
|
applyEdit: () => applyEdit,
|
|
374
550
|
callMorphAPI: () => callMorphAPI,
|
|
@@ -444,8 +620,12 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
444
620
|
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
445
621
|
);
|
|
446
622
|
}
|
|
447
|
-
const
|
|
448
|
-
|
|
623
|
+
const anchorThreshold = config.anchorCompactionThreshold ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;
|
|
624
|
+
const anchorPlan = config.anchorCompaction !== false && originalCode.length >= anchorThreshold ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions]) : void 0;
|
|
625
|
+
const requestCode = anchorPlan?.code ?? originalCode;
|
|
626
|
+
const requestInstructions = anchorPlan ? instructions + anchorPlan.instructionSuffix : instructions;
|
|
627
|
+
const message = `<instruction>${requestInstructions}</instruction>
|
|
628
|
+
<code>${requestCode}</code>
|
|
449
629
|
<update>${codeEdit}</update>`;
|
|
450
630
|
logger.debug("FastApply", "http_request", {
|
|
451
631
|
url: `${apiUrl}/v1/chat/completions`,
|
|
@@ -453,7 +633,10 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
453
633
|
filepath,
|
|
454
634
|
instruction_len: instructions.length,
|
|
455
635
|
original_len: originalCode.length,
|
|
456
|
-
|
|
636
|
+
request_code_len: requestCode.length,
|
|
637
|
+
code_edit_len: codeEdit.length,
|
|
638
|
+
anchor_count: anchorPlan?.anchorCount ?? 0,
|
|
639
|
+
unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0
|
|
457
640
|
});
|
|
458
641
|
const startTime = Date.now();
|
|
459
642
|
const client = new import_openai.default({
|
|
@@ -461,25 +644,49 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
461
644
|
baseURL: `${apiUrl}/v1`,
|
|
462
645
|
timeout,
|
|
463
646
|
maxRetries: config.retryConfig?.maxRetries ?? 3,
|
|
464
|
-
defaultHeaders: {
|
|
647
|
+
defaultHeaders: {
|
|
648
|
+
"X-Morph-SDK-Version": SDK_VERSION,
|
|
649
|
+
...anchorPlan ? { "X-Morph-Apply-Context": "extralong" } : {}
|
|
650
|
+
}
|
|
465
651
|
});
|
|
466
652
|
try {
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
653
|
+
const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;
|
|
654
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
655
|
+
const response = await client.chat.completions.create({
|
|
656
|
+
model,
|
|
657
|
+
messages: [{ role: "user", content: message }],
|
|
658
|
+
stream: true
|
|
659
|
+
});
|
|
660
|
+
const completion = await collectCompletion(response);
|
|
661
|
+
if (completion.finishReason === "length") {
|
|
662
|
+
throw new FastApplyContextLengthError(completion.completionId);
|
|
663
|
+
}
|
|
664
|
+
let content = completion.content;
|
|
665
|
+
if (!content) {
|
|
666
|
+
throw new Error("Morph API returned empty response");
|
|
667
|
+
}
|
|
668
|
+
if (anchorPlan) {
|
|
669
|
+
try {
|
|
670
|
+
content = anchorPlan.expand(content);
|
|
671
|
+
} catch (error) {
|
|
672
|
+
if (error instanceof FastApplyAnchorIntegrityError) {
|
|
673
|
+
if (attempt < maxAttempts) {
|
|
674
|
+
logger.warn("FastApply", "anchor_validation_retry", {
|
|
675
|
+
attempt,
|
|
676
|
+
completion_id: completion.completionId
|
|
677
|
+
});
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
throw new FastApplyAnchorIntegrityError(completion.completionId);
|
|
681
|
+
}
|
|
682
|
+
throw error;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const elapsed = Date.now() - startTime;
|
|
686
|
+
logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
|
|
687
|
+
return { content, completionId: completion.completionId };
|
|
479
688
|
}
|
|
480
|
-
|
|
481
|
-
logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
|
|
482
|
-
return { content, completionId: completion.completionId };
|
|
689
|
+
throw new FastApplyAnchorIntegrityError();
|
|
483
690
|
} catch (error) {
|
|
484
691
|
const elapsed = Date.now() - startTime;
|
|
485
692
|
const status = error?.status || error?.response?.status;
|
|
@@ -529,13 +736,13 @@ async function applyEdit(input, config = {}) {
|
|
|
529
736
|
} catch (error) {
|
|
530
737
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
531
738
|
logger.error("FastApply", "apply_edit_error", { error: errorMessage });
|
|
532
|
-
const
|
|
739
|
+
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
533
740
|
return {
|
|
534
741
|
success: false,
|
|
535
742
|
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
536
743
|
error: errorMessage,
|
|
537
|
-
errorCode:
|
|
538
|
-
completionId:
|
|
744
|
+
errorCode: structuredError?.code,
|
|
745
|
+
completionId: structuredError?.completionId
|
|
539
746
|
};
|
|
540
747
|
}
|
|
541
748
|
}
|
|
@@ -547,6 +754,8 @@ var init_apply = __esm({
|
|
|
547
754
|
import_openai = __toESM(require("openai"), 1);
|
|
548
755
|
init_version();
|
|
549
756
|
init_logger();
|
|
757
|
+
init_anchors();
|
|
758
|
+
init_anchors();
|
|
550
759
|
DEFAULT_API_URL = "https://api.morphllm.com";
|
|
551
760
|
DEFAULT_TIMEOUT2 = 6e5;
|
|
552
761
|
FastApplyContextLengthError = class extends Error {
|
|
@@ -1159,6 +1368,7 @@ __export(index_exports, {
|
|
|
1159
1368
|
BrowserClient: () => BrowserClient,
|
|
1160
1369
|
CodebaseSearchClient: () => CodebaseSearchClient,
|
|
1161
1370
|
CompactClient: () => CompactClient,
|
|
1371
|
+
FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
|
|
1162
1372
|
FastApplyClient: () => FastApplyClient,
|
|
1163
1373
|
FastApplyContextLengthError: () => FastApplyContextLengthError,
|
|
1164
1374
|
GeminiRouter: () => GeminiRouter,
|
|
@@ -1415,6 +1625,8 @@ var DEFAULT_CONFIG = {
|
|
|
1415
1625
|
generateUdiff: true,
|
|
1416
1626
|
autoWrite: true,
|
|
1417
1627
|
timeout: 6e5,
|
|
1628
|
+
anchorCompaction: true,
|
|
1629
|
+
anchorCompactionThreshold: 128 * 1024,
|
|
1418
1630
|
debug: false
|
|
1419
1631
|
};
|
|
1420
1632
|
var FastApplyClient = class extends APIResource {
|
|
@@ -1524,15 +1736,15 @@ async function executeEditFile(input, config = {}) {
|
|
|
1524
1736
|
};
|
|
1525
1737
|
} catch (error) {
|
|
1526
1738
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1527
|
-
const
|
|
1739
|
+
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
1528
1740
|
logger.error("FastApply", "execute_error", { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : void 0 });
|
|
1529
1741
|
return {
|
|
1530
1742
|
success: false,
|
|
1531
1743
|
filepath: input.target_filepath,
|
|
1532
1744
|
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
1533
1745
|
error: errorMessage,
|
|
1534
|
-
errorCode:
|
|
1535
|
-
completionId:
|
|
1746
|
+
errorCode: structuredError?.code,
|
|
1747
|
+
completionId: structuredError?.completionId
|
|
1536
1748
|
};
|
|
1537
1749
|
}
|
|
1538
1750
|
}
|
|
@@ -7006,6 +7218,7 @@ var warpGrepInputSchema = import_zod5.z.object({
|
|
|
7006
7218
|
BrowserClient,
|
|
7007
7219
|
CodebaseSearchClient,
|
|
7008
7220
|
CompactClient,
|
|
7221
|
+
FastApplyAnchorIntegrityError,
|
|
7009
7222
|
FastApplyClient,
|
|
7010
7223
|
FastApplyContextLengthError,
|
|
7011
7224
|
GeminiRouter,
|