hyperclaw 5.0.0 → 5.0.2

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.
Files changed (199) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +449 -99
  3. package/dist/a2ui-protocol-Gzm29Gaw.js +75 -0
  4. package/dist/agents-routing-Biy5ew4a.js +4 -0
  5. package/dist/agents-routing-CL3HQNoM.js +327 -0
  6. package/dist/api-keys-guide-CGn5BSF7.js +149 -0
  7. package/dist/api-keys-guide-ChbThbPj.js +149 -0
  8. package/dist/audit-BJohI_vC.js +441 -0
  9. package/dist/audit-NPIMmOSq.js +441 -0
  10. package/dist/bounty-tools-BUqUKjt0.js +211 -0
  11. package/dist/bounty-tools-CY_i91DU.js +211 -0
  12. package/dist/browser-tools-CxJY6pAn.js +5 -0
  13. package/dist/browser-tools-JZ9ji6AW.js +179 -0
  14. package/dist/chat-qVuqhlPu.js +258 -0
  15. package/dist/claw-tasks-B-8RRMdq.js +80 -0
  16. package/dist/claw-tasks-Cyzdbhz_.js +80 -0
  17. package/dist/connector-1x1rCBHz.js +162 -0
  18. package/dist/connector-B4jeCULG.js +305 -0
  19. package/dist/connector-B7qngfkT.js +286 -0
  20. package/dist/connector-B8BK0GBo.js +531 -0
  21. package/dist/connector-BE9eJs8-.js +182 -0
  22. package/dist/connector-BEe-DTGQ.js +189 -0
  23. package/dist/connector-BU7p5ZgB.js +167 -0
  24. package/dist/connector-BUzzq7Ij.js +568 -0
  25. package/dist/connector-BpDqLgnW.js +419 -0
  26. package/dist/connector-BpW88ut2.js +189 -0
  27. package/dist/connector-Bxv-gy8U.js +167 -0
  28. package/dist/connector-Bz14zcJv.js +213 -0
  29. package/dist/connector-C1zP5-5q.js +85 -0
  30. package/dist/connector-CAcpcovF.js +498 -0
  31. package/dist/connector-CJgVjS58.js +181 -0
  32. package/dist/connector-Cf53D6qV.js +425 -0
  33. package/dist/connector-CyHmlbNz.js +508 -0
  34. package/dist/connector-D22mJGVu.js +340 -0
  35. package/dist/connector-D6RtMmlL.js +225 -0
  36. package/dist/connector-D9EnT8A4.js +280 -0
  37. package/dist/connector-DNDwIh37.js +239 -0
  38. package/dist/connector-Di27MeO4.js +350 -0
  39. package/dist/connector-Do0BPiHt.js +194 -0
  40. package/dist/connector-DvLwOfJy.js +192 -0
  41. package/dist/connector-DvU83NSq.js +181 -0
  42. package/dist/connector-DxskpDc_.js +173 -0
  43. package/dist/connector-byy3eISx.js +552 -0
  44. package/dist/connector-vV89hsyd.js +218 -0
  45. package/dist/cost-tracker-Ca1UPZ33.js +103 -0
  46. package/dist/cost-tracker-fnaj_6M9.js +103 -0
  47. package/dist/credentials-store-BxijEirw.js +77 -0
  48. package/dist/credentials-store-CA8UtK0T.js +77 -0
  49. package/dist/credentials-store-CPkVO6-z.js +4 -0
  50. package/dist/credentials-store-Cm7DH-kh.js +4 -0
  51. package/dist/cron-tasks-L0mz1yyU.js +82 -0
  52. package/dist/cron-tasks-_pqQCmxc.js +82 -0
  53. package/dist/daemon-7ViroziB.js +5 -0
  54. package/dist/daemon-BfyKmZhr.js +318 -0
  55. package/dist/daemon-CNyunwkR.js +5 -0
  56. package/dist/daemon-CindY8OK.js +318 -0
  57. package/dist/delivery-DVHmv1IR.js +4 -0
  58. package/dist/delivery-DgiZcJBp.js +4 -0
  59. package/dist/delivery-DpMX0Yyc.js +95 -0
  60. package/dist/delivery-otAU4alM.js +95 -0
  61. package/dist/destructive-gate-CA0DtA5K.js +101 -0
  62. package/dist/destructive-gate-DZt71UZR.js +101 -0
  63. package/dist/developer-keys-Cnd1kswV.js +127 -0
  64. package/dist/developer-keys-DENo3ZA6.js +8 -0
  65. package/dist/doctor-Dgjoc3DG.js +230 -0
  66. package/dist/doctor-RwsOhtAl.js +6 -0
  67. package/dist/engine-B0kLfRL0.js +256 -0
  68. package/dist/engine-BJUpRUOv.js +7 -0
  69. package/dist/engine-D_VeoZHw.js +305 -0
  70. package/dist/engine-JjRnhlsE.js +7 -0
  71. package/dist/env-resolve-17ekEU6p.js +10 -0
  72. package/dist/env-resolve-BFJXWl94.js +115 -0
  73. package/dist/env-resolve-Z2XF6leB.js +115 -0
  74. package/dist/env-resolve-bDYssfih.js +10 -0
  75. package/dist/extraction-tools-DbxnxIco.js +5 -0
  76. package/dist/extraction-tools-Dg7AHS35.js +91 -0
  77. package/dist/form_data-CGAy4HE0.js +8657 -0
  78. package/dist/gmail-watch-setup-C3uSWznp.js +40 -0
  79. package/dist/health-DUjluWHQ.js +6 -0
  80. package/dist/health-DVfkpUQW.js +152 -0
  81. package/dist/heartbeat-engine-CrgL4mrP.js +83 -0
  82. package/dist/heartbeat-engine-Ut6pXBD6.js +83 -0
  83. package/dist/hub-9LaKnLjY.js +6 -0
  84. package/dist/hub-BO6bj8Yj.js +515 -0
  85. package/dist/hub-Bu52YZqW.js +6 -0
  86. package/dist/hub-CfwUz9YW.js +515 -0
  87. package/dist/hyperclawbot-BrcoYLOp.js +505 -0
  88. package/dist/hyperclawbot-CBiDSKsa.js +505 -0
  89. package/dist/inference-0mlFQqIm.js +922 -0
  90. package/dist/inference-DHR82Gh7.js +6 -0
  91. package/dist/inference-DhA8jpfH.js +2692 -0
  92. package/dist/inference-SzqFe_nk.js +6 -0
  93. package/dist/knowledge-graph-BrYpSgxW.js +131 -0
  94. package/dist/knowledge-graph-DE5lSF02.js +131 -0
  95. package/dist/loader-9JqY6Nlq.js +4 -0
  96. package/dist/loader-BkDi8MD9.js +400 -0
  97. package/dist/loader-Cjdd1kw4.js +400 -0
  98. package/dist/loader-DI2qDRPC.js +4 -0
  99. package/dist/logger-Cp8wC7F8.js +83 -0
  100. package/dist/logger-DCT2l9GV.js +83 -0
  101. package/dist/manager-3cq3DydI.js +4 -0
  102. package/dist/manager-B2Gls5RG.js +218 -0
  103. package/dist/manager-BUrFrPuq.js +117 -0
  104. package/dist/manager-Bi9UYyVR.js +105 -0
  105. package/dist/manager-Biz9ixWJ.js +40 -0
  106. package/dist/manager-CBUHJiY7.js +6 -0
  107. package/dist/manager-CVLLaKmq.js +218 -0
  108. package/dist/manager-CWNSML5D.js +117 -0
  109. package/dist/manager-SJe9gt-q.js +4 -0
  110. package/dist/mcp-CUoTCMw-.js +139 -0
  111. package/dist/mcp-loader-BIz-450x.js +94 -0
  112. package/dist/mcp-loader-CvxRDtPC.js +94 -0
  113. package/dist/memory-OL77OMOr.js +270 -0
  114. package/dist/memory-auto-CpQHZlEJ.js +306 -0
  115. package/dist/memory-auto-D-L2q21G.js +306 -0
  116. package/dist/memory-auto-DTcy5VBy.js +5 -0
  117. package/dist/memory-auto-Z6LCf-iK.js +5 -0
  118. package/dist/memory-gUi4VaIf.js +4 -0
  119. package/dist/memory-integration-B8RSN4pr.js +91 -0
  120. package/dist/memory-integration-g2vxwgoE.js +91 -0
  121. package/dist/moltbook-B-40gQOL.js +81 -0
  122. package/dist/moltbook-Cl8cQfxJ.js +81 -0
  123. package/dist/node-TWxRm84k.js +222 -0
  124. package/dist/nodes-registry-C9dCFwjh.js +52 -0
  125. package/dist/nodes-registry-DKRtsbNg.js +52 -0
  126. package/dist/oauth-flow-CeaaGAz0.js +150 -0
  127. package/dist/oauth-flow-JCfporKq.js +150 -0
  128. package/dist/oauth-provider-4R0EJlsT.js +110 -0
  129. package/dist/oauth-provider-B4dzn56l.js +110 -0
  130. package/dist/observability-CDZmeHfa.js +89 -0
  131. package/dist/observability-nZ3CBIxG.js +89 -0
  132. package/dist/onboard-BBBWcfhp.js +10 -0
  133. package/dist/onboard-BVOtKQdh.js +3641 -0
  134. package/dist/onboard-Bw28IRQ3.js +4070 -0
  135. package/dist/onboard-CGNIw27w.js +11 -0
  136. package/dist/orchestrator-BovkM63z.js +6 -0
  137. package/dist/orchestrator-CcKx1Ovk.js +189 -0
  138. package/dist/orchestrator-DSbpkP1X.js +189 -0
  139. package/dist/orchestrator-DcFfDLTX.js +6 -0
  140. package/dist/osint-B4_m3VHQ.js +277 -0
  141. package/dist/osint-B6BZKQAD.js +277 -0
  142. package/dist/pairing-B6RArWhD.js +196 -0
  143. package/dist/pairing-BsQ08DLq.js +4 -0
  144. package/dist/pc-access-B0KocJNe.js +819 -0
  145. package/dist/pc-access-DkzmugZ7.js +8 -0
  146. package/dist/pending-approval-BgNjjuI2.js +22 -0
  147. package/dist/pending-approval-C_HkX1QL.js +22 -0
  148. package/dist/providers-DxiamZSL.js +5 -0
  149. package/dist/providers-Dy15rDb7.js +657 -0
  150. package/dist/reminders-store-CzUY0zYx.js +58 -0
  151. package/dist/renderer-ANNfXsHn.js +225 -0
  152. package/dist/rules-BSQwwAYC.js +103 -0
  153. package/dist/run-main.js +142 -132
  154. package/dist/runner-BHRSOPEU.js +1271 -0
  155. package/dist/runner-CJFJUtPm.js +1271 -0
  156. package/dist/sdk/index.js +2 -2
  157. package/dist/sdk/index.mjs +2 -2
  158. package/dist/security--oQObeJO.js +4 -0
  159. package/dist/security-wBOg0TA8.js +73 -0
  160. package/dist/server-Brl_HQUB.js +1255 -0
  161. package/dist/server-CbTTpB5m.js +1255 -0
  162. package/dist/server-DP_bPzvI.js +4 -0
  163. package/dist/server-DhfipkwN.js +4 -0
  164. package/dist/session-store-B09r5HgB.js +5 -0
  165. package/dist/session-store-DCTQIVur.js +113 -0
  166. package/dist/sessions-tools-BdlN6Pb6.js +95 -0
  167. package/dist/sessions-tools-JVLDKSJ_.js +5 -0
  168. package/dist/skill-loader-B5oeliGu.js +7 -0
  169. package/dist/skill-loader-Wf3brNOj.js +160 -0
  170. package/dist/skill-runtime-BGlvly2s.js +102 -0
  171. package/dist/skill-runtime-BXWd-Ktf.js +102 -0
  172. package/dist/skill-runtime-DhL2T76p.js +5 -0
  173. package/dist/skill-runtime-jgklm02e.js +5 -0
  174. package/dist/src-BbPa6Q8p.js +63 -0
  175. package/dist/src-BeXtfkK2.js +458 -0
  176. package/dist/src-Bhybpk1J.js +63 -0
  177. package/dist/src-CGQjRI4N.js +20 -0
  178. package/dist/src-DMJ4-uqk.js +458 -0
  179. package/dist/sub-agent-tools-CmE345s_.js +39 -0
  180. package/dist/sub-agent-tools-DHY-4WWM.js +39 -0
  181. package/dist/theme-D0smfC_l.js +8 -0
  182. package/dist/theme-DajRRZbA.js +180 -0
  183. package/dist/tool-policy-DZvF8xlQ.js +189 -0
  184. package/dist/tool-policy-DgNqFWYn.js +189 -0
  185. package/dist/tts-elevenlabs-C06nUxMK.js +61 -0
  186. package/dist/tts-elevenlabs-JeFaGNJU.js +61 -0
  187. package/dist/update-check-BVEqHhFY.js +83 -0
  188. package/dist/update-check-w4XuxVl7.js +81 -0
  189. package/dist/vision-JOtOS1Br.js +121 -0
  190. package/dist/vision-fky3elEo.js +121 -0
  191. package/dist/vision-tools-C8B3776g.js +5 -0
  192. package/dist/vision-tools-CB28ZCO_.js +5 -0
  193. package/dist/vision-tools-dwn9p4el.js +51 -0
  194. package/dist/vision-tools-vPPwQ-0N.js +51 -0
  195. package/dist/voice-transcription-B6RtplmN.js +138 -0
  196. package/dist/voice-transcription-DBo5hXmu.js +138 -0
  197. package/dist/website-watch-tools-B-jRAeTe.js +139 -0
  198. package/dist/website-watch-tools-BC9xAL67.js +5 -0
  199. package/package.json +1 -1
@@ -0,0 +1,218 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const events = require_chunk.__toESM(require("events"));
4
+ const irc = require_chunk.__toESM(require("irc"));
5
+
6
+ //#region extensions/irc/src/connector.ts
7
+ function resolveEnvConfig(cfg) {
8
+ return {
9
+ server: cfg.server || process.env["IRC_HOST"] || "",
10
+ port: cfg.port ?? (process.env["IRC_PORT"] ? parseInt(process.env["IRC_PORT"], 10) : void 0),
11
+ tls: cfg.tls ?? (process.env["IRC_TLS"] === "true" || process.env["IRC_TLS"] === "1"),
12
+ nick: cfg.nick || process.env["IRC_NICK"] || "hyperclaw-bot",
13
+ username: cfg.username || process.env["IRC_USERNAME"],
14
+ realname: cfg.realname || process.env["IRC_REALNAME"],
15
+ password: cfg.password || process.env["IRC_PASSWORD"],
16
+ channels: cfg.channels?.length ? cfg.channels : process.env["IRC_CHANNELS"]?.split(",").map((c) => c.trim()).filter(Boolean) ?? [],
17
+ nickserv: cfg.nickserv ?? (process.env["IRC_NICKSERV_PASSWORD"] ? {
18
+ enabled: true,
19
+ service: "NickServ",
20
+ password: process.env["IRC_NICKSERV_PASSWORD"],
21
+ registerEmail: process.env["IRC_NICKSERV_REGISTER_EMAIL"]
22
+ } : void 0),
23
+ dmPolicy: cfg.dmPolicy ?? "pairing",
24
+ allowFrom: cfg.allowFrom ?? [],
25
+ groupPolicy: cfg.groupPolicy ?? "allowlist",
26
+ groupAllowFrom: cfg.groupAllowFrom ?? [],
27
+ groups: cfg.groups ?? {},
28
+ dangerouslyAllowNameMatching: cfg.dangerouslyAllowNameMatching ?? false
29
+ };
30
+ }
31
+ /** Match a sender (nick!user@host or bare nick) against an allowFrom entry. */
32
+ function matchSender(sender, pattern, allowBareNick) {
33
+ if (pattern === "*") return true;
34
+ if (pattern.startsWith("id:")) {
35
+ const id = pattern.slice(3);
36
+ return sender === id || sender.startsWith(id + "!");
37
+ }
38
+ if (pattern === sender) return true;
39
+ if (allowBareNick) {
40
+ const nick = sender.split("!")[0];
41
+ return nick === pattern;
42
+ }
43
+ return false;
44
+ }
45
+ function senderAllowed(sender, allowList, allowBareNick) {
46
+ if (!allowList.length) return false;
47
+ return allowList.some((p) => matchSender(sender, p, allowBareNick));
48
+ }
49
+ /** Return the first matching ToolsBySender policy for a sender. */
50
+ function resolveToolsBySender(sender, toolsBySender, allowBareNick) {
51
+ for (const [pattern, policy] of Object.entries(toolsBySender)) {
52
+ const pat = pattern.startsWith("id:") ? pattern : `id:${pattern}`;
53
+ if (matchSender(sender, pat === "id:*" ? "*" : pat, allowBareNick)) return policy;
54
+ }
55
+ return void 0;
56
+ }
57
+ /** Resolve effective tool policy for a sender in a channel. */
58
+ function resolveToolPolicy(sender, channelCfg, allowBareNick) {
59
+ if (!channelCfg) return void 0;
60
+ if (channelCfg.toolsBySender) {
61
+ const byS = resolveToolsBySender(sender, channelCfg.toolsBySender, allowBareNick);
62
+ if (byS) return byS;
63
+ }
64
+ return channelCfg.tools;
65
+ }
66
+ /** Find the best group config for a channel name. */
67
+ function getGroupConfig(channel, groups) {
68
+ return groups[channel] ?? groups["*"];
69
+ }
70
+ var IrcConnector = class extends events.EventEmitter {
71
+ client = null;
72
+ config;
73
+ constructor(rawConfig) {
74
+ super();
75
+ this.config = resolveEnvConfig(rawConfig);
76
+ }
77
+ async connect() {
78
+ return new Promise((resolve, reject) => {
79
+ const cfg = this.config;
80
+ const useTls = cfg.tls ?? false;
81
+ const port = cfg.port ?? (useTls ? 6697 : 6667);
82
+ const channels = (cfg.channels ?? []).map((c) => c.startsWith("#") ? c : `#${c}`);
83
+ this.client = new irc.default.Client(cfg.server, cfg.nick, {
84
+ port,
85
+ secure: useTls,
86
+ channels,
87
+ userName: cfg.username ?? cfg.nick,
88
+ realName: cfg.realname ?? "HyperClaw IRC Bot",
89
+ password: cfg.password,
90
+ autoConnect: true,
91
+ debug: false,
92
+ showErrors: true,
93
+ stripColors: true
94
+ });
95
+ this.client.on("registered", () => {
96
+ console.log(chalk.default.green(` 🦅 IRC: ${cfg.nick} on ${cfg.server}:${port}${useTls ? " (TLS)" : ""} connected`));
97
+ this._handleNickServ();
98
+ this.emit("connected", {
99
+ server: cfg.server,
100
+ nick: cfg.nick,
101
+ port,
102
+ tls: useTls
103
+ });
104
+ resolve();
105
+ });
106
+ this.client.on("error", (err) => {
107
+ console.log(chalk.default.yellow(` ⚠ IRC error: ${err.message}`));
108
+ reject(err);
109
+ });
110
+ this.client.on("message", (from, to, message) => {
111
+ const isChannel = to.startsWith("#");
112
+ if (isChannel) this._handleChannelMessage(from, to, message);
113
+ else this._handleDm(from, message);
114
+ });
115
+ this.client.on("pm", (from, message) => {
116
+ this._handleDm(from, message);
117
+ });
118
+ });
119
+ }
120
+ _handleNickServ() {
121
+ const ns = this.config.nickserv;
122
+ if (!ns?.enabled) return;
123
+ const service = ns.service ?? "NickServ";
124
+ const nsPassword = ns.password ?? process.env["IRC_NICKSERV_PASSWORD"];
125
+ if (ns.register && ns.registerEmail) {
126
+ console.log(chalk.default.gray(` IRC NickServ: attempting REGISTER`));
127
+ this.client.say(service, `REGISTER ${nsPassword} ${ns.registerEmail}`);
128
+ } else if (nsPassword) {
129
+ console.log(chalk.default.gray(` IRC NickServ: identifying`));
130
+ this.client.say(service, `IDENTIFY ${nsPassword}`);
131
+ }
132
+ }
133
+ _handleChannelMessage(from, channel, message) {
134
+ const cfg = this.config;
135
+ const text = message.trim();
136
+ if (!text) return;
137
+ const groupCfg = getGroupConfig(channel, cfg.groups ?? {});
138
+ if (cfg.groupPolicy === "allowlist") {
139
+ const defined = cfg.groups && (cfg.groups[channel] !== void 0 || cfg.groups["*"] !== void 0);
140
+ if (!defined) {
141
+ console.log(chalk.default.gray(` irc: drop channel ${channel} (groupPolicy=allowlist, not in groups)`));
142
+ return;
143
+ }
144
+ }
145
+ const allowBareNick = cfg.dangerouslyAllowNameMatching ?? false;
146
+ const perChannelAllow = groupCfg?.allowFrom ?? [];
147
+ const globalGroupAllow = cfg.groupAllowFrom ?? [];
148
+ const effectiveAllow = perChannelAllow.length ? perChannelAllow : globalGroupAllow;
149
+ if (effectiveAllow.length && !senderAllowed(from, effectiveAllow, allowBareNick)) {
150
+ console.log(chalk.default.gray(` irc: drop group sender ${from} (policy=allowlist)`));
151
+ return;
152
+ }
153
+ const requireMention = groupCfg?.requireMention ?? true;
154
+ if (requireMention) {
155
+ const mentionPatterns = [
156
+ cfg.nick,
157
+ `${cfg.nick}:`,
158
+ `@${cfg.nick}`,
159
+ `${cfg.nick},`
160
+ ];
161
+ const mentioned = mentionPatterns.some((p) => text.toLowerCase().startsWith(p.toLowerCase()));
162
+ if (!mentioned) {
163
+ console.log(chalk.default.gray(` irc: drop channel ${channel} (missing-mention)`));
164
+ return;
165
+ }
166
+ }
167
+ const toolPolicy = resolveToolPolicy(from, groupCfg, allowBareNick);
168
+ const payload = {
169
+ chatId: channel,
170
+ text,
171
+ from,
172
+ to: channel,
173
+ isChannel: true,
174
+ ...toolPolicy ? { toolPolicy } : {}
175
+ };
176
+ this.emit("message", payload);
177
+ }
178
+ _handleDm(from, message) {
179
+ const cfg = this.config;
180
+ const text = message.trim();
181
+ if (!text) return;
182
+ if (cfg.dmPolicy === "none") return;
183
+ if (cfg.dmPolicy === "allowlist") {
184
+ const allowBareNick = cfg.dangerouslyAllowNameMatching ?? false;
185
+ const allowList = cfg.allowFrom ?? [];
186
+ if (!senderAllowed(from, allowList, allowBareNick)) {
187
+ console.log(chalk.default.gray(` irc: drop DM from ${from} (dmPolicy=allowlist)`));
188
+ return;
189
+ }
190
+ }
191
+ const payload = {
192
+ chatId: from,
193
+ text,
194
+ from,
195
+ to: from,
196
+ isChannel: false
197
+ };
198
+ this.emit("message", payload);
199
+ }
200
+ async sendMessage(chatId, text) {
201
+ if (!this.client) throw new Error("IRC not connected");
202
+ const lines = text.split("\n").filter(Boolean);
203
+ for (const line of lines) this.client.say(chatId, line);
204
+ }
205
+ async disconnect() {
206
+ if (this.client) {
207
+ this.client.disconnect();
208
+ this.client = null;
209
+ }
210
+ }
211
+ getToolPolicy(sender, channel) {
212
+ const groupCfg = getGroupConfig(channel, this.config.groups ?? {});
213
+ return resolveToolPolicy(sender, groupCfg, this.config.dangerouslyAllowNameMatching ?? false);
214
+ }
215
+ };
216
+
217
+ //#endregion
218
+ exports.IrcConnector = IrcConnector;
@@ -0,0 +1,103 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
3
+ const path = require_chunk.__toESM(require("path"));
4
+
5
+ //#region src/infra/cost-tracker.ts
6
+ /** Rough cost per 1M tokens by provider/model (Claude Sonnet ballpark). */
7
+ const DEFAULT_COST_PER_1M_INPUT = 3;
8
+ const DEFAULT_COST_PER_1M_OUTPUT = 15;
9
+ function estimateCost(usage, model) {
10
+ if (!usage) return 0;
11
+ const inp = (usage.input || 0) + (usage.cacheRead || 0);
12
+ const inputCost = inp / 1e6 * DEFAULT_COST_PER_1M_INPUT;
13
+ const outputCost = (usage.output || 0) / 1e6 * DEFAULT_COST_PER_1M_OUTPUT;
14
+ return inputCost + outputCost;
15
+ }
16
+ /** Path to cost log file for a session. */
17
+ function getCostLogPath(baseDir, sessionId) {
18
+ return path.default.join(baseDir, "costs", `session-${sessionId}.jsonl`);
19
+ }
20
+ /** Append a cost entry for a session. */
21
+ async function recordUsage(baseDir, sessionId, usage, opts) {
22
+ const costUsd = estimateCost(usage, opts?.model);
23
+ const entry = {
24
+ sessionId,
25
+ source: opts?.source,
26
+ tenantId: opts?.tenantId,
27
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
28
+ usage,
29
+ costUsd,
30
+ model: opts?.model
31
+ };
32
+ const dir = path.default.join(baseDir, "costs");
33
+ await fs_extra.default.ensureDir(dir);
34
+ const fp = getCostLogPath(baseDir, sessionId);
35
+ await fs_extra.default.appendFile(fp, JSON.stringify(entry) + "\n");
36
+ }
37
+ /** Read and aggregate all entries for a session. */
38
+ async function getSessionSummary(baseDir, sessionId) {
39
+ const fp = getCostLogPath(baseDir, sessionId);
40
+ if (!await fs_extra.default.pathExists(fp)) return {
41
+ input: 0,
42
+ output: 0,
43
+ cacheRead: 0,
44
+ costUsd: 0,
45
+ runs: 0
46
+ };
47
+ const lines = (await fs_extra.default.readFile(fp, "utf8")).trim().split("\n").filter(Boolean);
48
+ let input = 0, output = 0, cacheRead = 0, costUsd = 0;
49
+ for (const line of lines) try {
50
+ const e = JSON.parse(line);
51
+ input += e.usage.input || 0;
52
+ output += e.usage.output || 0;
53
+ cacheRead += e.usage.cacheRead || 0;
54
+ costUsd += e.costUsd || 0;
55
+ } catch {}
56
+ return {
57
+ input,
58
+ output,
59
+ cacheRead,
60
+ costUsd,
61
+ runs: lines.length
62
+ };
63
+ }
64
+ /** Get global summary across all sessions. */
65
+ async function getGlobalSummary(baseDir) {
66
+ const dir = path.default.join(baseDir, "costs");
67
+ if (!await fs_extra.default.pathExists(dir)) return {
68
+ sessions: 0,
69
+ totalInput: 0,
70
+ totalOutput: 0,
71
+ totalCacheRead: 0,
72
+ totalCostUsd: 0,
73
+ totalRuns: 0
74
+ };
75
+ const files = (await fs_extra.default.readdir(dir)).filter((f) => f.startsWith("session-") && f.endsWith(".jsonl"));
76
+ let totalInput = 0, totalOutput = 0, totalCacheRead = 0, totalCostUsd = 0, totalRuns = 0;
77
+ for (const f of files) {
78
+ const fp = path.default.join(dir, f);
79
+ const content = await fs_extra.default.readFile(fp, "utf8").catch(() => "");
80
+ for (const line of content.trim().split("\n").filter(Boolean)) try {
81
+ const e = JSON.parse(line);
82
+ totalInput += e.usage.input || 0;
83
+ totalOutput += e.usage.output || 0;
84
+ totalCacheRead += e.usage.cacheRead || 0;
85
+ totalCostUsd += e.costUsd || 0;
86
+ totalRuns++;
87
+ } catch {}
88
+ }
89
+ return {
90
+ sessions: files.length,
91
+ totalInput,
92
+ totalOutput,
93
+ totalCacheRead,
94
+ totalCostUsd,
95
+ totalRuns
96
+ };
97
+ }
98
+
99
+ //#endregion
100
+ exports.estimateCost = estimateCost;
101
+ exports.getGlobalSummary = getGlobalSummary;
102
+ exports.getSessionSummary = getSessionSummary;
103
+ exports.recordUsage = recordUsage;
@@ -0,0 +1,103 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
3
+ const path = require_chunk.__toESM(require("path"));
4
+
5
+ //#region src/infra/cost-tracker.ts
6
+ /** Rough cost per 1M tokens by provider/model (Claude Sonnet ballpark). */
7
+ const DEFAULT_COST_PER_1M_INPUT = 3;
8
+ const DEFAULT_COST_PER_1M_OUTPUT = 15;
9
+ function estimateCost(usage, model) {
10
+ if (!usage) return 0;
11
+ const inp = (usage.input || 0) + (usage.cacheRead || 0);
12
+ const inputCost = inp / 1e6 * DEFAULT_COST_PER_1M_INPUT;
13
+ const outputCost = (usage.output || 0) / 1e6 * DEFAULT_COST_PER_1M_OUTPUT;
14
+ return inputCost + outputCost;
15
+ }
16
+ /** Path to cost log file for a session. */
17
+ function getCostLogPath(baseDir, sessionId) {
18
+ return path.default.join(baseDir, "costs", `session-${sessionId}.jsonl`);
19
+ }
20
+ /** Append a cost entry for a session. */
21
+ async function recordUsage(baseDir, sessionId, usage, opts) {
22
+ const costUsd = estimateCost(usage, opts?.model);
23
+ const entry = {
24
+ sessionId,
25
+ source: opts?.source,
26
+ tenantId: opts?.tenantId,
27
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
28
+ usage,
29
+ costUsd,
30
+ model: opts?.model
31
+ };
32
+ const dir = path.default.join(baseDir, "costs");
33
+ await fs_extra.default.ensureDir(dir);
34
+ const fp = getCostLogPath(baseDir, sessionId);
35
+ await fs_extra.default.appendFile(fp, JSON.stringify(entry) + "\n");
36
+ }
37
+ /** Read and aggregate all entries for a session. */
38
+ async function getSessionSummary(baseDir, sessionId) {
39
+ const fp = getCostLogPath(baseDir, sessionId);
40
+ if (!await fs_extra.default.pathExists(fp)) return {
41
+ input: 0,
42
+ output: 0,
43
+ cacheRead: 0,
44
+ costUsd: 0,
45
+ runs: 0
46
+ };
47
+ const lines = (await fs_extra.default.readFile(fp, "utf8")).trim().split("\n").filter(Boolean);
48
+ let input = 0, output = 0, cacheRead = 0, costUsd = 0;
49
+ for (const line of lines) try {
50
+ const e = JSON.parse(line);
51
+ input += e.usage.input || 0;
52
+ output += e.usage.output || 0;
53
+ cacheRead += e.usage.cacheRead || 0;
54
+ costUsd += e.costUsd || 0;
55
+ } catch {}
56
+ return {
57
+ input,
58
+ output,
59
+ cacheRead,
60
+ costUsd,
61
+ runs: lines.length
62
+ };
63
+ }
64
+ /** Get global summary across all sessions. */
65
+ async function getGlobalSummary(baseDir) {
66
+ const dir = path.default.join(baseDir, "costs");
67
+ if (!await fs_extra.default.pathExists(dir)) return {
68
+ sessions: 0,
69
+ totalInput: 0,
70
+ totalOutput: 0,
71
+ totalCacheRead: 0,
72
+ totalCostUsd: 0,
73
+ totalRuns: 0
74
+ };
75
+ const files = (await fs_extra.default.readdir(dir)).filter((f) => f.startsWith("session-") && f.endsWith(".jsonl"));
76
+ let totalInput = 0, totalOutput = 0, totalCacheRead = 0, totalCostUsd = 0, totalRuns = 0;
77
+ for (const f of files) {
78
+ const fp = path.default.join(dir, f);
79
+ const content = await fs_extra.default.readFile(fp, "utf8").catch(() => "");
80
+ for (const line of content.trim().split("\n").filter(Boolean)) try {
81
+ const e = JSON.parse(line);
82
+ totalInput += e.usage.input || 0;
83
+ totalOutput += e.usage.output || 0;
84
+ totalCacheRead += e.usage.cacheRead || 0;
85
+ totalCostUsd += e.costUsd || 0;
86
+ totalRuns++;
87
+ } catch {}
88
+ }
89
+ return {
90
+ sessions: files.length,
91
+ totalInput,
92
+ totalOutput,
93
+ totalCacheRead,
94
+ totalCostUsd,
95
+ totalRuns
96
+ };
97
+ }
98
+
99
+ //#endregion
100
+ exports.estimateCost = estimateCost;
101
+ exports.getGlobalSummary = getGlobalSummary;
102
+ exports.getSessionSummary = getSessionSummary;
103
+ exports.recordUsage = recordUsage;
@@ -0,0 +1,77 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+
7
+ //#region src/secrets/credentials-store.ts
8
+ var CredentialsStore = class {
9
+ credsDir;
10
+ constructor(baseDir) {
11
+ this.credsDir = path.default.join(baseDir || path.default.join(os.default.homedir(), ".hyperclaw"), "credentials");
12
+ }
13
+ filePath(providerId) {
14
+ const safe = providerId.replace(/[^a-zA-Z0-9_-]/g, "_");
15
+ return path.default.join(this.credsDir, `${safe}.json`);
16
+ }
17
+ async set(providerId, creds) {
18
+ await fs_extra.default.ensureDir(this.credsDir);
19
+ await fs_extra.default.chmod(this.credsDir, 448);
20
+ const record = {
21
+ ...creds,
22
+ providerId,
23
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
24
+ };
25
+ const fpath = this.filePath(providerId);
26
+ await fs_extra.default.writeJson(fpath, record, { spaces: 2 });
27
+ await fs_extra.default.chmod(fpath, 384);
28
+ }
29
+ async get(providerId) {
30
+ const fpath = this.filePath(providerId);
31
+ if (!await fs_extra.default.pathExists(fpath)) return null;
32
+ const stat = await fs_extra.default.stat(fpath);
33
+ if ((stat.mode & 63) !== 0) {
34
+ console.log(chalk.default.yellow(` ⚠ Unsafe permissions on credentials/${providerId}.json — fixing...`));
35
+ await fs_extra.default.chmod(fpath, 384);
36
+ }
37
+ return fs_extra.default.readJson(fpath);
38
+ }
39
+ async remove(providerId) {
40
+ const fpath = this.filePath(providerId);
41
+ await fs_extra.default.remove(fpath);
42
+ console.log(chalk.default.green(` ✔ Credentials removed: ${providerId}`));
43
+ }
44
+ async list() {
45
+ if (!await fs_extra.default.pathExists(this.credsDir)) return [];
46
+ const files = await fs_extra.default.readdir(this.credsDir);
47
+ return files.filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
48
+ }
49
+ async showList() {
50
+ const providers = await this.list();
51
+ console.log(chalk.default.bold.cyan("\n 🔐 CREDENTIALS\n"));
52
+ if (providers.length === 0) {
53
+ console.log(chalk.default.gray(" No credentials stored.\n"));
54
+ console.log(chalk.default.gray(" Add with: hyperclaw auth add <service_id> (for any API key)\n"));
55
+ console.log(chalk.default.gray(" Or: hyperclaw secrets set KEY=value (for .env vars)\n"));
56
+ return;
57
+ }
58
+ for (const p of providers) {
59
+ const cred = await this.get(p);
60
+ const hasKey = !!cred?.apiKey;
61
+ const hasRefresh = !!cred?.refreshToken;
62
+ const expiry = cred?.expiresAt ? new Date(cred.expiresAt) > /* @__PURE__ */ new Date() ? chalk.default.green("valid") : chalk.default.red("expired") : chalk.default.gray("no expiry");
63
+ console.log(` ${chalk.default.green("●")} ${chalk.default.white(p.padEnd(20))} ${hasKey ? chalk.default.cyan("api_key") : ""}${hasRefresh ? chalk.default.yellow(" refresh_token") : ""} ${expiry}`);
64
+ console.log(` ${chalk.default.gray(`Updated: ${cred?.updatedAt ? new Date(cred.updatedAt).toLocaleString() : "unknown"}`)}`);
65
+ console.log();
66
+ }
67
+ console.log(chalk.default.gray(" credentials/ — stored at ~/.hyperclaw/credentials/*.json (mode 0600)\n"));
68
+ }
69
+ };
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CredentialsStore', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CredentialsStore;
76
+ }
77
+ });
@@ -0,0 +1,77 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+
7
+ //#region src/secrets/credentials-store.ts
8
+ var CredentialsStore = class {
9
+ credsDir;
10
+ constructor(baseDir) {
11
+ this.credsDir = path.default.join(baseDir || path.default.join(os.default.homedir(), ".hyperclaw"), "credentials");
12
+ }
13
+ filePath(providerId) {
14
+ const safe = providerId.replace(/[^a-zA-Z0-9_-]/g, "_");
15
+ return path.default.join(this.credsDir, `${safe}.json`);
16
+ }
17
+ async set(providerId, creds) {
18
+ await fs_extra.default.ensureDir(this.credsDir);
19
+ await fs_extra.default.chmod(this.credsDir, 448);
20
+ const record = {
21
+ ...creds,
22
+ providerId,
23
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
24
+ };
25
+ const fpath = this.filePath(providerId);
26
+ await fs_extra.default.writeJson(fpath, record, { spaces: 2 });
27
+ await fs_extra.default.chmod(fpath, 384);
28
+ }
29
+ async get(providerId) {
30
+ const fpath = this.filePath(providerId);
31
+ if (!await fs_extra.default.pathExists(fpath)) return null;
32
+ const stat = await fs_extra.default.stat(fpath);
33
+ if ((stat.mode & 63) !== 0) {
34
+ console.log(chalk.default.yellow(` ⚠ Unsafe permissions on credentials/${providerId}.json — fixing...`));
35
+ await fs_extra.default.chmod(fpath, 384);
36
+ }
37
+ return fs_extra.default.readJson(fpath);
38
+ }
39
+ async remove(providerId) {
40
+ const fpath = this.filePath(providerId);
41
+ await fs_extra.default.remove(fpath);
42
+ console.log(chalk.default.green(` ✔ Credentials removed: ${providerId}`));
43
+ }
44
+ async list() {
45
+ if (!await fs_extra.default.pathExists(this.credsDir)) return [];
46
+ const files = await fs_extra.default.readdir(this.credsDir);
47
+ return files.filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
48
+ }
49
+ async showList() {
50
+ const providers = await this.list();
51
+ console.log(chalk.default.bold.cyan("\n 🔐 CREDENTIALS\n"));
52
+ if (providers.length === 0) {
53
+ console.log(chalk.default.gray(" No credentials stored.\n"));
54
+ console.log(chalk.default.gray(" Add with: hyperclaw auth add <service_id> (for any API key)\n"));
55
+ console.log(chalk.default.gray(" Or: hyperclaw secrets set KEY=value (for .env vars)\n"));
56
+ return;
57
+ }
58
+ for (const p of providers) {
59
+ const cred = await this.get(p);
60
+ const hasKey = !!cred?.apiKey;
61
+ const hasRefresh = !!cred?.refreshToken;
62
+ const expiry = cred?.expiresAt ? new Date(cred.expiresAt) > /* @__PURE__ */ new Date() ? chalk.default.green("valid") : chalk.default.red("expired") : chalk.default.gray("no expiry");
63
+ console.log(` ${chalk.default.green("●")} ${chalk.default.white(p.padEnd(20))} ${hasKey ? chalk.default.cyan("api_key") : ""}${hasRefresh ? chalk.default.yellow(" refresh_token") : ""} ${expiry}`);
64
+ console.log(` ${chalk.default.gray(`Updated: ${cred?.updatedAt ? new Date(cred.updatedAt).toLocaleString() : "unknown"}`)}`);
65
+ console.log();
66
+ }
67
+ console.log(chalk.default.gray(" credentials/ — stored at ~/.hyperclaw/credentials/*.json (mode 0600)\n"));
68
+ }
69
+ };
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CredentialsStore', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CredentialsStore;
76
+ }
77
+ });
@@ -0,0 +1,4 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_credentials_store = require('./credentials-store-BxijEirw.js');
3
+
4
+ exports.CredentialsStore = require_credentials_store.CredentialsStore;
@@ -0,0 +1,4 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_credentials_store = require('./credentials-store-CA8UtK0T.js');
3
+
4
+ exports.CredentialsStore = require_credentials_store.CredentialsStore;
@@ -0,0 +1,82 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
3
+ const path = require_chunk.__toESM(require("path"));
4
+ const os = require_chunk.__toESM(require("os"));
5
+
6
+ //#region src/services/cron-tasks.ts
7
+ const CRON_TASKS_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "cron-tasks.json");
8
+ let tasks = [];
9
+ async function loadCronTasks() {
10
+ try {
11
+ tasks = await fs_extra.default.readJson(CRON_TASKS_FILE);
12
+ } catch {
13
+ tasks = [];
14
+ }
15
+ return tasks;
16
+ }
17
+ async function saveCronTasks() {
18
+ await fs_extra.default.ensureDir(path.default.dirname(CRON_TASKS_FILE));
19
+ await fs_extra.default.writeJson(CRON_TASKS_FILE, tasks, { spaces: 2 });
20
+ }
21
+ function addCronTask(schedule, prompt, name) {
22
+ const id = `task-${Date.now().toString(36)}`;
23
+ const task = {
24
+ id,
25
+ schedule,
26
+ prompt,
27
+ name,
28
+ enabled: true,
29
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
30
+ };
31
+ tasks.push(task);
32
+ return task;
33
+ }
34
+ function removeCronTask(id) {
35
+ const i = tasks.findIndex((t) => t.id === id);
36
+ if (i >= 0) {
37
+ tasks.splice(i, 1);
38
+ return true;
39
+ }
40
+ return false;
41
+ }
42
+ async function runCronTask(task, port = 18789) {
43
+ const http = await import("http");
44
+ return new Promise((resolve, reject) => {
45
+ const payload = JSON.stringify({ message: task.prompt });
46
+ const req = http.request({
47
+ hostname: "127.0.0.1",
48
+ port,
49
+ path: "/api/webhook/inbound",
50
+ method: "POST",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "Content-Length": Buffer.byteLength(payload)
54
+ }
55
+ }, (res) => {
56
+ let data = "";
57
+ res.on("data", (c) => data += c);
58
+ res.on("end", async () => {
59
+ task.lastRunAt = (/* @__PURE__ */ new Date()).toISOString();
60
+ await saveCronTasks().catch(() => {});
61
+ resolve();
62
+ });
63
+ });
64
+ req.on("error", (e) => {
65
+ console.error(`[cron] task ${task.id} failed:`, e.message);
66
+ resolve();
67
+ });
68
+ req.setTimeout(6e4, () => {
69
+ req.destroy();
70
+ resolve();
71
+ });
72
+ req.write(payload);
73
+ req.end();
74
+ });
75
+ }
76
+
77
+ //#endregion
78
+ exports.addCronTask = addCronTask;
79
+ exports.loadCronTasks = loadCronTasks;
80
+ exports.removeCronTask = removeCronTask;
81
+ exports.runCronTask = runCronTask;
82
+ exports.saveCronTasks = saveCronTasks;