happy-coder 0.1.10 → 0.1.12

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 (50) hide show
  1. package/README.md +2 -0
  2. package/bin/happy +1 -0
  3. package/bin/happy.cmd +1 -0
  4. package/dist/index-B2GqfEZV.cjs +1564 -0
  5. package/dist/index-QItBXhux.mjs +1540 -0
  6. package/dist/index.cjs +585 -279
  7. package/dist/index.mjs +575 -269
  8. package/dist/install-B0DnBGS_.mjs +29 -0
  9. package/dist/install-B2r_gX72.cjs +109 -0
  10. package/dist/install-C809w0Cj.cjs +31 -0
  11. package/dist/install-DEPy62QN.mjs +97 -0
  12. package/dist/install-GZIzyuIE.cjs +99 -0
  13. package/dist/install-HKe7dyS4.mjs +107 -0
  14. package/dist/lib.cjs +1 -1
  15. package/dist/lib.d.cts +22 -3
  16. package/dist/lib.d.mts +22 -3
  17. package/dist/lib.mjs +1 -1
  18. package/dist/run-BmEaINbl.cjs +250 -0
  19. package/dist/run-DMbKhYfb.mjs +247 -0
  20. package/dist/run-FBXkmmN7.mjs +32 -0
  21. package/dist/run-q2To6b-c.cjs +34 -0
  22. package/dist/types-BRICSarm.mjs +870 -0
  23. package/dist/types-BTQRfIr3.cjs +892 -0
  24. package/dist/types-CEvzGLMI.cjs +882 -0
  25. package/dist/{types-DnQGY77F.mjs → types-D39L8JSd.mjs} +55 -23
  26. package/dist/types-DYBiuNUQ.cjs +883 -0
  27. package/dist/types-Df5dlWLV.mjs +871 -0
  28. package/dist/types-fXgEaaqP.mjs +861 -0
  29. package/dist/{types-B2JzqUiU.cjs → types-hotUTaWz.cjs} +53 -21
  30. package/dist/types-mykDX2xe.cjs +872 -0
  31. package/dist/types-tLWMaptR.mjs +879 -0
  32. package/dist/uninstall-BGgl5V8F.mjs +29 -0
  33. package/dist/uninstall-BWHglipH.mjs +40 -0
  34. package/dist/uninstall-C42CoSCI.cjs +53 -0
  35. package/dist/uninstall-CLkTtlMv.mjs +51 -0
  36. package/dist/uninstall-CdHMb6wi.cjs +31 -0
  37. package/dist/uninstall-FXyyAuGU.cjs +42 -0
  38. package/package.json +9 -3
  39. package/ripgrep/COPYING +3 -0
  40. package/ripgrep/arm64-darwin/rg +0 -0
  41. package/ripgrep/arm64-darwin/ripgrep.node +0 -0
  42. package/ripgrep/arm64-linux/rg +0 -0
  43. package/ripgrep/arm64-linux/ripgrep.node +0 -0
  44. package/ripgrep/x64-darwin/rg +0 -0
  45. package/ripgrep/x64-darwin/ripgrep.node +0 -0
  46. package/ripgrep/x64-linux/rg +0 -0
  47. package/ripgrep/x64-linux/ripgrep.node +0 -0
  48. package/ripgrep/x64-win32/rg.exe +0 -0
  49. package/ripgrep/x64-win32/ripgrep.node +0 -0
  50. package/scripts/ripgrep_launcher.cjs +57 -0
@@ -8,7 +8,7 @@ import { existsSync } from 'node:fs';
8
8
  import { EventEmitter } from 'node:events';
9
9
  import { io } from 'socket.io-client';
10
10
  import { z } from 'zod';
11
- import { randomBytes } from 'node:crypto';
11
+ import { randomBytes, randomUUID } from 'node:crypto';
12
12
  import tweetnacl from 'tweetnacl';
13
13
  import { Expo } from 'expo-server-sdk';
14
14
 
@@ -19,16 +19,20 @@ class Configuration {
19
19
  logsDir;
20
20
  settingsFile;
21
21
  privateKeyFile;
22
+ daemonPidFile;
22
23
  constructor(location) {
23
24
  this.serverUrl = process.env.HANDY_SERVER_URL || "https://handy-api.korshakov.org";
24
25
  if (location === "local") {
25
26
  this.happyDir = join(process.cwd(), ".happy");
26
- } else {
27
+ } else if (location === "global") {
27
28
  this.happyDir = join(homedir(), ".happy");
29
+ } else {
30
+ this.happyDir = join(location, ".happy");
28
31
  }
29
32
  this.logsDir = join(this.happyDir, "logs");
30
33
  this.settingsFile = join(this.happyDir, "settings.json");
31
34
  this.privateKeyFile = join(this.happyDir, "access.key");
35
+ this.daemonPidFile = join(this.happyDir, "daemon.pid");
32
36
  }
33
37
  }
34
38
  let configuration = void 0;
@@ -388,28 +392,39 @@ class ApiSessionClient extends EventEmitter {
388
392
  logger.debug("[API] Socket connection error:", error);
389
393
  });
390
394
  this.socket.on("update", (data) => {
391
- if (data.body.t === "new-message" && data.body.message.content.t === "encrypted") {
392
- const body = decrypt(decodeBase64(data.body.message.content.c), this.secret);
393
- logger.debugLargeJson("[SOCKET] [UPDATE] Received update:", body);
394
- const userResult = UserMessageSchema.safeParse(body);
395
- if (userResult.success) {
396
- if (this.pendingMessageCallback) {
397
- this.pendingMessageCallback(userResult.data);
395
+ try {
396
+ logger.debugLargeJson("[SOCKET] [UPDATE] Received update:", data);
397
+ if (!data.body) {
398
+ logger.debug("[SOCKET] [UPDATE] [ERROR] No body in update!");
399
+ return;
400
+ }
401
+ if (data.body.t === "new-message" && data.body.message.content.t === "encrypted") {
402
+ const body = decrypt(decodeBase64(data.body.message.content.c), this.secret);
403
+ logger.debugLargeJson("[SOCKET] [UPDATE] Received update:", body);
404
+ const userResult = UserMessageSchema.safeParse(body);
405
+ if (userResult.success) {
406
+ if (this.pendingMessageCallback) {
407
+ this.pendingMessageCallback(userResult.data);
408
+ } else {
409
+ this.pendingMessages.push(userResult.data);
410
+ }
398
411
  } else {
399
- this.pendingMessages.push(userResult.data);
412
+ this.emit("message", body);
413
+ }
414
+ } else if (data.body.t === "update-session") {
415
+ if (data.body.metadata && data.body.metadata.version > this.metadataVersion) {
416
+ this.metadata = decrypt(decodeBase64(data.body.metadata.value), this.secret);
417
+ this.metadataVersion = data.body.metadata.version;
418
+ }
419
+ if (data.body.agentState && data.body.agentState.version > this.agentStateVersion) {
420
+ this.agentState = data.body.agentState.value ? decrypt(decodeBase64(data.body.agentState.value), this.secret) : null;
421
+ this.agentStateVersion = data.body.agentState.version;
400
422
  }
401
423
  } else {
402
- this.emit("message", body);
403
- }
404
- } else if (data.body.t === "update-session") {
405
- if (data.body.metadata && data.body.metadata.version > this.metadataVersion) {
406
- this.metadata = decrypt(decodeBase64(data.body.metadata.value), this.secret);
407
- this.metadataVersion = data.body.metadata.version;
408
- }
409
- if (data.body.agentState && data.body.agentState.version > this.agentStateVersion) {
410
- this.agentState = data.body.agentState.value ? decrypt(decodeBase64(data.body.agentState.value), this.secret) : null;
411
- this.agentStateVersion = data.body.agentState.version;
424
+ this.emit("message", data.body);
412
425
  }
426
+ } catch (error) {
427
+ logger.debug("[SOCKET] [UPDATE] [ERROR] Error handling update", { error });
413
428
  }
414
429
  });
415
430
  this.socket.on("error", (error) => {
@@ -470,14 +485,31 @@ class ApiSessionClient extends EventEmitter {
470
485
  }));
471
486
  }
472
487
  }
488
+ sendSessionEvent(event, id) {
489
+ let content = {
490
+ role: "agent",
491
+ content: {
492
+ id: id ?? randomUUID(),
493
+ type: "event",
494
+ data: event
495
+ }
496
+ };
497
+ const encrypted = encodeBase64(encrypt(content, this.secret));
498
+ this.socket.emit("message", {
499
+ sid: this.sessionId,
500
+ message: encrypted
501
+ });
502
+ }
473
503
  /**
474
504
  * Send a ping message to keep the connection alive
475
505
  */
476
- keepAlive(thinking) {
506
+ keepAlive(thinking, mode) {
507
+ logger.debug(`[API] Sending keep alive message: ${thinking}`);
477
508
  this.socket.volatile.emit("session-alive", {
478
509
  sid: this.sessionId,
479
510
  time: Date.now(),
480
- thinking
511
+ thinking,
512
+ mode
481
513
  });
482
514
  }
483
515
  /**
@@ -815,4 +847,4 @@ const RawJSONLinesSchema = z.discriminatedUnion("type", [
815
847
  }).passthrough()
816
848
  ]);
817
849
 
818
- export { ApiClient as A, RawJSONLinesSchema as R, ApiSessionClient as a, initializeConfiguration as b, configuration as c, backoff as d, encodeBase64 as e, encodeBase64Url as f, decodeBase64 as g, delay as h, initLoggerWithGlobalConfiguration as i, encrypt as j, decrypt as k, logger as l };
850
+ export { ApiClient as A, RawJSONLinesSchema as R, ApiSessionClient as a, initializeConfiguration as b, configuration as c, delay as d, backoff as e, encodeBase64 as f, encodeBase64Url as g, decodeBase64 as h, initLoggerWithGlobalConfiguration as i, encrypt as j, decrypt as k, logger as l };