@swmansion/argent 0.16.2-next.1 → 0.16.2-next.11

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.
@@ -2235,8 +2235,8 @@ var require_resolve = __commonJS({
2235
2235
  }
2236
2236
  return count;
2237
2237
  }
2238
- function getFullPath(resolver, id = "", normalize) {
2239
- if (normalize !== false)
2238
+ function getFullPath(resolver, id = "", normalize2) {
2239
+ if (normalize2 !== false)
2240
2240
  id = normalizeId(id);
2241
2241
  const p = resolver.parse(id);
2242
2242
  return _getFullPath(resolver, p);
@@ -3632,7 +3632,7 @@ var require_fast_uri = __commonJS({
3632
3632
  "use strict";
3633
3633
  var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
3634
3634
  var { SCHEMES, getSchemeHandler } = require_schemes();
3635
- function normalize(uri, options) {
3635
+ function normalize2(uri, options) {
3636
3636
  if (typeof uri === "string") {
3637
3637
  uri = /** @type {T} */
3638
3638
  normalizeString(uri, options);
@@ -3899,7 +3899,7 @@ var require_fast_uri = __commonJS({
3899
3899
  }
3900
3900
  var fastUri = {
3901
3901
  SCHEMES,
3902
- normalize,
3902
+ normalize: normalize2,
3903
3903
  resolve: resolve5,
3904
3904
  resolveComponent,
3905
3905
  equal,
@@ -6891,7 +6891,7 @@ var require_dist = __commonJS({
6891
6891
 
6892
6892
  // ../argent-mcp/src/mcp-server.ts
6893
6893
  import { appendFile, mkdir as mkdir5 } from "node:fs/promises";
6894
- import { dirname as dirname5 } from "node:path";
6894
+ import { dirname as dirname6 } from "node:path";
6895
6895
  import { homedir as homedir5 } from "node:os";
6896
6896
 
6897
6897
  // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
@@ -16203,10 +16203,183 @@ async function applyClientFileDirectives(result) {
16203
16203
  }
16204
16204
 
16205
16205
  // ../argent-tools-client/src/artifacts.ts
16206
- import { mkdir as mkdir4, readFile as readFile4, rm as rm3, stat as stat2, writeFile as writeFile4 } from "node:fs/promises";
16206
+ import { copyFile, mkdir as mkdir4, readFile as readFile4, realpath, rm as rm3, stat as stat2, writeFile as writeFile4 } from "node:fs/promises";
16207
+ import { constants as fsConstants } from "node:fs";
16207
16208
  import { tmpdir as tmpdir2 } from "node:os";
16208
- import { basename as basename3, join as join5 } from "node:path";
16209
+ import { basename as basename3, dirname as dirname5, extname, isAbsolute as isAbsolute3, join as join8, normalize, sep as sep2 } from "node:path";
16209
16210
  import { createHash as createHash3 } from "node:crypto";
16211
+
16212
+ // ../configuration-core/src/flags.ts
16213
+ import * as fs2 from "node:fs";
16214
+ import * as path4 from "node:path";
16215
+ import { homedir as homedir3 } from "node:os";
16216
+ var PROJECT_MARKERS = [".argent", ".git", "package.json"];
16217
+ function findProjectRoot(startDir) {
16218
+ let current = path4.resolve(startDir);
16219
+ while (true) {
16220
+ for (const marker of PROJECT_MARKERS) {
16221
+ if (fs2.existsSync(path4.join(current, marker))) return current;
16222
+ }
16223
+ const parent = path4.dirname(current);
16224
+ if (parent === current) return null;
16225
+ current = parent;
16226
+ }
16227
+ }
16228
+ function resolveProjectRoot(startDir) {
16229
+ return findProjectRoot(startDir) ?? path4.resolve(startDir);
16230
+ }
16231
+ function getFlagsPath(scope, options = {}) {
16232
+ const home = options.homeDir ?? homedir3();
16233
+ if (scope === "global") {
16234
+ return path4.join(home, ".argent", "flags.json");
16235
+ }
16236
+ const cwd = options.cwd ?? process.cwd();
16237
+ return path4.join(resolveProjectRoot(cwd), ".argent", "flags.json");
16238
+ }
16239
+ function readFlagsFile(filePath) {
16240
+ let raw;
16241
+ try {
16242
+ raw = fs2.readFileSync(filePath, "utf8");
16243
+ } catch {
16244
+ return {};
16245
+ }
16246
+ let parsed;
16247
+ try {
16248
+ parsed = JSON.parse(raw);
16249
+ } catch {
16250
+ return {};
16251
+ }
16252
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
16253
+ const flags = parsed.flags;
16254
+ if (!flags || typeof flags !== "object" || Array.isArray(flags)) return {};
16255
+ const out = {};
16256
+ for (const [k, v] of Object.entries(flags)) {
16257
+ if (typeof v === "boolean") out[k] = v;
16258
+ }
16259
+ return out;
16260
+ }
16261
+ function readFlags(scope, options = {}) {
16262
+ return readFlagsFile(getFlagsPath(scope, options));
16263
+ }
16264
+ function isFlagEnabled(name, options = {}) {
16265
+ const projectFlags = readFlags("project", options);
16266
+ if (Object.hasOwn(projectFlags, name)) return projectFlags[name];
16267
+ const globalFlags = readFlags("global", options);
16268
+ if (Object.hasOwn(globalFlags, name)) return globalFlags[name];
16269
+ return options.default ?? false;
16270
+ }
16271
+
16272
+ // ../configuration-core/src/paths.ts
16273
+ import * as os from "node:os";
16274
+ import * as path5 from "node:path";
16275
+ function nonEmpty(value) {
16276
+ if (value == void 0) return null;
16277
+ const trimmed = value.trim();
16278
+ return trimmed === "" ? null : value;
16279
+ }
16280
+ function argentHomeDir() {
16281
+ const home = process.platform === "win32" ? nonEmpty(process.env.USERPROFILE) ?? os.homedir() : nonEmpty(process.env.HOME) ?? os.homedir();
16282
+ return path5.join(home, ".argent");
16283
+ }
16284
+ function configDir(scope = "global", options = {}) {
16285
+ if (scope === "global") {
16286
+ return options.homeDir ? path5.join(options.homeDir, ".argent") : argentHomeDir();
16287
+ }
16288
+ const cwd = options.cwd ?? process.cwd();
16289
+ return path5.join(resolveProjectRoot(cwd), ".argent");
16290
+ }
16291
+ function configFilePath(scope = "global", options = {}) {
16292
+ return path5.join(configDir(scope, options), "config.json");
16293
+ }
16294
+
16295
+ // ../configuration-core/src/config.ts
16296
+ import * as crypto from "node:crypto";
16297
+ import * as fs3 from "node:fs";
16298
+ import * as path6 from "node:path";
16299
+ function readConfigObject(scope = "global", options = {}) {
16300
+ try {
16301
+ const raw = fs3.readFileSync(configFilePath(scope, options), "utf8");
16302
+ const json = JSON.parse(raw);
16303
+ if (json && typeof json === "object" && !Array.isArray(json)) {
16304
+ return json;
16305
+ }
16306
+ } catch {
16307
+ }
16308
+ return {};
16309
+ }
16310
+ var LOCK_STALE_MS2 = 1e4;
16311
+ var LOCK_MAX_WAIT_MS = 2e3;
16312
+ var LOCK_RETRY_MS = 25;
16313
+ function sleepSync(ms) {
16314
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
16315
+ }
16316
+ function acquireConfigLock(finalPath) {
16317
+ const lockPath = finalPath + ".lock";
16318
+ const deadline = Date.now() + LOCK_MAX_WAIT_MS;
16319
+ for (; ; ) {
16320
+ try {
16321
+ const fd = fs3.openSync(lockPath, "wx", 384);
16322
+ try {
16323
+ fs3.writeSync(fd, `${process.pid}
16324
+ `);
16325
+ } catch {
16326
+ }
16327
+ return { fd, lockPath };
16328
+ } catch (err) {
16329
+ if (err.code !== "EEXIST") return null;
16330
+ try {
16331
+ if (Date.now() - fs3.statSync(lockPath).mtimeMs > LOCK_STALE_MS2) {
16332
+ fs3.unlinkSync(lockPath);
16333
+ continue;
16334
+ }
16335
+ } catch {
16336
+ }
16337
+ if (Date.now() >= deadline) return null;
16338
+ sleepSync(LOCK_RETRY_MS);
16339
+ }
16340
+ }
16341
+ }
16342
+ function releaseConfigLock(lock) {
16343
+ try {
16344
+ fs3.closeSync(lock.fd);
16345
+ } catch {
16346
+ }
16347
+ try {
16348
+ fs3.unlinkSync(lock.lockPath);
16349
+ } catch {
16350
+ }
16351
+ }
16352
+ function updateConfig(mutate, scope = "global", options = {}) {
16353
+ const dir = configDir(scope, options);
16354
+ fs3.mkdirSync(dir, { recursive: true });
16355
+ const finalPath = configFilePath(scope, options);
16356
+ const lock = acquireConfigLock(finalPath);
16357
+ try {
16358
+ const next = readConfigObject(scope, options);
16359
+ mutate(next);
16360
+ const tmpPath = path6.join(dir, `.config.tmp.${process.pid}.${crypto.randomUUID()}`);
16361
+ const fd = fs3.openSync(tmpPath, "wx", 384);
16362
+ try {
16363
+ fs3.writeSync(fd, JSON.stringify(next, null, 2) + "\n");
16364
+ fs3.fsyncSync(fd);
16365
+ } finally {
16366
+ fs3.closeSync(fd);
16367
+ }
16368
+ try {
16369
+ fs3.renameSync(tmpPath, finalPath);
16370
+ } catch (err) {
16371
+ try {
16372
+ fs3.unlinkSync(tmpPath);
16373
+ } catch {
16374
+ }
16375
+ throw err;
16376
+ }
16377
+ } finally {
16378
+ if (lock) releaseConfigLock(lock);
16379
+ }
16380
+ }
16381
+
16382
+ // ../argent-tools-client/src/artifacts.ts
16210
16383
  var ARTIFACT_MARKER = "__argentArtifact";
16211
16384
  function isArtifactHandle(value) {
16212
16385
  return !!value && typeof value === "object" && value[ARTIFACT_MARKER] === true && typeof value.id === "string" && typeof value.filename === "string";
@@ -16229,12 +16402,79 @@ function projectSlug() {
16229
16402
  return `${name}-${hash}`;
16230
16403
  }
16231
16404
  function artifactsRoot() {
16232
- return process.env.ARGENT_ARTIFACTS_DIR ?? join5(tmpdir2(), "argent-artifacts");
16405
+ return process.env.ARGENT_ARTIFACTS_DIR ?? join8(tmpdir2(), "argent-artifacts");
16233
16406
  }
16234
16407
  function artifactDir(deviceId) {
16235
16408
  const parts = [artifactsRoot(), projectSlug(), sessionId()];
16236
16409
  if (deviceId) parts.push(sanitizeSegment(deviceId));
16237
- return join5(...parts);
16410
+ return join8(...parts);
16411
+ }
16412
+ function durableBaseDir() {
16413
+ const projectRoot = findProjectRoot(process.cwd());
16414
+ return projectRoot ?? dirname5(argentHomeDir());
16415
+ }
16416
+ var ALLOWED_SAVE_DIRS = /* @__PURE__ */ new Set([normalize(".argent/recordings")]);
16417
+ var MAX_DURABLE_BYTES = 2 * 1024 * 1024 * 1024;
16418
+ async function readCapped(res, cap) {
16419
+ const headers = res.headers;
16420
+ const declared = Number(headers?.get?.("content-length"));
16421
+ if (Number.isFinite(declared) && declared > cap) return null;
16422
+ const body = res.body;
16423
+ if (!body?.getReader) {
16424
+ const buf = Buffer.from(await res.arrayBuffer());
16425
+ return buf.length > cap ? null : buf;
16426
+ }
16427
+ const reader = body.getReader();
16428
+ const chunks = [];
16429
+ let total = 0;
16430
+ for (; ; ) {
16431
+ const { done, value } = await reader.read();
16432
+ if (done) break;
16433
+ total += value.byteLength;
16434
+ if (total > cap) {
16435
+ await reader.cancel().catch(() => {
16436
+ });
16437
+ return null;
16438
+ }
16439
+ chunks.push(Buffer.from(value));
16440
+ }
16441
+ return Buffer.concat(chunks);
16442
+ }
16443
+ async function writeDurableUnique(dir, filename, write) {
16444
+ const ext = extname(filename);
16445
+ const stem = filename.slice(0, filename.length - ext.length);
16446
+ for (let i = 1; i <= 1e3; i++) {
16447
+ const candidate = i === 1 ? filename : `${stem} (${i})${ext}`;
16448
+ const path11 = join8(dir, candidate);
16449
+ try {
16450
+ await write(path11);
16451
+ return path11;
16452
+ } catch (err) {
16453
+ if (err?.code === "EEXIST") continue;
16454
+ throw err;
16455
+ }
16456
+ }
16457
+ return null;
16458
+ }
16459
+ function durableSaveTarget(handle) {
16460
+ if (typeof handle.saveDir !== "string" || !handle.saveDir || handle.archive) return null;
16461
+ const rel = normalize(handle.saveDir);
16462
+ if (isAbsolute3(rel) || rel === ".." || rel.startsWith(`..${sep2}`) || rel.split(sep2).includes("..")) {
16463
+ return null;
16464
+ }
16465
+ if (!ALLOWED_SAVE_DIRS.has(rel)) return null;
16466
+ const base = durableBaseDir();
16467
+ const dir = join8(base, rel);
16468
+ return { dir, path: join8(dir, sanitizeSegment(handle.filename)), base, rel };
16469
+ }
16470
+ async function confineToRealBase(dir, base, rel) {
16471
+ try {
16472
+ const realDir = await realpath(dir);
16473
+ const realBase = await realpath(base);
16474
+ return realDir === join8(realBase, rel);
16475
+ } catch {
16476
+ return false;
16477
+ }
16238
16478
  }
16239
16479
  async function resolveLocalFile(handle) {
16240
16480
  if (!handle.hostPath) return null;
@@ -16254,7 +16494,7 @@ async function resolveLocalFile(handle) {
16254
16494
  }
16255
16495
  }
16256
16496
  async function downloadAndExtractArchive(handle, data, dir) {
16257
- const tarball2 = join5(dir, `${sanitizeSegment(handle.filename)}.tar.gz`);
16497
+ const tarball2 = join8(dir, `${sanitizeSegment(handle.filename)}.tar.gz`);
16258
16498
  try {
16259
16499
  await writeFile4(tarball2, data);
16260
16500
  return await safeExtractTarGz(tarball2, dir, handle.filename);
@@ -16280,6 +16520,53 @@ async function materializeArtifacts(result, ctx) {
16280
16520
  async function walk(value) {
16281
16521
  if (isArtifactHandle(value)) {
16282
16522
  const localPath = await resolveLocalFile(value);
16523
+ const saveTarget = durableSaveTarget(value);
16524
+ if (saveTarget) {
16525
+ const filename = basename3(saveTarget.path);
16526
+ try {
16527
+ await mkdir4(saveTarget.dir, { recursive: true });
16528
+ if (!await confineToRealBase(saveTarget.dir, saveTarget.base, saveTarget.rel)) {
16529
+ return null;
16530
+ }
16531
+ if (localPath) {
16532
+ const finalPath2 = await writeDurableUnique(
16533
+ saveTarget.dir,
16534
+ filename,
16535
+ (p) => copyFile(localPath, p, fsConstants.COPYFILE_EXCL)
16536
+ );
16537
+ if (!finalPath2) return null;
16538
+ if (value.mimeType.startsWith("image/")) {
16539
+ images.push({
16540
+ localPath: finalPath2,
16541
+ data: await readFile4(finalPath2),
16542
+ mimeType: value.mimeType
16543
+ });
16544
+ }
16545
+ return finalPath2;
16546
+ }
16547
+ if (!Number.isInteger(value.size) || value.size <= 0 || value.size > MAX_DURABLE_BYTES) {
16548
+ return null;
16549
+ }
16550
+ const res = await fetchFn(`${ctx.toolsUrl}/artifacts/${value.id}`, {
16551
+ headers: authHeaders2
16552
+ });
16553
+ if (!res.ok) return null;
16554
+ const data = await readCapped(res, value.size);
16555
+ if (!data || data.length !== value.size) return null;
16556
+ const finalPath = await writeDurableUnique(
16557
+ saveTarget.dir,
16558
+ filename,
16559
+ (p) => writeFile4(p, data, { flag: "wx" })
16560
+ );
16561
+ if (!finalPath) return null;
16562
+ if (value.mimeType.startsWith("image/")) {
16563
+ images.push({ localPath: finalPath, data, mimeType: value.mimeType });
16564
+ }
16565
+ return finalPath;
16566
+ } catch {
16567
+ return null;
16568
+ }
16569
+ }
16283
16570
  if (localPath) {
16284
16571
  if (value.mimeType.startsWith("image/")) {
16285
16572
  images.push({ localPath, data: await readFile4(localPath), mimeType: value.mimeType });
@@ -16297,7 +16584,7 @@ async function materializeArtifacts(result, ctx) {
16297
16584
  return await downloadAndExtractArchive(value, data, dir);
16298
16585
  }
16299
16586
  if (value.size > 0 && data.length !== value.size) return null;
16300
- const downloadedPath = join5(dir, sanitizeSegment(value.filename));
16587
+ const downloadedPath = join8(dir, sanitizeSegment(value.filename));
16301
16588
  await writeFile4(downloadedPath, data);
16302
16589
  if (value.mimeType.startsWith("image/")) {
16303
16590
  images.push({ localPath: downloadedPath, data, mimeType: value.mimeType });
@@ -17546,8 +17833,8 @@ var PostHogSentryIntegration = class {
17546
17833
 
17547
17834
  // ../registry/src/artifacts.ts
17548
17835
  import { stat as stat3 } from "node:fs/promises";
17549
- import { randomUUID as randomUUID2 } from "node:crypto";
17550
- import { basename as basename4, extname } from "node:path";
17836
+ import { randomUUID as randomUUID3 } from "node:crypto";
17837
+ import { basename as basename4, extname as extname2 } from "node:path";
17551
17838
 
17552
17839
  // ../registry/src/failure-codes.ts
17553
17840
  var FAILURE_CODES = {
@@ -17732,6 +18019,21 @@ var FAILURE_CODES = {
17732
18019
  NATIVE_PROFILER_PERFETTO_PROCESS_ERROR: "NATIVE_PROFILER_PERFETTO_PROCESS_ERROR",
17733
18020
  NATIVE_PROFILER_PERFETTO_READY_TIMEOUT: "NATIVE_PROFILER_PERFETTO_READY_TIMEOUT",
17734
18021
  NATIVE_PROFILER_PERFETTO_READY_EXITED: "NATIVE_PROFILER_PERFETTO_READY_EXITED",
18022
+ // screen-recording-start / screen-recording-stop. One capture path for every
18023
+ // platform (simulator-server's frame stream into ffmpeg), so the stages name
18024
+ // the step that failed rather than the device family.
18025
+ SCREEN_RECORDING_FACTORY_OPTIONS_MISSING: "SCREEN_RECORDING_FACTORY_OPTIONS_MISSING",
18026
+ SCREEN_RECORDING_WRONG_PLATFORM: "SCREEN_RECORDING_WRONG_PLATFORM",
18027
+ SCREEN_RECORDING_ALREADY_ACTIVE: "SCREEN_RECORDING_ALREADY_ACTIVE",
18028
+ SCREEN_RECORDING_NO_ACTIVE_SESSION: "SCREEN_RECORDING_NO_ACTIVE_SESSION",
18029
+ SCREEN_RECORDING_STOP_IN_PROGRESS: "SCREEN_RECORDING_STOP_IN_PROGRESS",
18030
+ SCREEN_RECORDING_START_EXITED: "SCREEN_RECORDING_START_EXITED",
18031
+ SCREEN_RECORDING_START_TIMEOUT: "SCREEN_RECORDING_START_TIMEOUT",
18032
+ SCREEN_RECORDING_PROCESS_ERROR: "SCREEN_RECORDING_PROCESS_ERROR",
18033
+ SCREEN_RECORDING_OUTPUT_MISSING: "SCREEN_RECORDING_OUTPUT_MISSING",
18034
+ SCREEN_RECORDING_SERVER_SHUTTING_DOWN: "SCREEN_RECORDING_SERVER_SHUTTING_DOWN",
18035
+ SCREEN_RECORDING_STREAM_UNAVAILABLE: "SCREEN_RECORDING_STREAM_UNAVAILABLE",
18036
+ SCREEN_RECORDING_FFMPEG_NOT_FOUND: "SCREEN_RECORDING_FFMPEG_NOT_FOUND",
17735
18037
  FLOW_PROJECT_ROOT_REQUIRED: "FLOW_PROJECT_ROOT_REQUIRED",
17736
18038
  FLOW_PROJECT_ROOT_INVALID: "FLOW_PROJECT_ROOT_INVALID",
17737
18039
  FLOW_NAME_INVALID: "FLOW_NAME_INVALID",
@@ -17803,6 +18105,7 @@ var FAILURE_COMMANDS = [
17803
18105
  "android_devtools",
17804
18106
  "ax_service",
17805
18107
  "simulator_server",
18108
+ "ffmpeg",
17806
18109
  "cdp",
17807
18110
  "electron",
17808
18111
  "npm",
@@ -17835,7 +18138,7 @@ var FAILURE_SIGNAL_NAME_SET = new Set(FAILURE_SIGNAL_NAMES);
17835
18138
  var FAILURE_SPAWN_CODE_SET = new Set(FAILURE_SPAWN_CODES);
17836
18139
 
17837
18140
  // ../registry/src/registry.ts
17838
- import { randomUUID as randomUUID3 } from "node:crypto";
18141
+ import { randomUUID as randomUUID4 } from "node:crypto";
17839
18142
 
17840
18143
  // ../telemetry/src/events.ts
17841
18144
  var PLATFORMS = [
@@ -18067,7 +18370,7 @@ var ALLOWED = {
18067
18370
  },
18068
18371
  "toolserver:start": {},
18069
18372
  "toolserver:stop": {
18070
- reason: oneOf(["idle", "signal", "crash"]),
18373
+ reason: oneOf(["idle", "signal", "crash", "deferred"]),
18071
18374
  uptime_ms: DURATION_MS,
18072
18375
  total_tool_calls: COUNT,
18073
18376
  ...FAILURE_SIGNAL,
@@ -18112,10 +18415,10 @@ var ALLOWED = {
18112
18415
  };
18113
18416
 
18114
18417
  // ../telemetry/src/base-props.ts
18115
- import { randomUUID as randomUUID4 } from "node:crypto";
18418
+ import { randomUUID as randomUUID5 } from "node:crypto";
18116
18419
 
18117
18420
  // ../telemetry/src/cloud-agent-detect.ts
18118
- import { existsSync as existsSync2 } from "node:fs";
18421
+ import { existsSync as existsSync3 } from "node:fs";
18119
18422
 
18120
18423
  // ../../node_modules/ci-info/vendors.json
18121
18424
  var vendors_default = [
@@ -18486,7 +18789,7 @@ var vendors_default = [
18486
18789
  var _CI_VENDOR_COUNT_FOR_TEST = vendors_default.length;
18487
18790
 
18488
18791
  // ../telemetry/src/base-props.ts
18489
- var SESSION_ID2 = randomUUID4();
18792
+ var SESSION_ID2 = randomUUID5();
18490
18793
 
18491
18794
  // ../telemetry/src/identity.ts
18492
18795
  import * as crypto2 from "node:crypto";
@@ -18496,176 +18799,6 @@ import * as path8 from "node:path";
18496
18799
  // ../telemetry/src/paths.ts
18497
18800
  import * as path7 from "node:path";
18498
18801
 
18499
- // ../configuration-core/src/flags.ts
18500
- import * as fs2 from "node:fs";
18501
- import * as path4 from "node:path";
18502
- import { homedir as homedir3 } from "node:os";
18503
- var PROJECT_MARKERS = [".argent", ".git", "package.json"];
18504
- function findProjectRoot(startDir) {
18505
- let current = path4.resolve(startDir);
18506
- while (true) {
18507
- for (const marker of PROJECT_MARKERS) {
18508
- if (fs2.existsSync(path4.join(current, marker))) return current;
18509
- }
18510
- const parent = path4.dirname(current);
18511
- if (parent === current) return null;
18512
- current = parent;
18513
- }
18514
- }
18515
- function resolveProjectRoot(startDir) {
18516
- return findProjectRoot(startDir) ?? path4.resolve(startDir);
18517
- }
18518
- function getFlagsPath(scope, options = {}) {
18519
- const home = options.homeDir ?? homedir3();
18520
- if (scope === "global") {
18521
- return path4.join(home, ".argent", "flags.json");
18522
- }
18523
- const cwd = options.cwd ?? process.cwd();
18524
- return path4.join(resolveProjectRoot(cwd), ".argent", "flags.json");
18525
- }
18526
- function readFlagsFile(filePath) {
18527
- let raw;
18528
- try {
18529
- raw = fs2.readFileSync(filePath, "utf8");
18530
- } catch {
18531
- return {};
18532
- }
18533
- let parsed;
18534
- try {
18535
- parsed = JSON.parse(raw);
18536
- } catch {
18537
- return {};
18538
- }
18539
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
18540
- const flags = parsed.flags;
18541
- if (!flags || typeof flags !== "object" || Array.isArray(flags)) return {};
18542
- const out = {};
18543
- for (const [k, v] of Object.entries(flags)) {
18544
- if (typeof v === "boolean") out[k] = v;
18545
- }
18546
- return out;
18547
- }
18548
- function readFlags(scope, options = {}) {
18549
- return readFlagsFile(getFlagsPath(scope, options));
18550
- }
18551
- function isFlagEnabled(name, options = {}) {
18552
- const projectFlags = readFlags("project", options);
18553
- if (Object.hasOwn(projectFlags, name)) return projectFlags[name];
18554
- const globalFlags = readFlags("global", options);
18555
- if (Object.hasOwn(globalFlags, name)) return globalFlags[name];
18556
- return false;
18557
- }
18558
-
18559
- // ../configuration-core/src/paths.ts
18560
- import * as os from "node:os";
18561
- import * as path5 from "node:path";
18562
- function nonEmpty(value) {
18563
- if (value == void 0) return null;
18564
- const trimmed = value.trim();
18565
- return trimmed === "" ? null : value;
18566
- }
18567
- function argentHomeDir() {
18568
- const home = process.platform === "win32" ? nonEmpty(process.env.USERPROFILE) ?? os.homedir() : nonEmpty(process.env.HOME) ?? os.homedir();
18569
- return path5.join(home, ".argent");
18570
- }
18571
- function configDir(scope = "global", options = {}) {
18572
- if (scope === "global") {
18573
- return options.homeDir ? path5.join(options.homeDir, ".argent") : argentHomeDir();
18574
- }
18575
- const cwd = options.cwd ?? process.cwd();
18576
- return path5.join(resolveProjectRoot(cwd), ".argent");
18577
- }
18578
- function configFilePath(scope = "global", options = {}) {
18579
- return path5.join(configDir(scope, options), "config.json");
18580
- }
18581
-
18582
- // ../configuration-core/src/config.ts
18583
- import * as crypto from "node:crypto";
18584
- import * as fs3 from "node:fs";
18585
- import * as path6 from "node:path";
18586
- function readConfigObject(scope = "global", options = {}) {
18587
- try {
18588
- const raw = fs3.readFileSync(configFilePath(scope, options), "utf8");
18589
- const json = JSON.parse(raw);
18590
- if (json && typeof json === "object" && !Array.isArray(json)) {
18591
- return json;
18592
- }
18593
- } catch {
18594
- }
18595
- return {};
18596
- }
18597
- var LOCK_STALE_MS2 = 1e4;
18598
- var LOCK_MAX_WAIT_MS = 2e3;
18599
- var LOCK_RETRY_MS = 25;
18600
- function sleepSync(ms) {
18601
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
18602
- }
18603
- function acquireConfigLock(finalPath) {
18604
- const lockPath = finalPath + ".lock";
18605
- const deadline = Date.now() + LOCK_MAX_WAIT_MS;
18606
- for (; ; ) {
18607
- try {
18608
- const fd = fs3.openSync(lockPath, "wx", 384);
18609
- try {
18610
- fs3.writeSync(fd, `${process.pid}
18611
- `);
18612
- } catch {
18613
- }
18614
- return { fd, lockPath };
18615
- } catch (err) {
18616
- if (err.code !== "EEXIST") return null;
18617
- try {
18618
- if (Date.now() - fs3.statSync(lockPath).mtimeMs > LOCK_STALE_MS2) {
18619
- fs3.unlinkSync(lockPath);
18620
- continue;
18621
- }
18622
- } catch {
18623
- }
18624
- if (Date.now() >= deadline) return null;
18625
- sleepSync(LOCK_RETRY_MS);
18626
- }
18627
- }
18628
- }
18629
- function releaseConfigLock(lock) {
18630
- try {
18631
- fs3.closeSync(lock.fd);
18632
- } catch {
18633
- }
18634
- try {
18635
- fs3.unlinkSync(lock.lockPath);
18636
- } catch {
18637
- }
18638
- }
18639
- function updateConfig(mutate, scope = "global", options = {}) {
18640
- const dir = configDir(scope, options);
18641
- fs3.mkdirSync(dir, { recursive: true });
18642
- const finalPath = configFilePath(scope, options);
18643
- const lock = acquireConfigLock(finalPath);
18644
- try {
18645
- const next = readConfigObject(scope, options);
18646
- mutate(next);
18647
- const tmpPath = path6.join(dir, `.config.tmp.${process.pid}.${crypto.randomUUID()}`);
18648
- const fd = fs3.openSync(tmpPath, "wx", 384);
18649
- try {
18650
- fs3.writeSync(fd, JSON.stringify(next, null, 2) + "\n");
18651
- fs3.fsyncSync(fd);
18652
- } finally {
18653
- fs3.closeSync(fd);
18654
- }
18655
- try {
18656
- fs3.renameSync(tmpPath, finalPath);
18657
- } catch (err) {
18658
- try {
18659
- fs3.unlinkSync(tmpPath);
18660
- } catch {
18661
- }
18662
- throw err;
18663
- }
18664
- } finally {
18665
- if (lock) releaseConfigLock(lock);
18666
- }
18667
- }
18668
-
18669
18802
  // ../telemetry/src/fingerprint.ts
18670
18803
  import { execFileSync as execFileSync2, spawn as spawn2 } from "node:child_process";
18671
18804
 
@@ -19158,7 +19291,7 @@ async function startMcpServer(options) {
19158
19291
  async function spyLog(entry) {
19159
19292
  try {
19160
19293
  if (!logDirReady) {
19161
- await mkdir5(dirname5(LOG_FILE2), { recursive: true });
19294
+ await mkdir5(dirname6(LOG_FILE2), { recursive: true });
19162
19295
  logDirReady = true;
19163
19296
  }
19164
19297
  await appendFile(LOG_FILE2, JSON.stringify(entry) + "\n");