@theokit/sdk-tools 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -379,8 +379,11 @@ async function editViaBackend(filesystem, ctx, path, old_string, new_string) {
379
379
  let content;
380
380
  try {
381
381
  content = await backend.readFile(path);
382
- } catch {
383
- return JSON.stringify({ ok: false, error: "not_found", path });
382
+ } catch (err) {
383
+ if (err instanceof FileNotFoundError) {
384
+ return JSON.stringify({ ok: false, error: "not_found", path });
385
+ }
386
+ throw err;
384
387
  }
385
388
  const outcome = computeEdit(content, old_string, new_string);
386
389
  if (!outcome.ok) return JSON.stringify({ ok: false, error: "no_match", path });
@@ -654,6 +657,7 @@ function runGitProcess(cwd, args, timeoutMs, maxStdoutBytes) {
654
657
  });
655
658
  }
656
659
  var DEFAULT_EXCLUDES = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".theo"]);
660
+ var MAX_BACKEND_WALK_DEPTH = 64;
657
661
  function createGlobTool(opts) {
658
662
  const { projectRoot, filesystem } = opts;
659
663
  return Tool.create({
@@ -671,7 +675,7 @@ function createGlobTool(opts) {
671
675
  const backend = await resolveFilesystem(filesystem, ctx ?? {});
672
676
  const searchRel = cwd ?? "";
673
677
  const found = [];
674
- await walkDirBackend(backend, searchRel, searchRel, regex, found);
678
+ await walkDirBackend(backend, searchRel, searchRel, regex, found, 0);
675
679
  return JSON.stringify({ ok: true, files: found.sort(), count: found.length });
676
680
  }
677
681
  const searchRoot = cwd ? safePathJoin(projectRoot, cwd) : projectRoot;
@@ -712,7 +716,8 @@ async function walkDir(base, dir, pattern, results) {
712
716
  }
713
717
  }
714
718
  }
715
- async function walkDirBackend(backend, base, dir, pattern, results) {
719
+ async function walkDirBackend(backend, base, dir, pattern, results, depth) {
720
+ if (depth > MAX_BACKEND_WALK_DEPTH) return;
716
721
  let names;
717
722
  try {
718
723
  names = await backend.list(dir);
@@ -720,10 +725,10 @@ async function walkDirBackend(backend, base, dir, pattern, results) {
720
725
  return;
721
726
  }
722
727
  for (const name of names) {
723
- await walkBackendEntry(backend, base, dir, name, pattern, results);
728
+ await walkBackendEntry(backend, base, dir, name, pattern, results, depth);
724
729
  }
725
730
  }
726
- async function walkBackendEntry(backend, base, dir, name, pattern, results) {
731
+ async function walkBackendEntry(backend, base, dir, name, pattern, results, depth) {
727
732
  if (DEFAULT_EXCLUDES.has(name)) return;
728
733
  const fullRel = dir === "" ? name : `${dir}/${name}`;
729
734
  const relPath = base === "" ? fullRel : relative(base, fullRel);
@@ -734,7 +739,7 @@ async function walkBackendEntry(backend, base, dir, name, pattern, results) {
734
739
  return;
735
740
  }
736
741
  if (st.isDirectory) {
737
- await walkDirBackend(backend, base, fullRel, pattern, results);
742
+ await walkDirBackend(backend, base, fullRel, pattern, results, depth + 1);
738
743
  } else if (st.isFile && pattern.test(relPath)) {
739
744
  results.push(fullRel);
740
745
  }
@@ -1806,6 +1811,7 @@ var DEFAULT_MAX_MATCHES = 100;
1806
1811
  var DEFAULT_MAX_FILE_SIZE = 1024 * 1024;
1807
1812
  var BINARY_PROBE_BYTES2 = 8 * 1024;
1808
1813
  var PREVIEW_MAX = 200;
1814
+ var MAX_BACKEND_WALK_DEPTH2 = 64;
1809
1815
  function createSearchTextTool(opts) {
1810
1816
  const {
1811
1817
  projectRoot,
@@ -1834,7 +1840,7 @@ function createSearchTextTool(opts) {
1834
1840
  const scopeRel = resolveScopeRel(path, projectRoot);
1835
1841
  if ("error" in scopeRel) return scopeRel.error;
1836
1842
  const backend = await resolveFilesystem(filesystem, ctx ?? {});
1837
- await walkBackend(backend, scopeRel.rel, state);
1843
+ await walkBackend(backend, scopeRel.rel, state, 0);
1838
1844
  return JSON.stringify({
1839
1845
  ok: true,
1840
1846
  matches: state.matches,
@@ -1944,8 +1950,9 @@ function resolveScopeRel(path, projectRoot) {
1944
1950
  throw err;
1945
1951
  }
1946
1952
  }
1947
- async function walkBackend(backend, dirRel, state) {
1953
+ async function walkBackend(backend, dirRel, state, depth) {
1948
1954
  if (state.truncated) return;
1955
+ if (depth > MAX_BACKEND_WALK_DEPTH2) return;
1949
1956
  let names;
1950
1957
  try {
1951
1958
  names = await backend.list(dirRel);
@@ -1954,10 +1961,10 @@ async function walkBackend(backend, dirRel, state) {
1954
1961
  }
1955
1962
  for (const name of names) {
1956
1963
  if (state.truncated) return;
1957
- await handleBackendEntry(backend, dirRel, name, state);
1964
+ await handleBackendEntry(backend, dirRel, name, state, depth);
1958
1965
  }
1959
1966
  }
1960
- async function handleBackendEntry(backend, dirRel, name, state) {
1967
+ async function handleBackendEntry(backend, dirRel, name, state, depth) {
1961
1968
  const entryRel = dirRel === "" ? name : `${dirRel}/${name}`;
1962
1969
  if (isForbiddenPath(entryRel)) return;
1963
1970
  let st;
@@ -1967,7 +1974,7 @@ async function handleBackendEntry(backend, dirRel, name, state) {
1967
1974
  return;
1968
1975
  }
1969
1976
  if (st.isDirectory) {
1970
- await walkBackend(backend, entryRel, state);
1977
+ await walkBackend(backend, entryRel, state, depth + 1);
1971
1978
  } else if (st.isFile) {
1972
1979
  await scanFileBackend(backend, entryRel, st.size, state);
1973
1980
  }