alvin-bot 5.6.2 → 5.8.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +1 -1
  3. package/dist/claude.js +1 -102
  4. package/dist/config.js +1 -96
  5. package/dist/engine.js +1 -90
  6. package/dist/find-claude-binary.js +1 -98
  7. package/dist/handlers/async-agent-chunk-handler.js +1 -50
  8. package/dist/handlers/background-bypass.js +1 -75
  9. package/dist/handlers/commands.js +1 -2336
  10. package/dist/handlers/cron-progress.js +1 -52
  11. package/dist/handlers/document.js +1 -194
  12. package/dist/handlers/message.js +1 -959
  13. package/dist/handlers/photo.js +1 -154
  14. package/dist/handlers/platform-message.js +1 -360
  15. package/dist/handlers/stuck-timer.js +1 -54
  16. package/dist/handlers/video.js +1 -237
  17. package/dist/handlers/voice.js +1 -148
  18. package/dist/i18n.js +1 -805
  19. package/dist/index.js +1 -697
  20. package/dist/init-data-dir.js +1 -98
  21. package/dist/middleware/auth.js +1 -233
  22. package/dist/migrate.js +1 -162
  23. package/dist/paths.js +1 -146
  24. package/dist/platforms/discord.js +1 -175
  25. package/dist/platforms/index.js +1 -130
  26. package/dist/platforms/signal.js +1 -205
  27. package/dist/platforms/slack-slash-parser.js +1 -32
  28. package/dist/platforms/slack.js +1 -501
  29. package/dist/platforms/telegram.js +1 -111
  30. package/dist/platforms/types.js +1 -8
  31. package/dist/platforms/whatsapp-auth-helpers.js +1 -53
  32. package/dist/platforms/whatsapp.js +1 -707
  33. package/dist/providers/claude-sdk-provider.js +1 -565
  34. package/dist/providers/codex-cli-provider.js +1 -134
  35. package/dist/providers/index.js +1 -7
  36. package/dist/providers/ollama-provider.js +1 -32
  37. package/dist/providers/openai-compatible.js +1 -406
  38. package/dist/providers/registry.js +1 -352
  39. package/dist/providers/runtime-header.js +1 -45
  40. package/dist/providers/tool-executor.js +1 -475
  41. package/dist/providers/types.js +1 -227
  42. package/dist/services/access.js +1 -144
  43. package/dist/services/allowed-users-gate.js +1 -56
  44. package/dist/services/alvin-dispatch.js +1 -130
  45. package/dist/services/alvin-mcp-tools.js +1 -104
  46. package/dist/services/asset-index.js +1 -224
  47. package/dist/services/async-agent-parser.js +1 -418
  48. package/dist/services/async-agent-watcher.js +1 -443
  49. package/dist/services/auto-diagnostic.js +1 -228
  50. package/dist/services/broadcast.js +1 -52
  51. package/dist/services/browser-manager.js +1 -562
  52. package/dist/services/browser-webfetch.js +1 -127
  53. package/dist/services/browser.js +1 -121
  54. package/dist/services/cdp-bootstrap.js +1 -357
  55. package/dist/services/compaction.js +1 -144
  56. package/dist/services/critical-notify.js +1 -203
  57. package/dist/services/cron-resolver.js +1 -58
  58. package/dist/services/cron-scheduling.js +1 -310
  59. package/dist/services/cron.js +1 -861
  60. package/dist/services/custom-tools.js +1 -317
  61. package/dist/services/delivery-queue.js +1 -173
  62. package/dist/services/delivery-registry.js +1 -21
  63. package/dist/services/disk-cleanup.js +1 -203
  64. package/dist/services/elevenlabs.js +1 -58
  65. package/dist/services/embeddings/auto-detect.js +1 -74
  66. package/dist/services/embeddings/fts5.js +1 -108
  67. package/dist/services/embeddings/gemini.js +1 -65
  68. package/dist/services/embeddings/index.js +1 -496
  69. package/dist/services/embeddings/ollama.js +1 -78
  70. package/dist/services/embeddings/openai.js +1 -49
  71. package/dist/services/embeddings/provider.js +1 -22
  72. package/dist/services/embeddings/vector-base.js +1 -113
  73. package/dist/services/embeddings-migration.js +1 -193
  74. package/dist/services/embeddings.js +1 -9
  75. package/dist/services/env-file.js +1 -50
  76. package/dist/services/exec-guard.js +1 -71
  77. package/dist/services/fallback-order.js +1 -154
  78. package/dist/services/file-permissions.js +1 -93
  79. package/dist/services/heartbeat-file.js +1 -65
  80. package/dist/services/heartbeat.js +1 -313
  81. package/dist/services/hooks.js +1 -44
  82. package/dist/services/imagegen.js +1 -72
  83. package/dist/services/language-detect.js +1 -154
  84. package/dist/services/markdown.js +1 -63
  85. package/dist/services/mcp.js +1 -263
  86. package/dist/services/memory-extractor.js +1 -178
  87. package/dist/services/memory-inject-mode.js +1 -43
  88. package/dist/services/memory-layers.js +1 -156
  89. package/dist/services/memory.js +1 -146
  90. package/dist/services/ollama-manager.js +1 -339
  91. package/dist/services/permissions-wizard.js +1 -291
  92. package/dist/services/personality.js +1 -376
  93. package/dist/services/plugins.js +1 -171
  94. package/dist/services/preflight.js +1 -292
  95. package/dist/services/process-manager.js +1 -291
  96. package/dist/services/release-highlights.js +1 -79
  97. package/dist/services/reminders.js +1 -97
  98. package/dist/services/restart.js +1 -48
  99. package/dist/services/security-audit.js +1 -74
  100. package/dist/services/self-diagnosis.js +1 -272
  101. package/dist/services/self-search.js +1 -129
  102. package/dist/services/session-persistence.js +1 -237
  103. package/dist/services/session.js +1 -282
  104. package/dist/services/skills.js +1 -290
  105. package/dist/services/ssrf-guard.js +1 -162
  106. package/dist/services/standing-orders.js +1 -29
  107. package/dist/services/steer-channel.js +1 -46
  108. package/dist/services/stop-controller.js +1 -52
  109. package/dist/services/subagent-dedup.js +1 -0
  110. package/dist/services/subagent-delivery.js +1 -452
  111. package/dist/services/subagent-stats.js +1 -123
  112. package/dist/services/subagents.js +1 -814
  113. package/dist/services/sudo.js +1 -329
  114. package/dist/services/telegram.js +1 -158
  115. package/dist/services/timing-safe-bearer.js +1 -51
  116. package/dist/services/tool-discovery.js +1 -214
  117. package/dist/services/trends.js +1 -580
  118. package/dist/services/updater.js +1 -291
  119. package/dist/services/usage-tracker.js +1 -144
  120. package/dist/services/users.js +1 -271
  121. package/dist/services/voice.js +1 -104
  122. package/dist/services/watchdog-brake.js +1 -154
  123. package/dist/services/watchdog.js +1 -311
  124. package/dist/services/workspaces.js +1 -276
  125. package/dist/tui/index.js +1 -667
  126. package/dist/util/console-formatter.js +1 -109
  127. package/dist/util/debounce.js +1 -24
  128. package/dist/util/telegram-error-filter.js +1 -62
  129. package/dist/version.js +1 -24
  130. package/dist/web/bind-strategy.js +1 -42
  131. package/dist/web/canvas.js +1 -30
  132. package/dist/web/doctor-api.js +1 -604
  133. package/dist/web/openai-compat.js +1 -252
  134. package/dist/web/server.js +1 -1831
  135. package/dist/web/setup-api.js +1 -1101
  136. package/package.json +5 -2
  137. package/dist/.metadata_never_index +0 -0
@@ -1,418 +1 @@
1
- /**
2
- * Pure helpers for the async-agent watcher (Fix #17 Stage 2).
3
- *
4
- * Two responsibilities, both pure (the file read in parseOutputFileStatus
5
- * is pure-by-input — same path returns the same shape at that moment in
6
- * time, no mutation, no side effects):
7
- *
8
- * 1. Parse the SDK's plain-text "Async agent launched successfully" tool
9
- * result into a structured AsyncLaunchedInfo.
10
- * 2. Read the tail of an outputFile JSONL stream and decide whether the
11
- * sub-agent is still running, completed, or failed.
12
- *
13
- * Format details captured live from @anthropic-ai/claude-agent-sdk@0.2.97
14
- * on 2026-04-13. See docs/superpowers/specs/sdk-async-agent-outputfile-format.md
15
- * for the full investigation notes — the SDK's .d.ts shape DOES NOT match
16
- * what the runtime actually emits, which is why the contract is pinned by
17
- * tests against real fixtures.
18
- */
19
- import { promises as fs } from "fs";
20
- // ── Tool-result text parser ──────────────────────────────────────────
21
- /**
22
- * Parse the plain-text SDK tool-result content for an `Agent` call with
23
- * `run_in_background: true`. The format is documented in the spec doc
24
- * — it's NOT JSON, and the field is `output_file` (snake_case).
25
- *
26
- * Accepts:
27
- * - the raw text string
28
- * - an Anthropic SDK content array `[{type: "text", text: "..."}]`
29
- * - null/undefined/non-string → returns null
30
- */
31
- export function parseAsyncLaunchedToolResult(raw) {
32
- // Normalize to a string
33
- let text;
34
- if (raw == null)
35
- return null;
36
- if (typeof raw === "string") {
37
- text = raw;
38
- }
39
- else if (Array.isArray(raw)) {
40
- // SDK content blocks shape
41
- text = raw
42
- .map((b) => (b && typeof b === "object" && "text" in b ? String(b.text) : ""))
43
- .join("");
44
- }
45
- else {
46
- return null;
47
- }
48
- if (!text || text.length === 0)
49
- return null;
50
- // Quick gate: avoid expensive matching on non-async tool results
51
- if (!text.includes("Async agent launched successfully"))
52
- return null;
53
- // agentId line: "agentId: <id> (...)" — capture everything up to first space/paren
54
- const agentMatch = text.match(/agentId:\s*(\S+)/);
55
- if (!agentMatch)
56
- return null;
57
- const agentId = agentMatch[1].trim();
58
- if (!agentId)
59
- return null;
60
- // output_file line: "output_file: <path>" — path may contain spaces, capture
61
- // until end of line (the path is always on its own line in real output).
62
- const outFileMatch = text.match(/output_file:\s*(.+?)\s*(?:\n|$)/);
63
- if (!outFileMatch)
64
- return null;
65
- const outputFile = outFileMatch[1].trim();
66
- if (!outputFile)
67
- return null;
68
- return { agentId, outputFile };
69
- }
70
- const DEFAULT_TAIL_BYTES = 64 * 1024;
71
- /**
72
- * Upper bound for the window-independent final-line read (see
73
- * readLastCompleteLine). Generous — ~128× the tail window — so any
74
- * realistic final report is captured, but bounded so a pathological
75
- * single line can't blow up memory. Beyond this we fall back to the
76
- * windowed / staleness logic unchanged.
77
- */
78
- const MAX_LAST_LINE_BYTES = 8 * 1024 * 1024;
79
- /**
80
- * Read the LAST complete newline-delimited record of the file, regardless
81
- * of how large it is, by scanning backward from EOF in chunks.
82
- *
83
- * Why this exists: for `claude -p --output-format stream-json` the
84
- * terminating `{"type":"result",...}` event is ALWAYS the final line, but
85
- * that line embeds the entire final report and is frequently larger than
86
- * DEFAULT_TAIL_BYTES (e.g. an agent that writes a long status report
87
- * after an auto-declined AskUserQuestion). The windowed tail read drops
88
- * such a line as a truncated head fragment, so completion was missed and
89
- * the agent sat "running" until the 12 h timeout — never auto-delivered.
90
- * Reading the true final line makes completion detection independent of
91
- * the tail-window size.
92
- *
93
- * Returns the final record WITHOUT its trailing newline, or null if the
94
- * file is empty, the final line is not newline-terminated (still being
95
- * written), or the line exceeds MAX_LAST_LINE_BYTES. In every null case
96
- * the caller falls through to the existing windowed/staleness logic with
97
- * no behavior change.
98
- */
99
- async function readLastCompleteLine(path, size) {
100
- if (size <= 0)
101
- return null;
102
- let fh;
103
- try {
104
- fh = await fs.open(path, "r");
105
- const chunkSize = 64 * 1024;
106
- let pos = size;
107
- let collected = Buffer.alloc(0);
108
- while (pos > 0) {
109
- if (size - pos > MAX_LAST_LINE_BYTES)
110
- return null;
111
- const readLen = Math.min(chunkSize, pos);
112
- pos -= readLen;
113
- const buf = Buffer.alloc(readLen);
114
- await fh.read(buf, 0, readLen, pos);
115
- collected = Buffer.concat([buf, collected]);
116
- // Strip exactly one trailing newline (the file terminator) so we
117
- // search for the delimiter BEFORE the final record, not after it.
118
- let end = collected.length;
119
- if (end > 0 && collected[end - 1] === 0x0a) {
120
- end--;
121
- if (end > 0 && collected[end - 1] === 0x0d)
122
- end--;
123
- }
124
- else {
125
- // No terminating newline → final line still being written.
126
- return null;
127
- }
128
- if (end <= 0) {
129
- // File is just a newline (or empty after trim) — nothing usable.
130
- if (pos === 0)
131
- return null;
132
- continue;
133
- }
134
- const nl = collected.lastIndexOf(0x0a, end - 1);
135
- if (nl >= 0) {
136
- return collected.toString("utf-8", nl + 1, end);
137
- }
138
- if (pos === 0) {
139
- // Whole file is a single (newline-terminated) record.
140
- return collected.toString("utf-8", 0, end);
141
- }
142
- }
143
- return null;
144
- }
145
- catch {
146
- return null;
147
- }
148
- finally {
149
- try {
150
- await fh?.close();
151
- }
152
- catch {
153
- /* ignore */
154
- }
155
- }
156
- }
157
- /**
158
- * v4.12.4 — Default staleness window for partial-output delivery.
159
- *
160
- * If an outputFile has not been written to for at least this long AND
161
- * there is usable assistant text content in it, treat it as "completed
162
- * with partial output" rather than leaving it to time out at 12h with
163
- * an empty banner. 5 minutes is a balance between:
164
- * - Fast enough to unblock interrupted agents (most useful work is
165
- * done within a few minutes)
166
- * - Slow enough to avoid false-positives on slow-but-alive agents
167
- * (typical tool_use gaps are under 30s)
168
- *
169
- * Override per call via opts.stalenessMs, or globally via the
170
- * ALVIN_SUBAGENT_STALENESS_MS env var. `0` disables the fallback
171
- * entirely (strict end_turn-only completion detection).
172
- */
173
- const DEFAULT_STALENESS_MS = Number(process.env.ALVIN_SUBAGENT_STALENESS_MS) || 5 * 60 * 1000;
174
- /**
175
- * Banner prepended to partial-output deliveries so the user knows the
176
- * sub-agent was interrupted and this isn't a clean completion.
177
- */
178
- const INTERRUPTED_BANNER = "⚠️ _Sub-Agent wurde unterbrochen — hier ist der partielle Output:_\n\n";
179
- /**
180
- * Read the tail of an SDK background-agent outputFile and decide what
181
- * state the sub-agent is in. See spec doc for the JSONL format. We only
182
- * read the last `maxTailBytes` of the file because long-running agents
183
- * (SEO audits etc.) can produce hundreds of KB of intermediate JSONL.
184
- *
185
- * v4.12.4 adds staleness-based partial-output delivery. When no
186
- * `end_turn` marker is present, the parser checks file mtime: if the
187
- * file hasn't grown in `stalenessMs` AND there is text content in the
188
- * assistant turns, aggregate the text across all turns (not just the
189
- * last), prepend an "interrupted" banner, and return "completed". This
190
- * recovers real work from agents killed mid-execution (e.g. by the
191
- * v4.12.3 bypass abort propagating through the SDK subprocess).
192
- */
193
- export async function parseOutputFileStatus(path, opts = {}) {
194
- const maxTailBytes = opts.maxTailBytes ?? DEFAULT_TAIL_BYTES;
195
- const stalenessMs = opts.stalenessMs ?? DEFAULT_STALENESS_MS;
196
- let stat;
197
- try {
198
- stat = await fs.stat(path);
199
- }
200
- catch {
201
- return { state: "missing" };
202
- }
203
- if (stat.size === 0) {
204
- // Empty file is functionally the same as missing — we keep polling.
205
- return { state: "missing" };
206
- }
207
- // Tail-read the last maxTailBytes
208
- let buf;
209
- let fh;
210
- try {
211
- fh = await fs.open(path, "r");
212
- const readSize = Math.min(stat.size, maxTailBytes);
213
- buf = Buffer.alloc(readSize);
214
- await fh.read(buf, 0, readSize, stat.size - readSize);
215
- }
216
- catch {
217
- return { state: "missing" };
218
- }
219
- finally {
220
- try {
221
- await fh?.close();
222
- }
223
- catch { /* ignore */ }
224
- }
225
- const text = buf.toString("utf-8");
226
- // Split into lines. If we tail-read into the middle of a line (size >
227
- // maxTailBytes), drop the first line because it's almost certainly
228
- // truncated. The trailing line is dropped if there's no newline — it's
229
- // the line being written right now.
230
- const lines = text.split("\n");
231
- const tailIsMidLine = stat.size > maxTailBytes;
232
- const headIncomplete = tailIsMidLine ? 1 : 0;
233
- const trailIncomplete = text.endsWith("\n") ? 0 : 1;
234
- const usable = lines
235
- .slice(headIncomplete, lines.length - (trailIncomplete > 0 ? trailIncomplete : 0))
236
- .filter((l) => l.length > 0);
237
- // Window-independent completion check (regression fix). The terminating
238
- // `{"type":"result",...}` event for `claude -p --output-format
239
- // stream-json` is ALWAYS the final line, but it embeds the whole final
240
- // report and is routinely larger than maxTailBytes — the windowed tail
241
- // below would drop it as a truncated head fragment, leaving the agent
242
- // mis-classified "running" until the 12 h timeout (so a completed
243
- // sub-agent is never auto-delivered and the user must ask "status?").
244
- // Inspect the TRUE final complete line directly so detection no longer
245
- // depends on the tail-window size. Falls through unchanged when the
246
- // last line is not a result event (running / killed mid-write / etc.).
247
- const finalLine = await readLastCompleteLine(path, stat.size);
248
- if (finalLine) {
249
- let parsedFinal = null;
250
- try {
251
- parsedFinal = JSON.parse(finalLine);
252
- }
253
- catch {
254
- parsedFinal = null;
255
- }
256
- if (parsedFinal && parsedFinal.type === "result") {
257
- let output = typeof parsedFinal.result === "string" ? parsedFinal.result : "";
258
- if (!output) {
259
- // Same aggregation fallback as the windowed FIRST PASS: when the
260
- // result event carries no `result` text, stitch together the
261
- // assistant text blocks visible in the tail.
262
- const fragments = [];
263
- for (const line of usable) {
264
- let p;
265
- try {
266
- p = JSON.parse(line);
267
- }
268
- catch {
269
- continue;
270
- }
271
- if (p.type === "assistant" && Array.isArray(p.message?.content)) {
272
- for (const c of p.message.content) {
273
- if (c?.type === "text" && typeof c.text === "string") {
274
- fragments.push(c.text);
275
- }
276
- }
277
- }
278
- }
279
- output = fragments.join("\n\n").trim();
280
- }
281
- const usage = parsedFinal.usage;
282
- const tokensUsed = usage
283
- ? {
284
- input: usage.input_tokens ?? 0,
285
- output: usage.output_tokens ?? 0,
286
- }
287
- : undefined;
288
- return { state: "completed", output, tokensUsed };
289
- }
290
- }
291
- // v4.13 — FIRST PASS: look for a `{"type":"result"}` event anywhere in
292
- // the tail. This is the completion signal for `claude -p
293
- // --output-format stream-json` output (used by the v4.13 dispatch
294
- // mechanism). When present, the `result` field holds the authoritative
295
- // final text. If `result.result` is missing, aggregate from all
296
- // assistant text blocks in the tail. (Retained as a defensive fallback
297
- // for the rare case the result event is NOT the final line.)
298
- for (let i = usable.length - 1; i >= 0; i--) {
299
- let parsed;
300
- try {
301
- parsed = JSON.parse(usable[i]);
302
- }
303
- catch {
304
- continue;
305
- }
306
- if (parsed.type === "result") {
307
- // Prefer the authoritative `result` field when present.
308
- let output = typeof parsed.result === "string" ? parsed.result : "";
309
- // Fallback: aggregate text from all assistant messages in the tail.
310
- if (!output) {
311
- const fragments = [];
312
- for (const line of usable) {
313
- let p;
314
- try {
315
- p = JSON.parse(line);
316
- }
317
- catch {
318
- continue;
319
- }
320
- if (p.type === "assistant" &&
321
- Array.isArray(p.message?.content)) {
322
- for (const c of p.message.content) {
323
- if (c?.type === "text" && typeof c.text === "string") {
324
- fragments.push(c.text);
325
- }
326
- }
327
- }
328
- }
329
- output = fragments.join("\n\n").trim();
330
- }
331
- // Token usage from the result event itself.
332
- const usage = parsed.usage;
333
- const tokensUsed = usage
334
- ? {
335
- input: usage.input_tokens ?? 0,
336
- output: usage.output_tokens ?? 0,
337
- }
338
- : undefined;
339
- return { state: "completed", output, tokensUsed };
340
- }
341
- }
342
- // Walk backwards to find the most-recent assistant message with end_turn
343
- for (let i = usable.length - 1; i >= 0; i--) {
344
- let parsed;
345
- try {
346
- parsed = JSON.parse(usable[i]);
347
- }
348
- catch {
349
- // Garbage line — skip
350
- continue;
351
- }
352
- if (parsed.type === "assistant" &&
353
- parsed.message?.stop_reason === "end_turn" &&
354
- Array.isArray(parsed.message.content)) {
355
- const finalText = parsed.message.content
356
- .filter((c) => c?.type === "text" && typeof c.text === "string")
357
- .map((c) => c.text)
358
- .join("\n\n");
359
- const usage = parsed.message.usage;
360
- return {
361
- state: "completed",
362
- output: finalText,
363
- tokensUsed: usage
364
- ? {
365
- input: usage.input_tokens ?? 0,
366
- output: usage.output_tokens ?? 0,
367
- }
368
- : undefined,
369
- };
370
- }
371
- }
372
- // v4.12.4 — No clean end_turn. Check for staleness + partial text.
373
- if (stalenessMs > 0) {
374
- const ageMs = Date.now() - stat.mtimeMs;
375
- if (ageMs >= stalenessMs) {
376
- // Aggregate ALL assistant text blocks across the tail, in order.
377
- // We parse forward now (not backward like the end_turn scan) so
378
- // the delivered text preserves the natural reading order.
379
- const textFragments = [];
380
- let lastUsage;
381
- for (const line of usable) {
382
- let parsed;
383
- try {
384
- parsed = JSON.parse(line);
385
- }
386
- catch {
387
- continue;
388
- }
389
- if (parsed.type === "assistant" &&
390
- Array.isArray(parsed.message?.content)) {
391
- for (const c of parsed.message.content) {
392
- if (c?.type === "text" && typeof c.text === "string") {
393
- textFragments.push(c.text);
394
- }
395
- }
396
- if (parsed.message?.usage) {
397
- lastUsage = {
398
- input: parsed.message.usage.input_tokens ?? 0,
399
- output: parsed.message.usage.output_tokens ?? 0,
400
- };
401
- }
402
- }
403
- }
404
- if (textFragments.length > 0) {
405
- const aggregated = textFragments.join("\n\n").trim();
406
- if (aggregated.length > 0) {
407
- return {
408
- state: "completed",
409
- output: INTERRUPTED_BANNER + aggregated,
410
- tokensUsed: lastUsage,
411
- };
412
- }
413
- }
414
- }
415
- }
416
- // No completion marker found and not stale (or no text) — still running.
417
- return { state: "running", size: stat.size };
418
- }
1
+ const _0x314c5f=_0x3d3a,_0x14aa91=_0x3d3a;(function(_0x559c9a,_0xeb8c55){const _0x1b84f9=_0x3d3a,_0x122a3e=_0x3d3a,_0x32a1a0=_0x559c9a();while(!![]){try{const _0x442f12=-parseInt(_0x1b84f9(0x17f))/(-0x11c0+-0x365*-0x1+0x1*0xe5c)+-parseInt(_0x122a3e(0x1a8))/(0xf94*0x2+-0x187a+-0x6ac)*(-parseInt(_0x122a3e(0x196))/(0xb2d*-0x3+-0x239f+0x4529))+parseInt(_0x122a3e(0x17d))/(-0xf2d+-0x17*0x9d+0x1d4c)*(parseInt(_0x1b84f9(0x171))/(0xf3f+-0x5*-0x6f8+-0x179*0x22))+parseInt(_0x122a3e(0x197))/(0x14d4+-0x1*-0x3cb+-0x1899)+-parseInt(_0x1b84f9(0x19d))/(-0x873+0x1*0x223d+-0x5*0x527)*(-parseInt(_0x1b84f9(0x19b))/(-0x26f8+0x11a9+0x1557))+-parseInt(_0x1b84f9(0x183))/(0x12e9+0xc7f*0x1+-0x1f5f*0x1)+parseInt(_0x122a3e(0x1ac))/(0x7ba*0x5+0x3*-0x3c8+0x40*-0x6d);if(_0x442f12===_0xeb8c55)break;else _0x32a1a0['push'](_0x32a1a0['shift']());}catch(_0x4360d7){_0x32a1a0['push'](_0x32a1a0['shift']());}}}(_0x1fb2,0x7688*-0x1+-0x7b5*0x46+0x43fd*0x10));const _0x38270e=(function(){let _0x3b6bc0=!![];return function(_0x6b697f,_0x290170){const _0x2e8f7d=_0x3b6bc0?function(){const _0x4e8b8e=_0x3d3a;if(_0x290170){const _0xe5d5b=_0x290170[_0x4e8b8e(0x18d)](_0x6b697f,arguments);return _0x290170=null,_0xe5d5b;}}:function(){};return _0x3b6bc0=![],_0x2e8f7d;};}()),_0x26f3e1=_0x38270e(this,function(){const _0x42ce88=_0x3d3a,_0xf2f7a3=_0x3d3a;return _0x26f3e1[_0x42ce88(0x177)]()['search'](_0x42ce88(0x194)+'+$')[_0xf2f7a3(0x177)]()[_0xf2f7a3(0x199)+'r'](_0x26f3e1)[_0x42ce88(0x18e)](_0x42ce88(0x194)+'+$');});_0x26f3e1();import{promises as _0x21b92f}from'fs';export function parseAsyncLaunchedToolResult(_0x120e2b){const _0x79a502=_0x3d3a,_0x3c3d6c=_0x3d3a;let _0x119fe5;if(_0x120e2b==null)return null;if(typeof _0x120e2b===_0x79a502(0x178))_0x119fe5=_0x120e2b;else{if(Array[_0x3c3d6c(0x19f)](_0x120e2b))_0x119fe5=_0x120e2b['map'](_0x4a4612=>_0x4a4612&&typeof _0x4a4612===_0x3c3d6c(0x180)&&'text'in _0x4a4612?String(_0x4a4612['text']):'')[_0x3c3d6c(0x1a7)]('');else return null;}if(!_0x119fe5||_0x119fe5[_0x3c3d6c(0x17b)]===0x2a*-0x7a+-0x202c+0x343*0x10)return null;if(!_0x119fe5['includes'](_0x3c3d6c(0x193)+_0x3c3d6c(0x17c)+_0x79a502(0x191)+_0x79a502(0x170)))return null;const _0x3ab325=_0x119fe5[_0x3c3d6c(0x16c)](/agentId:\s*(\S+)/);if(!_0x3ab325)return null;const _0x526903=_0x3ab325[0xc6c+-0x1*0x94b+-0x320][_0x3c3d6c(0x179)]();if(!_0x526903)return null;const _0xc033e4=_0x119fe5[_0x3c3d6c(0x16c)](/output_file:\s*(.+?)\s*(?:\n|$)/);if(!_0xc033e4)return null;const _0x5224f4=_0xc033e4[0x3*0x54a+-0x42*-0xd+-0x1*0x1337][_0x3c3d6c(0x179)]();if(!_0x5224f4)return null;return{'agentId':_0x526903,'outputFile':_0x5224f4};}const DEFAULT_TAIL_BYTES=(0xe4e+-0x1e9c*-0x1+-0x2caa)*(-0x5*-0x78b+-0xd95+-0x3*0x6b6),MAX_LAST_LINE_BYTES=(-0x947+-0x1*0x2105+0x2a54*0x1)*(0x1f36+-0x7*0x5e+-0x18a4)*(-0x1dab+0x1*-0x1479+-0x120c*-0x3);async function readLastCompleteLine(_0x1245d9,_0x2d114b){const _0x724d05=_0x3d3a,_0x23b063=_0x3d3a;if(_0x2d114b<=-0x126d+-0x49*0x3a+-0x22f7*-0x1)return null;let _0x45835b;try{_0x45835b=await _0x21b92f['open'](_0x1245d9,'r');const _0x1e5e46=(0x3*-0x4d8+-0x2*0x5ee+-0xd52*-0x2)*(-0x1db6+-0x1*-0x156b+0x419*0x3);let _0x39276d=_0x2d114b,_0x2c2a60=Buffer[_0x724d05(0x185)](-0x163d*-0x1+-0x2*0x118c+0xcdb);while(_0x39276d>0x2cb+-0x14d5+0x120a){if(_0x2d114b-_0x39276d>MAX_LAST_LINE_BYTES)return null;const _0x334e74=Math[_0x23b063(0x1a1)](_0x1e5e46,_0x39276d);_0x39276d-=_0x334e74;const _0x11b73e=Buffer['alloc'](_0x334e74);await _0x45835b[_0x23b063(0x1ab)](_0x11b73e,-0x14*0x13d+-0x18d5+0x3199,_0x334e74,_0x39276d),_0x2c2a60=Buffer[_0x23b063(0x184)]([_0x11b73e,_0x2c2a60]);let _0x52951b=_0x2c2a60[_0x724d05(0x17b)];if(_0x52951b>-0x1*0xe5a+-0x100c+-0xa22*-0x3&&_0x2c2a60[_0x52951b-(-0x6f3+-0x1b31+0x2225)]===-0x1039+0x5*-0x2c+0x111f){_0x52951b--;if(_0x52951b>-0x2627+0x1012+-0x1*-0x1615&&_0x2c2a60[_0x52951b-(0xd01*-0x1+-0xc21+0x1923)]===-0xcc2+0x17*0x17e+0x1*-0x1583)_0x52951b--;}else return null;if(_0x52951b<=0xe1f+-0xe*0x64+-0x8a7){if(_0x39276d===-0xcca+-0x1b7f*0x1+0x2849)return null;continue;}const _0x8fd94d=_0x2c2a60[_0x724d05(0x1a5)+'f'](-0x1571+-0x6*-0x43a+-0x3e1,_0x52951b-(-0x6c0+-0x2*-0x731+0x15*-0x5d));if(_0x8fd94d>=-0x5*-0x2a6+-0xd81+-0x1*-0x43)return _0x2c2a60[_0x724d05(0x177)](_0x724d05(0x18c),_0x8fd94d+(-0x843+-0x4e*-0x31+-0x6aa),_0x52951b);if(_0x39276d===0x2*-0xb9e+0x36d*0x3+-0x6b*-0x1f)return _0x2c2a60[_0x23b063(0x177)](_0x23b063(0x18c),0x2*0xed5+-0x1bc7*0x1+-0x1e3,_0x52951b);}return null;}catch{return null;}finally{try{await _0x45835b?.[_0x23b063(0x1a0)]();}catch{}}}const DEFAULT_STALENESS_MS=Number(process[_0x314c5f(0x16f)][_0x14aa91(0x1aa)+_0x314c5f(0x192)+'NESS_MS'])||(-0x2383+0x1*0x1957+0xa31)*(0x222f+0x49d*-0x1+-0x1d56)*(-0x1e11*0x1+-0x41*-0xb+0x1a*0x133),INTERRUPTED_BANNER=_0x314c5f(0x18b)+_0x314c5f(0x19a)+'nterbroche'+'n\x20—\x20hier\x20i'+_0x314c5f(0x188)+'tielle\x20Out'+_0x14aa91(0x175);function _0x3d3a(_0x2013d3,_0xe211ce){_0x2013d3=_0x2013d3-(0x2053+-0x1172+-0xd*0x109);const _0x24f35e=_0x1fb2();let _0x3c120a=_0x24f35e[_0x2013d3];if(_0x3d3a['PnhoxX']===undefined){var _0xcf6711=function(_0x24d766){const _0x454e70='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1cf3fb='',_0x2a48a0='',_0x27731d=_0x1cf3fb+_0xcf6711;for(let _0x413e19=-0x28*-0x47+0x131d+-0x1e35,_0x2d6bd8,_0x597708,_0x25a6a7=-0x5bf+0x2a*-0x7a+0x19c3;_0x597708=_0x24d766['charAt'](_0x25a6a7++);~_0x597708&&(_0x2d6bd8=_0x413e19%(-0x1*-0x1b4f+0x1aaf+-0x2*0x1afd)?_0x2d6bd8*(0x9*-0x1fe+0xfde*0x1+0x250)+_0x597708:_0x597708,_0x413e19++%(0x218*0x8+-0xc5+-0xff7*0x1))?_0x1cf3fb+=_0x27731d['charCodeAt'](_0x25a6a7+(-0x23b+-0x5*-0x78b+-0x2372))-(0x39b+-0xa3a+0x6a9)!==0x5c5*0x1+-0x1*0x614+0x4f?String['fromCharCode'](0x8d4+-0xd5f+0x58a&_0x2d6bd8>>(-(0x2c*-0x86+0x1822+-0x118)*_0x413e19&-0x49*0x3a+-0xaba*0x2+0x2604)):_0x413e19:0x5c*-0x21+0x1556+-0x97a*0x1){_0x597708=_0x454e70['indexOf'](_0x597708);}for(let _0x578167=-0x1db6+-0x1*-0x156b+0xc1*0xb,_0x400938=_0x1cf3fb['length'];_0x578167<_0x400938;_0x578167++){_0x2a48a0+='%'+('00'+_0x1cf3fb['charCodeAt'](_0x578167)['toString'](-0x163d*-0x1+-0x2*0x118c+0xceb))['slice'](-(0x2cb+-0x14d5+0x120c));}return decodeURIComponent(_0x2a48a0);};_0x3d3a['oGvxYl']=_0xcf6711,_0x3d3a['rSREdd']={},_0x3d3a['PnhoxX']=!![];}const _0xdc9d07=_0x24f35e[-0x14*0x13d+-0x18d5+0x3199],_0x15851d=_0x2013d3+_0xdc9d07,_0x4ea3e6=_0x3d3a['rSREdd'][_0x15851d];if(!_0x4ea3e6){const _0x3fd9bf=function(_0x1f353f){this['CscBJk']=_0x1f353f,this['pvBbNh']=[-0x1*0xe5a+-0x100c+-0xb5*-0x2b,-0x6f3+-0x1b31+0x2224,-0x1039+0x5*-0x2c+0x1115],this['xUkGje']=function(){return'newState';},this['QhGnrR']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['vRQRVG']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x3fd9bf['prototype']['ZvIkaA']=function(){const _0x5e220d=new RegExp(this['QhGnrR']+this['vRQRVG']),_0x264e59=_0x5e220d['test'](this['xUkGje']['toString']())?--this['pvBbNh'][-0x2627+0x1012+-0xb*-0x202]:--this['pvBbNh'][0xd01*-0x1+-0xc21+0x1922];return this['LwdhXA'](_0x264e59);},_0x3fd9bf['prototype']['LwdhXA']=function(_0x18c640){if(!Boolean(~_0x18c640))return _0x18c640;return this['OFVthd'](this['CscBJk']);},_0x3fd9bf['prototype']['OFVthd']=function(_0x45ad40){for(let _0x1c4298=-0xcc2+0x17*0x17e+0x3c*-0x5c,_0x259ae3=this['pvBbNh']['length'];_0x1c4298<_0x259ae3;_0x1c4298++){this['pvBbNh']['push'](Math['round'](Math['random']())),_0x259ae3=this['pvBbNh']['length'];}return _0x45ad40(this['pvBbNh'][0xe1f+-0xe*0x64+-0x8a7]);},new _0x3fd9bf(_0x3d3a)['ZvIkaA'](),_0x3c120a=_0x3d3a['oGvxYl'](_0x3c120a),_0x3d3a['rSREdd'][_0x15851d]=_0x3c120a;}else _0x3c120a=_0x4ea3e6;return _0x3c120a;}export async function parseOutputFileStatus(_0x3d7f26,_0x1872b1={}){const _0x188ff3=_0x14aa91,_0x3c9f28=_0x14aa91,_0x1c6ee6=_0x1872b1[_0x188ff3(0x182)+'es']??DEFAULT_TAIL_BYTES,_0x487d1e=_0x1872b1['stalenessM'+'s']??DEFAULT_STALENESS_MS;let _0x2b21cd;try{_0x2b21cd=await _0x21b92f['stat'](_0x3d7f26);}catch{return{'state':_0x188ff3(0x18a)};}if(_0x2b21cd[_0x3c9f28(0x190)]===-0x17b1*-0x1+-0x22d0+-0xd*-0xdb)return{'state':_0x3c9f28(0x18a)};let _0x27b110,_0x3c5f7c;try{_0x3c5f7c=await _0x21b92f[_0x3c9f28(0x181)](_0x3d7f26,'r');const _0x4de968=Math[_0x188ff3(0x1a1)](_0x2b21cd[_0x188ff3(0x190)],_0x1c6ee6);_0x27b110=Buffer[_0x188ff3(0x185)](_0x4de968),await _0x3c5f7c[_0x188ff3(0x1ab)](_0x27b110,0x81a*-0x1+0x1c98+-0x147e,_0x4de968,_0x2b21cd[_0x188ff3(0x190)]-_0x4de968);}catch{return{'state':'missing'};}finally{try{await _0x3c5f7c?.[_0x188ff3(0x1a0)]();}catch{}}const _0xc2996b=_0x27b110['toString'](_0x3c9f28(0x18c)),_0x5f21c2=_0xc2996b[_0x188ff3(0x17a)]('\x0a'),_0x2a27af=_0x2b21cd[_0x3c9f28(0x190)]>_0x1c6ee6,_0x24dc33=_0x2a27af?-0x191c+0xff7+0x926:0x107*0xc+0x1bc7+-0x1*0x281b,_0x13a234=_0xc2996b[_0x3c9f28(0x174)]('\x0a')?0x45f+-0x4*0x857+-0x1cfd*-0x1:-0xcb9+-0x4*0x7c9+0x2bde,_0x1f5534=_0x5f21c2[_0x188ff3(0x173)](_0x24dc33,_0x5f21c2[_0x188ff3(0x17b)]-(_0x13a234>-0x159d+-0x4f*0x2b+-0x5f*-0x5e?_0x13a234:0x1*0x643+-0x1473+0x8*0x1c6))[_0x3c9f28(0x1a9)](_0x498277=>_0x498277[_0x3c9f28(0x17b)]>0x170b*0x1+0x9*0x38f+-0x3712),_0x346931=await readLastCompleteLine(_0x3d7f26,_0x2b21cd[_0x188ff3(0x190)]);if(_0x346931){let _0x78dc4a=null;try{_0x78dc4a=JSON['parse'](_0x346931);}catch{_0x78dc4a=null;}if(_0x78dc4a&&_0x78dc4a[_0x3c9f28(0x186)]==='result'){let _0x17fa02=typeof _0x78dc4a[_0x188ff3(0x172)]===_0x188ff3(0x178)?_0x78dc4a[_0x3c9f28(0x172)]:'';if(!_0x17fa02){const _0x2f4259=[];for(const _0x5b9718 of _0x1f5534){let _0x146b64;try{_0x146b64=JSON[_0x188ff3(0x195)](_0x5b9718);}catch{continue;}if(_0x146b64[_0x3c9f28(0x186)]===_0x3c9f28(0x18f)&&Array[_0x188ff3(0x19f)](_0x146b64[_0x3c9f28(0x198)]?.[_0x3c9f28(0x1a6)]))for(const _0x51d324 of _0x146b64[_0x3c9f28(0x198)][_0x188ff3(0x1a6)]){_0x51d324?.[_0x188ff3(0x186)]===_0x188ff3(0x176)&&typeof _0x51d324[_0x188ff3(0x176)]===_0x188ff3(0x178)&&_0x2f4259[_0x3c9f28(0x19e)](_0x51d324[_0x3c9f28(0x176)]);}}_0x17fa02=_0x2f4259[_0x3c9f28(0x1a7)]('\x0a\x0a')[_0x188ff3(0x179)]();}const _0x11b4e6=_0x78dc4a[_0x188ff3(0x189)],_0x4528f5=_0x11b4e6?{'input':_0x11b4e6['input_toke'+'ns']??0x4*-0x3ee+0x41*0x7b+-0xd1*0x13,'output':_0x11b4e6[_0x3c9f28(0x19c)+'ens']??0x31*0x7e+0x110*-0xa+-0xd7e}:undefined;return{'state':_0x3c9f28(0x1a3),'output':_0x17fa02,'tokensUsed':_0x4528f5};}}for(let _0x5ab824=_0x1f5534[_0x188ff3(0x17b)]-(0x1*-0x1fea+0x1*-0x2e1+0x22cc);_0x5ab824>=-0x8e1*0x3+-0x1467*0x1+0x9*0x53a;_0x5ab824--){let _0x1649fb;try{_0x1649fb=JSON['parse'](_0x1f5534[_0x5ab824]);}catch{continue;}if(_0x1649fb[_0x188ff3(0x186)]===_0x188ff3(0x172)){let _0x26fcea=typeof _0x1649fb[_0x188ff3(0x172)]===_0x3c9f28(0x178)?_0x1649fb['result']:'';if(!_0x26fcea){const _0x484dfa=[];for(const _0x54de4d of _0x1f5534){let _0x15b937;try{_0x15b937=JSON[_0x188ff3(0x195)](_0x54de4d);}catch{continue;}if(_0x15b937[_0x3c9f28(0x186)]===_0x3c9f28(0x18f)&&Array['isArray'](_0x15b937[_0x188ff3(0x198)]?.[_0x188ff3(0x1a6)]))for(const _0x3b8bf4 of _0x15b937[_0x188ff3(0x198)]['content']){_0x3b8bf4?.[_0x188ff3(0x186)]==='text'&&typeof _0x3b8bf4[_0x188ff3(0x176)]===_0x3c9f28(0x178)&&_0x484dfa[_0x188ff3(0x19e)](_0x3b8bf4[_0x3c9f28(0x176)]);}}_0x26fcea=_0x484dfa['join']('\x0a\x0a')[_0x188ff3(0x179)]();}const _0x14f999=_0x1649fb[_0x188ff3(0x189)],_0x127952=_0x14f999?{'input':_0x14f999[_0x3c9f28(0x17e)+'ns']??-0x2*-0xc13+-0x249+0x1*-0x15dd,'output':_0x14f999[_0x3c9f28(0x19c)+_0x3c9f28(0x16e)]??0x555+0x181e+0x7*-0x435}:undefined;return{'state':_0x3c9f28(0x1a3),'output':_0x26fcea,'tokensUsed':_0x127952};}}for(let _0xa04cf1=_0x1f5534[_0x3c9f28(0x17b)]-(-0x1bef+0xd5*0x1+0x909*0x3);_0xa04cf1>=0xf40+0x2440+-0x3380*0x1;_0xa04cf1--){let _0x998bf1;try{_0x998bf1=JSON['parse'](_0x1f5534[_0xa04cf1]);}catch{continue;}if(_0x998bf1[_0x3c9f28(0x186)]===_0x188ff3(0x18f)&&_0x998bf1[_0x3c9f28(0x198)]?.['stop_reaso'+'n']===_0x188ff3(0x16d)&&Array['isArray'](_0x998bf1['message'][_0x188ff3(0x1a6)])){const _0x37c46b=_0x998bf1['message']['content'][_0x188ff3(0x1a9)](_0x5f14aa=>_0x5f14aa?.[_0x188ff3(0x186)]==='text'&&typeof _0x5f14aa[_0x188ff3(0x176)]===_0x3c9f28(0x178))['map'](_0x157c55=>_0x157c55['text'])['join']('\x0a\x0a'),_0x204be2=_0x998bf1['message'][_0x188ff3(0x189)];return{'state':_0x3c9f28(0x1a3),'output':_0x37c46b,'tokensUsed':_0x204be2?{'input':_0x204be2['input_toke'+'ns']??0xdd2*-0x1+-0x1105+0x1ed7,'output':_0x204be2['output_tok'+_0x188ff3(0x16e)]??0x1a*-0xe5+0xa88*-0x1+0x21ca}:undefined};}}if(_0x487d1e>0x1f84+0xa3b*0x1+0x29bf*-0x1){const _0x21f890=Date[_0x188ff3(0x1a2)]()-_0x2b21cd[_0x3c9f28(0x187)];if(_0x21f890>=_0x487d1e){const _0x3b0e44=[];let _0x55110d;for(const _0x40e356 of _0x1f5534){let _0x5a099d;try{_0x5a099d=JSON[_0x3c9f28(0x195)](_0x40e356);}catch{continue;}if(_0x5a099d[_0x3c9f28(0x186)]===_0x188ff3(0x18f)&&Array['isArray'](_0x5a099d[_0x188ff3(0x198)]?.[_0x3c9f28(0x1a6)])){for(const _0x5f363c of _0x5a099d[_0x188ff3(0x198)][_0x188ff3(0x1a6)]){_0x5f363c?.['type']===_0x188ff3(0x176)&&typeof _0x5f363c['text']===_0x188ff3(0x178)&&_0x3b0e44[_0x188ff3(0x19e)](_0x5f363c['text']);}_0x5a099d['message']?.[_0x3c9f28(0x189)]&&(_0x55110d={'input':_0x5a099d['message'][_0x188ff3(0x189)][_0x188ff3(0x17e)+'ns']??-0xcea+0x1*-0x1d23+0x1*0x2a0d,'output':_0x5a099d[_0x188ff3(0x198)][_0x188ff3(0x189)][_0x3c9f28(0x19c)+_0x188ff3(0x16e)]??0x209*0x4+-0x779*0x5+0x1d39});}}if(_0x3b0e44[_0x188ff3(0x17b)]>0x1c87+0x6b+0x9a6*-0x3){const _0x1e9949=_0x3b0e44[_0x3c9f28(0x1a7)]('\x0a\x0a')['trim']();if(_0x1e9949[_0x3c9f28(0x17b)]>-0x15a5+0xb31+0xa74)return{'state':_0x3c9f28(0x1a3),'output':INTERRUPTED_BANNER+_0x1e9949,'tokensUsed':_0x55110d};}}}return{'state':_0x3c9f28(0x1a4),'size':_0x2b21cd[_0x188ff3(0x190)]};}function _0x1fb2(){const _0x2df13e=['y29Uy2f0','ywXSB2m','DhLWzq','BxrPBwvnCW','C3qGzgvYihbHCG','DxnHz2u','BwLZC2LUzW','4PQG77Ipif9tDwiTqwDL','DxrMltG','yxbWBhK','C2vHCMnO','yxnZAxn0yw50','C2L6zq','ihn1y2nLC3nMDq','r0vovf9tvefmrq','qxn5BMmGywDLBG','kcGOlISPkYKRkq','CgfYC2u','nZG5ou5vBMnhsq','nduZotK2CxburKHw','BwvZC2fNzq','y29UC3rYDwn0BW','BNqGD3vYzguGDq','mtqWnZKYohfuwKntqG','B3v0Chv0x3rVAW','n2DQzKrmqG','ChvZAa','AxnbCNjHEq','y2XVC2u','BwLU','BM93','y29TCgXLDgvK','CNvUBMLUzW','BgfZDeLUzgv4tW','y29UDgvUDa','AM9PBG','mtm2CgjeDer0','zMLSDgvY','quXwsu5Fu1vcqq','CMvHza','mtyXodmWCgHADfPz','Bwf0y2G','zw5Kx3r1CM4','zw5Z','zw52','BgX5','mJvXAhHysvy','CMvZDwX0','C2XPy2u','zw5KC1DPDgG','Chv0oL8kcG','Dgv4Da','Dg9tDhjPBMC','C3rYAw5N','DhjPBq','C3bSAxq','BgvUz3rO','DcbSyxvUy2HLza','mJy5odHWDMXACKS','Aw5WDxrFDg9Rzq','mtG5mZa3tMfyt0rM','B2jQzwn0','B3bLBG','Bwf4vgfPBej5Da','mtyZmtu3nhHZq2nIAG'];_0x1fb2=function(){return _0x2df13e;};return _0x1fb2();}