@debugbundle/cli 1.19.2 → 1.19.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/dist/main.cjs +440 -266
  3. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -18198,7 +18198,7 @@ var require_snapshot_recorder = __commonJS({
18198
18198
  "../../node_modules/.pnpm/undici@8.12.3/node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
18199
18199
  "use strict";
18200
18200
  var { writeFile, readFile, mkdir: mkdir5 } = require("node:fs/promises");
18201
- var { dirname: dirname9, resolve: resolve5 } = require("node:path");
18201
+ var { dirname: dirname10, resolve: resolve5 } = require("node:path");
18202
18202
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = require("node:timers");
18203
18203
  var { InvalidArgumentError, UndiciError } = require_errors();
18204
18204
  var { setHeader } = require_util();
@@ -18445,7 +18445,7 @@ var require_snapshot_recorder = __commonJS({
18445
18445
  throw new InvalidArgumentError("Snapshot path is required");
18446
18446
  }
18447
18447
  const resolvedPath = resolve5(path);
18448
- await mkdir5(dirname9(resolvedPath), { recursive: true });
18448
+ await mkdir5(dirname10(resolvedPath), { recursive: true });
18449
18449
  const data = Array.from(this.#snapshots.entries()).map(([hash3, snapshot]) => ({
18450
18450
  hash: hash3,
18451
18451
  snapshot
@@ -54914,6 +54914,15 @@ var RetrievalApiError = class extends Error {
54914
54914
  this.code = code;
54915
54915
  }
54916
54916
  };
54917
+ var ResourceIdSchema = external_exports.string().max(255).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/);
54918
+ function parseResourceId(value, code) {
54919
+ const parsed = ResourceIdSchema.safeParse(value);
54920
+ if (!parsed.success) throw new RetrievalApiError(400, code);
54921
+ return parsed.data;
54922
+ }
54923
+ function parseIncidentId(value) {
54924
+ return parseResourceId(value, "invalid_incident_id");
54925
+ }
54917
54926
  function parseApiError(status, body) {
54918
54927
  const parsed = ApiErrorResponseSchema.safeParse(body);
54919
54928
  if (!parsed.success) {
@@ -55017,7 +55026,7 @@ function createRetrievalApi(client) {
55017
55026
  const parsed = await expectParsed(
55018
55027
  client.request({
55019
55028
  method: "GET",
55020
- path: `/v1/incidents/${input3.incidentId}`,
55029
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}`,
55021
55030
  bearerToken: input3.bearerToken
55022
55031
  }),
55023
55032
  IncidentResponseSchema
@@ -55028,7 +55037,7 @@ function createRetrievalApi(client) {
55028
55037
  const parsed = await expectParsed(
55029
55038
  client.request({
55030
55039
  method: "GET",
55031
- path: `/v1/incidents/${input3.incidentId}/context`,
55040
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/context`,
55032
55041
  bearerToken: input3.bearerToken
55033
55042
  }),
55034
55043
  IncidentContextSchema
@@ -55039,7 +55048,7 @@ function createRetrievalApi(client) {
55039
55048
  const parsed = await expectMutation(
55040
55049
  client.request({
55041
55050
  method: "POST",
55042
- path: `/v1/incidents/${input3.incidentId}/resolve`,
55051
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/resolve`,
55043
55052
  bearerToken: input3.bearerToken
55044
55053
  }),
55045
55054
  IncidentResponseSchema
@@ -55064,7 +55073,7 @@ function createRetrievalApi(client) {
55064
55073
  const parsed = await expectMutation(
55065
55074
  client.request({
55066
55075
  method: "POST",
55067
- path: `/v1/incidents/${input3.incidentId}/reopen`,
55076
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/reopen`,
55068
55077
  bearerToken: input3.bearerToken
55069
55078
  }),
55070
55079
  IncidentResponseSchema
@@ -55089,7 +55098,7 @@ function createRetrievalApi(client) {
55089
55098
  const bundle = await expectParsed(
55090
55099
  client.request({
55091
55100
  method: "GET",
55092
- path: `/v1/incidents/${input3.incidentId}/bundle`,
55101
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/bundle`,
55093
55102
  bearerToken: input3.bearerToken
55094
55103
  }),
55095
55104
  BundleResponseSchema
@@ -55124,7 +55133,7 @@ function createRetrievalApi(client) {
55124
55133
  const reproduction = await expectParsed(
55125
55134
  client.request({
55126
55135
  method: "GET",
55127
- path: `/v1/incidents/${input3.incidentId}/reproduction`,
55136
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/reproduction`,
55128
55137
  bearerToken: input3.bearerToken
55129
55138
  }),
55130
55139
  ReproductionResponseSchema
@@ -55189,7 +55198,7 @@ function createRetrievalApi(client) {
55189
55198
  const parsed = await expectParsed(
55190
55199
  client.request({
55191
55200
  method: "GET",
55192
- path: `/v1/improvements/${input3.improvementId}`,
55201
+ path: `/v1/improvements/${encodeURIComponent(parseResourceId(input3.improvementId, "invalid_improvement_id"))}`,
55193
55202
  bearerToken: input3.bearerToken
55194
55203
  }),
55195
55204
  ImprovementResponseSchema
@@ -55200,7 +55209,7 @@ function createRetrievalApi(client) {
55200
55209
  const parsed = await expectMutation(
55201
55210
  client.request({
55202
55211
  method: "POST",
55203
- path: `/v1/improvements/${input3.improvementId}/resolve`,
55212
+ path: `/v1/improvements/${encodeURIComponent(parseResourceId(input3.improvementId, "invalid_improvement_id"))}/resolve`,
55204
55213
  bearerToken: input3.bearerToken
55205
55214
  }),
55206
55215
  ImprovementResponseSchema
@@ -55211,7 +55220,7 @@ function createRetrievalApi(client) {
55211
55220
  const parsed = await expectMutation(
55212
55221
  client.request({
55213
55222
  method: "POST",
55214
- path: `/v1/improvements/${input3.improvementId}/reopen`,
55223
+ path: `/v1/improvements/${encodeURIComponent(parseResourceId(input3.improvementId, "invalid_improvement_id"))}/reopen`,
55215
55224
  bearerToken: input3.bearerToken
55216
55225
  }),
55217
55226
  ImprovementResponseSchema
@@ -55222,7 +55231,7 @@ function createRetrievalApi(client) {
55222
55231
  const parsed = await expectMutation(
55223
55232
  client.request({
55224
55233
  method: "POST",
55225
- path: `/v1/improvements/${input3.improvementId}/snooze`,
55234
+ path: `/v1/improvements/${encodeURIComponent(parseResourceId(input3.improvementId, "invalid_improvement_id"))}/snooze`,
55226
55235
  bearerToken: input3.bearerToken,
55227
55236
  body: { snoozed_until: input3.snoozedUntil }
55228
55237
  }),
@@ -55234,7 +55243,7 @@ function createRetrievalApi(client) {
55234
55243
  return await expectParsed(
55235
55244
  client.request({
55236
55245
  method: "GET",
55237
- path: `/v1/projects/${input3.projectId}/improvements/${input3.improvementId}/bundle`,
55246
+ path: `/v1/projects/${encodeURIComponent(parseResourceId(input3.projectId, "invalid_project_id"))}/improvements/${encodeURIComponent(parseResourceId(input3.improvementId, "invalid_improvement_id"))}/bundle`,
55238
55247
  bearerToken: input3.bearerToken
55239
55248
  }),
55240
55249
  external_exports.union([
@@ -57672,11 +57681,11 @@ async function safePath(root, file2, allowLeafLink = false) {
57672
57681
  }
57673
57682
  return target;
57674
57683
  }
57675
- async function readManaged(root, file2) {
57684
+ async function readManaged(root, file2, maxBytes = 1024 * 1024) {
57676
57685
  const path = await safePath(root, file2);
57677
57686
  try {
57678
57687
  const initial = await (0, import_promises2.lstat)(path);
57679
- if (!initial.isFile() || initial.size > 1024 * 1024)
57688
+ if (!initial.isFile() || initial.size > maxBytes)
57680
57689
  throw new Error(`Invalid or oversized managed file: ${file2}`);
57681
57690
  const handle = await (0, import_promises2.open)(
57682
57691
  path,
@@ -57684,16 +57693,17 @@ async function readManaged(root, file2) {
57684
57693
  );
57685
57694
  try {
57686
57695
  const info = await handle.stat();
57687
- if (!info.isFile() || info.size > 1024 * 1024)
57696
+ if (!info.isFile() || info.size > maxBytes)
57688
57697
  throw new Error(`Invalid or oversized managed file: ${file2}`);
57689
- const buffer = Buffer.alloc(1024 * 1024 + 1);
57698
+ const limit = Math.min(maxBytes, info.size);
57699
+ const buffer = Buffer.alloc(limit + 1);
57690
57700
  let total = 0;
57691
57701
  while (total < buffer.length) {
57692
57702
  const { bytesRead } = await handle.read(buffer, total, buffer.length - total, total);
57693
57703
  if (bytesRead === 0) break;
57694
57704
  total += bytesRead;
57695
57705
  }
57696
- if (total > 1024 * 1024) throw new Error(`Oversized managed file: ${file2}`);
57706
+ if (total > limit) throw new Error(`Oversized or growing managed file: ${file2}`);
57697
57707
  try {
57698
57708
  return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
57699
57709
  buffer.subarray(0, total)
@@ -57709,7 +57719,7 @@ async function readManaged(root, file2) {
57709
57719
  throw error62;
57710
57720
  }
57711
57721
  }
57712
- async function writeManaged(root, file2, value, expected) {
57722
+ async function writeManaged(root, file2, value, expected, maxBytes = 1024 * 1024) {
57713
57723
  const path = await safePath(root, file2);
57714
57724
  await (0, import_promises2.mkdir)((0, import_node_path2.dirname)(path), { recursive: true });
57715
57725
  await safePath(root, file2);
@@ -57727,7 +57737,7 @@ async function writeManaged(root, file2, value, expected) {
57727
57737
  await handle.writeFile(value, "utf8");
57728
57738
  if (previousMode !== void 0) await handle.chmod(previousMode);
57729
57739
  await handle.close();
57730
- if (await readManaged(root, file2) !== expected)
57740
+ if (await readManaged(root, file2, maxBytes) !== expected)
57731
57741
  throw new Error(`File changed during setup: ${file2}`);
57732
57742
  await safePath(root, file2);
57733
57743
  await (0, import_promises2.rename)(temporary, path);
@@ -61939,23 +61949,57 @@ async function agentReadCommand(input3, dependencies = {}) {
61939
61949
  }
61940
61950
 
61941
61951
  // src/clean-command.ts
61942
- var import_promises11 = require("node:fs/promises");
61952
+ var import_promises10 = require("node:fs/promises");
61943
61953
  var import_node_path12 = require("node:path");
61944
61954
 
61945
- // src/cli-fs-helpers.ts
61955
+ // src/local-artifact-paths.ts
61946
61956
  var import_node_path9 = require("node:path");
61957
+ var paths = {
61958
+ bundle: external_exports.string().regex(/^\.debugbundle\/bundles\/local\/[A-Za-z0-9][A-Za-z0-9._-]*\.bundle\.json$/),
61959
+ reproduction: external_exports.string().regex(
61960
+ /^\.debugbundle\/bundles\/local\/reproductions\/[A-Za-z0-9][A-Za-z0-9._-]*\.reproduction\.json$/
61961
+ )
61962
+ };
61963
+ function validateLocalArtifactPath(value, kind) {
61964
+ const result = paths[kind].safeParse(value);
61965
+ if (!result.success) throw new RetrievalApiError(400, "invalid_local_artifact_path");
61966
+ return result.data;
61967
+ }
61968
+ async function resolveLocalArtifactPath(root, value, kind) {
61969
+ const path = validateLocalArtifactPath(value, kind);
61970
+ try {
61971
+ return await safePath(root, path);
61972
+ } catch {
61973
+ throw new RetrievalApiError(400, "invalid_local_artifact_path");
61974
+ }
61975
+ }
61976
+ var LOCAL_FILE_LIMIT = 2 ** 31 - 1;
61977
+ async function readWorkspaceFile(root, path, reader, maxBytes = LOCAL_FILE_LIMIT) {
61978
+ const file2 = (0, import_node_path9.relative)(root, path);
61979
+ await safePath(root, file2);
61980
+ const raw = reader ? await reader(path) : await readManaged(root, file2, maxBytes);
61981
+ if (raw === void 0)
61982
+ throw Object.assign(new Error("Local file not found."), { code: "ENOENT" });
61983
+ if (Buffer.byteLength(raw, "utf8") > maxBytes) throw new Error("Oversized local file.");
61984
+ return raw;
61985
+ }
61986
+ async function writeWorkspaceFile(root, path, contents, writer) {
61987
+ const file2 = (0, import_node_path9.relative)(root, path);
61988
+ await safePath(root, file2);
61989
+ if (writer) return writer(path, contents);
61990
+ const previous = await readManaged(root, file2, LOCAL_FILE_LIMIT);
61991
+ await writeManaged(root, file2, contents, previous, LOCAL_FILE_LIMIT);
61992
+ }
61993
+
61994
+ // src/cli-fs-helpers.ts
61947
61995
  function isRecord2(value) {
61948
61996
  return typeof value === "object" && value !== null;
61949
61997
  }
61950
61998
  function isMissingPathError(error62) {
61951
61999
  return typeof error62 === "object" && error62 !== null && "code" in error62 && error62.code === "ENOENT";
61952
62000
  }
61953
- function resolveWorkspacePath(rootDirectory, targetPath) {
61954
- return (0, import_node_path9.isAbsolute)(targetPath) ? targetPath : (0, import_node_path9.join)(rootDirectory, targetPath);
61955
- }
61956
62001
 
61957
62002
  // src/local-retrieval-store.ts
61958
- var import_promises9 = require("node:fs/promises");
61959
62003
  var import_node_path10 = require("node:path");
61960
62004
 
61961
62005
  // ../../packages/event-normalizer/src/local-correlation-scope.ts
@@ -62047,8 +62091,17 @@ function projectLocalEvidence(value) {
62047
62091
  return projected.value;
62048
62092
  }
62049
62093
  async function readLocalArtifact(path, dependencies) {
62050
- const readFile = dependencies?.readFile ?? import_promises9.readFile;
62051
- const raw = await readFile(path, "utf8");
62094
+ const reader = dependencies?.readFile;
62095
+ const raw = await readWorkspaceFile(
62096
+ getWorkspaceRoot(dependencies),
62097
+ path,
62098
+ reader ? (file2) => reader(file2, "utf8") : void 0,
62099
+ MAX_ARTIFACT_BYTES
62100
+ ).catch((error62) => {
62101
+ if (error62 instanceof Error && /oversized/i.test(error62.message))
62102
+ throw createReadError(503, "privacy_projection_unavailable");
62103
+ throw error62;
62104
+ });
62052
62105
  if (Buffer.byteLength(raw, "utf8") > MAX_ARTIFACT_BYTES) {
62053
62106
  throw createReadError(503, "privacy_projection_unavailable");
62054
62107
  }
@@ -62066,9 +62119,15 @@ function createReadError(status, code) {
62066
62119
  return new RetrievalApiError(status, code);
62067
62120
  }
62068
62121
  async function readJsonFile(path, dependencies) {
62069
- const readFile = dependencies?.readFile ?? import_promises9.readFile;
62122
+ const reader = dependencies?.readFile;
62070
62123
  try {
62071
- return JSON.parse(await readFile(path, "utf8"));
62124
+ return JSON.parse(
62125
+ await readWorkspaceFile(
62126
+ getWorkspaceRoot(dependencies),
62127
+ path,
62128
+ reader ? (file2) => reader(file2, "utf8") : void 0
62129
+ )
62130
+ );
62072
62131
  } catch (error62) {
62073
62132
  if (isRecord2(error62) && error62["code"] === "ENOENT") {
62074
62133
  throw error62;
@@ -62138,6 +62197,8 @@ function parseLocalIncident(candidate) {
62138
62197
  if (!isStringArray(candidate["source_event_types"]) || !isStringArray(candidate["matched_fields"])) {
62139
62198
  throw createReadError(400, "invalid_local_state");
62140
62199
  }
62200
+ validateLocalArtifactPath(candidate["bundle_path"], "bundle");
62201
+ validateLocalArtifactPath(candidate["reproduction_path"], "reproduction");
62141
62202
  const serviceRuntime = candidate["service_runtime"];
62142
62203
  const serviceFramework = candidate["service_framework"];
62143
62204
  const incidentReason = candidate["matched_fields"].includes("request_anomaly") ? deriveIncidentReasonFromSignal({
@@ -62262,9 +62323,15 @@ async function readLocalState(dependencies) {
62262
62323
  }
62263
62324
  async function writeLocalState(state2, dependencies) {
62264
62325
  const rootDirectory = getWorkspaceRoot(dependencies);
62265
- const writeFile = dependencies?.writeFile ?? import_promises9.writeFile;
62266
- await writeFile(getStateFilePath(rootDirectory), `${JSON.stringify(state2, null, 2)}
62267
- `, "utf8");
62326
+ parseLocalState(state2);
62327
+ const writer = dependencies?.writeFile;
62328
+ await writeWorkspaceFile(
62329
+ rootDirectory,
62330
+ getStateFilePath(rootDirectory),
62331
+ `${JSON.stringify(state2, null, 2)}
62332
+ `,
62333
+ writer ? (path, contents) => writer(path, contents, "utf8") : void 0
62334
+ );
62268
62335
  }
62269
62336
  async function updateLocalIncidentStatus(input3, dependencies) {
62270
62337
  const state2 = await readLocalState(dependencies);
@@ -62327,7 +62394,7 @@ async function getLocalBundle(input3, dependencies) {
62327
62394
  if (incident === void 0) throw createReadError(404, "incident_not_found");
62328
62395
  try {
62329
62396
  return await readLocalArtifact(
62330
- resolveWorkspacePath(rootDirectory, incident.bundle_path),
62397
+ await resolveLocalArtifactPath(rootDirectory, incident.bundle_path, "bundle"),
62331
62398
  dependencies
62332
62399
  );
62333
62400
  } catch (error62) {
@@ -62346,7 +62413,7 @@ async function getLocalReproduction(input3, dependencies) {
62346
62413
  if (incident === void 0) throw createReadError(404, "incident_not_found");
62347
62414
  try {
62348
62415
  return await readLocalArtifact(
62349
- resolveWorkspacePath(rootDirectory, incident.reproduction_path),
62416
+ await resolveLocalArtifactPath(rootDirectory, incident.reproduction_path, "reproduction"),
62350
62417
  dependencies
62351
62418
  );
62352
62419
  } catch (error62) {
@@ -62370,7 +62437,7 @@ async function reopenLocalIncident(input3, dependencies) {
62370
62437
  }
62371
62438
 
62372
62439
  // src/cloud-artifact-cache.ts
62373
- var import_promises10 = require("node:fs/promises");
62440
+ var import_promises9 = require("node:fs/promises");
62374
62441
  var import_node_path11 = require("node:path");
62375
62442
 
62376
62443
  // src/retrieval-source.ts
@@ -62431,6 +62498,7 @@ function safeCachedArtifact(value) {
62431
62498
  return result.value;
62432
62499
  }
62433
62500
  async function cacheCloudBundleArtifact(input3, dependencies) {
62501
+ parseIncidentId(input3.incidentId);
62434
62502
  await pruneExpiredCloudArtifacts(dependencies);
62435
62503
  const bundle = safeCachedArtifact(attachSourceToPayload(input3.bundle, "cloud"));
62436
62504
  await persistCloudArtifact(
@@ -62442,6 +62510,7 @@ async function cacheCloudBundleArtifact(input3, dependencies) {
62442
62510
  return bundle;
62443
62511
  }
62444
62512
  async function cacheCloudReproductionArtifact(input3, dependencies) {
62513
+ parseIncidentId(input3.incidentId);
62445
62514
  await pruneExpiredCloudArtifacts(dependencies);
62446
62515
  const reproduction = safeCachedArtifact(attachSourceToPayload(input3.reproduction, "cloud"));
62447
62516
  await persistCloudArtifact(
@@ -62453,15 +62522,24 @@ async function cacheCloudReproductionArtifact(input3, dependencies) {
62453
62522
  return reproduction;
62454
62523
  }
62455
62524
  async function syncCloudIncidentCacheStatus(input3, dependencies) {
62525
+ parseIncidentId(input3.incidentId);
62456
62526
  await pruneExpiredCloudArtifacts(dependencies);
62457
62527
  await Promise.all([
62458
62528
  updateCachedArtifactStatus(
62459
- (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_BUNDLE_DIRECTORY_PATH, `${input3.incidentId}.bundle.json`),
62529
+ (0, import_node_path11.join)(
62530
+ getWorkspaceRoot2(dependencies),
62531
+ CLOUD_BUNDLE_DIRECTORY_PATH,
62532
+ `${input3.incidentId}.bundle.json`
62533
+ ),
62460
62534
  input3,
62461
62535
  dependencies
62462
62536
  ),
62463
62537
  updateCachedArtifactStatus(
62464
- (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_REPRODUCTION_DIRECTORY_PATH, `${input3.incidentId}.reproduction.json`),
62538
+ (0, import_node_path11.join)(
62539
+ getWorkspaceRoot2(dependencies),
62540
+ CLOUD_REPRODUCTION_DIRECTORY_PATH,
62541
+ `${input3.incidentId}.reproduction.json`
62542
+ ),
62465
62543
  input3,
62466
62544
  dependencies
62467
62545
  )
@@ -62469,13 +62547,16 @@ async function syncCloudIncidentCacheStatus(input3, dependencies) {
62469
62547
  }
62470
62548
  async function syncCloudIncidentMutationCache(incident, dependencies) {
62471
62549
  try {
62472
- await syncCloudIncidentCacheStatus({
62473
- incidentId: String(incident["incident_id"]),
62474
- incident: {
62475
- ...typeof incident["status"] === "string" ? { status: incident["status"] } : {},
62476
- resolved_at: incident["status"] === "resolved" && typeof incident["resolved_at"] === "string" ? incident["resolved_at"] : null
62477
- }
62478
- }, dependencies);
62550
+ await syncCloudIncidentCacheStatus(
62551
+ {
62552
+ incidentId: String(incident["incident_id"]),
62553
+ incident: {
62554
+ ...typeof incident["status"] === "string" ? { status: incident["status"] } : {},
62555
+ resolved_at: incident["status"] === "resolved" && typeof incident["resolved_at"] === "string" ? incident["resolved_at"] : null
62556
+ }
62557
+ },
62558
+ dependencies
62559
+ );
62479
62560
  } catch {
62480
62561
  incident["cache_warning"] = "cloud_cache_update_unavailable";
62481
62562
  }
@@ -62489,7 +62570,12 @@ async function pruneExpiredCloudArtifacts(dependencies) {
62489
62570
  async function pruneCloudArtifactCache(input3, dependencies) {
62490
62571
  const now = (dependencies?.now ?? (() => /* @__PURE__ */ new Date()))().getTime();
62491
62572
  const [bundleDirectoryCounts, reproductionDirectoryCounts] = await Promise.all([
62492
- pruneExpiredArtifactsInDirectory((0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_BUNDLE_DIRECTORY_PATH), now, input3.olderThanMs, dependencies),
62573
+ pruneExpiredArtifactsInDirectory(
62574
+ (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_BUNDLE_DIRECTORY_PATH),
62575
+ now,
62576
+ input3.olderThanMs,
62577
+ dependencies
62578
+ ),
62493
62579
  pruneExpiredArtifactsInDirectory(
62494
62580
  (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_REPRODUCTION_DIRECTORY_PATH),
62495
62581
  now,
@@ -62503,9 +62589,10 @@ async function pruneCloudArtifactCache(input3, dependencies) {
62503
62589
  };
62504
62590
  }
62505
62591
  async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs, dependencies) {
62506
- const readdir = dependencies?.readdir ?? import_promises10.readdir;
62507
- const rm = dependencies?.rm ?? import_promises10.rm;
62508
- const stat = dependencies?.stat ?? import_promises10.stat;
62592
+ await checkedCachePath(directoryPath, dependencies);
62593
+ const readdir = dependencies?.readdir ?? import_promises9.readdir;
62594
+ const rm = dependencies?.rm ?? import_promises9.rm;
62595
+ const stat = dependencies?.stat ?? import_promises9.lstat;
62509
62596
  let fileNames;
62510
62597
  try {
62511
62598
  fileNames = await readdir(directoryPath);
@@ -62520,7 +62607,10 @@ async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs,
62520
62607
  if (fileName === "reproductions") {
62521
62608
  return { removed: 0, retained: 0 };
62522
62609
  }
62523
- const filePath = (0, import_node_path11.join)(directoryPath, fileName);
62610
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\.(bundle|reproduction)\.json$/.test(fileName)) {
62611
+ return { removed: 0, retained: 0 };
62612
+ }
62613
+ const filePath = await checkedCachePath((0, import_node_path11.join)(directoryPath, fileName), dependencies);
62524
62614
  let fileStats;
62525
62615
  try {
62526
62616
  fileStats = await stat(filePath);
@@ -62534,6 +62624,7 @@ async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs,
62534
62624
  if (now - lastAccessedAt <= olderThanMs) {
62535
62625
  return { removed: 0, retained: 1 };
62536
62626
  }
62627
+ await checkedCachePath(filePath, dependencies);
62537
62628
  await rm(filePath, { force: true });
62538
62629
  return { removed: 1, retained: 0 };
62539
62630
  })
@@ -62547,11 +62638,15 @@ async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs,
62547
62638
  );
62548
62639
  }
62549
62640
  async function updateCachedArtifactStatus(filePath, input3, dependencies) {
62550
- const readFile = dependencies?.readFile ?? import_promises10.readFile;
62551
- const writeFile = dependencies?.writeFile ?? import_promises10.writeFile;
62641
+ await checkedCachePath(filePath, dependencies);
62642
+ let raw;
62552
62643
  let payload;
62553
62644
  try {
62554
- const raw = await readFile(filePath, "utf8");
62645
+ raw = dependencies?.readFile ? await dependencies.readFile(filePath, "utf8") : await readManaged(
62646
+ getWorkspaceRoot2(dependencies),
62647
+ (0, import_node_path11.relative)(getWorkspaceRoot2(dependencies), filePath)
62648
+ );
62649
+ if (raw === void 0) return;
62555
62650
  if (Buffer.byteLength(raw, "utf8") > 512 * 1024) return;
62556
62651
  payload = JSON.parse(raw);
62557
62652
  } catch (error62) {
@@ -62561,8 +62656,13 @@ async function updateCachedArtifactStatus(filePath, input3, dependencies) {
62561
62656
  throw error62;
62562
62657
  }
62563
62658
  const nextPayload = applyIncidentStatusToPayload(payload, input3.incidentId, input3.incident);
62564
- await writeFile(filePath, `${JSON.stringify(safeCachedArtifact(attachSourceToPayload(nextPayload, "cloud")), null, 2)}
62565
- `, "utf8");
62659
+ await writeCachedFile(
62660
+ filePath,
62661
+ `${JSON.stringify(safeCachedArtifact(attachSourceToPayload(nextPayload, "cloud")), null, 2)}
62662
+ `,
62663
+ raw,
62664
+ dependencies
62665
+ );
62566
62666
  }
62567
62667
  function applyIncidentStatusToPayload(payload, incidentId, incident) {
62568
62668
  if (!isRecord2(payload)) {
@@ -62577,16 +62677,37 @@ function applyIncidentStatusToPayload(payload, incidentId, incident) {
62577
62677
  nextPayload["resolved_at"] = incident.resolved_at ?? null;
62578
62678
  }
62579
62679
  if (isRecord2(payload["incident"])) {
62580
- nextPayload["incident"] = applyIncidentStatusToPayload(payload["incident"], incidentId, incident);
62680
+ nextPayload["incident"] = applyIncidentStatusToPayload(
62681
+ payload["incident"],
62682
+ incidentId,
62683
+ incident
62684
+ );
62581
62685
  }
62582
62686
  return nextPayload;
62583
62687
  }
62584
62688
  async function persistCloudArtifact(directoryPath, fileName, payload, dependencies) {
62585
- const mkdir5 = dependencies?.mkdir ?? import_promises10.mkdir;
62586
- const writeFile = dependencies?.writeFile ?? import_promises10.writeFile;
62587
- await mkdir5(directoryPath, { recursive: true });
62588
- await writeFile((0, import_node_path11.join)(directoryPath, fileName), `${JSON.stringify(payload, null, 2)}
62589
- `, "utf8");
62689
+ if ((0, import_node_path11.basename)(fileName) !== fileName || fileName.includes("\\"))
62690
+ throw new Error("Invalid cache filename.");
62691
+ const filePath = await checkedCachePath((0, import_node_path11.join)(directoryPath, fileName), dependencies);
62692
+ const root = getWorkspaceRoot2(dependencies);
62693
+ const previous = await readManaged(root, (0, import_node_path11.relative)(root, filePath));
62694
+ await writeCachedFile(filePath, `${JSON.stringify(payload, null, 2)}
62695
+ `, previous, dependencies);
62696
+ }
62697
+ async function checkedCachePath(filePath, dependencies) {
62698
+ const root = getWorkspaceRoot2(dependencies);
62699
+ return safePath(root, (0, import_node_path11.relative)(root, filePath));
62700
+ }
62701
+ async function writeCachedFile(filePath, contents, expected, dependencies) {
62702
+ await checkedCachePath(filePath, dependencies);
62703
+ if (dependencies?.writeFile) {
62704
+ await dependencies.mkdir?.((0, import_node_path11.dirname)(filePath), { recursive: true });
62705
+ await checkedCachePath(filePath, dependencies);
62706
+ await dependencies.writeFile(filePath, contents, "utf8");
62707
+ return;
62708
+ }
62709
+ const root = getWorkspaceRoot2(dependencies);
62710
+ await writeManaged(root, (0, import_node_path11.relative)(root, filePath), contents, expected);
62590
62711
  }
62591
62712
 
62592
62713
  // src/clean-command.ts
@@ -62625,9 +62746,9 @@ function parseOlderThan(value) {
62625
62746
  return Number.parseInt(match[1], 10) * 24 * 60 * 60 * 1e3;
62626
62747
  }
62627
62748
  async function cleanProcessedEventFiles(input3, dependencies) {
62628
- const readdir = dependencies.readdir ?? import_promises11.readdir;
62629
- const rm = dependencies.rm ?? import_promises11.rm;
62630
- const stat = dependencies.stat ?? import_promises11.stat;
62749
+ const readdir = dependencies.readdir ?? import_promises10.readdir;
62750
+ const rm = dependencies.rm ?? import_promises10.rm;
62751
+ const stat = dependencies.stat ?? import_promises10.stat;
62631
62752
  const rootDirectory = (dependencies.cwd ?? process.cwd)();
62632
62753
  const eventsDirectoryPath = (0, import_node_path12.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH);
62633
62754
  const state2 = await readLocalState(dependencies);
@@ -62662,9 +62783,9 @@ async function cleanProcessedEventFiles(input3, dependencies) {
62662
62783
  return { removed, retained };
62663
62784
  }
62664
62785
  async function cleanRelaySpoolFiles(input3, dependencies) {
62665
- const readdir = dependencies.readdir ?? import_promises11.readdir;
62666
- const rm = dependencies.rm ?? import_promises11.rm;
62667
- const stat = dependencies.stat ?? import_promises11.stat;
62786
+ const readdir = dependencies.readdir ?? import_promises10.readdir;
62787
+ const rm = dependencies.rm ?? import_promises10.rm;
62788
+ const stat = dependencies.stat ?? import_promises10.stat;
62668
62789
  const rootDirectory = (dependencies.cwd ?? process.cwd)();
62669
62790
  const spoolDirectoryPath = (0, import_node_path12.join)(rootDirectory, LOCAL_RELAY_SPOOL_DIRECTORY_PATH);
62670
62791
  let spoolFileNames;
@@ -62715,7 +62836,7 @@ function sortLocalIncidentRemovalPriority(left, right) {
62715
62836
  return left.incident_id.localeCompare(right.incident_id);
62716
62837
  }
62717
62838
  async function applyLocalIncidentRetention(dependencies) {
62718
- const rm = dependencies.rm ?? import_promises11.rm;
62839
+ const rm = dependencies.rm ?? import_promises10.rm;
62719
62840
  const rootDirectory = (dependencies.cwd ?? process.cwd)();
62720
62841
  const state2 = await readLocalState(dependencies);
62721
62842
  const incidents = Object.values(state2.incidents);
@@ -62729,8 +62850,13 @@ async function applyLocalIncidentRetention(dependencies) {
62729
62850
  const nextIncidents = { ...state2.incidents };
62730
62851
  for (const incident of incidentsToRemove) {
62731
62852
  delete nextIncidents[incident.incident_id];
62732
- await rm(resolveWorkspacePath(rootDirectory, incident.bundle_path), { force: true });
62733
- await rm(resolveWorkspacePath(rootDirectory, incident.reproduction_path), { force: true });
62853
+ await rm(await resolveLocalArtifactPath(rootDirectory, incident.bundle_path, "bundle"), {
62854
+ force: true
62855
+ });
62856
+ await rm(
62857
+ await resolveLocalArtifactPath(rootDirectory, incident.reproduction_path, "reproduction"),
62858
+ { force: true }
62859
+ );
62734
62860
  }
62735
62861
  await writeLocalState(
62736
62862
  {
@@ -62748,10 +62874,12 @@ async function countLocalIncidents(dependencies) {
62748
62874
  return Object.keys((await readLocalState(dependencies)).incidents).length;
62749
62875
  }
62750
62876
  async function countDirectoryFiles(directoryPath, dependencies, extension) {
62751
- const readdir = dependencies.readdir ?? import_promises11.readdir;
62877
+ const readdir = dependencies.readdir ?? import_promises10.readdir;
62752
62878
  const rootDirectory = (dependencies.cwd ?? process.cwd)();
62753
62879
  try {
62754
- return (await readdir((0, import_node_path12.join)(rootDirectory, directoryPath))).filter((fileName) => fileName.endsWith(extension)).length;
62880
+ return (await readdir((0, import_node_path12.join)(rootDirectory, directoryPath))).filter(
62881
+ (fileName) => fileName.endsWith(extension)
62882
+ ).length;
62755
62883
  } catch (error62) {
62756
62884
  if (isMissingPathError(error62)) {
62757
62885
  return 0;
@@ -62766,10 +62894,15 @@ async function countRelaySpoolEventFiles(dependencies) {
62766
62894
  return countDirectoryFiles(LOCAL_RELAY_SPOOL_DIRECTORY_PATH, dependencies, ".events.json");
62767
62895
  }
62768
62896
  async function resetRuntimeData(dependencies) {
62769
- const mkdir5 = dependencies.mkdir ?? import_promises11.mkdir;
62770
- const rm = dependencies.rm ?? import_promises11.rm;
62897
+ const mkdir5 = dependencies.mkdir ?? import_promises10.mkdir;
62898
+ const rm = dependencies.rm ?? import_promises10.rm;
62771
62899
  const rootDirectory = (dependencies.cwd ?? process.cwd)();
62772
- const [processedEventFilesRemoved, relaySpoolFilesRemoved, cloudCacheFilesRemoved, localIncidentCount] = await Promise.all([
62900
+ const [
62901
+ processedEventFilesRemoved,
62902
+ relaySpoolFilesRemoved,
62903
+ cloudCacheFilesRemoved,
62904
+ localIncidentCount
62905
+ ] = await Promise.all([
62773
62906
  countProcessedAndUnprocessedEventFiles(dependencies),
62774
62907
  countRelaySpoolEventFiles(dependencies),
62775
62908
  countCloudArtifactFiles(dependencies),
@@ -62812,6 +62945,17 @@ async function cleanCommand(input3, dependencies = {}) {
62812
62945
  output: "Invalid value for --older-than."
62813
62946
  };
62814
62947
  }
62948
+ const root = (dependencies.cwd ?? process.cwd)();
62949
+ for (const path of [
62950
+ ".debugbundle/local/state.json",
62951
+ LOCAL_EVENTS_DIRECTORY_PATH,
62952
+ LOCAL_RELAY_SPOOL_DIRECTORY_PATH,
62953
+ LOCAL_BUNDLE_DIRECTORY_PATH2,
62954
+ LOCAL_REPRODUCTION_DIRECTORY_PATH,
62955
+ CLOUD_BUNDLE_DIRECTORY_PATH2,
62956
+ CLOUD_REPRODUCTION_DIRECTORY_PATH2
62957
+ ])
62958
+ await safePath(root, path);
62815
62959
  const hasEventsFlag = input3.events === true;
62816
62960
  const hasBundlesFlag = input3.bundles === true;
62817
62961
  const hasAllFlag = input3.all === true;
@@ -62838,9 +62982,15 @@ async function cleanCommand(input3, dependencies = {}) {
62838
62982
  output: input3.json ? JSON.stringify(summary2) : formatCleanOutput(summary2)
62839
62983
  };
62840
62984
  }
62841
- const processedEvents = runEventsCleanup ? await cleanProcessedEventFiles({ removeAllProcessed: input3.events === true, now }, dependencies) : { removed: 0, retained: await countProcessedAndUnprocessedEventFiles(dependencies) };
62985
+ const processedEvents = runEventsCleanup ? await cleanProcessedEventFiles(
62986
+ { removeAllProcessed: input3.events === true, now },
62987
+ dependencies
62988
+ ) : { removed: 0, retained: await countProcessedAndUnprocessedEventFiles(dependencies) };
62842
62989
  const relaySpool = await cleanRelaySpoolFiles({ now }, dependencies);
62843
- const cloudCache = runBundleCleanup ? await pruneCloudArtifactCache({ olderThanMs: bundleRetentionMs ?? DEFAULT_CLOUD_CACHE_RETENTION_MS }, { ...dependencies, now: () => now }) : await countCloudArtifactCache(dependencies);
62990
+ const cloudCache = runBundleCleanup ? await pruneCloudArtifactCache(
62991
+ { olderThanMs: bundleRetentionMs ?? DEFAULT_CLOUD_CACHE_RETENTION_MS },
62992
+ { ...dependencies, now: () => now }
62993
+ ) : await countCloudArtifactCache(dependencies);
62844
62994
  const localIncidents = runLocalIncidentCleanup ? await applyLocalIncidentRetention(dependencies) : { removed: 0, retained: await countLocalIncidents(dependencies) };
62845
62995
  const summary = {
62846
62996
  status: "ok",
@@ -62859,10 +63009,12 @@ async function cleanCommand(input3, dependencies = {}) {
62859
63009
  };
62860
63010
  }
62861
63011
  async function countProcessedAndUnprocessedEventFiles(dependencies) {
62862
- const readdir = dependencies.readdir ?? import_promises11.readdir;
63012
+ const readdir = dependencies.readdir ?? import_promises10.readdir;
62863
63013
  const rootDirectory = (dependencies.cwd ?? process.cwd)();
62864
63014
  try {
62865
- return (await readdir((0, import_node_path12.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH))).filter((fileName) => fileName.endsWith(".events.json")).length;
63015
+ return (await readdir((0, import_node_path12.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH))).filter(
63016
+ (fileName) => fileName.endsWith(".events.json")
63017
+ ).length;
62866
63018
  } catch (error62) {
62867
63019
  if (isMissingPathError(error62)) {
62868
63020
  return 0;
@@ -62871,11 +63023,14 @@ async function countProcessedAndUnprocessedEventFiles(dependencies) {
62871
63023
  }
62872
63024
  }
62873
63025
  async function countCloudArtifactCache(dependencies) {
62874
- return pruneCloudArtifactCache({ olderThanMs: Number.MAX_SAFE_INTEGER }, { ...dependencies, now: () => /* @__PURE__ */ new Date(0) });
63026
+ return pruneCloudArtifactCache(
63027
+ { olderThanMs: Number.MAX_SAFE_INTEGER },
63028
+ { ...dependencies, now: () => /* @__PURE__ */ new Date(0) }
63029
+ );
62875
63030
  }
62876
63031
 
62877
63032
  // src/connect-command.ts
62878
- var import_promises13 = require("node:fs/promises");
63033
+ var import_promises12 = require("node:fs/promises");
62879
63034
  var import_node_path14 = require("node:path");
62880
63035
 
62881
63036
  // src/connection-config.ts
@@ -62914,12 +63069,12 @@ async function readConnectionConfig(rootDirectory, readFile) {
62914
63069
 
62915
63070
  // src/interactive-auth.ts
62916
63071
  var import_node_process = require("node:process");
62917
- var import_promises12 = require("node:readline/promises");
63072
+ var import_promises11 = require("node:readline/promises");
62918
63073
  function isInteractiveTerminal() {
62919
63074
  return import_node_process.stdin.isTTY === true && import_node_process.stdout.isTTY === true;
62920
63075
  }
62921
63076
  async function promptForInteractiveLoginSelection() {
62922
- const readlineInterface = (0, import_promises12.createInterface)({
63077
+ const readlineInterface = (0, import_promises11.createInterface)({
62923
63078
  input: import_node_process.stdin,
62924
63079
  output: import_node_process.stdout
62925
63080
  });
@@ -63524,9 +63679,9 @@ function buildValidationFailureResult(input3) {
63524
63679
  }
63525
63680
  async function connectCommand(input3, dependencies = {}) {
63526
63681
  const cwd = dependencies.cwd ?? (() => process.cwd());
63527
- const readFile = dependencies.readFile ?? ((path) => (0, import_promises13.readFile)(path, "utf8"));
63528
- const stat = dependencies.stat ?? import_promises13.stat;
63529
- const writeFile = dependencies.writeFile ?? import_promises13.writeFile;
63682
+ const readFile = dependencies.readFile ?? ((path) => (0, import_promises12.readFile)(path, "utf8"));
63683
+ const stat = dependencies.stat ?? import_promises12.stat;
63684
+ const writeFile = dependencies.writeFile ?? import_promises12.writeFile;
63530
63685
  const readAuthState = dependencies.readAuthState ?? ((authInput) => readCliAuthState(authInput));
63531
63686
  const createHttpClient = dependencies.createHttpClient ?? ((clientInput) => {
63532
63687
  const httpClientDependencies = {};
@@ -63733,7 +63888,7 @@ var legacy_skill_hashes_default = {
63733
63888
  };
63734
63889
 
63735
63890
  // src/agent-setup.ts
63736
- var import_promises14 = require("node:readline/promises");
63891
+ var import_promises13 = require("node:readline/promises");
63737
63892
  var import_node_process2 = require("node:process");
63738
63893
  var MANAGED_AGENTS_START = "<!-- debugbundle:start -->";
63739
63894
  var MANAGED_AGENTS_END = "<!-- debugbundle:end -->";
@@ -63771,7 +63926,7 @@ async function chooseAgents(root, input3, dependencies) {
63771
63926
  let answer;
63772
63927
  if (dependencies.promptUser) answer = await dependencies.promptUser(prompt);
63773
63928
  else {
63774
- const terminal = (0, import_promises14.createInterface)({ input: import_node_process2.stdin, output: import_node_process2.stdout });
63929
+ const terminal = (0, import_promises13.createInterface)({ input: import_node_process2.stdin, output: import_node_process2.stdout });
63775
63930
  try {
63776
63931
  answer = await terminal.question(prompt);
63777
63932
  } finally {
@@ -63823,7 +63978,7 @@ function localScaffoldFailure(error62, json2 = false) {
63823
63978
  }
63824
63979
 
63825
63980
  // src/doctor-command.ts
63826
- var import_promises15 = require("node:fs/promises");
63981
+ var import_promises14 = require("node:fs/promises");
63827
63982
  var import_node_path15 = require("node:path");
63828
63983
 
63829
63984
  // ../../packages/event-normalizer/src/fingerprints.ts
@@ -65529,13 +65684,13 @@ async function runDoctorCommand(input3, dependencies = {}) {
65529
65684
  const now = dependencies.now ?? (() => /* @__PURE__ */ new Date());
65530
65685
  const fetchImpl = dependencies.fetchImpl ?? nodeFetch;
65531
65686
  const readAuthStateImpl = dependencies.readAuthState ?? readCliAuthState;
65532
- const readdir = dependencies.readdir ?? import_promises15.readdir;
65687
+ const readdir = dependencies.readdir ?? import_promises14.readdir;
65533
65688
  const readFile = dependencies.readFile ?? (async (filePath) => {
65534
65689
  const content = await readManaged(rootDirectory, (0, import_node_path15.relative)(rootDirectory, filePath));
65535
65690
  if (content === void 0) throw Object.assign(new Error("Missing local scaffold file."), { code: "ENOENT" });
65536
65691
  return content;
65537
65692
  });
65538
- const stat = dependencies.stat ?? import_promises15.stat;
65693
+ const stat = dependencies.stat ?? import_promises14.stat;
65539
65694
  const rootDirectory = await projectRoot(cwd());
65540
65695
  const currentTime = now();
65541
65696
  const { check: profileCheck, profile, validationErrors } = await loadProfile(rootDirectory, { readFile, stat });
@@ -65581,8 +65736,8 @@ async function doctorCommand(input3, dependencies = {}) {
65581
65736
 
65582
65737
  // src/ingest-command.ts
65583
65738
  var import_node_crypto8 = require("node:crypto");
65584
- var import_promises17 = require("node:fs/promises");
65585
- var import_node_path19 = require("node:path");
65739
+ var import_promises16 = require("node:fs/promises");
65740
+ var import_node_path18 = require("node:path");
65586
65741
 
65587
65742
  // ../../packages/log-parser/src/project-id.ts
65588
65743
  var import_node_crypto5 = require("node:crypto");
@@ -66070,6 +66225,10 @@ function parseIncidentState(candidate) {
66070
66225
  if (!isRecord2(candidate)) {
66071
66226
  return null;
66072
66227
  }
66228
+ if (typeof candidate["bundle_path"] === "string")
66229
+ validateLocalArtifactPath(candidate["bundle_path"], "bundle");
66230
+ if (typeof candidate["reproduction_path"] === "string")
66231
+ validateLocalArtifactPath(candidate["reproduction_path"], "reproduction");
66073
66232
  if (candidate["source"] !== "local" || candidate["status"] !== "open" && candidate["status"] !== "resolved") {
66074
66233
  return null;
66075
66234
  }
@@ -66146,8 +66305,11 @@ function parseIncidentState(candidate) {
66146
66305
  const occurrenceCount = candidate["occurrence_count"];
66147
66306
  const sourceEventId = candidate["source_event_id"];
66148
66307
  const sourceOccurredAt = candidate["source_occurred_at"];
66149
- const bundlePath = candidate["bundle_path"];
66150
- const reproductionPath = candidate["reproduction_path"];
66308
+ const bundlePath = validateLocalArtifactPath(candidate["bundle_path"], "bundle");
66309
+ const reproductionPath = validateLocalArtifactPath(
66310
+ candidate["reproduction_path"],
66311
+ "reproduction"
66312
+ );
66151
66313
  const generationNumber = candidate["generation_number"];
66152
66314
  const normalizedSourceEventTypes = [...sourceEventTypes].sort();
66153
66315
  return {
@@ -66241,8 +66403,9 @@ async function readState(statePath, readFile, stat) {
66241
66403
  }
66242
66404
  try {
66243
66405
  return parseState(await readFile(statePath));
66244
- } catch {
66245
- return null;
66406
+ } catch (error62) {
66407
+ if (error62 instanceof SyntaxError) return null;
66408
+ throw error62;
66246
66409
  }
66247
66410
  }
66248
66411
  async function readEventBatches(eventDirectoryPath, fileNames, readFile) {
@@ -66302,9 +66465,6 @@ function serializeState(state2) {
66302
66465
  `;
66303
66466
  }
66304
66467
 
66305
- // src/local-bundle-artifacts.ts
66306
- var import_node_path17 = require("node:path");
66307
-
66308
66468
  // ../../packages/bundle-engine/src/envelope-selection.ts
66309
66469
  function selectLatestEnvelope(envelopes, predicate) {
66310
66470
  for (let index = envelopes.length - 1; index >= 0; index -= 1) {
@@ -67943,12 +68103,20 @@ function localBundle(input3) {
67943
68103
  });
67944
68104
  }
67945
68105
  async function writeLocalBundleArtifacts(input3) {
68106
+ const bundlePath = await resolveLocalArtifactPath(
68107
+ input3.rootDirectory,
68108
+ input3.incident.bundle_path,
68109
+ "bundle"
68110
+ );
68111
+ const reproductionPath = await resolveLocalArtifactPath(
68112
+ input3.rootDirectory,
68113
+ input3.incident.reproduction_path,
68114
+ "reproduction"
68115
+ );
67946
68116
  let previous = null;
67947
68117
  if (input3.readFile) {
67948
68118
  try {
67949
- previous = BundleV1Schema.parse(
67950
- JSON.parse(await input3.readFile((0, import_node_path17.join)(input3.rootDirectory, input3.incident.bundle_path)))
67951
- );
68119
+ previous = BundleV1Schema.parse(JSON.parse(await input3.readFile(bundlePath)));
67952
68120
  } catch {
67953
68121
  }
67954
68122
  }
@@ -67958,19 +68126,19 @@ async function writeLocalBundleArtifacts(input3) {
67958
68126
  });
67959
68127
  if (previous && JSON.stringify({ ...bundle, metadata: previous.metadata }) === JSON.stringify(previous))
67960
68128
  return;
67961
- await input3.writeFile(
67962
- (0, import_node_path17.join)(input3.rootDirectory, input3.incident.bundle_path),
67963
- `${JSON.stringify(bundle, null, 2)}
67964
- `
67965
- );
67966
- await input3.writeFile(
67967
- (0, import_node_path17.join)(input3.rootDirectory, input3.incident.reproduction_path),
67968
- `${JSON.stringify(bundle.reproduction, null, 2)}
67969
- `
67970
- );
68129
+ await input3.writeFile(bundlePath, `${JSON.stringify(bundle, null, 2)}
68130
+ `);
68131
+ await input3.writeFile(reproductionPath, `${JSON.stringify(bundle.reproduction, null, 2)}
68132
+ `);
67971
68133
  }
67972
68134
  async function rebuildLocalDiagnosticArtifacts(input3) {
67973
68135
  const { incident } = input3;
68136
+ const bundlePath = await resolveLocalArtifactPath(
68137
+ input3.rootDirectory,
68138
+ incident.bundle_path,
68139
+ "bundle"
68140
+ );
68141
+ await resolveLocalArtifactPath(input3.rootDirectory, incident.reproduction_path, "reproduction");
67974
68142
  const primary = incident.source_events.find((event) => event.event_id === incident.source_event_id) ?? null;
67975
68143
  const association = associateDiagnosticEvidence({
67976
68144
  failure: primary,
@@ -67979,9 +68147,7 @@ async function rebuildLocalDiagnosticArtifacts(input3) {
67979
68147
  });
67980
68148
  let previous = null;
67981
68149
  try {
67982
- previous = BundleV1Schema.parse(
67983
- JSON.parse(await input3.readFile((0, import_node_path17.join)(input3.rootDirectory, incident.bundle_path)))
67984
- );
68150
+ previous = BundleV1Schema.parse(JSON.parse(await input3.readFile(bundlePath)));
67985
68151
  } catch {
67986
68152
  }
67987
68153
  if (association.events.length === 0 && previous?.context.recovery === void 0 && previous?.context.resource_observations === void 0)
@@ -68006,8 +68172,8 @@ async function rebuildLocalDiagnosticArtifacts(input3) {
68006
68172
 
68007
68173
  // src/process-command.ts
68008
68174
  var import_node_crypto7 = require("node:crypto");
68009
- var import_promises16 = require("node:fs/promises");
68010
- var import_node_path18 = require("node:path");
68175
+ var import_promises15 = require("node:fs/promises");
68176
+ var import_node_path17 = require("node:path");
68011
68177
  var LOCAL_EVENTS_DIRECTORY_PATH3 = ".debugbundle/local/events";
68012
68178
  var LOCAL_STATE_FILE_PATH = ".debugbundle/local/state.json";
68013
68179
  var LOCAL_BUNDLE_DIRECTORY_PATH3 = ".debugbundle/bundles/local";
@@ -68270,18 +68436,26 @@ function requireProjectId(event) {
68270
68436
  }
68271
68437
  async function processCommand(input3, dependencies = {}) {
68272
68438
  const cwd = dependencies.cwd ?? (() => process.cwd());
68273
- const mkdir5 = dependencies.mkdir ?? import_promises16.mkdir;
68274
- const readFile = dependencies.readFile ?? ((filePath) => (0, import_promises16.readFile)(filePath, "utf8"));
68275
- const readdir = dependencies.readdir ?? import_promises16.readdir;
68276
- const stat = dependencies.stat ?? import_promises16.stat;
68277
- const writeFile = dependencies.writeFile ?? ((filePath, content) => (0, import_promises16.writeFile)(filePath, content, "utf8"));
68278
68439
  const rootDirectory = cwd();
68279
- const eventsDirectoryPath = (0, import_node_path18.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH3);
68280
- const statePath = (0, import_node_path18.join)(rootDirectory, LOCAL_STATE_FILE_PATH);
68281
- const bundleDirectoryPath = (0, import_node_path18.join)(rootDirectory, LOCAL_BUNDLE_DIRECTORY_PATH3);
68282
- const reproductionDirectoryPath = (0, import_node_path18.join)(rootDirectory, LOCAL_REPRODUCTION_DIRECTORY_PATH2);
68440
+ const mkdir5 = dependencies.mkdir ?? import_promises15.mkdir;
68441
+ const readFile = (filePath) => readWorkspaceFile(rootDirectory, filePath, dependencies.readFile);
68442
+ const readdir = dependencies.readdir ?? import_promises15.readdir;
68443
+ const stat = dependencies.stat ?? import_promises15.stat;
68444
+ const writeFile = (filePath, content) => writeWorkspaceFile(rootDirectory, filePath, content, dependencies.writeFile);
68445
+ const eventsDirectoryPath = (0, import_node_path17.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH3);
68446
+ const statePath = (0, import_node_path17.join)(rootDirectory, LOCAL_STATE_FILE_PATH);
68447
+ const bundleDirectoryPath = (0, import_node_path17.join)(rootDirectory, LOCAL_BUNDLE_DIRECTORY_PATH3);
68448
+ const reproductionDirectoryPath = (0, import_node_path17.join)(rootDirectory, LOCAL_REPRODUCTION_DIRECTORY_PATH2);
68283
68449
  const capturePreset = input3.preset ?? "minimal";
68284
- await mkdir5((0, import_node_path18.join)(rootDirectory, ".debugbundle", "local"), { recursive: true });
68450
+ for (const path of [
68451
+ ".debugbundle/local",
68452
+ LOCAL_STATE_FILE_PATH,
68453
+ LOCAL_EVENTS_DIRECTORY_PATH3,
68454
+ LOCAL_BUNDLE_DIRECTORY_PATH3,
68455
+ LOCAL_REPRODUCTION_DIRECTORY_PATH2
68456
+ ])
68457
+ await safePath(rootDirectory, path);
68458
+ await mkdir5((0, import_node_path17.join)(rootDirectory, ".debugbundle", "local"), { recursive: true });
68285
68459
  await mkdir5(bundleDirectoryPath, { recursive: true });
68286
68460
  await mkdir5(reproductionDirectoryPath, { recursive: true });
68287
68461
  const previousState = await readState(statePath, readFile, stat);
@@ -68314,7 +68488,7 @@ async function processCommand(input3, dependencies = {}) {
68314
68488
  };
68315
68489
  }
68316
68490
  const batches = await readEventBatches(eventsDirectoryPath, targetEventFileNames, readFile);
68317
- const diagnosticReceiptPath = (0, import_node_path18.join)(rootDirectory, ".debugbundle/local/evidence-receipts.json");
68491
+ const diagnosticReceiptPath = (0, import_node_path17.join)(rootDirectory, ".debugbundle/local/evidence-receipts.json");
68318
68492
  const ledger = await pathExists4(diagnosticReceiptPath, stat) ? parseDiagnosticReceipts(JSON.parse(await readFile(diagnosticReceiptPath))) : { diagnostic_receipts: {}, diagnostic_payload_hashes: {} };
68319
68493
  const receipts = ledger.diagnostic_receipts;
68320
68494
  for (const [id, at] of Object.entries(previousState?.diagnostic_receipts ?? {})) {
@@ -68579,7 +68753,7 @@ function buildEventFileName(events, filePath) {
68579
68753
  return Number.isFinite(candidate) && candidate > latest ? candidate : latest;
68580
68754
  }, 0);
68581
68755
  const digest4 = (0, import_node_crypto8.createHash)("sha256").update([filePath, ...events.map((event) => event.event_id)].join("\0")).digest("hex").slice(0, 8);
68582
- return `${lastOccurredAt}-${digest4}-${slugify3(events[0]?.service.name ?? (0, import_node_path19.basename)(filePath))}.events.json`;
68756
+ return `${lastOccurredAt}-${digest4}-${slugify3(events[0]?.service.name ?? (0, import_node_path18.basename)(filePath))}.events.json`;
68583
68757
  }
68584
68758
  function formatHumanOutput(summary) {
68585
68759
  return [
@@ -68589,7 +68763,7 @@ function formatHumanOutput(summary) {
68589
68763
  ].join("\n");
68590
68764
  }
68591
68765
  async function readProfile(rootDirectory, readFile) {
68592
- const parsedProfile = ProfileSchema2.safeParse(JSON.parse(await readFile((0, import_node_path19.join)(rootDirectory, PROFILE_FILE_PATH))));
68766
+ const parsedProfile = ProfileSchema2.safeParse(JSON.parse(await readFile((0, import_node_path18.join)(rootDirectory, PROFILE_FILE_PATH))));
68593
68767
  if (!parsedProfile.success) {
68594
68768
  throw new Error(`Invalid ${PROFILE_FILE_PATH}`);
68595
68769
  }
@@ -68604,11 +68778,11 @@ async function ingestCommand(input3, dependencies = {}) {
68604
68778
  };
68605
68779
  }
68606
68780
  const cwd = dependencies.cwd ?? (() => process.cwd());
68607
- const mkdir5 = dependencies.mkdir ?? (async (path, options) => (0, import_promises17.mkdir)(path, options));
68781
+ const mkdir5 = dependencies.mkdir ?? (async (path, options) => (0, import_promises16.mkdir)(path, options));
68608
68782
  const processLocalEvents = dependencies.processCommand ?? processCommand;
68609
- const readFile = dependencies.readFile ?? (async (path) => (0, import_promises17.readFile)(path, "utf8"));
68610
- const rename4 = dependencies.rename ?? (async (sourcePath, destinationPath) => (0, import_promises17.rename)(sourcePath, destinationPath));
68611
- const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises17.writeFile)(path, content, "utf8"));
68783
+ const readFile = dependencies.readFile ?? (async (path) => (0, import_promises16.readFile)(path, "utf8"));
68784
+ const rename4 = dependencies.rename ?? (async (sourcePath, destinationPath) => (0, import_promises16.rename)(sourcePath, destinationPath));
68785
+ const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises16.writeFile)(path, content, "utf8"));
68612
68786
  try {
68613
68787
  const rootDirectory = cwd();
68614
68788
  const profile = await readProfile(rootDirectory, readFile);
@@ -68624,9 +68798,9 @@ async function ingestCommand(input3, dependencies = {}) {
68624
68798
  output: "No supported events were found in the input file."
68625
68799
  };
68626
68800
  }
68627
- const eventDirectory = (0, import_node_path19.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH4);
68801
+ const eventDirectory = (0, import_node_path18.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH4);
68628
68802
  const eventFile = buildEventFileName(events, input3.filePath);
68629
- const destinationPath = (0, import_node_path19.join)(eventDirectory, eventFile);
68803
+ const destinationPath = (0, import_node_path18.join)(eventDirectory, eventFile);
68630
68804
  const temporaryPath = `${destinationPath}.tmp`;
68631
68805
  await mkdir5(eventDirectory, { recursive: true });
68632
68806
  await writeFile(temporaryPath, `${JSON.stringify(events, null, 2)}
@@ -68665,8 +68839,8 @@ async function ingestCommand(input3, dependencies = {}) {
68665
68839
  }
68666
68840
 
68667
68841
  // src/watch-command.ts
68668
- var import_promises18 = require("node:fs/promises");
68669
- var import_node_path20 = require("node:path");
68842
+ var import_promises17 = require("node:fs/promises");
68843
+ var import_node_path19 = require("node:path");
68670
68844
  function normalizeBaseUrl5(baseUrl) {
68671
68845
  return baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
68672
68846
  }
@@ -68711,25 +68885,25 @@ async function watchCommand(input3, dependencies = {}) {
68711
68885
  };
68712
68886
  }
68713
68887
  const cwd = dependencies.cwd ?? (() => process.cwd());
68714
- const mkdir5 = dependencies.mkdir ?? (async (path, options) => (0, import_promises18.mkdir)(path, options));
68888
+ const mkdir5 = dependencies.mkdir ?? (async (path, options) => (0, import_promises17.mkdir)(path, options));
68715
68889
  const pollIntervalMs = dependencies.pollIntervalMs ?? 1e3;
68716
68890
  const processLocalEvents = dependencies.processCommand ?? processCommand;
68717
- const readFile = dependencies.readFile ?? (async (path) => (0, import_promises18.readFile)(path));
68891
+ const readFile = dependencies.readFile ?? (async (path) => (0, import_promises17.readFile)(path));
68718
68892
  const readEnv = dependencies.readEnv ?? ((name) => process.env[name]);
68719
- const rename4 = dependencies.rename ?? (async (sourcePath, destinationPath) => (0, import_promises18.rename)(sourcePath, destinationPath));
68893
+ const rename4 = dependencies.rename ?? (async (sourcePath, destinationPath) => (0, import_promises17.rename)(sourcePath, destinationPath));
68720
68894
  const fetchDependencies = dependencies.fetchImpl === void 0 ? void 0 : { fetchImpl: dependencies.fetchImpl };
68721
68895
  const sendEvents = dependencies.sendEvents ?? ((requestInput) => sendEventsToApi(requestInput, fetchDependencies));
68722
68896
  const signal = dependencies.signal;
68723
68897
  const sleep = dependencies.sleep ?? (async (milliseconds) => new Promise((resolve5) => setTimeout(resolve5, milliseconds)));
68724
- const stat = dependencies.stat ?? import_promises18.stat;
68725
- const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises18.writeFile)(path, content, "utf8"));
68898
+ const stat = dependencies.stat ?? import_promises17.stat;
68899
+ const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises17.writeFile)(path, content, "utf8"));
68726
68900
  try {
68727
68901
  const rootDirectory = cwd();
68728
68902
  const profile = await readProfile(
68729
68903
  rootDirectory,
68730
68904
  async (path) => (await readFile(path)).toString("utf8")
68731
68905
  );
68732
- const eventDirectory = (0, import_node_path20.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH4);
68906
+ const eventDirectory = (0, import_node_path19.join)(rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH4);
68733
68907
  const useCloudDelivery = input3.cloud === true;
68734
68908
  const connectionConfig = useCloudDelivery ? await readConnectionConfig(
68735
68909
  rootDirectory,
@@ -68810,7 +68984,7 @@ async function watchCommand(input3, dependencies = {}) {
68810
68984
  events,
68811
68985
  `${input3.logPath}:${batchesWritten + 1}`
68812
68986
  );
68813
- const destinationPath = (0, import_node_path20.join)(eventDirectory, eventFile);
68987
+ const destinationPath = (0, import_node_path19.join)(eventDirectory, eventFile);
68814
68988
  const temporaryPath = `${destinationPath}.tmp`;
68815
68989
  await writeFile(temporaryPath, `${JSON.stringify(events, null, 2)}
68816
68990
  `);
@@ -68861,11 +69035,11 @@ async function watchCommand(input3, dependencies = {}) {
68861
69035
  }
68862
69036
 
68863
69037
  // src/setup-command.ts
68864
- var import_promises20 = require("node:fs/promises");
68865
- var import_node_path23 = require("node:path");
69038
+ var import_promises19 = require("node:fs/promises");
69039
+ var import_node_path22 = require("node:path");
68866
69040
 
68867
69041
  // src/setup-service-discovery.ts
68868
- var import_node_path21 = require("node:path");
69042
+ var import_node_path20 = require("node:path");
68869
69043
  var IGNORED_ROOT_DIRECTORIES = /* @__PURE__ */ new Set([
68870
69044
  "apps",
68871
69045
  "contracts",
@@ -68961,36 +69135,36 @@ async function inferRuntime(rootDirectory, servicePath, packageJson, stat, prima
68961
69135
  return "Node.js";
68962
69136
  }
68963
69137
  for (const fileName of ["tsconfig.json", "tsconfig.base.json"]) {
68964
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, fileName), stat)) {
69138
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, fileName), stat)) {
68965
69139
  return "Node.js";
68966
69140
  }
68967
69141
  }
68968
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "requirements.txt"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "pyproject.toml"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "manage.py"), stat)) {
69142
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "requirements.txt"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "pyproject.toml"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "manage.py"), stat)) {
68969
69143
  return "Python";
68970
69144
  }
68971
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "composer.json"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "artisan"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "wp-config.php"), stat)) {
69145
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "composer.json"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "artisan"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "wp-config.php"), stat)) {
68972
69146
  return "PHP";
68973
69147
  }
68974
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "go.mod"), stat)) {
69148
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "go.mod"), stat)) {
68975
69149
  return "Go";
68976
69150
  }
68977
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "Gemfile"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "Gemfile.lock"), stat)) {
69151
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "Gemfile"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "Gemfile.lock"), stat)) {
68978
69152
  return "Ruby";
68979
69153
  }
68980
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "pom.xml"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "build.gradle"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "build.gradle.kts"), stat)) {
69154
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "pom.xml"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "build.gradle"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "build.gradle.kts"), stat)) {
68981
69155
  return "Java";
68982
69156
  }
68983
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "Cargo.toml"), stat)) {
69157
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "Cargo.toml"), stat)) {
68984
69158
  return "Rust";
68985
69159
  }
68986
69160
  return allowFallback ? inferRuntimeFromLanguages(primaryLanguages) : "unknown";
68987
69161
  }
68988
69162
  async function inferPythonFramework(rootDirectory, servicePath, readFile, stat) {
68989
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "manage.py"), stat)) {
69163
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "manage.py"), stat)) {
68990
69164
  return "Django";
68991
69165
  }
68992
69166
  for (const fileName of ["requirements.txt", "pyproject.toml"]) {
68993
- const filePath = (0, import_node_path21.join)(rootDirectory, servicePath, fileName);
69167
+ const filePath = (0, import_node_path20.join)(rootDirectory, servicePath, fileName);
68994
69168
  try {
68995
69169
  const contents = await readFile(filePath);
68996
69170
  if (/fastapi/iu.test(contents)) {
@@ -69008,39 +69182,39 @@ async function inferPythonFramework(rootDirectory, servicePath, readFile, stat)
69008
69182
  return "unknown";
69009
69183
  }
69010
69184
  async function inferPhpFramework(rootDirectory, servicePath, readFile, stat) {
69011
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "artisan"), stat)) {
69185
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "artisan"), stat)) {
69012
69186
  return "Laravel";
69013
69187
  }
69014
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "wp-config.php"), stat)) {
69188
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "wp-config.php"), stat)) {
69015
69189
  return "WordPress";
69016
69190
  }
69017
- if (await fileContains((0, import_node_path21.join)(rootDirectory, servicePath, "composer.json"), /laravel\/framework/iu, readFile)) {
69191
+ if (await fileContains((0, import_node_path20.join)(rootDirectory, servicePath, "composer.json"), /laravel\/framework/iu, readFile)) {
69018
69192
  return "Laravel";
69019
69193
  }
69020
- if (await fileContains((0, import_node_path21.join)(rootDirectory, servicePath, "composer.json"), /symfony\/(framework-bundle|http-kernel)/iu, readFile)) {
69194
+ if (await fileContains((0, import_node_path20.join)(rootDirectory, servicePath, "composer.json"), /symfony\/(framework-bundle|http-kernel)/iu, readFile)) {
69021
69195
  return "Symfony";
69022
69196
  }
69023
69197
  return "unknown";
69024
69198
  }
69025
69199
  async function inferRubyFramework(rootDirectory, servicePath, readFile, stat) {
69026
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "config", "application.rb"), stat)) {
69200
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "config", "application.rb"), stat)) {
69027
69201
  return "Rails";
69028
69202
  }
69029
- if (await fileContains((0, import_node_path21.join)(rootDirectory, servicePath, "Gemfile"), /gem\s+["']rails["']/iu, readFile)) {
69203
+ if (await fileContains((0, import_node_path20.join)(rootDirectory, servicePath, "Gemfile"), /gem\s+["']rails["']/iu, readFile)) {
69030
69204
  return "Rails";
69031
69205
  }
69032
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "config.ru"), stat) || await fileContains((0, import_node_path21.join)(rootDirectory, servicePath, "Gemfile"), /gem\s+["']rack["']/iu, readFile)) {
69206
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "config.ru"), stat) || await fileContains((0, import_node_path20.join)(rootDirectory, servicePath, "Gemfile"), /gem\s+["']rack["']/iu, readFile)) {
69033
69207
  return "Rack";
69034
69208
  }
69035
69209
  return "unknown";
69036
69210
  }
69037
69211
  async function inferJavaFramework(rootDirectory, servicePath, readFile, stat) {
69038
69212
  for (const fileName of ["pom.xml", "build.gradle", "build.gradle.kts"]) {
69039
- if (await fileContains((0, import_node_path21.join)(rootDirectory, servicePath, fileName), /spring-boot/iu, readFile)) {
69213
+ if (await fileContains((0, import_node_path20.join)(rootDirectory, servicePath, fileName), /spring-boot/iu, readFile)) {
69040
69214
  return "Spring Boot";
69041
69215
  }
69042
69216
  }
69043
- if (await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "src", "main", "webapp"), stat) || await pathExists5((0, import_node_path21.join)(rootDirectory, servicePath, "src", "main", "webapp", "WEB-INF", "web.xml"), stat)) {
69217
+ if (await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "src", "main", "webapp"), stat) || await pathExists5((0, import_node_path20.join)(rootDirectory, servicePath, "src", "main", "webapp", "WEB-INF", "web.xml"), stat)) {
69044
69218
  return "Servlet";
69045
69219
  }
69046
69220
  return "unknown";
@@ -69088,13 +69262,13 @@ function inferServiceKind(serviceName, servicePath, framework, packageJson) {
69088
69262
  return "backend";
69089
69263
  }
69090
69264
  async function buildDetectedService(rootDirectory, servicePath, readFile, stat, fallbackPackageJson, primaryLanguages, allowFallback) {
69091
- const packageJson = await readJsonFile2((0, import_node_path21.join)(rootDirectory, servicePath, "package.json"), readFile);
69265
+ const packageJson = await readJsonFile2((0, import_node_path20.join)(rootDirectory, servicePath, "package.json"), readFile);
69092
69266
  const runtime = await inferRuntime(rootDirectory, servicePath, packageJson, stat, primaryLanguages, allowFallback);
69093
69267
  if (runtime === "unknown" && !allowFallback) {
69094
69268
  return null;
69095
69269
  }
69096
69270
  const framework = await inferServiceFramework(rootDirectory, servicePath, runtime, packageJson, readFile, stat, fallbackPackageJson, allowFallback);
69097
- const name = packageJson?.name ?? (0, import_node_path21.basename)(servicePath);
69271
+ const name = packageJson?.name ?? (0, import_node_path20.basename)(servicePath);
69098
69272
  return {
69099
69273
  name,
69100
69274
  kind: inferServiceKind(name, servicePath, framework, packageJson),
@@ -69112,12 +69286,12 @@ async function detectRootServicePaths(rootDirectory, readdir, stat) {
69112
69286
  if (entry.startsWith(".") || IGNORED_ROOT_DIRECTORIES.has(entry)) {
69113
69287
  continue;
69114
69288
  }
69115
- const entryPath = (0, import_node_path21.join)(rootDirectory, entry);
69289
+ const entryPath = (0, import_node_path20.join)(rootDirectory, entry);
69116
69290
  const entryStats = await stat(entryPath);
69117
69291
  if (!entryStats.isDirectory()) {
69118
69292
  continue;
69119
69293
  }
69120
- if (await pathExists5((0, import_node_path21.join)(entryPath, "package.json"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "requirements.txt"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "pyproject.toml"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "manage.py"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "composer.json"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "artisan"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "wp-config.php"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "go.mod"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "Gemfile"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "Gemfile.lock"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "pom.xml"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "build.gradle"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "build.gradle.kts"), stat) || await pathExists5((0, import_node_path21.join)(entryPath, "Cargo.toml"), stat)) {
69294
+ if (await pathExists5((0, import_node_path20.join)(entryPath, "package.json"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "requirements.txt"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "pyproject.toml"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "manage.py"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "composer.json"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "artisan"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "wp-config.php"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "go.mod"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "Gemfile"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "Gemfile.lock"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "pom.xml"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "build.gradle"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "build.gradle.kts"), stat) || await pathExists5((0, import_node_path20.join)(entryPath, "Cargo.toml"), stat)) {
69121
69295
  servicePaths.push(entry);
69122
69296
  }
69123
69297
  }
@@ -69125,11 +69299,11 @@ async function detectRootServicePaths(rootDirectory, readdir, stat) {
69125
69299
  }
69126
69300
  async function detectServices(rootDirectory, readdir, readFile, stat, packageJson, primaryLanguages) {
69127
69301
  const services = [];
69128
- const appsDirectory = (0, import_node_path21.join)(rootDirectory, "apps");
69302
+ const appsDirectory = (0, import_node_path20.join)(rootDirectory, "apps");
69129
69303
  if (await pathExists5(appsDirectory, stat)) {
69130
69304
  const entries2 = (await readdir(appsDirectory)).sort();
69131
69305
  for (const entry of entries2) {
69132
- const entryPath = (0, import_node_path21.join)(appsDirectory, entry);
69306
+ const entryPath = (0, import_node_path20.join)(appsDirectory, entry);
69133
69307
  const entryStats = await stat(entryPath);
69134
69308
  if (!entryStats.isDirectory()) {
69135
69309
  continue;
@@ -69166,7 +69340,7 @@ async function detectServices(rootDirectory, readdir, readFile, stat, packageJso
69166
69340
  }
69167
69341
 
69168
69342
  // src/setup-relay-guidance.ts
69169
- var import_node_path22 = require("node:path");
69343
+ var import_node_path21 = require("node:path");
69170
69344
  var RELAY_ROUTE_PATH = "/debugbundle/browser";
69171
69345
  var WORDPRESS_RELAY_ROUTE_PATH = "/wp-json/debugbundle/v1/browser";
69172
69346
  async function pathExists6(filePath, stat) {
@@ -69192,7 +69366,7 @@ async function readJsonFile3(filePath, readFile) {
69192
69366
  }
69193
69367
  async function readPackageJsonForService(rootDirectory, servicePath, readFile) {
69194
69368
  const normalizedServicePath = servicePath === "." ? "" : servicePath ?? "";
69195
- return readJsonFile3((0, import_node_path22.join)(rootDirectory, normalizedServicePath, "package.json"), readFile);
69369
+ return readJsonFile3((0, import_node_path21.join)(rootDirectory, normalizedServicePath, "package.json"), readFile);
69196
69370
  }
69197
69371
  function collectDependencyNames2(packageJson) {
69198
69372
  return /* @__PURE__ */ new Set([
@@ -69273,9 +69447,9 @@ function buildInstructionOnlyGuidance(backendService, frontendServices, runtimeI
69273
69447
  }
69274
69448
  async function scaffoldFastifyRelayRoute(rootDirectory, servicePath, dependencies, frontendServices, backendService) {
69275
69449
  const candidatePath = await findFirstExistingPath([
69276
- (0, import_node_path22.join)(rootDirectory, servicePath, "src", "server.ts"),
69277
- (0, import_node_path22.join)(rootDirectory, servicePath, "src", "main.ts"),
69278
- (0, import_node_path22.join)(rootDirectory, servicePath, "server.ts")
69450
+ (0, import_node_path21.join)(rootDirectory, servicePath, "src", "server.ts"),
69451
+ (0, import_node_path21.join)(rootDirectory, servicePath, "src", "main.ts"),
69452
+ (0, import_node_path21.join)(rootDirectory, servicePath, "server.ts")
69279
69453
  ], dependencies.stat);
69280
69454
  if (candidatePath === null) {
69281
69455
  return buildInstructionOnlyGuidance(
@@ -69315,9 +69489,9 @@ async function scaffoldFastifyRelayRoute(rootDirectory, servicePath, dependencie
69315
69489
  }
69316
69490
  async function scaffoldExpressRelayRoute(rootDirectory, servicePath, dependencies, frontendServices, backendService) {
69317
69491
  const candidatePath = await findFirstExistingPath([
69318
- (0, import_node_path22.join)(rootDirectory, servicePath, "src", "server.ts"),
69319
- (0, import_node_path22.join)(rootDirectory, servicePath, "src", "app.ts"),
69320
- (0, import_node_path22.join)(rootDirectory, servicePath, "server.ts")
69492
+ (0, import_node_path21.join)(rootDirectory, servicePath, "src", "server.ts"),
69493
+ (0, import_node_path21.join)(rootDirectory, servicePath, "src", "app.ts"),
69494
+ (0, import_node_path21.join)(rootDirectory, servicePath, "server.ts")
69321
69495
  ], dependencies.stat);
69322
69496
  if (candidatePath === null) {
69323
69497
  return buildInstructionOnlyGuidance(
@@ -69357,8 +69531,8 @@ async function scaffoldExpressRelayRoute(rootDirectory, servicePath, dependencie
69357
69531
  }
69358
69532
  async function scaffoldNextJsRelayRoute(rootDirectory, servicePath, dependencies, frontendServices, backendService) {
69359
69533
  const candidateAppRoot = await findFirstExistingPath([
69360
- (0, import_node_path22.join)(rootDirectory, servicePath, "app"),
69361
- (0, import_node_path22.join)(rootDirectory, servicePath, "src", "app")
69534
+ (0, import_node_path21.join)(rootDirectory, servicePath, "app"),
69535
+ (0, import_node_path21.join)(rootDirectory, servicePath, "src", "app")
69362
69536
  ], dependencies.stat);
69363
69537
  if (candidateAppRoot === null) {
69364
69538
  return buildInstructionOnlyGuidance(
@@ -69367,8 +69541,8 @@ async function scaffoldNextJsRelayRoute(rootDirectory, servicePath, dependencies
69367
69541
  `Add app/debugbundle/browser/route.ts in ${servicePath} and export debugBundleRelay as POST from @debugbundle/sdk-node/relay/nextjs.`
69368
69542
  );
69369
69543
  }
69370
- const routeDirectory = (0, import_node_path22.join)(candidateAppRoot, "debugbundle", "browser");
69371
- const routePath = (0, import_node_path22.join)(routeDirectory, "route.ts");
69544
+ const routeDirectory = (0, import_node_path21.join)(candidateAppRoot, "debugbundle", "browser");
69545
+ const routePath = (0, import_node_path21.join)(routeDirectory, "route.ts");
69372
69546
  await dependencies.mkdir(routeDirectory, { recursive: true });
69373
69547
  await dependencies.writeFile(routePath, 'export { debugBundleRelay as POST } from "@debugbundle/sdk-node/relay/nextjs";\n');
69374
69548
  return {
@@ -69537,10 +69711,10 @@ async function resolveRelaySetup(rootDirectory, services, selectedTargetNames, r
69537
69711
  }
69538
69712
 
69539
69713
  // src/setup-target-selection.ts
69540
- var import_promises19 = require("node:readline/promises");
69714
+ var import_promises18 = require("node:readline/promises");
69541
69715
  var import_node_process3 = require("node:process");
69542
69716
  function defaultPromptUser(prompt) {
69543
- const terminal = (0, import_promises19.createInterface)({ input: import_node_process3.stdin, output: import_node_process3.stdout });
69717
+ const terminal = (0, import_promises18.createInterface)({ input: import_node_process3.stdin, output: import_node_process3.stdout });
69544
69718
  return terminal.question(prompt).finally(() => {
69545
69719
  terminal.close();
69546
69720
  });
@@ -69655,41 +69829,41 @@ function detectPackageManagers(rootDirectory, packageJson, existingPaths) {
69655
69829
  if (declaredPackageManager === "yarn") {
69656
69830
  packageManagers.add("yarn");
69657
69831
  }
69658
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "pnpm-lock.yaml")) || existingPaths.has((0, import_node_path23.join)(rootDirectory, "pnpm-workspace.yaml"))) {
69832
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "pnpm-lock.yaml")) || existingPaths.has((0, import_node_path22.join)(rootDirectory, "pnpm-workspace.yaml"))) {
69659
69833
  packageManagers.add("pnpm");
69660
69834
  }
69661
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "package-lock.json"))) {
69835
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "package-lock.json"))) {
69662
69836
  packageManagers.add("npm");
69663
69837
  }
69664
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "yarn.lock"))) {
69838
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "yarn.lock"))) {
69665
69839
  packageManagers.add("yarn");
69666
69840
  }
69667
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "poetry.lock")) || existingPaths.has((0, import_node_path23.join)(rootDirectory, "pyproject.toml"))) {
69841
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "poetry.lock")) || existingPaths.has((0, import_node_path22.join)(rootDirectory, "pyproject.toml"))) {
69668
69842
  packageManagers.add("poetry");
69669
69843
  }
69670
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "composer.json"))) {
69844
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "composer.json"))) {
69671
69845
  packageManagers.add("composer");
69672
69846
  }
69673
69847
  return [...packageManagers].sort();
69674
69848
  }
69675
69849
  function detectPrimaryLanguages(rootDirectory, existingPaths) {
69676
69850
  const languages = /* @__PURE__ */ new Set();
69677
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "tsconfig.json")) || existingPaths.has((0, import_node_path23.join)(rootDirectory, "tsconfig.base.json"))) {
69851
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "tsconfig.json")) || existingPaths.has((0, import_node_path22.join)(rootDirectory, "tsconfig.base.json"))) {
69678
69852
  languages.add("TypeScript");
69679
- } else if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "package.json"))) {
69853
+ } else if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "package.json"))) {
69680
69854
  languages.add("JavaScript");
69681
69855
  }
69682
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "pyproject.toml"))) {
69856
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "pyproject.toml"))) {
69683
69857
  languages.add("Python");
69684
69858
  }
69685
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "composer.json"))) {
69859
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "composer.json"))) {
69686
69860
  languages.add("PHP");
69687
69861
  }
69688
69862
  return [...languages].sort();
69689
69863
  }
69690
69864
  function detectDeploymentTargets(rootDirectory, existingPaths) {
69691
69865
  const targets = /* @__PURE__ */ new Set();
69692
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "docker-compose.yml")) || existingPaths.has((0, import_node_path23.join)(rootDirectory, "deploy", "selfhost", "docker-compose.yml"))) {
69866
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "docker-compose.yml")) || existingPaths.has((0, import_node_path22.join)(rootDirectory, "deploy", "selfhost", "docker-compose.yml"))) {
69693
69867
  targets.add("docker-compose");
69694
69868
  }
69695
69869
  return [...targets].sort();
@@ -69699,7 +69873,7 @@ function detectDeveloperWorkflow(packageJson, workflowName, existingPaths, rootD
69699
69873
  if (typeof packageScript === "string" && packageScript.length > 0) {
69700
69874
  return packageScript;
69701
69875
  }
69702
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "Makefile"))) {
69876
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "Makefile"))) {
69703
69877
  return `make ${workflowName}`;
69704
69878
  }
69705
69879
  return "manual";
@@ -69720,7 +69894,7 @@ function detectInstallWorkflow(packageManagers, existingPaths, rootDirectory) {
69720
69894
  if (packageManagers.includes("composer")) {
69721
69895
  return "composer install";
69722
69896
  }
69723
- if (existingPaths.has((0, import_node_path23.join)(rootDirectory, "Makefile"))) {
69897
+ if (existingPaths.has((0, import_node_path22.join)(rootDirectory, "Makefile"))) {
69724
69898
  return "make install";
69725
69899
  }
69726
69900
  return "manual";
@@ -69753,7 +69927,7 @@ async function detectRootPaths(rootDirectory, readdir, stat) {
69753
69927
  if (entry.startsWith(".") || entry === "node_modules") {
69754
69928
  continue;
69755
69929
  }
69756
- const entryStats = await stat((0, import_node_path23.join)(rootDirectory, entry));
69930
+ const entryStats = await stat((0, import_node_path22.join)(rootDirectory, entry));
69757
69931
  if (entryStats.isDirectory()) {
69758
69932
  rootPaths.push(entry);
69759
69933
  }
@@ -69763,8 +69937,8 @@ async function detectRootPaths(rootDirectory, readdir, stat) {
69763
69937
  async function detectInfrastructure(rootDirectory, readFile) {
69764
69938
  const composeContents = [];
69765
69939
  for (const candidatePath of [
69766
- (0, import_node_path23.join)(rootDirectory, "docker-compose.yml"),
69767
- (0, import_node_path23.join)(rootDirectory, "deploy", "selfhost", "docker-compose.yml")
69940
+ (0, import_node_path22.join)(rootDirectory, "docker-compose.yml"),
69941
+ (0, import_node_path22.join)(rootDirectory, "deploy", "selfhost", "docker-compose.yml")
69768
69942
  ]) {
69769
69943
  try {
69770
69944
  composeContents.push(await readFile(candidatePath));
@@ -69796,21 +69970,21 @@ async function detectInfrastructure(rootDirectory, readFile) {
69796
69970
  };
69797
69971
  }
69798
69972
  async function buildProfile(rootDirectory, dependencies) {
69799
- const packageJson = await readJsonFile4((0, import_node_path23.join)(rootDirectory, "package.json"), dependencies.readFile);
69973
+ const packageJson = await readJsonFile4((0, import_node_path22.join)(rootDirectory, "package.json"), dependencies.readFile);
69800
69974
  const existingPaths = /* @__PURE__ */ new Set([
69801
- (0, import_node_path23.join)(rootDirectory, "package.json"),
69802
- (0, import_node_path23.join)(rootDirectory, "pnpm-lock.yaml"),
69803
- (0, import_node_path23.join)(rootDirectory, "pnpm-workspace.yaml"),
69804
- (0, import_node_path23.join)(rootDirectory, "package-lock.json"),
69805
- (0, import_node_path23.join)(rootDirectory, "yarn.lock"),
69806
- (0, import_node_path23.join)(rootDirectory, "poetry.lock"),
69807
- (0, import_node_path23.join)(rootDirectory, "pyproject.toml"),
69808
- (0, import_node_path23.join)(rootDirectory, "composer.json"),
69809
- (0, import_node_path23.join)(rootDirectory, "docker-compose.yml"),
69810
- (0, import_node_path23.join)(rootDirectory, "deploy", "selfhost", "docker-compose.yml"),
69811
- (0, import_node_path23.join)(rootDirectory, "Makefile"),
69812
- (0, import_node_path23.join)(rootDirectory, "tsconfig.json"),
69813
- (0, import_node_path23.join)(rootDirectory, "tsconfig.base.json")
69975
+ (0, import_node_path22.join)(rootDirectory, "package.json"),
69976
+ (0, import_node_path22.join)(rootDirectory, "pnpm-lock.yaml"),
69977
+ (0, import_node_path22.join)(rootDirectory, "pnpm-workspace.yaml"),
69978
+ (0, import_node_path22.join)(rootDirectory, "package-lock.json"),
69979
+ (0, import_node_path22.join)(rootDirectory, "yarn.lock"),
69980
+ (0, import_node_path22.join)(rootDirectory, "poetry.lock"),
69981
+ (0, import_node_path22.join)(rootDirectory, "pyproject.toml"),
69982
+ (0, import_node_path22.join)(rootDirectory, "composer.json"),
69983
+ (0, import_node_path22.join)(rootDirectory, "docker-compose.yml"),
69984
+ (0, import_node_path22.join)(rootDirectory, "deploy", "selfhost", "docker-compose.yml"),
69985
+ (0, import_node_path22.join)(rootDirectory, "Makefile"),
69986
+ (0, import_node_path22.join)(rootDirectory, "tsconfig.json"),
69987
+ (0, import_node_path22.join)(rootDirectory, "tsconfig.base.json")
69814
69988
  ]);
69815
69989
  const confirmedExistingPaths = /* @__PURE__ */ new Set();
69816
69990
  for (const candidatePath of existingPaths) {
@@ -69860,21 +70034,21 @@ async function buildProfile(rootDirectory, dependencies) {
69860
70034
  async function setupCommand(input3, dependencies = {}) {
69861
70035
  const cwd = dependencies.cwd ?? (() => process.cwd());
69862
70036
  const mkdir5 = dependencies.mkdir ?? (async (path, options) => {
69863
- await (0, import_promises20.mkdir)(path, options);
70037
+ await (0, import_promises19.mkdir)(path, options);
69864
70038
  });
69865
- const readFile = dependencies.readFile ?? (async (path) => (0, import_promises20.readFile)(path, "utf8"));
69866
- const readdir = dependencies.readdir ?? (async (path) => (0, import_promises20.readdir)(path));
69867
- const stat = dependencies.stat ?? (async (path) => (0, import_promises20.stat)(path));
69868
- const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises20.writeFile)(path, content, "utf8"));
70039
+ const readFile = dependencies.readFile ?? (async (path) => (0, import_promises19.readFile)(path, "utf8"));
70040
+ const readdir = dependencies.readdir ?? (async (path) => (0, import_promises19.readdir)(path));
70041
+ const stat = dependencies.stat ?? (async (path) => (0, import_promises19.stat)(path));
70042
+ const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises19.writeFile)(path, content, "utf8"));
69869
70043
  const now = dependencies.now ?? (() => /* @__PURE__ */ new Date());
69870
70044
  try {
69871
70045
  const rootDirectory = await projectRoot(cwd());
69872
70046
  const selectedAgents = await chooseAgents(rootDirectory, input3, dependencies);
69873
- const packageJson = await readJsonFile4((0, import_node_path23.join)(rootDirectory, "package.json"), readFile);
70047
+ const packageJson = await readJsonFile4((0, import_node_path22.join)(rootDirectory, "package.json"), readFile);
69874
70048
  for (const filePath of [...GENERATED_FILE_PATHS, GITIGNORE_FILE_PATH]) await safePath(rootDirectory, filePath);
69875
70049
  for (const directoryPath of ENSURED_DIRECTORY_PATHS) {
69876
70050
  await safePath(rootDirectory, directoryPath);
69877
- await mkdir5((0, import_node_path23.join)(rootDirectory, directoryPath), { recursive: true });
70051
+ await mkdir5((0, import_node_path22.join)(rootDirectory, directoryPath), { recursive: true });
69878
70052
  }
69879
70053
  const profile = await buildProfile(rootDirectory, {
69880
70054
  now,
@@ -69892,11 +70066,11 @@ async function setupCommand(input3, dependencies = {}) {
69892
70066
  if (!preservedProfile) {
69893
70067
  const contents = `${JSON.stringify(profile, null, 2)}
69894
70068
  `;
69895
- if (dependencies.writeFile) await dependencies.writeFile((0, import_node_path23.join)(rootDirectory, PROFILE_FILE_PATH), contents);
70069
+ if (dependencies.writeFile) await dependencies.writeFile((0, import_node_path22.join)(rootDirectory, PROFILE_FILE_PATH), contents);
69896
70070
  else await writeManaged(rootDirectory, PROFILE_FILE_PATH, contents, void 0);
69897
70071
  }
69898
70072
  if (!preservedConnection) {
69899
- if (dependencies.writeFile) await dependencies.writeFile((0, import_node_path23.join)(rootDirectory, CONNECTION_FILE_PATH), buildConnectionConfig());
70073
+ if (dependencies.writeFile) await dependencies.writeFile((0, import_node_path22.join)(rootDirectory, CONNECTION_FILE_PATH), buildConnectionConfig());
69900
70074
  else await writeManaged(rootDirectory, CONNECTION_FILE_PATH, buildConnectionConfig(), void 0);
69901
70075
  }
69902
70076
  const agentReport = await manageAgentSetup({ root: rootDirectory, files: canonicalFiles(), legacyHashes: legacy_skill_hashes_default, instruction: buildManagedAgentsSection(), fix: true, legacyInstructions: true, ...selectedAgents === void 0 ? {} : { selected: selectedAgents } });
@@ -71335,14 +71509,14 @@ async function listServicesWithAuthCommand(input3, dependencies) {
71335
71509
  }
71336
71510
 
71337
71511
  // src/project-adoption-commands.ts
71338
- var import_node_path25 = require("node:path");
71512
+ var import_node_path24 = require("node:path");
71339
71513
 
71340
71514
  // ../../packages/project-adoption/src/index.ts
71341
71515
  var import_node_fs3 = require("node:fs");
71342
- var import_promises21 = require("node:fs/promises");
71516
+ var import_promises20 = require("node:fs/promises");
71343
71517
  var import_node_crypto9 = require("node:crypto");
71344
- var import_node_path24 = require("node:path");
71345
- var paths = [".debugbundle/local/connection.json", ".debugbundle/profile.json"];
71518
+ var import_node_path23 = require("node:path");
71519
+ var paths2 = [".debugbundle/local/connection.json", ".debugbundle/profile.json"];
71346
71520
  var digest3 = external_exports.string().regex(/^[a-f0-9]{64}$/);
71347
71521
  var changeSchema = external_exports.object({ pointer: external_exports.string(), before: external_exports.string().nullable(), after: external_exports.string().nullable() }).strict();
71348
71522
  var planBody = external_exports.object({
@@ -71354,7 +71528,7 @@ var planBody = external_exports.object({
71354
71528
  manifest_digest: digest3,
71355
71529
  files: external_exports.array(
71356
71530
  external_exports.object({
71357
- path: external_exports.enum(paths),
71531
+ path: external_exports.enum(paths2),
71358
71532
  before_sha256: digest3,
71359
71533
  after_sha256: digest3,
71360
71534
  changes: external_exports.array(changeSchema)
@@ -71381,20 +71555,20 @@ function manifestFor(input3) {
71381
71555
  fail("adoption_manifest_stale");
71382
71556
  return { operation, manifest };
71383
71557
  }
71384
- async function hierarchy(root, relative6) {
71385
- if ((0, import_node_path24.resolve)(root) !== root || await (0, import_promises21.realpath)(root) !== root) fail("adoption_unsafe_path");
71558
+ async function hierarchy(root, relative8) {
71559
+ if ((0, import_node_path23.resolve)(root) !== root || await (0, import_promises20.realpath)(root) !== root) fail("adoption_unsafe_path");
71386
71560
  try {
71387
- await safePath(root, relative6);
71561
+ await safePath(root, relative8);
71388
71562
  } catch {
71389
71563
  fail("adoption_unsafe_path");
71390
71564
  }
71391
71565
  }
71392
71566
  async function read(root, path) {
71393
71567
  await hierarchy(root, path);
71394
- const full = (0, import_node_path24.join)(root, path), before = await (0, import_promises21.lstat)(full);
71568
+ const full = (0, import_node_path23.join)(root, path), before = await (0, import_promises20.lstat)(full);
71395
71569
  if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1)
71396
71570
  fail("adoption_unsafe_path");
71397
- const file2 = await (0, import_promises21.open)(full, import_node_fs3.constants.O_RDONLY | import_node_fs3.constants.O_NOFOLLOW | import_node_fs3.constants.O_NONBLOCK);
71571
+ const file2 = await (0, import_promises20.open)(full, import_node_fs3.constants.O_RDONLY | import_node_fs3.constants.O_NOFOLLOW | import_node_fs3.constants.O_NONBLOCK);
71398
71572
  try {
71399
71573
  const info = await file2.stat();
71400
71574
  if (!info.isFile() || info.dev !== before.dev || info.ino !== before.ino || info.size > 1024 * 1024)
@@ -71434,7 +71608,7 @@ function child(parent, key) {
71434
71608
  }
71435
71609
  function render(file2, manifest, original, operationId) {
71436
71610
  const document = structuredClone(file2.data), changes = [];
71437
- if (file2.path === paths[0]) {
71611
+ if (file2.path === paths2[0]) {
71438
71612
  const parsed = ConnectionConfigSchema.safeParse(document);
71439
71613
  if (!parsed.success || parsed.data.mode !== "connected" || !manifest.origin_project_ids.includes(parsed.data.cloud_project_id ?? ""))
71440
71614
  fail("adoption_workspace_not_in_merge");
@@ -71489,7 +71663,7 @@ function render(file2, manifest, original, operationId) {
71489
71663
  }
71490
71664
  async function previewProjectAdoption(input3) {
71491
71665
  const { operation, manifest } = manifestFor(input3.operation);
71492
- const files = await Promise.all(paths.map((path) => read(input3.workspace_root, path)));
71666
+ const files = await Promise.all(paths2.map((path) => read(input3.workspace_root, path)));
71493
71667
  let original = files[0].data["cloud_project_id"];
71494
71668
  if (typeof original !== "string" || !manifest.origin_project_ids.includes(original))
71495
71669
  fail("adoption_workspace_not_in_merge");
@@ -71518,9 +71692,9 @@ async function previewProjectAdoption(input3) {
71518
71692
  return { ...body, plan_digest: hash2(JSON.stringify(body)) };
71519
71693
  }
71520
71694
  async function replace(root, snapshot, bytes, expectedHash) {
71521
- const path = (0, import_node_path24.join)(root, snapshot.path), temporary = (0, import_node_path24.join)((0, import_node_path24.dirname)(path), `.debugbundle-adoption-${(0, import_node_crypto9.randomBytes)(16).toString("hex")}.tmp`);
71695
+ const path = (0, import_node_path23.join)(root, snapshot.path), temporary = (0, import_node_path23.join)((0, import_node_path23.dirname)(path), `.debugbundle-adoption-${(0, import_node_crypto9.randomBytes)(16).toString("hex")}.tmp`);
71522
71696
  await hierarchy(root, snapshot.path);
71523
- const handle = await (0, import_promises21.open)(
71697
+ const handle = await (0, import_promises20.open)(
71524
71698
  temporary,
71525
71699
  import_node_fs3.constants.O_WRONLY | import_node_fs3.constants.O_CREAT | import_node_fs3.constants.O_EXCL | import_node_fs3.constants.O_NOFOLLOW,
71526
71700
  384
@@ -71538,10 +71712,10 @@ async function replace(root, snapshot, bytes, expectedHash) {
71538
71712
  if (hash2(current.bytes) !== expectedHash || current.dev !== snapshot.dev || current.ino !== snapshot.ino)
71539
71713
  fail("adoption_file_changed");
71540
71714
  await hierarchy(root, snapshot.path);
71541
- await (0, import_promises21.rename)(temporary, path);
71715
+ await (0, import_promises20.rename)(temporary, path);
71542
71716
  return { ...snapshot, bytes, dev: placed.dev, ino: placed.ino };
71543
71717
  } finally {
71544
- await (0, import_promises21.unlink)(temporary).catch(() => void 0);
71718
+ await (0, import_promises20.unlink)(temporary).catch(() => void 0);
71545
71719
  }
71546
71720
  }
71547
71721
  async function applyProjectAdoption(input3, hooks = {}) {
@@ -71553,9 +71727,9 @@ async function applyProjectAdoption(input3, hooks = {}) {
71553
71727
  const { operation, manifest } = manifestFor(input3.operation);
71554
71728
  if (operation.operation_id !== plan.operation_id || operation.canonical_project_id !== plan.canonical_project_id || hash2(JSON.stringify(manifest)) !== plan.manifest_digest || !manifest.origin_project_ids.includes(plan.original_project_id))
71555
71729
  fail("adoption_manifest_stale");
71556
- await hierarchy(plan.workspace_root, paths[0]);
71557
- const lockPath = (0, import_node_path24.join)(plan.workspace_root, ".debugbundle/adoption.lock");
71558
- const lock = await (0, import_promises21.open)(
71730
+ await hierarchy(plan.workspace_root, paths2[0]);
71731
+ const lockPath = (0, import_node_path23.join)(plan.workspace_root, ".debugbundle/adoption.lock");
71732
+ const lock = await (0, import_promises20.open)(
71559
71733
  lockPath,
71560
71734
  import_node_fs3.constants.O_WRONLY | import_node_fs3.constants.O_CREAT | import_node_fs3.constants.O_EXCL | import_node_fs3.constants.O_NOFOLLOW,
71561
71735
  384
@@ -71618,10 +71792,10 @@ async function applyProjectAdoption(input3, hooks = {}) {
71618
71792
  } finally {
71619
71793
  await lock.close();
71620
71794
  await hierarchy(plan.workspace_root, ".debugbundle/adoption.lock");
71621
- const current = await (0, import_promises21.lstat)(lockPath).catch(() => null);
71795
+ const current = await (0, import_promises20.lstat)(lockPath).catch(() => null);
71622
71796
  if (!lockIdentity || !current?.isFile() || current.nlink !== 1 || current.dev !== lockIdentity.dev || current.ino !== lockIdentity.ino)
71623
71797
  fail("adoption_lock_changed_review_required");
71624
- await (0, import_promises21.unlink)(lockPath);
71798
+ await (0, import_promises20.unlink)(lockPath);
71625
71799
  }
71626
71800
  }
71627
71801
 
@@ -71711,7 +71885,7 @@ function createProjectMergesApi(client) {
71711
71885
  }
71712
71886
 
71713
71887
  // src/project-merge-commands.ts
71714
- var import_promises22 = require("node:fs/promises");
71888
+ var import_promises21 = require("node:fs/promises");
71715
71889
  async function projectMergeWithAuthCommand(input3, dependencies = {}) {
71716
71890
  try {
71717
71891
  const auth2 = await (dependencies.readAuthState ?? readCliAuthState)(
@@ -71737,7 +71911,7 @@ async function projectMergeWithAuthCommand(input3, dependencies = {}) {
71737
71911
  async function readProjectMergeJson(path, maximumBytes = 4 * 1024 * 1024) {
71738
71912
  let file2;
71739
71913
  try {
71740
- file2 = await (0, import_promises22.open)(path, "r");
71914
+ file2 = await (0, import_promises21.open)(path, "r");
71741
71915
  const info = await file2.stat();
71742
71916
  if (!info.isFile() || info.size > maximumBytes) throw new Error("invalid");
71743
71917
  const buffer = Buffer.alloc(maximumBytes + 1);
@@ -71855,7 +72029,7 @@ async function handleProjectAdoptionCommand(argv, run = projectAdoptionWithAuthC
71855
72029
  if (action === "preview") {
71856
72030
  expectNoUnknownOptions(argv, [...common, "operation-id", "workspace-root"]);
71857
72031
  const operation_id = option("operation-id"), workspace_root = option("workspace-root");
71858
- if (!external_exports.string().guid().safeParse(operation_id).success || !(0, import_node_path25.isAbsolute)(workspace_root) || (0, import_node_path25.resolve)(workspace_root) !== workspace_root)
72032
+ if (!external_exports.string().guid().safeParse(operation_id).success || !(0, import_node_path24.isAbsolute)(workspace_root) || (0, import_node_path24.resolve)(workspace_root) !== workspace_root)
71859
72033
  throw new CliInputError(
71860
72034
  "Provide a valid operation ID and one canonical absolute workspace root."
71861
72035
  );
@@ -72178,8 +72352,8 @@ function formatCloudResult(input3, exitCode, checks, errors, incidentId, verific
72178
72352
 
72179
72353
  // src/verify-command.ts
72180
72354
  var import_node_crypto10 = require("node:crypto");
72181
- var import_promises23 = require("node:fs/promises");
72182
- var import_node_path26 = require("node:path");
72355
+ var import_promises22 = require("node:fs/promises");
72356
+ var import_node_path25 = require("node:path");
72183
72357
  function localFailureStepName(checks) {
72184
72358
  let hasLocalProcessing = false;
72185
72359
  let hasIncidentRetrieval = false;
@@ -72382,10 +72556,10 @@ function buildVerificationEvent(now, projectId) {
72382
72556
  };
72383
72557
  }
72384
72558
  async function writeVerificationEventBatch(input3, dependencies) {
72385
- const eventDirectory = (0, import_node_path26.join)(input3.rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH4);
72559
+ const eventDirectory = (0, import_node_path25.join)(input3.rootDirectory, LOCAL_EVENTS_DIRECTORY_PATH4);
72386
72560
  await dependencies.mkdir(eventDirectory, { recursive: true });
72387
72561
  const fileName = buildEventFileName([input3.event], `debugbundle-verify-local-${input3.runId}`);
72388
- const destinationPath = (0, import_node_path26.join)(eventDirectory, fileName);
72562
+ const destinationPath = (0, import_node_path25.join)(eventDirectory, fileName);
72389
72563
  const temporaryPath = `${destinationPath}.tmp`;
72390
72564
  await dependencies.writeFile(temporaryPath, `${JSON.stringify([input3.event], null, 2)}
72391
72565
  `);
@@ -72395,14 +72569,14 @@ async function writeVerificationEventBatch(input3, dependencies) {
72395
72569
  async function verifyLocalCommand(input3, dependencies = {}) {
72396
72570
  const cwd = dependencies.cwd ?? (() => process.cwd());
72397
72571
  const mkdir5 = dependencies.mkdir ?? (async (path, options) => {
72398
- await (0, import_promises23.mkdir)(path, options);
72572
+ await (0, import_promises22.mkdir)(path, options);
72399
72573
  });
72400
72574
  const now = dependencies.now ?? (() => /* @__PURE__ */ new Date());
72401
72575
  const processLocal = dependencies.processCommand ?? processCommand;
72402
72576
  const readVerifiedLocalState = dependencies.readLocalState ?? readLocalState;
72403
72577
  const readVerifiedLocalBundle = dependencies.getLocalBundle ?? getLocalBundle;
72404
- const rename4 = dependencies.rename ?? (async (sourcePath, destinationPath) => (0, import_promises23.rename)(sourcePath, destinationPath));
72405
- const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises23.writeFile)(path, content, "utf8"));
72578
+ const rename4 = dependencies.rename ?? (async (sourcePath, destinationPath) => (0, import_promises22.rename)(sourcePath, destinationPath));
72579
+ const writeFile = dependencies.writeFile ?? (async (path, content) => (0, import_promises22.writeFile)(path, content, "utf8"));
72406
72580
  const checks = [];
72407
72581
  function finalize2(exitCode, errors, incidentId) {
72408
72582
  return formatResult(input3, exitCode, checks, errors, incidentId);
@@ -72423,7 +72597,7 @@ async function verifyLocalCommand(input3, dependencies = {}) {
72423
72597
  });
72424
72598
  try {
72425
72599
  const rootDirectory = cwd();
72426
- const profile = await readProfile(rootDirectory, async (path) => (0, import_promises23.readFile)(path, "utf8"));
72600
+ const profile = await readProfile(rootDirectory, async (path) => (0, import_promises22.readFile)(path, "utf8"));
72427
72601
  const projectId = buildProjectId(profile);
72428
72602
  const verificationNow = now();
72429
72603
  const runId = verificationNow.toISOString().replace(/[-:.TZ]/g, "").slice(0, 14);
@@ -73178,8 +73352,8 @@ function formatUsage() {
73178
73352
  }
73179
73353
 
73180
73354
  // src/validate-command.ts
73181
- var import_promises24 = require("node:fs/promises");
73182
- var import_node_path27 = require("node:path");
73355
+ var import_promises23 = require("node:fs/promises");
73356
+ var import_node_path26 = require("node:path");
73183
73357
  var SUGGESTED_ACTIONS2 = [
73184
73358
  "Run debugbundle setup if .debugbundle/profile.json is missing.",
73185
73359
  "Run debugbundle profile validate for field-level profile errors.",
@@ -73285,22 +73459,22 @@ function buildValidateJsonOutput(checks, profileErrors, autoFixAvailable) {
73285
73459
  });
73286
73460
  }
73287
73461
  async function fixMissingFile(rootDirectory, filePath, buildContent, dependencies) {
73288
- const absoluteFilePath = (0, import_node_path27.join)(rootDirectory, filePath);
73289
- await dependencies.mkdir((0, import_node_path27.dirname)(absoluteFilePath), { recursive: true });
73462
+ const absoluteFilePath = (0, import_node_path26.join)(rootDirectory, filePath);
73463
+ await dependencies.mkdir((0, import_node_path26.dirname)(absoluteFilePath), { recursive: true });
73290
73464
  if (dependencies.writeFile) await dependencies.writeFile(absoluteFilePath, buildContent());
73291
73465
  else await writeManaged(rootDirectory, filePath, buildContent(), void 0);
73292
73466
  }
73293
73467
  async function runValidateCommand(input3, dependencies = {}) {
73294
73468
  const cwd = dependencies.cwd ?? (() => process.cwd());
73295
73469
  const mkdir5 = dependencies.mkdir ?? (async (path, options) => {
73296
- await (0, import_promises24.mkdir)(path, options);
73470
+ await (0, import_promises23.mkdir)(path, options);
73297
73471
  });
73298
73472
  const readFile = dependencies.readFile ?? (async (filePath) => {
73299
- const content = await readManaged(rootDirectory, (0, import_node_path27.relative)(rootDirectory, filePath));
73473
+ const content = await readManaged(rootDirectory, (0, import_node_path26.relative)(rootDirectory, filePath));
73300
73474
  if (content === void 0) throw Object.assign(new Error("Missing local scaffold file."), { code: "ENOENT" });
73301
73475
  return content;
73302
73476
  });
73303
- const stat = dependencies.stat ?? import_promises24.stat;
73477
+ const stat = dependencies.stat ?? import_promises23.stat;
73304
73478
  const rootDirectory = await projectRoot(cwd());
73305
73479
  for (const file2 of [PROFILE_FILE_PATH, CONNECTION_FILE_PATH, GITIGNORE_FILE_PATH]) await safePath(rootDirectory, file2);
73306
73480
  const profileValidation = await validateProfile(rootDirectory, { readFile, stat });
@@ -73327,7 +73501,7 @@ async function runValidateCommand(input3, dependencies = {}) {
73327
73501
  checks.push({ name: fixableFile.name, status: status2, message: file2.status === "ok" ? previous.status === "missing" ? `Wrote missing ${file2.path}` : previous.status === "stale" ? `Updated stale ${file2.path}` : `Found ${file2.path}` : file2.status === "missing" ? `Missing ${file2.path}` : file2.status === "stale" ? `Stale ${file2.path}; run debugbundle validate --fix to refresh it.` : file2.message });
73328
73502
  continue;
73329
73503
  }
73330
- if (await pathExists8((0, import_node_path27.join)(rootDirectory, fixableFile.filePath), stat)) {
73504
+ if (await pathExists8((0, import_node_path26.join)(rootDirectory, fixableFile.filePath), stat)) {
73331
73505
  checks.push({ name: fixableFile.name, status: "ok", message: `Found ${fixableFile.filePath}` });
73332
73506
  } else if (input3.fix) {
73333
73507
  await fixMissingFile(rootDirectory, fixableFile.filePath, fixableFile.buildContent, { mkdir: mkdir5, ...dependencies.writeFile ? { writeFile: dependencies.writeFile } : {} });
@@ -82344,7 +82518,7 @@ async function handleCaptureRuleCommand2(parsedArgv, dependencies) {
82344
82518
  // package.json
82345
82519
  var package_default = {
82346
82520
  name: "@debugbundle/cli",
82347
- version: "1.19.2",
82521
+ version: "1.19.4",
82348
82522
  private: false,
82349
82523
  description: "Command-line interface for DebugBundle",
82350
82524
  license: "Apache-2.0",