@morphllm/morphsdk 0.2.201 → 0.2.203
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-2PPYWRMZ.js +3 -4
- package/dist/{chunk-DBNSOYQ3.js → chunk-2UIOCSVJ.js} +3 -24
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/chunk-4R5MDGL6.cjs +280 -0
- package/dist/chunk-65W4I66Q.cjs +103 -0
- package/dist/{chunk-WBTXEJOC.js → chunk-66THRMD7.js} +10 -35
- package/dist/chunk-6TZCVTW5.js +3 -4
- package/dist/chunk-6WP7EA4F.js +2 -4
- package/dist/chunk-74A4HLIO.cjs +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7NA7X7W2.cjs +77 -0
- package/dist/chunk-7PJYY46L.cjs +2 -0
- package/dist/chunk-AFF6XYKL.cjs +71 -0
- package/dist/{chunk-P2KW2O5R.js → chunk-AJBZA23L.js} +3 -25
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/{chunk-FVT4PU4I.js → chunk-AXEKIRRY.js} +22 -62
- package/dist/chunk-B3FD67F2.cjs +256 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/{chunk-M6AVXUM4.js → chunk-E3XNKAMI.js} +5 -15
- package/dist/{chunk-TS3OJ4LA.js → chunk-E7FLETFO.js} +2 -8
- package/dist/{chunk-EQAWWVKV.js → chunk-EI2M567U.js} +2 -6
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/{chunk-VOXUA5ZH.js → chunk-EZ2OFDBJ.js} +5 -19
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-TZC3EOZS.js → chunk-GDFPZ3NJ.js} +4 -19
- package/dist/{chunk-LISSWRUD.js → chunk-GIQAIHUI.js} +8 -33
- package/dist/chunk-GSUQGDCL.cjs +235 -0
- package/dist/{chunk-5NSYDT36.js → chunk-H3HRSRR5.js} +4 -12
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HMLYJVZM.cjs +410 -0
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/{chunk-B376VMIH.js → chunk-IUM6CQYX.js} +3 -12
- package/dist/{chunk-OVLUL5AC.js → chunk-J56Q6C4Y.js} +4 -18
- package/dist/chunk-JBTR3FQD.cjs +135 -0
- package/dist/chunk-JNQKQKHS.cjs +81 -0
- package/dist/chunk-JOZC4T6C.cjs +168 -0
- package/dist/{chunk-ILY5N5NJ.js → chunk-JUGNTIVU.js} +6 -19
- package/dist/{chunk-SU7AAS3O.js → chunk-JY6COF3X.js} +5 -22
- package/dist/{chunk-JBAY3PRV.js → chunk-KLVJIC2O.js} +5 -17
- package/dist/chunk-KSZYOX6S.cjs +91 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-RZOJ4GSY.js → chunk-LLQH6CCB.js} +10 -28
- package/dist/chunk-M34E2AMK.js +1 -5
- package/dist/chunk-MF56KEI4.js +1 -4
- package/dist/chunk-MLKGABMK.js +1 -3
- package/dist/{chunk-I26FQELI.js → chunk-MLPZKUCO.js} +11 -5
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/{chunk-NWGRW4V7.js → chunk-N7UKZ5X7.js} +2 -6
- package/dist/chunk-NDUC7OV6.cjs +74 -0
- package/dist/{chunk-RJXAXR7Q.js → chunk-NLACTMZT.js} +6 -19
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCCGJ4S6.js +8 -0
- package/dist/chunk-ODY2NKQU.cjs +50 -0
- package/dist/chunk-OM5ZSXQW.cjs +91 -0
- package/dist/chunk-OOEORM7H.cjs +334 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/{chunk-BZXOAC2R.js → chunk-OSL4CNSO.js} +7 -23
- package/dist/chunk-OXXMTDOY.cjs +86 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/chunk-S6QBPXBI.cjs +107 -0
- package/dist/chunk-TL34BLQD.cjs +10 -0
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UUCRWJJR.cjs +313 -0
- package/dist/chunk-VDFLPO7B.cjs +396 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-ZLG2M2I4.cjs +21 -0
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/client.cjs +40 -4353
- package/dist/client.js +32 -37
- package/dist/core/client.cjs +10 -476
- package/dist/core/client.js +6 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +20 -488
- package/dist/core/index.js +8 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +62 -1111
- package/dist/edge.js +10 -42
- package/dist/index.cjs +115 -4424
- package/dist/index.js +39 -87
- package/dist/modelrouter/core.cjs +28 -648
- package/dist/modelrouter/core.js +8 -21
- package/dist/modelrouter/index.cjs +28 -648
- package/dist/modelrouter/index.js +8 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +27 -2777
- package/dist/subagents/anthropic.js +19 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +27 -2754
- package/dist/subagents/vercel.js +19 -24
- package/dist/tools/compact/core.cjs +12 -548
- package/dist/tools/compact/core.js +8 -13
- package/dist/tools/compact/index.cjs +17 -595
- package/dist/tools/compact/index.js +9 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +27 -891
- package/dist/tools/fastapply/anthropic.js +11 -24
- package/dist/tools/fastapply/apply.cjs +28 -672
- package/dist/tools/fastapply/apply.js +4 -19
- package/dist/tools/fastapply/core.cjs +37 -1061
- package/dist/tools/fastapply/core.js +9 -29
- package/dist/tools/fastapply/index.cjs +62 -1062
- package/dist/tools/fastapply/index.js +14 -44
- package/dist/tools/fastapply/openai.cjs +32 -901
- package/dist/tools/fastapply/openai.js +11 -26
- package/dist/tools/fastapply/prompts.cjs +10 -62
- package/dist/tools/fastapply/prompts.js +2 -9
- package/dist/tools/fastapply/types.cjs +1 -17
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +25 -897
- package/dist/tools/fastapply/vercel.js +11 -22
- package/dist/tools/index.cjs +62 -1062
- package/dist/tools/index.js +14 -44
- package/dist/tools/utils/resilience.cjs +15 -312
- package/dist/tools/utils/resilience.js +3 -12
- package/dist/tools/warp_grep/agent/config.cjs +16 -127
- package/dist/tools/warp_grep/agent/config.js +2 -11
- package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
- package/dist/tools/warp_grep/agent/formatter.js +2 -9
- package/dist/tools/warp_grep/agent/parser.cjs +16 -83
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
- package/dist/tools/warp_grep/agent/runner.js +7 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +47 -2554
- package/dist/tools/warp_grep/anthropic.js +19 -35
- package/dist/tools/warp_grep/client.cjs +49 -2464
- package/dist/tools/warp_grep/client.js +17 -34
- package/dist/tools/warp_grep/gemini.cjs +48 -2483
- package/dist/tools/warp_grep/gemini.js +21 -41
- package/dist/tools/warp_grep/harness.cjs +81 -929
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +124 -2568
- package/dist/tools/warp_grep/index.js +24 -87
- package/dist/tools/warp_grep/openai.cjs +53 -2568
- package/dist/tools/warp_grep/openai.js +19 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
- package/dist/tools/warp_grep/providers/local.cjs +10 -582
- package/dist/tools/warp_grep/providers/local.js +6 -11
- package/dist/tools/warp_grep/providers/remote.cjs +8 -331
- package/dist/tools/warp_grep/providers/remote.js +3 -8
- package/dist/tools/warp_grep/providers/types.cjs +1 -17
- package/dist/tools/warp_grep/providers/types.js +1 -0
- package/dist/tools/warp_grep/utils/files.cjs +9 -42
- package/dist/tools/warp_grep/utils/files.js +2 -7
- package/dist/tools/warp_grep/utils/github.cjs +9 -43
- package/dist/tools/warp_grep/utils/github.js +2 -7
- package/dist/tools/warp_grep/utils/paths.cjs +28 -104
- package/dist/tools/warp_grep/utils/paths.js +2 -17
- package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -86
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +53 -2550
- package/dist/tools/warp_grep/vercel.js +19 -37
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +2 -2
- package/dist/chunk-UZCXOOZO.js +0 -203
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVL4QNALG_cjs = require('./chunk-VL4QNALG.cjs');
|
|
4
|
+
var chunkTL34BLQD_cjs = require('./chunk-TL34BLQD.cjs');
|
|
5
|
+
var diff = require('diff');
|
|
6
|
+
var OpenAI = require('openai');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var OpenAI__default = /*#__PURE__*/_interopDefault(OpenAI);
|
|
11
|
+
|
|
12
|
+
// tools/fastapply/anchors.ts
|
|
13
|
+
var DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
|
|
14
|
+
var DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
|
|
15
|
+
var FastApplyAnchorIntegrityError = class extends Error {
|
|
16
|
+
code = "anchor_integrity_failed";
|
|
17
|
+
completionId;
|
|
18
|
+
constructor(completionId) {
|
|
19
|
+
super(
|
|
20
|
+
"Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
|
|
21
|
+
);
|
|
22
|
+
this.name = "FastApplyAnchorIntegrityError";
|
|
23
|
+
this.completionId = completionId;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function escapeRegExp(value) {
|
|
27
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
28
|
+
}
|
|
29
|
+
function findNamespace(values) {
|
|
30
|
+
for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
|
|
31
|
+
const prefix = `\u27EAM${namespace}:`;
|
|
32
|
+
if (values.every((value) => !value.includes(prefix))) {
|
|
33
|
+
return namespace;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw new Error("Unable to allocate a Fast Apply anchor namespace");
|
|
37
|
+
}
|
|
38
|
+
function htmlLabel(token) {
|
|
39
|
+
if (!token.startsWith("<")) return "text";
|
|
40
|
+
const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
|
|
41
|
+
return (match?.[1] ?? "tag").toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
|
|
44
|
+
return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
|
|
45
|
+
value: token,
|
|
46
|
+
label: htmlLabel(token),
|
|
47
|
+
anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
function sourceUnits(originalCode, editContext) {
|
|
51
|
+
const trimmed = originalCode.trimStart().toLowerCase();
|
|
52
|
+
const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
|
|
53
|
+
if (looksLikeHtml) {
|
|
54
|
+
const contextWords = new Set(
|
|
55
|
+
editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
|
|
56
|
+
);
|
|
57
|
+
return htmlTokenUnits(originalCode, contextWords);
|
|
58
|
+
}
|
|
59
|
+
const parts = originalCode.split(/(\r\n|\n|\r)/);
|
|
60
|
+
const units = [];
|
|
61
|
+
for (let index = 0; index < parts.length; index += 2) {
|
|
62
|
+
const line = parts[index] ?? "";
|
|
63
|
+
const lineEnding = parts[index + 1] ?? "";
|
|
64
|
+
units.push({
|
|
65
|
+
value: line,
|
|
66
|
+
label: "line",
|
|
67
|
+
anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
|
|
68
|
+
});
|
|
69
|
+
if (lineEnding) {
|
|
70
|
+
units.push({ value: lineEnding, anchorable: false });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return units;
|
|
74
|
+
}
|
|
75
|
+
function copyCount(value) {
|
|
76
|
+
const words = {
|
|
77
|
+
one: 1,
|
|
78
|
+
two: 2,
|
|
79
|
+
three: 3,
|
|
80
|
+
four: 4,
|
|
81
|
+
five: 5,
|
|
82
|
+
six: 6,
|
|
83
|
+
seven: 7,
|
|
84
|
+
eight: 8,
|
|
85
|
+
nine: 9,
|
|
86
|
+
ten: 10
|
|
87
|
+
};
|
|
88
|
+
return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
|
|
89
|
+
}
|
|
90
|
+
function structuralExpectation(originalCode, editContext) {
|
|
91
|
+
const context = editContext.join(" ");
|
|
92
|
+
const match = context.match(
|
|
93
|
+
/(?: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
|
|
94
|
+
);
|
|
95
|
+
if (!match) return void 0;
|
|
96
|
+
const tag = match[1].toLowerCase();
|
|
97
|
+
const addedCopies = copyCount(match[2]);
|
|
98
|
+
if (addedCopies === void 0) return void 0;
|
|
99
|
+
const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
|
|
100
|
+
const originalCount = originalCode.match(tagPattern)?.length ?? 0;
|
|
101
|
+
if (originalCount === 0) return void 0;
|
|
102
|
+
return { tag, expectedCount: originalCount * (addedCopies + 1) };
|
|
103
|
+
}
|
|
104
|
+
function createAnchorCompactionPlan(originalCode, collisionValues = []) {
|
|
105
|
+
const namespace = findNamespace([originalCode, ...collisionValues]);
|
|
106
|
+
const expectation = structuralExpectation(originalCode, collisionValues);
|
|
107
|
+
const markerPrefix = `\u27EAM${namespace}:`;
|
|
108
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
109
|
+
const values = [];
|
|
110
|
+
const markers = [];
|
|
111
|
+
let anchorCount = 0;
|
|
112
|
+
let skeleton = "";
|
|
113
|
+
for (const unit of sourceUnits(originalCode, collisionValues)) {
|
|
114
|
+
if (!unit.anchorable) {
|
|
115
|
+
skeleton += unit.value;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
let id = definitions.get(unit.value);
|
|
119
|
+
if (id === void 0) {
|
|
120
|
+
id = values.length;
|
|
121
|
+
definitions.set(unit.value, id);
|
|
122
|
+
values.push(unit.value);
|
|
123
|
+
markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
|
|
124
|
+
}
|
|
125
|
+
skeleton += markers[id];
|
|
126
|
+
anchorCount++;
|
|
127
|
+
}
|
|
128
|
+
if (anchorCount === 0 || skeleton.length >= originalCode.length) {
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
|
|
132
|
+
const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
|
|
133
|
+
const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
|
|
134
|
+
const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
|
|
135
|
+
const code = [
|
|
136
|
+
definitionsBegin,
|
|
137
|
+
serializedDefinitions,
|
|
138
|
+
definitionsEnd,
|
|
139
|
+
codeBegin,
|
|
140
|
+
skeleton
|
|
141
|
+
].join("\n");
|
|
142
|
+
const instructionSuffix = `
|
|
143
|
+
|
|
144
|
+
LARGE-FILE ANCHOR PROTOCOL:
|
|
145
|
+
The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
|
|
146
|
+
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.
|
|
147
|
+
Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
|
|
148
|
+
Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
|
|
149
|
+
To modify an anchored fragment, output the modified source instead of its placeholder.
|
|
150
|
+
Do not invent or alter placeholder IDs.`;
|
|
151
|
+
const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
|
|
152
|
+
return {
|
|
153
|
+
code,
|
|
154
|
+
instructionSuffix,
|
|
155
|
+
anchorCount,
|
|
156
|
+
uniqueAnchorCount: values.length,
|
|
157
|
+
hasStructuralValidation: expectation !== void 0,
|
|
158
|
+
expand(content) {
|
|
159
|
+
const codeBeginIndex = content.lastIndexOf(codeBegin);
|
|
160
|
+
const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
|
|
161
|
+
const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
|
|
162
|
+
const id = Number(idText);
|
|
163
|
+
const value = values[id];
|
|
164
|
+
return value === void 0 || markers[id] !== marker ? marker : value;
|
|
165
|
+
});
|
|
166
|
+
if (expanded.includes(markerPrefix)) {
|
|
167
|
+
throw new FastApplyAnchorIntegrityError();
|
|
168
|
+
}
|
|
169
|
+
if (expectation) {
|
|
170
|
+
const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
|
|
171
|
+
const actualCount = expanded.match(tagPattern)?.length ?? 0;
|
|
172
|
+
if (actualCount !== expectation.expectedCount) {
|
|
173
|
+
throw new FastApplyAnchorIntegrityError();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return expanded;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// tools/fastapply/apply.ts
|
|
182
|
+
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
183
|
+
var DEFAULT_TIMEOUT = 6e5;
|
|
184
|
+
var FastApplyContextLengthError = class extends Error {
|
|
185
|
+
code = "context_length_exceeded";
|
|
186
|
+
completionId;
|
|
187
|
+
constructor(completionId) {
|
|
188
|
+
super(
|
|
189
|
+
"Fast Apply exhausted its context window before producing the complete file. Retry with a smaller input/update or use sparse anchors for unchanged code."
|
|
190
|
+
);
|
|
191
|
+
this.name = "FastApplyContextLengthError";
|
|
192
|
+
this.completionId = completionId;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function isAsyncIterable(value) {
|
|
196
|
+
return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
|
|
197
|
+
}
|
|
198
|
+
async function collectCompletion(response) {
|
|
199
|
+
if (!isAsyncIterable(response)) {
|
|
200
|
+
const completion = response;
|
|
201
|
+
return {
|
|
202
|
+
content: completion.choices?.[0]?.message?.content ?? "",
|
|
203
|
+
completionId: completion.id,
|
|
204
|
+
finishReason: completion.choices?.[0]?.finish_reason
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const content = [];
|
|
208
|
+
let completionId;
|
|
209
|
+
let finishReason;
|
|
210
|
+
for await (const chunk of response) {
|
|
211
|
+
completionId = chunk.id ?? completionId;
|
|
212
|
+
for (const choice of chunk.choices ?? []) {
|
|
213
|
+
if (choice.delta?.content) {
|
|
214
|
+
content.push(choice.delta.content);
|
|
215
|
+
}
|
|
216
|
+
if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
|
|
217
|
+
finishReason = choice.finish_reason;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return { content: content.join(""), completionId, finishReason };
|
|
222
|
+
}
|
|
223
|
+
function generateUdiff(original, modified, filepath) {
|
|
224
|
+
return diff.createTwoFilesPatch(
|
|
225
|
+
filepath,
|
|
226
|
+
filepath,
|
|
227
|
+
original,
|
|
228
|
+
modified,
|
|
229
|
+
"Original",
|
|
230
|
+
"Modified"
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
function countChanges(original, modified) {
|
|
234
|
+
const diff = generateUdiff(original, modified, "file");
|
|
235
|
+
const lines = diff.split("\n");
|
|
236
|
+
let linesAdded = 0;
|
|
237
|
+
let linesRemoved = 0;
|
|
238
|
+
for (const line of lines) {
|
|
239
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
240
|
+
linesAdded++;
|
|
241
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
242
|
+
linesRemoved++;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const linesModified = Math.min(linesAdded, linesRemoved);
|
|
246
|
+
return {
|
|
247
|
+
linesAdded: linesAdded - linesModified,
|
|
248
|
+
linesRemoved: linesRemoved - linesModified,
|
|
249
|
+
linesModified
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
async function callMorphAPI(originalCode, codeEdit, instructions, filepath, config) {
|
|
253
|
+
const apiKey = config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
254
|
+
const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
|
|
255
|
+
const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
|
|
256
|
+
const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
|
|
257
|
+
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
258
|
+
config.debug || false;
|
|
259
|
+
if (!apiKey) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const anchorThreshold = config.anchorCompactionThreshold ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;
|
|
265
|
+
const anchorPlan = config.anchorCompaction !== false && originalCode.length >= anchorThreshold ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions]) : void 0;
|
|
266
|
+
const requestCode = anchorPlan?.code ?? originalCode;
|
|
267
|
+
const requestInstructions = anchorPlan ? instructions + anchorPlan.instructionSuffix : instructions;
|
|
268
|
+
const message = `<instruction>${requestInstructions}</instruction>
|
|
269
|
+
<code>${requestCode}</code>
|
|
270
|
+
<update>${codeEdit}</update>`;
|
|
271
|
+
chunkVL4QNALG_cjs.logger.debug("FastApply", "http_request", {
|
|
272
|
+
url: `${apiUrl}/v1/chat/completions`,
|
|
273
|
+
model,
|
|
274
|
+
filepath,
|
|
275
|
+
instruction_len: instructions.length,
|
|
276
|
+
original_len: originalCode.length,
|
|
277
|
+
request_code_len: requestCode.length,
|
|
278
|
+
code_edit_len: codeEdit.length,
|
|
279
|
+
anchor_count: anchorPlan?.anchorCount ?? 0,
|
|
280
|
+
unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0
|
|
281
|
+
});
|
|
282
|
+
const startTime = Date.now();
|
|
283
|
+
const client = new OpenAI__default.default({
|
|
284
|
+
apiKey,
|
|
285
|
+
baseURL: `${apiUrl}/v1`,
|
|
286
|
+
timeout,
|
|
287
|
+
maxRetries: config.retryConfig?.maxRetries ?? 3,
|
|
288
|
+
defaultHeaders: {
|
|
289
|
+
"X-Morph-SDK-Version": chunkTL34BLQD_cjs.SDK_VERSION,
|
|
290
|
+
...anchorPlan ? { "X-Morph-Apply-Context": "extralong" } : {}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
try {
|
|
294
|
+
const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;
|
|
295
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
296
|
+
const response = await client.chat.completions.create({
|
|
297
|
+
model,
|
|
298
|
+
messages: [{ role: "user", content: message }],
|
|
299
|
+
stream: true
|
|
300
|
+
});
|
|
301
|
+
const completion = await collectCompletion(response);
|
|
302
|
+
if (completion.finishReason === "length") {
|
|
303
|
+
throw new FastApplyContextLengthError(completion.completionId);
|
|
304
|
+
}
|
|
305
|
+
let content = completion.content;
|
|
306
|
+
if (!content) {
|
|
307
|
+
throw new Error("Morph API returned empty response");
|
|
308
|
+
}
|
|
309
|
+
if (anchorPlan) {
|
|
310
|
+
try {
|
|
311
|
+
content = anchorPlan.expand(content);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
if (error instanceof FastApplyAnchorIntegrityError) {
|
|
314
|
+
if (attempt < maxAttempts) {
|
|
315
|
+
chunkVL4QNALG_cjs.logger.warn("FastApply", "anchor_validation_retry", {
|
|
316
|
+
attempt,
|
|
317
|
+
completion_id: completion.completionId
|
|
318
|
+
});
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
throw new FastApplyAnchorIntegrityError(completion.completionId);
|
|
322
|
+
}
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const elapsed = Date.now() - startTime;
|
|
327
|
+
chunkVL4QNALG_cjs.logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
|
|
328
|
+
return { content, completionId: completion.completionId };
|
|
329
|
+
}
|
|
330
|
+
throw new FastApplyAnchorIntegrityError();
|
|
331
|
+
} catch (error) {
|
|
332
|
+
const elapsed = Date.now() - startTime;
|
|
333
|
+
const status = error?.status || error?.response?.status;
|
|
334
|
+
chunkVL4QNALG_cjs.logger.error("FastApply", "http_error", {
|
|
335
|
+
status,
|
|
336
|
+
error: error?.message,
|
|
337
|
+
latency_ms: elapsed
|
|
338
|
+
});
|
|
339
|
+
if (status === 401) {
|
|
340
|
+
const err = new Error(
|
|
341
|
+
"Authentication failed: Your Morph API key is invalid or has been revoked. Please visit https://morphllm.com to get a valid API key, then update your MCP configuration."
|
|
342
|
+
);
|
|
343
|
+
err.status = 401;
|
|
344
|
+
throw err;
|
|
345
|
+
}
|
|
346
|
+
if (status === 429) {
|
|
347
|
+
const err = new Error(
|
|
348
|
+
"Rate limited: You've exceeded your Morph API usage limits. Please visit https://morphllm.com to check your plan and purchase additional credits."
|
|
349
|
+
);
|
|
350
|
+
err.status = 429;
|
|
351
|
+
throw err;
|
|
352
|
+
}
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
async function applyEdit(input, config = {}) {
|
|
357
|
+
const filepath = input.filepath || "file";
|
|
358
|
+
try {
|
|
359
|
+
chunkVL4QNALG_cjs.logger.debug("FastApply", "apply_edit_start", { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });
|
|
360
|
+
const instruction = input.instruction ?? input.instructions ?? "";
|
|
361
|
+
const { content: mergedCode, completionId } = await callMorphAPI(
|
|
362
|
+
input.originalCode,
|
|
363
|
+
input.codeEdit,
|
|
364
|
+
instruction,
|
|
365
|
+
filepath,
|
|
366
|
+
config
|
|
367
|
+
);
|
|
368
|
+
const udiff = config.generateUdiff !== false ? generateUdiff(input.originalCode, mergedCode, filepath) : void 0;
|
|
369
|
+
const changes = countChanges(input.originalCode, mergedCode);
|
|
370
|
+
return {
|
|
371
|
+
success: true,
|
|
372
|
+
mergedCode,
|
|
373
|
+
udiff,
|
|
374
|
+
changes,
|
|
375
|
+
completionId
|
|
376
|
+
};
|
|
377
|
+
} catch (error) {
|
|
378
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
379
|
+
chunkVL4QNALG_cjs.logger.error("FastApply", "apply_edit_error", { error: errorMessage });
|
|
380
|
+
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
381
|
+
return {
|
|
382
|
+
success: false,
|
|
383
|
+
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
384
|
+
error: errorMessage,
|
|
385
|
+
errorCode: structuredError?.code,
|
|
386
|
+
completionId: structuredError?.completionId
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
exports.FastApplyAnchorIntegrityError = FastApplyAnchorIntegrityError;
|
|
392
|
+
exports.FastApplyContextLengthError = FastApplyContextLengthError;
|
|
393
|
+
exports.applyEdit = applyEdit;
|
|
394
|
+
exports.callMorphAPI = callMorphAPI;
|
|
395
|
+
exports.countChanges = countChanges;
|
|
396
|
+
exports.generateUdiff = generateUdiff;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// tools/warp_grep/providers/code_storage_http.ts
|
|
4
|
+
var MODEL_REPO_ROOT = /^\/?home\/ubuntu\/repo(?:\/|$)/;
|
|
5
|
+
function toRepoRelative(path) {
|
|
6
|
+
if (!path) return path;
|
|
7
|
+
const stripped = path.replace(MODEL_REPO_ROOT, "").replace(/^\.?\/+/, "");
|
|
8
|
+
return stripped || ".";
|
|
9
|
+
}
|
|
10
|
+
async function post(url, body, op, apiKey) {
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
...apiKey ? { Authorization: `Bearer ${apiKey}` } : {}
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify(body)
|
|
18
|
+
});
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
const text = await res.text().catch(() => res.statusText);
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(text);
|
|
23
|
+
if (parsed.error) return `Error: ${parsed.error}`;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
return `Error: ${op} failed (${res.status}): ${text}`;
|
|
27
|
+
}
|
|
28
|
+
const data = await res.json();
|
|
29
|
+
if (data.error) throw new Error(data.error);
|
|
30
|
+
return data.stdout;
|
|
31
|
+
}
|
|
32
|
+
function createCodeStorageHttpCommands(config) {
|
|
33
|
+
const { baseUrl, repoId, branch, apiKey } = config;
|
|
34
|
+
const encodedRepoId = encodeURIComponent(repoId);
|
|
35
|
+
return {
|
|
36
|
+
grep: (pattern, path, glob) => post(`${baseUrl}/api/code-search/${encodedRepoId}/grep`, { pattern, path: toRepoRelative(path), glob, branch }, "grep", apiKey),
|
|
37
|
+
read: (path, start, end) => post(`${baseUrl}/api/code-search/${encodedRepoId}/read`, { path: toRepoRelative(path), start, end, branch }, "read", apiKey),
|
|
38
|
+
listDir: (path, maxDepth) => post(`${baseUrl}/api/code-search/${encodedRepoId}/list`, { path: toRepoRelative(path), maxDepth, branch }, "list", apiKey)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.createCodeStorageHttpCommands = createCodeStorageHttpCommands;
|
|
43
|
+
exports.toRepoRelative = toRepoRelative;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// logger.ts
|
|
4
|
+
var MorphLogger = class {
|
|
5
|
+
enabled;
|
|
6
|
+
fileStream;
|
|
7
|
+
/** Resolves once the file stream is initialized (or immediately if no file logging). */
|
|
8
|
+
ready;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
|
|
11
|
+
this.fileStream = null;
|
|
12
|
+
const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
|
|
13
|
+
if (f) {
|
|
14
|
+
this.ready = import('fs').then((fs) => {
|
|
15
|
+
this.fileStream = fs.createWriteStream(f, { flags: "a" });
|
|
16
|
+
}).catch(() => {
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
this.ready = Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
debug(component, msg, data) {
|
|
23
|
+
this._log("debug", component, msg, data);
|
|
24
|
+
}
|
|
25
|
+
info(component, msg, data) {
|
|
26
|
+
this._log("info", component, msg, data);
|
|
27
|
+
}
|
|
28
|
+
warn(component, msg, data) {
|
|
29
|
+
this._log("warn", component, msg, data);
|
|
30
|
+
}
|
|
31
|
+
error(component, msg, data) {
|
|
32
|
+
this._log("error", component, msg, data);
|
|
33
|
+
}
|
|
34
|
+
enable() {
|
|
35
|
+
this.enabled = true;
|
|
36
|
+
}
|
|
37
|
+
get isEnabled() {
|
|
38
|
+
return this.enabled;
|
|
39
|
+
}
|
|
40
|
+
_log(level, component, msg, data) {
|
|
41
|
+
if (level !== "error" && !this.enabled) return;
|
|
42
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
43
|
+
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
44
|
+
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
45
|
+
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var logger = new MorphLogger();
|
|
49
|
+
|
|
50
|
+
exports.logger = logger;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4EQQGUZ7_cjs = require('./chunk-4EQQGUZ7.cjs');
|
|
4
|
+
|
|
5
|
+
// tools/warp_grep/providers/remote.ts
|
|
6
|
+
var SKIP_NAMES = /* @__PURE__ */ new Set([
|
|
7
|
+
// Version control
|
|
8
|
+
".git",
|
|
9
|
+
".svn",
|
|
10
|
+
".hg",
|
|
11
|
+
".bzr",
|
|
12
|
+
// Dependencies
|
|
13
|
+
"node_modules",
|
|
14
|
+
"bower_components",
|
|
15
|
+
".pnpm",
|
|
16
|
+
".yarn",
|
|
17
|
+
"vendor",
|
|
18
|
+
"Pods",
|
|
19
|
+
".bundle",
|
|
20
|
+
// Python
|
|
21
|
+
"__pycache__",
|
|
22
|
+
".pytest_cache",
|
|
23
|
+
".mypy_cache",
|
|
24
|
+
".ruff_cache",
|
|
25
|
+
".venv",
|
|
26
|
+
"venv",
|
|
27
|
+
".tox",
|
|
28
|
+
".nox",
|
|
29
|
+
".eggs",
|
|
30
|
+
// Build outputs
|
|
31
|
+
"dist",
|
|
32
|
+
"build",
|
|
33
|
+
"out",
|
|
34
|
+
"output",
|
|
35
|
+
"target",
|
|
36
|
+
"_build",
|
|
37
|
+
".next",
|
|
38
|
+
".nuxt",
|
|
39
|
+
".output",
|
|
40
|
+
".vercel",
|
|
41
|
+
".netlify",
|
|
42
|
+
// Cache
|
|
43
|
+
".cache",
|
|
44
|
+
".parcel-cache",
|
|
45
|
+
".turbo",
|
|
46
|
+
".nx",
|
|
47
|
+
".gradle",
|
|
48
|
+
// IDE
|
|
49
|
+
".idea",
|
|
50
|
+
".vscode",
|
|
51
|
+
".vs",
|
|
52
|
+
// Coverage
|
|
53
|
+
"coverage",
|
|
54
|
+
".coverage",
|
|
55
|
+
"htmlcov",
|
|
56
|
+
".nyc_output",
|
|
57
|
+
// Temp
|
|
58
|
+
"tmp",
|
|
59
|
+
"temp",
|
|
60
|
+
".tmp",
|
|
61
|
+
".temp",
|
|
62
|
+
// Lock files
|
|
63
|
+
"package-lock.json",
|
|
64
|
+
"yarn.lock",
|
|
65
|
+
"pnpm-lock.yaml",
|
|
66
|
+
"bun.lockb",
|
|
67
|
+
"Cargo.lock",
|
|
68
|
+
"Gemfile.lock",
|
|
69
|
+
"poetry.lock"
|
|
70
|
+
]);
|
|
71
|
+
var SKIP_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
72
|
+
".min.js",
|
|
73
|
+
".min.css",
|
|
74
|
+
".bundle.js",
|
|
75
|
+
".wasm",
|
|
76
|
+
".so",
|
|
77
|
+
".dll",
|
|
78
|
+
".pyc",
|
|
79
|
+
".map",
|
|
80
|
+
".js.map"
|
|
81
|
+
]);
|
|
82
|
+
function shouldSkip(name) {
|
|
83
|
+
if (SKIP_NAMES.has(name)) return true;
|
|
84
|
+
if (name.startsWith(".")) return true;
|
|
85
|
+
for (const ext of SKIP_EXTENSIONS) {
|
|
86
|
+
if (name.endsWith(ext)) return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
var RemoteCommandsProvider = class {
|
|
91
|
+
constructor(repoRoot, commands) {
|
|
92
|
+
this.repoRoot = repoRoot;
|
|
93
|
+
this.commands = commands;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Run grep command and parse ripgrep output
|
|
97
|
+
*/
|
|
98
|
+
async grep(params) {
|
|
99
|
+
try {
|
|
100
|
+
const stdout = await this.commands.grep(params.pattern, params.path, params.glob);
|
|
101
|
+
const lines = (stdout || "").trim().split(/\r?\n/).filter((l) => l.length > 0);
|
|
102
|
+
if (lines.length > chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_OUTPUT_LINES) {
|
|
103
|
+
const truncated = lines.slice(0, chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_OUTPUT_LINES);
|
|
104
|
+
truncated.push(`... (output truncated at ${chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_OUTPUT_LINES} of ${lines.length} lines)`);
|
|
105
|
+
return { lines: truncated };
|
|
106
|
+
}
|
|
107
|
+
return { lines };
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return {
|
|
110
|
+
lines: [],
|
|
111
|
+
error: `[GREP ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Read file and add line numbers
|
|
117
|
+
*/
|
|
118
|
+
async read(params) {
|
|
119
|
+
const rawStart = params.start;
|
|
120
|
+
const rawEnd = params.end;
|
|
121
|
+
const startValid = rawStart === void 0 || Number.isFinite(rawStart) && rawStart > 0;
|
|
122
|
+
const endValid = rawEnd === void 0 || Number.isFinite(rawEnd) && rawEnd > 0;
|
|
123
|
+
const rangeValid = startValid && endValid && (rawStart === void 0 || rawEnd === void 0 || rawStart <= rawEnd);
|
|
124
|
+
const start = rangeValid && rawStart !== void 0 ? rawStart : 1;
|
|
125
|
+
const end = rangeValid && rawEnd !== void 0 ? rawEnd : 1e6;
|
|
126
|
+
try {
|
|
127
|
+
const stdout = await this.commands.read(params.path, start, end);
|
|
128
|
+
const contentLines = (stdout || "").split("\n");
|
|
129
|
+
if (contentLines.length > 0 && contentLines[contentLines.length - 1] === "") {
|
|
130
|
+
contentLines.pop();
|
|
131
|
+
}
|
|
132
|
+
const lines = contentLines.map((content, idx) => `${start + idx}|${content}`);
|
|
133
|
+
if (lines.length > chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_READ_LINES) {
|
|
134
|
+
const truncated = lines.slice(0, chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_READ_LINES);
|
|
135
|
+
truncated.push(`... (output truncated at ${chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_READ_LINES} of ${lines.length} lines)`);
|
|
136
|
+
return { lines: truncated };
|
|
137
|
+
}
|
|
138
|
+
return { lines };
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return {
|
|
141
|
+
lines: [],
|
|
142
|
+
error: `[READ ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* List directory and parse find output
|
|
148
|
+
*/
|
|
149
|
+
async listDirectory(params) {
|
|
150
|
+
const maxDepth = params.maxDepth ?? chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
151
|
+
const maxResults = params.maxResults ?? chunk4EQQGUZ7_cjs.AGENT_CONFIG.MAX_OUTPUT_LINES;
|
|
152
|
+
try {
|
|
153
|
+
const stdout = await this.commands.listDir(params.path, maxDepth);
|
|
154
|
+
const paths = (stdout || "").trim().split(/\r?\n/).filter((p) => p.length > 0);
|
|
155
|
+
const regex = params.pattern ? new RegExp(params.pattern) : null;
|
|
156
|
+
const entries = [];
|
|
157
|
+
for (const fullPath of paths) {
|
|
158
|
+
if (fullPath === params.path || fullPath === this.repoRoot) continue;
|
|
159
|
+
const name = fullPath.split("/").pop() || "";
|
|
160
|
+
if (shouldSkip(name)) continue;
|
|
161
|
+
if (regex && !regex.test(name)) continue;
|
|
162
|
+
let relativePath = fullPath;
|
|
163
|
+
if (fullPath.startsWith(this.repoRoot)) {
|
|
164
|
+
relativePath = fullPath.slice(this.repoRoot.length).replace(/^\//, "");
|
|
165
|
+
}
|
|
166
|
+
const depth = relativePath.split("/").filter(Boolean).length - 1;
|
|
167
|
+
const hasExtension = name.includes(".") && !name.startsWith(".");
|
|
168
|
+
const type = hasExtension ? "file" : "dir";
|
|
169
|
+
entries.push({
|
|
170
|
+
name,
|
|
171
|
+
path: relativePath,
|
|
172
|
+
type,
|
|
173
|
+
depth: Math.max(0, depth)
|
|
174
|
+
});
|
|
175
|
+
if (entries.length >= maxResults) break;
|
|
176
|
+
}
|
|
177
|
+
return entries;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Glob search - finds files matching a pattern.
|
|
184
|
+
* Falls back to a grep --files approach via the listDir command.
|
|
185
|
+
*/
|
|
186
|
+
async glob(params) {
|
|
187
|
+
const searchPath = params.path || this.repoRoot;
|
|
188
|
+
try {
|
|
189
|
+
const stdout = await this.commands.listDir(searchPath, 10);
|
|
190
|
+
const allPaths = (stdout || "").trim().split(/\r?\n/).filter((p) => p.length > 0);
|
|
191
|
+
const globToRegex = (glob) => {
|
|
192
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
193
|
+
return new RegExp(escaped);
|
|
194
|
+
};
|
|
195
|
+
const regex = globToRegex(params.pattern);
|
|
196
|
+
const matched = allPaths.filter((p) => {
|
|
197
|
+
const name = p.split("/").pop() || "";
|
|
198
|
+
return regex.test(name) && !shouldSkip(name);
|
|
199
|
+
});
|
|
200
|
+
const totalFound = matched.length;
|
|
201
|
+
return { files: matched.slice(0, 100), searchDir: searchPath, totalFound };
|
|
202
|
+
} catch (error) {
|
|
203
|
+
return {
|
|
204
|
+
files: [],
|
|
205
|
+
searchDir: searchPath,
|
|
206
|
+
totalFound: 0,
|
|
207
|
+
error: `[GLOB ERROR] ${error instanceof Error ? error.message : String(error)}`
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
exports.RemoteCommandsProvider = RemoteCommandsProvider;
|