opencode-fast-apply 2.1.4 → 2.1.5
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/index.d.ts.map +1 -1
- package/dist/index.js +18 -30
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,qBAAqB,CAAA;AA2ZvD,eAAO,MAAM,eAAe,EAAE,MA4J7B,CAAA;AAGD,eAAe,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -18,18 +18,18 @@ const FAST_APPLY_URL = (process.env.FAST_APPLY_URL || "http://localhost:1234/v1"
|
|
|
18
18
|
const FAST_APPLY_MODEL = process.env.FAST_APPLY_MODEL || "fastapply-1.5b";
|
|
19
19
|
const FAST_APPLY_TEMPERATURE = parseFloat(process.env.FAST_APPLY_TEMPERATURE || "0.05");
|
|
20
20
|
const FAST_APPLY_SYSTEM_PROMPT = "You are a coding assistant that helps merge code updates, ensuring every modification is fully integrated.";
|
|
21
|
-
const FAST_APPLY_USER_PROMPT = `Merge all changes from the
|
|
21
|
+
const FAST_APPLY_USER_PROMPT = `Merge all changes from the <<<UPDATE>>> snippet into the <<<CODE>>> below.
|
|
22
22
|
- Preserve the code's structure, order, comments, and indentation exactly.
|
|
23
|
-
- Output only the updated code, enclosed within
|
|
23
|
+
- Output only the updated code, enclosed within <<<UPDATED_CODE>>> and <<</UPDATED_CODE>>> tags.
|
|
24
24
|
- Do not include any additional text, explanations, placeholders, ellipses, or code fences.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
<<<CODE>>>{original_code}<<</CODE>>>
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
<<<UPDATE>>>{update_snippet}<<</UPDATE>>>
|
|
29
29
|
|
|
30
30
|
Provide the complete updated code.`;
|
|
31
|
-
const UPDATED_CODE_START = "
|
|
32
|
-
const UPDATED_CODE_END = "
|
|
31
|
+
const UPDATED_CODE_START = "<<<UPDATED_CODE>>>";
|
|
32
|
+
const UPDATED_CODE_END = "<<</UPDATED_CODE>>>";
|
|
33
33
|
const TOOL_INSTRUCTIONS = `**DEFAULT tool for editing existing files. Use INSTEAD of native 'edit' tool.**
|
|
34
34
|
|
|
35
35
|
CRITICAL: For EXISTING files ONLY. Use 'write' for new files.
|
|
@@ -97,27 +97,17 @@ function alsoKeepThis() {
|
|
|
97
97
|
|
|
98
98
|
## Fallback
|
|
99
99
|
If API fails, use native \`edit\` tool with exact string matching.`;
|
|
100
|
-
function escapeXmlTags(text) {
|
|
101
|
-
return text
|
|
102
|
-
.replace(/<updated-code>/g, "<updated-code>")
|
|
103
|
-
.replace(/<\/updated-code>/g, "</updated-code>");
|
|
104
|
-
}
|
|
105
|
-
function unescapeXmlTags(text) {
|
|
106
|
-
return text
|
|
107
|
-
.replace(/<updated-code>/g, "<updated-code>")
|
|
108
|
-
.replace(/<\/updated-code>/g, "</updated-code>");
|
|
109
|
-
}
|
|
110
100
|
function extractUpdatedCode(raw) {
|
|
111
101
|
const stripped = raw.trim();
|
|
112
102
|
const startTag = UPDATED_CODE_START;
|
|
113
103
|
const endTag = UPDATED_CODE_END;
|
|
114
104
|
let startIdx = stripped.indexOf(startTag);
|
|
115
105
|
if (startIdx === -1) {
|
|
116
|
-
startIdx = stripped.indexOf("
|
|
106
|
+
startIdx = stripped.indexOf("<<<UPDATED_CODE");
|
|
117
107
|
if (startIdx !== -1) {
|
|
118
|
-
const closeTagIdx = stripped.indexOf("
|
|
108
|
+
const closeTagIdx = stripped.indexOf(">>>", startIdx);
|
|
119
109
|
if (closeTagIdx !== -1) {
|
|
120
|
-
startIdx = closeTagIdx +
|
|
110
|
+
startIdx = closeTagIdx + 3;
|
|
121
111
|
}
|
|
122
112
|
}
|
|
123
113
|
}
|
|
@@ -128,28 +118,28 @@ function extractUpdatedCode(raw) {
|
|
|
128
118
|
if (stripped.startsWith("```") && stripped.endsWith("```")) {
|
|
129
119
|
const lines = stripped.split("\n");
|
|
130
120
|
if (lines.length >= 2) {
|
|
131
|
-
return
|
|
121
|
+
return lines.slice(1, -1).join("\n");
|
|
132
122
|
}
|
|
133
123
|
}
|
|
134
|
-
return
|
|
124
|
+
return stripped;
|
|
135
125
|
}
|
|
136
126
|
let endIdx = stripped.indexOf(endTag, startIdx);
|
|
137
127
|
if (endIdx === -1) {
|
|
138
|
-
endIdx = stripped.indexOf("
|
|
128
|
+
endIdx = stripped.indexOf("<<</UPDATED_CODE", startIdx);
|
|
139
129
|
}
|
|
140
130
|
if (endIdx === -1) {
|
|
141
131
|
const extracted = stripped.slice(startIdx).trim();
|
|
142
|
-
const lastCloseTag = extracted.lastIndexOf("
|
|
132
|
+
const lastCloseTag = extracted.lastIndexOf("<<<");
|
|
143
133
|
if (lastCloseTag !== -1 && extracted.slice(lastCloseTag).toLowerCase().includes("update")) {
|
|
144
|
-
return
|
|
134
|
+
return extracted.slice(0, lastCloseTag).trim();
|
|
145
135
|
}
|
|
146
|
-
return
|
|
136
|
+
return extracted;
|
|
147
137
|
}
|
|
148
138
|
const inner = stripped.substring(startIdx, endIdx);
|
|
149
139
|
if (!inner || inner.trim().length === 0) {
|
|
150
140
|
throw new Error("Empty updated-code block");
|
|
151
141
|
}
|
|
152
|
-
return
|
|
142
|
+
return inner;
|
|
153
143
|
}
|
|
154
144
|
function generateUnifiedDiff(filepath, original, modified) {
|
|
155
145
|
const patch = createTwoFilesPatch(`a/${filepath}`, `b/${filepath}`, original, modified, "", "", { context: 3 });
|
|
@@ -229,11 +219,9 @@ async function callFastApply(originalCode, codeEdit, instructions) {
|
|
|
229
219
|
};
|
|
230
220
|
}
|
|
231
221
|
try {
|
|
232
|
-
const escapedOriginalCode = escapeXmlTags(originalCode);
|
|
233
|
-
const escapedCodeEdit = escapeXmlTags(codeEdit);
|
|
234
222
|
const userContent = FAST_APPLY_USER_PROMPT
|
|
235
|
-
.replace("{original_code}",
|
|
236
|
-
.replace("{update_snippet}",
|
|
223
|
+
.replace("{original_code}", originalCode)
|
|
224
|
+
.replace("{update_snippet}", codeEdit);
|
|
237
225
|
const response = await fetch(`${FAST_APPLY_URL}/v1/chat/completions`, {
|
|
238
226
|
method: "POST",
|
|
239
227
|
headers: {
|
package/package.json
CHANGED