@kmmao/happy-agent 0.5.4 → 0.5.5

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.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { MachineMetadata, DaemonState, TunnelProviderInfo, TunnelEntry, TunnelState } from '@kmmao/happy-wire';
2
+ import * as z from 'zod';
3
3
  import { EventEmitter } from 'node:events';
4
4
  import { Socket } from 'socket.io-client';
5
5
 
@@ -28,6 +28,332 @@ declare function authLogin(config: Config, opts?: {
28
28
  declare function authLogout(config: Config): Promise<void>;
29
29
  declare function authStatus(config: Config): Promise<void>;
30
30
 
31
+ /**
32
+ * Machine-related Zod schemas shared across CLI, Agent, and Server.
33
+ *
34
+ * Single source of truth for MachineMetadata, DaemonState,
35
+ * and Tailscale types. All packages import from here.
36
+ */
37
+
38
+ declare const MachineMetadataSchema: z.ZodObject<{
39
+ host: z.ZodString;
40
+ platform: z.ZodString;
41
+ happyCliVersion: z.ZodString;
42
+ homeDir: z.ZodString;
43
+ happyHomeDir: z.ZodString;
44
+ happyLibDir: z.ZodString;
45
+ }, z.core.$strip>;
46
+ type MachineMetadata = z.infer<typeof MachineMetadataSchema>;
47
+ declare const TunnelEntrySchema: z.ZodObject<{
48
+ provider: z.ZodString;
49
+ localPort: z.ZodNumber;
50
+ remotePort: z.ZodOptional<z.ZodNumber>;
51
+ protocol: z.ZodString;
52
+ path: z.ZodOptional<z.ZodString>;
53
+ target: z.ZodString;
54
+ publicUrl: z.ZodOptional<z.ZodString>;
55
+ accessScope: z.ZodEnum<{
56
+ public: "public";
57
+ private: "private";
58
+ tailnet: "tailnet";
59
+ }>;
60
+ hostname: z.ZodOptional<z.ZodString>;
61
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
62
+ }, z.core.$strip>;
63
+ type TunnelEntry = z.infer<typeof TunnelEntrySchema>;
64
+ declare const TunnelProviderInfoSchema: z.ZodObject<{
65
+ provider: z.ZodString;
66
+ status: z.ZodEnum<{
67
+ "not-installed": "not-installed";
68
+ available: "available";
69
+ unavailable: "unavailable";
70
+ }>;
71
+ version: z.ZodOptional<z.ZodString>;
72
+ entries: z.ZodArray<z.ZodObject<{
73
+ provider: z.ZodString;
74
+ localPort: z.ZodNumber;
75
+ remotePort: z.ZodOptional<z.ZodNumber>;
76
+ protocol: z.ZodString;
77
+ path: z.ZodOptional<z.ZodString>;
78
+ target: z.ZodString;
79
+ publicUrl: z.ZodOptional<z.ZodString>;
80
+ accessScope: z.ZodEnum<{
81
+ public: "public";
82
+ private: "private";
83
+ tailnet: "tailnet";
84
+ }>;
85
+ hostname: z.ZodOptional<z.ZodString>;
86
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
87
+ }, z.core.$strip>>;
88
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
89
+ }, z.core.$strip>;
90
+ type TunnelProviderInfo = z.infer<typeof TunnelProviderInfoSchema>;
91
+ declare const TunnelStateSchema: z.ZodObject<{
92
+ providers: z.ZodArray<z.ZodObject<{
93
+ provider: z.ZodString;
94
+ status: z.ZodEnum<{
95
+ "not-installed": "not-installed";
96
+ available: "available";
97
+ unavailable: "unavailable";
98
+ }>;
99
+ version: z.ZodOptional<z.ZodString>;
100
+ entries: z.ZodArray<z.ZodObject<{
101
+ provider: z.ZodString;
102
+ localPort: z.ZodNumber;
103
+ remotePort: z.ZodOptional<z.ZodNumber>;
104
+ protocol: z.ZodString;
105
+ path: z.ZodOptional<z.ZodString>;
106
+ target: z.ZodString;
107
+ publicUrl: z.ZodOptional<z.ZodString>;
108
+ accessScope: z.ZodEnum<{
109
+ public: "public";
110
+ private: "private";
111
+ tailnet: "tailnet";
112
+ }>;
113
+ hostname: z.ZodOptional<z.ZodString>;
114
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
115
+ }, z.core.$strip>>;
116
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
117
+ }, z.core.$strip>>;
118
+ }, z.core.$strip>;
119
+ type TunnelState = z.infer<typeof TunnelStateSchema>;
120
+ declare const DaemonStateSchema: z.ZodObject<{
121
+ status: z.ZodUnion<readonly [z.ZodEnum<{
122
+ running: "running";
123
+ "shutting-down": "shutting-down";
124
+ }>, z.ZodString]>;
125
+ pid: z.ZodOptional<z.ZodNumber>;
126
+ httpPort: z.ZodOptional<z.ZodNumber>;
127
+ startTime: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
128
+ startedAt: z.ZodOptional<z.ZodNumber>;
129
+ startedWithCliVersion: z.ZodOptional<z.ZodString>;
130
+ shutdownRequestedAt: z.ZodOptional<z.ZodNumber>;
131
+ shutdownSource: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
132
+ unknown: "unknown";
133
+ "mobile-app": "mobile-app";
134
+ cli: "cli";
135
+ "os-signal": "os-signal";
136
+ }>, z.ZodString]>>;
137
+ tailscale: z.ZodOptional<z.ZodObject<{
138
+ status: z.ZodEnum<{
139
+ connected: "connected";
140
+ disconnected: "disconnected";
141
+ "not-installed": "not-installed";
142
+ }>;
143
+ ipv4: z.ZodOptional<z.ZodString>;
144
+ ipv6: z.ZodOptional<z.ZodString>;
145
+ hostname: z.ZodOptional<z.ZodString>;
146
+ tailnetName: z.ZodOptional<z.ZodString>;
147
+ version: z.ZodOptional<z.ZodString>;
148
+ serves: z.ZodOptional<z.ZodArray<z.ZodObject<{
149
+ port: z.ZodNumber;
150
+ path: z.ZodOptional<z.ZodString>;
151
+ protocol: z.ZodString;
152
+ target: z.ZodString;
153
+ funnel: z.ZodBoolean;
154
+ hostname: z.ZodString;
155
+ }, z.core.$strip>>>;
156
+ }, z.core.$strip>>;
157
+ tunnels: z.ZodOptional<z.ZodObject<{
158
+ providers: z.ZodArray<z.ZodObject<{
159
+ provider: z.ZodString;
160
+ status: z.ZodEnum<{
161
+ "not-installed": "not-installed";
162
+ available: "available";
163
+ unavailable: "unavailable";
164
+ }>;
165
+ version: z.ZodOptional<z.ZodString>;
166
+ entries: z.ZodArray<z.ZodObject<{
167
+ provider: z.ZodString;
168
+ localPort: z.ZodNumber;
169
+ remotePort: z.ZodOptional<z.ZodNumber>;
170
+ protocol: z.ZodString;
171
+ path: z.ZodOptional<z.ZodString>;
172
+ target: z.ZodString;
173
+ publicUrl: z.ZodOptional<z.ZodString>;
174
+ accessScope: z.ZodEnum<{
175
+ public: "public";
176
+ private: "private";
177
+ tailnet: "tailnet";
178
+ }>;
179
+ hostname: z.ZodOptional<z.ZodString>;
180
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
181
+ }, z.core.$strip>>;
182
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
183
+ }, z.core.$strip>>;
184
+ }, z.core.$strip>>;
185
+ automation: z.ZodOptional<z.ZodObject<{
186
+ updatedAt: z.ZodNumber;
187
+ counts: z.ZodObject<{
188
+ queued: z.ZodNumber;
189
+ dispatching: z.ZodNumber;
190
+ running: z.ZodNumber;
191
+ completed: z.ZodNumber;
192
+ failed: z.ZodNumber;
193
+ cancelled: z.ZodNumber;
194
+ }, z.core.$strip>;
195
+ recentJobs: z.ZodArray<z.ZodObject<{
196
+ id: z.ZodString;
197
+ kind: z.ZodEnum<{
198
+ supervisor: "supervisor";
199
+ webhook: "webhook";
200
+ agent_loop: "agent_loop";
201
+ task: "task";
202
+ }>;
203
+ status: z.ZodEnum<{
204
+ running: "running";
205
+ queued: "queued";
206
+ dispatching: "dispatching";
207
+ completed: "completed";
208
+ failed: "failed";
209
+ cancelled: "cancelled";
210
+ }>;
211
+ priority: z.ZodEnum<{
212
+ urgent: "urgent";
213
+ user: "user";
214
+ background: "background";
215
+ }>;
216
+ dedupeKey: z.ZodString;
217
+ attempt: z.ZodNumber;
218
+ maxAttempts: z.ZodNumber;
219
+ createdAt: z.ZodNumber;
220
+ updatedAt: z.ZodNumber;
221
+ dispatchedAt: z.ZodOptional<z.ZodNumber>;
222
+ completedAt: z.ZodOptional<z.ZodNumber>;
223
+ nextRunAt: z.ZodOptional<z.ZodNumber>;
224
+ sessionId: z.ZodOptional<z.ZodString>;
225
+ label: z.ZodOptional<z.ZodString>;
226
+ projectId: z.ZodOptional<z.ZodString>;
227
+ runId: z.ZodOptional<z.ZodString>;
228
+ loopId: z.ZodOptional<z.ZodString>;
229
+ loopIteration: z.ZodOptional<z.ZodNumber>;
230
+ continuityKey: z.ZodOptional<z.ZodString>;
231
+ errorMessage: z.ZodOptional<z.ZodString>;
232
+ recovered: z.ZodOptional<z.ZodBoolean>;
233
+ }, z.core.$strip>>;
234
+ guardians: z.ZodOptional<z.ZodArray<z.ZodObject<{
235
+ key: z.ZodString;
236
+ projectId: z.ZodString;
237
+ loopId: z.ZodOptional<z.ZodString>;
238
+ sessionId: z.ZodString;
239
+ updatedAt: z.ZodNumber;
240
+ lastRunId: z.ZodOptional<z.ZodString>;
241
+ attached: z.ZodOptional<z.ZodBoolean>;
242
+ recovered: z.ZodOptional<z.ZodBoolean>;
243
+ }, z.core.$strip>>>;
244
+ guardianUsage: z.ZodOptional<z.ZodArray<z.ZodObject<{
245
+ key: z.ZodString;
246
+ projectId: z.ZodOptional<z.ZodString>;
247
+ loopId: z.ZodOptional<z.ZodString>;
248
+ reuseCount: z.ZodNumber;
249
+ rememberCount: z.ZodNumber;
250
+ resetCount: z.ZodNumber;
251
+ lastUsedAt: z.ZodNumber;
252
+ currentSessionId: z.ZodOptional<z.ZodString>;
253
+ }, z.core.$strip>>>;
254
+ auditStats: z.ZodOptional<z.ZodObject<{
255
+ totalEvents: z.ZodNumber;
256
+ lastEventAt: z.ZodOptional<z.ZodNumber>;
257
+ queuedCount: z.ZodNumber;
258
+ sessionStartedCount: z.ZodNumber;
259
+ terminalCompletedCount: z.ZodNumber;
260
+ terminalFailedCount: z.ZodNumber;
261
+ terminalCancelledCount: z.ZodNumber;
262
+ guardianReuseCount: z.ZodNumber;
263
+ guardianRememberCount: z.ZodNumber;
264
+ guardianResetCount: z.ZodNumber;
265
+ sessionReattachedCount: z.ZodNumber;
266
+ watchdogStopCount: z.ZodNumber;
267
+ stopRequestCount: z.ZodNumber;
268
+ guardianEligibleRunCount: z.ZodNumber;
269
+ guardianReuseRate: z.ZodNumber;
270
+ activeGuardianCount: z.ZodNumber;
271
+ }, z.core.$strip>>;
272
+ recentAuditEvents: z.ZodOptional<z.ZodArray<z.ZodObject<{
273
+ id: z.ZodString;
274
+ occurredAt: z.ZodNumber;
275
+ kind: z.ZodString;
276
+ jobId: z.ZodOptional<z.ZodString>;
277
+ dedupeKey: z.ZodOptional<z.ZodString>;
278
+ sessionId: z.ZodOptional<z.ZodString>;
279
+ projectId: z.ZodOptional<z.ZodString>;
280
+ runId: z.ZodOptional<z.ZodString>;
281
+ loopId: z.ZodOptional<z.ZodString>;
282
+ trigger: z.ZodOptional<z.ZodString>;
283
+ status: z.ZodOptional<z.ZodString>;
284
+ guardianKey: z.ZodOptional<z.ZodString>;
285
+ guardianSessionId: z.ZodOptional<z.ZodString>;
286
+ message: z.ZodOptional<z.ZodString>;
287
+ }, z.core.$strip>>>;
288
+ loops: z.ZodOptional<z.ZodArray<z.ZodObject<{
289
+ id: z.ZodString;
290
+ name: z.ZodOptional<z.ZodString>;
291
+ directory: z.ZodString;
292
+ enabled: z.ZodBoolean;
293
+ intervalMs: z.ZodNumber;
294
+ cronExpression: z.ZodOptional<z.ZodString>;
295
+ iteration: z.ZodNumber;
296
+ nextRunAt: z.ZodNumber;
297
+ runtimeState: z.ZodString;
298
+ phase: z.ZodString;
299
+ lastTriggerSource: z.ZodOptional<z.ZodString>;
300
+ lastBriefSummary: z.ZodOptional<z.ZodString>;
301
+ lastError: z.ZodOptional<z.ZodString>;
302
+ agent: z.ZodString;
303
+ }, z.core.$strip>>>;
304
+ bootstrapProfiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
305
+ id: z.ZodString;
306
+ name: z.ZodOptional<z.ZodString>;
307
+ rootDirectory: z.ZodString;
308
+ intervalMs: z.ZodNumber;
309
+ enabled: z.ZodBoolean;
310
+ status: z.ZodString;
311
+ statusUpdatedAt: z.ZodNumber;
312
+ lastRunAt: z.ZodOptional<z.ZodNumber>;
313
+ lastRepoCount: z.ZodOptional<z.ZodNumber>;
314
+ lastSuggestionCount: z.ZodOptional<z.ZodNumber>;
315
+ lastError: z.ZodOptional<z.ZodString>;
316
+ }, z.core.$strip>>>;
317
+ autoDreamProfiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
318
+ id: z.ZodString;
319
+ name: z.ZodOptional<z.ZodString>;
320
+ rootDirectory: z.ZodString;
321
+ intervalMs: z.ZodNumber;
322
+ enabled: z.ZodBoolean;
323
+ nextRunAt: z.ZodNumber;
324
+ status: z.ZodString;
325
+ stage: z.ZodString;
326
+ statusUpdatedAt: z.ZodNumber;
327
+ lastRunAt: z.ZodOptional<z.ZodNumber>;
328
+ lastMemoryFiles: z.ZodOptional<z.ZodNumber>;
329
+ lastError: z.ZodOptional<z.ZodString>;
330
+ }, z.core.$strip>>>;
331
+ }, z.core.$strip>>;
332
+ recentBriefs: z.ZodOptional<z.ZodArray<z.ZodObject<{
333
+ loopId: z.ZodString;
334
+ loopName: z.ZodOptional<z.ZodString>;
335
+ status: z.ZodEnum<{
336
+ completed: "completed";
337
+ failed: "failed";
338
+ cancelled: "cancelled";
339
+ }>;
340
+ summary: z.ZodString;
341
+ detail: z.ZodString;
342
+ generatedAt: z.ZodNumber;
343
+ sessionId: z.ZodOptional<z.ZodString>;
344
+ }, z.core.$strip>>>;
345
+ cliInstall: z.ZodOptional<z.ZodObject<{
346
+ source: z.ZodEnum<{
347
+ unknown: "unknown";
348
+ "npm-global": "npm-global";
349
+ "local-source": "local-source";
350
+ }>;
351
+ canSelfUpgrade: z.ZodBoolean;
352
+ }, z.core.$strip>>;
353
+ killed: z.ZodOptional<z.ZodBoolean>;
354
+ }, z.core.$strip>;
355
+ type DaemonState = z.infer<typeof DaemonStateSchema>;
356
+
31
357
  type EncryptionVariant = "legacy" | "dataKey";
32
358
  type SessionEncryption = {
33
359
  readonly key: Uint8Array;
@@ -54,6 +380,7 @@ type DecryptedSession = {
54
380
  active: boolean;
55
381
  activeAt: number;
56
382
  metadata: unknown;
383
+ metadataVersion: number;
57
384
  agentState: unknown | null;
58
385
  dataEncryptionKey: string | null;
59
386
  encryption: SessionEncryption;
@@ -229,6 +556,8 @@ type SessionClientOptions = {
229
556
  readonly encryptionVariant: EncryptionVariant;
230
557
  readonly token: string;
231
558
  readonly serverUrl: string;
559
+ readonly initialMetadata?: unknown | null;
560
+ readonly initialMetadataVersion?: number;
232
561
  readonly initialAgentState?: unknown | null;
233
562
  /** Working directory for RPC handlers (bash cwd, file operations). Defaults to process.cwd(). */
234
563
  readonly workingDirectory?: string;
@@ -250,13 +579,16 @@ declare class SessionClient extends EventEmitter {
250
579
  constructor(opts: SessionClientOptions);
251
580
  sendMessage(text: string, meta?: Record<string, unknown>): void;
252
581
  getMetadata(): unknown | null;
582
+ getMetadataVersion(): number;
253
583
  getAgentState(): unknown | null;
254
584
  setThinking(thinking: boolean): void;
255
585
  waitForConnect(timeoutMs?: number): Promise<void>;
256
586
  waitForIdle(timeoutMs?: number): Promise<void>;
257
587
  sendStop(): void;
258
588
  close(): void;
589
+ private updateMetadataOnce;
259
590
  updateMetadata(newMetadata: unknown): Promise<void>;
591
+ updateMetadataWith(handler: (metadata: unknown | null) => unknown): Promise<void>;
260
592
  updateAgentState(newState: unknown | null): Promise<void>;
261
593
  private setupSocketListeners;
262
594
  }