@kmmao/happy-agent 0.3.10 → 0.4.0

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/index.d.cts CHANGED
@@ -361,17 +361,59 @@ declare class TunnelManager {
361
361
  * - CLI-specific logging (debugLargeJson)
362
362
  */
363
363
 
364
+ /** Strongly-typed ephemeral event from server. */
365
+ type EphemeralEvent = {
366
+ type: "activity";
367
+ id: string;
368
+ active: boolean;
369
+ activeAt: number;
370
+ thinking: boolean;
371
+ } | {
372
+ type: "webhook-trigger";
373
+ webhookEventId: string;
374
+ issueNumber: number;
375
+ issueTitle: string;
376
+ issueBody: string;
377
+ issueAuthor: string;
378
+ issueLabels: string[];
379
+ issueUrl: string;
380
+ repoUrl: string;
381
+ repoPath: string;
382
+ provider: string;
383
+ } | {
384
+ type: "supervisor-trigger";
385
+ projectId: string;
386
+ runId: string;
387
+ trigger: string;
388
+ machineId: string;
389
+ repoPath: string;
390
+ mode?: string;
391
+ dimensions?: string[];
392
+ changedFiles?: string[];
393
+ customRules?: string;
394
+ } | {
395
+ type: "task-trigger";
396
+ taskId: string;
397
+ prompt: string;
398
+ directory: string;
399
+ priority: string;
400
+ projectId?: string;
401
+ resultToken?: string;
402
+ skillContents?: Array<{
403
+ name: string;
404
+ content: string;
405
+ }>;
406
+ };
364
407
  type MachineClientOptions = {
365
408
  readonly token: string;
366
409
  readonly machine: Machine;
367
410
  readonly serverUrl: string;
411
+ /** Agent package version for DaemonState reporting. */
412
+ readonly agentVersion?: string;
368
413
  /** Working directory for RPC handlers. Defaults to process.cwd(). */
369
414
  readonly workingDirectory?: string;
370
415
  /** Handler for ephemeral events from server. */
371
- readonly onEphemeral?: (data: {
372
- type: string;
373
- [key: string]: unknown;
374
- }) => void;
416
+ readonly onEphemeral?: (data: EphemeralEvent) => void;
375
417
  };
376
418
  declare class MachineClient {
377
419
  readonly machine: Machine;
@@ -383,11 +425,78 @@ declare class MachineClient {
383
425
  private tunnelManager;
384
426
  private readonly token;
385
427
  private readonly serverUrl;
428
+ private readonly agentVersion;
429
+ private readonly startTime;
386
430
  private readonly onEphemeral?;
431
+ private automationEnabled;
432
+ private automationServerUrl;
433
+ private automationAuthToken;
387
434
  constructor(opts: MachineClientOptions);
435
+ private registerMachineHandlers;
388
436
  connect(): void;
389
437
  updateMachineMetadata(handler: (metadata: MachineMetadata | null) => MachineMetadata): Promise<void>;
390
438
  updateDaemonState(handler: (state: DaemonState | null) => DaemonState): Promise<void>;
439
+ /** Emit a session lifecycle event. */
440
+ emitSessionEvent(sessionId: string, eventType: string, summary: string, detail?: Record<string, unknown>): void;
441
+ /** Report webhook processing status. */
442
+ emitWebhookStatus(data: {
443
+ webhookEventId: string;
444
+ status: "dispatched" | "completed" | "failed";
445
+ sessionId?: string;
446
+ errorMessage?: string;
447
+ }): void;
448
+ /** Report supervisor run status. */
449
+ emitSupervisorRunStatus(data: {
450
+ runId: string;
451
+ projectId: string;
452
+ status: "running" | "completed" | "failed";
453
+ sessionId?: string;
454
+ actionsCount?: number;
455
+ issuesCreated?: number;
456
+ errorMessage?: string;
457
+ }): void;
458
+ /** Submit a knowledge entry from a session. */
459
+ emitSubmitKnowledge(sid: string, entry: {
460
+ entryType: string;
461
+ contributorType: string;
462
+ action: string;
463
+ title: string;
464
+ content: string;
465
+ request?: string;
466
+ outcome?: string;
467
+ tags: string[];
468
+ confidence: string;
469
+ model?: string;
470
+ affectedFiles: string[];
471
+ }): void;
472
+ /** Fetch knowledge for a session. */
473
+ emitFetchKnowledge(sid: string, mode: "auto" | "full" | "minimal", contextHints: string[] | undefined, callback: (response: {
474
+ profile: {
475
+ techStack: string[];
476
+ architectureType?: string;
477
+ knownPitfalls: string[];
478
+ coreConventions: string[];
479
+ lastUpdatedAt: number;
480
+ } | null;
481
+ entries: {
482
+ id: string;
483
+ entryType: string;
484
+ title: string;
485
+ content: string;
486
+ tags: string[];
487
+ confidence: string;
488
+ createdAt: string;
489
+ }[];
490
+ }) => void): void;
491
+ /** Stream task log chunk. */
492
+ emitTaskLog(sid: string, taskId: string, outputFile: string, chunk: string, offset: number): void;
493
+ /**
494
+ * Enable automation handling — agent will process webhook, supervisor,
495
+ * and task triggers from the server by spawning Happy CLI sessions.
496
+ */
497
+ enableAutomation(serverUrl: string, authToken: string): void;
498
+ /** Internal dispatch for ephemeral events that need automation handling. */
499
+ private handleAutomationEvent;
391
500
  /** Seed initial Tailscale info detected before connect. */
392
501
  setTailscaleInfo(info: TailscaleInfo): void;
393
502
  /** Attach a TunnelManager for periodic tunnel state refresh. */
@@ -399,5 +508,26 @@ declare class MachineClient {
399
508
  private stopTailscaleRefresh;
400
509
  }
401
510
 
402
- export { MachineClient, RpcHandlerManager, SessionClient, authLogin, authLogout, authStatus, createRpcHandlerManager, createSession, deleteSession, fetchMessagesAfterSeq, getOrCreateMachine, getSessionMessages, listActiveSessions, listMachines, listSessions, loadConfig, readCredentials, requireCredentials, resolveSessionEncryption, sendMessagesBatch };
403
- export type { Config, Credentials, DecryptedMessage, DecryptedSession, EncryptionVariant, MachineClientOptions, RpcHandler, RpcHandlerConfig, SessionClientOptions, SessionEncryption };
511
+ /**
512
+ * Daemon mode persistent background process that connects to the server,
513
+ * registers RPC handlers, and processes automation triggers.
514
+ *
515
+ * Usage: happy-agent daemon start [--directory <dir>]
516
+ *
517
+ * The daemon:
518
+ * 1. Loads credentials and config
519
+ * 2. Registers/gets machine identity
520
+ * 3. Detects Tailscale and tunnel state
521
+ * 4. Creates MachineClient with all RPC handlers
522
+ * 5. Enables automation (webhook/supervisor/task triggers)
523
+ * 6. Runs until SIGTERM/SIGINT
524
+ */
525
+ declare function startDaemon(options: {
526
+ directory?: string;
527
+ foreground?: boolean;
528
+ }): Promise<void>;
529
+ declare function stopDaemon(): void;
530
+ declare function daemonStatus(): void;
531
+
532
+ export { MachineClient, RpcHandlerManager, SessionClient, authLogin, authLogout, authStatus, createRpcHandlerManager, createSession, daemonStatus, deleteSession, fetchMessagesAfterSeq, getOrCreateMachine, getSessionMessages, listActiveSessions, listMachines, listSessions, loadConfig, readCredentials, requireCredentials, resolveSessionEncryption, sendMessagesBatch, startDaemon, stopDaemon };
533
+ export type { Config, Credentials, DecryptedMessage, DecryptedSession, EncryptionVariant, EphemeralEvent, MachineClientOptions, RpcHandler, RpcHandlerConfig, SessionClientOptions, SessionEncryption };
package/dist/index.d.mts CHANGED
@@ -361,17 +361,59 @@ declare class TunnelManager {
361
361
  * - CLI-specific logging (debugLargeJson)
362
362
  */
363
363
 
364
+ /** Strongly-typed ephemeral event from server. */
365
+ type EphemeralEvent = {
366
+ type: "activity";
367
+ id: string;
368
+ active: boolean;
369
+ activeAt: number;
370
+ thinking: boolean;
371
+ } | {
372
+ type: "webhook-trigger";
373
+ webhookEventId: string;
374
+ issueNumber: number;
375
+ issueTitle: string;
376
+ issueBody: string;
377
+ issueAuthor: string;
378
+ issueLabels: string[];
379
+ issueUrl: string;
380
+ repoUrl: string;
381
+ repoPath: string;
382
+ provider: string;
383
+ } | {
384
+ type: "supervisor-trigger";
385
+ projectId: string;
386
+ runId: string;
387
+ trigger: string;
388
+ machineId: string;
389
+ repoPath: string;
390
+ mode?: string;
391
+ dimensions?: string[];
392
+ changedFiles?: string[];
393
+ customRules?: string;
394
+ } | {
395
+ type: "task-trigger";
396
+ taskId: string;
397
+ prompt: string;
398
+ directory: string;
399
+ priority: string;
400
+ projectId?: string;
401
+ resultToken?: string;
402
+ skillContents?: Array<{
403
+ name: string;
404
+ content: string;
405
+ }>;
406
+ };
364
407
  type MachineClientOptions = {
365
408
  readonly token: string;
366
409
  readonly machine: Machine;
367
410
  readonly serverUrl: string;
411
+ /** Agent package version for DaemonState reporting. */
412
+ readonly agentVersion?: string;
368
413
  /** Working directory for RPC handlers. Defaults to process.cwd(). */
369
414
  readonly workingDirectory?: string;
370
415
  /** Handler for ephemeral events from server. */
371
- readonly onEphemeral?: (data: {
372
- type: string;
373
- [key: string]: unknown;
374
- }) => void;
416
+ readonly onEphemeral?: (data: EphemeralEvent) => void;
375
417
  };
376
418
  declare class MachineClient {
377
419
  readonly machine: Machine;
@@ -383,11 +425,78 @@ declare class MachineClient {
383
425
  private tunnelManager;
384
426
  private readonly token;
385
427
  private readonly serverUrl;
428
+ private readonly agentVersion;
429
+ private readonly startTime;
386
430
  private readonly onEphemeral?;
431
+ private automationEnabled;
432
+ private automationServerUrl;
433
+ private automationAuthToken;
387
434
  constructor(opts: MachineClientOptions);
435
+ private registerMachineHandlers;
388
436
  connect(): void;
389
437
  updateMachineMetadata(handler: (metadata: MachineMetadata | null) => MachineMetadata): Promise<void>;
390
438
  updateDaemonState(handler: (state: DaemonState | null) => DaemonState): Promise<void>;
439
+ /** Emit a session lifecycle event. */
440
+ emitSessionEvent(sessionId: string, eventType: string, summary: string, detail?: Record<string, unknown>): void;
441
+ /** Report webhook processing status. */
442
+ emitWebhookStatus(data: {
443
+ webhookEventId: string;
444
+ status: "dispatched" | "completed" | "failed";
445
+ sessionId?: string;
446
+ errorMessage?: string;
447
+ }): void;
448
+ /** Report supervisor run status. */
449
+ emitSupervisorRunStatus(data: {
450
+ runId: string;
451
+ projectId: string;
452
+ status: "running" | "completed" | "failed";
453
+ sessionId?: string;
454
+ actionsCount?: number;
455
+ issuesCreated?: number;
456
+ errorMessage?: string;
457
+ }): void;
458
+ /** Submit a knowledge entry from a session. */
459
+ emitSubmitKnowledge(sid: string, entry: {
460
+ entryType: string;
461
+ contributorType: string;
462
+ action: string;
463
+ title: string;
464
+ content: string;
465
+ request?: string;
466
+ outcome?: string;
467
+ tags: string[];
468
+ confidence: string;
469
+ model?: string;
470
+ affectedFiles: string[];
471
+ }): void;
472
+ /** Fetch knowledge for a session. */
473
+ emitFetchKnowledge(sid: string, mode: "auto" | "full" | "minimal", contextHints: string[] | undefined, callback: (response: {
474
+ profile: {
475
+ techStack: string[];
476
+ architectureType?: string;
477
+ knownPitfalls: string[];
478
+ coreConventions: string[];
479
+ lastUpdatedAt: number;
480
+ } | null;
481
+ entries: {
482
+ id: string;
483
+ entryType: string;
484
+ title: string;
485
+ content: string;
486
+ tags: string[];
487
+ confidence: string;
488
+ createdAt: string;
489
+ }[];
490
+ }) => void): void;
491
+ /** Stream task log chunk. */
492
+ emitTaskLog(sid: string, taskId: string, outputFile: string, chunk: string, offset: number): void;
493
+ /**
494
+ * Enable automation handling — agent will process webhook, supervisor,
495
+ * and task triggers from the server by spawning Happy CLI sessions.
496
+ */
497
+ enableAutomation(serverUrl: string, authToken: string): void;
498
+ /** Internal dispatch for ephemeral events that need automation handling. */
499
+ private handleAutomationEvent;
391
500
  /** Seed initial Tailscale info detected before connect. */
392
501
  setTailscaleInfo(info: TailscaleInfo): void;
393
502
  /** Attach a TunnelManager for periodic tunnel state refresh. */
@@ -399,5 +508,26 @@ declare class MachineClient {
399
508
  private stopTailscaleRefresh;
400
509
  }
401
510
 
402
- export { MachineClient, RpcHandlerManager, SessionClient, authLogin, authLogout, authStatus, createRpcHandlerManager, createSession, deleteSession, fetchMessagesAfterSeq, getOrCreateMachine, getSessionMessages, listActiveSessions, listMachines, listSessions, loadConfig, readCredentials, requireCredentials, resolveSessionEncryption, sendMessagesBatch };
403
- export type { Config, Credentials, DecryptedMessage, DecryptedSession, EncryptionVariant, MachineClientOptions, RpcHandler, RpcHandlerConfig, SessionClientOptions, SessionEncryption };
511
+ /**
512
+ * Daemon mode persistent background process that connects to the server,
513
+ * registers RPC handlers, and processes automation triggers.
514
+ *
515
+ * Usage: happy-agent daemon start [--directory <dir>]
516
+ *
517
+ * The daemon:
518
+ * 1. Loads credentials and config
519
+ * 2. Registers/gets machine identity
520
+ * 3. Detects Tailscale and tunnel state
521
+ * 4. Creates MachineClient with all RPC handlers
522
+ * 5. Enables automation (webhook/supervisor/task triggers)
523
+ * 6. Runs until SIGTERM/SIGINT
524
+ */
525
+ declare function startDaemon(options: {
526
+ directory?: string;
527
+ foreground?: boolean;
528
+ }): Promise<void>;
529
+ declare function stopDaemon(): void;
530
+ declare function daemonStatus(): void;
531
+
532
+ export { MachineClient, RpcHandlerManager, SessionClient, authLogin, authLogout, authStatus, createRpcHandlerManager, createSession, daemonStatus, deleteSession, fetchMessagesAfterSeq, getOrCreateMachine, getSessionMessages, listActiveSessions, listMachines, listSessions, loadConfig, readCredentials, requireCredentials, resolveSessionEncryption, sendMessagesBatch, startDaemon, stopDaemon };
533
+ export type { Config, Credentials, DecryptedMessage, DecryptedSession, EncryptionVariant, EphemeralEvent, MachineClientOptions, RpcHandler, RpcHandlerConfig, SessionClientOptions, SessionEncryption };