very-happy-cli 0.2.159 → 0.2.161
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/{AcpBackend-VsfkZiVF.mjs → AcpBackend-6U6pQgx1.mjs} +4 -2
- package/dist/{AcpBackend-DUYFlyfN.cjs → AcpBackend-Ba98QDif.cjs} +78 -76
- package/dist/{AcpSessionManager-Bdv8LWXh.cjs → AcpSessionManager-BAY1Pggx.cjs} +9 -9
- package/dist/{AcpSessionManager-rYtVb0kN.mjs → AcpSessionManager-CoMWFVw3.mjs} +1 -1
- package/dist/BasePermissionHandler-2R0uH2CI.cjs +157 -0
- package/dist/BasePermissionHandler-BvvhBTja.mjs +155 -0
- package/dist/BaseReasoningProcessor-DyhO1uoU.mjs +198 -0
- package/dist/BaseReasoningProcessor-fsVNmCEF.cjs +200 -0
- package/dist/RemoteModeDisplay-D-HewyXg.mjs +150 -0
- package/dist/RemoteModeDisplay-NC1gPHtj.cjs +153 -0
- package/dist/agentAttachments-Dbw8iMCZ.cjs +20 -0
- package/dist/agentAttachments-M_B5qEF2.mjs +18 -0
- package/dist/agentGuidance-B5NATuFa.cjs +28 -0
- package/dist/agentGuidance-CQuNlNx8.mjs +20 -0
- package/dist/{agentHome-CvsJyeQB.mjs → agentHome-Ck1i1TQB.mjs} +8 -22
- package/dist/{agentHome-CHh4lmjM.cjs → agentHome-DvNnGphb.cjs} +14 -28
- package/dist/api-B2vLMS-z.cjs +3346 -0
- package/dist/api-SffjRQ1b.mjs +3339 -0
- package/dist/{types-Dh-s4Lqs.mjs → apiMachine-BpW9t8MO.mjs} +9116 -16205
- package/dist/{types-BbvK1Tr_.cjs → apiMachine-gFA54X7y.cjs} +9104 -16247
- package/dist/assistantTools-BfA0R3_m.cjs +380 -0
- package/dist/assistantTools-CgiTbnWb.mjs +376 -0
- package/dist/attachmentContent-CSGxr71v.mjs +82 -0
- package/dist/attachmentContent-DMMZzevR.cjs +88 -0
- package/dist/attachmentLimits-CzVrqgLR.cjs +354 -0
- package/dist/attachmentLimits-yba1uHFO.mjs +348 -0
- package/dist/auth-Bt4ceBBy.cjs +227 -0
- package/dist/auth-CYHjQ8oQ.mjs +225 -0
- package/dist/auth-DdyVZSo6.mjs +218 -0
- package/dist/auth-x4CEoysH.cjs +220 -0
- package/dist/authRelay-BdYkC1Po.cjs +156 -0
- package/dist/authRelay-DSAvg1uv.mjs +143 -0
- package/dist/{auto-DKmEls8Z.cjs → auto-BDXDUnjB.cjs} +70 -79
- package/dist/{auto-nb8GhRRy.mjs → auto-CXLlRi3a.mjs} +27 -36
- package/dist/backgroundTaskActivity-8PdPxrvy.mjs +149 -0
- package/dist/backgroundTaskActivity-CBvUdj39.cjs +157 -0
- package/dist/bootstrap-BNQq05jR.mjs +112 -0
- package/dist/bootstrap-CkgIq8N3.cjs +116 -0
- package/dist/browser-9pyhQr1R.mjs +20 -0
- package/dist/browser-BDOlKWYe.cjs +22 -0
- package/dist/claudeCliPath-BqkaH2oR.mjs +8 -0
- package/dist/claudeCliPath-U4HHmV4r.cjs +10 -0
- package/dist/claudeLocal-BDuGFnjJ.cjs +343 -0
- package/dist/claudeLocal-CQa8qnwq.mjs +339 -0
- package/dist/claudeLocalLauncher-Bd5I2-j6.cjs +154 -0
- package/dist/claudeLocalLauncher-CDqQI9ak.mjs +152 -0
- package/dist/cliUpdate-DsKXPFYp.cjs +120 -0
- package/dist/cliUpdate-Y34VGe9Y.mjs +112 -0
- package/dist/client-Brn-UwVk.mjs +100 -0
- package/dist/client-CXb1VJui.mjs +112 -0
- package/dist/client-C_axwRry.cjs +104 -0
- package/dist/client-DOBWJL3u.cjs +119 -0
- package/dist/codex/happyMcpStdioBridge.cjs +33 -14
- package/dist/codex/happyMcpStdioBridge.mjs +26 -7
- package/dist/codexAppServerClient-ZzhUTWPo.cjs +1090 -0
- package/dist/codexAppServerClient-oeQKD6Qf.mjs +1088 -0
- package/dist/codexCommand-C7H0NpBe.cjs +2088 -0
- package/dist/codexCommand-CJ82bl3l.mjs +2086 -0
- package/dist/codexThreadFork-BCaEMBiM.mjs +338 -0
- package/dist/codexThreadFork-BZqF-9bX.cjs +350 -0
- package/dist/{config-ClLtM6F3.mjs → config-BglnktIo.mjs} +7 -40
- package/dist/{config-DLx-vW3I.cjs → config-CYpL1Ahd.cjs} +26 -59
- package/dist/configuration-DoWFJUPm.mjs +170 -0
- package/dist/configuration-v9f8LM9T.cjs +181 -0
- package/dist/connect-hgcNjyAB.mjs +682 -0
- package/dist/connect-yEvjdRvx.cjs +684 -0
- package/dist/constants-BC4St0xd.mjs +11 -0
- package/dist/constants-VJ0N6WuG.cjs +17 -0
- package/dist/contentLogMetadata-BlWI0egu.mjs +51 -0
- package/dist/contentLogMetadata-ZSFk_NjQ.cjs +54 -0
- package/dist/context-B45vMtSZ.cjs +69 -0
- package/dist/context-C9GHPLEm.mjs +65 -0
- package/dist/controlClient-DjoKTtgK.mjs +260 -0
- package/dist/controlClient-fEHE85bH.cjs +279 -0
- package/dist/createSessionMetadata-BRLB9CNO.cjs +58 -0
- package/dist/createSessionMetadata-mIeehclp.mjs +54 -0
- package/dist/defaultPermissionMode-BnxJPVHT.mjs +4 -0
- package/dist/defaultPermissionMode-CxmTXUQR.cjs +7 -0
- package/dist/detectCLI-CSGMlV51.mjs +58 -0
- package/dist/detectCLI-DR9ZaN6B.cjs +61 -0
- package/dist/deterministicJson-DKDP_mM-.cjs +507 -0
- package/dist/deterministicJson-p835AdAU.mjs +502 -0
- package/dist/doctor-BPkYWSuq.mjs +75 -0
- package/dist/doctor-BeUuQXFs.mjs +391 -0
- package/dist/doctor-hVNnSZJn.cjs +395 -0
- package/dist/doctor-u46qYYKX.cjs +79 -0
- package/dist/doctorReadiness-BCZGcN0a.cjs +151 -0
- package/dist/doctorReadiness-C208SMN9.mjs +142 -0
- package/dist/editPaths-BVfS_FFL.mjs +68 -0
- package/dist/editPaths-Bqp4OFPw.cjs +73 -0
- package/dist/ensureDaemonRunning-CO7d1gOC.mjs +61 -0
- package/dist/ensureDaemonRunning-Dg9aZfjs.cjs +64 -0
- package/dist/handleResumeCommand-BiTPK0qd.mjs +240 -0
- package/dist/handleResumeCommand-DnVmy7a3.cjs +245 -0
- package/dist/ids-B6ZC0HGt.cjs +13 -0
- package/dist/ids-DU6sLx4C.mjs +10 -0
- package/dist/index-B6UGRQ7h.mjs +102 -0
- package/dist/{index-2mCaeKyf.mjs → index-CAFwetLk.mjs} +68 -38
- package/dist/index-Cqx-Raq6.mjs +68 -0
- package/dist/index-D3kI0hDR.cjs +107 -0
- package/dist/index-DA7yINuk.cjs +994 -0
- package/dist/{index-BEOMECtE.cjs → index-LIn6nCcq.cjs} +121 -91
- package/dist/index-Pf2cV9cn.cjs +182 -0
- package/dist/index-SPGPenK5.mjs +158 -0
- package/dist/index-gNTWtSKN.cjs +71 -0
- package/dist/index-qdS1friN.mjs +949 -0
- package/dist/index.cjs +5 -46
- package/dist/index.mjs +5 -46
- package/dist/{install-BPhJppvd.mjs → install-BO_W7VhL.mjs} +37 -37
- package/dist/install-Bu85vlHD.cjs +88 -0
- package/dist/install-ClUUl3yp.mjs +86 -0
- package/dist/{install-BOHrUaFM.cjs → install-Cs5qAPrB.cjs} +38 -38
- package/dist/{installPiTools-DuZ6jZvX.cjs → installPiTools-BKnXjrVu.cjs} +2 -3
- package/dist/{installPiTools-Cj7yU9Fc.mjs → installPiTools-B_CdM5_2.mjs} +1 -2
- package/dist/{installTerminalHooks-Cou3WUf3.cjs → installTerminalHooks-BQZbvxsZ.cjs} +5 -40
- package/dist/{installTerminalHooks-WeznjkuC.mjs → installTerminalHooks-By7gBMEF.mjs} +3 -38
- package/dist/lib.cjs +28 -19
- package/dist/lib.d.cts +12 -2
- package/dist/lib.d.mts +12 -2
- package/dist/lib.mjs +23 -14
- package/dist/lidState-C2dI0FAN.mjs +297 -0
- package/dist/lidState-KHHu1015.cjs +305 -0
- package/dist/limits-C-a7gr04.cjs +43 -0
- package/dist/limits-DIo7rEBR.mjs +36 -0
- package/dist/localHappyAgentAuth-BXiHPXdC.cjs +86 -0
- package/dist/localHappyAgentAuth-DCsetiyG.mjs +82 -0
- package/dist/logger-Bc8-u1w0.cjs +275 -0
- package/dist/logger-fXoNzNuB.mjs +271 -0
- package/dist/loginShellEnv-BkuYtExZ.cjs +182 -0
- package/dist/loginShellEnv-Dw8M7tkI.mjs +167 -0
- package/dist/machineMetadata-BHjehxJY.mjs +38 -0
- package/dist/machineMetadata-BibDMFVx.cjs +41 -0
- package/dist/main-BktM4A1K.mjs +939 -0
- package/dist/main-CLaX-t-b.cjs +941 -0
- package/dist/manager-BQ4flvQZ.mjs +101 -0
- package/dist/manager-Cly8xVIR.cjs +105 -0
- package/dist/{mcp-Dy3f_K0h.mjs → mcp-CeUd9KDr.mjs} +27 -33
- package/dist/{mcp-CPYbtsYG.cjs → mcp-GBfE70nk.cjs} +42 -48
- package/dist/messageBuffer-BWlGgR3A.mjs +71 -0
- package/dist/messageBuffer-fJMH6uY8.cjs +73 -0
- package/dist/mirrorProtocol-BNLtoWjO.mjs +170 -0
- package/dist/mirrorProtocol-BUtmg1ws.cjs +186 -0
- package/dist/oneShotPrompts-CL0dip9C.cjs +16 -0
- package/dist/oneShotPrompts-DT4p6RNd.mjs +12 -0
- package/dist/package-Cl5BEP5x.cjs +173 -0
- package/dist/package-uOg9SCKi.mjs +171 -0
- package/dist/path-B7zW-WwE.cjs +18 -0
- package/dist/path-D2wdaNSk.mjs +15 -0
- package/dist/peerTools-CIeiy9wn.cjs +283 -0
- package/dist/peerTools-Dz3_7Bkk.mjs +272 -0
- package/dist/permissionMode-CH4FoZfU.mjs +80 -0
- package/dist/permissionMode-CrV-XuMs.cjs +87 -0
- package/dist/persistence-CBNMzSa8.cjs +414 -0
- package/dist/persistence-oET5n61f.mjs +372 -0
- package/dist/piExtension.mjs +2 -1
- package/dist/piRunnerArgs-Bf7RUF__.cjs +66 -0
- package/dist/piRunnerArgs-Dk1ncwHF.mjs +59 -0
- package/dist/{piRuntime-NtF0YqjH.cjs → piRuntime-B_6TE9Eb.cjs} +4 -4
- package/dist/{piRuntime-kLZNpAAl.mjs → piRuntime-BwRdhK_N.mjs} +2 -2
- package/dist/{piTerminal-B0fEOV_2.mjs → piTerminal-Bap3R8Re.mjs} +32 -35
- package/dist/{piTerminal-9J0GAKzb.cjs → piTerminal-CagmEoez.cjs} +32 -35
- package/dist/previewPath-B0rBdhy1.cjs +83 -0
- package/dist/previewPath-CXN4Vag0.mjs +81 -0
- package/dist/projectPath-BTBIMB57.mjs +10 -0
- package/dist/projectPath-ChLhdOyt.cjs +13 -0
- package/dist/registerCommonHandlers-BjSV2Skz.cjs +538 -0
- package/dist/registerCommonHandlers-CrgvJsOy.mjs +536 -0
- package/dist/registerKillSessionHandler-6TC2S3lf.cjs +366 -0
- package/dist/registerKillSessionHandler-Cbc8Rgtd.mjs +363 -0
- package/dist/remoteSessionClient-BNx78NLb.cjs +634 -0
- package/dist/remoteSessionClient-CO7qOjR0.mjs +612 -0
- package/dist/resources-BdFBQi8r.mjs +117 -0
- package/dist/resources-JDPugcDq.cjs +120 -0
- package/dist/run-2l5vSt2h.mjs +5743 -0
- package/dist/run-D5xAEWSB.cjs +5766 -0
- package/dist/runClaude-BX6ixjtW.cjs +894 -0
- package/dist/runClaude-BgN6xo05.mjs +892 -0
- package/dist/runClaudeDeps-Bp20MScE.cjs +4168 -0
- package/dist/runClaudeDeps-COBBhD9o.mjs +4129 -0
- package/dist/{runGemini-F-mqx3_K.cjs → runGemini-CSMPkt0p.cjs} +202 -175
- package/dist/{runGemini-DV6Ouadt.mjs → runGemini-Cc2jq-uh.mjs} +58 -31
- package/dist/{runOpenClaw-D7MlPS5n.mjs → runOpenClaw-CIlCwdW2.mjs} +31 -32
- package/dist/{runOpenClaw-Qqo9j63M.cjs → runOpenClaw-YBwua4Rf.cjs} +64 -65
- package/dist/sandbox-C4gXLP1p.cjs +187 -0
- package/dist/sandbox-CNkwOtHI.mjs +180 -0
- package/dist/selfCheck-CU8xSDsl.cjs +87 -0
- package/dist/selfCheck-hJ6PCh7v.mjs +84 -0
- package/dist/{send-CLhYXNgy.mjs → send-CGHcKZ-w.mjs} +12 -5
- package/dist/{send-4qJTCAYW.cjs → send-DY9Nr-x4.cjs} +16 -9
- package/dist/server-II51Mimf.cjs +407 -0
- package/dist/server-m2b5pamZ.mjs +404 -0
- package/dist/sessionLock-7ePAYDOg.cjs +205 -0
- package/dist/sessionLock-Cw6FmbMv.mjs +197 -0
- package/dist/sessionModeFile-BVCV5f7E.cjs +36 -0
- package/dist/sessionModeFile-CDmDyRkD.mjs +32 -0
- package/dist/sessionOps-C_f1wKOr.mjs +760 -0
- package/dist/sessionOps-DJdExmBy.cjs +783 -0
- package/dist/sessionScanner-CaAHLyNV.mjs +206 -0
- package/dist/sessionScanner-D1goKdd3.cjs +209 -0
- package/dist/{sessions-Bh1pyddi.cjs → sessions-DGs6ALNo.cjs} +37 -28
- package/dist/{sessions-CzIH2rGp.mjs → sessions-DnvmWUel.mjs} +17 -8
- package/dist/setupOfflineReconnection-CVViqZft.mjs +72 -0
- package/dist/setupOfflineReconnection-R7XuR_sj.cjs +74 -0
- package/dist/smallFastModel-BLNgMrwR.mjs +18 -0
- package/dist/smallFastModel-D_uxGMo3.cjs +21 -0
- package/dist/{spawn-CmFOSVdW.cjs → spawn-CXTH7qg1.cjs} +61 -65
- package/dist/{spawn-CPIWlPOM.mjs → spawn-DNYSvFtC.mjs} +35 -40
- package/dist/spawnAgents-BGQiEF-w.cjs +52 -0
- package/dist/spawnAgents-DZzZ9jMI.mjs +45 -0
- package/dist/spawnHappyCLI-BhYj84rv.cjs +66 -0
- package/dist/spawnHappyCLI-cqWQbwsb.mjs +64 -0
- package/dist/specialCommands-BSqhYg5X.mjs +52 -0
- package/dist/specialCommands-DSsTeRej.cjs +54 -0
- package/dist/startFileWatcher-CKKx-8ZO.cjs +71 -0
- package/dist/startFileWatcher-CdegMbJj.mjs +69 -0
- package/dist/startupPlan-BLMbfQIH.cjs +12 -0
- package/dist/startupPlan-DFMyNgAs.mjs +10 -0
- package/dist/streamRelay-BiKw59Cc.cjs +233 -0
- package/dist/streamRelay-FPVbHpbM.mjs +231 -0
- package/dist/sync-CVk4QERO.cjs +71 -0
- package/dist/sync-CxD-w_40.mjs +69 -0
- package/dist/systemPrompt-BygJcmbi.cjs +97 -0
- package/dist/systemPrompt-DmtypUc7.mjs +94 -0
- package/dist/{teams-CEahj4cm.mjs → teams-BOC6nIPL.mjs} +9 -40
- package/dist/{teams-CB1R9-Z9.cjs → teams-BsvpOBfn.cjs} +14 -45
- package/dist/template-BaHAmH2K.cjs +129 -0
- package/dist/template-CiOPa2rd.mjs +121 -0
- package/dist/{terminalTitleSuggest-DKgX3osW.mjs → terminalTitleSuggest-CeKsX_V6.mjs} +1 -9
- package/dist/{terminalTitleSuggest-Dji8I0Jy.cjs → terminalTitleSuggest-DhvRFX3H.cjs} +0 -10
- package/dist/terminals-B_bfC9c2.cjs +250 -0
- package/dist/terminals-Dlg0x3nY.mjs +235 -0
- package/dist/time-BZNdNiIV.mjs +38 -0
- package/dist/time-CNRE4ChD.cjs +42 -0
- package/dist/titleGenerator-CFRhU-xq.cjs +172 -0
- package/dist/titleGenerator-ox6ptCsp.mjs +166 -0
- package/dist/tmuxSocket-B8Yx20sT.mjs +19 -0
- package/dist/tmuxSocket-D-Xt6Vn-.cjs +24 -0
- package/dist/{todo-DqyRI4wP.cjs → todo-B-KB7oAB.cjs} +15 -12
- package/dist/{todo-Cknp5D4U.mjs → todo-C5KBVbUw.mjs} +11 -8
- package/dist/tools-BZabNIid.mjs +177 -0
- package/dist/tools-BmQQUATY.mjs +60 -0
- package/dist/tools-CsSovyNp.cjs +180 -0
- package/dist/tools-lMDra4Pv.cjs +63 -0
- package/dist/trimIdent-4gvk9Wk6.cjs +22 -0
- package/dist/trimIdent-BAjmv_TG.mjs +20 -0
- package/dist/types-CRS-srZK.cjs +66 -0
- package/dist/types-CkqAACXx.mjs +64 -0
- package/dist/uninstall-B1WLtC1d.mjs +47 -0
- package/dist/uninstall-fvA5aWpU.cjs +49 -0
- package/package.json +7 -7
- package/scripts/session_hook_forwarder.cjs +9 -2
- package/dist/agentGuidance-BRDN1NoZ.cjs +0 -2217
- package/dist/agentGuidance-KgvYuF3R.mjs +0 -2145
- package/dist/index-BF6WfgV5.mjs +0 -19624
- package/dist/index-C-JazrMB.mjs +0 -52
- package/dist/index-blDSadUR.cjs +0 -58
- package/dist/index-rH3DrQ5B.cjs +0 -19688
- package/dist/limits-BH5CV5vR.cjs +0 -2683
- package/dist/limits-CjRj8IX5.mjs +0 -2558
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('node:fs/promises');
|
|
4
|
+
var node_fs = require('node:fs');
|
|
5
|
+
var configuration = require('./configuration-v9f8LM9T.cjs');
|
|
6
|
+
var z = require('zod');
|
|
7
|
+
var authRelay = require('./authRelay-BdYkC1Po.cjs');
|
|
8
|
+
var logger = require('./logger-Bc8-u1w0.cjs');
|
|
9
|
+
require('node:os');
|
|
10
|
+
require('node:path');
|
|
11
|
+
require('./package-Cl5BEP5x.cjs');
|
|
12
|
+
require('node:crypto');
|
|
13
|
+
require('tweetnacl');
|
|
14
|
+
require('chalk');
|
|
15
|
+
require('node:util');
|
|
16
|
+
|
|
17
|
+
function _interopNamespaceDefault(e) {
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n.default = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
35
|
+
|
|
36
|
+
const SandboxConfigSchema = z__namespace.object({
|
|
37
|
+
enabled: z__namespace.boolean().default(false),
|
|
38
|
+
workspaceRoot: z__namespace.string().optional(),
|
|
39
|
+
sessionIsolation: z__namespace.enum(["strict", "workspace", "custom"]).default("workspace"),
|
|
40
|
+
customWritePaths: z__namespace.array(z__namespace.string()).default([]),
|
|
41
|
+
denyReadPaths: z__namespace.array(z__namespace.string()).default(["~/.ssh", "~/.aws", "~/.gnupg"]),
|
|
42
|
+
extraWritePaths: z__namespace.array(z__namespace.string()).default(["/tmp"]),
|
|
43
|
+
denyWritePaths: z__namespace.array(z__namespace.string()).default([".env"]),
|
|
44
|
+
networkMode: z__namespace.enum(["blocked", "allowed", "custom"]).default("allowed"),
|
|
45
|
+
allowedDomains: z__namespace.array(z__namespace.string()).default([]),
|
|
46
|
+
deniedDomains: z__namespace.array(z__namespace.string()).default([]),
|
|
47
|
+
allowLocalBinding: z__namespace.boolean().default(true)
|
|
48
|
+
});
|
|
49
|
+
const SUPPORTED_SCHEMA_VERSION = 2;
|
|
50
|
+
const defaultSettings = {
|
|
51
|
+
schemaVersion: SUPPORTED_SCHEMA_VERSION,
|
|
52
|
+
onboardingCompleted: false,
|
|
53
|
+
sandboxConfig: void 0
|
|
54
|
+
};
|
|
55
|
+
function migrateSettings(raw, fromVersion) {
|
|
56
|
+
let migrated = { ...raw };
|
|
57
|
+
return migrated;
|
|
58
|
+
}
|
|
59
|
+
async function readSettingsOutcome() {
|
|
60
|
+
if (!node_fs.existsSync(configuration.configuration.settingsFile)) {
|
|
61
|
+
return { kind: "absent" };
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return { kind: "ok", settings: await parseSettingsFile() };
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return { kind: "unreadable", error: error?.message ?? String(error) };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function readSettings() {
|
|
70
|
+
const outcome = await readSettingsOutcome();
|
|
71
|
+
if (outcome.kind === "ok") return outcome.settings;
|
|
72
|
+
if (outcome.kind === "unreadable") {
|
|
73
|
+
logger.logger.warn(`Failed to read settings: ${outcome.error}`);
|
|
74
|
+
}
|
|
75
|
+
return { ...defaultSettings };
|
|
76
|
+
}
|
|
77
|
+
async function parseSettingsFile() {
|
|
78
|
+
const content = await promises.readFile(configuration.configuration.settingsFile, "utf8");
|
|
79
|
+
const raw = JSON.parse(content);
|
|
80
|
+
const schemaVersion = raw.schemaVersion ?? 1;
|
|
81
|
+
if (schemaVersion > SUPPORTED_SCHEMA_VERSION) {
|
|
82
|
+
logger.logger.warn(
|
|
83
|
+
`\u26A0\uFE0F Settings schema v${schemaVersion} > supported v${SUPPORTED_SCHEMA_VERSION}. Update happy-cli for full functionality.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const migrated = migrateSettings(raw);
|
|
87
|
+
if (migrated.sandboxConfig !== void 0) {
|
|
88
|
+
try {
|
|
89
|
+
migrated.sandboxConfig = SandboxConfigSchema.parse(migrated.sandboxConfig);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logger.logger.warn(`\u26A0\uFE0F Invalid sandbox config - skipping. Error: ${error.message}`);
|
|
92
|
+
migrated.sandboxConfig = void 0;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { ...defaultSettings, ...migrated };
|
|
96
|
+
}
|
|
97
|
+
async function writeSettings(settings) {
|
|
98
|
+
await configuration.ensurePrivateDirectory(configuration.configuration.happyHomeDir);
|
|
99
|
+
const settingsWithVersion = {
|
|
100
|
+
...settings,
|
|
101
|
+
schemaVersion: settings.schemaVersion ?? SUPPORTED_SCHEMA_VERSION
|
|
102
|
+
};
|
|
103
|
+
await configuration.writePrivateFile(configuration.configuration.settingsFile, JSON.stringify(settingsWithVersion, null, 2));
|
|
104
|
+
}
|
|
105
|
+
async function updateSettings(updater) {
|
|
106
|
+
const LOCK_RETRY_INTERVAL_MS = 100;
|
|
107
|
+
const MAX_LOCK_ATTEMPTS = 50;
|
|
108
|
+
const STALE_LOCK_TIMEOUT_MS = 1e4;
|
|
109
|
+
const lockFile = configuration.configuration.settingsFile + ".lock";
|
|
110
|
+
const tmpFile = configuration.configuration.settingsFile + ".tmp";
|
|
111
|
+
let fileHandle;
|
|
112
|
+
let attempts = 0;
|
|
113
|
+
while (attempts < MAX_LOCK_ATTEMPTS) {
|
|
114
|
+
try {
|
|
115
|
+
fileHandle = await promises.open(lockFile, node_fs.constants.O_CREAT | node_fs.constants.O_EXCL | node_fs.constants.O_WRONLY, configuration.PRIVATE_FILE_MODE);
|
|
116
|
+
break;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (err.code === "EEXIST") {
|
|
119
|
+
attempts++;
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_INTERVAL_MS));
|
|
121
|
+
try {
|
|
122
|
+
const stats = await promises.stat(lockFile);
|
|
123
|
+
if (Date.now() - stats.mtimeMs > STALE_LOCK_TIMEOUT_MS) {
|
|
124
|
+
await promises.unlink(lockFile).catch(() => {
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!fileHandle) {
|
|
135
|
+
throw new Error(`Failed to acquire settings lock after ${MAX_LOCK_ATTEMPTS * LOCK_RETRY_INTERVAL_MS / 1e3} seconds`);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const outcome = await readSettingsOutcome();
|
|
139
|
+
if (outcome.kind === "unreadable") {
|
|
140
|
+
throw new Error(
|
|
141
|
+
`Settings file ${configuration.configuration.settingsFile} exists but could not be read (${outcome.error}). Refusing to overwrite it \u2014 fix or remove the file (a removed file is recreated with defaults).`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const current = outcome.kind === "ok" ? outcome.settings : { ...defaultSettings };
|
|
145
|
+
const updated = await updater(current);
|
|
146
|
+
await configuration.ensurePrivateDirectory(configuration.configuration.happyHomeDir);
|
|
147
|
+
await configuration.writePrivateFile(tmpFile, JSON.stringify(updated, null, 2));
|
|
148
|
+
await promises.rename(tmpFile, configuration.configuration.settingsFile);
|
|
149
|
+
await configuration.hardenPrivateFile(configuration.configuration.settingsFile);
|
|
150
|
+
return updated;
|
|
151
|
+
} finally {
|
|
152
|
+
await fileHandle.close();
|
|
153
|
+
await promises.unlink(lockFile).catch(() => {
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const credentialsSchema = z__namespace.object({
|
|
158
|
+
token: z__namespace.string(),
|
|
159
|
+
authServerUrl: z__namespace.string().optional(),
|
|
160
|
+
secret: z__namespace.string().base64().nullish(),
|
|
161
|
+
// Legacy
|
|
162
|
+
encryption: z__namespace.object({
|
|
163
|
+
publicKey: z__namespace.string().base64(),
|
|
164
|
+
machineKey: z__namespace.string().base64()
|
|
165
|
+
}).nullish()
|
|
166
|
+
});
|
|
167
|
+
async function readCredentials() {
|
|
168
|
+
if (!node_fs.existsSync(configuration.configuration.privateKeyFile)) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
const keyBase64 = await promises.readFile(configuration.configuration.privateKeyFile, "utf8");
|
|
173
|
+
const credentials = credentialsSchema.parse(JSON.parse(keyBase64));
|
|
174
|
+
if (credentials.secret) {
|
|
175
|
+
return {
|
|
176
|
+
token: credentials.token,
|
|
177
|
+
authServerUrl: credentials.authServerUrl,
|
|
178
|
+
encryption: {
|
|
179
|
+
type: "legacy",
|
|
180
|
+
secret: new Uint8Array(Buffer.from(credentials.secret, "base64"))
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
} else if (credentials.encryption) {
|
|
184
|
+
return {
|
|
185
|
+
token: credentials.token,
|
|
186
|
+
authServerUrl: credentials.authServerUrl,
|
|
187
|
+
encryption: {
|
|
188
|
+
type: "dataKey",
|
|
189
|
+
publicKey: new Uint8Array(Buffer.from(credentials.encryption.publicKey, "base64")),
|
|
190
|
+
machineKey: new Uint8Array(Buffer.from(credentials.encryption.machineKey, "base64"))
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
async function readCredentialsForConfiguredRelay() {
|
|
200
|
+
const credentials = await readCredentials();
|
|
201
|
+
if (!credentials) return null;
|
|
202
|
+
const relayProblem = authRelay.credentialRelayProblem(credentials.authServerUrl, configuration.configuration.serverUrl);
|
|
203
|
+
if (relayProblem) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
`${relayProblem} Use a separate HAPPY_HOME_DIR for this relay, or run \`very-happy auth login --force\` before making relay requests.`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return credentials;
|
|
209
|
+
}
|
|
210
|
+
async function writeCredentialsLegacy(credentials) {
|
|
211
|
+
await configuration.ensurePrivateDirectory(configuration.configuration.happyHomeDir);
|
|
212
|
+
await configuration.writePrivateFile(configuration.configuration.privateKeyFile, JSON.stringify({
|
|
213
|
+
secret: authRelay.encodeBase64(credentials.secret),
|
|
214
|
+
token: credentials.token,
|
|
215
|
+
authServerUrl: configuration.configuration.serverUrl
|
|
216
|
+
}, null, 2));
|
|
217
|
+
}
|
|
218
|
+
async function writeCredentialsDataKey(credentials) {
|
|
219
|
+
await configuration.ensurePrivateDirectory(configuration.configuration.happyHomeDir);
|
|
220
|
+
await configuration.writePrivateFile(configuration.configuration.privateKeyFile, JSON.stringify({
|
|
221
|
+
encryption: { publicKey: authRelay.encodeBase64(credentials.publicKey), machineKey: authRelay.encodeBase64(credentials.machineKey) },
|
|
222
|
+
token: credentials.token,
|
|
223
|
+
authServerUrl: configuration.configuration.serverUrl
|
|
224
|
+
}, null, 2));
|
|
225
|
+
}
|
|
226
|
+
async function clearCredentials() {
|
|
227
|
+
if (node_fs.existsSync(configuration.configuration.privateKeyFile)) {
|
|
228
|
+
await promises.unlink(configuration.configuration.privateKeyFile);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async function clearMachineId() {
|
|
232
|
+
await updateSettings((settings) => ({
|
|
233
|
+
...settings,
|
|
234
|
+
machineId: void 0
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
async function readDaemonState() {
|
|
238
|
+
try {
|
|
239
|
+
if (!node_fs.existsSync(configuration.configuration.daemonStateFile)) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
const content = await promises.readFile(configuration.configuration.daemonStateFile, "utf-8");
|
|
243
|
+
return JSON.parse(content);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error(`[PERSISTENCE] Daemon state file corrupted: ${configuration.configuration.daemonStateFile}`, error);
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function writeDaemonState(state) {
|
|
250
|
+
configuration.writePrivateFileSync(configuration.configuration.daemonStateFile, JSON.stringify(state, null, 2));
|
|
251
|
+
}
|
|
252
|
+
async function clearDaemonState() {
|
|
253
|
+
if (node_fs.existsSync(configuration.configuration.daemonStateFile)) {
|
|
254
|
+
await promises.unlink(configuration.configuration.daemonStateFile);
|
|
255
|
+
}
|
|
256
|
+
if (node_fs.existsSync(configuration.configuration.daemonLockFile)) {
|
|
257
|
+
try {
|
|
258
|
+
await promises.unlink(configuration.configuration.daemonLockFile);
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async function acquireDaemonLock(maxAttempts = 5, delayIncrementMs = 200) {
|
|
264
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
265
|
+
try {
|
|
266
|
+
const fileHandle = await promises.open(
|
|
267
|
+
configuration.configuration.daemonLockFile,
|
|
268
|
+
node_fs.constants.O_CREAT | node_fs.constants.O_EXCL | node_fs.constants.O_WRONLY,
|
|
269
|
+
configuration.PRIVATE_FILE_MODE
|
|
270
|
+
);
|
|
271
|
+
await fileHandle.writeFile(String(process.pid));
|
|
272
|
+
return fileHandle;
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (error.code === "EEXIST") {
|
|
275
|
+
try {
|
|
276
|
+
const lockPid = node_fs.readFileSync(configuration.configuration.daemonLockFile, "utf-8").trim();
|
|
277
|
+
if (lockPid && !isNaN(Number(lockPid))) {
|
|
278
|
+
try {
|
|
279
|
+
process.kill(Number(lockPid), 0);
|
|
280
|
+
} catch {
|
|
281
|
+
node_fs.unlinkSync(configuration.configuration.daemonLockFile);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
} catch {
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (attempt === maxAttempts) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
const delayMs = attempt * delayIncrementMs;
|
|
292
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
async function releaseDaemonLock(lockHandle) {
|
|
298
|
+
try {
|
|
299
|
+
await lockHandle.close();
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
if (node_fs.existsSync(configuration.configuration.daemonLockFile)) {
|
|
304
|
+
node_fs.unlinkSync(configuration.configuration.daemonLockFile);
|
|
305
|
+
}
|
|
306
|
+
} catch {
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const SESSION_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1e3;
|
|
310
|
+
function readPersistedSessions() {
|
|
311
|
+
try {
|
|
312
|
+
if (!node_fs.existsSync(configuration.configuration.sessionsFile)) return {};
|
|
313
|
+
const data = JSON.parse(node_fs.readFileSync(configuration.configuration.sessionsFile, "utf-8"));
|
|
314
|
+
if (!data?.sessions || typeof data.sessions !== "object") return {};
|
|
315
|
+
const now = Date.now();
|
|
316
|
+
const sessions = {};
|
|
317
|
+
for (const [id, session] of Object.entries(data.sessions)) {
|
|
318
|
+
if (now - session.savedAt < SESSION_MAX_AGE_MS) {
|
|
319
|
+
sessions[id] = session;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return sessions;
|
|
323
|
+
} catch {
|
|
324
|
+
return {};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function readTrackedClaudeSessionIds() {
|
|
328
|
+
try {
|
|
329
|
+
if (!node_fs.existsSync(configuration.configuration.sessionsFile)) return [];
|
|
330
|
+
const data = JSON.parse(node_fs.readFileSync(configuration.configuration.sessionsFile, "utf-8"));
|
|
331
|
+
if (!data?.sessions || typeof data.sessions !== "object") return [];
|
|
332
|
+
const ids = /* @__PURE__ */ new Set();
|
|
333
|
+
for (const session of Object.values(data.sessions)) {
|
|
334
|
+
const metadata = (session ?? {}).metadata;
|
|
335
|
+
for (const id of [metadata?.claudeSessionId, metadata?.importedFromClaudeSessionId]) {
|
|
336
|
+
if (typeof id === "string" && id.length > 0) ids.add(id.toLowerCase());
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return [...ids];
|
|
340
|
+
} catch {
|
|
341
|
+
return [];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function readTrackedCodexThreadIds() {
|
|
345
|
+
try {
|
|
346
|
+
if (!node_fs.existsSync(configuration.configuration.sessionsFile)) return [];
|
|
347
|
+
const data = JSON.parse(node_fs.readFileSync(configuration.configuration.sessionsFile, "utf-8"));
|
|
348
|
+
if (!data?.sessions || typeof data.sessions !== "object") return [];
|
|
349
|
+
const ids = /* @__PURE__ */ new Set();
|
|
350
|
+
for (const session of Object.values(data.sessions)) {
|
|
351
|
+
const metadata = (session ?? {}).metadata;
|
|
352
|
+
for (const id of [metadata?.codexThreadId, metadata?.importedFromCodexThreadId]) {
|
|
353
|
+
if (typeof id === "string" && id.length > 0) ids.add(id.toLowerCase());
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return [...ids];
|
|
357
|
+
} catch {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function persistSession(sessionId, session) {
|
|
362
|
+
try {
|
|
363
|
+
const existing = readPersistedSessions();
|
|
364
|
+
existing[sessionId] = session;
|
|
365
|
+
const tmpFile = configuration.configuration.sessionsFile + ".tmp";
|
|
366
|
+
configuration.writePrivateFileSync(tmpFile, JSON.stringify({ sessions: existing }, null, 2));
|
|
367
|
+
node_fs.renameSync(tmpFile, configuration.configuration.sessionsFile);
|
|
368
|
+
configuration.hardenPrivateFileSync(configuration.configuration.sessionsFile);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
logger.logger.debug(`[PERSISTENCE] Failed to persist session ${sessionId}:`, error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function deletePersistedSessions(sessionIds) {
|
|
374
|
+
try {
|
|
375
|
+
const existing = readPersistedSessions();
|
|
376
|
+
let changed = false;
|
|
377
|
+
for (const id of sessionIds) {
|
|
378
|
+
if (id in existing) {
|
|
379
|
+
delete existing[id];
|
|
380
|
+
changed = true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (!changed) return;
|
|
384
|
+
const tmpFile = configuration.configuration.sessionsFile + ".tmp";
|
|
385
|
+
configuration.writePrivateFileSync(tmpFile, JSON.stringify({ sessions: existing }, null, 2));
|
|
386
|
+
node_fs.renameSync(tmpFile, configuration.configuration.sessionsFile);
|
|
387
|
+
configuration.hardenPrivateFileSync(configuration.configuration.sessionsFile);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
logger.logger.debug(`[PERSISTENCE] Failed to delete persisted sessions:`, error);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
exports.SUPPORTED_SCHEMA_VERSION = SUPPORTED_SCHEMA_VERSION;
|
|
394
|
+
exports.SandboxConfigSchema = SandboxConfigSchema;
|
|
395
|
+
exports.acquireDaemonLock = acquireDaemonLock;
|
|
396
|
+
exports.clearCredentials = clearCredentials;
|
|
397
|
+
exports.clearDaemonState = clearDaemonState;
|
|
398
|
+
exports.clearMachineId = clearMachineId;
|
|
399
|
+
exports.deletePersistedSessions = deletePersistedSessions;
|
|
400
|
+
exports.persistSession = persistSession;
|
|
401
|
+
exports.readCredentials = readCredentials;
|
|
402
|
+
exports.readCredentialsForConfiguredRelay = readCredentialsForConfiguredRelay;
|
|
403
|
+
exports.readDaemonState = readDaemonState;
|
|
404
|
+
exports.readPersistedSessions = readPersistedSessions;
|
|
405
|
+
exports.readSettings = readSettings;
|
|
406
|
+
exports.readSettingsOutcome = readSettingsOutcome;
|
|
407
|
+
exports.readTrackedClaudeSessionIds = readTrackedClaudeSessionIds;
|
|
408
|
+
exports.readTrackedCodexThreadIds = readTrackedCodexThreadIds;
|
|
409
|
+
exports.releaseDaemonLock = releaseDaemonLock;
|
|
410
|
+
exports.updateSettings = updateSettings;
|
|
411
|
+
exports.writeCredentialsDataKey = writeCredentialsDataKey;
|
|
412
|
+
exports.writeCredentialsLegacy = writeCredentialsLegacy;
|
|
413
|
+
exports.writeDaemonState = writeDaemonState;
|
|
414
|
+
exports.writeSettings = writeSettings;
|