@commonlyai/cli 0.1.92 → 0.1.94
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 +1 -1
- package/src/lib/adapters/opencode.js +28 -10
package/package.json
CHANGED
|
@@ -342,6 +342,18 @@ const startProviderProxy = async ({ provider, keyFile, tokenFile }) => {
|
|
|
342
342
|
await writeFile(tokenFile, proxyToken, { encoding: 'utf8', mode: 0o600 });
|
|
343
343
|
await chmod(tokenFile, 0o600);
|
|
344
344
|
|
|
345
|
+
const logRefusedRequest = (method, requestPath) => {
|
|
346
|
+
let normalizedPath = '/';
|
|
347
|
+
try {
|
|
348
|
+
normalizedPath = new URL(requestPath || '/', 'http://127.0.0.1').pathname || '/';
|
|
349
|
+
} catch {
|
|
350
|
+
// Do not include an unparseable raw request target in logs.
|
|
351
|
+
}
|
|
352
|
+
const safeMethod = typeof method === 'string' && /^[A-Z]+$/.test(method)
|
|
353
|
+
? method : 'UNKNOWN';
|
|
354
|
+
process.stderr.write(`[opencode] provider proxy refused ${safeMethod} ${normalizedPath}\n`);
|
|
355
|
+
};
|
|
356
|
+
|
|
345
357
|
const server = createServer((incoming, outgoing) => {
|
|
346
358
|
const supplied = Buffer.from(incoming.headers.authorization || '');
|
|
347
359
|
const expected = Buffer.from(`Bearer ${proxyToken}`);
|
|
@@ -356,22 +368,26 @@ const startProviderProxy = async ({ provider, keyFile, tokenFile }) => {
|
|
|
356
368
|
return;
|
|
357
369
|
}
|
|
358
370
|
const rejectRoute = (path) => {
|
|
371
|
+
logRefusedRequest(incoming.method, path);
|
|
359
372
|
incoming.resume();
|
|
360
373
|
outgoing.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
|
|
361
374
|
outgoing.end(`Unsupported provider request: ${incoming.method || 'UNKNOWN'} ${path}`);
|
|
362
375
|
};
|
|
376
|
+
const rejectBadRequest = () => {
|
|
377
|
+
logRefusedRequest(incoming.method, incoming.url);
|
|
378
|
+
incoming.resume();
|
|
379
|
+
outgoing.writeHead(400).end();
|
|
380
|
+
};
|
|
363
381
|
|
|
364
382
|
let target;
|
|
365
383
|
try {
|
|
366
384
|
const requestPath = incoming.url || '/';
|
|
367
385
|
if (!requestPath.startsWith('/') || requestPath.startsWith('//')) {
|
|
368
|
-
|
|
369
|
-
outgoing.writeHead(400).end();
|
|
386
|
+
rejectBadRequest();
|
|
370
387
|
return;
|
|
371
388
|
}
|
|
372
389
|
if (/%(?:2f|5c|2e)/i.test(requestPath)) {
|
|
373
|
-
|
|
374
|
-
outgoing.writeHead(400).end();
|
|
390
|
+
rejectBadRequest();
|
|
375
391
|
return;
|
|
376
392
|
}
|
|
377
393
|
// OpenCode owns this local request path, so never use it as an outbound
|
|
@@ -405,8 +421,7 @@ const startProviderProxy = async ({ provider, keyFile, tokenFile }) => {
|
|
|
405
421
|
host: upstream.host,
|
|
406
422
|
};
|
|
407
423
|
} catch {
|
|
408
|
-
|
|
409
|
-
outgoing.writeHead(400).end();
|
|
424
|
+
rejectBadRequest();
|
|
410
425
|
return;
|
|
411
426
|
}
|
|
412
427
|
|
|
@@ -754,9 +769,12 @@ export default {
|
|
|
754
769
|
const configPath = join(tempDir, 'opencode.json');
|
|
755
770
|
const configDir = join(tempDir, 'config-dir');
|
|
756
771
|
const xdgConfig = join(tempDir, 'xdg-config');
|
|
757
|
-
|
|
758
|
-
//
|
|
759
|
-
//
|
|
772
|
+
const home = isPublic ? join(tempDir, 'home') : null;
|
|
773
|
+
// OpenCode initializes its global and XDG config directories during
|
|
774
|
+
// startup, so create those roots and their ignore files before wrapping.
|
|
775
|
+
// Keep public HOME per-spawn, but leave $HOME/.opencode absent: OpenCode
|
|
776
|
+
// loads it after OPENCODE_CONFIG when present, which could persist config
|
|
777
|
+
// or MCP injection into later spawns.
|
|
760
778
|
const xdgConfigDir = join(xdgConfig, 'opencode');
|
|
761
779
|
await Promise.all([
|
|
762
780
|
mkdir(configDir),
|
|
@@ -828,7 +846,7 @@ export default {
|
|
|
828
846
|
dataHome: openCodeHome.dataHome,
|
|
829
847
|
stateHome,
|
|
830
848
|
cacheHome,
|
|
831
|
-
home
|
|
849
|
+
home,
|
|
832
850
|
tempWork,
|
|
833
851
|
credentialFile: credential?.path || null,
|
|
834
852
|
});
|