@corbat-tech/coco 2.28.5 → 2.29.0
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/cli/index.js +102 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { setGlobalDispatcher, EnvHttpProxyAgent } from 'undici';
|
|
2
3
|
import * as fs5 from 'fs';
|
|
3
4
|
import fs5__default, { accessSync, readFileSync, constants as constants$1 } from 'fs';
|
|
4
5
|
import * as path39 from 'path';
|
|
@@ -62,6 +63,69 @@ var __export = (target, all) => {
|
|
|
62
63
|
for (var name in all)
|
|
63
64
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
64
65
|
};
|
|
66
|
+
function getProxyFromEnv() {
|
|
67
|
+
for (const key of PROXY_ENV_VARS) {
|
|
68
|
+
const value = process.env[key];
|
|
69
|
+
if (value && value.trim().length > 0) {
|
|
70
|
+
return value.trim();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function maskProxyUrl(url) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = new URL(url);
|
|
78
|
+
if (parsed.password) {
|
|
79
|
+
parsed.password = "***";
|
|
80
|
+
}
|
|
81
|
+
return parsed.toString();
|
|
82
|
+
} catch {
|
|
83
|
+
return "[invalid proxy URL]";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function installProxyDispatcher() {
|
|
87
|
+
if (installed) return getProxyFromEnv() ? maskProxyUrl(getProxyFromEnv()) : null;
|
|
88
|
+
const proxy = getProxyFromEnv();
|
|
89
|
+
if (!proxy) return null;
|
|
90
|
+
try {
|
|
91
|
+
setGlobalDispatcher(new EnvHttpProxyAgent());
|
|
92
|
+
installed = true;
|
|
93
|
+
return maskProxyUrl(proxy);
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function describeFetchError(error) {
|
|
99
|
+
if (!(error instanceof Error)) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
const cause = unwrapCause(error);
|
|
103
|
+
return {
|
|
104
|
+
code: cause?.code,
|
|
105
|
+
hostname: cause?.hostname
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function unwrapCause(error) {
|
|
109
|
+
let current = error;
|
|
110
|
+
let depth = 0;
|
|
111
|
+
while (current && depth < 5) {
|
|
112
|
+
const next = current.cause;
|
|
113
|
+
if (!next) break;
|
|
114
|
+
current = next;
|
|
115
|
+
depth++;
|
|
116
|
+
}
|
|
117
|
+
if (current && typeof current === "object") {
|
|
118
|
+
return current;
|
|
119
|
+
}
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
var PROXY_ENV_VARS, installed;
|
|
123
|
+
var init_proxy = __esm({
|
|
124
|
+
"src/utils/proxy.ts"() {
|
|
125
|
+
PROXY_ENV_VARS = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
|
|
126
|
+
installed = false;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
65
129
|
function findPackageJson() {
|
|
66
130
|
let dir = dirname(fileURLToPath(import.meta.url));
|
|
67
131
|
for (let i = 0; i < 10; i++) {
|
|
@@ -1944,8 +2008,15 @@ async function runBrowserOAuthFlow(provider) {
|
|
|
1944
2008
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
1945
2009
|
console.log();
|
|
1946
2010
|
console.log(chalk.yellow(" \u26A0 Browser authentication failed"));
|
|
1947
|
-
const
|
|
1948
|
-
|
|
2011
|
+
const isNetwork = errorMsg.includes("fetch failed") || errorMsg.toLowerCase().includes("network error") || errorMsg.includes("ECONNREFUSED") || errorMsg.includes("ENOTFOUND") || errorMsg.includes("ETIMEDOUT");
|
|
2012
|
+
if (isNetwork) {
|
|
2013
|
+
const { code } = describeFetchError(error);
|
|
2014
|
+
console.log(chalk.dim(" Error: Network error"));
|
|
2015
|
+
printNetworkTroubleshooting(code);
|
|
2016
|
+
} else {
|
|
2017
|
+
const errorCategory = errorMsg.includes("timeout") || errorMsg.includes("Timeout") ? "Request timed out" : errorMsg.includes("401") || errorMsg.includes("403") ? "Authorization denied" : errorMsg.includes("invalid_grant") || errorMsg.includes("invalid_client") ? "Invalid credentials" : "Authentication error (see debug logs for details)";
|
|
2018
|
+
console.log(chalk.dim(` Error: ${errorCategory}`));
|
|
2019
|
+
}
|
|
1949
2020
|
console.log();
|
|
1950
2021
|
const fallbackOptions = [];
|
|
1951
2022
|
if (config?.deviceAuthEndpoint) {
|
|
@@ -2235,14 +2306,38 @@ async function runCopilotDeviceFlow() {
|
|
|
2235
2306
|
console.log(chalk.yellow(" \u26A0 Authentication timed out. Please try again."));
|
|
2236
2307
|
} else if (errorMsg.includes("denied")) {
|
|
2237
2308
|
console.log(chalk.yellow(" \u26A0 Access was denied."));
|
|
2309
|
+
} else if (errorMsg.includes("fetch failed") || errorMsg.toLowerCase().includes("network")) {
|
|
2310
|
+
const { code } = describeFetchError(error);
|
|
2311
|
+
console.log(chalk.red(" \u2717 Network error reaching GitHub"));
|
|
2312
|
+
printNetworkTroubleshooting(code);
|
|
2238
2313
|
} else {
|
|
2239
|
-
|
|
2240
|
-
console.log(chalk.red(` \u2717 ${category}`));
|
|
2314
|
+
console.log(chalk.red(" \u2717 Authentication error \u2014 see debug logs for details"));
|
|
2241
2315
|
}
|
|
2242
2316
|
console.log();
|
|
2243
2317
|
return null;
|
|
2244
2318
|
}
|
|
2245
2319
|
}
|
|
2320
|
+
function printNetworkTroubleshooting(code) {
|
|
2321
|
+
const proxy = getProxyFromEnv();
|
|
2322
|
+
if (proxy) {
|
|
2323
|
+
console.log(chalk.dim(` Proxy in use: ${maskProxyUrl(proxy)}`));
|
|
2324
|
+
console.log(chalk.dim(" \u2192 Verify the proxy allows github.com and api.github.com."));
|
|
2325
|
+
} else {
|
|
2326
|
+
console.log(chalk.dim(" No HTTPS_PROXY / HTTP_PROXY env vars detected."));
|
|
2327
|
+
console.log(chalk.dim(" \u2192 If you're behind a corporate proxy, set HTTPS_PROXY and retry."));
|
|
2328
|
+
}
|
|
2329
|
+
if (code === "SELF_SIGNED_CERT_IN_CHAIN" || code === "UNABLE_TO_VERIFY_LEAF_SIGNATURE") {
|
|
2330
|
+
console.log(
|
|
2331
|
+
chalk.dim(
|
|
2332
|
+
" \u2192 A TLS interceptor is rewriting certificates. Add your corp root CA to NODE_EXTRA_CA_CERTS."
|
|
2333
|
+
)
|
|
2334
|
+
);
|
|
2335
|
+
} else if (code === "ENOTFOUND") {
|
|
2336
|
+
console.log(chalk.dim(" \u2192 Check DNS: `nslookup github.com`"));
|
|
2337
|
+
} else if (code === "ETIMEDOUT" || code === "UND_ERR_CONNECT_TIMEOUT") {
|
|
2338
|
+
console.log(chalk.dim(" \u2192 A firewall may be dropping the connection silently."));
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2246
2341
|
async function getOrRefreshOAuthToken(provider) {
|
|
2247
2342
|
if (provider === "copilot") {
|
|
2248
2343
|
const tokenResult = await getValidCopilotToken();
|
|
@@ -2273,6 +2368,7 @@ var init_flow = __esm({
|
|
|
2273
2368
|
init_pkce();
|
|
2274
2369
|
init_callback_server();
|
|
2275
2370
|
init_platform();
|
|
2371
|
+
init_proxy();
|
|
2276
2372
|
init_copilot();
|
|
2277
2373
|
execFileAsync2 = promisify(execFile);
|
|
2278
2374
|
}
|
|
@@ -24937,6 +25033,7 @@ var init_input_echo = __esm({
|
|
|
24937
25033
|
});
|
|
24938
25034
|
|
|
24939
25035
|
// src/cli/index.ts
|
|
25036
|
+
init_proxy();
|
|
24940
25037
|
init_version();
|
|
24941
25038
|
|
|
24942
25039
|
// src/orchestrator/project.ts
|
|
@@ -56258,6 +56355,7 @@ ${stdinContent}
|
|
|
56258
56355
|
// src/cli/index.ts
|
|
56259
56356
|
init_env();
|
|
56260
56357
|
init_errors();
|
|
56358
|
+
installProxyDispatcher();
|
|
56261
56359
|
var program = new Command();
|
|
56262
56360
|
program.name("coco").description("Corbat-Coco: Autonomous Coding Agent with Self-Review and Quality Convergence").version(VERSION, "-v, --version", "Output the current version");
|
|
56263
56361
|
registerInitCommand(program);
|