revdeck 0.2.1 → 0.2.3

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/daemon.js CHANGED
@@ -1165,7 +1165,7 @@ async function writeFileAtomic(file, data, mode = 384) {
1165
1165
  init_redact();
1166
1166
 
1167
1167
  // src/version.ts
1168
- var VERSION = "0.2.1";
1168
+ var VERSION = "0.2.3";
1169
1169
  var PROTOCOL_VERSION = 1;
1170
1170
 
1171
1171
  // src/daemon/main.ts
@@ -1814,7 +1814,11 @@ var reviewConfigSchema = z.object({
1814
1814
  })
1815
1815
  ).default([]),
1816
1816
  /** Пути, которые не ревьюятся (сгенерированный код и т.п.). */
1817
- ignore: z.array(z.string().min(1)).default([])
1817
+ ignore: z.array(z.string().min(1)).default([]),
1818
+ /** 0 — без ограничения; иначе документ обрезается до этого размера. */
1819
+ maxDocumentBytes: z.number().int().nonnegative().default(0),
1820
+ /** 0 — без ограничения; иначе общий контекст правил обрезается. */
1821
+ maxTotalBytes: z.number().int().nonnegative().default(0)
1818
1822
  }).prefault({}),
1819
1823
  checks: z.array(
1820
1824
  z.object({
@@ -1897,8 +1901,7 @@ function checksForPaths(config, paths) {
1897
1901
  import path4 from "node:path";
1898
1902
  import { existsSync as existsSync3 } from "node:fs";
1899
1903
  init_redact();
1900
- var MAX_DOC_BYTES = 96 * 1024;
1901
- var MAX_TOTAL_BYTES = 320 * 1024;
1904
+ var MAX_READ_BYTES = 16 * 1024 * 1024;
1902
1905
  async function buildEffectiveRules(options) {
1903
1906
  const { root, config, configPath } = options;
1904
1907
  const language = options.language ?? "ru";
@@ -1907,6 +1910,8 @@ async function buildEffectiveRules(options) {
1907
1910
  const files = options.files.filter((file) => !config.rules.ignore.some((pattern) => globToRegExp(pattern).test(file)));
1908
1911
  const ignored = options.files.length - files.length;
1909
1912
  if (ignored > 0) warnings.push(`${ignored} ${t("\u0444\u0430\u0439\u043B(\u043E\u0432) \u0438\u0441\u043A\u043B\u044E\u0447\u0435\u043D\u044B \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u043E\u0439 rules.ignore", "file(s) excluded by rules.ignore")}`);
1913
+ const documentLimit = config.rules.maxDocumentBytes > 0 ? config.rules.maxDocumentBytes : Number.POSITIVE_INFINITY;
1914
+ const totalLimit = config.rules.maxTotalBytes > 0 ? config.rules.maxTotalBytes : Number.POSITIVE_INFINITY;
1910
1915
  const cache = /* @__PURE__ */ new Map();
1911
1916
  let totalBytes = 0;
1912
1917
  const readDoc = async (selector) => {
@@ -1926,9 +1931,10 @@ async function buildEffectiveRules(options) {
1926
1931
  warnings.push(`${t("\u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442", "document")} ${relative} ${t("\u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D", "not found")}`);
1927
1932
  } else {
1928
1933
  try {
1929
- const raw = await readTextNoFollow(resolved, MAX_DOC_BYTES * 2);
1930
- const truncated = raw.length > MAX_DOC_BYTES;
1931
- cached = { exists: true, text: truncated ? raw.slice(0, MAX_DOC_BYTES) : raw, truncated };
1934
+ const readLimit = Number.isFinite(documentLimit) ? Math.max(documentLimit * 2, 4096) : MAX_READ_BYTES;
1935
+ const raw = await readTextNoFollow(resolved, readLimit);
1936
+ const truncated = Number.isFinite(documentLimit) && raw.length > documentLimit;
1937
+ cached = { exists: true, text: truncated ? raw.slice(0, documentLimit) : raw, truncated };
1932
1938
  } catch (error) {
1933
1939
  cached = { exists: false, text: "", truncated: false };
1934
1940
  warnings.push(`${relative}: ${redactLine(error)}`);
@@ -1958,7 +1964,7 @@ async function buildEffectiveRules(options) {
1958
1964
  }
1959
1965
  const documents = [];
1960
1966
  for (const doc of docs) {
1961
- if (totalBytes > MAX_TOTAL_BYTES) {
1967
+ if (Number.isFinite(totalLimit) && totalBytes > totalLimit) {
1962
1968
  warnings.push(t("\u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u043F\u0440\u0430\u0432\u0438\u043B \u043E\u0431\u0440\u0435\u0437\u0430\u043D: \u043F\u0440\u0435\u0432\u044B\u0448\u0435\u043D \u043B\u0438\u043C\u0438\u0442 \u0440\u0430\u0437\u043C\u0435\u0440\u0430", "rules context truncated: size limit exceeded"));
1963
1969
  break;
1964
1970
  }
@@ -2037,6 +2043,7 @@ function normalizeHeading(value) {
2037
2043
  }
2038
2044
  function renderRules(rules, options = {}) {
2039
2045
  const maxBytes = options.maxBytes ?? 2e5;
2046
+ const limit = maxBytes > 0 ? maxBytes : Number.POSITIVE_INFINITY;
2040
2047
  const withExcerpts = options.withExcerpts ?? true;
2041
2048
  const language = options.language ?? "ru";
2042
2049
  const t = (ru, en) => language === "ru" ? ru : en;
@@ -2061,7 +2068,7 @@ ${rules.warnings.map((item) => `- ${item}`).join("\n")}`);
2061
2068
  ${doc.excerpt}${doc.truncated ? `
2062
2069
 
2063
2070
  [${t("\u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442 \u043E\u0431\u0440\u0435\u0437\u0430\u043D", "document truncated")}]` : ""}`);
2064
- if (out.join("\n").length > maxBytes) {
2071
+ if (Number.isFinite(limit) && out.join("\n").length > limit) {
2065
2072
  out.push(`
2066
2073
  [${t("\u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u043F\u0440\u0430\u0432\u0438\u043B \u043E\u0431\u0440\u0435\u0437\u0430\u043D \u043F\u043E \u0440\u0430\u0437\u043C\u0435\u0440\u0443", "rules context truncated by size")}]`);
2067
2074
  return out.join("\n");
@@ -3171,12 +3178,14 @@ ${errors.join("\n")}`));
3171
3178
  files: changedPaths(stored.snapshot.diff),
3172
3179
  language
3173
3180
  });
3181
+ const maxBytes = config.rules.maxTotalBytes ?? 0;
3174
3182
  return {
3175
- markdown: renderRules(effective, { language }),
3183
+ markdown: renderRules(effective, { language, maxBytes }),
3176
3184
  configPath: effective.configPath,
3177
3185
  warnings: effective.warnings,
3178
3186
  checks: effective.checks,
3179
- language
3187
+ language,
3188
+ maxBytes
3180
3189
  };
3181
3190
  }
3182
3191
  async runChecks(id, options) {
@@ -3523,7 +3532,7 @@ var SECURITY_HEADERS = {
3523
3532
  "x-content-type-options": "nosniff",
3524
3533
  "x-frame-options": "DENY",
3525
3534
  "referrer-policy": "no-referrer",
3526
- "content-security-policy": "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
3535
+ "content-security-policy": "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: http: https:; media-src 'self' http: https:; font-src 'self'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
3527
3536
  };
3528
3537
  var COOKIE = "revdeck_session";
3529
3538
  function safeEqual(left, right) {