@zhigang1992/happy-cli 0.12.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 (47) hide show
  1. package/README.md +60 -0
  2. package/bin/happy-mcp.mjs +32 -0
  3. package/bin/happy.mjs +35 -0
  4. package/dist/codex/happyMcpStdioBridge.cjs +80 -0
  5. package/dist/codex/happyMcpStdioBridge.d.cts +2 -0
  6. package/dist/codex/happyMcpStdioBridge.d.mts +2 -0
  7. package/dist/codex/happyMcpStdioBridge.mjs +78 -0
  8. package/dist/index-BOBrKhX5.cjs +6655 -0
  9. package/dist/index-DsHtmQqP.mjs +6624 -0
  10. package/dist/index.cjs +42 -0
  11. package/dist/index.d.cts +1 -0
  12. package/dist/index.d.mts +1 -0
  13. package/dist/index.mjs +39 -0
  14. package/dist/lib.cjs +31 -0
  15. package/dist/lib.d.cts +817 -0
  16. package/dist/lib.d.mts +817 -0
  17. package/dist/lib.mjs +21 -0
  18. package/dist/list-BW6QBLa1.cjs +328 -0
  19. package/dist/list-hET5tyMc.mjs +326 -0
  20. package/dist/prompt-DXkgjktW.cjs +203 -0
  21. package/dist/prompt-Dz7G8yGx.mjs +201 -0
  22. package/dist/runCodex-CLGYMNs2.mjs +1335 -0
  23. package/dist/runCodex-CylcX5Ug.cjs +1338 -0
  24. package/dist/types-BsjUgWOx.cjs +2264 -0
  25. package/dist/types-CGco5Y-r.mjs +2213 -0
  26. package/package.json +126 -0
  27. package/scripts/claude_local_launcher.cjs +98 -0
  28. package/scripts/claude_remote_launcher.cjs +13 -0
  29. package/scripts/ripgrep_launcher.cjs +33 -0
  30. package/scripts/unpack-tools.cjs +163 -0
  31. package/tools/archives/difftastic-LICENSE +21 -0
  32. package/tools/archives/difftastic-arm64-darwin.tar.gz +0 -0
  33. package/tools/archives/difftastic-arm64-linux.tar.gz +0 -0
  34. package/tools/archives/difftastic-x64-darwin.tar.gz +0 -0
  35. package/tools/archives/difftastic-x64-linux.tar.gz +0 -0
  36. package/tools/archives/difftastic-x64-win32.tar.gz +0 -0
  37. package/tools/archives/ripgrep-LICENSE +3 -0
  38. package/tools/archives/ripgrep-arm64-darwin.tar.gz +0 -0
  39. package/tools/archives/ripgrep-arm64-linux.tar.gz +0 -0
  40. package/tools/archives/ripgrep-x64-darwin.tar.gz +0 -0
  41. package/tools/archives/ripgrep-x64-linux.tar.gz +0 -0
  42. package/tools/archives/ripgrep-x64-win32.tar.gz +0 -0
  43. package/tools/licenses/difftastic-LICENSE +21 -0
  44. package/tools/licenses/ripgrep-LICENSE +3 -0
  45. package/tools/unpacked/difft +0 -0
  46. package/tools/unpacked/rg +0 -0
  47. package/tools/unpacked/ripgrep.node +0 -0
package/dist/lib.d.cts ADDED
@@ -0,0 +1,817 @@
1
+ import { z } from 'zod';
2
+ import { EventEmitter } from 'node:events';
3
+ import { Socket } from 'socket.io-client';
4
+ import { ExpoPushMessage } from 'expo-server-sdk';
5
+
6
+ /**
7
+ * Simplified schema that only validates fields actually used in the codebase
8
+ * while preserving all other fields through passthrough()
9
+ */
10
+
11
+ declare const UsageSchema: z.ZodObject<{
12
+ input_tokens: z.ZodNumber;
13
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
14
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
15
+ output_tokens: z.ZodNumber;
16
+ service_tier: z.ZodOptional<z.ZodString>;
17
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
18
+ input_tokens: z.ZodNumber;
19
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
20
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
21
+ output_tokens: z.ZodNumber;
22
+ service_tier: z.ZodOptional<z.ZodString>;
23
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
24
+ input_tokens: z.ZodNumber;
25
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
26
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
27
+ output_tokens: z.ZodNumber;
28
+ service_tier: z.ZodOptional<z.ZodString>;
29
+ }, z.ZodTypeAny, "passthrough">>;
30
+ declare const RawJSONLinesSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
31
+ type: z.ZodLiteral<"user">;
32
+ isSidechain: z.ZodOptional<z.ZodBoolean>;
33
+ isMeta: z.ZodOptional<z.ZodBoolean>;
34
+ uuid: z.ZodString;
35
+ message: z.ZodObject<{
36
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
37
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
38
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
39
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
40
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
41
+ }, z.ZodTypeAny, "passthrough">>;
42
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
43
+ type: z.ZodLiteral<"user">;
44
+ isSidechain: z.ZodOptional<z.ZodBoolean>;
45
+ isMeta: z.ZodOptional<z.ZodBoolean>;
46
+ uuid: z.ZodString;
47
+ message: z.ZodObject<{
48
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
49
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
50
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
51
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
52
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
53
+ }, z.ZodTypeAny, "passthrough">>;
54
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
55
+ type: z.ZodLiteral<"user">;
56
+ isSidechain: z.ZodOptional<z.ZodBoolean>;
57
+ isMeta: z.ZodOptional<z.ZodBoolean>;
58
+ uuid: z.ZodString;
59
+ message: z.ZodObject<{
60
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
61
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
62
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
63
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
64
+ content: z.ZodUnion<[z.ZodString, z.ZodAny]>;
65
+ }, z.ZodTypeAny, "passthrough">>;
66
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
67
+ uuid: z.ZodString;
68
+ type: z.ZodLiteral<"assistant">;
69
+ message: z.ZodObject<{
70
+ usage: z.ZodOptional<z.ZodObject<{
71
+ input_tokens: z.ZodNumber;
72
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
73
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
74
+ output_tokens: z.ZodNumber;
75
+ service_tier: z.ZodOptional<z.ZodString>;
76
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
77
+ input_tokens: z.ZodNumber;
78
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
79
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
80
+ output_tokens: z.ZodNumber;
81
+ service_tier: z.ZodOptional<z.ZodString>;
82
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
83
+ input_tokens: z.ZodNumber;
84
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
85
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
86
+ output_tokens: z.ZodNumber;
87
+ service_tier: z.ZodOptional<z.ZodString>;
88
+ }, z.ZodTypeAny, "passthrough">>>;
89
+ content: z.ZodAny;
90
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
91
+ usage: z.ZodOptional<z.ZodObject<{
92
+ input_tokens: z.ZodNumber;
93
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
94
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
95
+ output_tokens: z.ZodNumber;
96
+ service_tier: z.ZodOptional<z.ZodString>;
97
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
98
+ input_tokens: z.ZodNumber;
99
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
100
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
101
+ output_tokens: z.ZodNumber;
102
+ service_tier: z.ZodOptional<z.ZodString>;
103
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
104
+ input_tokens: z.ZodNumber;
105
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
106
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
107
+ output_tokens: z.ZodNumber;
108
+ service_tier: z.ZodOptional<z.ZodString>;
109
+ }, z.ZodTypeAny, "passthrough">>>;
110
+ content: z.ZodAny;
111
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
112
+ usage: z.ZodOptional<z.ZodObject<{
113
+ input_tokens: z.ZodNumber;
114
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
115
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
116
+ output_tokens: z.ZodNumber;
117
+ service_tier: z.ZodOptional<z.ZodString>;
118
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
119
+ input_tokens: z.ZodNumber;
120
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
121
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
122
+ output_tokens: z.ZodNumber;
123
+ service_tier: z.ZodOptional<z.ZodString>;
124
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
125
+ input_tokens: z.ZodNumber;
126
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
127
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
128
+ output_tokens: z.ZodNumber;
129
+ service_tier: z.ZodOptional<z.ZodString>;
130
+ }, z.ZodTypeAny, "passthrough">>>;
131
+ content: z.ZodAny;
132
+ }, z.ZodTypeAny, "passthrough">>;
133
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
134
+ uuid: z.ZodString;
135
+ type: z.ZodLiteral<"assistant">;
136
+ message: z.ZodObject<{
137
+ usage: z.ZodOptional<z.ZodObject<{
138
+ input_tokens: z.ZodNumber;
139
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
140
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
141
+ output_tokens: z.ZodNumber;
142
+ service_tier: z.ZodOptional<z.ZodString>;
143
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
144
+ input_tokens: z.ZodNumber;
145
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
146
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
147
+ output_tokens: z.ZodNumber;
148
+ service_tier: z.ZodOptional<z.ZodString>;
149
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
150
+ input_tokens: z.ZodNumber;
151
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
152
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
153
+ output_tokens: z.ZodNumber;
154
+ service_tier: z.ZodOptional<z.ZodString>;
155
+ }, z.ZodTypeAny, "passthrough">>>;
156
+ content: z.ZodAny;
157
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
158
+ usage: z.ZodOptional<z.ZodObject<{
159
+ input_tokens: z.ZodNumber;
160
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
161
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
162
+ output_tokens: z.ZodNumber;
163
+ service_tier: z.ZodOptional<z.ZodString>;
164
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
165
+ input_tokens: z.ZodNumber;
166
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
167
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
168
+ output_tokens: z.ZodNumber;
169
+ service_tier: z.ZodOptional<z.ZodString>;
170
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
171
+ input_tokens: z.ZodNumber;
172
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
173
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
174
+ output_tokens: z.ZodNumber;
175
+ service_tier: z.ZodOptional<z.ZodString>;
176
+ }, z.ZodTypeAny, "passthrough">>>;
177
+ content: z.ZodAny;
178
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
179
+ usage: z.ZodOptional<z.ZodObject<{
180
+ input_tokens: z.ZodNumber;
181
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
182
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
183
+ output_tokens: z.ZodNumber;
184
+ service_tier: z.ZodOptional<z.ZodString>;
185
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
186
+ input_tokens: z.ZodNumber;
187
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
188
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
189
+ output_tokens: z.ZodNumber;
190
+ service_tier: z.ZodOptional<z.ZodString>;
191
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
192
+ input_tokens: z.ZodNumber;
193
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
194
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
195
+ output_tokens: z.ZodNumber;
196
+ service_tier: z.ZodOptional<z.ZodString>;
197
+ }, z.ZodTypeAny, "passthrough">>>;
198
+ content: z.ZodAny;
199
+ }, z.ZodTypeAny, "passthrough">>;
200
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
201
+ uuid: z.ZodString;
202
+ type: z.ZodLiteral<"assistant">;
203
+ message: z.ZodObject<{
204
+ usage: z.ZodOptional<z.ZodObject<{
205
+ input_tokens: z.ZodNumber;
206
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
207
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
208
+ output_tokens: z.ZodNumber;
209
+ service_tier: z.ZodOptional<z.ZodString>;
210
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
211
+ input_tokens: z.ZodNumber;
212
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
213
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
214
+ output_tokens: z.ZodNumber;
215
+ service_tier: z.ZodOptional<z.ZodString>;
216
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
217
+ input_tokens: z.ZodNumber;
218
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
219
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
220
+ output_tokens: z.ZodNumber;
221
+ service_tier: z.ZodOptional<z.ZodString>;
222
+ }, z.ZodTypeAny, "passthrough">>>;
223
+ content: z.ZodAny;
224
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
225
+ usage: z.ZodOptional<z.ZodObject<{
226
+ input_tokens: z.ZodNumber;
227
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
228
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
229
+ output_tokens: z.ZodNumber;
230
+ service_tier: z.ZodOptional<z.ZodString>;
231
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
232
+ input_tokens: z.ZodNumber;
233
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
234
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
235
+ output_tokens: z.ZodNumber;
236
+ service_tier: z.ZodOptional<z.ZodString>;
237
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
238
+ input_tokens: z.ZodNumber;
239
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
240
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
241
+ output_tokens: z.ZodNumber;
242
+ service_tier: z.ZodOptional<z.ZodString>;
243
+ }, z.ZodTypeAny, "passthrough">>>;
244
+ content: z.ZodAny;
245
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
246
+ usage: z.ZodOptional<z.ZodObject<{
247
+ input_tokens: z.ZodNumber;
248
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
249
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
250
+ output_tokens: z.ZodNumber;
251
+ service_tier: z.ZodOptional<z.ZodString>;
252
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
253
+ input_tokens: z.ZodNumber;
254
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
255
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
256
+ output_tokens: z.ZodNumber;
257
+ service_tier: z.ZodOptional<z.ZodString>;
258
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
259
+ input_tokens: z.ZodNumber;
260
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
261
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
262
+ output_tokens: z.ZodNumber;
263
+ service_tier: z.ZodOptional<z.ZodString>;
264
+ }, z.ZodTypeAny, "passthrough">>>;
265
+ content: z.ZodAny;
266
+ }, z.ZodTypeAny, "passthrough">>;
267
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
268
+ type: z.ZodLiteral<"summary">;
269
+ summary: z.ZodString;
270
+ leafUuid: z.ZodString;
271
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
272
+ type: z.ZodLiteral<"summary">;
273
+ summary: z.ZodString;
274
+ leafUuid: z.ZodString;
275
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
276
+ type: z.ZodLiteral<"summary">;
277
+ summary: z.ZodString;
278
+ leafUuid: z.ZodString;
279
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
280
+ type: z.ZodLiteral<"system">;
281
+ uuid: z.ZodString;
282
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
283
+ type: z.ZodLiteral<"system">;
284
+ uuid: z.ZodString;
285
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
286
+ type: z.ZodLiteral<"system">;
287
+ uuid: z.ZodString;
288
+ }, z.ZodTypeAny, "passthrough">>]>;
289
+ type RawJSONLines = z.infer<typeof RawJSONLinesSchema>;
290
+
291
+ /**
292
+ * Common RPC types and interfaces for both session and machine clients
293
+ */
294
+ /**
295
+ * Generic RPC handler function type
296
+ * @template TRequest - The request data type
297
+ * @template TResponse - The response data type
298
+ */
299
+ type RpcHandler<TRequest = any, TResponse = any> = (data: TRequest) => TResponse | Promise<TResponse>;
300
+ /**
301
+ * RPC request data from server
302
+ */
303
+ interface RpcRequest {
304
+ method: string;
305
+ params: string;
306
+ }
307
+ /**
308
+ * Configuration for RPC handler manager
309
+ */
310
+ interface RpcHandlerConfig {
311
+ scopePrefix: string;
312
+ encryptionKey: Uint8Array;
313
+ encryptionVariant: 'legacy' | 'dataKey';
314
+ logger?: (message: string, data?: any) => void;
315
+ }
316
+
317
+ /**
318
+ * Generic RPC handler manager for session and machine clients
319
+ * Manages RPC method registration, encryption/decryption, and handler execution
320
+ */
321
+
322
+ declare class RpcHandlerManager {
323
+ private handlers;
324
+ private readonly scopePrefix;
325
+ private readonly encryptionKey;
326
+ private readonly encryptionVariant;
327
+ private readonly logger;
328
+ private socket;
329
+ constructor(config: RpcHandlerConfig);
330
+ /**
331
+ * Register an RPC handler for a specific method
332
+ * @param method - The method name (without prefix)
333
+ * @param handler - The handler function
334
+ */
335
+ registerHandler<TRequest = any, TResponse = any>(method: string, handler: RpcHandler<TRequest, TResponse>): void;
336
+ /**
337
+ * Handle an incoming RPC request
338
+ * @param request - The RPC request data
339
+ * @param callback - The response callback
340
+ */
341
+ handleRequest(request: RpcRequest): Promise<any>;
342
+ onSocketConnect(socket: Socket): void;
343
+ onSocketDisconnect(): void;
344
+ /**
345
+ * Get the number of registered handlers
346
+ */
347
+ getHandlerCount(): number;
348
+ /**
349
+ * Check if a handler is registered
350
+ * @param method - The method name (without prefix)
351
+ */
352
+ hasHandler(method: string): boolean;
353
+ /**
354
+ * Clear all handlers
355
+ */
356
+ clearHandlers(): void;
357
+ /**
358
+ * Get the prefixed method name
359
+ * @param method - The method name
360
+ */
361
+ private getPrefixedMethod;
362
+ }
363
+
364
+ declare class ApiSessionClient extends EventEmitter {
365
+ private readonly token;
366
+ readonly sessionId: string;
367
+ private metadata;
368
+ private metadataVersion;
369
+ private agentState;
370
+ private agentStateVersion;
371
+ private socket;
372
+ private pendingMessages;
373
+ private pendingMessageCallback;
374
+ readonly rpcHandlerManager: RpcHandlerManager;
375
+ private agentStateLock;
376
+ private metadataLock;
377
+ private encryptionKey;
378
+ private encryptionVariant;
379
+ constructor(token: string, session: Session);
380
+ onUserMessage(callback: (data: UserMessage) => void): void;
381
+ /**
382
+ * Send message to session
383
+ * @param body - Message body (can be MessageContent or raw content for agent messages)
384
+ */
385
+ sendClaudeSessionMessage(body: RawJSONLines): void;
386
+ sendCodexMessage(body: any): void;
387
+ sendSessionEvent(event: {
388
+ type: 'switch';
389
+ mode: 'local' | 'remote';
390
+ } | {
391
+ type: 'message';
392
+ message: string;
393
+ } | {
394
+ type: 'permission-mode-changed';
395
+ mode: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
396
+ } | {
397
+ type: 'ready';
398
+ }, id?: string): void;
399
+ /**
400
+ * Send a ping message to keep the connection alive
401
+ */
402
+ keepAlive(thinking: boolean, mode: 'local' | 'remote'): void;
403
+ /**
404
+ * Send session death message
405
+ */
406
+ sendSessionDeath(): void;
407
+ /**
408
+ * Send usage data to the server
409
+ */
410
+ sendUsageData(usage: Usage): void;
411
+ /**
412
+ * Update session metadata
413
+ * @param handler - Handler function that returns the updated metadata
414
+ */
415
+ updateMetadata(handler: (metadata: Metadata) => Metadata): void;
416
+ /**
417
+ * Update session agent state
418
+ * @param handler - Handler function that returns the updated agent state
419
+ */
420
+ updateAgentState(handler: (metadata: AgentState) => AgentState): void;
421
+ /**
422
+ * Wait for socket buffer to flush
423
+ */
424
+ flush(): Promise<void>;
425
+ close(): Promise<void>;
426
+ }
427
+
428
+ type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
429
+
430
+ /**
431
+ * Usage data type from Claude
432
+ */
433
+ type Usage = z.infer<typeof UsageSchema>;
434
+ /**
435
+ * Session information
436
+ */
437
+ type Session = {
438
+ id: string;
439
+ seq: number;
440
+ encryptionKey: Uint8Array;
441
+ encryptionVariant: 'legacy' | 'dataKey';
442
+ metadata: Metadata;
443
+ metadataVersion: number;
444
+ agentState: AgentState | null;
445
+ agentStateVersion: number;
446
+ };
447
+ /**
448
+ * Machine metadata - static information (rarely changes)
449
+ */
450
+ declare const MachineMetadataSchema: z.ZodObject<{
451
+ host: z.ZodString;
452
+ platform: z.ZodString;
453
+ happyCliVersion: z.ZodString;
454
+ homeDir: z.ZodString;
455
+ happyHomeDir: z.ZodString;
456
+ happyLibDir: z.ZodString;
457
+ }, "strip", z.ZodTypeAny, {
458
+ host: string;
459
+ platform: string;
460
+ happyCliVersion: string;
461
+ homeDir: string;
462
+ happyHomeDir: string;
463
+ happyLibDir: string;
464
+ }, {
465
+ host: string;
466
+ platform: string;
467
+ happyCliVersion: string;
468
+ homeDir: string;
469
+ happyHomeDir: string;
470
+ happyLibDir: string;
471
+ }>;
472
+ type MachineMetadata = z.infer<typeof MachineMetadataSchema>;
473
+ /**
474
+ * Daemon state - dynamic runtime information (frequently updated)
475
+ */
476
+ declare const DaemonStateSchema: z.ZodObject<{
477
+ status: z.ZodUnion<[z.ZodEnum<["running", "shutting-down"]>, z.ZodString]>;
478
+ pid: z.ZodOptional<z.ZodNumber>;
479
+ httpPort: z.ZodOptional<z.ZodNumber>;
480
+ startedAt: z.ZodOptional<z.ZodNumber>;
481
+ shutdownRequestedAt: z.ZodOptional<z.ZodNumber>;
482
+ shutdownSource: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["mobile-app", "cli", "os-signal", "unknown"]>, z.ZodString]>>;
483
+ }, "strip", z.ZodTypeAny, {
484
+ status: string;
485
+ pid?: number | undefined;
486
+ httpPort?: number | undefined;
487
+ startedAt?: number | undefined;
488
+ shutdownRequestedAt?: number | undefined;
489
+ shutdownSource?: string | undefined;
490
+ }, {
491
+ status: string;
492
+ pid?: number | undefined;
493
+ httpPort?: number | undefined;
494
+ startedAt?: number | undefined;
495
+ shutdownRequestedAt?: number | undefined;
496
+ shutdownSource?: string | undefined;
497
+ }>;
498
+ type DaemonState = z.infer<typeof DaemonStateSchema>;
499
+ type Machine = {
500
+ id: string;
501
+ encryptionKey: Uint8Array;
502
+ encryptionVariant: 'legacy' | 'dataKey';
503
+ metadata: MachineMetadata;
504
+ metadataVersion: number;
505
+ daemonState: DaemonState | null;
506
+ daemonStateVersion: number;
507
+ };
508
+ declare const UserMessageSchema: z.ZodObject<{
509
+ role: z.ZodLiteral<"user">;
510
+ content: z.ZodObject<{
511
+ type: z.ZodLiteral<"text">;
512
+ text: z.ZodString;
513
+ }, "strip", z.ZodTypeAny, {
514
+ type: "text";
515
+ text: string;
516
+ }, {
517
+ type: "text";
518
+ text: string;
519
+ }>;
520
+ localKey: z.ZodOptional<z.ZodString>;
521
+ meta: z.ZodOptional<z.ZodObject<{
522
+ sentFrom: z.ZodOptional<z.ZodString>;
523
+ permissionMode: z.ZodOptional<z.ZodString>;
524
+ model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
525
+ fallbackModel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
526
+ customSystemPrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
527
+ appendSystemPrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
528
+ allowedTools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
529
+ disallowedTools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
530
+ }, "strip", z.ZodTypeAny, {
531
+ sentFrom?: string | undefined;
532
+ permissionMode?: string | undefined;
533
+ model?: string | null | undefined;
534
+ fallbackModel?: string | null | undefined;
535
+ customSystemPrompt?: string | null | undefined;
536
+ appendSystemPrompt?: string | null | undefined;
537
+ allowedTools?: string[] | null | undefined;
538
+ disallowedTools?: string[] | null | undefined;
539
+ }, {
540
+ sentFrom?: string | undefined;
541
+ permissionMode?: string | undefined;
542
+ model?: string | null | undefined;
543
+ fallbackModel?: string | null | undefined;
544
+ customSystemPrompt?: string | null | undefined;
545
+ appendSystemPrompt?: string | null | undefined;
546
+ allowedTools?: string[] | null | undefined;
547
+ disallowedTools?: string[] | null | undefined;
548
+ }>>;
549
+ }, "strip", z.ZodTypeAny, {
550
+ content: {
551
+ type: "text";
552
+ text: string;
553
+ };
554
+ role: "user";
555
+ localKey?: string | undefined;
556
+ meta?: {
557
+ sentFrom?: string | undefined;
558
+ permissionMode?: string | undefined;
559
+ model?: string | null | undefined;
560
+ fallbackModel?: string | null | undefined;
561
+ customSystemPrompt?: string | null | undefined;
562
+ appendSystemPrompt?: string | null | undefined;
563
+ allowedTools?: string[] | null | undefined;
564
+ disallowedTools?: string[] | null | undefined;
565
+ } | undefined;
566
+ }, {
567
+ content: {
568
+ type: "text";
569
+ text: string;
570
+ };
571
+ role: "user";
572
+ localKey?: string | undefined;
573
+ meta?: {
574
+ sentFrom?: string | undefined;
575
+ permissionMode?: string | undefined;
576
+ model?: string | null | undefined;
577
+ fallbackModel?: string | null | undefined;
578
+ customSystemPrompt?: string | null | undefined;
579
+ appendSystemPrompt?: string | null | undefined;
580
+ allowedTools?: string[] | null | undefined;
581
+ disallowedTools?: string[] | null | undefined;
582
+ } | undefined;
583
+ }>;
584
+ type UserMessage = z.infer<typeof UserMessageSchema>;
585
+ type Metadata = {
586
+ path: string;
587
+ host: string;
588
+ version?: string;
589
+ name?: string;
590
+ os?: string;
591
+ summary?: {
592
+ text: string;
593
+ updatedAt: number;
594
+ };
595
+ machineId?: string;
596
+ claudeSessionId?: string;
597
+ tools?: string[];
598
+ slashCommands?: string[];
599
+ homeDir: string;
600
+ happyHomeDir: string;
601
+ happyLibDir: string;
602
+ happyToolsDir: string;
603
+ startedFromDaemon?: boolean;
604
+ hostPid?: number;
605
+ startedBy?: 'daemon' | 'terminal';
606
+ lifecycleState?: 'running' | 'archiveRequested' | 'archived' | string;
607
+ lifecycleStateSince?: number;
608
+ archivedBy?: string;
609
+ archiveReason?: string;
610
+ flavor?: string;
611
+ permissionMode?: PermissionMode;
612
+ };
613
+ type AgentState = {
614
+ controlledByUser?: boolean | null | undefined;
615
+ requests?: {
616
+ [id: string]: {
617
+ tool: string;
618
+ arguments: any;
619
+ createdAt: number;
620
+ };
621
+ };
622
+ completedRequests?: {
623
+ [id: string]: {
624
+ tool: string;
625
+ arguments: any;
626
+ createdAt: number;
627
+ completedAt: number;
628
+ status: 'canceled' | 'denied' | 'approved';
629
+ reason?: string;
630
+ mode?: PermissionMode;
631
+ decision?: 'approved' | 'approved_for_session' | 'denied' | 'abort';
632
+ allowTools?: string[];
633
+ };
634
+ };
635
+ };
636
+
637
+ interface SpawnSessionOptions {
638
+ machineId?: string;
639
+ directory: string;
640
+ sessionId?: string;
641
+ approvedNewDirectoryCreation?: boolean;
642
+ agent?: 'claude' | 'codex';
643
+ token?: string;
644
+ }
645
+ type SpawnSessionResult = {
646
+ type: 'success';
647
+ sessionId: string;
648
+ } | {
649
+ type: 'requestToApproveDirectoryCreation';
650
+ directory: string;
651
+ } | {
652
+ type: 'error';
653
+ errorMessage: string;
654
+ };
655
+
656
+ /**
657
+ * WebSocket client for machine/daemon communication with Happy server
658
+ * Similar to ApiSessionClient but for machine-scoped connections
659
+ */
660
+
661
+ type MachineRpcHandlers = {
662
+ spawnSession: (options: SpawnSessionOptions) => Promise<SpawnSessionResult>;
663
+ stopSession: (sessionId: string) => boolean;
664
+ requestShutdown: () => void;
665
+ };
666
+ declare class ApiMachineClient {
667
+ private token;
668
+ private machine;
669
+ private socket;
670
+ private keepAliveInterval;
671
+ private rpcHandlerManager;
672
+ constructor(token: string, machine: Machine);
673
+ setRPCHandlers({ spawnSession, stopSession, requestShutdown }: MachineRpcHandlers): void;
674
+ /**
675
+ * Update machine metadata
676
+ * Currently unused, changes from the mobile client are more likely
677
+ * for example to set a custom name.
678
+ */
679
+ updateMachineMetadata(handler: (metadata: MachineMetadata | null) => MachineMetadata): Promise<void>;
680
+ /**
681
+ * Update daemon state (runtime info) - similar to session updateAgentState
682
+ * Simplified without lock - relies on backoff for retry
683
+ */
684
+ updateDaemonState(handler: (state: DaemonState | null) => DaemonState): Promise<void>;
685
+ connect(): void;
686
+ private startKeepAlive;
687
+ private stopKeepAlive;
688
+ shutdown(): void;
689
+ }
690
+
691
+ interface PushToken {
692
+ id: string;
693
+ token: string;
694
+ createdAt: number;
695
+ updatedAt: number;
696
+ }
697
+ declare class PushNotificationClient {
698
+ private readonly token;
699
+ private readonly baseUrl;
700
+ private readonly expo;
701
+ constructor(token: string, baseUrl?: string);
702
+ /**
703
+ * Fetch all push tokens for the authenticated user
704
+ */
705
+ fetchPushTokens(): Promise<PushToken[]>;
706
+ /**
707
+ * Send push notification via Expo Push API with retry
708
+ * @param messages - Array of push messages to send
709
+ */
710
+ sendPushNotifications(messages: ExpoPushMessage[]): Promise<void>;
711
+ /**
712
+ * Send a push notification to all registered devices for the user
713
+ * @param title - Notification title
714
+ * @param body - Notification body
715
+ * @param data - Additional data to send with the notification
716
+ */
717
+ sendToAllDevices(title: string, body: string, data?: Record<string, any>): void;
718
+ }
719
+
720
+ /**
721
+ * Minimal persistence functions for happy CLI
722
+ *
723
+ * Handles settings and private key storage in ~/.happy/ or local .happy/
724
+ */
725
+
726
+ type Credentials = {
727
+ token: string;
728
+ encryption: {
729
+ type: 'legacy';
730
+ secret: Uint8Array;
731
+ } | {
732
+ type: 'dataKey';
733
+ dataKeySeed: Uint8Array;
734
+ machineKey: Uint8Array;
735
+ };
736
+ };
737
+
738
+ declare class ApiClient {
739
+ static create(credential: Credentials): Promise<ApiClient>;
740
+ private readonly credential;
741
+ private readonly pushClient;
742
+ private constructor();
743
+ /**
744
+ * Create a new session or load existing one with the given tag
745
+ */
746
+ getOrCreateSession(opts: {
747
+ tag: string;
748
+ metadata: Metadata;
749
+ state: AgentState | null;
750
+ }): Promise<Session>;
751
+ /**
752
+ * Register or update machine with the server
753
+ * Returns the current machine state from the server with decrypted metadata and daemonState
754
+ */
755
+ getOrCreateMachine(opts: {
756
+ machineId: string;
757
+ metadata: MachineMetadata;
758
+ daemonState?: DaemonState;
759
+ }): Promise<Machine>;
760
+ sessionSyncClient(session: Session): ApiSessionClient;
761
+ machineSyncClient(machine: Machine): ApiMachineClient;
762
+ push(): PushNotificationClient;
763
+ /**
764
+ * Register a vendor API token with the server
765
+ * The token is sent as a JSON string - server handles encryption
766
+ */
767
+ registerVendorToken(vendor: 'openai' | 'anthropic' | 'gemini', apiKey: any): Promise<void>;
768
+ }
769
+
770
+ /**
771
+ * Design decisions:
772
+ * - Logging should be done only through file for debugging, otherwise we might disturb the claude session when in interactive mode
773
+ * - Use info for logs that are useful to the user - this is our UI
774
+ * - File output location: ~/.handy/logs/<date time in local timezone>.log
775
+ */
776
+ declare class Logger {
777
+ readonly logFilePath: string;
778
+ private dangerouslyUnencryptedServerLoggingUrl;
779
+ constructor(logFilePath?: string);
780
+ localTimezoneTimestamp(): string;
781
+ debug(message: string, ...args: unknown[]): void;
782
+ debugLargeJson(message: string, object: unknown, maxStringLength?: number, maxArrayLength?: number): void;
783
+ info(message: string, ...args: unknown[]): void;
784
+ infoDeveloper(message: string, ...args: unknown[]): void;
785
+ warn(message: string, ...args: unknown[]): void;
786
+ getLogPath(): string;
787
+ private logToConsole;
788
+ private sendToRemoteServer;
789
+ private logToFile;
790
+ }
791
+ declare let logger: Logger;
792
+
793
+ /**
794
+ * Global configuration for happy CLI
795
+ *
796
+ * Centralizes all configuration including environment variables and paths
797
+ * Environment files should be loaded using Node's --env-file flag
798
+ */
799
+ declare class Configuration {
800
+ readonly serverUrl: string;
801
+ readonly webappUrl: string;
802
+ readonly isDaemonProcess: boolean;
803
+ readonly happyHomeDir: string;
804
+ readonly logsDir: string;
805
+ readonly settingsFile: string;
806
+ readonly privateKeyFile: string;
807
+ readonly daemonStateFile: string;
808
+ readonly daemonLockFile: string;
809
+ readonly currentCliVersion: string;
810
+ readonly isExperimentalEnabled: boolean;
811
+ readonly disableCaffeinate: boolean;
812
+ constructor();
813
+ }
814
+ declare const configuration: Configuration;
815
+
816
+ export { ApiClient, ApiSessionClient, RawJSONLinesSchema, configuration, logger };
817
+ export type { RawJSONLines };