alvin-bot 5.7.0 → 5.8.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.
- package/CHANGELOG.md +25 -0
- package/README.md +25 -31
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -174
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -583
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -86
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1902
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
|
@@ -1,357 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CDP Bootstrap — spawns Chromium with remote-debugging-port=9222 independently.
|
|
3
|
-
*
|
|
4
|
-
* Avoids two problems that plague naive CDP setups:
|
|
5
|
-
*
|
|
6
|
-
* 1. **LaunchServices hijack** — invoking /Applications/Google Chrome.app while
|
|
7
|
-
* the user's Chrome is running silently redirects the call to the existing
|
|
8
|
-
* instance without applying --remote-debugging-port. Log symptom:
|
|
9
|
-
* "Wird in einer aktuellen Browsersitzung geöffnet." We avoid it by
|
|
10
|
-
* preferring Playwright's "Google Chrome for Testing" binary, which has a
|
|
11
|
-
* distinct bundle ID.
|
|
12
|
-
*
|
|
13
|
-
* 2. **Stale PID files** — a crashed Chromium leaves chrome-cdp.pid pointing at
|
|
14
|
-
* a dead process; subsequent starts conclude "already running" and fail
|
|
15
|
-
* silently. We verify liveness via both `ps` and a CDP /json/version probe.
|
|
16
|
-
*
|
|
17
|
-
* The module is idempotent: `ensureRunning()` is safe to call repeatedly; if
|
|
18
|
-
* CDP is already healthy it returns immediately.
|
|
19
|
-
*/
|
|
20
|
-
import { spawn } from "child_process";
|
|
21
|
-
import fs from "fs";
|
|
22
|
-
import path from "path";
|
|
23
|
-
import os from "os";
|
|
24
|
-
import http from "http";
|
|
25
|
-
import { CDP_PROFILE_DIR, CDP_SCREENSHOTS_DIR, CDP_PID_FILE, CDP_LOG_FILE, } from "../paths.js";
|
|
26
|
-
const CDP_PORT = 9222;
|
|
27
|
-
const CDP_VERSION_URL = `http://127.0.0.1:${CDP_PORT}/json/version`;
|
|
28
|
-
const START_TIMEOUT_MS = 15_000;
|
|
29
|
-
// ── Binary resolution ───────────────────────────────────────────────
|
|
30
|
-
/**
|
|
31
|
-
* Find Playwright's bundled Chromium. Prefers "Google Chrome for Testing"
|
|
32
|
-
* (distinct macOS bundle ID — no LaunchServices conflict with user Chrome),
|
|
33
|
-
* falls back to plain Chromium for older Playwright installs.
|
|
34
|
-
*
|
|
35
|
-
* Returns null if no bundled Chromium is present — callers should then fall
|
|
36
|
-
* back to a user-supplied binary or error out with guidance.
|
|
37
|
-
*/
|
|
38
|
-
export function findPlaywrightChromium() {
|
|
39
|
-
const pwRoot = path.join(os.homedir(), "Library", "Caches", "ms-playwright");
|
|
40
|
-
if (!fs.existsSync(pwRoot)) {
|
|
41
|
-
// Linux cache path
|
|
42
|
-
const linuxPwRoot = path.join(os.homedir(), ".cache", "ms-playwright");
|
|
43
|
-
if (fs.existsSync(linuxPwRoot))
|
|
44
|
-
return resolveFromPwRoot(linuxPwRoot);
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return resolveFromPwRoot(pwRoot);
|
|
48
|
-
}
|
|
49
|
-
function resolveFromPwRoot(pwRoot) {
|
|
50
|
-
let dirs;
|
|
51
|
-
try {
|
|
52
|
-
dirs = fs.readdirSync(pwRoot).filter((d) => /^chromium-\d+$/.test(d));
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
if (dirs.length === 0)
|
|
58
|
-
return null;
|
|
59
|
-
// Latest version by numeric suffix
|
|
60
|
-
dirs.sort((a, b) => {
|
|
61
|
-
const na = parseInt(a.replace("chromium-", ""), 10);
|
|
62
|
-
const nb = parseInt(b.replace("chromium-", ""), 10);
|
|
63
|
-
return nb - na;
|
|
64
|
-
});
|
|
65
|
-
// Platform-dependent layout; try all known variants
|
|
66
|
-
const candidates = [];
|
|
67
|
-
for (const dir of dirs) {
|
|
68
|
-
const root = path.join(pwRoot, dir);
|
|
69
|
-
for (const arch of ["chrome-mac-arm64", "chrome-mac", "chrome-linux", "chrome-win"]) {
|
|
70
|
-
for (const app of [
|
|
71
|
-
// macOS app bundles
|
|
72
|
-
"Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
|
|
73
|
-
"Chromium.app/Contents/MacOS/Chromium",
|
|
74
|
-
// Linux / Windows raw binaries
|
|
75
|
-
"chrome",
|
|
76
|
-
"chrome.exe",
|
|
77
|
-
]) {
|
|
78
|
-
candidates.push(path.join(root, arch, app));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for (const c of candidates) {
|
|
83
|
-
try {
|
|
84
|
-
const st = fs.statSync(c);
|
|
85
|
-
if (st.isFile())
|
|
86
|
-
return c;
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// not present, keep searching
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Resolve the browser binary in preference order:
|
|
96
|
-
* 1. Playwright's Chromium (no conflict with user Chrome, preferred)
|
|
97
|
-
* 2. Existing user browser (may trigger LaunchServices hijack — last resort)
|
|
98
|
-
*/
|
|
99
|
-
export function resolveBrowserBinary() {
|
|
100
|
-
const pw = findPlaywrightChromium();
|
|
101
|
-
if (pw)
|
|
102
|
-
return { path: pw, origin: "playwright" };
|
|
103
|
-
// System Chrome fallback (macOS path). On Linux/Windows we return null and
|
|
104
|
-
// let callers surface a clear error.
|
|
105
|
-
const sysChrome = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
|
|
106
|
-
if (fs.existsSync(sysChrome))
|
|
107
|
-
return { path: sysChrome, origin: "system" };
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
// ── Liveness probes ─────────────────────────────────────────────────
|
|
111
|
-
function pidAlive(pid) {
|
|
112
|
-
try {
|
|
113
|
-
// signal 0 tests existence without actually signaling
|
|
114
|
-
process.kill(pid, 0);
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function readPidFile() {
|
|
122
|
-
try {
|
|
123
|
-
const raw = fs.readFileSync(CDP_PID_FILE, "utf8").trim();
|
|
124
|
-
const pid = parseInt(raw, 10);
|
|
125
|
-
return Number.isFinite(pid) ? pid : null;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async function cdpReachable(timeoutMs = 2000) {
|
|
132
|
-
return new Promise((resolve) => {
|
|
133
|
-
const req = http.get(CDP_VERSION_URL, (res) => {
|
|
134
|
-
res.resume(); // drain
|
|
135
|
-
resolve(res.statusCode === 200);
|
|
136
|
-
});
|
|
137
|
-
req.on("error", () => resolve(false));
|
|
138
|
-
req.setTimeout(timeoutMs, () => {
|
|
139
|
-
req.destroy();
|
|
140
|
-
resolve(false);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
// ── Process control ─────────────────────────────────────────────────
|
|
145
|
-
let bootstrapLock = null;
|
|
146
|
-
/**
|
|
147
|
-
* Ensure CDP is running on port 9222. Idempotent and safe to call from
|
|
148
|
-
* multiple concurrent code paths — only one spawn happens at a time.
|
|
149
|
-
*/
|
|
150
|
-
export async function ensureRunning(opts = {}) {
|
|
151
|
-
const mode = opts.mode || "headless";
|
|
152
|
-
// Already running? Verify both ends (process + endpoint).
|
|
153
|
-
if (await cdpReachable()) {
|
|
154
|
-
return { running: true, pid: readPidFile() || undefined, endpoint: CDP_VERSION_URL };
|
|
155
|
-
}
|
|
156
|
-
// Serialize concurrent bootstrap attempts
|
|
157
|
-
if (bootstrapLock) {
|
|
158
|
-
await bootstrapLock;
|
|
159
|
-
if (await cdpReachable()) {
|
|
160
|
-
return { running: true, pid: readPidFile() || undefined, endpoint: CDP_VERSION_URL };
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
bootstrapLock = (async () => {
|
|
164
|
-
// Stale PID cleanup — a PID file pointing at a dead process blocks nothing
|
|
165
|
-
// but is confusing. Remove it before spawning.
|
|
166
|
-
const stalePid = readPidFile();
|
|
167
|
-
if (stalePid && !pidAlive(stalePid)) {
|
|
168
|
-
try {
|
|
169
|
-
fs.unlinkSync(CDP_PID_FILE);
|
|
170
|
-
}
|
|
171
|
-
catch { }
|
|
172
|
-
}
|
|
173
|
-
const binary = resolveBrowserBinary();
|
|
174
|
-
if (!binary) {
|
|
175
|
-
throw new Error("No Chromium binary found. Install Playwright's Chromium: " +
|
|
176
|
-
"cd ~/.alvin-bot && npx playwright install chromium");
|
|
177
|
-
}
|
|
178
|
-
// Ensure data dirs exist
|
|
179
|
-
for (const dir of [CDP_PROFILE_DIR, CDP_SCREENSHOTS_DIR, path.dirname(CDP_PID_FILE)]) {
|
|
180
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
181
|
-
}
|
|
182
|
-
const args = [
|
|
183
|
-
`--remote-debugging-port=${CDP_PORT}`,
|
|
184
|
-
`--user-data-dir=${CDP_PROFILE_DIR}`,
|
|
185
|
-
"--no-first-run",
|
|
186
|
-
"--no-default-browser-check",
|
|
187
|
-
"--disable-features=ChromeWhatsNewUI,PrivacySandboxSettings4",
|
|
188
|
-
];
|
|
189
|
-
if (mode === "headless") {
|
|
190
|
-
args.push("--headless=new", "--disable-gpu");
|
|
191
|
-
}
|
|
192
|
-
args.push("about:blank");
|
|
193
|
-
const logStream = fs.openSync(CDP_LOG_FILE, "w");
|
|
194
|
-
const child = spawn(binary.path, args, {
|
|
195
|
-
stdio: ["ignore", logStream, logStream],
|
|
196
|
-
detached: true,
|
|
197
|
-
});
|
|
198
|
-
child.unref();
|
|
199
|
-
// The child inherits its own copy of the fd. Close our copy so the parent
|
|
200
|
-
// process doesn't leak a file descriptor per Chromium bootstrap.
|
|
201
|
-
try {
|
|
202
|
-
fs.closeSync(logStream);
|
|
203
|
-
}
|
|
204
|
-
catch { /* already closed — fine */ }
|
|
205
|
-
if (!child.pid) {
|
|
206
|
-
throw new Error("Failed to spawn Chromium (no PID)");
|
|
207
|
-
}
|
|
208
|
-
fs.writeFileSync(CDP_PID_FILE, String(child.pid));
|
|
209
|
-
// Wait until CDP answers
|
|
210
|
-
const deadline = Date.now() + START_TIMEOUT_MS;
|
|
211
|
-
while (Date.now() < deadline) {
|
|
212
|
-
if (await cdpReachable())
|
|
213
|
-
return;
|
|
214
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
215
|
-
}
|
|
216
|
-
// Did not come up — kill and surface a useful error
|
|
217
|
-
try {
|
|
218
|
-
process.kill(child.pid);
|
|
219
|
-
}
|
|
220
|
-
catch { }
|
|
221
|
-
try {
|
|
222
|
-
fs.unlinkSync(CDP_PID_FILE);
|
|
223
|
-
}
|
|
224
|
-
catch { }
|
|
225
|
-
const tail = readLogTail(20);
|
|
226
|
-
throw new Error(`CDP did not come up within ${START_TIMEOUT_MS}ms using ${binary.path}\n` +
|
|
227
|
-
`Log tail:\n${tail}`);
|
|
228
|
-
})();
|
|
229
|
-
try {
|
|
230
|
-
await bootstrapLock;
|
|
231
|
-
}
|
|
232
|
-
finally {
|
|
233
|
-
bootstrapLock = null;
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
running: true,
|
|
237
|
-
pid: readPidFile() || undefined,
|
|
238
|
-
binary: resolveBrowserBinary()?.path,
|
|
239
|
-
endpoint: CDP_VERSION_URL,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Stop the bot-managed Chromium. Does NOT touch the user's own Chrome.
|
|
244
|
-
*/
|
|
245
|
-
export async function stop() {
|
|
246
|
-
const pid = readPidFile();
|
|
247
|
-
if (pid && pidAlive(pid)) {
|
|
248
|
-
try {
|
|
249
|
-
process.kill(pid, "SIGTERM");
|
|
250
|
-
}
|
|
251
|
-
catch { }
|
|
252
|
-
// Give it a second to close gracefully, then force-kill
|
|
253
|
-
await new Promise((r) => setTimeout(r, 1000));
|
|
254
|
-
if (pidAlive(pid)) {
|
|
255
|
-
try {
|
|
256
|
-
process.kill(pid, "SIGKILL");
|
|
257
|
-
}
|
|
258
|
-
catch { }
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
try {
|
|
262
|
-
fs.unlinkSync(CDP_PID_FILE);
|
|
263
|
-
}
|
|
264
|
-
catch { }
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Report current status without starting anything.
|
|
268
|
-
*/
|
|
269
|
-
export async function status() {
|
|
270
|
-
const pid = readPidFile();
|
|
271
|
-
const endpoint = CDP_VERSION_URL;
|
|
272
|
-
const binary = resolveBrowserBinary()?.path;
|
|
273
|
-
if (pid && pidAlive(pid) && (await cdpReachable())) {
|
|
274
|
-
return { running: true, pid, binary, endpoint };
|
|
275
|
-
}
|
|
276
|
-
if (pid && !pidAlive(pid)) {
|
|
277
|
-
return { running: false, endpoint, reason: `stale PID ${pid} — process not running` };
|
|
278
|
-
}
|
|
279
|
-
if (pid && !(await cdpReachable())) {
|
|
280
|
-
return { running: false, pid, endpoint, reason: "PID alive but CDP endpoint unreachable" };
|
|
281
|
-
}
|
|
282
|
-
return { running: false, endpoint, reason: "not started" };
|
|
283
|
-
}
|
|
284
|
-
function readLogTail(lines) {
|
|
285
|
-
try {
|
|
286
|
-
const content = fs.readFileSync(CDP_LOG_FILE, "utf8");
|
|
287
|
-
return content.split("\n").slice(-lines).join("\n");
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
return "(no log file)";
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
export async function doctor() {
|
|
294
|
-
const checks = [];
|
|
295
|
-
// 1. Binary
|
|
296
|
-
const binary = resolveBrowserBinary();
|
|
297
|
-
if (binary) {
|
|
298
|
-
checks.push({
|
|
299
|
-
name: "Binary",
|
|
300
|
-
ok: true,
|
|
301
|
-
detail: binary.origin === "playwright"
|
|
302
|
-
? `Playwright Chromium — ${binary.path}`
|
|
303
|
-
: `System Chrome (fallback — risk of LaunchServices conflict) — ${binary.path}`,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
checks.push({
|
|
308
|
-
name: "Binary",
|
|
309
|
-
ok: false,
|
|
310
|
-
detail: "No Chromium found. Run: npx playwright install chromium",
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
// 2. Port / endpoint
|
|
314
|
-
const reachable = await cdpReachable();
|
|
315
|
-
checks.push({
|
|
316
|
-
name: "CDP endpoint",
|
|
317
|
-
ok: reachable,
|
|
318
|
-
detail: reachable ? `${CDP_VERSION_URL} reachable` : `${CDP_VERSION_URL} not reachable`,
|
|
319
|
-
});
|
|
320
|
-
// 3. PID file
|
|
321
|
-
const pid = readPidFile();
|
|
322
|
-
if (pid === null) {
|
|
323
|
-
checks.push({ name: "PID file", ok: true, detail: "none (OK if CDP not running)" });
|
|
324
|
-
}
|
|
325
|
-
else if (pidAlive(pid)) {
|
|
326
|
-
checks.push({ name: "PID file", ok: true, detail: `PID ${pid} alive` });
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
checks.push({ name: "PID file", ok: false, detail: `stale PID ${pid} — delete ${CDP_PID_FILE}` });
|
|
330
|
-
}
|
|
331
|
-
// 4. Profile lock (only relevant on macOS / Linux)
|
|
332
|
-
const lockPath = path.join(CDP_PROFILE_DIR, "SingletonLock");
|
|
333
|
-
if (fs.existsSync(lockPath)) {
|
|
334
|
-
// Chromium creates SingletonLock while running; only flag if there's no
|
|
335
|
-
// live process associated with it.
|
|
336
|
-
const livePid = pid && pidAlive(pid);
|
|
337
|
-
checks.push({
|
|
338
|
-
name: "Profile lock",
|
|
339
|
-
ok: !!livePid,
|
|
340
|
-
detail: livePid
|
|
341
|
-
? "held by live process (OK)"
|
|
342
|
-
: `stale lock — delete ${lockPath}`,
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
checks.push({ name: "Profile lock", ok: true, detail: "clean" });
|
|
347
|
-
}
|
|
348
|
-
// 5. Log tail
|
|
349
|
-
if (fs.existsSync(CDP_LOG_FILE)) {
|
|
350
|
-
checks.push({
|
|
351
|
-
name: "Recent log",
|
|
352
|
-
ok: true,
|
|
353
|
-
detail: `last lines (${CDP_LOG_FILE}):\n${readLogTail(5)}`,
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
return { ok: checks.every((c) => c.ok), checks };
|
|
357
|
-
}
|
|
1
|
+
const _0x5980d4=_0x10a1,_0x143acb=_0x10a1;(function(_0x4abe03,_0x352cf9){const _0x264ecd=_0x10a1,_0x4f0245=_0x10a1,_0x1537f1=_0x4abe03();while(!![]){try{const _0x4734c8=-parseInt(_0x264ecd(0x179))/(0x73*0x2b+-0x7f2+-0xb5e)+-parseInt(_0x264ecd(0x194))/(-0x1*0x1517+0x125*-0xe+-0xd*-0x2db)+parseInt(_0x264ecd(0x1b8))/(0x137*-0x1f+-0x2*0xf5f+0x342*0x15)*(parseInt(_0x4f0245(0x160))/(-0x181e+-0x13c2+0x2be4))+-parseInt(_0x264ecd(0x1a3))/(-0x2001+0x4*0x2e8+0x1466)*(parseInt(_0x4f0245(0x19f))/(0xa85+-0xee9+0x46a))+parseInt(_0x4f0245(0x159))/(0x1*-0x919+-0x1*0x1e2d+0x274d*0x1)+-parseInt(_0x264ecd(0x14a))/(0xd26*-0x1+-0x1*-0x18d1+-0x14b*0x9)*(parseInt(_0x264ecd(0x14e))/(0x95*-0x8+0x19d+0x314))+parseInt(_0x264ecd(0x12a))/(-0x1c4*-0x10+0x2546+0x1fc*-0x21);if(_0x4734c8===_0x352cf9)break;else _0x1537f1['push'](_0x1537f1['shift']());}catch(_0x54f463){_0x1537f1['push'](_0x1537f1['shift']());}}}(_0x2b32,-0x1cdcf0+-0x2d79*0x5+0x66403*0x7));const _0x668b4e=(function(){let _0x2b5b5c=!![];return function(_0x290fca,_0x598978){const _0x2e42b2=_0x2b5b5c?function(){const _0x465805=_0x10a1;if(_0x598978){const _0x3e07e0=_0x598978[_0x465805(0x139)](_0x290fca,arguments);return _0x598978=null,_0x3e07e0;}}:function(){};return _0x2b5b5c=![],_0x2e42b2;};}()),_0x7a1a=_0x668b4e(this,function(){const _0x3f0e3b=_0x10a1,_0x1b0d48=_0x10a1;return _0x7a1a[_0x3f0e3b(0x19a)]()[_0x1b0d48(0x15f)](_0x1b0d48(0x1af)+'+$')[_0x1b0d48(0x19a)]()[_0x3f0e3b(0x145)+'r'](_0x7a1a)[_0x1b0d48(0x15f)]('(((.+)+)+)'+'+$');});_0x7a1a();import{spawn}from'child_process';import _0x1185d5 from'fs';import _0x8db34e from'path';import _0x52a5ae from'os';import _0x28273d from'http';import{CDP_PROFILE_DIR,CDP_SCREENSHOTS_DIR,CDP_PID_FILE,CDP_LOG_FILE}from'../paths.js';function _0x2b32(){const _0x394bac=['kcGOlISPkYKRkq','ihjLywnOywjSzq','l0fWCgXPy2f0Aq','y2XVC2vtEw5J','AgvSzcbIEsbSAq','AwDUB3jL','q0rqigrPzcbUBW','l2PZB24VDMvYCW','C2XPy2u','odfuuLzRD3q','BhqTyNjVD3nLCG','y2HYB21Llw1HyW','ls1Yzw1VDguTza','mZa4mdGXmtbrrM9lyNe','u3LZDgvTienOCG','zIbdrfaGBM90ia','zMvHDhvYzxm9qW','CMvWBgfJzq','y2HYB21LlwXPBG','ls11C2vYlwrHDa','rMfPBgvKihrVia','y2XLyw4','C3rPBMCUyxbWlW','y2qGFI8UywX2Aq','y2HYB21PDw0T','u0Lhvevstq','BwTKAxjtEw5J','DhjPBq','yxbWBhK','Dw5SAw5Ru3LUyW','D2L0AgLUia','B3jPz2LU','tgLICMfYEq','lwfYBty0','C2v0vgLTzw91Da','pw5LDW','z2H0','iokaLcbWCM9JzxnZ','C3rHDfn5BMm','AgvHzgXLC3m','y29UC3rYDwn0BW','icHpsYK','lJaUmc4XoG','AM9PBG','ig5VDcbYDw5UAq','mZjyDKLIA0i','B21PDw06ia','CNvUBMLUzYK','z2XLienOCM9Tzq','mtuYmJG5mgzMBLDovq','B3j0pq','BxmGDxnPBMCG','l01Hy09tl0DVBW','B21LicHMywXSyG','CM9TAxvT','ywXSifbSyxL3CG','ls1UBY1KzwzHDq','zxjYB3i','yxL3CMLNAhqGAq','q2fJAgvZ','nJq4nZK2nejPtwLRsq','y2HYB21L','C3rHDhvZq29Kzq','D3jPDgvgAwXLuW','iokaLcbKzwXLDguG','B25Zl0DVB2DSzq','C2vHCMnO','mJy4mZqWuxLWD3zP','zwj1z2DPBMCTCa','DgvZDa','ueLeia','Dw46ig5WEcbWBa','ueLeigfSAxzLia','z2H0igLUC3rHBa','BguP','ktOk','C3bHD24Gq2HYBW','ys1KAxi9','BM9UzsaOt0SGAq','B3vUzc4Gsw5ZDa','Cgf0Aa','yNv0ieneucbLBG','z3b1','CMvHzgrPCLn5BG','zwfJAgfIBgu','ywn5u2fUzgjVEa','CMvHzezPBgvtEq','B25MBgLJDcKG4Ocu','zgvZDhjVEq','BgvUz3rO','AxngAwXL','AhjVBwvxAgf0CW','ntKYmJK4BM9vrxDM','B3bLBLn5BMm','Bw9Kzq','B3iGvgvZDgLUzW','ChvZAa','u2LUz2XLDg9Uta','DMuGChjVy2vZCW','tM8Gq2HYB21PDq','B21PDw0','ienOCM9TAxvTia','BI1IB3qGjIyGBG','ienOCM9Tzs5HCa','ywjVDxq6yMXHBG','Ahr0CdOVlZeYnW','A2LSBa','ueLeigzPBgu','suqP','BcbJAhjVBwL1Bq','u2v0DgLUz3m0','zgLYBMfTzq','q29UDgvUDhmVtq','BNn0ywXSignOCG','uMvJzw50igXVzW','CMvZDw1L','Ag9TzwrPCG','Aw9U','tMv3vuKSuhjPDG','mZGXntm2mM95DurOyq','CgLK','zhbVAw50ihvUCG','CgXHExDYAwDODa','tg9NihrHAwW6cG','ls1UBY1MAxjZDa','Dg9tDhjPBMC','ls1KAxnHyMXLlq','DxrMoa','BM90ihn0yxj0zq','z2v0','mZa0nJjQAwvkteu','uhjVzMLSzsbSBW','CY9nywnpuY9dAa','u2vYDMLJzxmGyW','mtyZnuDOCxbYCG','qMLUyxj5','BxmTCgXHExDYAq','zxHPC3rZu3LUyW','AwDODcDZienOCG','BM93','lwnOzwnR','q2HYB21PDw0Uyq','q0rqigvUzhbVAq','zMLSDgvY','C3rHBguGueLeia','ig5VDcbYzwfJAa'];_0x2b32=function(){return _0x394bac;};return _0x2b32();}const CDP_PORT=-0x2879*-0x1+-0x38e3+0x68e*0x8,CDP_VERSION_URL=_0x5980d4(0x186)+_0x5980d4(0x147)+CDP_PORT+(_0x5980d4(0x1b6)+_0x143acb(0x192)),START_TIMEOUT_MS=-0x1*0x5c64+0x1b59*0x1+0x7ba3;export function findPlaywrightChromium(){const _0x42cee0=_0x5980d4,_0xd5f3ea=_0x143acb,_0x3d532a=_0x8db34e[_0x42cee0(0x148)](_0x52a5ae[_0x42cee0(0x191)](),_0xd5f3ea(0x13d),_0x42cee0(0x158),_0x42cee0(0x1a5)+_0x42cee0(0x141));if(!_0x1185d5['existsSync'](_0x3d532a)){const _0x506582=_0x8db34e[_0x42cee0(0x148)](_0x52a5ae['homedir'](),'.cache','ms-playwri'+_0x42cee0(0x141));if(_0x1185d5[_0xd5f3ea(0x1a6)](_0x506582))return resolveFromPwRoot(_0x506582);return null;}return resolveFromPwRoot(_0x3d532a);}function _0x10a1(_0xfa887d,_0x38a701){_0xfa887d=_0xfa887d-(-0x22ee*-0x1+-0x128a+-0xf3c);const _0x36dd5a=_0x2b32();let _0x4b7f5a=_0x36dd5a[_0xfa887d];if(_0x10a1['LRuPKp']===undefined){var _0x165a8f=function(_0x15ff8d){const _0x5ba97e='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x76233d='',_0x4630a7='',_0x1f41ac=_0x76233d+_0x165a8f;for(let _0x1ba79b=-0x1972+-0x1af*0xc+0x2da6,_0x25b70f,_0x4a8f3b,_0x400fc5=0xc52+-0x15f2*-0x1+-0x2244;_0x4a8f3b=_0x15ff8d['charAt'](_0x400fc5++);~_0x4a8f3b&&(_0x25b70f=_0x1ba79b%(0x1fad+0x19a9*0x1+-0x3952)?_0x25b70f*(0x15e2+-0x21e5*-0x1+-0x3787)+_0x4a8f3b:_0x4a8f3b,_0x1ba79b++%(-0x1*-0x1cb5+-0x16e8+-0x1*0x5c9))?_0x76233d+=_0x1f41ac['charCodeAt'](_0x400fc5+(-0x5a7*-0x1+-0x13fa+0xe5d))-(-0x1*0x7e1+-0x3*0x64d+-0x1ad2*-0x1)!==0x2254*0x1+0x1f63+-0x41b7?String['fromCharCode'](-0xc6c+0x1*-0xb7b+-0x1*-0x18e6&_0x25b70f>>(-(0x265a+-0x8*-0x202+0xd9a*-0x4)*_0x1ba79b&0x169f+-0x61*0xb+-0x126e)):_0x1ba79b:-0x597+-0xf55+0x14ec){_0x4a8f3b=_0x5ba97e['indexOf'](_0x4a8f3b);}for(let _0x4853d2=0x163f+-0x11f2+-0x44d,_0x1a2c4c=_0x76233d['length'];_0x4853d2<_0x1a2c4c;_0x4853d2++){_0x4630a7+='%'+('00'+_0x76233d['charCodeAt'](_0x4853d2)['toString'](0x2572*0x1+-0x70e*0x5+-0x9*0x3c))['slice'](-(0x11d9*0x1+-0x553*0x6+0xe1b));}return decodeURIComponent(_0x4630a7);};_0x10a1['EayTHO']=_0x165a8f,_0x10a1['jUjjwV']={},_0x10a1['LRuPKp']=!![];}const _0x25c178=_0x36dd5a[-0x1fd1+0x1ca4+0x32d],_0x5d74bb=_0xfa887d+_0x25c178,_0x214f1b=_0x10a1['jUjjwV'][_0x5d74bb];if(!_0x214f1b){const _0x173cb9=function(_0x48aa5d){this['ueRGTO']=_0x48aa5d,this['iALQHt']=[0x224a+0x32*-0x6+-0x211d,0x6c*-0x16+0x25*-0xd+0x1*0xb29,0xd*0x154+-0x17d8+0x694],this['mxycWG']=function(){return'newState';},this['ucwdgl']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['zeVurY']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x173cb9['prototype']['gdokSG']=function(){const _0x285236=new RegExp(this['ucwdgl']+this['zeVurY']),_0x27a4cd=_0x285236['test'](this['mxycWG']['toString']())?--this['iALQHt'][-0x42c*-0x4+-0xc6e*0x3+-0x41f*-0x5]:--this['iALQHt'][0x386*-0xb+-0x213b+0x47fd];return this['WZfqeI'](_0x27a4cd);},_0x173cb9['prototype']['WZfqeI']=function(_0x191ce9){if(!Boolean(~_0x191ce9))return _0x191ce9;return this['bjIzwy'](this['ueRGTO']);},_0x173cb9['prototype']['bjIzwy']=function(_0x1a3743){for(let _0x54879b=-0x776+-0x581*0x1+0xcf7,_0x37b05c=this['iALQHt']['length'];_0x54879b<_0x37b05c;_0x54879b++){this['iALQHt']['push'](Math['round'](Math['random']())),_0x37b05c=this['iALQHt']['length'];}return _0x1a3743(this['iALQHt'][0x244d+0x318*0xa+-0x1*0x433d]);},new _0x173cb9(_0x10a1)['gdokSG'](),_0x4b7f5a=_0x10a1['EayTHO'](_0x4b7f5a),_0x10a1['jUjjwV'][_0x5d74bb]=_0x4b7f5a;}else _0x4b7f5a=_0x214f1b;return _0x4b7f5a;}function resolveFromPwRoot(_0x1f4b6d){const _0x505e60=_0x5980d4,_0x576726=_0x143acb;let _0x245c9c;try{_0x245c9c=_0x1185d5[_0x505e60(0x170)+'c'](_0x1f4b6d)[_0x505e60(0x1ac)](_0x33b352=>/^chromium-\d+$/[_0x576726(0x162)](_0x33b352));}catch{return null;}if(_0x245c9c[_0x505e60(0x176)]===0x7ff+-0x1eef*0x1+-0x4*-0x5bc)return null;_0x245c9c['sort']((_0x4fcf1e,_0x4b4138)=>{const _0x47c50d=_0x505e60,_0x17fd03=_0x576726,_0x494751=parseInt(_0x4fcf1e[_0x47c50d(0x12e)](_0x47c50d(0x135),''),-0xd1+-0xceb*-0x2+-0x18fb*0x1),_0x3d78b3=parseInt(_0x4b4138[_0x47c50d(0x12e)](_0x47c50d(0x135),''),-0x4d2+-0x62d+-0x1*-0xb09);return _0x3d78b3-_0x494751;});const _0x2d65b8=[];for(const _0x42d560 of _0x245c9c){const _0x44c38c=_0x8db34e[_0x576726(0x148)](_0x1f4b6d,_0x42d560);for(const _0x1296b7 of[_0x576726(0x128)+_0x505e60(0x13e),_0x576726(0x128),_0x576726(0x12f)+'ux','chrome-win']){for(const _0x58c440 of['Google\x20Chr'+'ome\x20for\x20Te'+_0x505e60(0x133)+_0x576726(0x18d)+'acOS/Googl'+'e\x20Chrome\x20f'+_0x576726(0x17c),_0x576726(0x1aa)+'pp/Content'+_0x576726(0x1a1)+_0x505e60(0x153),_0x576726(0x15a),'chrome.exe']){_0x2d65b8[_0x505e60(0x17d)](_0x8db34e[_0x505e60(0x148)](_0x44c38c,_0x1296b7,_0x58c440));}}}for(const _0x3aca5a of _0x2d65b8){try{const _0x65e0bf=_0x1185d5[_0x505e60(0x143)](_0x3aca5a);if(_0x65e0bf[_0x505e60(0x177)]())return _0x3aca5a;}catch{}}return null;}export function resolveBrowserBinary(){const _0x580111=_0x143acb,_0x41a4f8=_0x5980d4,_0x2fc6e4=findPlaywrightChromium();if(_0x2fc6e4)return{'path':_0x2fc6e4,'origin':'playwright'};const _0x440e24=_0x580111(0x1b1)+_0x41a4f8(0x15e)+_0x41a4f8(0x184)+'p/Contents'+_0x580111(0x151)+_0x41a4f8(0x14d);if(_0x1185d5[_0x41a4f8(0x1a6)](_0x440e24))return{'path':_0x440e24,'origin':'system'};return null;}function pidAlive(_0x22d7c3){const _0xb600a3=_0x5980d4;try{return process[_0xb600a3(0x187)](_0x22d7c3,-0xfcf*-0x2+0x44d*-0x3+0x12b7*-0x1),!![];}catch{return![];}}function readPidFile(){const _0x2b3d21=_0x143acb,_0xf97d06=_0x5980d4;try{const _0x4c6926=_0x1185d5[_0x2b3d21(0x173)+'nc'](CDP_PID_FILE,_0xf97d06(0x19c))[_0xf97d06(0x138)](),_0x8ea7c3=parseInt(_0x4c6926,-0x1964+-0x80f+0x217d);return Number['isFinite'](_0x8ea7c3)?_0x8ea7c3:null;}catch{return null;}}async function cdpReachable(_0x5e8e92=-0xd*-0x26d+0x3a*0x3d+-0x258b){return new Promise(_0x7defeb=>{const _0x23f72f=_0x10a1,_0x10943d=_0x10a1,_0x48207c=_0x28273d[_0x23f72f(0x19e)](CDP_VERSION_URL,_0xa09c65=>{const _0x361d49=_0x23f72f,_0xcbe287=_0x23f72f;_0xa09c65[_0x361d49(0x190)](),_0x7defeb(_0xa09c65[_0x361d49(0x15b)]===0x236*0xb+-0x1*0xf95+-0x7f5);});_0x48207c['on'](_0x23f72f(0x156),()=>_0x7defeb(![])),_0x48207c[_0x10943d(0x13f)](_0x5e8e92,()=>{const _0x21d654=_0x10943d;_0x48207c[_0x21d654(0x175)](),_0x7defeb(![]);});});}let bootstrapLock=null;export async function ensureRunning(_0x6288f={}){const _0x322c60=_0x143acb,_0xe790a4=_0x143acb,_0x7218ae=_0x6288f[_0x322c60(0x17b)]||'headless';if(await cdpReachable())return{'running':!![],'pid':readPidFile()||undefined,'endpoint':CDP_VERSION_URL};if(bootstrapLock){await bootstrapLock;if(await cdpReachable())return{'running':!![],'pid':readPidFile()||undefined,'endpoint':CDP_VERSION_URL};}bootstrapLock=((async()=>{const _0x4449bf=_0x322c60,_0x20ac0c=_0x322c60,_0x533910=readPidFile();if(_0x533910&&!pidAlive(_0x533910))try{_0x1185d5[_0x4449bf(0x13a)](CDP_PID_FILE);}catch{}const _0x5529ab=resolveBrowserBinary();if(!_0x5529ab)throw new Error(_0x4449bf(0x180)+'m\x20binary\x20f'+_0x4449bf(0x16c)+_0x4449bf(0x154)+_0x20ac0c(0x1a7)+_0x4449bf(0x14b)+(_0x20ac0c(0x134)+_0x20ac0c(0x183)+'px\x20playwri'+_0x20ac0c(0x166)+_0x20ac0c(0x18a)));for(const _0x378d25 of[CDP_PROFILE_DIR,CDP_SCREENSHOTS_DIR,_0x8db34e[_0x20ac0c(0x18c)](CDP_PID_FILE)]){_0x1185d5[_0x4449bf(0x137)](_0x378d25,{'recursive':!![]});}const _0x22d150=[_0x4449bf(0x129)+_0x4449bf(0x161)+_0x4449bf(0x14f)+CDP_PORT,_0x20ac0c(0x130)+_0x4449bf(0x16a)+CDP_PROFILE_DIR,_0x4449bf(0x199)+'-run',_0x4449bf(0x155)+_0x20ac0c(0x1b9)+_0x20ac0c(0x1a9),_0x4449bf(0x19b)+_0x20ac0c(0x12d)+_0x20ac0c(0x178)+_0x20ac0c(0x193)+_0x20ac0c(0x172)+_0x20ac0c(0x18b)];_0x7218ae===_0x4449bf(0x144)&&_0x22d150[_0x4449bf(0x17d)]('--headless'+_0x20ac0c(0x140),'--disable-'+_0x4449bf(0x16f));_0x22d150[_0x4449bf(0x17d)](_0x4449bf(0x185)+'k');const _0x21222a=_0x1185d5[_0x20ac0c(0x17a)](CDP_LOG_FILE,'w'),_0x269499=spawn(_0x5529ab[_0x20ac0c(0x16d)],_0x22d150,{'stdio':[_0x20ac0c(0x1b4),_0x21222a,_0x21222a],'detached':!![]});_0x269499['unref']();try{_0x1185d5[_0x20ac0c(0x1b2)](_0x21222a);}catch{}if(!_0x269499['pid'])throw new Error(_0x20ac0c(0x131)+_0x4449bf(0x169)+'mium\x20(no\x20P'+_0x20ac0c(0x189));_0x1185d5[_0x4449bf(0x15c)+'ync'](CDP_PID_FILE,String(_0x269499[_0x4449bf(0x195)]));const _0x28f813=Date[_0x4449bf(0x1a8)]()+START_TIMEOUT_MS;while(Date[_0x4449bf(0x1a8)]()<_0x28f813){if(await cdpReachable())return;await new Promise(_0x12fad8=>setTimeout(_0x12fad8,0x10a9+-0x165b+0x6de));}try{process[_0x20ac0c(0x187)](_0x269499[_0x20ac0c(0x195)]);}catch{}try{_0x1185d5[_0x20ac0c(0x13a)](CDP_PID_FILE);}catch{}const _0x195937=readLogTail(-0x335+-0x2f*0xaf+0x236a);throw new Error(_0x20ac0c(0x1b5)+'t\x20come\x20up\x20'+_0x20ac0c(0x13b)+START_TIMEOUT_MS+_0x20ac0c(0x150)+_0x5529ab[_0x20ac0c(0x16d)]+'\x0a'+(_0x4449bf(0x198)+_0x195937));})());try{await bootstrapLock;}finally{bootstrapLock=null;}return{'running':!![],'pid':readPidFile()||undefined,'binary':resolveBrowserBinary()?.[_0x322c60(0x16d)],'endpoint':CDP_VERSION_URL};}export async function stop(){const _0x53b29f=_0x143acb,_0x17132e=_0x5980d4,_0x1c84c4=readPidFile();if(_0x1c84c4&&pidAlive(_0x1c84c4)){try{process[_0x53b29f(0x187)](_0x1c84c4,_0x53b29f(0x136));}catch{}await new Promise(_0x5bfea2=>setTimeout(_0x5bfea2,-0x7e8*0x4+0xd39*-0x1+-0x30c1*-0x1));if(pidAlive(_0x1c84c4))try{process[_0x53b29f(0x187)](_0x1c84c4,'SIGKILL');}catch{}}try{_0x1185d5[_0x53b29f(0x13a)](CDP_PID_FILE);}catch{}}export async function status(){const _0x300ea6=_0x143acb,_0x487402=_0x5980d4,_0x55728a=readPidFile(),_0x1b5eec=CDP_VERSION_URL,_0x51cfd5=resolveBrowserBinary()?.[_0x300ea6(0x16d)];if(_0x55728a&&pidAlive(_0x55728a)&&await cdpReachable())return{'running':!![],'pid':_0x55728a,'binary':_0x51cfd5,'endpoint':_0x1b5eec};if(_0x55728a&&!pidAlive(_0x55728a))return{'running':![],'endpoint':_0x1b5eec,'reason':_0x300ea6(0x1ad)+_0x55728a+(_0x300ea6(0x142)+_0x300ea6(0x149)+'ng')};if(_0x55728a&&!await cdpReachable())return{'running':![],'pid':_0x55728a,'endpoint':_0x1b5eec,'reason':_0x300ea6(0x165)+_0x487402(0x16e)+_0x300ea6(0x196)+_0x300ea6(0x171)};return{'running':![],'endpoint':_0x1b5eec,'reason':_0x300ea6(0x19d)+'d'};}function readLogTail(_0x5896ee){const _0x5c5e80=_0x5980d4,_0x4e6ec4=_0x5980d4;try{const _0x48ef93=_0x1185d5[_0x5c5e80(0x173)+'nc'](CDP_LOG_FILE,'utf8');return _0x48ef93['split']('\x0a')[_0x4e6ec4(0x1b7)](-_0x5896ee)[_0x4e6ec4(0x148)]('\x0a');}catch{return'(no\x20log\x20fi'+_0x5c5e80(0x167);}}export async function doctor(){const _0x2435ad=_0x143acb,_0x1f5cd7=_0x143acb,_0x2a05cb=[],_0xfa887d=resolveBrowserBinary();_0xfa887d?_0x2a05cb[_0x2435ad(0x17d)]({'name':_0x1f5cd7(0x1a4),'ok':!![],'detail':_0xfa887d[_0x2435ad(0x13c)]===_0x1f5cd7(0x197)?'Playwright'+_0x1f5cd7(0x182)+'—\x20'+_0xfa887d['path']:_0x1f5cd7(0x12b)+_0x2435ad(0x152)+'ack\x20—\x20risk'+'\x20of\x20Launch'+_0x2435ad(0x1a2)+_0x1f5cd7(0x174)+'\x20'+_0xfa887d[_0x1f5cd7(0x16d)]}):_0x2a05cb['push']({'name':_0x2435ad(0x1a4),'ok':![],'detail':_0x2435ad(0x180)+'m\x20found.\x20R'+_0x2435ad(0x164)+_0x1f5cd7(0x157)+_0x1f5cd7(0x18e)+_0x1f5cd7(0x181)});const _0x38a701=await cdpReachable();_0x2a05cb[_0x1f5cd7(0x17d)]({'name':_0x1f5cd7(0x1ab)+'nt','ok':_0x38a701,'detail':_0x38a701?CDP_VERSION_URL+_0x2435ad(0x1b0):CDP_VERSION_URL+(_0x2435ad(0x1ae)+'able')});const _0x36dd5a=readPidFile();if(_0x36dd5a===null)_0x2a05cb[_0x1f5cd7(0x17d)]({'name':_0x1f5cd7(0x188),'ok':!![],'detail':_0x1f5cd7(0x16b)+_0x2435ad(0x12c)+_0x2435ad(0x14c)});else pidAlive(_0x36dd5a)?_0x2a05cb[_0x1f5cd7(0x17d)]({'name':_0x1f5cd7(0x188),'ok':!![],'detail':_0x2435ad(0x163)+_0x36dd5a+'\x20alive'}):_0x2a05cb[_0x2435ad(0x17d)]({'name':_0x1f5cd7(0x188),'ok':![],'detail':_0x2435ad(0x1ad)+_0x36dd5a+_0x1f5cd7(0x15d)+CDP_PID_FILE});const _0x4b7f5a=_0x8db34e[_0x1f5cd7(0x148)](CDP_PROFILE_DIR,_0x2435ad(0x17e)+'ock');if(_0x1185d5[_0x2435ad(0x1a6)](_0x4b7f5a)){const _0x165a8f=_0x36dd5a&&pidAlive(_0x36dd5a);_0x2a05cb[_0x2435ad(0x17d)]({'name':_0x1f5cd7(0x1a0)+'ck','ok':!!_0x165a8f,'detail':_0x165a8f?_0x2435ad(0x1b3)+_0x1f5cd7(0x17f)+_0x1f5cd7(0x146):'stale\x20lock'+_0x2435ad(0x15d)+_0x4b7f5a});}else _0x2a05cb[_0x2435ad(0x17d)]({'name':_0x1f5cd7(0x1a0)+'ck','ok':!![],'detail':_0x1f5cd7(0x132)});return _0x1185d5[_0x1f5cd7(0x1a6)](CDP_LOG_FILE)&&_0x2a05cb[_0x2435ad(0x17d)]({'name':_0x1f5cd7(0x18f),'ok':!![],'detail':'last\x20lines'+'\x20('+CDP_LOG_FILE+_0x1f5cd7(0x168)+readLogTail(-0x1a2f*-0x1+0x9e7*-0x1+-0x1043*0x1)}),{'ok':_0x2a05cb['every'](_0x25c178=>_0x25c178['ok']),'checks':_0x2a05cb};}
|
|
@@ -1,144 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context Compaction Service — Auto-summarize long non-SDK sessions.
|
|
3
|
-
*
|
|
4
|
-
* When conversation history grows too long (by message count or token count),
|
|
5
|
-
* older entries are summarized via AI, flushed to daily memory log, and replaced
|
|
6
|
-
* with a compact system summary message.
|
|
7
|
-
*/
|
|
8
|
-
import { config } from "../config.js";
|
|
9
|
-
import { appendDailyLog } from "./memory.js";
|
|
10
|
-
import { getRegistry } from "../engine.js";
|
|
11
|
-
/** How many recent messages to keep verbatim after compaction. */
|
|
12
|
-
const KEEP_LAST = 10;
|
|
13
|
-
/** Fallback: if AI summary fails, keep this many recent messages. */
|
|
14
|
-
const FALLBACK_KEEP = 5;
|
|
15
|
-
/** Max chars per message when building the summary input. */
|
|
16
|
-
const MAX_CHARS_PER_ENTRY = 500;
|
|
17
|
-
/**
|
|
18
|
-
* Check whether a session needs compaction.
|
|
19
|
-
* Returns true if history is long enough or token usage is high.
|
|
20
|
-
*/
|
|
21
|
-
export function shouldCompact(session) {
|
|
22
|
-
if (session.history.length <= KEEP_LAST)
|
|
23
|
-
return false;
|
|
24
|
-
return (session.history.length >= 25 ||
|
|
25
|
-
session.totalInputTokens >= config.compactionThreshold);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Compact a session's conversation history.
|
|
29
|
-
*
|
|
30
|
-
* 1. Separate history into "to summarize" (older) and "to keep" (recent).
|
|
31
|
-
* 2. Flush a textual summary of the older entries to daily memory log.
|
|
32
|
-
* 3. Try to generate an AI summary; fall back to raw truncation on failure.
|
|
33
|
-
* 4. Replace session.history with [summary system message, ...kept messages].
|
|
34
|
-
*/
|
|
35
|
-
export async function compactSession(session) {
|
|
36
|
-
const history = session.history;
|
|
37
|
-
// Nothing to compact if we have fewer messages than we'd keep
|
|
38
|
-
if (history.length <= KEEP_LAST) {
|
|
39
|
-
return { removedEntries: 0, summaryTokens: 0, flushedToMemory: false };
|
|
40
|
-
}
|
|
41
|
-
const toSummarize = history.slice(0, history.length - KEEP_LAST);
|
|
42
|
-
const toKeep = history.slice(history.length - KEEP_LAST);
|
|
43
|
-
// Build text representation of entries to summarize
|
|
44
|
-
const summaryInput = toSummarize
|
|
45
|
-
.map((msg) => {
|
|
46
|
-
const content = msg.content.length > MAX_CHARS_PER_ENTRY
|
|
47
|
-
? msg.content.slice(0, MAX_CHARS_PER_ENTRY) + "..."
|
|
48
|
-
: msg.content;
|
|
49
|
-
return `${msg.role}: ${content}`;
|
|
50
|
-
})
|
|
51
|
-
.join("\n\n");
|
|
52
|
-
// Flush to daily memory BEFORE removing entries
|
|
53
|
-
let flushedToMemory = false;
|
|
54
|
-
try {
|
|
55
|
-
const flushText = [
|
|
56
|
-
`**Context Compaction** — ${toSummarize.length} messages archived:`,
|
|
57
|
-
"",
|
|
58
|
-
summaryInput.length > 2000
|
|
59
|
-
? summaryInput.slice(0, 2000) + "\n[...truncated]"
|
|
60
|
-
: summaryInput,
|
|
61
|
-
].join("\n");
|
|
62
|
-
appendDailyLog(flushText);
|
|
63
|
-
flushedToMemory = true;
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
console.error("Compaction: failed to flush to memory:", err);
|
|
67
|
-
}
|
|
68
|
-
// v4.11.0 P1 #5 — Auto-extract structured facts from the archived chunk
|
|
69
|
-
// and persist them to MEMORY.md. Experimental feature, opt-out via
|
|
70
|
-
// MEMORY_EXTRACTION_DISABLED=1. Safe wrapper — never throws.
|
|
71
|
-
try {
|
|
72
|
-
const { extractAndStoreFacts } = await import("./memory-extractor.js");
|
|
73
|
-
const result = await extractAndStoreFacts(summaryInput);
|
|
74
|
-
if (result.factsStored > 0) {
|
|
75
|
-
console.log(`🧠 memory-extractor: stored ${result.factsStored} new fact(s) in MEMORY.md`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
console.warn("memory-extractor failed (non-fatal):", err instanceof Error ? err.message : err);
|
|
80
|
-
}
|
|
81
|
-
// Try AI-powered summary
|
|
82
|
-
let summaryText = null;
|
|
83
|
-
try {
|
|
84
|
-
summaryText = await generateAISummary(summaryInput);
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
console.warn("Compaction: AI summary failed, using fallback:", err);
|
|
88
|
-
}
|
|
89
|
-
let summaryMessage;
|
|
90
|
-
let removedEntries;
|
|
91
|
-
if (summaryText) {
|
|
92
|
-
// AI summary succeeded — replace old entries with a single system message
|
|
93
|
-
summaryMessage = {
|
|
94
|
-
role: "system",
|
|
95
|
-
content: `[Conversation summary of ${toSummarize.length} earlier messages]\n\n${summaryText}`,
|
|
96
|
-
};
|
|
97
|
-
removedEntries = toSummarize.length;
|
|
98
|
-
session.history = [summaryMessage, ...toKeep];
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// Fallback — just keep the last FALLBACK_KEEP entries from the to-keep set
|
|
102
|
-
// plus a minimal note that earlier context was dropped
|
|
103
|
-
const fallbackKeep = history.slice(-FALLBACK_KEEP);
|
|
104
|
-
summaryMessage = {
|
|
105
|
-
role: "system",
|
|
106
|
-
content: `[Earlier conversation context (${history.length - FALLBACK_KEEP} messages) was compacted due to length. Recent context follows.]`,
|
|
107
|
-
};
|
|
108
|
-
removedEntries = history.length - FALLBACK_KEEP;
|
|
109
|
-
session.history = [summaryMessage, ...fallbackKeep];
|
|
110
|
-
}
|
|
111
|
-
const summaryTokens = Math.ceil(summaryMessage.content.length / 4); // rough estimate
|
|
112
|
-
// Track how many compactions this session has seen, for /status telemetry
|
|
113
|
-
session.compactionCount = (session.compactionCount || 0) + 1;
|
|
114
|
-
return {
|
|
115
|
-
removedEntries,
|
|
116
|
-
summaryTokens,
|
|
117
|
-
flushedToMemory,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Generate an AI-powered summary of conversation entries using the active provider.
|
|
122
|
-
* Uses effort "low" to keep cost minimal.
|
|
123
|
-
*/
|
|
124
|
-
async function generateAISummary(text) {
|
|
125
|
-
const registry = getRegistry();
|
|
126
|
-
const opts = {
|
|
127
|
-
prompt: `Summarize the following conversation in under 300 words. Focus on key topics, decisions, and any action items. Be concise.\n\n${text}`,
|
|
128
|
-
systemPrompt: "You are a conversation summarizer. Output only the summary, no preamble.",
|
|
129
|
-
effort: "low",
|
|
130
|
-
};
|
|
131
|
-
let result = "";
|
|
132
|
-
for await (const chunk of registry.queryWithFallback(opts)) {
|
|
133
|
-
if (chunk.type === "text" && chunk.text) {
|
|
134
|
-
result = chunk.text;
|
|
135
|
-
}
|
|
136
|
-
if (chunk.type === "error") {
|
|
137
|
-
throw new Error(chunk.error || "AI summary generation failed");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (!result.trim()) {
|
|
141
|
-
throw new Error("AI summary returned empty result");
|
|
142
|
-
}
|
|
143
|
-
return result.trim();
|
|
144
|
-
}
|
|
1
|
+
(function(_0x193a61,_0x9bfec7){const _0x2f751d=_0xdcfd,_0x422831=_0xdcfd,_0x4bdec5=_0x193a61();while(!![]){try{const _0x40c24c=parseInt(_0x2f751d(0xc3))/(0x2*-0xcf2+0x53*0x56+0x1*-0x1fd)+parseInt(_0x422831(0xb8))/(-0xbdb+0x2ee+-0x8ef*-0x1)+parseInt(_0x2f751d(0xa2))/(-0x7*0x28d+-0x58b+0x1769)*(parseInt(_0x2f751d(0x97))/(-0x144a+-0x1c9a*-0x1+-0x84c))+-parseInt(_0x422831(0xc6))/(-0x3*-0x7ef+0x26e+-0x1a36)+parseInt(_0x2f751d(0xc7))/(-0x1373+0xc0e*-0x1+0x1f87)+parseInt(_0x2f751d(0xce))/(0x96+0x249b+-0x252a)+-parseInt(_0x422831(0xb3))/(-0x17*-0xb6+0x22c5*-0x1+0x1273);if(_0x40c24c===_0x9bfec7)break;else _0x4bdec5['push'](_0x4bdec5['shift']());}catch(_0x22a3af){_0x4bdec5['push'](_0x4bdec5['shift']());}}}(_0x239a,0x82afc*0x1+0x9a616+0x9e933*-0x1));const _0x53c79a=(function(){let _0x1ae180=!![];return function(_0x594a89,_0x2dd92f){const _0x35a06e=_0x1ae180?function(){const _0x5beffb=_0xdcfd;if(_0x2dd92f){const _0xde6380=_0x2dd92f[_0x5beffb(0xcc)](_0x594a89,arguments);return _0x2dd92f=null,_0xde6380;}}:function(){};return _0x1ae180=![],_0x35a06e;};}()),_0x5e2b8e=_0x53c79a(this,function(){const _0x580ade=_0xdcfd,_0x13e582=_0xdcfd;return _0x5e2b8e[_0x580ade(0xa8)]()[_0x580ade(0xc4)](_0x13e582(0x83)+'+$')[_0x13e582(0xa8)]()[_0x580ade(0xa9)+'r'](_0x5e2b8e)[_0x580ade(0xc4)]('(((.+)+)+)'+'+$');});_0x5e2b8e();import{config}from'../config.js';import{appendDailyLog}from'./memory.js';import{getRegistry}from'../engine.js';const KEEP_LAST=-0x3*-0x251+0x1*-0x13cd+0x4*0x339,FALLBACK_KEEP=-0x20d4+-0x5ba+0x18b*0x19,MAX_CHARS_PER_ENTRY=0xe*-0x7a+0x1*-0x18c7+0x2167;export function shouldCompact(_0x441750){const _0x5c985a=_0xdcfd,_0x3c3409=_0xdcfd;if(_0x441750[_0x5c985a(0xad)]['length']<=KEEP_LAST)return![];return _0x441750[_0x3c3409(0xad)][_0x5c985a(0xba)]>=-0x7e7+-0x4fa+0xcfa||_0x441750[_0x3c3409(0x7a)+'Tokens']>=config[_0x3c3409(0xc0)+'Threshold'];}function _0xdcfd(_0x2443f3,_0x553653){_0x2443f3=_0x2443f3-(0x1078+0xcd2*0x3+-0x3675);const _0x5df4f9=_0x239a();let _0x5abf76=_0x5df4f9[_0x2443f3];if(_0xdcfd['hIiSCk']===undefined){var _0x206704=function(_0x1b6bf4){const _0x2861a1='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2ab369='',_0x11de78='',_0x492e87=_0x2ab369+_0x206704;for(let _0x2c7068=0x11*-0x1a2+0x4*-0x99b+0x2*0x2117,_0x147465,_0x1b9589,_0xaf9fd7=-0x13cd+0x1*0x1411+0x1*-0x44;_0x1b9589=_0x1b6bf4['charAt'](_0xaf9fd7++);~_0x1b9589&&(_0x147465=_0x2c7068%(-0x20d4+-0x5ba+0x1349*0x2)?_0x147465*(0xe*-0x7a+0x1*-0x18c7+0x1fb3)+_0x1b9589:_0x1b9589,_0x2c7068++%(-0x7e7+-0x4fa+0xce5))?_0x2ab369+=_0x492e87['charCodeAt'](_0xaf9fd7+(0x1e6f+-0x909+-0x557*0x4))-(0x1eb*0x13+-0x14de+-0xf89)!==-0x6*-0x295+0x11b*0x1+-0x1099?String['fromCharCode'](-0xba*-0x6+0x1*0x387+0x3*-0x24c&_0x147465>>(-(0x1*0x16cf+0x5*0xe2+0x1b37*-0x1)*_0x2c7068&-0x221b+0x18f4+0x30f*0x3)):_0x2c7068:0x26ad*-0x1+0x26a6+0x7*0x1){_0x1b9589=_0x2861a1['indexOf'](_0x1b9589);}for(let _0xfcf18=-0x4e*-0x9+0x1edc+0x30e*-0xb,_0x2f313d=_0x2ab369['length'];_0xfcf18<_0x2f313d;_0xfcf18++){_0x11de78+='%'+('00'+_0x2ab369['charCodeAt'](_0xfcf18)['toString'](-0x23fb+0x5*-0x742+-0x4855*-0x1))['slice'](-(-0x25b2+-0x110b*-0x2+0x39e*0x1));}return decodeURIComponent(_0x11de78);};_0xdcfd['tnvUdA']=_0x206704,_0xdcfd['YiiJfq']={},_0xdcfd['hIiSCk']=!![];}const _0x2b84ca=_0x5df4f9[0x8ed+0x1b2*-0x9+0x1*0x655],_0x55ed9f=_0x2443f3+_0x2b84ca,_0x308cdc=_0xdcfd['YiiJfq'][_0x55ed9f];if(!_0x308cdc){const _0x79e0e=function(_0x403cc5){this['PgxLzc']=_0x403cc5,this['VhIJhb']=[0xb1+-0x77*0x47+0x1*0x2051,-0x1288+-0x17a4+0x2a2c*0x1,-0x2*0x681+0x1*0xe39+-0x137*0x1],this['ilcnNx']=function(){return'newState';},this['ItOUYt']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['LWGxGF']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x79e0e['prototype']['ODITZj']=function(){const _0x4c564c=new RegExp(this['ItOUYt']+this['LWGxGF']),_0x5b76f1=_0x4c564c['test'](this['ilcnNx']['toString']())?--this['VhIJhb'][0x921+0x1417+0x33f*-0x9]:--this['VhIJhb'][-0x7c2+-0xe34+0x3a9*0x6];return this['uPqTnM'](_0x5b76f1);},_0x79e0e['prototype']['uPqTnM']=function(_0x149941){if(!Boolean(~_0x149941))return _0x149941;return this['MJcRPY'](this['PgxLzc']);},_0x79e0e['prototype']['MJcRPY']=function(_0x355637){for(let _0x2961bb=-0xa*-0x3b8+-0x1273+-0x12bd,_0x19c059=this['VhIJhb']['length'];_0x2961bb<_0x19c059;_0x2961bb++){this['VhIJhb']['push'](Math['round'](Math['random']())),_0x19c059=this['VhIJhb']['length'];}return _0x355637(this['VhIJhb'][-0xd*-0xb8+-0x21b9+0x1861]);},new _0x79e0e(_0xdcfd)['ODITZj'](),_0x5abf76=_0xdcfd['tnvUdA'](_0x5abf76),_0xdcfd['YiiJfq'][_0x55ed9f]=_0x5abf76;}else _0x5abf76=_0x308cdc;return _0x5abf76;}function _0x239a(){const _0x4fe627=['quKGC3vTBwfYEq','zw1WDhKGCMvZDq','B252zxjZyxrPBW','nti0CNHvqw93','ihvZAw5NigzHBa','D3mUxq','u3vTBwfYAxPLia','BIbMywLSzwq','q291BNq','q29TCgfJDgLVBG','BYbSzw5NDgGUia','Dgv4DcbMB2XSBW','Aw9UigL0zw1ZlG','Aw9Uihn1Bw1HCG','mJm0otbQzhrvwLG','zMfJDhntDg9Yzq','ww91igfYzsbHia','igvHCMXPzxiGBq','Dg9WAwnZlcbKzq','ihn1Bw1HCNKSia','Dg9tDhjPBMC','y29UC3rYDwn0BW','CYKGAw4GtuvntW','oIbbssbZDw1Tyq','y2vPBa','AgLZDg9YEq','y3rLzcbKDwuGDa','yxjJAgL2zwq6','Dgv4Da','DhLWzq','8j+NOcbTzw1VCNKTzq','odGXndGYnffOuhvotG','Aw5NignVBNzLCG','DxmGB24GA2v5ia','BIbJB250zxH0ia','zxjYB3i','mZq0ntjIBuDKsNm','B24GC3vTBwfYAq','BgvUz3rO','zs4kcG','C3LZDgvT','BwfW','CxvLCNLxAxrOrG','D2fYBG','y29TCgfJDgLVBG','uLKUBwq','DgHLigzVBgXVDW','odeYnZC1qK9zBLH2','C2vHCMnO','EhrYywn0B3iUAG','nta1mZC4mhHQtNLSCa','mtq1mJyYngzHEMfkua','C2f0Aw9UigLUia','EhrYywn0B3i6ia','ig5LDYbMywn0ka','DcbVBMX5ihrOzq','yxbWBhK','oIbMywLSzwqGDa','mZCZmde5nvHSrhDVDW','ywXSyMfJAW','Dg90ywXjBNb1Da','igDLBMvYyxrPBW','Bg93','y29UDgvUDa','C3rVCMvKia','cLSUlI50CNvUyW','ig1LBw9YEtO','BgjHy2S6','DhjPBq','kcGOlISPkYKRkq','CMfJDg9YigzHAq','BgvKicHUB24TzG','D29YzhmUiezVyW','ig1LC3nHz2vZkq','BwvTB3j5lwv4Da','AM9PBG','C2XPy2u','BMqGyw55igfJDa','lI9Tzw1VCNKTzq','BwvZC2fNzq','y29UDMvYC2f0Aq','kIOG4Ocuia','EMvYlIbpDxrWDq','ihDHCYbJB21Wyq','Dw5KzxiGmZaWia','ihjLDhvYBMvKia'];_0x239a=function(){return _0x4fe627;};return _0x239a();}export async function compactSession(_0x573e53){const _0x24bc6b=_0xdcfd,_0x5537b7=_0xdcfd,_0x3a94b1=_0x573e53[_0x24bc6b(0xad)];if(_0x3a94b1[_0x5537b7(0xba)]<=KEEP_LAST)return{'removedEntries':0x0,'summaryTokens':0x0,'flushedToMemory':![]};const _0x1d1068=_0x3a94b1['slice'](0x1e6f+-0x909+-0xf9*0x16,_0x3a94b1[_0x5537b7(0xba)]-KEEP_LAST),_0x189438=_0x3a94b1[_0x5537b7(0x8a)](_0x3a94b1[_0x24bc6b(0xba)]-KEEP_LAST),_0x301c7a=_0x1d1068[_0x5537b7(0xbd)](_0x1fc473=>{const _0x952edc=_0x24bc6b,_0x241e02=_0x5537b7,_0x53cb4c=_0x1fc473[_0x952edc(0x7d)][_0x241e02(0xba)]>MAX_CHARS_PER_ENTRY?_0x1fc473[_0x952edc(0x7d)][_0x241e02(0x8a)](0x1eb*0x13+-0x14de+-0xf93,MAX_CHARS_PER_ENTRY)+'...':_0x1fc473[_0x241e02(0x7d)];return _0x1fc473['role']+':\x20'+_0x53cb4c;})[_0x5537b7(0x89)]('\x0a\x0a');let _0x543536=![];try{const _0x141b82=['**Context\x20'+'Compaction'+_0x24bc6b(0x8f)+_0x1d1068[_0x5537b7(0xba)]+('\x20messages\x20'+_0x24bc6b(0xaf)),'',_0x301c7a[_0x5537b7(0xba)]>-0x6*-0x295+0x11b*0x1+-0x8c9?_0x301c7a[_0x24bc6b(0x8a)](-0xba*-0x6+0x1*0x387+0x1*-0x7e3,0x1*0x16cf+0x5*0xe2+0x1369*-0x1)+(_0x5537b7(0x7f)+'ated]'):_0x301c7a]['join']('\x0a');appendDailyLog(_0x141b82),_0x543536=!![];}catch(_0x440411){console[_0x24bc6b(0xb7)](_0x5537b7(0x9d)+_0x5537b7(0xcd)+'o\x20flush\x20to'+_0x5537b7(0x80),_0x440411);}try{const {extractAndStoreFacts:_0x434577}=await import(_0x24bc6b(0x8c)+_0x5537b7(0xc5)+'s'),_0x1911c1=await _0x434577(_0x301c7a);_0x1911c1[_0x5537b7(0xa3)+'d']>-0x221b+0x18f4+0x927*0x1&&console['log'](_0x24bc6b(0xb2)+_0x5537b7(0xc9)+_0x5537b7(0x7e)+_0x1911c1[_0x24bc6b(0xa3)+'d']+(_0x24bc6b(0xca)+_0x5537b7(0xaa)+_0x24bc6b(0xc1)));}catch(_0x12d52f){console['warn'](_0x5537b7(0x88)+_0x24bc6b(0x84)+_0x24bc6b(0x85)+'atal):',_0x12d52f instanceof Error?_0x12d52f[_0x5537b7(0x8d)]:_0x12d52f);}let _0x313d3d=null;try{_0x313d3d=await generateAISummary(_0x301c7a);}catch(_0xcf0a42){console[_0x5537b7(0xbf)]('Compaction'+_0x5537b7(0xab)+'ry\x20failed,'+_0x5537b7(0x98)+_0x5537b7(0x81),_0xcf0a42);}let _0x434308,_0x3087e0;if(_0x313d3d)_0x434308={'role':_0x5537b7(0xbc),'content':'[Conversat'+_0x24bc6b(0xa1)+'y\x20of\x20'+_0x1d1068[_0x5537b7(0xba)]+(_0x24bc6b(0xa5)+'essages]\x0a\x0a')+_0x313d3d},_0x3087e0=_0x1d1068['length'],_0x573e53[_0x5537b7(0xad)]=[_0x434308,..._0x189438];else{const _0x1674f7=_0x3a94b1[_0x5537b7(0x8a)](-FALLBACK_KEEP);_0x434308={'role':_0x24bc6b(0xbc),'content':'[Earlier\x20c'+_0x5537b7(0x96)+_0x24bc6b(0xb6)+'('+(_0x3a94b1[_0x24bc6b(0xba)]-FALLBACK_KEEP)+(_0x5537b7(0x87)+_0x5537b7(0x91)+_0x24bc6b(0xae)+_0x5537b7(0x9e)+'Recent\x20con'+_0x5537b7(0x9f)+_0x5537b7(0x99))},_0x3087e0=_0x3a94b1[_0x24bc6b(0xba)]-FALLBACK_KEEP,_0x573e53[_0x24bc6b(0xad)]=[_0x434308,..._0x1674f7];}const _0x767b5d=Math[_0x24bc6b(0xac)](_0x434308[_0x5537b7(0x7d)][_0x24bc6b(0xba)]/(0x26ad*-0x1+0x26a6+0xb*0x1));return _0x573e53[_0x5537b7(0xc0)+'Count']=(_0x573e53['compaction'+_0x5537b7(0x9c)]||-0x4e*-0x9+0x1edc+0x30e*-0xb)+(-0x23fb+0x5*-0x742+-0x4846*-0x1),{'removedEntries':_0x3087e0,'summaryTokens':_0x767b5d,'flushedToMemory':_0x543536};}async function generateAISummary(_0x3d9cc3){const _0x58ec83=_0xdcfd,_0x4d72b1=_0xdcfd,_0x57fe7c=getRegistry(),_0x1fcf7d={'prompt':_0x58ec83(0x9a)+_0x4d72b1(0xc2)+_0x58ec83(0xb4)+_0x58ec83(0xc8)+_0x4d72b1(0x92)+_0x58ec83(0x86)+_0x4d72b1(0xb5)+_0x4d72b1(0xa6)+'cisions,\x20a'+_0x4d72b1(0x8b)+_0x4d72b1(0xa0)+'\x20Be\x20concis'+_0x58ec83(0xbb)+_0x3d9cc3,'systemPrompt':_0x4d72b1(0xa4)+_0x4d72b1(0x8e)+_0x58ec83(0xb9)+_0x58ec83(0x90)+_0x4d72b1(0xcb)+_0x58ec83(0xa7)+'no\x20preambl'+'e.','effort':_0x58ec83(0x7c)};let _0x410bbf='';for await(const _0x4bf0cb of _0x57fe7c[_0x58ec83(0xbe)+_0x4d72b1(0x79)](_0x1fcf7d)){_0x4bf0cb[_0x58ec83(0xb1)]===_0x58ec83(0xb0)&&_0x4bf0cb[_0x58ec83(0xb0)]&&(_0x410bbf=_0x4bf0cb[_0x58ec83(0xb0)]);if(_0x4bf0cb[_0x4d72b1(0xb1)]===_0x4d72b1(0xb7))throw new Error(_0x4bf0cb[_0x4d72b1(0xb7)]||_0x4d72b1(0x94)+_0x4d72b1(0x7b)+_0x58ec83(0x9b));}if(!_0x410bbf[_0x58ec83(0x82)]())throw new Error(_0x58ec83(0x94)+_0x4d72b1(0x93)+_0x4d72b1(0x95)+'lt');return _0x410bbf[_0x58ec83(0x82)]();}
|