hyperclaw 4.0.2 → 5.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.
Files changed (194) hide show
  1. package/README.md +246 -60
  2. package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
  3. package/dist/agents-routing-ChHiZp36.js +327 -0
  4. package/dist/agents-routing-ChqZ6l2S.js +4 -0
  5. package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
  6. package/dist/api-keys-guide-CGn5BSF7.js +149 -0
  7. package/dist/audit-BJohI_vC.js +441 -0
  8. package/dist/audit-BaIiyWFu.js +441 -0
  9. package/dist/bounty-tools-CY_i91DU.js +211 -0
  10. package/dist/bounty-tools-DWudyZie.js +211 -0
  11. package/dist/browser-tools-BsTeGMnX.js +5 -0
  12. package/dist/browser-tools-D8_rLe2p.js +179 -0
  13. package/dist/claw-tasks-CgTsiNE8.js +80 -0
  14. package/dist/claw-tasks-Cyzdbhz_.js +80 -0
  15. package/dist/connector-5N0-X_xs.js +194 -0
  16. package/dist/connector-B3v0qcXg.js +425 -0
  17. package/dist/connector-B8R3iBY1.js +280 -0
  18. package/dist/connector-BAM-08NN.js +189 -0
  19. package/dist/connector-BC8FIVu4.js +181 -0
  20. package/dist/connector-BDmwwaVc.js +213 -0
  21. package/dist/connector-BGjbBy69.js +225 -0
  22. package/dist/connector-BO2SRzfG.js +218 -0
  23. package/dist/connector-BfXky0L3.js +167 -0
  24. package/dist/connector-BiiSJpx3.js +192 -0
  25. package/dist/connector-BnDmIhIu.js +85 -0
  26. package/dist/connector-C1HSoUyk.js +189 -0
  27. package/dist/connector-CKQHZOXg.js +568 -0
  28. package/dist/connector-CRl-iidy.js +239 -0
  29. package/dist/connector-Ci9glMD-.js +340 -0
  30. package/dist/connector-CjtZIEDj.js +181 -0
  31. package/dist/connector-Ck6JtOsX.js +531 -0
  32. package/dist/connector-D8Kelee0.js +286 -0
  33. package/dist/connector-DAnRJ0oP.js +162 -0
  34. package/dist/connector-DXTp5PE8.js +508 -0
  35. package/dist/connector-Dih6dUPP.js +173 -0
  36. package/dist/connector-DqTH_tPX.js +182 -0
  37. package/dist/connector-DrnEiiyP.js +419 -0
  38. package/dist/connector-DtR5GGTX.js +167 -0
  39. package/dist/connector-Tky_qS_K.js +350 -0
  40. package/dist/connector-ZSc3oTTy.js +305 -0
  41. package/dist/connector-sW5yhU1m.js +498 -0
  42. package/dist/connector-u3ICd3Ic.js +552 -0
  43. package/dist/cost-tracker-Ca1UPZ33.js +103 -0
  44. package/dist/cost-tracker-DD9wtWsr.js +103 -0
  45. package/dist/credentials-store-C6ir0Dae.js +4 -0
  46. package/dist/credentials-store-CA8UtK0T.js +77 -0
  47. package/dist/credentials-store-Cm7DH-kh.js +4 -0
  48. package/dist/credentials-store-H13LqOwJ.js +77 -0
  49. package/dist/cron-tasks-Bli7Kzd2.js +82 -0
  50. package/dist/cron-tasks-_pqQCmxc.js +82 -0
  51. package/dist/daemon-7ViroziB.js +5 -0
  52. package/dist/daemon-BfyKmZhr.js +318 -0
  53. package/dist/daemon-Bg4GtCmc.js +318 -0
  54. package/dist/daemon-DhmwY8k4.js +5 -0
  55. package/dist/delivery-BmIYy9VQ.js +4 -0
  56. package/dist/delivery-DVHmv1IR.js +4 -0
  57. package/dist/delivery-DpMX0Yyc.js +95 -0
  58. package/dist/delivery-pWUPBp1F.js +95 -0
  59. package/dist/destructive-gate-D6vWOdEl.js +101 -0
  60. package/dist/destructive-gate-DZt71UZR.js +101 -0
  61. package/dist/developer-keys-CPWT7Q6S.js +8 -0
  62. package/dist/developer-keys-DrrcUqFa.js +127 -0
  63. package/dist/doctor-BvCe8BBk.js +230 -0
  64. package/dist/doctor-CxyPLYsJ.js +6 -0
  65. package/dist/engine-B0kLfRL0.js +256 -0
  66. package/dist/engine-BJUpRUOv.js +7 -0
  67. package/dist/engine-CEDSqXfw.js +256 -0
  68. package/dist/engine-Da4JMNpI.js +7 -0
  69. package/dist/env-resolve-17ekEU6p.js +10 -0
  70. package/dist/env-resolve-CiXbWYwe.js +10 -0
  71. package/dist/env-resolve-CmGWhWXJ.js +115 -0
  72. package/dist/env-resolve-Z2XF6leB.js +115 -0
  73. package/dist/extraction-tools-HOZstZ0y.js +91 -0
  74. package/dist/extraction-tools-m4lmAv7l.js +5 -0
  75. package/dist/form_data-Cz040rio.js +8657 -0
  76. package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
  77. package/dist/health-B-asI__D.js +6 -0
  78. package/dist/health-Ds2YlpTB.js +152 -0
  79. package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
  80. package/dist/heartbeat-engine-Ut6pXBD6.js +83 -0
  81. package/dist/hub-9LaKnLjY.js +6 -0
  82. package/dist/hub-CfwUz9YW.js +515 -0
  83. package/dist/hub-D0XwdjM-.js +515 -0
  84. package/dist/hub-LiD5Iztb.js +6 -0
  85. package/dist/hyperclawbot-CBiDSKsa.js +505 -0
  86. package/dist/hyperclawbot-zvczQgKx.js +505 -0
  87. package/dist/inference-0mlFQqIm.js +922 -0
  88. package/dist/inference-BKVkBREb.js +6 -0
  89. package/dist/inference-DCXH4Q3x.js +922 -0
  90. package/dist/inference-SzqFe_nk.js +6 -0
  91. package/dist/knowledge-graph-DE5lSF02.js +131 -0
  92. package/dist/knowledge-graph-iBG76fvm.js +131 -0
  93. package/dist/loader-BkDi8MD9.js +400 -0
  94. package/dist/loader-CC45xGpC.js +4 -0
  95. package/dist/loader-CnEdOyjT.js +400 -0
  96. package/dist/loader-DI2qDRPC.js +4 -0
  97. package/dist/logger-Cp8wC7F8.js +83 -0
  98. package/dist/logger-ybOp7VOC.js +83 -0
  99. package/dist/manager-03ipO9R0.js +105 -0
  100. package/dist/manager-B2Gls5RG.js +218 -0
  101. package/dist/manager-BpDfbDjg.js +117 -0
  102. package/dist/manager-Bxl0sqlh.js +4 -0
  103. package/dist/manager-CWNSML5D.js +117 -0
  104. package/dist/manager-CrVDn6eN.js +6 -0
  105. package/dist/manager-FCgF1plu.js +218 -0
  106. package/dist/manager-SJe9gt-q.js +4 -0
  107. package/dist/manager-rgCsaWT1.js +40 -0
  108. package/dist/mcp-CfoSU4Uz.js +139 -0
  109. package/dist/mcp-loader-CvxRDtPC.js +94 -0
  110. package/dist/mcp-loader-DkRBsLpk.js +94 -0
  111. package/dist/memory-BlHL7JCO.js +4 -0
  112. package/dist/memory-DsS_eFvJ.js +270 -0
  113. package/dist/memory-auto-BkvtSFUw.js +5 -0
  114. package/dist/memory-auto-Bnz_-1wP.js +306 -0
  115. package/dist/memory-auto-CpQHZlEJ.js +306 -0
  116. package/dist/memory-auto-Z6LCf-iK.js +5 -0
  117. package/dist/memory-integration-cSYkZyEo.js +91 -0
  118. package/dist/memory-integration-g2vxwgoE.js +91 -0
  119. package/dist/moltbook-BtLDZTfM.js +81 -0
  120. package/dist/moltbook-Cl8cQfxJ.js +81 -0
  121. package/dist/node-Dw2Gi-cP.js +222 -0
  122. package/dist/nodes-registry-B8dmrlLv.js +52 -0
  123. package/dist/nodes-registry-C9dCFwjh.js +52 -0
  124. package/dist/oauth-flow-CeaaGAz0.js +150 -0
  125. package/dist/oauth-flow-DQPvMHRH.js +150 -0
  126. package/dist/oauth-provider-B4dzn56l.js +110 -0
  127. package/dist/oauth-provider-Uo4Nib_c.js +110 -0
  128. package/dist/observability-BV-Yx0V9.js +89 -0
  129. package/dist/observability-nZ3CBIxG.js +89 -0
  130. package/dist/onboard-0WoDxbv_.js +10 -0
  131. package/dist/onboard-BBBWcfhp.js +10 -0
  132. package/dist/onboard-BXNXCQp4.js +4070 -0
  133. package/dist/onboard-Bw28IRQ3.js +4070 -0
  134. package/dist/orchestrator-BovkM63z.js +6 -0
  135. package/dist/orchestrator-DSbpkP1X.js +189 -0
  136. package/dist/orchestrator-DmnEvMaL.js +189 -0
  137. package/dist/orchestrator-RI3bpqqc.js +6 -0
  138. package/dist/osint-B4_m3VHQ.js +277 -0
  139. package/dist/pairing-6iM27aD8.js +196 -0
  140. package/dist/pairing-dGoiGepK.js +4 -0
  141. package/dist/pc-access-CgCsYrpt.js +8 -0
  142. package/dist/pc-access-_iH2aorG.js +819 -0
  143. package/dist/pending-approval-BgNjjuI2.js +22 -0
  144. package/dist/pending-approval-CUXjysAo.js +22 -0
  145. package/dist/reminders-store-Drjed_-h.js +58 -0
  146. package/dist/renderer-BVQrd0_g.js +225 -0
  147. package/dist/rules-BE4GV6cV.js +103 -0
  148. package/dist/run-main.js +1639 -460
  149. package/dist/runner-CJFJUtPm.js +1271 -0
  150. package/dist/runner-DatMMYYE.js +1271 -0
  151. package/dist/sdk/index.js +2 -2
  152. package/dist/sdk/index.mjs +2 -2
  153. package/dist/security-BqNyT4ID.js +4 -0
  154. package/dist/security-tpgqPWWH.js +73 -0
  155. package/dist/server-Brl_HQUB.js +1255 -0
  156. package/dist/server-D4wVHiX9.js +4 -0
  157. package/dist/server-Dh3JlBFB.js +1255 -0
  158. package/dist/server-DhfipkwN.js +4 -0
  159. package/dist/session-store-BUiPz0Vv.js +5 -0
  160. package/dist/session-store-is4B6qmD.js +113 -0
  161. package/dist/sessions-tools-CbUTFe4i.js +5 -0
  162. package/dist/sessions-tools-CeqD7iil.js +95 -0
  163. package/dist/skill-loader-BaNLVmJy.js +7 -0
  164. package/dist/skill-loader-HgpF6Vqs.js +159 -0
  165. package/dist/skill-runtime-BXWd-Ktf.js +102 -0
  166. package/dist/skill-runtime-CJN24QPW.js +102 -0
  167. package/dist/skill-runtime-jgklm02e.js +5 -0
  168. package/dist/skill-runtime-w1ig_lcw.js +5 -0
  169. package/dist/src-Bhybpk1J.js +63 -0
  170. package/dist/src-BxPHKO5x.js +63 -0
  171. package/dist/src-DIc-L2IG.js +20 -0
  172. package/dist/src-DMJ4-uqk.js +458 -0
  173. package/dist/src-g_rNx5rh.js +458 -0
  174. package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
  175. package/dist/sub-agent-tools-DHY-4WWM.js +39 -0
  176. package/dist/theme-DcxwcUgZ.js +180 -0
  177. package/dist/theme-cx0fkgWC.js +8 -0
  178. package/dist/tool-policy-CNT-mF2Z.js +189 -0
  179. package/dist/tool-policy-DZvF8xlQ.js +189 -0
  180. package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
  181. package/dist/tts-elevenlabs-C06nUxMK.js +61 -0
  182. package/dist/update-check-C2Dz85wJ.js +81 -0
  183. package/dist/update-check-w4XuxVl7.js +81 -0
  184. package/dist/vision-BMmiIKy7.js +121 -0
  185. package/dist/vision-JOtOS1Br.js +121 -0
  186. package/dist/vision-tools-CB28ZCO_.js +5 -0
  187. package/dist/vision-tools-DVuYc17I.js +51 -0
  188. package/dist/vision-tools-U3YC4L-g.js +5 -0
  189. package/dist/vision-tools-vPPwQ-0N.js +51 -0
  190. package/dist/voice-transcription-B555DbWR.js +138 -0
  191. package/dist/voice-transcription-DBo5hXmu.js +138 -0
  192. package/dist/website-watch-tools-DFMrJU-R.js +139 -0
  193. package/dist/website-watch-tools-Du3W5sN7.js +5 -0
  194. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+
2
+ //#region src/channels/delivery.ts
3
+ /**
4
+
5
+ * src/channels/delivery.ts
6
+
7
+ * Delivery pipeline: queue retry, per-channel chunking, media handling.
8
+
9
+ */
10
+ const CHANNEL_MAX_LENGTH = {
11
+ telegram: 4096,
12
+ discord: 2e3,
13
+ whatsapp: 4096,
14
+ "whatsapp-baileys": 4096,
15
+ slack: 4e4,
16
+ googlechat: 4096,
17
+ msteams: 28e3,
18
+ matrix: 32768,
19
+ irc: 512,
20
+ mattermost: 16383,
21
+ signal: 4096,
22
+ line: 2e3,
23
+ twitch: 490,
24
+ viber: 7e3,
25
+ default: 4e3
26
+ };
27
+ function chunkForChannel(text, channelId) {
28
+ const max = CHANNEL_MAX_LENGTH[channelId] ?? CHANNEL_MAX_LENGTH.default;
29
+ if (text.length <= max) return [text];
30
+ const chunks = [];
31
+ let i = 0;
32
+ while (i < text.length) {
33
+ let end = Math.min(i + max, text.length);
34
+ if (end < text.length) {
35
+ const nl = text.lastIndexOf("\n", end);
36
+ if (nl > i) end = nl + 1;
37
+ }
38
+ chunks.push(text.slice(i, end));
39
+ i = end;
40
+ }
41
+ return chunks;
42
+ }
43
+ const DEFAULT_RETRIES = 3;
44
+ const DEFAULT_BACKOFF_MS = 1e3;
45
+ async function withRetry(fn, opts) {
46
+ const retries = opts?.retries ?? DEFAULT_RETRIES;
47
+ const backoff = opts?.backoffMs ?? DEFAULT_BACKOFF_MS;
48
+ let lastErr = null;
49
+ for (let i = 0; i <= retries; i++) try {
50
+ return await fn();
51
+ } catch (e) {
52
+ lastErr = e;
53
+ opts?.onRetry?.(i + 1, lastErr);
54
+ if (i < retries) await new Promise((r) => setTimeout(r, backoff * Math.pow(2, i)));
55
+ }
56
+ throw lastErr;
57
+ }
58
+ /** Enrich message text from voice note (transcribe if audioPath provided). */
59
+ async function enrichVoiceNote(msg) {
60
+ if (!msg.audioPath) return msg.text;
61
+ if (msg.text && msg.text !== "[voice note]") return msg.text;
62
+ try {
63
+ const { transcribeVoiceNote } = await Promise.resolve().then(() => require("./voice-transcription-DBo5hXmu.js"));
64
+ const text = await transcribeVoiceNote(msg.audioPath);
65
+ return text || msg.text;
66
+ } catch (e) {
67
+ return `[Voice note — transcription failed: ${e.message}]`;
68
+ }
69
+ }
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CHANNEL_MAX_LENGTH', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CHANNEL_MAX_LENGTH;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, 'chunkForChannel', {
79
+ enumerable: true,
80
+ get: function () {
81
+ return chunkForChannel;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, 'enrichVoiceNote', {
85
+ enumerable: true,
86
+ get: function () {
87
+ return enrichVoiceNote;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, 'withRetry', {
91
+ enumerable: true,
92
+ get: function () {
93
+ return withRetry;
94
+ }
95
+ });
@@ -0,0 +1,95 @@
1
+
2
+ //#region src/channels/delivery.ts
3
+ /**
4
+
5
+ * src/channels/delivery.ts
6
+
7
+ * Delivery pipeline: queue retry, per-channel chunking, media handling.
8
+
9
+ */
10
+ const CHANNEL_MAX_LENGTH = {
11
+ telegram: 4096,
12
+ discord: 2e3,
13
+ whatsapp: 4096,
14
+ "whatsapp-baileys": 4096,
15
+ slack: 4e4,
16
+ googlechat: 4096,
17
+ msteams: 28e3,
18
+ matrix: 32768,
19
+ irc: 512,
20
+ mattermost: 16383,
21
+ signal: 4096,
22
+ line: 2e3,
23
+ twitch: 490,
24
+ viber: 7e3,
25
+ default: 4e3
26
+ };
27
+ function chunkForChannel(text, channelId) {
28
+ const max = CHANNEL_MAX_LENGTH[channelId] ?? CHANNEL_MAX_LENGTH.default;
29
+ if (text.length <= max) return [text];
30
+ const chunks = [];
31
+ let i = 0;
32
+ while (i < text.length) {
33
+ let end = Math.min(i + max, text.length);
34
+ if (end < text.length) {
35
+ const nl = text.lastIndexOf("\n", end);
36
+ if (nl > i) end = nl + 1;
37
+ }
38
+ chunks.push(text.slice(i, end));
39
+ i = end;
40
+ }
41
+ return chunks;
42
+ }
43
+ const DEFAULT_RETRIES = 3;
44
+ const DEFAULT_BACKOFF_MS = 1e3;
45
+ async function withRetry(fn, opts) {
46
+ const retries = opts?.retries ?? DEFAULT_RETRIES;
47
+ const backoff = opts?.backoffMs ?? DEFAULT_BACKOFF_MS;
48
+ let lastErr = null;
49
+ for (let i = 0; i <= retries; i++) try {
50
+ return await fn();
51
+ } catch (e) {
52
+ lastErr = e;
53
+ opts?.onRetry?.(i + 1, lastErr);
54
+ if (i < retries) await new Promise((r) => setTimeout(r, backoff * Math.pow(2, i)));
55
+ }
56
+ throw lastErr;
57
+ }
58
+ /** Enrich message text from voice note (transcribe if audioPath provided). */
59
+ async function enrichVoiceNote(msg) {
60
+ if (!msg.audioPath) return msg.text;
61
+ if (msg.text && msg.text !== "[voice note]") return msg.text;
62
+ try {
63
+ const { transcribeVoiceNote } = await Promise.resolve().then(() => require("./voice-transcription-B555DbWR.js"));
64
+ const text = await transcribeVoiceNote(msg.audioPath);
65
+ return text || msg.text;
66
+ } catch (e) {
67
+ return `[Voice note — transcription failed: ${e.message}]`;
68
+ }
69
+ }
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CHANNEL_MAX_LENGTH', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CHANNEL_MAX_LENGTH;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, 'chunkForChannel', {
79
+ enumerable: true,
80
+ get: function () {
81
+ return chunkForChannel;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, 'enrichVoiceNote', {
85
+ enumerable: true,
86
+ get: function () {
87
+ return enrichVoiceNote;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, 'withRetry', {
91
+ enumerable: true,
92
+ get: function () {
93
+ return withRetry;
94
+ }
95
+ });
@@ -0,0 +1,101 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+
3
+ //#region src/infra/destructive-gate.ts
4
+ function isDangerousShellCommand(cmd) {
5
+ const c = (cmd || "").trim();
6
+ for (const re of DANGEROUS_SHELL_PATTERNS) if (re.test(c)) return true;
7
+ return false;
8
+ }
9
+ /**
10
+
11
+ * Wrap tools so destructive ones are gated. When sessionId set, stores pending for confirm flow.
12
+
13
+ */
14
+ function applyDestructiveGate(tools, opts) {
15
+ const { elevated, source, sessionId } = opts;
16
+ const fromChannel = source && CHANNEL_SOURCES.has(source);
17
+ if (!fromChannel || elevated) return tools;
18
+ return tools.map((t) => {
19
+ if (DESTRUCTIVE_TOOLS.includes(t.name)) {
20
+ const orig = t.handler;
21
+ return {
22
+ ...t,
23
+ handler: async (input) => {
24
+ if (sessionId) {
25
+ const { setPending } = await Promise.resolve().then(() => require("./pending-approval-CUXjysAo.js"));
26
+ setPending(sessionId, {
27
+ toolName: t.name,
28
+ input,
29
+ execute: () => orig(input)
30
+ });
31
+ return PENDING_MSG;
32
+ }
33
+ return BLOCKED_MSG;
34
+ }
35
+ };
36
+ }
37
+ if (t.name === "run_shell") {
38
+ const orig = t.handler;
39
+ return {
40
+ ...t,
41
+ handler: async (input) => {
42
+ const cmd = input.command || "";
43
+ if (isDangerousShellCommand(cmd)) {
44
+ if (sessionId) {
45
+ const { setPending } = await Promise.resolve().then(() => require("./pending-approval-CUXjysAo.js"));
46
+ setPending(sessionId, {
47
+ toolName: "run_shell",
48
+ input,
49
+ execute: () => orig(input)
50
+ });
51
+ return PENDING_MSG;
52
+ }
53
+ return BLOCKED_MSG;
54
+ }
55
+ return orig(input);
56
+ }
57
+ };
58
+ }
59
+ return t;
60
+ });
61
+ }
62
+ var DESTRUCTIVE_TOOLS, DANGEROUS_SHELL_PATTERNS, CHANNEL_SOURCES, BLOCKED_MSG, PENDING_MSG;
63
+ var init_destructive_gate = require_chunk.__esm({ "src/infra/destructive-gate.ts"() {
64
+ DESTRUCTIVE_TOOLS = ["delete_file", "kill_process"];
65
+ DANGEROUS_SHELL_PATTERNS = [
66
+ /\brm\s+-[rf]\b|\brm\s+--recursive|\brm\s+-rf\b/,
67
+ /\bmkfs\.|format\s+/i,
68
+ /\bdd\s+if=/,
69
+ /\b>\/dev\/sd[a-z]/,
70
+ /\bshutdown\s+-/,
71
+ /\breboot\b/i,
72
+ /\b:\(\)\s*\{\s*:\s*\|\s*:\s*&\s*\}/,
73
+ /\bcurl\s+.*\s*\|\s*sh\b/,
74
+ /\bwget\s+.*\s*\|\s*(bash|sh)\b/
75
+ ];
76
+ CHANNEL_SOURCES = new Set([
77
+ "telegram",
78
+ "discord",
79
+ "whatsapp",
80
+ "slack",
81
+ "signal",
82
+ "matrix",
83
+ "line",
84
+ "nostr",
85
+ "feishu",
86
+ "msteams",
87
+ "teams",
88
+ "instagram",
89
+ "messenger",
90
+ "twitter",
91
+ "viber",
92
+ "zalo",
93
+ "webhook:inbound"
94
+ ]);
95
+ BLOCKED_MSG = "Blocked: destructive action requires elevated session. Use \"elevate\" or run from CLI with full access.";
96
+ PENDING_MSG = "This action requires confirmation. Ask the user to reply \"confirm\" to proceed.";
97
+ } });
98
+
99
+ //#endregion
100
+ init_destructive_gate();
101
+ exports.applyDestructiveGate = applyDestructiveGate;
@@ -0,0 +1,101 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+
3
+ //#region src/infra/destructive-gate.ts
4
+ function isDangerousShellCommand(cmd) {
5
+ const c = (cmd || "").trim();
6
+ for (const re of DANGEROUS_SHELL_PATTERNS) if (re.test(c)) return true;
7
+ return false;
8
+ }
9
+ /**
10
+
11
+ * Wrap tools so destructive ones are gated. When sessionId set, stores pending for confirm flow.
12
+
13
+ */
14
+ function applyDestructiveGate(tools, opts) {
15
+ const { elevated, source, sessionId } = opts;
16
+ const fromChannel = source && CHANNEL_SOURCES.has(source);
17
+ if (!fromChannel || elevated) return tools;
18
+ return tools.map((t) => {
19
+ if (DESTRUCTIVE_TOOLS.includes(t.name)) {
20
+ const orig = t.handler;
21
+ return {
22
+ ...t,
23
+ handler: async (input) => {
24
+ if (sessionId) {
25
+ const { setPending } = await Promise.resolve().then(() => require("./pending-approval-BgNjjuI2.js"));
26
+ setPending(sessionId, {
27
+ toolName: t.name,
28
+ input,
29
+ execute: () => orig(input)
30
+ });
31
+ return PENDING_MSG;
32
+ }
33
+ return BLOCKED_MSG;
34
+ }
35
+ };
36
+ }
37
+ if (t.name === "run_shell") {
38
+ const orig = t.handler;
39
+ return {
40
+ ...t,
41
+ handler: async (input) => {
42
+ const cmd = input.command || "";
43
+ if (isDangerousShellCommand(cmd)) {
44
+ if (sessionId) {
45
+ const { setPending } = await Promise.resolve().then(() => require("./pending-approval-BgNjjuI2.js"));
46
+ setPending(sessionId, {
47
+ toolName: "run_shell",
48
+ input,
49
+ execute: () => orig(input)
50
+ });
51
+ return PENDING_MSG;
52
+ }
53
+ return BLOCKED_MSG;
54
+ }
55
+ return orig(input);
56
+ }
57
+ };
58
+ }
59
+ return t;
60
+ });
61
+ }
62
+ var DESTRUCTIVE_TOOLS, DANGEROUS_SHELL_PATTERNS, CHANNEL_SOURCES, BLOCKED_MSG, PENDING_MSG;
63
+ var init_destructive_gate = require_chunk.__esm({ "src/infra/destructive-gate.ts"() {
64
+ DESTRUCTIVE_TOOLS = ["delete_file", "kill_process"];
65
+ DANGEROUS_SHELL_PATTERNS = [
66
+ /\brm\s+-[rf]\b|\brm\s+--recursive|\brm\s+-rf\b/,
67
+ /\bmkfs\.|format\s+/i,
68
+ /\bdd\s+if=/,
69
+ /\b>\/dev\/sd[a-z]/,
70
+ /\bshutdown\s+-/,
71
+ /\breboot\b/i,
72
+ /\b:\(\)\s*\{\s*:\s*\|\s*:\s*&\s*\}/,
73
+ /\bcurl\s+.*\s*\|\s*sh\b/,
74
+ /\bwget\s+.*\s*\|\s*(bash|sh)\b/
75
+ ];
76
+ CHANNEL_SOURCES = new Set([
77
+ "telegram",
78
+ "discord",
79
+ "whatsapp",
80
+ "slack",
81
+ "signal",
82
+ "matrix",
83
+ "line",
84
+ "nostr",
85
+ "feishu",
86
+ "msteams",
87
+ "teams",
88
+ "instagram",
89
+ "messenger",
90
+ "twitter",
91
+ "viber",
92
+ "zalo",
93
+ "webhook:inbound"
94
+ ]);
95
+ BLOCKED_MSG = "Blocked: destructive action requires elevated session. Use \"elevate\" or run from CLI with full access.";
96
+ PENDING_MSG = "This action requires confirmation. Ask the user to reply \"confirm\" to proceed.";
97
+ } });
98
+
99
+ //#endregion
100
+ init_destructive_gate();
101
+ exports.applyDestructiveGate = applyDestructiveGate;
@@ -0,0 +1,8 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ require('./paths-AIyBxIzm.js');
3
+ const require_developer_keys = require('./developer-keys-DrrcUqFa.js');
4
+
5
+ exports.createDeveloperKey = require_developer_keys.createDeveloperKey;
6
+ exports.listDeveloperKeys = require_developer_keys.listDeveloperKeys;
7
+ exports.revokeDeveloperKey = require_developer_keys.revokeDeveloperKey;
8
+ exports.validateDeveloperKey = require_developer_keys.validateDeveloperKey;
@@ -0,0 +1,127 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_paths = require('./paths-AIyBxIzm.js');
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const crypto = require_chunk.__toESM(require("crypto"));
6
+
7
+ //#region src/infra/developer-keys.ts
8
+ require_paths.init_paths();
9
+ const KEYS_FILE = "developer-keys.json";
10
+ function getKeysPath(baseDir) {
11
+ const root = baseDir ?? require_paths.getHyperClawDir();
12
+ return path.default.join(root, KEYS_FILE);
13
+ }
14
+ function hashKey(key) {
15
+ return crypto.default.createHash("sha256").update(key, "utf8").digest("hex");
16
+ }
17
+ function generateKey() {
18
+ return `hc_${crypto.default.randomBytes(24).toString("base64url")}`;
19
+ }
20
+ async function loadKeys(baseDir) {
21
+ const fp = getKeysPath(baseDir);
22
+ if (!await fs_extra.default.pathExists(fp)) return [];
23
+ try {
24
+ const data = await fs_extra.default.readJson(fp);
25
+ return Array.isArray(data.keys) ? data.keys : [];
26
+ } catch {
27
+ return [];
28
+ }
29
+ }
30
+ async function saveKeys(keys, baseDir) {
31
+ const fp = getKeysPath(baseDir);
32
+ const dir = path.default.dirname(fp);
33
+ await fs_extra.default.ensureDir(dir);
34
+ await fs_extra.default.writeJson(fp, {
35
+ keys,
36
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
37
+ }, { spaces: 2 });
38
+ }
39
+ /** Create a new developer key. Returns the raw key (show once). Optional tenantId for multi-tenant. */
40
+ async function createDeveloperKey(name, opts) {
41
+ const rawKey = generateKey();
42
+ const keyHash = hashKey(rawKey);
43
+ const id = `key_${crypto.default.randomBytes(8).toString("hex")}`;
44
+ const entry = {
45
+ id,
46
+ name: name || "Unnamed",
47
+ keyHash,
48
+ tenantId: opts?.tenantId,
49
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
50
+ };
51
+ const keys = await loadKeys(opts?.baseDir);
52
+ keys.push(entry);
53
+ await saveKeys(keys, opts?.baseDir);
54
+ return {
55
+ id,
56
+ key: rawKey,
57
+ name: entry.name,
58
+ tenantId: entry.tenantId
59
+ };
60
+ }
61
+ /** List developer keys (without raw keys). Optional tenantId filter. */
62
+ async function listDeveloperKeys(opts) {
63
+ let keys = await loadKeys(opts?.baseDir);
64
+ if (opts?.tenantId) keys = keys.filter((k) => k.tenantId === opts.tenantId);
65
+ return keys.map((k) => ({
66
+ id: k.id,
67
+ name: k.name,
68
+ tenantId: k.tenantId,
69
+ createdAt: k.createdAt,
70
+ lastUsedAt: k.lastUsedAt
71
+ }));
72
+ }
73
+ /** Revoke a developer key by id. */
74
+ async function revokeDeveloperKey(id) {
75
+ const keys = await loadKeys();
76
+ const before = keys.length;
77
+ const filtered = keys.filter((k) => k.id !== id);
78
+ if (filtered.length === before) return false;
79
+ await saveKeys(filtered);
80
+ return true;
81
+ }
82
+ /**
83
+
84
+ * Validate a Bearer token. Returns { valid: true, tenantId?: string } or { valid: false }.
85
+
86
+ * Use with gateway token check: valid = gatewayToken OR result.valid.
87
+
88
+ */
89
+ async function validateDeveloperKey(bearer, opts) {
90
+ if (!bearer || bearer.length < 20) return { valid: false };
91
+ const keys = await loadKeys(opts?.baseDir);
92
+ const hash = hashKey(bearer);
93
+ const idx = keys.findIndex((k) => k.keyHash === hash);
94
+ if (idx < 0) return { valid: false };
95
+ keys[idx].lastUsedAt = (/* @__PURE__ */ new Date()).toISOString();
96
+ await saveKeys(keys, opts?.baseDir).catch(() => {});
97
+ return {
98
+ valid: true,
99
+ tenantId: keys[idx].tenantId
100
+ };
101
+ }
102
+
103
+ //#endregion
104
+ Object.defineProperty(exports, 'createDeveloperKey', {
105
+ enumerable: true,
106
+ get: function () {
107
+ return createDeveloperKey;
108
+ }
109
+ });
110
+ Object.defineProperty(exports, 'listDeveloperKeys', {
111
+ enumerable: true,
112
+ get: function () {
113
+ return listDeveloperKeys;
114
+ }
115
+ });
116
+ Object.defineProperty(exports, 'revokeDeveloperKey', {
117
+ enumerable: true,
118
+ get: function () {
119
+ return revokeDeveloperKey;
120
+ }
121
+ });
122
+ Object.defineProperty(exports, 'validateDeveloperKey', {
123
+ enumerable: true,
124
+ get: function () {
125
+ return validateDeveloperKey;
126
+ }
127
+ });