@zonease/happy 0.6.38 → 0.6.40

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 (112) hide show
  1. package/bin/happy.mjs +10 -0
  2. package/dist/{types-DvTsFaqR.cjs → api-C7FyJfZ1.cjs} +400 -1964
  3. package/dist/{types-BWpRU1VN.mjs → api-D6WL40-U.mjs} +220 -1729
  4. package/dist/auth-C7ZScWEw.cjs +274 -0
  5. package/dist/auth-DCsIoZLT.cjs +183 -0
  6. package/dist/auth-DO9GexAR.mjs +181 -0
  7. package/dist/auth-DxJ3VvrX.mjs +270 -0
  8. package/dist/browser-AoVGRX7y.mjs +20 -0
  9. package/dist/browser-DzgO4oaD.cjs +22 -0
  10. package/dist/claudeLocal-C6BdzhDx.cjs +352 -0
  11. package/dist/claudeLocal-CWNGpJ0-.mjs +344 -0
  12. package/dist/codex/happyMcpStdioBridge.cjs +4 -1
  13. package/dist/codex/happyMcpStdioBridge.mjs +4 -1
  14. package/dist/common-BdNgghUJ.mjs +75 -0
  15. package/dist/common-CZvSRU4p.cjs +83 -0
  16. package/dist/{config-0Xnc8ARM.cjs → config-CclB3QW9.cjs} +21 -34
  17. package/dist/{config-_GW4YBCP.mjs → config-DZk-mJ0K.mjs} +7 -20
  18. package/dist/connect-BXLUKJ5P.mjs +679 -0
  19. package/dist/connect-k9CqDJ-T.cjs +681 -0
  20. package/dist/{constants-B4x1K7by.cjs → constants-E_UWYTo3.cjs} +2 -2
  21. package/dist/{constants-BO9OAFOT.mjs → constants-pmXZGibX.mjs} +1 -1
  22. package/dist/controlClient-B23M-WPp.cjs +177 -0
  23. package/dist/controlClient-DB5tDU7V.mjs +167 -0
  24. package/dist/deviceKeys-BTdo34Uz.mjs +175 -0
  25. package/dist/deviceKeys-C540DcXl.cjs +182 -0
  26. package/dist/diagnose-B3D1a_v0.cjs +60 -0
  27. package/dist/diagnose-CuRKXxt1.mjs +58 -0
  28. package/dist/doctor-BQGLhrcI.cjs +214 -0
  29. package/dist/doctor-C08m5Z9f.cjs +78 -0
  30. package/dist/doctor-CU4JLGQ1.mjs +211 -0
  31. package/dist/doctor-ON7pN5G5.mjs +74 -0
  32. package/dist/downloadImage-DZXI3mXL.mjs +887 -0
  33. package/dist/downloadImage-cQ1Z7hkC.cjs +897 -0
  34. package/dist/enroll-B55BQR56.mjs +113 -0
  35. package/dist/enroll-Bo-CNio1.cjs +115 -0
  36. package/dist/evidence-DQp8QWcv.cjs +129 -0
  37. package/dist/evidence-DTYRAaOZ.mjs +127 -0
  38. package/dist/formatImageMessage-CixDYY6G.cjs +46 -0
  39. package/dist/formatImageMessage-DbKSSjMx.mjs +43 -0
  40. package/dist/github-DKcyF1zp.mjs +57 -0
  41. package/dist/github-h9GhJJ_C.cjs +59 -0
  42. package/dist/index-CDTNgfUf.cjs +578 -0
  43. package/dist/index-CPKdvi7J.mjs +554 -0
  44. package/dist/index.cjs +812 -40
  45. package/dist/index.mjs +813 -40
  46. package/dist/install-B1e6rdy7.mjs +94 -0
  47. package/dist/install-CgUPGIoF.mjs +95 -0
  48. package/dist/install-D7Ir7ciZ.cjs +96 -0
  49. package/dist/install-DSDufaPd.cjs +98 -0
  50. package/dist/lib.cjs +18 -12
  51. package/dist/lib.d.cts +77 -0
  52. package/dist/lib.d.mts +77 -0
  53. package/dist/lib.mjs +13 -7
  54. package/dist/{loadableToolOutput-va3RLplh.mjs → loadableToolOutput-Bfei9wPq.mjs} +4 -2
  55. package/dist/{loadableToolOutput-5vdQB98M.cjs → loadableToolOutput-CbLGtvST.cjs} +63 -61
  56. package/dist/mcpToolSchemas-CjeTfrAs.mjs +62 -0
  57. package/dist/mcpToolSchemas-DK42yoZ_.cjs +64 -0
  58. package/dist/persistence-CBTtC_dm.cjs +996 -0
  59. package/dist/persistence-DKfF81pd.mjs +944 -0
  60. package/dist/projectPath-BTBIMB57.mjs +10 -0
  61. package/dist/projectPath-ChLhdOyt.cjs +13 -0
  62. package/dist/prompt-BTWDZZO0.cjs +25 -0
  63. package/dist/prompt-BsAZsPbo.mjs +22 -0
  64. package/dist/release-BMEzNONE.mjs +168 -0
  65. package/dist/release-EhOJeAZe.cjs +171 -0
  66. package/dist/run-BVZsMNwN.mjs +2164 -0
  67. package/dist/run-CURx7LhK.cjs +2188 -0
  68. package/dist/runClaude-6Gi0sYQy.mjs +3763 -0
  69. package/dist/runClaude-CL3Kt5ex.cjs +3766 -0
  70. package/dist/{runCodex-DiKzBf9q.mjs → runCodex-ClwEgJ7M.mjs} +36 -20
  71. package/dist/{runCodex-skq0j05d.cjs → runCodex-YKyVBkJ3.cjs} +169 -153
  72. package/dist/{runGemini-BeqrVq8R.mjs → runGemini-BPWxVr60.mjs} +34 -17
  73. package/dist/{runGemini-CVp-CEIh.cjs → runGemini-Xz2W1spn.cjs} +212 -195
  74. package/dist/{runOneShot-ltCpHbBB.mjs → runOneShot-CdCWiiLr.mjs} +14 -38
  75. package/dist/{runOneShot-BQNkNW61.cjs → runOneShot-DjZyCvDI.cjs} +31 -55
  76. package/dist/{serve-BNdoEDVx.mjs → serve-B48JttQ3.mjs} +12 -35
  77. package/dist/{serve-BECdtivY.cjs → serve-B8vaWQA0.cjs} +35 -58
  78. package/dist/session-BXboDn2V.mjs +108 -0
  79. package/dist/session-BZO25zxp.cjs +110 -0
  80. package/dist/sessionKeyCache-B6cGadYL.mjs +33 -0
  81. package/dist/sessionKeyCache-CDmexJ9p.cjs +36 -0
  82. package/dist/sessionList-CgAYZpNj.mjs +51 -0
  83. package/dist/sessionList-lQ-nqEhc.cjs +54 -0
  84. package/dist/sessionSummary-CcORiQSq.cjs +393 -0
  85. package/dist/sessionSummary-DCWQoaDP.mjs +387 -0
  86. package/dist/spawnHappyCLI-KiazE3kL.cjs +70 -0
  87. package/dist/spawnHappyCLI-yBIP_Oqi.mjs +66 -0
  88. package/dist/ssh-q5uZhqBf.mjs +359 -0
  89. package/dist/ssh-yMllSHu5.cjs +365 -0
  90. package/dist/systemdScope-BeOtAkhk.mjs +25 -0
  91. package/dist/systemdScope-DW3-UoKB.cjs +29 -0
  92. package/dist/task-_nr7J19j.cjs +167 -0
  93. package/dist/task-wNX1N2i4.mjs +165 -0
  94. package/dist/time-Bj2HRkKH.cjs +33 -0
  95. package/dist/time-DgsBLJA_.mjs +29 -0
  96. package/dist/trimIdent-4gvk9Wk6.cjs +22 -0
  97. package/dist/trimIdent-BAjmv_TG.mjs +20 -0
  98. package/dist/types-BoJh4Qfv.mjs +57 -0
  99. package/dist/types-DWeB7aqh.cjs +59 -0
  100. package/dist/uninstall-Buaz7d-X.cjs +77 -0
  101. package/dist/uninstall-Dxf6_4mQ.mjs +75 -0
  102. package/dist/update-CGlIfa8e.cjs +111 -0
  103. package/dist/update-CnnoX2cV.mjs +109 -0
  104. package/dist/workflowCommon-B0d01Y_a.mjs +56 -0
  105. package/dist/workflowCommon-Bl568-rt.cjs +62 -0
  106. package/dist/workflowReports-BEWuQesA.cjs +113 -0
  107. package/dist/workflowReports-Dd8-4-8f.mjs +108 -0
  108. package/package.json +1 -1
  109. package/dist/index-BbCDDvoB.cjs +0 -11376
  110. package/dist/index-vvZXdswy.mjs +0 -11336
  111. package/dist/mcpToolSchemas-CdPXJQmb.mjs +0 -175
  112. package/dist/mcpToolSchemas-f-kttjFw.cjs +0 -186
@@ -0,0 +1,387 @@
1
+ import axios from 'axios';
2
+ import { z } from 'zod';
3
+ import { q as decryptLegacy, f as decodeBase64, m as decryptWithDataKey, c as configuration } from './persistence-DKfF81pd.mjs';
4
+ import { decryptWithEphemeralKey } from './auth-DxJ3VvrX.mjs';
5
+ import { r as readCachedSessionKey } from './sessionKeyCache-B6cGadYL.mjs';
6
+
7
+ function resolveSessionKey(credentials, dataEncryptionKey, sessionId) {
8
+ if (credentials.encryption.type === "legacy") {
9
+ return { key: credentials.encryption.secret, variant: "legacy" };
10
+ }
11
+ if (sessionId) {
12
+ const cached = readCachedSessionKey(sessionId, credentials.encryption.machineKey);
13
+ if (cached) {
14
+ return { key: cached, variant: "dataKey" };
15
+ }
16
+ }
17
+ if (!dataEncryptionKey) {
18
+ return null;
19
+ }
20
+ const blob = decodeBase64(dataEncryptionKey);
21
+ if (blob.length < 1 || blob[0] !== 0) {
22
+ return null;
23
+ }
24
+ const opened = decryptWithEphemeralKey(blob.slice(1), credentials.encryption.machineKey);
25
+ if (!opened) {
26
+ return null;
27
+ }
28
+ return { key: opened, variant: "dataKey" };
29
+ }
30
+ function decryptSessionRow(credentials, row) {
31
+ const resolved = resolveSessionKey(credentials, row.dataEncryptionKey, row.id);
32
+ if (!resolved) {
33
+ return null;
34
+ }
35
+ let metadata = null;
36
+ if (row.metadata) {
37
+ try {
38
+ metadata = resolved.variant === "legacy" ? decryptLegacy(decodeBase64(row.metadata), resolved.key) : decryptWithDataKey(decodeBase64(row.metadata), resolved.key);
39
+ } catch {
40
+ metadata = null;
41
+ }
42
+ }
43
+ let agentState = null;
44
+ if (row.agentState) {
45
+ try {
46
+ agentState = resolved.variant === "legacy" ? decryptLegacy(decodeBase64(row.agentState), resolved.key) : decryptWithDataKey(decodeBase64(row.agentState), resolved.key);
47
+ } catch {
48
+ agentState = null;
49
+ }
50
+ }
51
+ return {
52
+ id: row.id,
53
+ seq: row.seq,
54
+ createdAt: row.createdAt,
55
+ updatedAt: row.updatedAt,
56
+ activeAt: row.activeAt,
57
+ active: row.active,
58
+ metadata,
59
+ agentState,
60
+ isShared: row.isShared,
61
+ encryptionKey: resolved.key,
62
+ encryptionVariant: resolved.variant
63
+ };
64
+ }
65
+
66
+ async function fetchSessionById(credentials, sessionId) {
67
+ const response = await axios.get(
68
+ `${configuration.serverUrl}/v1/sessions`,
69
+ {
70
+ headers: { Authorization: `Bearer ${credentials.token}` },
71
+ timeout: 1e4
72
+ }
73
+ );
74
+ const row = response.data.sessions.find((s) => s.id === sessionId);
75
+ if (!row) return null;
76
+ return decryptSessionRow(credentials, row);
77
+ }
78
+
79
+ function extractEncryptedBase64(content) {
80
+ if (typeof content === "string") return content;
81
+ if (content && typeof content === "object" && content.t === "encrypted" && typeof content.c === "string") {
82
+ return content.c;
83
+ }
84
+ return null;
85
+ }
86
+ function buildPreview(content) {
87
+ if (!content) return "";
88
+ if (content.type === "text" && typeof content.text === "string") {
89
+ return content.text;
90
+ }
91
+ if (content.type === "mixed" && typeof content.text === "string") {
92
+ return content.text;
93
+ }
94
+ if (content.type === "output") {
95
+ const data = content.data;
96
+ if (typeof data === "string") return data;
97
+ if (data && typeof data === "object") {
98
+ if (data.type === "message" && typeof data.message === "string") return data.message;
99
+ if (data.type === "reasoning" && typeof data.message === "string") return data.message;
100
+ if (typeof data.text === "string") return data.text;
101
+ }
102
+ }
103
+ return "";
104
+ }
105
+ function decryptMessage(raw, encryptionKey, encryptionVariant) {
106
+ const base64 = extractEncryptedBase64(raw.content);
107
+ let decrypted = null;
108
+ if (base64) {
109
+ try {
110
+ const bytes = decodeBase64(base64);
111
+ decrypted = encryptionVariant === "legacy" ? decryptLegacy(bytes, encryptionKey) : decryptWithDataKey(bytes, encryptionKey);
112
+ } catch {
113
+ decrypted = null;
114
+ }
115
+ }
116
+ const role = decrypted?.role === "user" || decrypted?.role === "agent" ? decrypted.role : "unknown";
117
+ const content = decrypted?.content ?? null;
118
+ return {
119
+ id: raw.id,
120
+ seq: raw.seq,
121
+ role,
122
+ content,
123
+ meta: decrypted?.meta ?? null,
124
+ textPreview: buildPreview(content),
125
+ sentBy: raw.sentBy,
126
+ sentByName: raw.sentByName,
127
+ createdAt: raw.createdAt,
128
+ updatedAt: raw.updatedAt,
129
+ deliveryIssue: raw.deliveryIssue ?? void 0
130
+ };
131
+ }
132
+
133
+ const DEFAULT_LIMIT = 200;
134
+ const DEFAULT_TEXT_LIMIT = 800;
135
+ const DEFAULT_MAX_TURNS = 80;
136
+ const DEFAULT_MAX_TOOLS_PER_TURN = 12;
137
+ const sessionSummaryInputSchema = {
138
+ sessionId: z.string().describe("Target session ID (from happy_session_list)."),
139
+ limit: z.number().int().min(1).max(500).optional().describe(`Max raw messages to compact in this call. Default: ${DEFAULT_LIMIT}.`),
140
+ beforeSeq: z.number().int().min(1).optional().describe("Return messages with seq < this value (paginate backwards). Mutually exclusive with afterSeq."),
141
+ afterSeq: z.number().int().min(0).optional().describe("Return messages with seq > this value (paginate forwards). Mutually exclusive with beforeSeq."),
142
+ maxTurns: z.number().int().min(1).max(200).optional().describe(`Max compact turns to return. Default: ${DEFAULT_MAX_TURNS}.`),
143
+ textLimit: z.number().int().min(80).max(4e3).optional().describe(`Max chars per user/assistant text block. Default: ${DEFAULT_TEXT_LIMIT}.`),
144
+ includeTools: z.boolean().optional().describe("Include compact tool-use names. Default: true."),
145
+ maxToolsPerTurn: z.number().int().min(0).max(50).optional().describe(`Max tool names per turn when includeTools=true. Default: ${DEFAULT_MAX_TOOLS_PER_TURN}.`)
146
+ };
147
+ function trimText(text, limit) {
148
+ const normalized = text.replace(/\r\n/g, "\n").trim();
149
+ if (normalized.length <= limit) return normalized;
150
+ return `${normalized.slice(0, limit)}\u2026`;
151
+ }
152
+ function oneLine(text) {
153
+ return text.replace(/\s+/g, " ").trim();
154
+ }
155
+ function imageCount(content) {
156
+ return Array.isArray(content?.images) ? content.images.length : 0;
157
+ }
158
+ function isHumanOnlyMessage(message) {
159
+ const meta = message.meta;
160
+ if (!meta || typeof meta !== "object") return false;
161
+ const collaboration = meta.collaboration;
162
+ return meta.humanOnly === true || meta.skipAiContext === true || collaboration?.kind === "mention";
163
+ }
164
+ function assistantContentItems(messageData) {
165
+ if (Array.isArray(messageData?.message?.content)) {
166
+ return messageData.message.content;
167
+ }
168
+ if (Array.isArray(messageData?.content)) {
169
+ return messageData.content;
170
+ }
171
+ return [];
172
+ }
173
+ function extractAssistantTexts(message, textLimit) {
174
+ const content = message.content;
175
+ if (content?.type !== "output") return [];
176
+ const data = content.data;
177
+ if (typeof data === "string") {
178
+ return [trimText(data, textLimit)].filter(Boolean);
179
+ }
180
+ if (!data || typeof data !== "object") return [];
181
+ const directMessage = typeof data.message === "string" ? data.message : null;
182
+ if (directMessage) {
183
+ return [trimText(directMessage, textLimit)].filter(Boolean);
184
+ }
185
+ const directText = typeof data.text === "string" ? data.text : null;
186
+ if (directText) {
187
+ return [trimText(directText, textLimit)].filter(Boolean);
188
+ }
189
+ return assistantContentItems(data).filter((item) => item?.type === "text" && typeof item.text === "string").map((item) => trimText(item.text, textLimit)).filter(Boolean);
190
+ }
191
+ function extractToolNames(message) {
192
+ const content = message.content;
193
+ if (content?.type !== "output") return [];
194
+ const data = content.data;
195
+ if (!data || typeof data !== "object") return [];
196
+ const names = [];
197
+ for (const item of assistantContentItems(data)) {
198
+ if (item?.type === "tool_use" && typeof item.name === "string") {
199
+ names.push(item.name);
200
+ }
201
+ if (item?.type === "tool_call" && typeof item.name === "string") {
202
+ names.push(item.name);
203
+ }
204
+ }
205
+ const directToolName = typeof data.toolName === "string" ? data.toolName : typeof data.name === "string" && (data.type === "tool_call" || data.type === "tool_use") ? data.name : null;
206
+ if (directToolName) {
207
+ names.push(directToolName);
208
+ }
209
+ return names;
210
+ }
211
+ function pushTurn(turns, turn) {
212
+ if (!turn) return;
213
+ if (!turn.user && turn.assistantTexts.length === 0 && turn.tools.length === 0) return;
214
+ turns.push(turn);
215
+ }
216
+ function compactSessionMessages(messages, options) {
217
+ const chronological = [...messages].sort((a, b) => a.seq - b.seq);
218
+ const turns = [];
219
+ let current = null;
220
+ let compactedCount = 0;
221
+ for (const message of chronological) {
222
+ if (isHumanOnlyMessage(message)) {
223
+ continue;
224
+ }
225
+ if (message.role === "user") {
226
+ const content = message.content;
227
+ const text = typeof content?.text === "string" ? trimText(content.text, options.textLimit) : "";
228
+ if (!text && imageCount(content) === 0) continue;
229
+ pushTurn(turns, current);
230
+ current = {
231
+ startSeq: message.seq,
232
+ endSeq: message.seq,
233
+ startedAt: message.createdAt,
234
+ user: {
235
+ seq: message.seq,
236
+ createdAt: message.createdAt,
237
+ text,
238
+ imageCount: imageCount(content)
239
+ },
240
+ assistantTexts: [],
241
+ tools: [],
242
+ omittedToolCount: 0
243
+ };
244
+ compactedCount += 1;
245
+ continue;
246
+ }
247
+ const texts = extractAssistantTexts(message, options.textLimit);
248
+ const toolNames = options.includeTools ? extractToolNames(message) : [];
249
+ if (texts.length === 0 && toolNames.length === 0) continue;
250
+ if (!current) {
251
+ current = {
252
+ startSeq: message.seq,
253
+ endSeq: message.seq,
254
+ startedAt: message.createdAt,
255
+ user: null,
256
+ assistantTexts: [],
257
+ tools: [],
258
+ omittedToolCount: 0
259
+ };
260
+ }
261
+ current.endSeq = message.seq;
262
+ for (const text of texts) {
263
+ current.assistantTexts.push({ seq: message.seq, createdAt: message.createdAt, text });
264
+ compactedCount += 1;
265
+ }
266
+ for (const name of toolNames) {
267
+ if (current.tools.length < options.maxToolsPerTurn) {
268
+ current.tools.push({ seq: message.seq, createdAt: message.createdAt, name });
269
+ } else {
270
+ current.omittedToolCount += 1;
271
+ }
272
+ compactedCount += 1;
273
+ }
274
+ }
275
+ pushTurn(turns, current);
276
+ return {
277
+ turns: turns.slice(-options.maxTurns),
278
+ compactedCount
279
+ };
280
+ }
281
+ function formatTimestamp(ms) {
282
+ return new Date(ms).toISOString();
283
+ }
284
+ function buildSummaryText(result) {
285
+ const lines = [];
286
+ lines.push(`# Happy session ${result.sessionId}`);
287
+ lines.push("");
288
+ lines.push(`- Active: ${result.active ? "yes" : "no"}`);
289
+ lines.push(`- Agent: ${[result.agent.name, result.agent.model].filter(Boolean).join(" / ") || "unknown"}`);
290
+ lines.push(`- Path: ${result.path ?? "unknown"}`);
291
+ lines.push(`- Updated: ${formatTimestamp(result.updatedAt)}`);
292
+ if (result.storedSummary) {
293
+ lines.push(`- Stored summary: ${oneLine(result.storedSummary)}`);
294
+ }
295
+ lines.push(`- Window: ${result.messageWindow.rawCount} raw messages, ${result.messageWindow.compactedCount} compact items, hasMore=${result.messageWindow.hasMore}`);
296
+ lines.push("");
297
+ if (result.turns.length === 0) {
298
+ lines.push("No user/assistant text found in this window.");
299
+ return lines.join("\n");
300
+ }
301
+ result.turns.forEach((turn, index) => {
302
+ lines.push(`## Turn ${index + 1} (seq ${turn.startSeq}-${turn.endSeq})`);
303
+ if (turn.user) {
304
+ const imageSuffix = turn.user.imageCount > 0 ? ` [${turn.user.imageCount} image${turn.user.imageCount === 1 ? "" : "s"}]` : "";
305
+ lines.push(`User: ${oneLine(turn.user.text) || "(no text)"}${imageSuffix}`);
306
+ } else {
307
+ lines.push("User: (continuation before the first user message in this window)");
308
+ }
309
+ for (const text of turn.assistantTexts) {
310
+ lines.push(`Assistant: ${oneLine(text.text)}`);
311
+ }
312
+ if (turn.tools.length > 0) {
313
+ const omitted = turn.omittedToolCount > 0 ? `, +${turn.omittedToolCount} more` : "";
314
+ lines.push(`Tools: ${turn.tools.map((tool) => tool.name).join(", ")}${omitted}`);
315
+ }
316
+ lines.push("");
317
+ });
318
+ return lines.join("\n").trimEnd();
319
+ }
320
+ async function runSessionSummary(credentials, input) {
321
+ if (input.beforeSeq !== void 0 && input.afterSeq !== void 0) {
322
+ throw new Error("Specify only one of beforeSeq / afterSeq, not both.");
323
+ }
324
+ const session = await fetchSessionById(credentials, input.sessionId);
325
+ if (!session) {
326
+ throw new Error(`Session ${input.sessionId} not found or not decryptable.`);
327
+ }
328
+ const params = {
329
+ limit: String(input.limit ?? DEFAULT_LIMIT)
330
+ };
331
+ if (input.beforeSeq !== void 0) params.before_seq = String(input.beforeSeq);
332
+ if (input.afterSeq !== void 0) params.after_seq = String(input.afterSeq);
333
+ const response = await axios.get(
334
+ `${configuration.serverUrl}/v3/sessions/${encodeURIComponent(input.sessionId)}/messages`,
335
+ {
336
+ params,
337
+ headers: { Authorization: `Bearer ${credentials.token}` },
338
+ timeout: 1e4
339
+ }
340
+ );
341
+ const decrypted = response.data.messages.map(
342
+ (raw) => decryptMessage(raw, session.encryptionKey, session.encryptionVariant)
343
+ );
344
+ const compacted = compactSessionMessages(decrypted, {
345
+ textLimit: input.textLimit ?? DEFAULT_TEXT_LIMIT,
346
+ maxTurns: input.maxTurns ?? DEFAULT_MAX_TURNS,
347
+ includeTools: input.includeTools ?? true,
348
+ maxToolsPerTurn: input.maxToolsPerTurn ?? DEFAULT_MAX_TOOLS_PER_TURN
349
+ });
350
+ const seqs = decrypted.map((message) => message.seq);
351
+ const minSeq = seqs.length > 0 ? Math.min(...seqs) : null;
352
+ const maxSeq = seqs.length > 0 ? Math.max(...seqs) : null;
353
+ const meta = session.metadata ?? {};
354
+ const resultWithoutText = {
355
+ sessionId: session.id,
356
+ active: session.active,
357
+ activeAt: session.activeAt,
358
+ createdAt: session.createdAt,
359
+ updatedAt: session.updatedAt,
360
+ agent: {
361
+ name: typeof meta.agentName === "string" ? meta.agentName : null,
362
+ model: typeof meta.model === "string" ? meta.model : null,
363
+ mode: typeof meta.permissionMode === "string" ? meta.permissionMode : null,
364
+ flavor: typeof meta.flavor === "string" ? meta.flavor : null
365
+ },
366
+ machine: {
367
+ id: typeof meta.machineId === "string" ? meta.machineId : null,
368
+ name: typeof meta.machineName === "string" ? meta.machineName : null
369
+ },
370
+ path: typeof meta.path === "string" ? meta.path : null,
371
+ storedSummary: typeof meta.summary?.text === "string" ? meta.summary.text : null,
372
+ messageWindow: {
373
+ rawCount: decrypted.length,
374
+ compactedCount: compacted.compactedCount,
375
+ hasMore: response.data.hasMore,
376
+ nextBeforeSeq: minSeq,
377
+ nextAfterSeq: maxSeq
378
+ },
379
+ turns: compacted.turns
380
+ };
381
+ return {
382
+ ...resultWithoutText,
383
+ summaryText: buildSummaryText(resultWithoutText)
384
+ };
385
+ }
386
+
387
+ export { decryptMessage as a, decryptSessionRow as d, fetchSessionById as f, runSessionSummary as r, sessionSummaryInputSchema as s };
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+ var path = require('node:path');
5
+ var projectPath = require('./projectPath-ChLhdOyt.cjs');
6
+ var logger = require('./persistence-CBTtC_dm.cjs');
7
+ var fs = require('node:fs');
8
+
9
+ let cachedRuntime = null;
10
+ function getRuntime() {
11
+ if (cachedRuntime) return cachedRuntime;
12
+ if (typeof globalThis.Bun !== "undefined") {
13
+ cachedRuntime = "bun";
14
+ return cachedRuntime;
15
+ }
16
+ if (typeof globalThis.Deno !== "undefined") {
17
+ cachedRuntime = "deno";
18
+ return cachedRuntime;
19
+ }
20
+ if (process?.versions?.bun) {
21
+ cachedRuntime = "bun";
22
+ return cachedRuntime;
23
+ }
24
+ if (process?.versions?.deno) {
25
+ cachedRuntime = "deno";
26
+ return cachedRuntime;
27
+ }
28
+ if (process?.versions?.node) {
29
+ cachedRuntime = "node";
30
+ return cachedRuntime;
31
+ }
32
+ cachedRuntime = "unknown";
33
+ return cachedRuntime;
34
+ }
35
+ const isBun = () => getRuntime() === "bun";
36
+
37
+ function spawnHappyCLI(args, options = {}) {
38
+ const projectRoot = projectPath.projectPath();
39
+ const entrypoint = path.join(projectRoot, "dist", "index.mjs");
40
+ let directory;
41
+ if ("cwd" in options) {
42
+ directory = options.cwd;
43
+ } else {
44
+ directory = process.cwd();
45
+ }
46
+ const fullCommand = `happy ${args.join(" ")}`;
47
+ logger.logger.debug(`[SPAWN HAPPY CLI] Spawning: ${fullCommand} in ${directory}`);
48
+ const nodeArgs = [
49
+ "--no-warnings",
50
+ "--no-deprecation",
51
+ entrypoint,
52
+ ...args
53
+ ];
54
+ if (!fs.existsSync(entrypoint)) {
55
+ const errorMessage = `Entrypoint ${entrypoint} does not exist`;
56
+ logger.logger.debug(`[SPAWN HAPPY CLI] ${errorMessage}`);
57
+ throw new Error(errorMessage);
58
+ }
59
+ const runtime = isBun() ? "bun" : "node";
60
+ return child_process.spawn(runtime, nodeArgs, options);
61
+ }
62
+
63
+ var spawnHappyCLI$1 = /*#__PURE__*/Object.freeze({
64
+ __proto__: null,
65
+ spawnHappyCLI: spawnHappyCLI
66
+ });
67
+
68
+ exports.isBun = isBun;
69
+ exports.spawnHappyCLI = spawnHappyCLI;
70
+ exports.spawnHappyCLI$1 = spawnHappyCLI$1;
@@ -0,0 +1,66 @@
1
+ import { spawn } from 'child_process';
2
+ import { join } from 'node:path';
3
+ import { p as projectPath } from './projectPath-BTBIMB57.mjs';
4
+ import { l as logger } from './persistence-DKfF81pd.mjs';
5
+ import { existsSync } from 'node:fs';
6
+
7
+ let cachedRuntime = null;
8
+ function getRuntime() {
9
+ if (cachedRuntime) return cachedRuntime;
10
+ if (typeof globalThis.Bun !== "undefined") {
11
+ cachedRuntime = "bun";
12
+ return cachedRuntime;
13
+ }
14
+ if (typeof globalThis.Deno !== "undefined") {
15
+ cachedRuntime = "deno";
16
+ return cachedRuntime;
17
+ }
18
+ if (process?.versions?.bun) {
19
+ cachedRuntime = "bun";
20
+ return cachedRuntime;
21
+ }
22
+ if (process?.versions?.deno) {
23
+ cachedRuntime = "deno";
24
+ return cachedRuntime;
25
+ }
26
+ if (process?.versions?.node) {
27
+ cachedRuntime = "node";
28
+ return cachedRuntime;
29
+ }
30
+ cachedRuntime = "unknown";
31
+ return cachedRuntime;
32
+ }
33
+ const isBun = () => getRuntime() === "bun";
34
+
35
+ function spawnHappyCLI(args, options = {}) {
36
+ const projectRoot = projectPath();
37
+ const entrypoint = join(projectRoot, "dist", "index.mjs");
38
+ let directory;
39
+ if ("cwd" in options) {
40
+ directory = options.cwd;
41
+ } else {
42
+ directory = process.cwd();
43
+ }
44
+ const fullCommand = `happy ${args.join(" ")}`;
45
+ logger.debug(`[SPAWN HAPPY CLI] Spawning: ${fullCommand} in ${directory}`);
46
+ const nodeArgs = [
47
+ "--no-warnings",
48
+ "--no-deprecation",
49
+ entrypoint,
50
+ ...args
51
+ ];
52
+ if (!existsSync(entrypoint)) {
53
+ const errorMessage = `Entrypoint ${entrypoint} does not exist`;
54
+ logger.debug(`[SPAWN HAPPY CLI] ${errorMessage}`);
55
+ throw new Error(errorMessage);
56
+ }
57
+ const runtime = isBun() ? "bun" : "node";
58
+ return spawn(runtime, nodeArgs, options);
59
+ }
60
+
61
+ var spawnHappyCLI$1 = /*#__PURE__*/Object.freeze({
62
+ __proto__: null,
63
+ spawnHappyCLI: spawnHappyCLI
64
+ });
65
+
66
+ export { spawnHappyCLI$1 as a, isBun as i, spawnHappyCLI as s };