peachsim 0.1.696 → 0.1.698
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/detox/index.ts +21 -11
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +747 -31
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1561 -1439
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +1 -1
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +1482 -1359
- package/dist-lib/swift-compile.cjs +3 -1
- package/dist-lib/swift-compile.mjs +2 -1
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +2 -2
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/src/expo-swift-host.ts +174 -43
- package/src/expoSwiftContract.ts +19 -0
- package/src/swift-compile.ts +1 -1
- package/src/swift-submit.ts +2 -1
package/dist-lib/detox/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.698 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -2104,6 +2104,107 @@ function isAppBootTargetUrl(initUrl) {
|
|
|
2104
2104
|
}
|
|
2105
2105
|
}
|
|
2106
2106
|
|
|
2107
|
+
// cli/ws-bridge.ts
|
|
2108
|
+
var import_ws = require("ws");
|
|
2109
|
+
|
|
2110
|
+
// src/simulator-route.ts
|
|
2111
|
+
var PEACH_SIMULATOR_PATH = "/simulator";
|
|
2112
|
+
var SIMULATOR_DOCUMENT_PATH = new RegExp(
|
|
2113
|
+
`^${PEACH_SIMULATOR_PATH}(?:/(?:rn(?:/[^/]+)?|app/[^/]+|dock/[^/]+))?/?$`
|
|
2114
|
+
);
|
|
2115
|
+
|
|
2116
|
+
// src/bridge-constants.ts
|
|
2117
|
+
var DEFAULT_SOOTSIM_BRIDGE_PORT = 7668;
|
|
2118
|
+
var DEFAULT_SOOTSIM_BRIDGE_URL = `http://localhost:${DEFAULT_SOOTSIM_BRIDGE_PORT}/`;
|
|
2119
|
+
function parsePort(value) {
|
|
2120
|
+
if (typeof value === "number") {
|
|
2121
|
+
return Number.isInteger(value) && value > 0 ? value : null;
|
|
2122
|
+
}
|
|
2123
|
+
if (typeof value !== "string") return null;
|
|
2124
|
+
const trimmed = value.trim();
|
|
2125
|
+
if (!trimmed) return null;
|
|
2126
|
+
const parsed = Number(trimmed);
|
|
2127
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : null;
|
|
2128
|
+
}
|
|
2129
|
+
function parsePortOffset(value) {
|
|
2130
|
+
const parsed = parsePort(value);
|
|
2131
|
+
return parsed === null ? 0 : parsed;
|
|
2132
|
+
}
|
|
2133
|
+
function resolveSootsimBridgePort(input = {}) {
|
|
2134
|
+
const explicitPort = parsePort(input.explicitPort);
|
|
2135
|
+
if (explicitPort !== null) return explicitPort;
|
|
2136
|
+
return DEFAULT_SOOTSIM_BRIDGE_PORT + parsePortOffset(input.portOffset);
|
|
2137
|
+
}
|
|
2138
|
+
function resolveSootsimBridgePortForHttpPort(input) {
|
|
2139
|
+
const explicitPort = parsePort(input.explicitPort);
|
|
2140
|
+
if (explicitPort !== null) return explicitPort;
|
|
2141
|
+
const httpPort = parsePort(input.httpPort);
|
|
2142
|
+
const portOffset = httpPort === null ? 0 : Math.max(0, httpPort - input.baseHttpPort);
|
|
2143
|
+
return resolveSootsimBridgePort({ portOffset });
|
|
2144
|
+
}
|
|
2145
|
+
var HOSTED_SHELL_PATH = new RegExp(`^(?:${PEACH_SIMULATOR_PATH}|/sootsim)(?:/|$)`);
|
|
2146
|
+
var AUTOMATION_SIM_IDLE_REAP_TTL_MS = 5 * 6e4;
|
|
2147
|
+
|
|
2148
|
+
// src/home-paths.ts
|
|
2149
|
+
var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
|
|
2150
|
+
|
|
2151
|
+
// ../peach-engine/src/metro-fingerprint-registry-client.ts
|
|
2152
|
+
var import_metro_fingerprint_registry = require("peachsim/metro-fingerprint-registry");
|
|
2153
|
+
|
|
2154
|
+
// ../peach-engine/src/metro-fingerprint.ts
|
|
2155
|
+
var import_metro_production_bundle = require("peachsim/metro-production-bundle");
|
|
2156
|
+
var import_react_native_host_modules = require("peachsim/react-native-host-modules");
|
|
2157
|
+
|
|
2158
|
+
// src/cloud-contract.ts
|
|
2159
|
+
var RNX_CLOUD_MAX_ARTIFACT_BYTES = 20 * 1024 * 1024;
|
|
2160
|
+
var RNX_CLOUD_DESIGN_MAX_STORAGE_BYTES = 1024 * 1024;
|
|
2161
|
+
var RNX_CLOUD_COMMAND_SCOPES = {
|
|
2162
|
+
state: "read",
|
|
2163
|
+
tree: "read",
|
|
2164
|
+
query: "read",
|
|
2165
|
+
resolve: "read",
|
|
2166
|
+
screenshot: "read",
|
|
2167
|
+
capture: "read",
|
|
2168
|
+
captureRegions: "read",
|
|
2169
|
+
memory: "read",
|
|
2170
|
+
diagnostics: "read",
|
|
2171
|
+
storageSnapshot: "read",
|
|
2172
|
+
perform: "drive",
|
|
2173
|
+
waitFor: "drive",
|
|
2174
|
+
tap: "drive",
|
|
2175
|
+
longPress: "drive",
|
|
2176
|
+
settle: "drive",
|
|
2177
|
+
openUrl: "drive",
|
|
2178
|
+
setAppearance: "drive",
|
|
2179
|
+
keyboard: "drive",
|
|
2180
|
+
focus: "drive",
|
|
2181
|
+
flowStatus: "drive",
|
|
2182
|
+
reset: "reset",
|
|
2183
|
+
camera: "media",
|
|
2184
|
+
location: "media",
|
|
2185
|
+
// string evaluation and arbitrary bridge calls are maestro's boundary: the
|
|
2186
|
+
// customer sdk never carries this scope, and the service grants it only to
|
|
2187
|
+
// the account api key caller. close rides along, since ending the page ends
|
|
2188
|
+
// the sim and belongs to the sim's owner rather than any driver.
|
|
2189
|
+
evaluate: "debug",
|
|
2190
|
+
call: "debug",
|
|
2191
|
+
close: "debug"
|
|
2192
|
+
};
|
|
2193
|
+
function scopeTableKeys() {
|
|
2194
|
+
return Object.keys(RNX_CLOUD_COMMAND_SCOPES).filter(
|
|
2195
|
+
(key) => Object.prototype.hasOwnProperty.call(RNX_CLOUD_COMMAND_SCOPES, key)
|
|
2196
|
+
);
|
|
2197
|
+
}
|
|
2198
|
+
var RNX_CLOUD_COMMAND_TYPES = Object.freeze(scopeTableKeys());
|
|
2199
|
+
var RNX_CLOUD_COMMAND_TYPE_SET = new Set(RNX_CLOUD_COMMAND_TYPES);
|
|
2200
|
+
var RNX_CLOUD_TOKEN_SCOPES = Object.freeze([
|
|
2201
|
+
"read",
|
|
2202
|
+
"drive",
|
|
2203
|
+
"reset",
|
|
2204
|
+
"media"
|
|
2205
|
+
]);
|
|
2206
|
+
var RNX_CLOUD_ALL_COMMAND_SCOPES = Object.freeze(["read", "drive", "reset", "media", "debug"]);
|
|
2207
|
+
|
|
2107
2208
|
// src/public-brand.ts
|
|
2108
2209
|
var name = "Peach";
|
|
2109
2210
|
var peachPublicBrand = Object.freeze({
|
|
@@ -2113,6 +2214,613 @@ var peachPublicBrand = Object.freeze({
|
|
|
2113
2214
|
domain: "peachsim.com",
|
|
2114
2215
|
origin: "https://peachsim.com"
|
|
2115
2216
|
});
|
|
2217
|
+
var rnxPublicBrand = peachPublicBrand;
|
|
2218
|
+
|
|
2219
|
+
// cli/run-rnx.ts
|
|
2220
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
2221
|
+
var sinks = new import_node_async_hooks.AsyncLocalStorage();
|
|
2222
|
+
|
|
2223
|
+
// cli/cloud-session.ts
|
|
2224
|
+
var MAX_ENCODED_SESSION_BYTES = 32 * 1024;
|
|
2225
|
+
var RNX_SHELL_UPDATE_PREFIX = "__RNX_SHELL_UPDATE_V1__";
|
|
2226
|
+
var RNX_SHELL_UPDATE_SET_PREFIX = `${RNX_SHELL_UPDATE_PREFIX}set:`;
|
|
2227
|
+
var RNX_SHELL_UPDATE_UNSET = `${RNX_SHELL_UPDATE_PREFIX}unset`;
|
|
2228
|
+
|
|
2229
|
+
// cli/commands/detect.ts
|
|
2230
|
+
var import_json5 = __toESM(require("json5"), 1);
|
|
2231
|
+
var import_yaml = require("yaml");
|
|
2232
|
+
|
|
2233
|
+
// cli/cloud-client.ts
|
|
2234
|
+
var DEFAULT_RNX_CLOUD_ORIGIN = rnxPublicBrand.origin;
|
|
2235
|
+
|
|
2236
|
+
// cli/current-sim.ts
|
|
2237
|
+
var import_fs2 = require("fs");
|
|
2238
|
+
var import_os = require("os");
|
|
2239
|
+
var import_path = require("path");
|
|
2240
|
+
|
|
2241
|
+
// cli/parent-pid.ts
|
|
2242
|
+
var import_child_process = require("child_process");
|
|
2243
|
+
var import_fs = require("fs");
|
|
2244
|
+
var import_module = require("module");
|
|
2245
|
+
var cached = null;
|
|
2246
|
+
var cachedComm = null;
|
|
2247
|
+
function getParentPid(pid) {
|
|
2248
|
+
if (!cached) cached = build();
|
|
2249
|
+
try {
|
|
2250
|
+
return cached(pid);
|
|
2251
|
+
} catch {
|
|
2252
|
+
return null;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
function getProcessComm(pid) {
|
|
2256
|
+
if (!cachedComm) cachedComm = buildComm();
|
|
2257
|
+
try {
|
|
2258
|
+
return cachedComm(pid);
|
|
2259
|
+
} catch {
|
|
2260
|
+
return null;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
function buildComm() {
|
|
2264
|
+
if (process.platform === "linux") {
|
|
2265
|
+
return (pid) => {
|
|
2266
|
+
try {
|
|
2267
|
+
return (0, import_fs.readFileSync)(`/proc/${pid}/comm`, "utf8").trim() || null;
|
|
2268
|
+
} catch {
|
|
2269
|
+
return null;
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
if (process.platform === "darwin") {
|
|
2274
|
+
const ffi = tryBuildDarwinCommFfi();
|
|
2275
|
+
if (ffi) return ffi;
|
|
2276
|
+
return (pid) => readProcessTable().get(pid)?.comm || null;
|
|
2277
|
+
}
|
|
2278
|
+
return () => null;
|
|
2279
|
+
}
|
|
2280
|
+
function build() {
|
|
2281
|
+
const envPpid = Number(process.env.PPID);
|
|
2282
|
+
if (Number.isFinite(envPpid) && envPpid > 1 && envPpid !== process.ppid) {
|
|
2283
|
+
return () => envPpid;
|
|
2284
|
+
}
|
|
2285
|
+
if (process.platform === "linux") return buildLinux();
|
|
2286
|
+
if (process.platform === "darwin") {
|
|
2287
|
+
const ffi = tryBuildDarwinFfi();
|
|
2288
|
+
if (ffi) return ffi;
|
|
2289
|
+
return (pid) => {
|
|
2290
|
+
const ppid = readProcessTable().get(pid)?.ppid;
|
|
2291
|
+
return ppid !== void 0 && ppid > 0 ? ppid : null;
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
return () => null;
|
|
2295
|
+
}
|
|
2296
|
+
var PROCESS_TABLE_TTL_MS = 2e3;
|
|
2297
|
+
var processTable = { readAt: 0, rows: /* @__PURE__ */ new Map() };
|
|
2298
|
+
function readProcessTable() {
|
|
2299
|
+
const now = Date.now();
|
|
2300
|
+
if (processTable.readAt && now - processTable.readAt < PROCESS_TABLE_TTL_MS) {
|
|
2301
|
+
return processTable.rows;
|
|
2302
|
+
}
|
|
2303
|
+
const rows = /* @__PURE__ */ new Map();
|
|
2304
|
+
try {
|
|
2305
|
+
const out = (0, import_child_process.execFileSync)("ps", ["-eo", "pid=,ppid=,comm="], {
|
|
2306
|
+
encoding: "utf8",
|
|
2307
|
+
timeout: 5e3,
|
|
2308
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
2309
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
2310
|
+
});
|
|
2311
|
+
for (const line of out.split("\n")) {
|
|
2312
|
+
const parsed = line.trim().match(/^(\d+)\s+(\d+)\s+(.*)$/);
|
|
2313
|
+
if (!parsed) continue;
|
|
2314
|
+
rows.set(Number(parsed[1]), {
|
|
2315
|
+
ppid: Number(parsed[2]),
|
|
2316
|
+
comm: (parsed[3].split("/").at(-1) ?? "").slice(0, PBI_COMM_LEN)
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
} catch {
|
|
2320
|
+
}
|
|
2321
|
+
processTable = { readAt: now, rows };
|
|
2322
|
+
return rows;
|
|
2323
|
+
}
|
|
2324
|
+
function buildLinux() {
|
|
2325
|
+
return (pid) => {
|
|
2326
|
+
try {
|
|
2327
|
+
const raw = (0, import_fs.readFileSync)(`/proc/${pid}/stat`, "utf8");
|
|
2328
|
+
const end = raw.lastIndexOf(")");
|
|
2329
|
+
if (end < 0) return null;
|
|
2330
|
+
const rest = raw.slice(end + 1).trim().split(/\s+/);
|
|
2331
|
+
const ppid = Number(rest[1]);
|
|
2332
|
+
return Number.isFinite(ppid) && ppid > 0 ? ppid : null;
|
|
2333
|
+
} catch {
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
}
|
|
2338
|
+
var PROC_PIDTBSDINFO = 3;
|
|
2339
|
+
var PROC_BSDINFO_SIZE = 216;
|
|
2340
|
+
var PBI_PPID_OFFSET = 16;
|
|
2341
|
+
var PBI_COMM_OFFSET = 48;
|
|
2342
|
+
var PBI_COMM_LEN = 16;
|
|
2343
|
+
function tryBuildDarwinFfi() {
|
|
2344
|
+
if (!process.versions?.bun) return null;
|
|
2345
|
+
try {
|
|
2346
|
+
const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
|
|
2347
|
+
const { dlopen, FFIType } = r("bun:ffi");
|
|
2348
|
+
const lib = dlopen("/usr/lib/libproc.dylib", {
|
|
2349
|
+
proc_pidinfo: {
|
|
2350
|
+
args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
|
|
2351
|
+
returns: FFIType.i32
|
|
2352
|
+
}
|
|
2353
|
+
});
|
|
2354
|
+
const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
|
|
2355
|
+
return (pid) => {
|
|
2356
|
+
const ret = Number(
|
|
2357
|
+
lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
|
|
2358
|
+
);
|
|
2359
|
+
if (ret <= 0) return null;
|
|
2360
|
+
const ppid = buf.readUInt32LE(PBI_PPID_OFFSET);
|
|
2361
|
+
return ppid > 0 ? ppid : null;
|
|
2362
|
+
};
|
|
2363
|
+
} catch {
|
|
2364
|
+
return null;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
function tryBuildDarwinCommFfi() {
|
|
2368
|
+
if (!process.versions?.bun) return null;
|
|
2369
|
+
try {
|
|
2370
|
+
const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
|
|
2371
|
+
const { dlopen, FFIType } = r("bun:ffi");
|
|
2372
|
+
const lib = dlopen("/usr/lib/libproc.dylib", {
|
|
2373
|
+
proc_pidinfo: {
|
|
2374
|
+
args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
|
|
2375
|
+
returns: FFIType.i32
|
|
2376
|
+
}
|
|
2377
|
+
});
|
|
2378
|
+
const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
|
|
2379
|
+
return (pid) => {
|
|
2380
|
+
const ret = Number(
|
|
2381
|
+
lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
|
|
2382
|
+
);
|
|
2383
|
+
if (ret <= 0) return null;
|
|
2384
|
+
const raw = buf.subarray(PBI_COMM_OFFSET, PBI_COMM_OFFSET + PBI_COMM_LEN);
|
|
2385
|
+
const end = raw.indexOf(0);
|
|
2386
|
+
const comm = raw.subarray(0, end < 0 ? raw.length : end).toString("utf8");
|
|
2387
|
+
return comm || null;
|
|
2388
|
+
};
|
|
2389
|
+
} catch {
|
|
2390
|
+
return null;
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
// cli/secure-file.ts
|
|
2395
|
+
var import_node_crypto = require("node:crypto");
|
|
2396
|
+
var import_node_fs = require("node:fs");
|
|
2397
|
+
var import_node_path = require("node:path");
|
|
2398
|
+
function writeSecureJsonAtomic(filepath, value) {
|
|
2399
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(filepath), { recursive: true });
|
|
2400
|
+
const temporary = `${filepath}.tmp-${process.pid}-${(0, import_node_crypto.randomUUID)()}`;
|
|
2401
|
+
let descriptor = null;
|
|
2402
|
+
try {
|
|
2403
|
+
descriptor = (0, import_node_fs.openSync)(temporary, "wx", 384);
|
|
2404
|
+
(0, import_node_fs.fchmodSync)(descriptor, 384);
|
|
2405
|
+
(0, import_node_fs.writeFileSync)(descriptor, `${JSON.stringify(value, null, 2)}
|
|
2406
|
+
`);
|
|
2407
|
+
(0, import_node_fs.fsyncSync)(descriptor);
|
|
2408
|
+
(0, import_node_fs.closeSync)(descriptor);
|
|
2409
|
+
descriptor = null;
|
|
2410
|
+
(0, import_node_fs.renameSync)(temporary, filepath);
|
|
2411
|
+
} catch (error) {
|
|
2412
|
+
if (descriptor !== null) (0, import_node_fs.closeSync)(descriptor);
|
|
2413
|
+
(0, import_node_fs.rmSync)(temporary, { force: true });
|
|
2414
|
+
throw error;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// cli/current-sim.ts
|
|
2419
|
+
var CURRENT_SIM_VERSION = 2;
|
|
2420
|
+
var CURRENT_SIM_PATH_ENV = "SOOTSIM_CLI_CURRENT_SIM_PATH";
|
|
2421
|
+
var IDENTITY_ENV_VARS = [
|
|
2422
|
+
"PEACH_CLI_IDENTITY",
|
|
2423
|
+
// explicit override — fastest path, skips all pid lookups
|
|
2424
|
+
"CLAUDE_CODE_SESSION_ID",
|
|
2425
|
+
// claude code, if ever set
|
|
2426
|
+
"CODEX_THREAD_ID",
|
|
2427
|
+
// codex / openai agent thread, stable across tool invocations
|
|
2428
|
+
// a Team Machine session, per agent run. its other runners set no session
|
|
2429
|
+
// variable of their own, and the terminal variables below are inherited from
|
|
2430
|
+
// whatever shell started the daemon, so every such agent would share one key.
|
|
2431
|
+
"TM_SESSION",
|
|
2432
|
+
"TERM_SESSION_ID",
|
|
2433
|
+
// macOS Terminal.app + iTerm2
|
|
2434
|
+
"ITERM_SESSION_ID",
|
|
2435
|
+
// iTerm2 (older variant)
|
|
2436
|
+
"TMUX_PANE",
|
|
2437
|
+
// tmux — stable per pane
|
|
2438
|
+
"STY",
|
|
2439
|
+
// GNU screen session
|
|
2440
|
+
"KITTY_WINDOW_ID",
|
|
2441
|
+
// kitty
|
|
2442
|
+
"WEZTERM_PANE",
|
|
2443
|
+
// wezterm
|
|
2444
|
+
"ALACRITTY_WINDOW_ID",
|
|
2445
|
+
// alacritty
|
|
2446
|
+
"WINDOWID",
|
|
2447
|
+
// X11 terminals
|
|
2448
|
+
"VSCODE_INJECTION"
|
|
2449
|
+
// vscode integrated terminal
|
|
2450
|
+
];
|
|
2451
|
+
var IMMORTAL_HOST_COMM_RE = /^(?:tmux|screen)|^tm$/i;
|
|
2452
|
+
function findTopAncestor(start, maxDepth = 20) {
|
|
2453
|
+
let prev = start;
|
|
2454
|
+
let pid = getParentPid(start);
|
|
2455
|
+
if (!pid || pid <= 1) {
|
|
2456
|
+
const comm = getProcessComm(start);
|
|
2457
|
+
return start > 1 && comm && !IMMORTAL_HOST_COMM_RE.test(comm) ? start : null;
|
|
2458
|
+
}
|
|
2459
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
2460
|
+
const comm = getProcessComm(pid);
|
|
2461
|
+
if (comm && IMMORTAL_HOST_COMM_RE.test(comm)) return prev;
|
|
2462
|
+
const parent = getParentPid(pid);
|
|
2463
|
+
if (!parent || parent <= 1) {
|
|
2464
|
+
return comm ? pid : prev;
|
|
2465
|
+
}
|
|
2466
|
+
prev = pid;
|
|
2467
|
+
pid = parent;
|
|
2468
|
+
}
|
|
2469
|
+
return pid;
|
|
2470
|
+
}
|
|
2471
|
+
function getCliIdentity() {
|
|
2472
|
+
for (const name2 of IDENTITY_ENV_VARS) {
|
|
2473
|
+
const value = process.env[name2];
|
|
2474
|
+
if (value && value.trim()) {
|
|
2475
|
+
return { key: `${name2}:${value.trim()}`, source: name2, stable: true };
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
const topPid = findTopAncestor(process.ppid);
|
|
2479
|
+
if (topPid && topPid > 1) {
|
|
2480
|
+
return { key: `gppid-${topPid}`, source: "grand-ppid", stable: true };
|
|
2481
|
+
}
|
|
2482
|
+
return { key: `pid-${process.ppid}`, source: "ppid", stable: false };
|
|
2483
|
+
}
|
|
2484
|
+
function getCliIdentityKey() {
|
|
2485
|
+
return getCliIdentity().key;
|
|
2486
|
+
}
|
|
2487
|
+
function getCurrentSimPath() {
|
|
2488
|
+
if (process.env[CURRENT_SIM_PATH_ENV]) {
|
|
2489
|
+
return (0, import_path.resolve)(process.env[CURRENT_SIM_PATH_ENV]);
|
|
2490
|
+
}
|
|
2491
|
+
const key = getCliIdentityKey();
|
|
2492
|
+
return (0, import_path.join)((0, import_os.tmpdir)(), `peach-current-sim-${key}.json`);
|
|
2493
|
+
}
|
|
2494
|
+
function legacyCloudCredentialDirectory(filepath) {
|
|
2495
|
+
return (0, import_path.join)((0, import_path.dirname)(filepath), `${(0, import_path.basename)(filepath)}.credentials`);
|
|
2496
|
+
}
|
|
2497
|
+
function readCurrentTarget() {
|
|
2498
|
+
const filepath = getCurrentSimPath();
|
|
2499
|
+
(0, import_fs2.rmSync)(legacyCloudCredentialDirectory(filepath), { recursive: true, force: true });
|
|
2500
|
+
if (!(0, import_fs2.existsSync)(filepath)) return null;
|
|
2501
|
+
try {
|
|
2502
|
+
const parsed = JSON.parse((0, import_fs2.readFileSync)(filepath, "utf8"));
|
|
2503
|
+
if (parsed === null || typeof parsed !== "object") {
|
|
2504
|
+
(0, import_fs2.rmSync)(filepath, { force: true });
|
|
2505
|
+
return null;
|
|
2506
|
+
}
|
|
2507
|
+
const version = Reflect.get(parsed, "version");
|
|
2508
|
+
const plane = Reflect.get(parsed, "plane");
|
|
2509
|
+
const simId = Reflect.get(parsed, "simId");
|
|
2510
|
+
const updatedAt = Reflect.get(parsed, "updatedAt");
|
|
2511
|
+
if (version !== 1 && version !== CURRENT_SIM_VERSION || version === CURRENT_SIM_VERSION && plane !== "local" || typeof simId !== "string" || !simId.trim() || typeof updatedAt !== "string") {
|
|
2512
|
+
(0, import_fs2.rmSync)(filepath, { force: true });
|
|
2513
|
+
return null;
|
|
2514
|
+
}
|
|
2515
|
+
const target = {
|
|
2516
|
+
version: CURRENT_SIM_VERSION,
|
|
2517
|
+
plane: "local",
|
|
2518
|
+
simId: simId.trim(),
|
|
2519
|
+
updatedAt
|
|
2520
|
+
};
|
|
2521
|
+
if (version === 1) writeSecureJsonAtomic(filepath, target);
|
|
2522
|
+
return target;
|
|
2523
|
+
} catch {
|
|
2524
|
+
(0, import_fs2.rmSync)(filepath, { force: true });
|
|
2525
|
+
return null;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
function readCurrentSimId() {
|
|
2529
|
+
return readCurrentTarget()?.simId ?? null;
|
|
2530
|
+
}
|
|
2531
|
+
function saveCurrentSimId(simId) {
|
|
2532
|
+
const normalized = simId.trim();
|
|
2533
|
+
if (!normalized) return;
|
|
2534
|
+
writeSecureJsonAtomic(getCurrentSimPath(), {
|
|
2535
|
+
version: CURRENT_SIM_VERSION,
|
|
2536
|
+
plane: "local",
|
|
2537
|
+
simId: normalized,
|
|
2538
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// cli/ws-bridge.ts
|
|
2543
|
+
function bridgeWsUrl(wsPort) {
|
|
2544
|
+
return `ws://127.0.0.1:${wsPort}`;
|
|
2545
|
+
}
|
|
2546
|
+
var BridgeSimLockedError = class extends Error {
|
|
2547
|
+
lock;
|
|
2548
|
+
constructor(message, lock) {
|
|
2549
|
+
super(message);
|
|
2550
|
+
this.name = "BridgeSimLockedError";
|
|
2551
|
+
this.lock = lock;
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
function describeSimIdSource(source) {
|
|
2555
|
+
if (source === "flag") return "via --sim";
|
|
2556
|
+
if (source === "saved") return "saved via `peach use`";
|
|
2557
|
+
return "primary fallback \u2014 no sim pinned";
|
|
2558
|
+
}
|
|
2559
|
+
var BRIDGE_VALUE_FLAGS_TABLE = [
|
|
2560
|
+
{
|
|
2561
|
+
names: ["--port", "-p"],
|
|
2562
|
+
// naming the flag pins the world even when the value is missing or junk,
|
|
2563
|
+
// so a later --base-url cannot quietly retarget the run to another shell.
|
|
2564
|
+
apply: (state, value) => {
|
|
2565
|
+
state.explicitPort = true;
|
|
2566
|
+
if (value !== void 0) state.wsPort = Number(value);
|
|
2567
|
+
}
|
|
2568
|
+
},
|
|
2569
|
+
{
|
|
2570
|
+
names: ["--timeout"],
|
|
2571
|
+
apply: (state, value) => {
|
|
2572
|
+
if (value !== void 0) state.commandTimeoutMs = Number(value);
|
|
2573
|
+
}
|
|
2574
|
+
},
|
|
2575
|
+
{
|
|
2576
|
+
// `--sim` is the canonical target flag; `--session` / `--tab` are
|
|
2577
|
+
// documented aliases (CLAUDE.md, the peach agent skills, and engine docs all
|
|
2578
|
+
// say `--session <id>`). without these aliases an agent following the docs
|
|
2579
|
+
// would have `--session ef` silently ignored and get the *currently
|
|
2580
|
+
// pinned* sim's tree instead — wrong-app data with no error.
|
|
2581
|
+
names: ["--sim", "--session", "--tab"],
|
|
2582
|
+
apply: (state, value) => {
|
|
2583
|
+
if (value === void 0) return;
|
|
2584
|
+
state.simId = value.trim() || void 0;
|
|
2585
|
+
state.simIdSource = "flag";
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
];
|
|
2589
|
+
var BRIDGE_VALUE_FLAGS = BRIDGE_VALUE_FLAGS_TABLE.flatMap(
|
|
2590
|
+
(flag) => [...flag.names]
|
|
2591
|
+
);
|
|
2592
|
+
function createBridge(wsPort, opts = {}) {
|
|
2593
|
+
let nextId = 1;
|
|
2594
|
+
const commandTimeoutMs = opts.commandTimeoutMs ?? 15e3;
|
|
2595
|
+
const pending = /* @__PURE__ */ new Map();
|
|
2596
|
+
const ws = new import_ws.WebSocket(bridgeWsUrl(wsPort));
|
|
2597
|
+
const identity = getCliIdentity();
|
|
2598
|
+
const ready = new Promise((resolve2, reject) => {
|
|
2599
|
+
ws.on("open", () => {
|
|
2600
|
+
try {
|
|
2601
|
+
ws.send(
|
|
2602
|
+
JSON.stringify({
|
|
2603
|
+
type: "bridge:hello",
|
|
2604
|
+
id: 0,
|
|
2605
|
+
cliIdentityKey: identity.key,
|
|
2606
|
+
cliIdentitySource: identity.source,
|
|
2607
|
+
cliLabel: opts.cliLabel
|
|
2608
|
+
})
|
|
2609
|
+
);
|
|
2610
|
+
} catch {
|
|
2611
|
+
}
|
|
2612
|
+
resolve2();
|
|
2613
|
+
});
|
|
2614
|
+
ws.on("error", (err) => {
|
|
2615
|
+
const cause = err.message ? `: ${err.message}` : "";
|
|
2616
|
+
reject(
|
|
2617
|
+
new Error(
|
|
2618
|
+
`could not connect to ${bridgeWsUrl(wsPort)}${cause}
|
|
2619
|
+
for sandboxed or agent runners, keep \`peach serve --port ${wsPort}\` running in a persistent terminal or background task.`
|
|
2620
|
+
)
|
|
2621
|
+
);
|
|
2622
|
+
});
|
|
2623
|
+
});
|
|
2624
|
+
ready.catch(() => {
|
|
2625
|
+
});
|
|
2626
|
+
let warnedAboutContention = false;
|
|
2627
|
+
let noticedTarget = false;
|
|
2628
|
+
const lineageBySimId = /* @__PURE__ */ new Map();
|
|
2629
|
+
const lineageLookupBySimId = /* @__PURE__ */ new Map();
|
|
2630
|
+
function pickReloadedTarget(sims, retiredSimId) {
|
|
2631
|
+
const lineage = lineageBySimId.get(retiredSimId);
|
|
2632
|
+
if (!lineage) return null;
|
|
2633
|
+
const matches = (Array.isArray(sims) ? sims : []).filter(
|
|
2634
|
+
(sim) => sim.readyState === "open" && sim.meta?.sootsimHostPid === lineage.hostPid && sim.connectedAt > lineage.connectedAt
|
|
2635
|
+
);
|
|
2636
|
+
const successor = matches.find((sim) => sim.id === retiredSimId) ?? (matches.length === 1 ? matches[0] : null);
|
|
2637
|
+
if (!successor) return null;
|
|
2638
|
+
lineageBySimId.set(successor.id, {
|
|
2639
|
+
hostPid: lineage.hostPid,
|
|
2640
|
+
connectedAt: successor.connectedAt
|
|
2641
|
+
});
|
|
2642
|
+
return successor.id;
|
|
2643
|
+
}
|
|
2644
|
+
function maybeNoticeTarget(cmdType, simId) {
|
|
2645
|
+
if (noticedTarget) return;
|
|
2646
|
+
if (process.env.SOOTSIM_QUIET_TARGET_NOTICE === "1") return;
|
|
2647
|
+
if (cmdType.startsWith("bridge:") || cmdType === "focus" || cmdType === "close")
|
|
2648
|
+
return;
|
|
2649
|
+
noticedTarget = true;
|
|
2650
|
+
const label = simId ?? "primary";
|
|
2651
|
+
const source = describeSimIdSource(simId ? opts.simIdSource : "none");
|
|
2652
|
+
process.stderr.write(` \u2192 ${label} (${source})
|
|
2653
|
+
`);
|
|
2654
|
+
}
|
|
2655
|
+
ws.on("message", (data) => {
|
|
2656
|
+
let msg;
|
|
2657
|
+
try {
|
|
2658
|
+
msg = JSON.parse(data.toString());
|
|
2659
|
+
} catch {
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
if (msg.id === 0) return;
|
|
2663
|
+
const p = pending.get(msg.id);
|
|
2664
|
+
if (!p) return;
|
|
2665
|
+
pending.delete(msg.id);
|
|
2666
|
+
if (msg._otherCliCount > 0 && !warnedAboutContention) {
|
|
2667
|
+
warnedAboutContention = true;
|
|
2668
|
+
process.stderr.write(
|
|
2669
|
+
`
|
|
2670
|
+
\u26A0 ${msg._otherCliCount} other CLI identity/identities are driving this sim
|
|
2671
|
+
taps, scrolls, and keyboard input from multiple agents will collide on
|
|
2672
|
+
the same screen state (this is not a bridge throughput limit).
|
|
2673
|
+
use \`peach open --new\` for an isolated sim per agent.
|
|
2674
|
+
|
|
2675
|
+
`
|
|
2676
|
+
);
|
|
2677
|
+
}
|
|
2678
|
+
if (msg.error) {
|
|
2679
|
+
if (msg._locked) {
|
|
2680
|
+
p.reject(new BridgeSimLockedError(msg.error, msg._locked));
|
|
2681
|
+
} else {
|
|
2682
|
+
p.reject(new Error(msg.error));
|
|
2683
|
+
}
|
|
2684
|
+
} else {
|
|
2685
|
+
p.resolve(msg.result);
|
|
2686
|
+
}
|
|
2687
|
+
});
|
|
2688
|
+
ws.on("close", (code, reason) => {
|
|
2689
|
+
const msg = reason?.toString() || "connection closed";
|
|
2690
|
+
for (const [id, p] of pending) {
|
|
2691
|
+
pending.delete(id);
|
|
2692
|
+
p.reject(new Error(`sim disconnected: ${msg} (code ${code})`));
|
|
2693
|
+
}
|
|
2694
|
+
});
|
|
2695
|
+
return {
|
|
2696
|
+
plane: "local",
|
|
2697
|
+
async send(cmd, callOpts) {
|
|
2698
|
+
const effectiveTimeoutMs = callOpts?.timeoutMs ?? commandTimeoutMs;
|
|
2699
|
+
const sendOnce = async (defaultSimId, cmdOverride) => {
|
|
2700
|
+
await ready;
|
|
2701
|
+
const id = nextId++;
|
|
2702
|
+
return new Promise((resolve2, reject) => {
|
|
2703
|
+
const timeout = setTimeout(() => {
|
|
2704
|
+
pending.delete(id);
|
|
2705
|
+
reject(
|
|
2706
|
+
new Error(
|
|
2707
|
+
`command timed out after ${Math.round(effectiveTimeoutMs / 1e3)}s`
|
|
2708
|
+
)
|
|
2709
|
+
);
|
|
2710
|
+
}, effectiveTimeoutMs);
|
|
2711
|
+
pending.set(id, {
|
|
2712
|
+
resolve: (v) => {
|
|
2713
|
+
clearTimeout(timeout);
|
|
2714
|
+
resolve2(v);
|
|
2715
|
+
},
|
|
2716
|
+
reject: (e) => {
|
|
2717
|
+
clearTimeout(timeout);
|
|
2718
|
+
reject(e);
|
|
2719
|
+
}
|
|
2720
|
+
});
|
|
2721
|
+
const payload = { ...cmdOverride ?? cmd, id };
|
|
2722
|
+
if (payload.simId === void 0 && defaultSimId) {
|
|
2723
|
+
payload.simId = defaultSimId;
|
|
2724
|
+
}
|
|
2725
|
+
maybeNoticeTarget(payload.type ?? "", payload.simId);
|
|
2726
|
+
ws.send(JSON.stringify(payload));
|
|
2727
|
+
});
|
|
2728
|
+
};
|
|
2729
|
+
const sentSimId = opts.simIdSource === "flag" ? opts.simId : readCurrentSimId() ?? opts.simId;
|
|
2730
|
+
const targetedSimId = typeof cmd.simId === "string" && cmd.simId ? cmd.simId : sentSimId;
|
|
2731
|
+
try {
|
|
2732
|
+
if (targetedSimId && cmd.type !== "bridge:list-sims" && !lineageBySimId.has(targetedSimId)) {
|
|
2733
|
+
let lookup = lineageLookupBySimId.get(targetedSimId);
|
|
2734
|
+
if (!lookup) {
|
|
2735
|
+
lookup = (async () => {
|
|
2736
|
+
try {
|
|
2737
|
+
const sims = await sendOnce(void 0, { type: "bridge:list-sims" });
|
|
2738
|
+
if (!Array.isArray(sims)) return;
|
|
2739
|
+
const targeted = sims.find(
|
|
2740
|
+
(sim) => sim.id === targetedSimId
|
|
2741
|
+
);
|
|
2742
|
+
const hostPid = targeted?.meta?.sootsimHostPid;
|
|
2743
|
+
if (targeted && typeof hostPid === "number") {
|
|
2744
|
+
lineageBySimId.set(targetedSimId, {
|
|
2745
|
+
hostPid,
|
|
2746
|
+
connectedAt: targeted.connectedAt
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
} catch {
|
|
2750
|
+
} finally {
|
|
2751
|
+
lineageLookupBySimId.delete(targetedSimId);
|
|
2752
|
+
}
|
|
2753
|
+
})();
|
|
2754
|
+
lineageLookupBySimId.set(targetedSimId, lookup);
|
|
2755
|
+
}
|
|
2756
|
+
await lookup;
|
|
2757
|
+
}
|
|
2758
|
+
return await sendOnce(sentSimId);
|
|
2759
|
+
} catch (error) {
|
|
2760
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2761
|
+
const missingSimMessage = `no sim connected with id ${sentSimId}`;
|
|
2762
|
+
if (opts.simIdSource !== "flag" && sentSimId && cmd.simId === void 0 && (message === missingSimMessage || message.startsWith(`${missingSimMessage};`))) {
|
|
2763
|
+
const successor = pickReloadedTarget(
|
|
2764
|
+
await sendOnce(void 0, { type: "bridge:list-sims" }),
|
|
2765
|
+
sentSimId
|
|
2766
|
+
);
|
|
2767
|
+
if (successor) {
|
|
2768
|
+
saveCurrentSimId(successor);
|
|
2769
|
+
process.stderr.write(
|
|
2770
|
+
` note: sim ${sentSimId} reloaded and reconnected as ${successor}; following it
|
|
2771
|
+
`
|
|
2772
|
+
);
|
|
2773
|
+
return sendOnce(successor);
|
|
2774
|
+
}
|
|
2775
|
+
throw new Error(
|
|
2776
|
+
`saved sim ${sentSimId} is not connected${message.slice(missingSimMessage.length)}; commands resume when it reconnects, or run \`peach list\` and \`peach use <sim>\`, or open a fresh sim`
|
|
2777
|
+
);
|
|
2778
|
+
}
|
|
2779
|
+
throw error;
|
|
2780
|
+
}
|
|
2781
|
+
},
|
|
2782
|
+
async listSims() {
|
|
2783
|
+
const sims = await this.send({ type: "bridge:list-sims" });
|
|
2784
|
+
return Array.isArray(sims) ? sims : [];
|
|
2785
|
+
},
|
|
2786
|
+
// a caller holding its own pinned sim id (a flow runner sets simId on every
|
|
2787
|
+
// command, so it never reaches the pin-following path in send) asks here
|
|
2788
|
+
// after a reload retires its socket. the page can reconnect under a new id
|
|
2789
|
+
// or restore the old id; null means no unique same-host target exists.
|
|
2790
|
+
async resolveReloadedSim(retiredSimId) {
|
|
2791
|
+
return pickReloadedTarget(await this.listSims(), retiredSimId);
|
|
2792
|
+
},
|
|
2793
|
+
async focusSim(simId) {
|
|
2794
|
+
return this.send({ type: "focus", simId });
|
|
2795
|
+
},
|
|
2796
|
+
async closeSim(simId) {
|
|
2797
|
+
return this.send({ type: "close", simId });
|
|
2798
|
+
},
|
|
2799
|
+
async claim(simId, claimOpts = {}) {
|
|
2800
|
+
const result = await this.send({
|
|
2801
|
+
type: "bridge:claim",
|
|
2802
|
+
simId,
|
|
2803
|
+
force: claimOpts.force === true
|
|
2804
|
+
});
|
|
2805
|
+
return result;
|
|
2806
|
+
},
|
|
2807
|
+
close() {
|
|
2808
|
+
try {
|
|
2809
|
+
if (ws.readyState === import_ws.WebSocket.OPEN) {
|
|
2810
|
+
ws.send(JSON.stringify({ type: "bridge:bye", id: 0 }));
|
|
2811
|
+
}
|
|
2812
|
+
} catch {
|
|
2813
|
+
}
|
|
2814
|
+
ws.close();
|
|
2815
|
+
const terminateGrace = setTimeout(() => {
|
|
2816
|
+
if (ws.readyState !== import_ws.WebSocket.CLOSED) {
|
|
2817
|
+
ws.terminate();
|
|
2818
|
+
}
|
|
2819
|
+
}, 250);
|
|
2820
|
+
ws.once("close", () => clearTimeout(terminateGrace));
|
|
2821
|
+
}
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2116
2824
|
|
|
2117
2825
|
// src/menu.ts
|
|
2118
2826
|
var SOOTSIM_SHELL_COMMAND_NAME = "sootsim:shell-command";
|
|
@@ -2196,8 +2904,8 @@ async function pollUntil(read, ready, options) {
|
|
|
2196
2904
|
let intervalTimer;
|
|
2197
2905
|
try {
|
|
2198
2906
|
await Promise.race([
|
|
2199
|
-
new Promise((
|
|
2200
|
-
intervalTimer = setTimeout(
|
|
2907
|
+
new Promise((resolve2) => {
|
|
2908
|
+
intervalTimer = setTimeout(resolve2, Math.min(intervalMs, remaining));
|
|
2201
2909
|
}),
|
|
2202
2910
|
boundary
|
|
2203
2911
|
]);
|
|
@@ -2930,10 +3638,10 @@ var SootSimWaitForAction = class {
|
|
|
2930
3638
|
throw lastError || new Error(`waitFor timed out after ${ms}ms`);
|
|
2931
3639
|
}
|
|
2932
3640
|
// if no withTimeout is called, just run the assertion once
|
|
2933
|
-
async then(
|
|
3641
|
+
async then(resolve2, reject) {
|
|
2934
3642
|
try {
|
|
2935
3643
|
await this.withTimeout(5e3);
|
|
2936
|
-
|
|
3644
|
+
resolve2(void 0);
|
|
2937
3645
|
} catch (e) {
|
|
2938
3646
|
reject(e);
|
|
2939
3647
|
}
|
|
@@ -3292,7 +4000,7 @@ async function waitForSootsimShellReady(page, timeout = 3e4) {
|
|
|
3292
4000
|
await page.evaluate(
|
|
3293
4001
|
async ({ timeoutMs, expectsInitialAppPaint: expectsInitialAppPaint2 }) => {
|
|
3294
4002
|
let deadline = Date.now() + timeoutMs;
|
|
3295
|
-
const sleep = (ms) => new Promise((
|
|
4003
|
+
const sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3296
4004
|
const remaining = () => Math.max(1, deadline - Date.now());
|
|
3297
4005
|
const withTimeout = async (label, promise) => {
|
|
3298
4006
|
let timer = null;
|
|
@@ -3377,10 +4085,10 @@ async function waitForSootsimWorkletsIdle(page, timeout = 3e3) {
|
|
|
3377
4085
|
if (typeof getPeerStats !== "function") {
|
|
3378
4086
|
return { settled: true, skipped: true };
|
|
3379
4087
|
}
|
|
3380
|
-
const sleep = (ms) => new Promise((
|
|
4088
|
+
const sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3381
4089
|
const readStats = () => Promise.race([
|
|
3382
4090
|
getPeerStats(false),
|
|
3383
|
-
new Promise((
|
|
4091
|
+
new Promise((resolve2) => setTimeout(() => resolve2(null), 250))
|
|
3384
4092
|
]);
|
|
3385
4093
|
const start = Date.now();
|
|
3386
4094
|
const deadline = start + timeout2;
|
|
@@ -3429,7 +4137,7 @@ var CONTEXT_MEDIA_QUIESCE_TIMEOUT_MS = 2500;
|
|
|
3429
4137
|
async function quiesceContextMedia(context) {
|
|
3430
4138
|
const pages = context.pages();
|
|
3431
4139
|
if (pages.length === 0) return;
|
|
3432
|
-
const sleep = (ms) => new Promise((
|
|
4140
|
+
const sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3433
4141
|
await Promise.race([
|
|
3434
4142
|
Promise.all(
|
|
3435
4143
|
pages.map(
|
|
@@ -3533,7 +4241,7 @@ async function waitForSootsimIdle(page, maxMs = 3e3, strict = false) {
|
|
|
3533
4241
|
const pollMs = 50;
|
|
3534
4242
|
const requiredStablePolls = 3;
|
|
3535
4243
|
const layoutTolerance = 1;
|
|
3536
|
-
const sleep = (ms) => new Promise((
|
|
4244
|
+
const sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3537
4245
|
const isLayoutStable = (a, b) => {
|
|
3538
4246
|
if (!a || a.length !== b.length) return false;
|
|
3539
4247
|
for (let i = 0; i < b.length; i++) {
|
|
@@ -3859,11 +4567,11 @@ var MAX_SETTLED_SPEED_PT_PER_SEC = 2;
|
|
|
3859
4567
|
async function waitForFrameClock(page, minMs = 25) {
|
|
3860
4568
|
const start = performance.now();
|
|
3861
4569
|
await page.evaluate(
|
|
3862
|
-
() => new Promise((
|
|
3863
|
-
const timeoutId = setTimeout(() =>
|
|
4570
|
+
() => new Promise((resolve2) => {
|
|
4571
|
+
const timeoutId = setTimeout(() => resolve2(), 50);
|
|
3864
4572
|
requestAnimationFrame(() => {
|
|
3865
4573
|
clearTimeout(timeoutId);
|
|
3866
|
-
|
|
4574
|
+
resolve2();
|
|
3867
4575
|
});
|
|
3868
4576
|
})
|
|
3869
4577
|
);
|
|
@@ -4147,8 +4855,8 @@ function createSootSimElement(matcher) {
|
|
|
4147
4855
|
);
|
|
4148
4856
|
}
|
|
4149
4857
|
await page.evaluate(
|
|
4150
|
-
() => new Promise((
|
|
4151
|
-
requestAnimationFrame(() =>
|
|
4858
|
+
() => new Promise((resolve2) => {
|
|
4859
|
+
requestAnimationFrame(() => resolve2());
|
|
4152
4860
|
})
|
|
4153
4861
|
);
|
|
4154
4862
|
if (_synchronizationEnabled) {
|
|
@@ -4843,7 +5551,7 @@ var device = {
|
|
|
4843
5551
|
} else {
|
|
4844
5552
|
while (!state.triggerCompleted) {
|
|
4845
5553
|
if (state.cancelled) throw new Error("peach motion capture was cancelled");
|
|
4846
|
-
await new Promise((
|
|
5554
|
+
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
4847
5555
|
}
|
|
4848
5556
|
}
|
|
4849
5557
|
let visibleStart = null;
|
|
@@ -5162,13 +5870,13 @@ var device = {
|
|
|
5162
5870
|
state.ready = true;
|
|
5163
5871
|
while (state.anchorPerformanceMs === null || state.anchorWallMs === null) {
|
|
5164
5872
|
if (state.cancelled) throw new Error("peach timed capture was cancelled");
|
|
5165
|
-
await new Promise((
|
|
5873
|
+
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
5166
5874
|
}
|
|
5167
5875
|
const captureAnchorMs = state.anchorWallMs;
|
|
5168
5876
|
const captureAnchorPerformanceMs = state.anchorPerformanceMs;
|
|
5169
5877
|
const snaps = await Promise.all(
|
|
5170
5878
|
input.stages.map(
|
|
5171
|
-
(stage) => new Promise((
|
|
5879
|
+
(stage) => new Promise((resolve2) => {
|
|
5172
5880
|
const fire = async () => {
|
|
5173
5881
|
const actualMs = performance.now() - captureAnchorPerformanceMs;
|
|
5174
5882
|
const captureRequestedAtMs = Date.now();
|
|
@@ -5192,7 +5900,7 @@ var device = {
|
|
|
5192
5900
|
if (!dataUrl) {
|
|
5193
5901
|
dataUrl = await screenshot({ format: "png" });
|
|
5194
5902
|
}
|
|
5195
|
-
|
|
5903
|
+
resolve2({
|
|
5196
5904
|
label: stage.label,
|
|
5197
5905
|
offsetMs: stage.offsetMs,
|
|
5198
5906
|
actualMs,
|
|
@@ -5200,7 +5908,7 @@ var device = {
|
|
|
5200
5908
|
dataUrl
|
|
5201
5909
|
});
|
|
5202
5910
|
} catch {
|
|
5203
|
-
|
|
5911
|
+
resolve2({
|
|
5204
5912
|
label: stage.label,
|
|
5205
5913
|
offsetMs: stage.offsetMs,
|
|
5206
5914
|
actualMs,
|
|
@@ -5330,20 +6038,28 @@ var device = {
|
|
|
5330
6038
|
},
|
|
5331
6039
|
async shake() {
|
|
5332
6040
|
},
|
|
5333
|
-
//
|
|
5334
|
-
//
|
|
5335
|
-
// (AppleSimUtils/simctl location set) and CLLocationManager delivers the fix
|
|
5336
|
-
// asynchronously. here the platform is the harness browser, so grant page
|
|
5337
|
-
// geolocation and override the context fix; the guest location seam observes
|
|
5338
|
-
// it through navigator.geolocation exactly like the app observes Core
|
|
5339
|
-
// Location. app permission state is untouched, matching native.
|
|
6041
|
+
// native detox sets the simulator's location without changing app permissions.
|
|
6042
|
+
// target this page's device through the same location owner as peach location.
|
|
5340
6043
|
async setLocation(lat, lon) {
|
|
5341
6044
|
const page = getPage();
|
|
5342
|
-
const
|
|
5343
|
-
|
|
5344
|
-
|
|
6045
|
+
const simId = await page.evaluate(() => window.SootSim?.state.simId);
|
|
6046
|
+
if (!simId) throw new Error("peach location requires a registered harness sim");
|
|
6047
|
+
const port = resolveSootsimBridgePortForHttpPort({
|
|
6048
|
+
explicitPort: process.env.SOOTSIM_BRIDGE_PORT,
|
|
6049
|
+
httpPort: new URL(page.url()).port,
|
|
6050
|
+
baseHttpPort: 5173
|
|
5345
6051
|
});
|
|
5346
|
-
|
|
6052
|
+
const bridge = createBridge(port, { simId, simIdSource: "flag" });
|
|
6053
|
+
try {
|
|
6054
|
+
const result = await bridge.send({
|
|
6055
|
+
type: "location",
|
|
6056
|
+
location: { action: "set", latitude: lat, longitude: lon }
|
|
6057
|
+
});
|
|
6058
|
+
if (!result || typeof result !== "object" || Reflect.get(result, "ok") !== true)
|
|
6059
|
+
throw new Error(`peach location set failed: ${JSON.stringify(result)}`);
|
|
6060
|
+
} finally {
|
|
6061
|
+
bridge.close();
|
|
6062
|
+
}
|
|
5347
6063
|
},
|
|
5348
6064
|
async setStatusBar(config) {
|
|
5349
6065
|
await dispatchStatusBarOverride(config);
|