@koreanhole/opencodex 3.2.28 → 3.2.30
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koreanhole/opencodex",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.30",
|
|
4
4
|
"description": "Full opencodex runtime with Cline 2.2.0+ JSON and Gemini CLI headless provider adapters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./bin/package-main.mjs",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
|
-
"opencodex": "
|
|
16
|
-
"ocx": "
|
|
15
|
+
"opencodex": "bin/ocx.mjs",
|
|
16
|
+
"ocx": "bin/ocx.mjs"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"bin",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const INHERITED_ENV_KEYS = [
|
|
2
2
|
"PATH", "HOME", "USERPROFILE", "LANG", "LC_ALL", "LC_CTYPE", "TMPDIR", "TEMP", "TMP",
|
|
3
3
|
"SHELL", "SYSTEMROOT", "APPDATA", "LOCALAPPDATA", "PROGRAMFILES", "PROGRAMFILES(X86)",
|
|
4
|
-
"COMSPEC", "PATHEXT", "SYSTEMDRIVE", "USERNAME", "TZ",
|
|
4
|
+
"COMSPEC", "PATHEXT", "SYSTEMDRIVE", "USERNAME", "TZ", "NODE_OPTIONS",
|
|
5
5
|
] as const;
|
|
6
6
|
|
|
7
7
|
/** A deterministic child environment with no inherited vendor credentials. */
|
|
@@ -3,6 +3,7 @@ import { accessSync, constants, existsSync, readFileSync, statSync } from "node:
|
|
|
3
3
|
import { chmod, copyFile, link, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
6
7
|
import type { AdapterEvent, IncomingMeta, OcxUsage } from "../../../types";
|
|
7
8
|
import { redactSecretString } from "../../../lib/redact";
|
|
8
9
|
import { commandInvocation } from "../../../lib/win-exec";
|
|
@@ -24,6 +25,8 @@ const MAX_CAPTURE_FILE_BYTES = 4 * 1024 * 1024;
|
|
|
24
25
|
const CAPTURE_POLL_MS = 25;
|
|
25
26
|
const GEMINI_MCP_SERVER_NAME = "opencodex";
|
|
26
27
|
|
|
28
|
+
const TOOLS_PRELOAD_PATH = fileURLToPath(new URL("./preload/strip-empty-tools.cjs", import.meta.url));
|
|
29
|
+
|
|
27
30
|
const GEMINI_SYSTEM_SETTINGS = JSON.stringify({
|
|
28
31
|
tools: { core: [] },
|
|
29
32
|
hooksConfig: { enabled: false },
|
|
@@ -437,6 +440,15 @@ export function buildGeminiHeadlessEnv(
|
|
|
437
440
|
NO_COLOR: "1",
|
|
438
441
|
});
|
|
439
442
|
if (platform === "win32") env.NODE_USE_SYSTEM_CA = "1";
|
|
443
|
+
const preloadPath = /[\s"]/.test(TOOLS_PRELOAD_PATH)
|
|
444
|
+
? `"${TOOLS_PRELOAD_PATH.replace(/"/g, '\\"')}"`
|
|
445
|
+
: TOOLS_PRELOAD_PATH;
|
|
446
|
+
const operatorNodeOptions = env.NODE_OPTIONS ?? "";
|
|
447
|
+
env.NODE_OPTIONS = operatorNodeOptions.includes(TOOLS_PRELOAD_PATH)
|
|
448
|
+
? operatorNodeOptions
|
|
449
|
+
: operatorNodeOptions
|
|
450
|
+
? `${operatorNodeOptions} --require ${preloadPath}`
|
|
451
|
+
: `--require ${preloadPath}`;
|
|
440
452
|
return env;
|
|
441
453
|
}
|
|
442
454
|
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Adapter-owned preload: the Gemini CLI sends a placeholder tool entry that the
|
|
3
|
+
// provider rejects with HTTP 400. Strip tool entries without an initialized
|
|
4
|
+
// tool type from outbound JSON bodies before dispatch. Never logs a body.
|
|
5
|
+
|
|
6
|
+
const TOOL_TYPE_KEYS = [
|
|
7
|
+
"functionDeclarations",
|
|
8
|
+
"function_declarations",
|
|
9
|
+
"codeExecution",
|
|
10
|
+
"code_execution",
|
|
11
|
+
"googleSearchRetrieval",
|
|
12
|
+
"google_search_retrieval",
|
|
13
|
+
"googleSearch",
|
|
14
|
+
"google_search",
|
|
15
|
+
"urlContext",
|
|
16
|
+
"url_context",
|
|
17
|
+
"computerUse",
|
|
18
|
+
"computer_use",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const INSTALLED = Symbol.for("opencodex.gemini.stripEmptyTools");
|
|
22
|
+
const WRAPPED = Symbol.for("opencodex.gemini.stripEmptyTools.request");
|
|
23
|
+
|
|
24
|
+
function hasToolType(entry) {
|
|
25
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return false;
|
|
26
|
+
return TOOL_TYPE_KEYS.some(key => entry[key] !== null && entry[key] !== undefined);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isEmptyObject(value) {
|
|
30
|
+
return Boolean(value)
|
|
31
|
+
&& typeof value === "object"
|
|
32
|
+
&& !Array.isArray(value)
|
|
33
|
+
&& Object.keys(value).length === 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Only the body root and one request envelope level are inspected.
|
|
37
|
+
function sanitize(node) {
|
|
38
|
+
let changed = false;
|
|
39
|
+
const inspect = value => {
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
41
|
+
if (Array.isArray(value.tools)) {
|
|
42
|
+
const kept = value.tools.filter(hasToolType);
|
|
43
|
+
if (kept.length === 0) {
|
|
44
|
+
delete value.tools;
|
|
45
|
+
changed = true;
|
|
46
|
+
} else if (kept.length !== value.tools.length) {
|
|
47
|
+
value.tools = kept;
|
|
48
|
+
changed = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const key of ["toolConfig", "tool_config"]) {
|
|
52
|
+
if (key in value && isEmptyObject(value[key])) {
|
|
53
|
+
delete value[key];
|
|
54
|
+
changed = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
inspect(node);
|
|
59
|
+
if (node.request && typeof node.request === "object") inspect(node.request);
|
|
60
|
+
return changed;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Returns the rewritten JSON text, or null when the body stays unchanged. */
|
|
64
|
+
function rewrittenText(text) {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = JSON.parse(text);
|
|
67
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
68
|
+
return sanitize(parsed) ? JSON.stringify(parsed) : null;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function rewriteBody(body) {
|
|
75
|
+
try {
|
|
76
|
+
if (typeof body === "string") {
|
|
77
|
+
const text = rewrittenText(body);
|
|
78
|
+
return text === null ? null : { value: text };
|
|
79
|
+
}
|
|
80
|
+
if (Buffer.isBuffer(body) || body instanceof Uint8Array) {
|
|
81
|
+
const text = rewrittenText(Buffer.from(body.buffer, body.byteOffset, body.byteLength).toString("utf8"));
|
|
82
|
+
return text === null ? null : { value: Buffer.from(text, "utf8") };
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
// Any sanitizer failure leaves the vendor request untouched.
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function withoutContentLength(headers) {
|
|
91
|
+
if (!headers) return undefined;
|
|
92
|
+
if (typeof Headers !== "undefined" && headers instanceof Headers) {
|
|
93
|
+
const copy = new Headers(headers);
|
|
94
|
+
copy.delete("content-length");
|
|
95
|
+
return copy;
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(headers)) {
|
|
98
|
+
return headers.filter(pair => String(pair?.[0] ?? "").toLowerCase() !== "content-length");
|
|
99
|
+
}
|
|
100
|
+
if (typeof headers === "object") {
|
|
101
|
+
const copy = {};
|
|
102
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
103
|
+
if (key.toLowerCase() !== "content-length") copy[key] = value;
|
|
104
|
+
}
|
|
105
|
+
return copy;
|
|
106
|
+
}
|
|
107
|
+
return headers;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function setLength(request, body) {
|
|
111
|
+
try {
|
|
112
|
+
if (request.getHeader("content-length") === undefined) return;
|
|
113
|
+
const length = typeof body === "string" ? Buffer.byteLength(body) : body.length;
|
|
114
|
+
request.setHeader("content-length", String(length));
|
|
115
|
+
} catch {
|
|
116
|
+
// Headers already flushed: send the rewritten body as is.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function wrapClientRequest(request) {
|
|
121
|
+
if (!request || request[WRAPPED] || typeof request.write !== "function" || typeof request.end !== "function") {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
Object.defineProperty(request, WRAPPED, { value: true });
|
|
125
|
+
const write = request.write;
|
|
126
|
+
const end = request.end;
|
|
127
|
+
let pending;
|
|
128
|
+
let flushed = false;
|
|
129
|
+
|
|
130
|
+
const flushPending = () => {
|
|
131
|
+
if (pending === undefined) return;
|
|
132
|
+
const chunk = pending;
|
|
133
|
+
pending = undefined;
|
|
134
|
+
flushed = true;
|
|
135
|
+
write.call(request, chunk);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Bodies written across several writes are forwarded unchanged.
|
|
139
|
+
request.write = function (chunk, encoding, callback) {
|
|
140
|
+
if (typeof encoding === "function") {
|
|
141
|
+
callback = encoding;
|
|
142
|
+
encoding = undefined;
|
|
143
|
+
}
|
|
144
|
+
if (pending !== undefined || flushed || chunk === null || chunk === undefined) {
|
|
145
|
+
flushPending();
|
|
146
|
+
return write.call(request, chunk, encoding, callback);
|
|
147
|
+
}
|
|
148
|
+
pending = chunk;
|
|
149
|
+
if (typeof callback === "function") callback();
|
|
150
|
+
return true;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
request.end = function (chunk, encoding, callback) {
|
|
154
|
+
if (typeof chunk === "function") {
|
|
155
|
+
callback = chunk;
|
|
156
|
+
chunk = undefined;
|
|
157
|
+
encoding = undefined;
|
|
158
|
+
} else if (typeof encoding === "function") {
|
|
159
|
+
callback = encoding;
|
|
160
|
+
encoding = undefined;
|
|
161
|
+
}
|
|
162
|
+
if (pending === undefined && chunk !== undefined) {
|
|
163
|
+
const next = rewriteBody(chunk);
|
|
164
|
+
if (next === null) return end.call(request, chunk, encoding, callback);
|
|
165
|
+
setLength(request, next.value);
|
|
166
|
+
return end.call(request, next.value, encoding, callback);
|
|
167
|
+
}
|
|
168
|
+
if (pending !== undefined && chunk === undefined) {
|
|
169
|
+
const buffered = pending;
|
|
170
|
+
pending = undefined;
|
|
171
|
+
flushed = true;
|
|
172
|
+
const next = rewriteBody(buffered);
|
|
173
|
+
if (next === null) {
|
|
174
|
+
write.call(request, buffered);
|
|
175
|
+
return end.call(request, callback);
|
|
176
|
+
}
|
|
177
|
+
setLength(request, next.value);
|
|
178
|
+
write.call(request, next.value);
|
|
179
|
+
return end.call(request, callback);
|
|
180
|
+
}
|
|
181
|
+
flushPending();
|
|
182
|
+
return end.call(request, chunk, encoding, callback);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function patchFetch() {
|
|
187
|
+
const original = globalThis.fetch;
|
|
188
|
+
if (typeof original !== "function") return;
|
|
189
|
+
globalThis.fetch = function (input, init) {
|
|
190
|
+
try {
|
|
191
|
+
if (!init || typeof init !== "object" || init.body === undefined || init.body === null) {
|
|
192
|
+
return original.apply(this, arguments);
|
|
193
|
+
}
|
|
194
|
+
const next = rewriteBody(init.body);
|
|
195
|
+
if (next === null) return original.apply(this, arguments);
|
|
196
|
+
const headers = withoutContentLength(init.headers);
|
|
197
|
+
const nextInit = { ...init, body: next.value };
|
|
198
|
+
if (headers !== undefined) nextInit.headers = headers;
|
|
199
|
+
return original.call(this, input, nextInit);
|
|
200
|
+
} catch {
|
|
201
|
+
return original.apply(this, arguments);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function patchNodeHttp() {
|
|
207
|
+
for (const name of ["http", "https"]) {
|
|
208
|
+
let module;
|
|
209
|
+
try {
|
|
210
|
+
module = require(name);
|
|
211
|
+
} catch {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (!module || module[INSTALLED] || typeof module.request !== "function") continue;
|
|
215
|
+
const original = module.request;
|
|
216
|
+
module.request = function () {
|
|
217
|
+
const request = original.apply(this, arguments);
|
|
218
|
+
try {
|
|
219
|
+
wrapClientRequest(request);
|
|
220
|
+
} catch {
|
|
221
|
+
// Leave the request unwrapped on any interception failure.
|
|
222
|
+
}
|
|
223
|
+
return request;
|
|
224
|
+
};
|
|
225
|
+
module[INSTALLED] = true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function install() {
|
|
230
|
+
if (globalThis[INSTALLED]) return;
|
|
231
|
+
Object.defineProperty(globalThis, INSTALLED, { value: true });
|
|
232
|
+
patchFetch();
|
|
233
|
+
patchNodeHttp();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
install();
|
|
238
|
+
} catch {
|
|
239
|
+
// Never throw into the vendor CLI path.
|
|
240
|
+
}
|