happy-imou-cloud 2.0.0 → 2.0.1
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/{BaseReasoningProcessor-BRCQXCZY.cjs → BaseReasoningProcessor-01KqA3Kz.cjs} +96 -9
- package/dist/{BaseReasoningProcessor-BKLRCKTU.mjs → BaseReasoningProcessor-DQE2l7Xu.mjs} +95 -10
- package/dist/{api-BGXYX0yH.mjs → api-B5Ui8Fw0.mjs} +68 -6
- package/dist/{api-D7OK-mML.cjs → api-B8v4tczT.cjs} +70 -5
- package/dist/{command-CnLtKtP-.mjs → command-BfIuJmeo.mjs} +3 -3
- package/dist/{command-G85giEAF.cjs → command-D8yNlaDo.cjs} +3 -3
- package/dist/{index-C7Y0R-MI.mjs → index-BByhFIIq.mjs} +682 -220
- package/dist/{index-B_wlQBy2.cjs → index-BOqJ9hwi.cjs} +684 -220
- package/dist/index.cjs +4 -4
- package/dist/index.mjs +4 -4
- package/dist/lib.cjs +1 -1
- package/dist/lib.d.cts +1 -0
- package/dist/lib.d.mts +1 -0
- package/dist/lib.mjs +1 -1
- package/dist/{persistence-DHgf1CTG.cjs → persistence-C33AMdtv.cjs} +1 -1
- package/dist/{persistence-BA_unuca.mjs → persistence-CzpZpiL3.mjs} +1 -1
- package/dist/{registerKillSessionHandler-CLREXN11.cjs → registerKillSessionHandler-BkzQulD9.cjs} +6 -4
- package/dist/{registerKillSessionHandler-C2-yHm1V.mjs → registerKillSessionHandler-BtSK7IOa.mjs} +6 -4
- package/dist/{runClaude-CwAitpX-.cjs → runClaude-CNVufgZb.cjs} +14 -6
- package/dist/{runClaude-uNC5Eym4.mjs → runClaude-C_WLfM6c.mjs} +13 -5
- package/dist/{runCodex-B-05E-YZ.mjs → runCodex-8eWjTPJr.mjs} +636 -819
- package/dist/{runCodex-Cm0VTqw_.cjs → runCodex-Dzy8anlX.cjs} +639 -819
- package/dist/{runGemini-CLWjwDYS.cjs → runGemini-CgsVKP7m.cjs} +20 -16
- package/dist/{runGemini-_biXvQAH.mjs → runGemini-nbr0mm-S.mjs} +20 -16
- package/package.json +14 -14
- package/scripts/env-wrapper.cjs +11 -11
- package/scripts/setup-dev.cjs +4 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chalk = require('chalk');
|
|
4
|
-
var api = require('./api-
|
|
5
|
-
var persistence = require('./persistence-
|
|
4
|
+
var api = require('./api-B8v4tczT.cjs');
|
|
5
|
+
var persistence = require('./persistence-C33AMdtv.cjs');
|
|
6
6
|
var z = require('zod');
|
|
7
7
|
var fs$2 = require('fs/promises');
|
|
8
8
|
var os$1 = require('os');
|
|
@@ -70,7 +70,7 @@ async function openBrowser(url) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index-
|
|
73
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index-BOqJ9hwi.cjs', document.baseURI).href)));
|
|
74
74
|
const QRCode = require$1("qrcode-terminal/vendor/QRCode");
|
|
75
75
|
const QRErrorCorrectLevel = require$1("qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel");
|
|
76
76
|
const pendingTempFiles = /* @__PURE__ */ new Set();
|
|
@@ -241,6 +241,64 @@ const AuthSelector = ({ onSelect, onCancel }) => {
|
|
|
241
241
|
})), /* @__PURE__ */ React.createElement(ink.Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(ink.Text, { dimColor: true }, "Use arrows or 1-2 to select, Enter to confirm")));
|
|
242
242
|
};
|
|
243
243
|
|
|
244
|
+
async function ensureSigningCredentials(credentials, opts = {}) {
|
|
245
|
+
if (credentials.signing) {
|
|
246
|
+
return credentials;
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const response = await axios.post(`${api.configuration.serverUrl}/v1/auth/refresh`, {}, {
|
|
250
|
+
headers: api.buildAuthenticatedHeaders({
|
|
251
|
+
credentials,
|
|
252
|
+
method: "POST",
|
|
253
|
+
url: `${api.configuration.serverUrl}/v1/auth/refresh`,
|
|
254
|
+
body: {},
|
|
255
|
+
headers: {
|
|
256
|
+
"Content-Type": "application/json"
|
|
257
|
+
},
|
|
258
|
+
signRequest: false
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
if (!response.data?.success || !response.data?.token || !response.data?.signing) {
|
|
262
|
+
api.logger.debug("[AUTH] Signing bootstrap returned incomplete payload", response.data);
|
|
263
|
+
throw new api.SigningBootstrapRequiredError(api.SIGNING_BOOTSTRAP_REQUIRED_MESSAGE);
|
|
264
|
+
}
|
|
265
|
+
const upgradedCredentials = {
|
|
266
|
+
...credentials,
|
|
267
|
+
token: response.data.token,
|
|
268
|
+
signing: response.data.signing
|
|
269
|
+
};
|
|
270
|
+
if (upgradedCredentials.encryption.type === "legacy") {
|
|
271
|
+
await persistence.writeCredentialsLegacy({
|
|
272
|
+
secret: upgradedCredentials.encryption.secret,
|
|
273
|
+
token: upgradedCredentials.token,
|
|
274
|
+
signing: upgradedCredentials.signing
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
await persistence.writeCredentialsDataKey({
|
|
278
|
+
publicKey: upgradedCredentials.encryption.publicKey,
|
|
279
|
+
machineKey: upgradedCredentials.encryption.machineKey,
|
|
280
|
+
token: upgradedCredentials.token,
|
|
281
|
+
signing: upgradedCredentials.signing
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
api.logger.debug("[AUTH] Signing credentials bootstrapped successfully");
|
|
285
|
+
return upgradedCredentials;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (axios.isAxiosError(error) && error.response?.status === 401) {
|
|
288
|
+
api.logger.debug("[AUTH] Signing bootstrap rejected with 401");
|
|
289
|
+
throw new api.SigningBootstrapRequiredError(api.SIGNING_BOOTSTRAP_REQUIRED_MESSAGE);
|
|
290
|
+
}
|
|
291
|
+
if (error instanceof api.SigningBootstrapRequiredError) {
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
api.logger.debug("[AUTH] Failed to bootstrap signing credentials", error);
|
|
295
|
+
if (opts.failFast) {
|
|
296
|
+
throw new api.SigningBootstrapRequiredError(api.SIGNING_BOOTSTRAP_REQUIRED_MESSAGE);
|
|
297
|
+
}
|
|
298
|
+
return credentials;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
244
302
|
function isNonInteractive() {
|
|
245
303
|
return !process.stdin.isTTY || !process.stdout.isTTY;
|
|
246
304
|
}
|
|
@@ -542,7 +600,7 @@ async function authAndSetupMachineIfNeeded() {
|
|
|
542
600
|
} else {
|
|
543
601
|
api.logger.debug("[AUTH] Using existing credentials");
|
|
544
602
|
}
|
|
545
|
-
credentials = await ensureSigningCredentials(credentials);
|
|
603
|
+
credentials = await ensureSigningCredentials(credentials, { failFast: newAuth });
|
|
546
604
|
const currentSettings = await persistence.readSettings();
|
|
547
605
|
const settings = newAuth || !currentSettings.machineId ? await persistence.updateSettings(async (s) => ({
|
|
548
606
|
...s,
|
|
@@ -551,53 +609,6 @@ async function authAndSetupMachineIfNeeded() {
|
|
|
551
609
|
api.logger.debug(`[AUTH] Machine ID: ${settings.machineId}`);
|
|
552
610
|
return { credentials, machineId: settings.machineId };
|
|
553
611
|
}
|
|
554
|
-
async function ensureSigningCredentials(credentials) {
|
|
555
|
-
if (credentials.signing) {
|
|
556
|
-
return credentials;
|
|
557
|
-
}
|
|
558
|
-
try {
|
|
559
|
-
const response = await axios.post(`${api.configuration.serverUrl}/v1/auth/refresh`, {}, {
|
|
560
|
-
headers: api.buildAuthenticatedHeaders({
|
|
561
|
-
credentials,
|
|
562
|
-
method: "POST",
|
|
563
|
-
url: `${api.configuration.serverUrl}/v1/auth/refresh`,
|
|
564
|
-
body: {},
|
|
565
|
-
headers: {
|
|
566
|
-
"Content-Type": "application/json"
|
|
567
|
-
},
|
|
568
|
-
signRequest: false
|
|
569
|
-
})
|
|
570
|
-
});
|
|
571
|
-
if (!response.data?.success || !response.data?.token || !response.data?.signing) {
|
|
572
|
-
api.logger.debug("[AUTH] Signing bootstrap returned incomplete payload");
|
|
573
|
-
return credentials;
|
|
574
|
-
}
|
|
575
|
-
const upgradedCredentials = {
|
|
576
|
-
...credentials,
|
|
577
|
-
token: response.data.token,
|
|
578
|
-
signing: response.data.signing
|
|
579
|
-
};
|
|
580
|
-
if (upgradedCredentials.encryption.type === "legacy") {
|
|
581
|
-
await persistence.writeCredentialsLegacy({
|
|
582
|
-
secret: upgradedCredentials.encryption.secret,
|
|
583
|
-
token: upgradedCredentials.token,
|
|
584
|
-
signing: upgradedCredentials.signing
|
|
585
|
-
});
|
|
586
|
-
} else {
|
|
587
|
-
await persistence.writeCredentialsDataKey({
|
|
588
|
-
publicKey: upgradedCredentials.encryption.publicKey,
|
|
589
|
-
machineKey: upgradedCredentials.encryption.machineKey,
|
|
590
|
-
token: upgradedCredentials.token,
|
|
591
|
-
signing: upgradedCredentials.signing
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
api.logger.debug("[AUTH] Signing credentials bootstrapped successfully");
|
|
595
|
-
return upgradedCredentials;
|
|
596
|
-
} catch (error) {
|
|
597
|
-
api.logger.debug("[AUTH] Failed to bootstrap signing credentials", error);
|
|
598
|
-
return credentials;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
612
|
|
|
602
613
|
let caffeinateProcess = null;
|
|
603
614
|
function startCaffeinate() {
|
|
@@ -682,7 +693,7 @@ function setupCleanupHandlers() {
|
|
|
682
693
|
});
|
|
683
694
|
}
|
|
684
695
|
|
|
685
|
-
const __dirname$1 = path$1.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index-
|
|
696
|
+
const __dirname$1 = path$1.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index-BOqJ9hwi.cjs', document.baseURI).href))));
|
|
686
697
|
function projectPath() {
|
|
687
698
|
const path = path$1.resolve(__dirname$1, "..");
|
|
688
699
|
return path;
|
|
@@ -980,6 +991,32 @@ async function checkIfDaemonRunningAndCleanupStaleState() {
|
|
|
980
991
|
return false;
|
|
981
992
|
}
|
|
982
993
|
}
|
|
994
|
+
async function isDaemonControlServerResponsive(timeoutMs = 1e3) {
|
|
995
|
+
const state = await persistence.readDaemonState();
|
|
996
|
+
if (!state?.httpPort) {
|
|
997
|
+
api.logger.debug("[DAEMON CONTROL] No daemon state or control port found for readiness check");
|
|
998
|
+
return false;
|
|
999
|
+
}
|
|
1000
|
+
try {
|
|
1001
|
+
process.kill(state.pid, 0);
|
|
1002
|
+
} catch {
|
|
1003
|
+
api.logger.debug("[DAEMON CONTROL] Daemon PID not running during readiness check, cleaning up state");
|
|
1004
|
+
await cleanupDaemonState();
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
try {
|
|
1008
|
+
const response = await fetch(`http://127.0.0.1:${state.httpPort}/list`, {
|
|
1009
|
+
method: "POST",
|
|
1010
|
+
headers: { "Content-Type": "application/json" },
|
|
1011
|
+
body: JSON.stringify({}),
|
|
1012
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
1013
|
+
});
|
|
1014
|
+
return response.ok;
|
|
1015
|
+
} catch (error) {
|
|
1016
|
+
api.logger.debug("[DAEMON CONTROL] Daemon control server not ready yet", error);
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
983
1020
|
async function isDaemonRunningCurrentlyInstalledHappyVersion() {
|
|
984
1021
|
api.logger.debug("[DAEMON CONTROL] Checking if daemon is running same version");
|
|
985
1022
|
const runningDaemon = await checkIfDaemonRunningAndCleanupStaleState();
|
|
@@ -997,7 +1034,10 @@ async function isDaemonRunningCurrentlyInstalledHappyVersion() {
|
|
|
997
1034
|
const packageJson = JSON.parse(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
998
1035
|
const currentCliVersion = packageJson.version;
|
|
999
1036
|
api.logger.debug(`[DAEMON CONTROL] Current CLI version: ${currentCliVersion}, Daemon started with version: ${state.startedWithCliVersion}`);
|
|
1000
|
-
|
|
1037
|
+
if (currentCliVersion !== state.startedWithCliVersion) {
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
return await isDaemonControlServerResponsive();
|
|
1001
1041
|
} catch (error) {
|
|
1002
1042
|
api.logger.debug("[DAEMON CONTROL] Error checking daemon version", error);
|
|
1003
1043
|
return false;
|
|
@@ -1214,7 +1254,7 @@ ${typeLabels[type] || type}:`));
|
|
|
1214
1254
|
}
|
|
1215
1255
|
if (filter === "all" && allProcesses.length > 1) {
|
|
1216
1256
|
console.log(chalk.bold("\n\u{1F4A1} Process Management"));
|
|
1217
|
-
console.log(chalk.gray("To clean up runaway processes:
|
|
1257
|
+
console.log(chalk.gray("To clean up runaway processes: hicloud doctor clean"));
|
|
1218
1258
|
}
|
|
1219
1259
|
} catch (error) {
|
|
1220
1260
|
console.log(chalk.red("\u274C Error checking daemon status"));
|
|
@@ -1396,7 +1436,8 @@ function startDaemonControlServer({
|
|
|
1396
1436
|
schema: {
|
|
1397
1437
|
body: z.z.object({
|
|
1398
1438
|
directory: z.z.string(),
|
|
1399
|
-
sessionId: z.z.string().optional()
|
|
1439
|
+
sessionId: z.z.string().optional(),
|
|
1440
|
+
agent: z.z.enum(["claude", "codex", "gemini"]).optional()
|
|
1400
1441
|
}),
|
|
1401
1442
|
response: {
|
|
1402
1443
|
200: z.z.object({
|
|
@@ -1417,9 +1458,9 @@ function startDaemonControlServer({
|
|
|
1417
1458
|
}
|
|
1418
1459
|
}
|
|
1419
1460
|
}, async (request, reply) => {
|
|
1420
|
-
const { directory, sessionId } = request.body;
|
|
1421
|
-
api.logger.debug(`[CONTROL SERVER] Spawn session request: dir=${directory}, sessionId=${sessionId || "new"}`);
|
|
1422
|
-
const result = await spawnSession({ directory, sessionId });
|
|
1461
|
+
const { directory, sessionId, agent } = request.body;
|
|
1462
|
+
api.logger.debug(`[CONTROL SERVER] Spawn session request: dir=${directory}, sessionId=${sessionId || "new"}, agent=${agent || "claude"}`);
|
|
1463
|
+
const result = await spawnSession({ directory, sessionId, agent });
|
|
1423
1464
|
switch (result.type) {
|
|
1424
1465
|
case "success":
|
|
1425
1466
|
if (!result.sessionId) {
|
|
@@ -2934,13 +2975,13 @@ async function handleAuthCommand(args) {
|
|
|
2934
2975
|
}
|
|
2935
2976
|
function showAuthHelp() {
|
|
2936
2977
|
console.log(`
|
|
2937
|
-
${chalk.bold("
|
|
2978
|
+
${chalk.bold("hicloud auth")} - Authentication management
|
|
2938
2979
|
|
|
2939
2980
|
${chalk.bold("Usage:")}
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2981
|
+
hicloud auth login [--force] Authenticate with Happy
|
|
2982
|
+
hicloud auth logout [--yes] Remove authentication and machine data
|
|
2983
|
+
hicloud auth status Show authentication status
|
|
2984
|
+
hicloud auth help Show this help message
|
|
2944
2985
|
|
|
2945
2986
|
${chalk.bold("Options:")}
|
|
2946
2987
|
--force Clear credentials, machine ID, and stop daemon before re-auth
|
|
@@ -2980,7 +3021,7 @@ async function handleAuthLogin(args) {
|
|
|
2980
3021
|
console.log(chalk.green("\u2713 Already authenticated"));
|
|
2981
3022
|
console.log(chalk.gray(` Machine ID: ${settings.machineId}`));
|
|
2982
3023
|
console.log(chalk.gray(` Host: ${os.hostname()}`));
|
|
2983
|
-
console.log(chalk.gray(` Use '
|
|
3024
|
+
console.log(chalk.gray(` Use 'hicloud auth login --force' to re-authenticate`));
|
|
2984
3025
|
return;
|
|
2985
3026
|
} else if (existingCreds && !settings?.machineId) {
|
|
2986
3027
|
console.log(chalk.yellow("\u26A0\uFE0F Credentials exist but machine ID is missing"));
|
|
@@ -3011,7 +3052,7 @@ async function handleAuthLogout(args = []) {
|
|
|
3011
3052
|
let confirmed = skipConfirm;
|
|
3012
3053
|
if (!confirmed) {
|
|
3013
3054
|
if (isNonInteractive) {
|
|
3014
|
-
throw new Error('Non-interactive terminal detected. Use "
|
|
3055
|
+
throw new Error('Non-interactive terminal detected. Use "hicloud auth logout --yes" to confirm.');
|
|
3015
3056
|
}
|
|
3016
3057
|
const rl = node_readline.createInterface({
|
|
3017
3058
|
input: process.stdin,
|
|
@@ -3034,7 +3075,7 @@ async function handleAuthLogout(args = []) {
|
|
|
3034
3075
|
fs.rmSync(happyDir, { recursive: true, force: true });
|
|
3035
3076
|
}
|
|
3036
3077
|
console.log(chalk.green("\u2713 Successfully logged out"));
|
|
3037
|
-
console.log(chalk.gray(' Run "
|
|
3078
|
+
console.log(chalk.gray(' Run "hicloud auth login" to authenticate again'));
|
|
3038
3079
|
} catch (error) {
|
|
3039
3080
|
throw new Error(`Failed to logout: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3040
3081
|
}
|
|
@@ -3048,20 +3089,20 @@ async function handleAuthStatus() {
|
|
|
3048
3089
|
console.log(chalk.bold("\nAuthentication Status\n"));
|
|
3049
3090
|
if (!credentials) {
|
|
3050
3091
|
console.log(chalk.red("\u2717 Not authenticated"));
|
|
3051
|
-
console.log(chalk.gray(' Run "
|
|
3092
|
+
console.log(chalk.gray(' Run "hicloud auth login" to authenticate'));
|
|
3052
3093
|
return;
|
|
3053
3094
|
}
|
|
3054
3095
|
console.log(chalk.green("\u2713 Authenticated"));
|
|
3055
3096
|
const tokenPreview = credentials.token.substring(0, 30) + "...";
|
|
3056
3097
|
console.log(chalk.gray(` Token: ${tokenPreview}`));
|
|
3057
|
-
console.log(chalk.gray(` Request signing: ${credentials
|
|
3098
|
+
console.log(chalk.gray(` Request signing: ${describeSigningStatus(credentials)}`));
|
|
3058
3099
|
if (settings?.machineId) {
|
|
3059
3100
|
console.log(chalk.green("\u2713 Machine registered"));
|
|
3060
3101
|
console.log(chalk.gray(` Machine ID: ${settings.machineId}`));
|
|
3061
3102
|
console.log(chalk.gray(` Host: ${os.hostname()}`));
|
|
3062
3103
|
} else {
|
|
3063
3104
|
console.log(chalk.yellow("\u26A0\uFE0F Machine not registered"));
|
|
3064
|
-
console.log(chalk.gray(' Run "
|
|
3105
|
+
console.log(chalk.gray(' Run "hicloud auth login --force" to fix this'));
|
|
3065
3106
|
}
|
|
3066
3107
|
console.log(chalk.gray(`
|
|
3067
3108
|
Data directory: ${api.configuration.happyCloudHomeDir}`));
|
|
@@ -3076,6 +3117,12 @@ async function handleAuthStatus() {
|
|
|
3076
3117
|
console.log(chalk.gray("\u2717 Daemon not running"));
|
|
3077
3118
|
}
|
|
3078
3119
|
}
|
|
3120
|
+
function describeSigningStatus(credentials) {
|
|
3121
|
+
if (credentials.signing) {
|
|
3122
|
+
return "ready";
|
|
3123
|
+
}
|
|
3124
|
+
return "not initialized (server write requests may still fail until signing bootstrap succeeds)";
|
|
3125
|
+
}
|
|
3079
3126
|
|
|
3080
3127
|
const CLIENT_ID$2 = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
3081
3128
|
const AUTH_BASE_URL = "https://auth.openai.com";
|
|
@@ -3592,14 +3639,14 @@ async function handleConnectCommand(args) {
|
|
|
3592
3639
|
}
|
|
3593
3640
|
function showConnectHelp() {
|
|
3594
3641
|
console.log(`
|
|
3595
|
-
${chalk.bold("
|
|
3642
|
+
${chalk.bold("hicloud connect")} - Connect AI vendor API keys to Happy cloud
|
|
3596
3643
|
|
|
3597
3644
|
${chalk.bold("Usage:")}
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3645
|
+
hicloud connect codex Store your Codex API key in Happy cloud
|
|
3646
|
+
hicloud connect claude Store your Anthropic API key in Happy cloud
|
|
3647
|
+
hicloud connect gemini Store your Gemini API key in Happy cloud
|
|
3648
|
+
hicloud connect status Show connection status for all vendors
|
|
3649
|
+
hicloud connect help Show this help message
|
|
3603
3650
|
|
|
3604
3651
|
${chalk.bold("Description:")}
|
|
3605
3652
|
The connect command allows you to securely store your AI vendor API keys
|
|
@@ -3607,13 +3654,13 @@ ${chalk.bold("Description:")}
|
|
|
3607
3654
|
without exposing your API keys locally.
|
|
3608
3655
|
|
|
3609
3656
|
${chalk.bold("Examples:")}
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3657
|
+
hicloud connect codex
|
|
3658
|
+
hicloud connect claude
|
|
3659
|
+
hicloud connect gemini
|
|
3660
|
+
hicloud connect status
|
|
3614
3661
|
|
|
3615
3662
|
${chalk.bold("Notes:")}
|
|
3616
|
-
\u2022 You must be authenticated with Happy first (run '
|
|
3663
|
+
\u2022 You must be authenticated with Happy first (run 'hicloud auth login')
|
|
3617
3664
|
\u2022 API keys are encrypted and stored securely in Happy cloud
|
|
3618
3665
|
\u2022 You can manage your stored keys at https://happycloudcode.imou.com
|
|
3619
3666
|
`);
|
|
@@ -3625,7 +3672,7 @@ async function handleConnectVendor(vendor, displayName) {
|
|
|
3625
3672
|
const credentials = await persistence.readCredentials();
|
|
3626
3673
|
if (!credentials) {
|
|
3627
3674
|
console.log(chalk.yellow("\u26A0\uFE0F Not authenticated with Happy"));
|
|
3628
|
-
console.log(chalk.gray(' Please run "
|
|
3675
|
+
console.log(chalk.gray(' Please run "hicloud auth login" first'));
|
|
3629
3676
|
process.exit(1);
|
|
3630
3677
|
}
|
|
3631
3678
|
const api$1 = await api.ApiClient.create(credentials);
|
|
@@ -3657,7 +3704,7 @@ async function handleConnectStatus() {
|
|
|
3657
3704
|
const credentials = await persistence.readCredentials();
|
|
3658
3705
|
if (!credentials) {
|
|
3659
3706
|
console.log(chalk.yellow("\u26A0\uFE0F Not authenticated with Happy"));
|
|
3660
|
-
console.log(chalk.gray(' Please run "
|
|
3707
|
+
console.log(chalk.gray(' Please run "hicloud auth login" first'));
|
|
3661
3708
|
process.exit(1);
|
|
3662
3709
|
}
|
|
3663
3710
|
const api$1 = await api.ApiClient.create(credentials);
|
|
@@ -3692,8 +3739,8 @@ async function handleConnectStatus() {
|
|
|
3692
3739
|
}
|
|
3693
3740
|
}
|
|
3694
3741
|
console.log("");
|
|
3695
|
-
console.log(chalk.gray("To connect a vendor, run:
|
|
3696
|
-
console.log(chalk.gray("Example:
|
|
3742
|
+
console.log(chalk.gray("To connect a vendor, run: hicloud connect <vendor>"));
|
|
3743
|
+
console.log(chalk.gray("Example: hicloud connect gemini"));
|
|
3697
3744
|
console.log("");
|
|
3698
3745
|
}
|
|
3699
3746
|
function updateLocalGeminiCredentials(tokens) {
|
|
@@ -4078,6 +4125,77 @@ class AgentRegistry {
|
|
|
4078
4125
|
}
|
|
4079
4126
|
const agentRegistry = new AgentRegistry();
|
|
4080
4127
|
|
|
4128
|
+
const PREFERRED_MESSAGE_FIELDS = ["stderr", "error", "message", "detail", "stdout", "text", "reason"];
|
|
4129
|
+
function safeSerializeDisplayValue(value) {
|
|
4130
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
4131
|
+
try {
|
|
4132
|
+
const serialized = JSON.stringify(value, (_key, currentValue) => {
|
|
4133
|
+
if (typeof currentValue === "bigint") {
|
|
4134
|
+
return currentValue.toString();
|
|
4135
|
+
}
|
|
4136
|
+
if (currentValue instanceof Error) {
|
|
4137
|
+
return {
|
|
4138
|
+
name: currentValue.name,
|
|
4139
|
+
message: currentValue.message,
|
|
4140
|
+
stack: currentValue.stack
|
|
4141
|
+
};
|
|
4142
|
+
}
|
|
4143
|
+
if (typeof currentValue === "object" && currentValue !== null) {
|
|
4144
|
+
if (seen.has(currentValue)) {
|
|
4145
|
+
return "[Circular]";
|
|
4146
|
+
}
|
|
4147
|
+
seen.add(currentValue);
|
|
4148
|
+
}
|
|
4149
|
+
return currentValue;
|
|
4150
|
+
});
|
|
4151
|
+
return serialized ?? String(value);
|
|
4152
|
+
} catch {
|
|
4153
|
+
return String(value);
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
function formatDisplayMessage(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
4157
|
+
if (typeof value === "string") {
|
|
4158
|
+
return value;
|
|
4159
|
+
}
|
|
4160
|
+
if (value instanceof Error) {
|
|
4161
|
+
return value.message || String(value);
|
|
4162
|
+
}
|
|
4163
|
+
if (value === null || value === void 0) {
|
|
4164
|
+
return "";
|
|
4165
|
+
}
|
|
4166
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) {
|
|
4167
|
+
return value.toString("utf8");
|
|
4168
|
+
}
|
|
4169
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
4170
|
+
return String(value);
|
|
4171
|
+
}
|
|
4172
|
+
if (typeof value === "object") {
|
|
4173
|
+
if (seen.has(value)) {
|
|
4174
|
+
return "[Circular]";
|
|
4175
|
+
}
|
|
4176
|
+
seen.add(value);
|
|
4177
|
+
const record = value;
|
|
4178
|
+
for (const field of PREFERRED_MESSAGE_FIELDS) {
|
|
4179
|
+
if (!(field in record)) {
|
|
4180
|
+
continue;
|
|
4181
|
+
}
|
|
4182
|
+
const formattedField = formatDisplayMessage(record[field], seen).trim();
|
|
4183
|
+
if (formattedField.length > 0) {
|
|
4184
|
+
return formattedField;
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
return safeSerializeDisplayValue(value);
|
|
4188
|
+
}
|
|
4189
|
+
return String(value);
|
|
4190
|
+
}
|
|
4191
|
+
function truncateDisplayMessage(value, maxLength) {
|
|
4192
|
+
const formatted = formatDisplayMessage(value);
|
|
4193
|
+
if (formatted.length <= maxLength) {
|
|
4194
|
+
return formatted;
|
|
4195
|
+
}
|
|
4196
|
+
return `${formatted.substring(0, maxLength)}...`;
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4081
4199
|
const DEFAULT_TIMEOUTS = {
|
|
4082
4200
|
/** Default initialization timeout: 60 seconds */
|
|
4083
4201
|
init: 6e4,
|
|
@@ -4372,7 +4490,7 @@ class CodexTransport extends DefaultTransport {
|
|
|
4372
4490
|
return 800;
|
|
4373
4491
|
}
|
|
4374
4492
|
}
|
|
4375
|
-
|
|
4493
|
+
new CodexTransport();
|
|
4376
4494
|
|
|
4377
4495
|
class ClaudeTransport extends DefaultTransport {
|
|
4378
4496
|
constructor() {
|
|
@@ -4706,6 +4824,70 @@ const RETRY_CONFIG = {
|
|
|
4706
4824
|
/** Maximum delay between retries in ms */
|
|
4707
4825
|
maxDelayMs: 5e3
|
|
4708
4826
|
};
|
|
4827
|
+
function getSessionUpdates(params) {
|
|
4828
|
+
const notification = params;
|
|
4829
|
+
const updates = Array.isArray(notification.updates) ? notification.updates.filter((update) => Boolean(update && typeof update === "object")) : [];
|
|
4830
|
+
if (updates.length > 0) {
|
|
4831
|
+
return updates;
|
|
4832
|
+
}
|
|
4833
|
+
if (notification.update && typeof notification.update === "object") {
|
|
4834
|
+
return [notification.update];
|
|
4835
|
+
}
|
|
4836
|
+
return [];
|
|
4837
|
+
}
|
|
4838
|
+
function asNonNegativeFiniteNumber(value) {
|
|
4839
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
|
|
4840
|
+
}
|
|
4841
|
+
function extractUsageTokens(record) {
|
|
4842
|
+
const used = asNonNegativeFiniteNumber(record.used);
|
|
4843
|
+
const size = asNonNegativeFiniteNumber(record.size);
|
|
4844
|
+
if (used != null || size != null) {
|
|
4845
|
+
const tokens2 = {
|
|
4846
|
+
total: used ?? 0
|
|
4847
|
+
};
|
|
4848
|
+
if (used != null) tokens2.used = used;
|
|
4849
|
+
if (size != null) tokens2.size = size;
|
|
4850
|
+
return tokens2;
|
|
4851
|
+
}
|
|
4852
|
+
const input = asNonNegativeFiniteNumber(record.input_tokens) ?? asNonNegativeFiniteNumber(record.inputTokens) ?? asNonNegativeFiniteNumber(record.prompt_tokens) ?? asNonNegativeFiniteNumber(record.promptTokens);
|
|
4853
|
+
const output = asNonNegativeFiniteNumber(record.output_tokens) ?? asNonNegativeFiniteNumber(record.outputTokens) ?? asNonNegativeFiniteNumber(record.completion_tokens) ?? asNonNegativeFiniteNumber(record.completionTokens);
|
|
4854
|
+
const cacheRead = asNonNegativeFiniteNumber(record.cache_read_input_tokens) ?? asNonNegativeFiniteNumber(record.cacheReadInputTokens) ?? asNonNegativeFiniteNumber(record.cache_read_tokens) ?? asNonNegativeFiniteNumber(record.cacheReadTokens) ?? asNonNegativeFiniteNumber(record.cached_read_tokens) ?? asNonNegativeFiniteNumber(record.cachedReadTokens);
|
|
4855
|
+
const cacheCreation = asNonNegativeFiniteNumber(record.cache_creation_input_tokens) ?? asNonNegativeFiniteNumber(record.cacheCreationInputTokens) ?? asNonNegativeFiniteNumber(record.cache_creation_tokens) ?? asNonNegativeFiniteNumber(record.cacheCreationTokens) ?? asNonNegativeFiniteNumber(record.cached_write_tokens) ?? asNonNegativeFiniteNumber(record.cachedWriteTokens);
|
|
4856
|
+
const thought = asNonNegativeFiniteNumber(record.thought_tokens) ?? asNonNegativeFiniteNumber(record.thoughtTokens);
|
|
4857
|
+
const totalFromPayload = asNonNegativeFiniteNumber(record.total_tokens) ?? asNonNegativeFiniteNumber(record.totalTokens);
|
|
4858
|
+
const anyPresent = totalFromPayload != null || input != null || output != null || cacheRead != null || cacheCreation != null || thought != null;
|
|
4859
|
+
if (!anyPresent) {
|
|
4860
|
+
return null;
|
|
4861
|
+
}
|
|
4862
|
+
const total = totalFromPayload ?? (input ?? 0) + (output ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0) + (thought ?? 0);
|
|
4863
|
+
const tokens = { total };
|
|
4864
|
+
if (input != null) tokens.input = input;
|
|
4865
|
+
if (output != null) tokens.output = output;
|
|
4866
|
+
if (cacheRead != null) tokens.cache_read = cacheRead;
|
|
4867
|
+
if (cacheCreation != null) tokens.cache_creation = cacheCreation;
|
|
4868
|
+
if (thought != null) tokens.thought = thought;
|
|
4869
|
+
return tokens;
|
|
4870
|
+
}
|
|
4871
|
+
function isApprovalOption(option) {
|
|
4872
|
+
if (option.optionId === "proceed_once" || option.optionId === "proceed_always" || option.optionId === "cancel") {
|
|
4873
|
+
return true;
|
|
4874
|
+
}
|
|
4875
|
+
const searchable = `${option.name ?? ""} ${option.label ?? ""}`.toLowerCase();
|
|
4876
|
+
return searchable.includes("once") || searchable.includes("always") || searchable.includes("cancel");
|
|
4877
|
+
}
|
|
4878
|
+
function isSelectionPermissionRequest(params) {
|
|
4879
|
+
if (Array.isArray(params.codex_command) && params.codex_command.length > 0) {
|
|
4880
|
+
return false;
|
|
4881
|
+
}
|
|
4882
|
+
if (params.requestedSchema?.properties?.optionId) {
|
|
4883
|
+
return true;
|
|
4884
|
+
}
|
|
4885
|
+
const options = Array.isArray(params.options) ? params.options : [];
|
|
4886
|
+
if (options.length === 0) {
|
|
4887
|
+
return false;
|
|
4888
|
+
}
|
|
4889
|
+
return !options.every((option) => isApprovalOption(option));
|
|
4890
|
+
}
|
|
4709
4891
|
function nodeToWebStreams(stdin, stdout) {
|
|
4710
4892
|
const writable = new WritableStream({
|
|
4711
4893
|
write(chunk) {
|
|
@@ -4769,7 +4951,7 @@ async function withRetry(operation, options) {
|
|
|
4769
4951
|
try {
|
|
4770
4952
|
return await operation();
|
|
4771
4953
|
} catch (error) {
|
|
4772
|
-
lastError =
|
|
4954
|
+
lastError = normalizeAcpError(error);
|
|
4773
4955
|
if (attempt < options.maxAttempts) {
|
|
4774
4956
|
const delayMs = Math.min(
|
|
4775
4957
|
options.baseDelayMs * Math.pow(2, attempt - 1),
|
|
@@ -4783,6 +4965,49 @@ async function withRetry(operation, options) {
|
|
|
4783
4965
|
}
|
|
4784
4966
|
throw lastError;
|
|
4785
4967
|
}
|
|
4968
|
+
function formatAcpErrorMessage(error) {
|
|
4969
|
+
if (error instanceof Error && error.message && error.message !== "[object Object]") {
|
|
4970
|
+
return error.message;
|
|
4971
|
+
}
|
|
4972
|
+
if (typeof error === "object" && error !== null) {
|
|
4973
|
+
const record = error;
|
|
4974
|
+
const message = formatDisplayMessage(error).trim();
|
|
4975
|
+
const code = record.code;
|
|
4976
|
+
const status = record.status;
|
|
4977
|
+
const prefix = [
|
|
4978
|
+
code !== void 0 && code !== null ? `[code=${String(code)}]` : "",
|
|
4979
|
+
status !== void 0 && status !== null ? `[status=${String(status)}]` : ""
|
|
4980
|
+
].filter(Boolean).join(" ");
|
|
4981
|
+
if (message.length > 0) {
|
|
4982
|
+
return prefix ? `${prefix} ${message}` : message;
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
const fallback = formatDisplayMessage(error).trim();
|
|
4986
|
+
return fallback || "Unknown ACP error";
|
|
4987
|
+
}
|
|
4988
|
+
function normalizeAcpError(error) {
|
|
4989
|
+
if (error instanceof Error && error.message && error.message !== "[object Object]") {
|
|
4990
|
+
return error;
|
|
4991
|
+
}
|
|
4992
|
+
const normalized = new Error(formatAcpErrorMessage(error));
|
|
4993
|
+
normalized.name = error instanceof Error ? error.name : "Error";
|
|
4994
|
+
if (error && typeof error === "object") {
|
|
4995
|
+
const { message: _message, ...rest } = error;
|
|
4996
|
+
Object.assign(normalized, rest);
|
|
4997
|
+
}
|
|
4998
|
+
return normalized;
|
|
4999
|
+
}
|
|
5000
|
+
function enrichAcpError(error, stderrExcerpt) {
|
|
5001
|
+
const normalized = normalizeAcpError(error);
|
|
5002
|
+
if (!stderrExcerpt.trim()) {
|
|
5003
|
+
return normalized;
|
|
5004
|
+
}
|
|
5005
|
+
const existingStderr = normalized.stderr;
|
|
5006
|
+
if (typeof existingStderr !== "string" || existingStderr.trim().length === 0) {
|
|
5007
|
+
Object.assign(normalized, { stderr: stderrExcerpt });
|
|
5008
|
+
}
|
|
5009
|
+
return normalized;
|
|
5010
|
+
}
|
|
4786
5011
|
class AcpBackend {
|
|
4787
5012
|
constructor(options) {
|
|
4788
5013
|
this.options = options;
|
|
@@ -4810,6 +5035,21 @@ class AcpBackend {
|
|
|
4810
5035
|
idleTimeout = null;
|
|
4811
5036
|
/** Transport handler for agent-specific behavior */
|
|
4812
5037
|
transport;
|
|
5038
|
+
/** Keep a short rolling stderr buffer so startup failures can surface the real cause. */
|
|
5039
|
+
recentStderrLines = [];
|
|
5040
|
+
recordRecentStderr(text) {
|
|
5041
|
+
const normalized = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
5042
|
+
if (normalized.length === 0) {
|
|
5043
|
+
return;
|
|
5044
|
+
}
|
|
5045
|
+
this.recentStderrLines.push(...normalized);
|
|
5046
|
+
if (this.recentStderrLines.length > 12) {
|
|
5047
|
+
this.recentStderrLines = this.recentStderrLines.slice(-12);
|
|
5048
|
+
}
|
|
5049
|
+
}
|
|
5050
|
+
getRecentStderrExcerpt() {
|
|
5051
|
+
return this.recentStderrLines.slice(-6).join("\n");
|
|
5052
|
+
}
|
|
4813
5053
|
onMessage(handler) {
|
|
4814
5054
|
this.listeners.push(handler);
|
|
4815
5055
|
}
|
|
@@ -4837,6 +5077,7 @@ class AcpBackend {
|
|
|
4837
5077
|
this.emit({ type: "status", status: "starting" });
|
|
4838
5078
|
try {
|
|
4839
5079
|
api.logger.debug(`[AcpBackend] Starting session: ${sessionId}`);
|
|
5080
|
+
this.recentStderrLines = [];
|
|
4840
5081
|
const args = this.options.args || [];
|
|
4841
5082
|
if (process.platform === "win32") {
|
|
4842
5083
|
const fullCommand = [this.options.command, ...args].join(" ");
|
|
@@ -4863,6 +5104,7 @@ class AcpBackend {
|
|
|
4863
5104
|
this.process.stderr.on("data", (data) => {
|
|
4864
5105
|
const text = data.toString();
|
|
4865
5106
|
if (!text.trim()) return;
|
|
5107
|
+
this.recordRecentStderr(text);
|
|
4866
5108
|
const hasActiveInvestigation = this.transport.isInvestigationTool ? Array.from(this.activeToolCalls).some((id) => this.transport.isInvestigationTool(id)) : false;
|
|
4867
5109
|
const context = {
|
|
4868
5110
|
activeToolCalls: this.activeToolCalls,
|
|
@@ -4973,6 +5215,7 @@ class AcpBackend {
|
|
|
4973
5215
|
}
|
|
4974
5216
|
this.toolCallCountSincePrompt++;
|
|
4975
5217
|
const options = extendedParams.options || [];
|
|
5218
|
+
const isSelectionRequest = isSelectionPermissionRequest(extendedParams);
|
|
4976
5219
|
api.logger.debug(`[AcpBackend] Permission request: tool=${toolName}, toolCallId=${toolCallId}, input=`, JSON.stringify(input));
|
|
4977
5220
|
api.logger.debug(`[AcpBackend] Permission request params structure:`, JSON.stringify({
|
|
4978
5221
|
hasToolCall: !!toolCall,
|
|
@@ -4981,6 +5224,42 @@ class AcpBackend {
|
|
|
4981
5224
|
paramsKind: extendedParams.kind,
|
|
4982
5225
|
paramsKeys: Object.keys(params)
|
|
4983
5226
|
}, null, 2));
|
|
5227
|
+
if (isSelectionRequest) {
|
|
5228
|
+
const selectionOptions = options.reduce((acc, option) => {
|
|
5229
|
+
if (!option.optionId) {
|
|
5230
|
+
return acc;
|
|
5231
|
+
}
|
|
5232
|
+
const displayOption = option;
|
|
5233
|
+
acc.push({
|
|
5234
|
+
optionId: option.optionId,
|
|
5235
|
+
label: displayOption.label || option.name || option.optionId,
|
|
5236
|
+
description: displayOption.description || option.name || option.optionId
|
|
5237
|
+
});
|
|
5238
|
+
return acc;
|
|
5239
|
+
}, []);
|
|
5240
|
+
if (selectionOptions.length === 0) {
|
|
5241
|
+
api.logger.debug("[AcpBackend] Selection request has no valid options, cancelling");
|
|
5242
|
+
return { outcome: { outcome: "selected", optionId: "cancel" } };
|
|
5243
|
+
}
|
|
5244
|
+
if (!this.options.selectionHandler) {
|
|
5245
|
+
api.logger.debug("[AcpBackend] No selection handler configured, cancelling selection request");
|
|
5246
|
+
return { outcome: { outcome: "selected", optionId: "cancel" } };
|
|
5247
|
+
}
|
|
5248
|
+
try {
|
|
5249
|
+
const selectionMessage = typeof extendedParams.message === "string" && extendedParams.message.trim().length > 0 ? extendedParams.message : formatDisplayMessage(input).trim() || toolName;
|
|
5250
|
+
const requestId = extendedParams.codex_event_id || extendedParams.codex_elicitation || toolCallId;
|
|
5251
|
+
const response = await this.options.selectionHandler.handleSelection({
|
|
5252
|
+
id: requestId,
|
|
5253
|
+
message: selectionMessage,
|
|
5254
|
+
options: selectionOptions,
|
|
5255
|
+
defaultOptionId: extendedParams.requestedSchema?.properties?.optionId?.default
|
|
5256
|
+
});
|
|
5257
|
+
return { outcome: { outcome: "selected", optionId: response.optionId } };
|
|
5258
|
+
} catch (error) {
|
|
5259
|
+
api.logger.debug("[AcpBackend] Error in selection handler:", error);
|
|
5260
|
+
return { outcome: { outcome: "selected", optionId: "cancel" } };
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
4984
5263
|
this.emit({
|
|
4985
5264
|
type: "permission-request",
|
|
4986
5265
|
id: permissionId,
|
|
@@ -5154,18 +5433,19 @@ class AcpBackend {
|
|
|
5154
5433
|
if (initialPrompt) {
|
|
5155
5434
|
this.sendPrompt(sessionId, initialPrompt).catch((error) => {
|
|
5156
5435
|
api.logger.debug("[AcpBackend] Error sending initial prompt:", error);
|
|
5157
|
-
this.emit({ type: "status", status: "error", detail:
|
|
5436
|
+
this.emit({ type: "status", status: "error", detail: formatAcpErrorMessage(error) });
|
|
5158
5437
|
});
|
|
5159
5438
|
}
|
|
5160
5439
|
return { sessionId };
|
|
5161
5440
|
} catch (error) {
|
|
5162
|
-
|
|
5441
|
+
const enrichedError = enrichAcpError(error, this.getRecentStderrExcerpt());
|
|
5442
|
+
api.logger.debug("[AcpBackend] Error starting session:", enrichedError);
|
|
5163
5443
|
this.emit({
|
|
5164
5444
|
type: "status",
|
|
5165
5445
|
status: "error",
|
|
5166
|
-
detail:
|
|
5446
|
+
detail: formatAcpErrorMessage(enrichedError)
|
|
5167
5447
|
});
|
|
5168
|
-
throw
|
|
5448
|
+
throw enrichedError;
|
|
5169
5449
|
}
|
|
5170
5450
|
}
|
|
5171
5451
|
/**
|
|
@@ -5196,51 +5476,73 @@ class AcpBackend {
|
|
|
5196
5476
|
}
|
|
5197
5477
|
};
|
|
5198
5478
|
}
|
|
5479
|
+
emitUsageTelemetry(payload, source) {
|
|
5480
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
5481
|
+
return false;
|
|
5482
|
+
}
|
|
5483
|
+
const tokens = extractUsageTokens(payload);
|
|
5484
|
+
if (!tokens) {
|
|
5485
|
+
return false;
|
|
5486
|
+
}
|
|
5487
|
+
this.emit({
|
|
5488
|
+
type: "token-count",
|
|
5489
|
+
key: source,
|
|
5490
|
+
tokens,
|
|
5491
|
+
source
|
|
5492
|
+
});
|
|
5493
|
+
return true;
|
|
5494
|
+
}
|
|
5199
5495
|
handleSessionUpdate(params) {
|
|
5200
|
-
const
|
|
5201
|
-
|
|
5202
|
-
if (!update) {
|
|
5496
|
+
const updates = getSessionUpdates(params);
|
|
5497
|
+
if (updates.length === 0) {
|
|
5203
5498
|
api.logger.debug("[AcpBackend] Received session update without update field:", params);
|
|
5204
5499
|
return;
|
|
5205
5500
|
}
|
|
5206
|
-
const
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5501
|
+
for (const update of updates) {
|
|
5502
|
+
const sessionUpdateType = update.sessionUpdate;
|
|
5503
|
+
if (sessionUpdateType !== "agent_message_chunk") {
|
|
5504
|
+
api.logger.debug(`[AcpBackend] Received session update: ${sessionUpdateType}`, JSON.stringify({
|
|
5505
|
+
sessionUpdate: sessionUpdateType,
|
|
5506
|
+
toolCallId: update.toolCallId,
|
|
5507
|
+
status: update.status,
|
|
5508
|
+
kind: update.kind,
|
|
5509
|
+
hasContent: !!update.content,
|
|
5510
|
+
hasLocations: !!update.locations
|
|
5511
|
+
}, null, 2));
|
|
5512
|
+
}
|
|
5513
|
+
const ctx = this.createHandlerContext();
|
|
5514
|
+
if (sessionUpdateType === "agent_message_chunk") {
|
|
5515
|
+
handleAgentMessageChunk(update, ctx);
|
|
5516
|
+
continue;
|
|
5517
|
+
}
|
|
5518
|
+
if (sessionUpdateType === "tool_call_update") {
|
|
5519
|
+
const result = handleToolCallUpdate(update, ctx);
|
|
5520
|
+
if (result.toolCallCountSincePrompt !== void 0) {
|
|
5521
|
+
this.toolCallCountSincePrompt = result.toolCallCountSincePrompt;
|
|
5522
|
+
}
|
|
5523
|
+
continue;
|
|
5524
|
+
}
|
|
5525
|
+
if (sessionUpdateType === "agent_thought_chunk") {
|
|
5526
|
+
handleAgentThoughtChunk(update, ctx);
|
|
5527
|
+
continue;
|
|
5528
|
+
}
|
|
5529
|
+
if (sessionUpdateType === "tool_call") {
|
|
5530
|
+
handleToolCall(update, ctx);
|
|
5531
|
+
continue;
|
|
5532
|
+
}
|
|
5533
|
+
if (sessionUpdateType === "usage_update") {
|
|
5534
|
+
this.emitUsageTelemetry(update, "acp-usage-update");
|
|
5535
|
+
continue;
|
|
5536
|
+
}
|
|
5537
|
+
const handledLegacy = handleLegacyMessageChunk(update, ctx).handled;
|
|
5538
|
+
const handledPlan = handlePlanUpdate(update, ctx).handled;
|
|
5539
|
+
const handledThinking = handleThinkingUpdate(update, ctx).handled;
|
|
5540
|
+
const handledUsage = this.emitUsageTelemetry(update.usage, "acp-session-usage");
|
|
5541
|
+
const updateTypeStr = sessionUpdateType;
|
|
5542
|
+
const handledTypes = ["agent_message_chunk", "tool_call_update", "agent_thought_chunk", "tool_call", "usage_update"];
|
|
5543
|
+
if (updateTypeStr && !handledTypes.includes(updateTypeStr) && !handledLegacy && !handledPlan && !handledThinking && !handledUsage) {
|
|
5544
|
+
api.logger.debug(`[AcpBackend] Unhandled session update type: ${updateTypeStr}`, JSON.stringify(update, null, 2));
|
|
5226
5545
|
}
|
|
5227
|
-
return;
|
|
5228
|
-
}
|
|
5229
|
-
if (sessionUpdateType === "agent_thought_chunk") {
|
|
5230
|
-
handleAgentThoughtChunk(update, ctx);
|
|
5231
|
-
return;
|
|
5232
|
-
}
|
|
5233
|
-
if (sessionUpdateType === "tool_call") {
|
|
5234
|
-
handleToolCall(update, ctx);
|
|
5235
|
-
return;
|
|
5236
|
-
}
|
|
5237
|
-
handleLegacyMessageChunk(update, ctx);
|
|
5238
|
-
handlePlanUpdate(update, ctx);
|
|
5239
|
-
handleThinkingUpdate(update, ctx);
|
|
5240
|
-
const updateTypeStr = sessionUpdateType;
|
|
5241
|
-
const handledTypes = ["agent_message_chunk", "tool_call_update", "agent_thought_chunk", "tool_call"];
|
|
5242
|
-
if (updateTypeStr && !handledTypes.includes(updateTypeStr) && !update.messageChunk && !update.plan && !update.thinking) {
|
|
5243
|
-
api.logger.debug(`[AcpBackend] Unhandled session update type: ${updateTypeStr}`, JSON.stringify(update, null, 2));
|
|
5244
5546
|
}
|
|
5245
5547
|
}
|
|
5246
5548
|
// Promise resolver for waitForIdle - set when waiting for response to complete
|
|
@@ -5277,17 +5579,9 @@ class AcpBackend {
|
|
|
5277
5579
|
if (error instanceof Error) {
|
|
5278
5580
|
errorDetail = error.message;
|
|
5279
5581
|
} else if (typeof error === "object" && error !== null) {
|
|
5280
|
-
|
|
5281
|
-
const fallbackMessage = (typeof errObj.message === "string" ? errObj.message : void 0) || String(error);
|
|
5282
|
-
if (errObj.code !== void 0) {
|
|
5283
|
-
errorDetail = JSON.stringify({ code: errObj.code, message: fallbackMessage });
|
|
5284
|
-
} else if (typeof errObj.message === "string") {
|
|
5285
|
-
errorDetail = errObj.message;
|
|
5286
|
-
} else {
|
|
5287
|
-
errorDetail = String(error);
|
|
5288
|
-
}
|
|
5582
|
+
errorDetail = formatAcpErrorMessage(error);
|
|
5289
5583
|
} else {
|
|
5290
|
-
errorDetail =
|
|
5584
|
+
errorDetail = formatAcpErrorMessage(error);
|
|
5291
5585
|
}
|
|
5292
5586
|
this.emit({
|
|
5293
5587
|
type: "status",
|
|
@@ -5638,59 +5932,213 @@ function registerGeminiAgent() {
|
|
|
5638
5932
|
api.logger.debug("[Gemini] Registered with agent registry");
|
|
5639
5933
|
}
|
|
5640
5934
|
|
|
5641
|
-
function
|
|
5642
|
-
for (const
|
|
5643
|
-
|
|
5935
|
+
function readFirstEnv(...names) {
|
|
5936
|
+
for (const name of names) {
|
|
5937
|
+
const raw = process.env[name];
|
|
5938
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
5939
|
+
return raw.trim();
|
|
5940
|
+
}
|
|
5941
|
+
}
|
|
5942
|
+
return "";
|
|
5943
|
+
}
|
|
5944
|
+
function normalizeCommandPath(command) {
|
|
5945
|
+
if (path.isAbsolute(command)) {
|
|
5946
|
+
return command;
|
|
5947
|
+
}
|
|
5948
|
+
const resolved = path.resolve(process.cwd(), command);
|
|
5949
|
+
return fs.existsSync(resolved) ? resolved : command;
|
|
5950
|
+
}
|
|
5951
|
+
function resolveCommandOnPath(command) {
|
|
5952
|
+
const pathValue = typeof process.env.PATH === "string" ? process.env.PATH : "";
|
|
5953
|
+
if (!pathValue) {
|
|
5954
|
+
return null;
|
|
5955
|
+
}
|
|
5956
|
+
const extensions = process.platform === "win32" ? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").map((value) => value.trim().toLowerCase()).filter(Boolean) : [""];
|
|
5957
|
+
for (const dir of pathValue.split(path.delimiter)) {
|
|
5958
|
+
const trimmedDir = dir.trim();
|
|
5959
|
+
if (!trimmedDir) {
|
|
5960
|
+
continue;
|
|
5961
|
+
}
|
|
5962
|
+
const directCandidate = path.join(trimmedDir, command);
|
|
5963
|
+
if (fs.existsSync(directCandidate)) {
|
|
5964
|
+
return directCandidate;
|
|
5965
|
+
}
|
|
5966
|
+
if (process.platform !== "win32") {
|
|
5967
|
+
continue;
|
|
5968
|
+
}
|
|
5969
|
+
const hasExtension = /\.[^\\/]+$/.test(command);
|
|
5970
|
+
if (hasExtension) {
|
|
5971
|
+
continue;
|
|
5972
|
+
}
|
|
5973
|
+
for (const extension of extensions) {
|
|
5974
|
+
const candidate = path.join(trimmedDir, `${command}${extension.toLowerCase()}`);
|
|
5644
5975
|
if (fs.existsSync(candidate)) {
|
|
5645
5976
|
return candidate;
|
|
5646
5977
|
}
|
|
5647
|
-
} catch {
|
|
5648
5978
|
}
|
|
5649
5979
|
}
|
|
5650
5980
|
return null;
|
|
5651
5981
|
}
|
|
5652
|
-
function
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
const resolved = firstExistingPath([
|
|
5657
|
-
path.join(npmGlobalBin, "codex.cmd"),
|
|
5658
|
-
path.join(npmGlobalBin, "codex.ps1"),
|
|
5659
|
-
path.join(npmGlobalBin, "codex")
|
|
5660
|
-
]);
|
|
5661
|
-
if (resolved) {
|
|
5662
|
-
return resolved;
|
|
5663
|
-
}
|
|
5982
|
+
function readCodexAcpNpxMode() {
|
|
5983
|
+
const raw = readFirstEnv("HAPPY_CODEX_ACP_NPX_MODE", "HAPPIER_CODEX_ACP_NPX_MODE").toLowerCase();
|
|
5984
|
+
if (raw === "auto" || raw === "never" || raw === "force") {
|
|
5985
|
+
return raw;
|
|
5664
5986
|
}
|
|
5665
|
-
return "
|
|
5987
|
+
return "auto";
|
|
5988
|
+
}
|
|
5989
|
+
function isBinOnPath(baseName) {
|
|
5990
|
+
return resolveCommandOnPath(baseName) !== null;
|
|
5666
5991
|
}
|
|
5667
|
-
function
|
|
5668
|
-
|
|
5992
|
+
function readCodexAcpConfigOverrides() {
|
|
5993
|
+
const raw = readFirstEnv("HAPPY_CODEX_ACP_CONFIG_OVERRIDES", "HAPPIER_CODEX_ACP_CONFIG_OVERRIDES");
|
|
5994
|
+
return raw.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
5995
|
+
}
|
|
5996
|
+
function buildCodexAcpConfigArgs(options) {
|
|
5997
|
+
const args = [...options.baseArgs ?? []];
|
|
5998
|
+
const overrides = [...readCodexAcpConfigOverrides()];
|
|
5999
|
+
if (options.model) {
|
|
6000
|
+
overrides.push(`model=${JSON.stringify(options.model)}`);
|
|
6001
|
+
}
|
|
6002
|
+
if (options.approvalPolicy) {
|
|
6003
|
+
overrides.push(`approval_policy=${JSON.stringify(options.approvalPolicy)}`);
|
|
6004
|
+
}
|
|
6005
|
+
if (options.sandbox) {
|
|
6006
|
+
overrides.push(`sandbox_mode=${JSON.stringify(options.sandbox)}`);
|
|
6007
|
+
}
|
|
6008
|
+
for (const override of overrides) {
|
|
6009
|
+
args.push("-c", override);
|
|
6010
|
+
}
|
|
6011
|
+
return args;
|
|
6012
|
+
}
|
|
6013
|
+
function resolveNpxCommand() {
|
|
6014
|
+
return resolveCommandOnPath(process.platform === "win32" ? "npx.cmd" : "npx") ?? resolveCommandOnPath("npx") ?? (process.platform === "win32" ? "npx.cmd" : "npx");
|
|
6015
|
+
}
|
|
6016
|
+
function resolveCodexAcpSpawn(options = {}) {
|
|
6017
|
+
if (options.args) {
|
|
6018
|
+
const command = normalizeCommandPath(options.command || readFirstEnv("HAPPY_CODEX_ACP_BIN", "HAPPY_CODEX_ACP_COMMAND", "HAPPIER_CODEX_ACP_BIN") || "codex-acp");
|
|
6019
|
+
return {
|
|
6020
|
+
command,
|
|
6021
|
+
args: [...options.args]
|
|
6022
|
+
};
|
|
6023
|
+
}
|
|
6024
|
+
const directArgs = buildCodexAcpConfigArgs(options);
|
|
6025
|
+
if (options.command) {
|
|
6026
|
+
return {
|
|
6027
|
+
command: normalizeCommandPath(options.command),
|
|
6028
|
+
args: directArgs
|
|
6029
|
+
};
|
|
6030
|
+
}
|
|
6031
|
+
const envOverride = readFirstEnv("HAPPY_CODEX_ACP_BIN", "HAPPY_CODEX_ACP_COMMAND", "HAPPIER_CODEX_ACP_BIN");
|
|
6032
|
+
if (envOverride) {
|
|
6033
|
+
return {
|
|
6034
|
+
command: normalizeCommandPath(envOverride),
|
|
6035
|
+
args: directArgs
|
|
6036
|
+
};
|
|
6037
|
+
}
|
|
6038
|
+
const npxMode = readCodexAcpNpxMode();
|
|
6039
|
+
const codexAcpOnPath = resolveCommandOnPath(process.platform === "win32" ? "codex-acp.cmd" : "codex-acp") ?? resolveCommandOnPath("codex-acp");
|
|
6040
|
+
if (npxMode !== "force" && codexAcpOnPath) {
|
|
6041
|
+
return {
|
|
6042
|
+
command: codexAcpOnPath,
|
|
6043
|
+
args: directArgs
|
|
6044
|
+
};
|
|
6045
|
+
}
|
|
6046
|
+
if (npxMode === "never") {
|
|
6047
|
+
return {
|
|
6048
|
+
command: process.platform === "win32" ? "codex-acp.cmd" : "codex-acp",
|
|
6049
|
+
args: directArgs
|
|
6050
|
+
};
|
|
6051
|
+
}
|
|
6052
|
+
return {
|
|
6053
|
+
command: resolveNpxCommand(),
|
|
6054
|
+
args: ["--prefer-offline", "-y", "@zed-industries/codex-acp", ...directArgs]
|
|
6055
|
+
};
|
|
6056
|
+
}
|
|
6057
|
+
function validateCodexAcpSpawn(options = {}) {
|
|
6058
|
+
let spawn;
|
|
6059
|
+
try {
|
|
6060
|
+
spawn = resolveCodexAcpSpawn(options);
|
|
6061
|
+
} catch (error) {
|
|
6062
|
+
return {
|
|
6063
|
+
ok: false,
|
|
6064
|
+
errorMessage: error instanceof Error ? error.message : "Codex ACP is enabled, but the command could not be resolved."
|
|
6065
|
+
};
|
|
6066
|
+
}
|
|
6067
|
+
const normalizedCommand = spawn.command.trim();
|
|
6068
|
+
const commandLower = normalizedCommand.toLowerCase();
|
|
6069
|
+
const npxMode = readCodexAcpNpxMode();
|
|
6070
|
+
if (path.isAbsolute(normalizedCommand)) {
|
|
6071
|
+
if (!fs.existsSync(normalizedCommand)) {
|
|
6072
|
+
return {
|
|
6073
|
+
ok: false,
|
|
6074
|
+
errorMessage: `Codex ACP is enabled, but the resolved command does not exist: ${normalizedCommand}`
|
|
6075
|
+
};
|
|
6076
|
+
}
|
|
6077
|
+
return { ok: true, spawn };
|
|
6078
|
+
}
|
|
6079
|
+
if (commandLower.endsWith("npx") || commandLower.endsWith("npx.cmd")) {
|
|
6080
|
+
if (isBinOnPath("npx") || isBinOnPath("npx.cmd")) {
|
|
6081
|
+
return { ok: true, spawn };
|
|
6082
|
+
}
|
|
6083
|
+
return {
|
|
6084
|
+
ok: false,
|
|
6085
|
+
errorMessage: "Codex ACP is enabled, but codex-acp is not installed and npx is not available. Install codex-acp, install Node.js/npm so npx is available, or set HAPPY_CODEX_ACP_BIN to a working codex-acp executable."
|
|
6086
|
+
};
|
|
6087
|
+
}
|
|
6088
|
+
if (commandLower === "codex-acp" || commandLower === "codex-acp.cmd") {
|
|
6089
|
+
if (isBinOnPath("codex-acp") || isBinOnPath("codex-acp.cmd")) {
|
|
6090
|
+
return { ok: true, spawn };
|
|
6091
|
+
}
|
|
6092
|
+
return {
|
|
6093
|
+
ok: false,
|
|
6094
|
+
errorMessage: npxMode === "never" ? "Codex ACP is enabled, but codex-acp is not installed and npx fallback is disabled. Install codex-acp, add it to PATH, or set HAPPY_CODEX_ACP_BIN to the executable." : "Codex ACP is enabled, but codex-acp could not be resolved on PATH. Install codex-acp, add it to PATH, or set HAPPY_CODEX_ACP_BIN to the executable."
|
|
6095
|
+
};
|
|
6096
|
+
}
|
|
6097
|
+
return { ok: true, spawn };
|
|
5669
6098
|
}
|
|
5670
6099
|
|
|
5671
|
-
|
|
5672
|
-
|
|
6100
|
+
class CodexAcpTransport extends CodexTransport {
|
|
6101
|
+
constructor(initTimeoutMs) {
|
|
6102
|
+
super();
|
|
6103
|
+
this.initTimeoutMs = initTimeoutMs;
|
|
6104
|
+
}
|
|
6105
|
+
getInitTimeout() {
|
|
6106
|
+
return this.initTimeoutMs;
|
|
6107
|
+
}
|
|
6108
|
+
}
|
|
6109
|
+
function resolveCodexTransport(command) {
|
|
6110
|
+
if (/npx(?:\.cmd)?$/i.test(command)) {
|
|
6111
|
+
return new CodexAcpTransport(18e4);
|
|
6112
|
+
}
|
|
6113
|
+
return new CodexAcpTransport(6e4);
|
|
5673
6114
|
}
|
|
5674
6115
|
function createCodexBackend(options) {
|
|
5675
|
-
const
|
|
5676
|
-
|
|
6116
|
+
const spawn = resolveCodexAcpSpawn({
|
|
6117
|
+
command: options.command,
|
|
6118
|
+
args: options.args,
|
|
6119
|
+
baseArgs: options.baseArgs,
|
|
6120
|
+
model: options.model,
|
|
6121
|
+
sandbox: options.sandbox,
|
|
6122
|
+
approvalPolicy: options.approvalPolicy
|
|
6123
|
+
});
|
|
5677
6124
|
const backendOptions = {
|
|
5678
6125
|
agentName: "codex",
|
|
5679
6126
|
cwd: options.cwd,
|
|
5680
|
-
command,
|
|
5681
|
-
args,
|
|
6127
|
+
command: spawn.command,
|
|
6128
|
+
args: spawn.args,
|
|
5682
6129
|
env: {
|
|
5683
6130
|
...options.env,
|
|
5684
6131
|
NODE_ENV: "production"
|
|
5685
6132
|
},
|
|
5686
6133
|
mcpServers: options.mcpServers,
|
|
5687
6134
|
permissionHandler: options.permissionHandler,
|
|
5688
|
-
|
|
6135
|
+
selectionHandler: options.selectionHandler,
|
|
6136
|
+
transportHandler: resolveCodexTransport(spawn.command)
|
|
5689
6137
|
};
|
|
5690
6138
|
return {
|
|
5691
6139
|
backend: new AcpBackend(backendOptions),
|
|
5692
|
-
command,
|
|
5693
|
-
args
|
|
6140
|
+
command: spawn.command,
|
|
6141
|
+
args: spawn.args
|
|
5694
6142
|
};
|
|
5695
6143
|
}
|
|
5696
6144
|
function registerCodexAgent() {
|
|
@@ -5876,17 +6324,26 @@ async function ensureUnifiedDaemonStarted() {
|
|
|
5876
6324
|
env: process.env
|
|
5877
6325
|
});
|
|
5878
6326
|
daemonProcess.unref();
|
|
5879
|
-
|
|
6327
|
+
for (let i = 0; i < 100; i++) {
|
|
6328
|
+
if (await isDaemonRunningCurrentlyInstalledHappyVersion()) {
|
|
6329
|
+
return;
|
|
6330
|
+
}
|
|
6331
|
+
if (await isDaemonControlServerResponsive(500)) {
|
|
6332
|
+
return;
|
|
6333
|
+
}
|
|
6334
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
6335
|
+
}
|
|
6336
|
+
throw new Error("Failed to start Happy background service.");
|
|
5880
6337
|
}
|
|
5881
6338
|
async function executeUnifiedProvider(opts) {
|
|
5882
6339
|
const credentials = await ensureUnifiedRuntimePrerequisites(opts.credentials);
|
|
5883
6340
|
if (opts.provider === "claude") {
|
|
5884
|
-
const { runClaude } = await Promise.resolve().then(function () { return require('./runClaude-
|
|
6341
|
+
const { runClaude } = await Promise.resolve().then(function () { return require('./runClaude-CNVufgZb.cjs'); });
|
|
5885
6342
|
await runClaude(credentials, opts.claudeOptions ?? {});
|
|
5886
6343
|
return;
|
|
5887
6344
|
}
|
|
5888
6345
|
if (opts.provider === "codex") {
|
|
5889
|
-
const { runCodex } = await Promise.resolve().then(function () { return require('./runCodex-
|
|
6346
|
+
const { runCodex } = await Promise.resolve().then(function () { return require('./runCodex-Dzy8anlX.cjs'); });
|
|
5890
6347
|
await runCodex({
|
|
5891
6348
|
credentials,
|
|
5892
6349
|
startedBy: opts.startedBy,
|
|
@@ -5896,7 +6353,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
5896
6353
|
return;
|
|
5897
6354
|
}
|
|
5898
6355
|
if (opts.provider === "gemini") {
|
|
5899
|
-
const { runGemini } = await Promise.resolve().then(function () { return require('./runGemini-
|
|
6356
|
+
const { runGemini } = await Promise.resolve().then(function () { return require('./runGemini-CgsVKP7m.cjs'); });
|
|
5900
6357
|
await runGemini({
|
|
5901
6358
|
credentials,
|
|
5902
6359
|
startedBy: opts.startedBy
|
|
@@ -5909,6 +6366,10 @@ async function executeUnifiedProvider(opts) {
|
|
|
5909
6366
|
});
|
|
5910
6367
|
}
|
|
5911
6368
|
|
|
6369
|
+
function shouldRunMainClaudeFlow(opts) {
|
|
6370
|
+
return !opts.showHelp && !opts.showVersion;
|
|
6371
|
+
}
|
|
6372
|
+
|
|
5912
6373
|
(async () => {
|
|
5913
6374
|
const args = process.argv.slice(2);
|
|
5914
6375
|
const isRemoteMode = args.includes("--happy-starting-mode") && args.includes("remote");
|
|
@@ -5917,7 +6378,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
5917
6378
|
Object.defineProperty(process.stderr, "isTTY", { value: false });
|
|
5918
6379
|
}
|
|
5919
6380
|
if (!args.includes("--version")) {
|
|
5920
|
-
api.logger.debug("Starting
|
|
6381
|
+
api.logger.debug("Starting hicloud CLI with args: ", process.argv);
|
|
5921
6382
|
}
|
|
5922
6383
|
const subcommand = args[0];
|
|
5923
6384
|
if (!args.includes("--version")) ;
|
|
@@ -5934,7 +6395,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
5934
6395
|
return;
|
|
5935
6396
|
} else if (subcommand === "runtime") {
|
|
5936
6397
|
if (args[1] === "providers") {
|
|
5937
|
-
const { renderRuntimeProviders } = await Promise.resolve().then(function () { return require('./command-
|
|
6398
|
+
const { renderRuntimeProviders } = await Promise.resolve().then(function () { return require('./command-D8yNlaDo.cjs'); });
|
|
5938
6399
|
console.log(renderRuntimeProviders());
|
|
5939
6400
|
return;
|
|
5940
6401
|
}
|
|
@@ -5960,8 +6421,8 @@ async function executeUnifiedProvider(opts) {
|
|
|
5960
6421
|
}
|
|
5961
6422
|
return;
|
|
5962
6423
|
}
|
|
5963
|
-
console.log("Usage:
|
|
5964
|
-
console.log("
|
|
6424
|
+
console.log("Usage: hicloud runtime providers");
|
|
6425
|
+
console.log(" hicloud runtime launch <claude|codex|gemini|cursor> [prompt]");
|
|
5965
6426
|
return;
|
|
5966
6427
|
} else if (subcommand === "auth") {
|
|
5967
6428
|
try {
|
|
@@ -6112,8 +6573,8 @@ async function executeUnifiedProvider(opts) {
|
|
|
6112
6573
|
const projectId = args[3];
|
|
6113
6574
|
try {
|
|
6114
6575
|
const { saveGoogleCloudProjectToConfig } = await Promise.resolve().then(function () { return config; });
|
|
6115
|
-
const { readCredentials: readCredentials2 } = await Promise.resolve().then(function () { return require('./persistence-
|
|
6116
|
-
const { ApiClient: ApiClient2 } = await Promise.resolve().then(function () { return require('./api-
|
|
6576
|
+
const { readCredentials: readCredentials2 } = await Promise.resolve().then(function () { return require('./persistence-C33AMdtv.cjs'); });
|
|
6577
|
+
const { ApiClient: ApiClient2 } = await Promise.resolve().then(function () { return require('./api-B8v4tczT.cjs'); }).then(function (n) { return n.api; });
|
|
6117
6578
|
let userEmail = void 0;
|
|
6118
6579
|
try {
|
|
6119
6580
|
const credentials = await readCredentials2();
|
|
@@ -6159,7 +6620,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
6159
6620
|
console.log("No Google Cloud Project configured.");
|
|
6160
6621
|
console.log("");
|
|
6161
6622
|
console.log('If you see "Authentication required" error, you may need to set a project:');
|
|
6162
|
-
console.log("
|
|
6623
|
+
console.log(" hicloud gemini project set <your-project-id>");
|
|
6163
6624
|
console.log("");
|
|
6164
6625
|
console.log("This is required for Google Workspace accounts.");
|
|
6165
6626
|
console.log("Guide: https://goo.gle/gemini-cli-auth-docs#workspace-gca");
|
|
@@ -6171,7 +6632,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
6171
6632
|
}
|
|
6172
6633
|
}
|
|
6173
6634
|
if (geminiSubcommand === "project" && !args[2]) {
|
|
6174
|
-
console.log("Usage:
|
|
6635
|
+
console.log("Usage: hicloud gemini project <command>");
|
|
6175
6636
|
console.log("");
|
|
6176
6637
|
console.log("Commands:");
|
|
6177
6638
|
console.log(" set <project-id> Set Google Cloud Project ID");
|
|
@@ -6203,7 +6664,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
6203
6664
|
}
|
|
6204
6665
|
return;
|
|
6205
6666
|
} else if (subcommand === "logout") {
|
|
6206
|
-
console.log(chalk.yellow('Note: "
|
|
6667
|
+
console.log(chalk.yellow('Note: "hicloud logout" is deprecated. Use "hicloud auth logout" instead.\n'));
|
|
6207
6668
|
try {
|
|
6208
6669
|
await handleAuthCommand(["logout"]);
|
|
6209
6670
|
} catch (error) {
|
|
@@ -6262,7 +6723,7 @@ async function executeUnifiedProvider(opts) {
|
|
|
6262
6723
|
child.unref();
|
|
6263
6724
|
let started = false;
|
|
6264
6725
|
for (let i = 0; i < 100; i++) {
|
|
6265
|
-
if (await checkIfDaemonRunningAndCleanupStaleState()) {
|
|
6726
|
+
if (await checkIfDaemonRunningAndCleanupStaleState() && await isDaemonControlServerResponsive(500)) {
|
|
6266
6727
|
started = true;
|
|
6267
6728
|
break;
|
|
6268
6729
|
}
|
|
@@ -6319,20 +6780,20 @@ async function executeUnifiedProvider(opts) {
|
|
|
6319
6780
|
}
|
|
6320
6781
|
} else {
|
|
6321
6782
|
console.log(`
|
|
6322
|
-
${chalk.bold("
|
|
6783
|
+
${chalk.bold("hicloud daemon")} - Daemon management
|
|
6323
6784
|
|
|
6324
6785
|
${chalk.bold("Usage:")}
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6786
|
+
hicloud daemon start Start the daemon (detached)
|
|
6787
|
+
hicloud daemon stop Stop the daemon (sessions stay alive)
|
|
6788
|
+
hicloud daemon status Show daemon status
|
|
6789
|
+
hicloud daemon list List active sessions
|
|
6329
6790
|
|
|
6330
6791
|
If you want to kill all happy related processes run
|
|
6331
|
-
${chalk.cyan("
|
|
6792
|
+
${chalk.cyan("hicloud doctor clean")}
|
|
6332
6793
|
|
|
6333
6794
|
${chalk.bold("Note:")} The daemon runs in the background and manages Claude sessions.
|
|
6334
6795
|
|
|
6335
|
-
${chalk.bold("To clean up runaway processes:")} Use ${chalk.cyan("
|
|
6796
|
+
${chalk.bold("To clean up runaway processes:")} Use ${chalk.cyan("hicloud doctor clean")}
|
|
6336
6797
|
`);
|
|
6337
6798
|
}
|
|
6338
6799
|
return;
|
|
@@ -6407,33 +6868,33 @@ ${chalk.bold("To clean up runaway processes:")} Use ${chalk.cyan("happy-cloud do
|
|
|
6407
6868
|
${chalk.bold(BRAND_CONFIG.name)} - AI \u7F16\u7A0B\u52A9\u624B
|
|
6408
6869
|
|
|
6409
6870
|
${chalk.bold("Usage:")}
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6871
|
+
hicloud [options] Start Claude with mobile control
|
|
6872
|
+
hicloud auth Manage authentication
|
|
6873
|
+
hicloud codex Start Codex mode
|
|
6874
|
+
hicloud gemini Start Gemini mode (ACP)
|
|
6875
|
+
hicloud cursor Start Cursor mode (experimental ACP)
|
|
6876
|
+
hicloud connect Connect AI vendor API keys
|
|
6877
|
+
hicloud notify Send push notification
|
|
6878
|
+
hicloud daemon Manage background service that allows
|
|
6418
6879
|
to spawn new sessions away from your computer
|
|
6419
|
-
|
|
6880
|
+
hicloud doctor System diagnostics & troubleshooting
|
|
6420
6881
|
|
|
6421
6882
|
${chalk.bold("Examples:")}
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6883
|
+
hicloud Start session
|
|
6884
|
+
hicloud --yolo Start with bypassing permissions
|
|
6885
|
+
hicloud sugar for --dangerously-skip-permissions
|
|
6886
|
+
hicloud --chrome Enable Chrome browser access for this session
|
|
6887
|
+
hicloud --no-chrome Disable Chrome even if default is on
|
|
6888
|
+
hicloud --js-runtime bun Use bun instead of node to spawn Claude Code
|
|
6889
|
+
hicloud --claude-env ANTHROPIC_BASE_URL=http://127.0.0.1:3456
|
|
6429
6890
|
Use a custom API endpoint (e.g., claude-code-router)
|
|
6430
|
-
|
|
6431
|
-
|
|
6891
|
+
hicloud auth login --force Authenticate
|
|
6892
|
+
hicloud doctor Run diagnostics
|
|
6432
6893
|
|
|
6433
6894
|
${chalk.bold(`${BRAND_CONFIG.name} supports ALL Claude options!`)}
|
|
6434
|
-
Use any claude flag with
|
|
6895
|
+
Use any claude flag with hicloud as you would with claude. Our favorite:
|
|
6435
6896
|
|
|
6436
|
-
|
|
6897
|
+
hicloud --resume
|
|
6437
6898
|
|
|
6438
6899
|
${chalk.gray("\u2500".repeat(60))}
|
|
6439
6900
|
${chalk.bold.cyan("Claude Code Options (from `claude --help`):")}
|
|
@@ -6448,8 +6909,9 @@ ${chalk.bold.cyan("Claude Code Options (from `claude --help`):")}
|
|
|
6448
6909
|
}
|
|
6449
6910
|
if (showVersion) {
|
|
6450
6911
|
console.log(getVersionString());
|
|
6912
|
+
return;
|
|
6451
6913
|
}
|
|
6452
|
-
if (
|
|
6914
|
+
if (shouldRunMainClaudeFlow({ showHelp, showVersion })) {
|
|
6453
6915
|
printBanner();
|
|
6454
6916
|
}
|
|
6455
6917
|
try {
|
|
@@ -6485,31 +6947,31 @@ async function handleNotifyCommand(args) {
|
|
|
6485
6947
|
}
|
|
6486
6948
|
if (showHelp) {
|
|
6487
6949
|
console.log(`
|
|
6488
|
-
${chalk.bold("
|
|
6950
|
+
${chalk.bold("hicloud notify")} - Send notification
|
|
6489
6951
|
|
|
6490
6952
|
${chalk.bold("Usage:")}
|
|
6491
|
-
|
|
6492
|
-
|
|
6953
|
+
hicloud notify -p <message> [-t <title>] Send notification with custom message and optional title
|
|
6954
|
+
hicloud notify -h, --help Show this help
|
|
6493
6955
|
|
|
6494
6956
|
${chalk.bold("Options:")}
|
|
6495
6957
|
-p <message> Notification message (required)
|
|
6496
6958
|
-t <title> Notification title (optional, defaults to "Happy")
|
|
6497
6959
|
|
|
6498
6960
|
${chalk.bold("Examples:")}
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6961
|
+
hicloud notify -p "Deployment complete!"
|
|
6962
|
+
hicloud notify -p "System update complete" -t "Server Status"
|
|
6963
|
+
hicloud notify -t "Alert" -p "Database connection restored"
|
|
6502
6964
|
`);
|
|
6503
6965
|
return;
|
|
6504
6966
|
}
|
|
6505
6967
|
if (!message) {
|
|
6506
6968
|
console.error(chalk.red('Error: Message is required. Use -p "your message" to specify the notification text.'));
|
|
6507
|
-
console.log(chalk.gray('Run "
|
|
6969
|
+
console.log(chalk.gray('Run "hicloud notify --help" for usage information.'));
|
|
6508
6970
|
process.exit(1);
|
|
6509
6971
|
}
|
|
6510
6972
|
let credentials = await persistence.readCredentials();
|
|
6511
6973
|
if (!credentials) {
|
|
6512
|
-
console.error(chalk.red('Error: Not authenticated. Please run "
|
|
6974
|
+
console.error(chalk.red('Error: Not authenticated. Please run "hicloud auth login" first.'));
|
|
6513
6975
|
process.exit(1);
|
|
6514
6976
|
}
|
|
6515
6977
|
console.log(chalk.blue("\u{1F4F1} Sending push notification..."));
|
|
@@ -6539,8 +7001,10 @@ exports.ExitCodeError = ExitCodeError;
|
|
|
6539
7001
|
exports.GEMINI_MODEL_ENV = GEMINI_MODEL_ENV;
|
|
6540
7002
|
exports.claudeCheckSession = claudeCheckSession;
|
|
6541
7003
|
exports.claudeLocal = claudeLocal;
|
|
7004
|
+
exports.createCodexBackend = createCodexBackend;
|
|
6542
7005
|
exports.createDefaultRuntimeShell = createDefaultRuntimeShell;
|
|
6543
7006
|
exports.createGeminiBackend = createGeminiBackend;
|
|
7007
|
+
exports.formatDisplayMessage = formatDisplayMessage;
|
|
6544
7008
|
exports.getEnvironmentInfo = getEnvironmentInfo;
|
|
6545
7009
|
exports.getInitialGeminiModel = getInitialGeminiModel;
|
|
6546
7010
|
exports.getProjectPath = getProjectPath;
|
|
@@ -6549,9 +7013,9 @@ exports.isBun = isBun;
|
|
|
6549
7013
|
exports.notifyDaemonSessionStarted = notifyDaemonSessionStarted;
|
|
6550
7014
|
exports.projectPath = projectPath;
|
|
6551
7015
|
exports.readGeminiLocalConfig = readGeminiLocalConfig;
|
|
6552
|
-
exports.resolveCodexExecutable = resolveCodexExecutable;
|
|
6553
7016
|
exports.saveGeminiModelToConfig = saveGeminiModelToConfig;
|
|
6554
|
-
exports.shouldUseShellForCodex = shouldUseShellForCodex;
|
|
6555
7017
|
exports.startCaffeinate = startCaffeinate;
|
|
6556
7018
|
exports.stopCaffeinate = stopCaffeinate;
|
|
6557
7019
|
exports.trimIdent = trimIdent;
|
|
7020
|
+
exports.truncateDisplayMessage = truncateDisplayMessage;
|
|
7021
|
+
exports.validateCodexAcpSpawn = validateCodexAcpSpawn;
|