revdeck 0.4.5 → 0.5.0
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/CHANGELOG.md +38 -0
- package/README.md +42 -3
- package/README.ru.md +42 -3
- package/dist/cli.js +477 -81
- package/dist/cli.js.map +4 -4
- package/dist/daemon.js +525 -19
- package/dist/daemon.js.map +4 -4
- package/dist/mcp.js +208 -25
- package/dist/mcp.js.map +4 -4
- package/dist/ui/assets/{index-DZ9XSSBl.css → index-CcmcJhhu.css} +1 -1
- package/dist/ui/assets/index-CuvK5owY.js +10 -0
- package/dist/ui/index.html +2 -2
- package/docs/configuration.md +135 -2
- package/docs/ru/configuration.md +138 -2
- package/package.json +1 -1
- package/skills/revdeck/en/SKILL.md +20 -0
- package/skills/revdeck/ru/SKILL.md +20 -0
- package/dist/ui/assets/index-pR3id2Nv.js +0 -10
package/dist/daemon.js
CHANGED
|
@@ -1169,6 +1169,7 @@ function findRepoRoot(start = process.cwd()) {
|
|
|
1169
1169
|
}
|
|
1170
1170
|
}
|
|
1171
1171
|
var CONFIG_FILES = [".revdeck.yml", ".revdeck.yaml"];
|
|
1172
|
+
var LOCAL_CONFIG_FILES = [".revdeck.local.yml", ".revdeck.local.yaml"];
|
|
1172
1173
|
function findConfigFile(root) {
|
|
1173
1174
|
for (const name of CONFIG_FILES) {
|
|
1174
1175
|
const candidate = path.join(root, name);
|
|
@@ -1176,6 +1177,13 @@ function findConfigFile(root) {
|
|
|
1176
1177
|
}
|
|
1177
1178
|
return null;
|
|
1178
1179
|
}
|
|
1180
|
+
function findLocalConfigFile(root) {
|
|
1181
|
+
for (const name of LOCAL_CONFIG_FILES) {
|
|
1182
|
+
const candidate = path.join(root, name);
|
|
1183
|
+
if (existsSync(candidate)) return candidate;
|
|
1184
|
+
}
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1179
1187
|
function stateDir() {
|
|
1180
1188
|
if (process.env.REVDECK_STATE_DIR) return path.resolve(process.env.REVDECK_STATE_DIR);
|
|
1181
1189
|
const base = process.env.XDG_STATE_HOME || path.join(os.homedir(), ".local", "state");
|
|
@@ -1258,7 +1266,7 @@ async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
|
|
|
1258
1266
|
init_redact();
|
|
1259
1267
|
|
|
1260
1268
|
// src/version.ts
|
|
1261
|
-
var VERSION = "0.
|
|
1269
|
+
var VERSION = "0.5.0";
|
|
1262
1270
|
var PROTOCOL_VERSION = 1;
|
|
1263
1271
|
|
|
1264
1272
|
// src/daemon/main.ts
|
|
@@ -1449,6 +1457,16 @@ var Store = class {
|
|
|
1449
1457
|
detail TEXT NOT NULL
|
|
1450
1458
|
);
|
|
1451
1459
|
CREATE INDEX IF NOT EXISTS audit_review ON audit(review_id, at);
|
|
1460
|
+
CREATE TABLE IF NOT EXISTS review_versions (
|
|
1461
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1462
|
+
review_id TEXT NOT NULL REFERENCES reviews(id) ON DELETE CASCADE,
|
|
1463
|
+
head_sha TEXT NOT NULL DEFAULT '',
|
|
1464
|
+
base_sha TEXT NOT NULL DEFAULT '',
|
|
1465
|
+
diff_hash TEXT NOT NULL,
|
|
1466
|
+
data_json TEXT NOT NULL,
|
|
1467
|
+
created_at TEXT NOT NULL
|
|
1468
|
+
);
|
|
1469
|
+
CREATE INDEX IF NOT EXISTS review_versions_review ON review_versions(review_id, created_at);
|
|
1452
1470
|
`);
|
|
1453
1471
|
const findingColumns = this.db.prepare("PRAGMA table_info(findings)").all();
|
|
1454
1472
|
if (!findingColumns.some((column) => text(column, "name") === "agent_note")) {
|
|
@@ -1563,6 +1581,50 @@ var Store = class {
|
|
|
1563
1581
|
if (!row) return null;
|
|
1564
1582
|
return json(row, "info_json", null);
|
|
1565
1583
|
}
|
|
1584
|
+
addVersion(id, version, keep = 20, now = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1585
|
+
const last = this.db.prepare("SELECT head_sha, diff_hash FROM review_versions WHERE review_id = ? ORDER BY id DESC LIMIT 1").get(id);
|
|
1586
|
+
if (last && String(last.head_sha ?? "") === version.headSha && String(last.diff_hash ?? "") === version.diffHash) return;
|
|
1587
|
+
this.db.prepare("INSERT INTO review_versions (review_id, head_sha, base_sha, diff_hash, data_json, created_at) VALUES (?, ?, ?, ?, ?, ?)").run(id, version.headSha, version.baseSha, version.diffHash, JSON.stringify(version.data), now);
|
|
1588
|
+
this.db.prepare("DELETE FROM review_versions WHERE review_id = ? AND id NOT IN (SELECT id FROM review_versions WHERE review_id = ? ORDER BY id DESC LIMIT ?)").run(id, id, Math.max(1, keep));
|
|
1589
|
+
}
|
|
1590
|
+
listVersions(id) {
|
|
1591
|
+
const rows = this.db.prepare("SELECT * FROM review_versions WHERE review_id = ? ORDER BY id DESC").all(id);
|
|
1592
|
+
return rows.map((row) => {
|
|
1593
|
+
const data = json(row, "data_json", {});
|
|
1594
|
+
const stats = data.stats ?? {};
|
|
1595
|
+
const files = Array.isArray(data.files) ? data.files.length : 0;
|
|
1596
|
+
const findings = Array.isArray(data.findings) ? data.findings.length : 0;
|
|
1597
|
+
return {
|
|
1598
|
+
id: Number(row.id),
|
|
1599
|
+
headSha: text(row, "head_sha"),
|
|
1600
|
+
baseSha: text(row, "base_sha"),
|
|
1601
|
+
diffHash: text(row, "diff_hash"),
|
|
1602
|
+
createdAt: text(row, "created_at"),
|
|
1603
|
+
files,
|
|
1604
|
+
findings,
|
|
1605
|
+
additions: Number(stats.additions ?? 0),
|
|
1606
|
+
deletions: Number(stats.deletions ?? 0)
|
|
1607
|
+
};
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
getVersion(id, versionId) {
|
|
1611
|
+
const row = this.db.prepare("SELECT * FROM review_versions WHERE review_id = ? AND id = ?").get(id, versionId);
|
|
1612
|
+
if (!row) return null;
|
|
1613
|
+
const data = json(row, "data_json", {});
|
|
1614
|
+
const stats = data.stats ?? {};
|
|
1615
|
+
return {
|
|
1616
|
+
id: Number(row.id),
|
|
1617
|
+
headSha: text(row, "head_sha"),
|
|
1618
|
+
baseSha: text(row, "base_sha"),
|
|
1619
|
+
diffHash: text(row, "diff_hash"),
|
|
1620
|
+
createdAt: text(row, "created_at"),
|
|
1621
|
+
files: Array.isArray(data.files) ? data.files.length : 0,
|
|
1622
|
+
findings: Array.isArray(data.findings) ? data.findings.length : 0,
|
|
1623
|
+
additions: Number(stats.additions ?? 0),
|
|
1624
|
+
deletions: Number(stats.deletions ?? 0),
|
|
1625
|
+
data
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1566
1628
|
removeReview(id) {
|
|
1567
1629
|
this.db.prepare("DELETE FROM reviews WHERE id = ?").run(id);
|
|
1568
1630
|
}
|
|
@@ -1901,7 +1963,144 @@ function classifyFile(path11) {
|
|
|
1901
1963
|
|
|
1902
1964
|
// src/core/config.ts
|
|
1903
1965
|
init_locale();
|
|
1966
|
+
|
|
1967
|
+
// src/core/review-roles.ts
|
|
1968
|
+
var REVIEW_ROLE_IDS = [
|
|
1969
|
+
"correctness",
|
|
1970
|
+
"architecture",
|
|
1971
|
+
"tests",
|
|
1972
|
+
"security",
|
|
1973
|
+
"performance",
|
|
1974
|
+
"compatibility",
|
|
1975
|
+
"docs",
|
|
1976
|
+
"concurrency",
|
|
1977
|
+
"ux",
|
|
1978
|
+
"data",
|
|
1979
|
+
"api",
|
|
1980
|
+
"dependencies",
|
|
1981
|
+
"observability",
|
|
1982
|
+
"build",
|
|
1983
|
+
"privacy",
|
|
1984
|
+
"general"
|
|
1985
|
+
];
|
|
1986
|
+
var DEFAULT_REVIEW_ROLES = ["correctness", "architecture", "tests"];
|
|
1987
|
+
var REVIEW_ROLES = {
|
|
1988
|
+
correctness: {
|
|
1989
|
+
criteria: ["6", "10"],
|
|
1990
|
+
title: { ru: "\u041A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u043E\u0441\u0442\u044C", en: "Correctness" },
|
|
1991
|
+
focus: { ru: "\u043B\u043E\u0433\u0438\u043A\u0430, \u0433\u0440\u0430\u043D\u0438\u0447\u043D\u044B\u0435 \u0441\u043B\u0443\u0447\u0430\u0438, \u043E\u0448\u0438\u0431\u043A\u0438, null/undefined, async \u0438 \u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435", en: "logic, edge cases, errors, null/undefined, async and state" }
|
|
1992
|
+
},
|
|
1993
|
+
architecture: {
|
|
1994
|
+
criteria: ["3", "4", "5", "7"],
|
|
1995
|
+
title: { ru: "\u0410\u0440\u0445\u0438\u0442\u0435\u043A\u0442\u0443\u0440\u0430", en: "Architecture" },
|
|
1996
|
+
focus: { ru: "\u0441\u043B\u043E\u0438 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438, \u043E\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043D\u043D\u043E\u0441\u0442\u044C, \u0441\u0432\u044F\u0437\u043D\u043E\u0441\u0442\u044C, \u043F\u0440\u0435\u0446\u0435\u0434\u0435\u043D\u0442\u044B \u0438 ADR", en: "layers and dependencies, responsibility, coupling, precedents and ADRs" }
|
|
1997
|
+
},
|
|
1998
|
+
tests: {
|
|
1999
|
+
criteria: ["8"],
|
|
2000
|
+
title: { ru: "\u0422\u0435\u0441\u0442\u044B", en: "Tests" },
|
|
2001
|
+
focus: { ru: "\u043F\u043E\u043A\u0440\u044B\u0442\u0438\u0435, assertions, \u043E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044E\u0449\u0438\u0435 \u0441\u0446\u0435\u043D\u0430\u0440\u0438\u0438 \u0438 \u043D\u0435\u0441\u0442\u0430\u0431\u0438\u043B\u044C\u043D\u044B\u0435 \u0442\u0435\u0441\u0442\u044B", en: "coverage, assertions, missing scenarios and flaky tests" }
|
|
2002
|
+
},
|
|
2003
|
+
security: {
|
|
2004
|
+
criteria: ["10"],
|
|
2005
|
+
title: { ru: "\u0411\u0435\u0437\u043E\u043F\u0430\u0441\u043D\u043E\u0441\u0442\u044C", en: "Security" },
|
|
2006
|
+
focus: { ru: "\u0430\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u044F, \u0432\u0430\u043B\u0438\u0434\u0430\u0446\u0438\u044F \u0432\u0432\u043E\u0434\u0430, \u0441\u0435\u043A\u0440\u0435\u0442\u044B, \u0438\u043D\u044A\u0435\u043A\u0446\u0438\u0438, shell \u0438 \u043E\u043F\u0430\u0441\u043D\u044B\u0435 \u043F\u0440\u0430\u0432\u0430", en: "authorization, input validation, secrets, injections, shell and dangerous permissions" }
|
|
2007
|
+
},
|
|
2008
|
+
performance: {
|
|
2009
|
+
criteria: ["10"],
|
|
2010
|
+
title: { ru: "\u041F\u0440\u043E\u0438\u0437\u0432\u043E\u0434\u0438\u0442\u0435\u043B\u044C\u043D\u043E\u0441\u0442\u044C", en: "Performance" },
|
|
2011
|
+
focus: { ru: "\u0441\u043B\u043E\u0436\u043D\u043E\u0441\u0442\u044C, N+1, \u043B\u0438\u0448\u043D\u0438\u0435 \u0430\u043B\u043B\u043E\u043A\u0430\u0446\u0438\u0438, \u043A\u0435\u0448\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0438 \u0431\u043B\u043E\u043A\u0438\u0440\u0443\u044E\u0449\u0438\u0435 \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u0438", en: "complexity, N+1, extra allocations, caching and blocking operations" }
|
|
2012
|
+
},
|
|
2013
|
+
compatibility: {
|
|
2014
|
+
criteria: ["6", "7"],
|
|
2015
|
+
title: { ru: "\u0421\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u043E\u0441\u0442\u044C", en: "Compatibility" },
|
|
2016
|
+
focus: { ru: "\u043F\u0443\u0431\u043B\u0438\u0447\u043D\u044B\u0439 API, \u043E\u0431\u0440\u0430\u0442\u043D\u0430\u044F \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u043E\u0441\u0442\u044C, \u043C\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u043A\u043E\u043D\u0444\u0438\u0433\u043E\u0432", en: "public API, backward compatibility, migrations and config changes" }
|
|
2017
|
+
},
|
|
2018
|
+
docs: {
|
|
2019
|
+
criteria: ["9"],
|
|
2020
|
+
title: { ru: "\u0414\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430\u0446\u0438\u044F", en: "Documentation" },
|
|
2021
|
+
focus: { ru: "\u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430\u0446\u0438\u044F, \u043A\u043E\u043D\u0444\u0438\u0433\u0438, CHANGELOG \u0438 \u0441\u043E\u0433\u043B\u0430\u0441\u043E\u0432\u0430\u043D\u043D\u043E\u0441\u0442\u044C AI-\u0438\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0439", en: "documentation, configs, CHANGELOG and consistency of AI instructions" }
|
|
2022
|
+
},
|
|
2023
|
+
concurrency: {
|
|
2024
|
+
criteria: ["10"],
|
|
2025
|
+
title: { ru: "\u041A\u043E\u043D\u043A\u0443\u0440\u0435\u043D\u0442\u043D\u043E\u0441\u0442\u044C", en: "Concurrency" },
|
|
2026
|
+
focus: { ru: "\u0433\u043E\u043D\u043A\u0438, \u0431\u043B\u043E\u043A\u0438\u0440\u043E\u0432\u043A\u0438, \u0438\u0434\u0435\u043C\u043F\u043E\u0442\u0435\u043D\u0442\u043D\u043E\u0441\u0442\u044C, retries \u0438 \u043E\u0442\u043C\u0435\u043D\u0430 \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u0439", en: "races, locks, idempotency, retries and cancellation" }
|
|
2027
|
+
},
|
|
2028
|
+
ux: {
|
|
2029
|
+
criteria: ["9", "10"],
|
|
2030
|
+
title: { ru: "UX \u0438 \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E\u0441\u0442\u044C", en: "UX and accessibility" },
|
|
2031
|
+
focus: { ru: "\u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u044F UI, \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E\u0441\u0442\u044C, \u043E\u0448\u0438\u0431\u043A\u0438 \u0438 \u043F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435 \u043D\u0430 \u0443\u0437\u043A\u0438\u0445 \u044D\u043A\u0440\u0430\u043D\u0430\u0445", en: "UI states, accessibility, errors and narrow-screen behavior" }
|
|
2032
|
+
},
|
|
2033
|
+
data: {
|
|
2034
|
+
criteria: ["3", "10"],
|
|
2035
|
+
title: { ru: "\u0414\u0430\u043D\u043D\u044B\u0435 \u0438 \u043C\u0438\u0433\u0440\u0430\u0446\u0438\u0438", en: "Data and migrations" },
|
|
2036
|
+
focus: { ru: "\u0441\u0445\u0435\u043C\u044B, \u043C\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u0445\u0440\u0430\u043D\u0435\u043D\u0438\u0435, \u043E\u0431\u0440\u0430\u0442\u043D\u0430\u044F \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u043E\u0441\u0442\u044C \u0434\u0430\u043D\u043D\u044B\u0445", en: "schemas, migrations, storage and data backward compatibility" }
|
|
2037
|
+
},
|
|
2038
|
+
api: {
|
|
2039
|
+
criteria: ["6", "7"],
|
|
2040
|
+
title: { ru: "\u041F\u0443\u0431\u043B\u0438\u0447\u043D\u044B\u0439 API", en: "Public API" },
|
|
2041
|
+
focus: { ru: "\u043A\u043E\u043D\u0442\u0440\u0430\u043A\u0442\u044B, \u0432\u0435\u0440\u0441\u0438\u043E\u043D\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 API, \u043E\u0431\u0440\u0430\u0431\u043E\u0442\u043A\u0430 \u043E\u0448\u0438\u0431\u043E\u043A \u0438 \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u043E\u0441\u0442\u044C \u043A\u043B\u0438\u0435\u043D\u0442\u043E\u0432", en: "contracts, API versioning, error handling and client compatibility" }
|
|
2042
|
+
},
|
|
2043
|
+
dependencies: {
|
|
2044
|
+
criteria: ["3", "10"],
|
|
2045
|
+
title: { ru: "\u0417\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438", en: "Dependencies" },
|
|
2046
|
+
focus: { ru: "\u0432\u0435\u0440\u0441\u0438\u0438, \u043B\u0438\u0446\u0435\u043D\u0437\u0438\u0438, supply chain \u0438 \u043B\u0438\u0448\u043D\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438", en: "versions, licenses, supply chain and unnecessary dependencies" }
|
|
2047
|
+
},
|
|
2048
|
+
observability: {
|
|
2049
|
+
criteria: ["9", "10"],
|
|
2050
|
+
title: { ru: "\u041D\u0430\u0431\u043B\u044E\u0434\u0430\u0435\u043C\u043E\u0441\u0442\u044C", en: "Observability" },
|
|
2051
|
+
focus: { ru: "\u043B\u043E\u0433\u0438, \u043C\u0435\u0442\u0440\u0438\u043A\u0438, \u0442\u0440\u0435\u0439\u0441\u044B, \u043E\u0448\u0438\u0431\u043A\u0438 \u0438 \u043E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0438", en: "logs, metrics, traces, errors and missing diagnostics" }
|
|
2052
|
+
},
|
|
2053
|
+
build: {
|
|
2054
|
+
criteria: ["8", "9"],
|
|
2055
|
+
title: { ru: "\u0421\u0431\u043E\u0440\u043A\u0430 \u0438 CI", en: "Build and CI" },
|
|
2056
|
+
focus: { ru: "CI, \u0441\u0431\u043E\u0440\u043A\u0430, \u0443\u043F\u0430\u043A\u043E\u0432\u043A\u0430, \u043A\u0435\u0448\u0438 \u0438 \u0432\u043E\u0441\u043F\u0440\u043E\u0438\u0437\u0432\u043E\u0434\u0438\u043C\u043E\u0441\u0442\u044C", en: "CI, builds, packaging, caches and reproducibility" }
|
|
2057
|
+
},
|
|
2058
|
+
privacy: {
|
|
2059
|
+
criteria: ["9", "10"],
|
|
2060
|
+
title: { ru: "\u041F\u0440\u0438\u0432\u0430\u0442\u043D\u043E\u0441\u0442\u044C", en: "Privacy" },
|
|
2061
|
+
focus: { ru: "PII, \u0445\u0440\u0430\u043D\u0435\u043D\u0438\u0435 \u043F\u0435\u0440\u0441\u043E\u043D\u0430\u043B\u044C\u043D\u044B\u0445 \u0434\u0430\u043D\u043D\u044B\u0445, \u043B\u043E\u0433\u0438 \u0438 \u0443\u0442\u0435\u0447\u043A\u0438", en: "PII, personal data storage, logs and leaks" }
|
|
2062
|
+
},
|
|
2063
|
+
general: {
|
|
2064
|
+
criteria: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
|
|
2065
|
+
title: { ru: "\u041E\u0431\u0449\u0435\u0435 \u0440\u0435\u0432\u044C\u044E", en: "General review" },
|
|
2066
|
+
focus: { ru: "\u043F\u043E\u043B\u043D\u043E\u0435 \u0440\u0435\u0432\u044C\u044E \u043F\u043E \u0432\u0441\u0435\u043C \u0440\u0430\u0437\u0434\u0435\u043B\u0430\u043C Criteria.md", en: "full review across all Criteria.md sections" }
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
function effectiveRoleIds(agents, roles) {
|
|
2070
|
+
const base = roles.length ? roles : DEFAULT_REVIEW_ROLES;
|
|
2071
|
+
return Array.from({ length: agents }, (_, index) => base[index % base.length]);
|
|
2072
|
+
}
|
|
2073
|
+
function resolveReviewRole(id, language, custom = {}) {
|
|
2074
|
+
if (id in REVIEW_ROLES) {
|
|
2075
|
+
const role2 = REVIEW_ROLES[id];
|
|
2076
|
+
return {
|
|
2077
|
+
id,
|
|
2078
|
+
title: role2.title[language],
|
|
2079
|
+
description: role2.focus[language],
|
|
2080
|
+
criteria: role2.criteria,
|
|
2081
|
+
instructions: ""
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
2084
|
+
const role = custom[id];
|
|
2085
|
+
if (!role) return null;
|
|
2086
|
+
return {
|
|
2087
|
+
id,
|
|
2088
|
+
title: role.title,
|
|
2089
|
+
description: role.description,
|
|
2090
|
+
criteria: role.criteria,
|
|
2091
|
+
instructions: role.instructions ?? ""
|
|
2092
|
+
};
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
// src/core/config.ts
|
|
1904
2096
|
var matchSchema = z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]);
|
|
2097
|
+
var customRoleSchema = z.object({
|
|
2098
|
+
title: z.string().min(1).max(120),
|
|
2099
|
+
description: z.string().min(1).max(2e3),
|
|
2100
|
+
criteria: z.array(z.string().min(1).max(20)).max(20).default([]),
|
|
2101
|
+
focus: z.string().max(2e3).optional(),
|
|
2102
|
+
instructions: z.string().max(8e3).optional()
|
|
2103
|
+
});
|
|
1905
2104
|
var reviewConfigSchema = z.object({
|
|
1906
2105
|
version: z.literal(1).default(1),
|
|
1907
2106
|
provider: z.object({
|
|
@@ -1916,6 +2115,48 @@ var reviewConfigSchema = z.object({
|
|
|
1916
2115
|
output: z.object({
|
|
1917
2116
|
language: z.enum(["auto", "ru", "en"]).default("auto")
|
|
1918
2117
|
}).prefault({}),
|
|
2118
|
+
review: z.object({
|
|
2119
|
+
/** Сколько независимых ревьюеров запускать. */
|
|
2120
|
+
agents: z.number().int().min(1).max(8).default(3),
|
|
2121
|
+
/** Роли агентов; встроенные id или ключи customRoles. */
|
|
2122
|
+
roles: z.array(z.string().min(1).max(64)).min(1).max(10).default([...DEFAULT_REVIEW_ROLES]),
|
|
2123
|
+
/** Пользовательские роли с описанием и инструкциями. */
|
|
2124
|
+
customRoles: z.record(z.string().min(1).max(64), customRoleSchema).default({}),
|
|
2125
|
+
/** Явные группы изменений; остальные группируются по типу и модулю. */
|
|
2126
|
+
groups: z.array(
|
|
2127
|
+
z.object({
|
|
2128
|
+
id: z.string().min(1).max(64),
|
|
2129
|
+
title: z.string().min(1).max(120),
|
|
2130
|
+
match: matchSchema
|
|
2131
|
+
})
|
|
2132
|
+
).max(100).default([]),
|
|
2133
|
+
/** Опциональный скан секретов; по умолчанию выключен. */
|
|
2134
|
+
secrets: z.object({
|
|
2135
|
+
enabled: z.boolean().default(false),
|
|
2136
|
+
scan: z.enum(["diff", "files", "both"]).default("diff"),
|
|
2137
|
+
includeTests: z.boolean().default(false),
|
|
2138
|
+
/** Glob-пути или id правила (`rule:generic-secret`). */
|
|
2139
|
+
allowlist: z.array(z.string().min(1)).default([])
|
|
2140
|
+
}).prefault({}),
|
|
2141
|
+
/** История версий ревью (снимки по commit SHA). */
|
|
2142
|
+
history: z.object({
|
|
2143
|
+
enabled: z.boolean().default(false),
|
|
2144
|
+
keep: z.number().int().min(1).max(100).default(20)
|
|
2145
|
+
}).prefault({}),
|
|
2146
|
+
/** Запрет любых изменений: drafts, findings, публикация. */
|
|
2147
|
+
readOnly: z.boolean().default(false)
|
|
2148
|
+
}).prefault({}).superRefine((value, ctx) => {
|
|
2149
|
+
for (const key of Object.keys(value.customRoles)) {
|
|
2150
|
+
if (REVIEW_ROLE_IDS.includes(key)) {
|
|
2151
|
+
ctx.addIssue({ code: "custom", path: ["customRoles", key], message: `role ${key} is built in and cannot be overridden` });
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
for (const role of value.roles) {
|
|
2155
|
+
if (!REVIEW_ROLE_IDS.includes(role) && !(role in value.customRoles)) {
|
|
2156
|
+
ctx.addIssue({ code: "custom", path: ["roles"], message: `unknown role: ${role}` });
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
}),
|
|
1919
2160
|
rules: z.object({
|
|
1920
2161
|
/** Общие документы, если ни одна строка map не подошла. Пусто — автообнаружение. */
|
|
1921
2162
|
sources: z.array(z.string().min(1)).default([]),
|
|
@@ -1961,31 +2202,39 @@ var DISCOVERED_SOURCES = [
|
|
|
1961
2202
|
"docs/Styleguide.md",
|
|
1962
2203
|
"docs/CONTRIBUTING.md"
|
|
1963
2204
|
];
|
|
1964
|
-
function
|
|
1965
|
-
|
|
2205
|
+
function isRecord(value) {
|
|
2206
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2207
|
+
}
|
|
2208
|
+
function parseYamlData(text2, source) {
|
|
1966
2209
|
try {
|
|
1967
|
-
|
|
2210
|
+
return parseYaml(text2);
|
|
1968
2211
|
} catch (error) {
|
|
1969
2212
|
throw new ConfigError(tr(`${source}: \u043D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 YAML: ${error.message}`, `${source}: invalid YAML: ${error.message}`));
|
|
1970
2213
|
}
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
if (!
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2214
|
+
}
|
|
2215
|
+
function mergeConfigData(base, local) {
|
|
2216
|
+
if (!isRecord(base) || !isRecord(local)) return local;
|
|
2217
|
+
const result = { ...base };
|
|
2218
|
+
for (const [key, value] of Object.entries(local)) {
|
|
2219
|
+
const current2 = result[key];
|
|
2220
|
+
result[key] = isRecord(current2) && isRecord(value) ? mergeConfigData(current2, value) : value;
|
|
2221
|
+
}
|
|
2222
|
+
return result;
|
|
1978
2223
|
}
|
|
1979
2224
|
async function loadConfig(root = findRepoRoot()) {
|
|
1980
2225
|
const warnings = [];
|
|
1981
2226
|
const file = findConfigFile(root);
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
config = reviewConfigSchema.parse({});
|
|
2227
|
+
const localFile = findLocalConfigFile(root);
|
|
2228
|
+
const baseData = file ? parseYamlData(await readTextNoFollow(file), path3.relative(root, file) || file) : {};
|
|
2229
|
+
const localData = localFile ? parseYamlData(await readTextNoFollow(localFile), path3.relative(root, localFile) || localFile) : {};
|
|
2230
|
+
if (!file && !localFile) {
|
|
1987
2231
|
warnings.push(tr("\u0444\u0430\u0439\u043B .revdeck.yml \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: \u043F\u0440\u0430\u0432\u0438\u043B\u0430 \u0432\u0437\u044F\u0442\u044B \u0438\u0437 \u0430\u0432\u0442\u043E\u043E\u0431\u043D\u0430\u0440\u0443\u0436\u0435\u043D\u043D\u044B\u0445 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432", ".revdeck.yml not found: rules come from auto-discovered documents"));
|
|
1988
2232
|
}
|
|
2233
|
+
const merged = mergeConfigData(baseData, localData);
|
|
2234
|
+
const config = reviewConfigSchema.parse(merged);
|
|
2235
|
+
const baseReadOnly = isRecord(baseData) && isRecord(baseData.review) && baseData.review.readOnly === true;
|
|
2236
|
+
const localReadOnly = isRecord(localData) && isRecord(localData.review) && localData.review.readOnly === true;
|
|
2237
|
+
config.review.readOnly = baseReadOnly || localReadOnly;
|
|
1989
2238
|
if (!config.rules.sources.length && !config.rules.map.length) {
|
|
1990
2239
|
const found = DISCOVERED_SOURCES.filter((item) => existsSync2(path3.join(root, item)));
|
|
1991
2240
|
config.rules.sources = found;
|
|
@@ -1993,7 +2242,12 @@ async function loadConfig(root = findRepoRoot()) {
|
|
|
1993
2242
|
warnings.push(tr("\u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u044B \u0441 \u043F\u0440\u0430\u0432\u0438\u043B\u0430\u043C\u0438 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u044B: \u0440\u0435\u0432\u044C\u044E \u0431\u0443\u0434\u0435\u0442 \u043E\u043F\u0438\u0440\u0430\u0442\u044C\u0441\u044F \u0442\u043E\u043B\u044C\u043A\u043E \u043D\u0430 \u043A\u043E\u0434 \u0438 \u0437\u0434\u0440\u0430\u0432\u044B\u0439 \u0441\u043C\u044B\u0441\u043B", "no rule documents found: the review will rely on the code only"));
|
|
1994
2243
|
}
|
|
1995
2244
|
}
|
|
1996
|
-
return {
|
|
2245
|
+
return {
|
|
2246
|
+
config,
|
|
2247
|
+
path: file,
|
|
2248
|
+
localPath: localFile,
|
|
2249
|
+
warnings
|
|
2250
|
+
};
|
|
1997
2251
|
}
|
|
1998
2252
|
function assertConfigPath(root, relative) {
|
|
1999
2253
|
const cleaned = relative.split("#")[0];
|
|
@@ -2202,6 +2456,114 @@ ${doc.excerpt}${doc.truncated ? `
|
|
|
2202
2456
|
// src/daemon/service.ts
|
|
2203
2457
|
init_diff();
|
|
2204
2458
|
|
|
2459
|
+
// src/core/groups.ts
|
|
2460
|
+
var CLASS_LABEL = {
|
|
2461
|
+
docs: "Documentation",
|
|
2462
|
+
test: "Tests",
|
|
2463
|
+
config: "Configuration",
|
|
2464
|
+
style: "Styles",
|
|
2465
|
+
generated: "Generated",
|
|
2466
|
+
app: "Application",
|
|
2467
|
+
other: "Other"
|
|
2468
|
+
};
|
|
2469
|
+
function computeGroups(diff, custom = []) {
|
|
2470
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2471
|
+
const add = (group, path11, additions, deletions) => {
|
|
2472
|
+
group.files.push(path11);
|
|
2473
|
+
group.additions += additions;
|
|
2474
|
+
group.deletions += deletions;
|
|
2475
|
+
groups.set(group.id, group);
|
|
2476
|
+
};
|
|
2477
|
+
for (const file of diff) {
|
|
2478
|
+
let additions = 0;
|
|
2479
|
+
let deletions = 0;
|
|
2480
|
+
for (const hunk of file.hunks) {
|
|
2481
|
+
for (const line of hunk.lines) {
|
|
2482
|
+
if (line.kind === "+") additions += 1;
|
|
2483
|
+
else if (line.kind === "-") deletions += 1;
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
const customGroup = custom.find((item) => {
|
|
2487
|
+
const patterns = Array.isArray(item.match) ? item.match : [item.match];
|
|
2488
|
+
return patterns.some((pattern) => globToRegExp(pattern).test(file.path));
|
|
2489
|
+
});
|
|
2490
|
+
if (customGroup) {
|
|
2491
|
+
const group2 = groups.get(customGroup.id) ?? { id: customGroup.id, title: customGroup.title, files: [], additions: 0, deletions: 0 };
|
|
2492
|
+
add(group2, file.path, additions, deletions);
|
|
2493
|
+
continue;
|
|
2494
|
+
}
|
|
2495
|
+
const kind = classifyFile(file.path);
|
|
2496
|
+
if (kind !== "app" && kind !== "other") {
|
|
2497
|
+
const id2 = kind;
|
|
2498
|
+
const group2 = groups.get(id2) ?? { id: id2, title: CLASS_LABEL[kind], files: [], additions: 0, deletions: 0 };
|
|
2499
|
+
add(group2, file.path, additions, deletions);
|
|
2500
|
+
continue;
|
|
2501
|
+
}
|
|
2502
|
+
const module = file.path.split("/")[0] || "root";
|
|
2503
|
+
const id = `module:${module}`;
|
|
2504
|
+
const group = groups.get(id) ?? { id, title: module, files: [], additions: 0, deletions: 0 };
|
|
2505
|
+
add(group, file.path, additions, deletions);
|
|
2506
|
+
}
|
|
2507
|
+
return [...groups.values()].sort((left, right) => right.additions + right.deletions - (left.additions + left.deletions) || left.title.localeCompare(right.title));
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
// src/core/secrets.ts
|
|
2511
|
+
var PATTERNS = [
|
|
2512
|
+
{ id: "aws-access-key", title: "AWS access key", regex: /\bAKIA[0-9A-Z]{16}\b/g },
|
|
2513
|
+
{ id: "github-token", title: "GitHub token", regex: /\bgh[pousr]_[A-Za-z0-9]{20,}\b/g },
|
|
2514
|
+
{ id: "gitlab-token", title: "GitLab token", regex: /\bglpat-[A-Za-z0-9_-]{20,}\b/g },
|
|
2515
|
+
{ id: "stripe-live-key", title: "Stripe live key", regex: /\bsk_live_[A-Za-z0-9]{16,}\b/g },
|
|
2516
|
+
{ id: "openai-key", title: "OpenAI key", regex: /\bsk-[A-Za-z0-9]{20,}\b/g },
|
|
2517
|
+
{
|
|
2518
|
+
id: "private-key",
|
|
2519
|
+
title: "Private key",
|
|
2520
|
+
regex: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----/g
|
|
2521
|
+
},
|
|
2522
|
+
{
|
|
2523
|
+
id: "generic-secret",
|
|
2524
|
+
title: "Generic secret assignment",
|
|
2525
|
+
regex: /\b(?:api[_-]?key|secret|token|password|passwd)\b\s*[:=]\s*['"`][^'"`\n]{12,}['"`]/gi
|
|
2526
|
+
}
|
|
2527
|
+
];
|
|
2528
|
+
function maskSecret(value) {
|
|
2529
|
+
const trimmed = value.trim();
|
|
2530
|
+
if (trimmed.length <= 8) return "***";
|
|
2531
|
+
return `${trimmed.slice(0, 4)}\u2026${trimmed.slice(-2)}`;
|
|
2532
|
+
}
|
|
2533
|
+
function isAllowlisted(path11, rule, allowlist) {
|
|
2534
|
+
return allowlist.some((entry) => {
|
|
2535
|
+
const normalized = entry.trim();
|
|
2536
|
+
if (!normalized) return false;
|
|
2537
|
+
if (normalized === rule || normalized === `rule:${rule}`) return true;
|
|
2538
|
+
if (normalized.startsWith("rule:")) return false;
|
|
2539
|
+
return globToRegExp(normalized).test(path11);
|
|
2540
|
+
});
|
|
2541
|
+
}
|
|
2542
|
+
function scanLines(path11, lines, options = {}) {
|
|
2543
|
+
if (!options.includeTests && classifyFile(path11) === "test") return [];
|
|
2544
|
+
const allowlist = options.allowlist ?? [];
|
|
2545
|
+
const findings = [];
|
|
2546
|
+
for (const line of lines) {
|
|
2547
|
+
let specific = false;
|
|
2548
|
+
for (const pattern of PATTERNS) {
|
|
2549
|
+
if (isAllowlisted(path11, pattern.id, allowlist)) continue;
|
|
2550
|
+
if (pattern.id === "generic-secret" && specific) continue;
|
|
2551
|
+
pattern.regex.lastIndex = 0;
|
|
2552
|
+
const match = pattern.regex.exec(line.text);
|
|
2553
|
+
if (!match) continue;
|
|
2554
|
+
if (pattern.id !== "generic-secret") specific = true;
|
|
2555
|
+
findings.push({
|
|
2556
|
+
rule: pattern.id,
|
|
2557
|
+
title: pattern.title,
|
|
2558
|
+
file: path11,
|
|
2559
|
+
line: line.number,
|
|
2560
|
+
preview: maskSecret(match[0])
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
return findings;
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2205
2567
|
// src/core/sanitize.ts
|
|
2206
2568
|
init_locale();
|
|
2207
2569
|
var CONTROL_OR_HIDDEN = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u00ad\u061c\u115f\u1160\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u2800\u3164\ufeff\uffa0]/;
|
|
@@ -2744,8 +3106,21 @@ var ReviewService = class {
|
|
|
2744
3106
|
syncedAt
|
|
2745
3107
|
});
|
|
2746
3108
|
if (diff.length) this.markStaleFindings(id, diff);
|
|
3109
|
+
this.recordVersion(id, info, diff);
|
|
2747
3110
|
this.emit(id);
|
|
2748
3111
|
}
|
|
3112
|
+
recordVersion(id, info, diff) {
|
|
3113
|
+
const history = this.configOf(id)?.review?.history;
|
|
3114
|
+
if (!history?.enabled) return;
|
|
3115
|
+
const view = this.getReview(id);
|
|
3116
|
+
const diffHash = createHash2("sha256").update(canonicalJson(diff)).digest("hex");
|
|
3117
|
+
this.store.addVersion(
|
|
3118
|
+
id,
|
|
3119
|
+
{ headSha: info.commit.head, baseSha: info.commit.base, diffHash, data: view },
|
|
3120
|
+
history.keep,
|
|
3121
|
+
this.now().toISOString()
|
|
3122
|
+
);
|
|
3123
|
+
}
|
|
2749
3124
|
markStaleFindings(id, diff) {
|
|
2750
3125
|
const findings = this.store.listFindings(id);
|
|
2751
3126
|
if (!findings.length) return;
|
|
@@ -2783,12 +3158,14 @@ var ReviewService = class {
|
|
|
2783
3158
|
const findings = applyDecisions(this.store.listFindings(id), this.store.listDecisions(id)).sort(
|
|
2784
3159
|
(a, b) => levelOrder(a.level) - levelOrder(b.level) || a.file.localeCompare(b.file) || (a.line ?? 0) - (b.line ?? 0)
|
|
2785
3160
|
);
|
|
3161
|
+
const groups = computeGroups(snapshot.diff, this.configOf(id)?.review?.groups ?? []);
|
|
2786
3162
|
return {
|
|
2787
3163
|
id,
|
|
2788
3164
|
info,
|
|
2789
3165
|
diff: snapshot.diff,
|
|
2790
3166
|
threads,
|
|
2791
3167
|
reactions: snapshot.reactions,
|
|
3168
|
+
groups,
|
|
2792
3169
|
summary: this.store.getSummary(id),
|
|
2793
3170
|
findings,
|
|
2794
3171
|
drafts,
|
|
@@ -2796,12 +3173,80 @@ var ReviewService = class {
|
|
|
2796
3173
|
decisions: this.store.listDecisions(id),
|
|
2797
3174
|
user: snapshot.user,
|
|
2798
3175
|
syncedAt: snapshot.syncedAt,
|
|
2799
|
-
errors: snapshot.errors
|
|
3176
|
+
errors: snapshot.errors,
|
|
3177
|
+
readOnly: this.isReadOnly(id)
|
|
2800
3178
|
};
|
|
2801
3179
|
}
|
|
2802
3180
|
getView(id) {
|
|
2803
3181
|
return toReviewView(this.getReview(id), this.now().getTime());
|
|
2804
3182
|
}
|
|
3183
|
+
async secrets(id) {
|
|
3184
|
+
const stored = this.store.getReview(id);
|
|
3185
|
+
if (!stored) throw new Error(tr(`\u0440\u0435\u0432\u044C\u044E ${id} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E`, `review ${id} not found`));
|
|
3186
|
+
const config = this.configOf(id)?.review?.secrets;
|
|
3187
|
+
if (!config?.enabled) return { enabled: false, scan: config?.scan ?? "diff", findings: [] };
|
|
3188
|
+
const options = {
|
|
3189
|
+
...config.allowlist.length ? { allowlist: config.allowlist } : {},
|
|
3190
|
+
includeTests: config.includeTests
|
|
3191
|
+
};
|
|
3192
|
+
const findings = [];
|
|
3193
|
+
if (config.scan !== "files") {
|
|
3194
|
+
for (const file of stored.snapshot.diff) {
|
|
3195
|
+
const lines = file.hunks.flatMap(
|
|
3196
|
+
(hunk) => hunk.lines.filter((line) => line.kind === "+" && line.newLine !== null).map((line) => ({ number: line.newLine, text: line.text }))
|
|
3197
|
+
);
|
|
3198
|
+
findings.push(...scanLines(file.path, lines, options));
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
if (config.scan !== "diff") {
|
|
3202
|
+
for (const file of stored.snapshot.diff) {
|
|
3203
|
+
if (file.binary) continue;
|
|
3204
|
+
try {
|
|
3205
|
+
const resolved = assertConfigPath(stored.row.root, file.path);
|
|
3206
|
+
const text2 = await readTextNoFollow(resolved, 1e6);
|
|
3207
|
+
const lines = text2.split("\n").map((line, index) => ({ number: index + 1, text: line }));
|
|
3208
|
+
findings.push(...scanLines(file.path, lines, options));
|
|
3209
|
+
} catch {
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
const unique = [...new Map(findings.map((item) => [`${item.file}:${item.line}:${item.rule}`, item])).values()];
|
|
3214
|
+
this.store.audit(id, "secrets.scan", { count: unique.length, scan: config.scan });
|
|
3215
|
+
return { enabled: true, scan: config.scan, findings: unique };
|
|
3216
|
+
}
|
|
3217
|
+
analytics(id) {
|
|
3218
|
+
const review = this.getReview(id);
|
|
3219
|
+
const decisions = review.decisions;
|
|
3220
|
+
const decisionOf = (finding) => decisions[finding.id]?.decision ?? finding.decision;
|
|
3221
|
+
const accepted = review.findings.filter((finding) => decisionOf(finding) === "accept").length;
|
|
3222
|
+
const rejected = review.findings.filter((finding) => decisionOf(finding) === "reject").length;
|
|
3223
|
+
const discussed = review.findings.filter((finding) => decisionOf(finding) === "discuss").length;
|
|
3224
|
+
const published = review.findings.filter((finding) => finding.status === "published").length;
|
|
3225
|
+
const pending = review.findings.length - accepted - rejected - discussed;
|
|
3226
|
+
const levels = {};
|
|
3227
|
+
for (const finding of review.findings) levels[finding.level] = (levels[finding.level] ?? 0) + 1;
|
|
3228
|
+
const drafts = review.drafts.filter((draft) => draft.body.trim() !== "");
|
|
3229
|
+
return {
|
|
3230
|
+
generatedAt: this.now().toISOString(),
|
|
3231
|
+
findings: { total: review.findings.length, accepted, rejected, discussed, pending, published },
|
|
3232
|
+
levels,
|
|
3233
|
+
threads: {
|
|
3234
|
+
total: review.threads.length,
|
|
3235
|
+
open: review.threads.filter((thread) => !thread.resolved).length,
|
|
3236
|
+
resolved: review.threads.filter((thread) => thread.resolved).length
|
|
3237
|
+
},
|
|
3238
|
+
drafts: { ready: drafts.filter((draft) => !draft.replied).length, published: drafts.filter((draft) => draft.replied).length },
|
|
3239
|
+
acceptanceRate: accepted + rejected ? accepted / (accepted + rejected) : null,
|
|
3240
|
+
rejections: review.findings.filter((finding) => decisionOf(finding) === "reject").map((finding) => ({
|
|
3241
|
+
id: finding.id,
|
|
3242
|
+
level: finding.level,
|
|
3243
|
+
file: finding.file,
|
|
3244
|
+
line: finding.line,
|
|
3245
|
+
title: finding.title,
|
|
3246
|
+
note: decisions[finding.id]?.note ?? finding.note
|
|
3247
|
+
}))
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
2805
3250
|
listReviews() {
|
|
2806
3251
|
return this.store.listReviews();
|
|
2807
3252
|
}
|
|
@@ -2841,6 +3286,7 @@ var ReviewService = class {
|
|
|
2841
3286
|
// ---------------------------------------------------------------- summary
|
|
2842
3287
|
setSummary(id, input) {
|
|
2843
3288
|
this.requireReview(id);
|
|
3289
|
+
this.assertWritable(id);
|
|
2844
3290
|
const value = input ?? {};
|
|
2845
3291
|
const list = (item, limit) => (Array.isArray(item) ? item : []).map((entry) => String(entry ?? "").trim()).filter(Boolean).slice(0, limit).map((entry) => entry.slice(0, 4e3));
|
|
2846
3292
|
const summary = {
|
|
@@ -2856,6 +3302,7 @@ var ReviewService = class {
|
|
|
2856
3302
|
}
|
|
2857
3303
|
// ---------------------------------------------------------------- findings
|
|
2858
3304
|
setFindings(id, raw) {
|
|
3305
|
+
this.assertWritable(id);
|
|
2859
3306
|
const review = this.getReview(id);
|
|
2860
3307
|
if (!Array.isArray(raw)) throw new Error(tr("findings: \u043E\u0436\u0438\u0434\u0430\u043B\u0441\u044F \u043C\u0430\u0441\u0441\u0438\u0432", "findings: expected an array"));
|
|
2861
3308
|
const existing = this.store.listFindings(id);
|
|
@@ -2893,6 +3340,7 @@ ${errors.join("\n")}`));
|
|
|
2893
3340
|
}
|
|
2894
3341
|
setDecisions(id, raw) {
|
|
2895
3342
|
this.requireReview(id);
|
|
3343
|
+
this.assertWritable(id);
|
|
2896
3344
|
const patch = {};
|
|
2897
3345
|
const input = raw ?? {};
|
|
2898
3346
|
for (const [findingId, value] of Object.entries(input)) {
|
|
@@ -2909,6 +3357,7 @@ ${errors.join("\n")}`));
|
|
|
2909
3357
|
}
|
|
2910
3358
|
// ---------------------------------------------------------------- drafts
|
|
2911
3359
|
setDraft(id, threadId, patch) {
|
|
3360
|
+
this.assertWritable(id);
|
|
2912
3361
|
const review = this.getReview(id);
|
|
2913
3362
|
const thread = review.threads.find((item) => item.id === threadId);
|
|
2914
3363
|
if (!thread) throw new Error(tr(`\u0442\u0440\u0435\u0434\u0430 ${threadId} \u043D\u0435\u0442 \u0432 \u044D\u0442\u043E\u043C \u0440\u0435\u0432\u044C\u044E`, `thread ${threadId} is not in this review`));
|
|
@@ -2949,6 +3398,7 @@ ${errors.join("\n")}`));
|
|
|
2949
3398
|
return result;
|
|
2950
3399
|
}
|
|
2951
3400
|
async reactToReview(id, emoji) {
|
|
3401
|
+
this.assertWritable(id);
|
|
2952
3402
|
if (!REACTIONS.includes(emoji)) {
|
|
2953
3403
|
throw new Error(tr(`\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u0440\u0435\u0430\u043A\u0446\u0438\u044F ${emoji}: ${REACTIONS.join(", ")}`, `unknown reaction ${emoji}: ${REACTIONS.join(", ")}`));
|
|
2954
3404
|
}
|
|
@@ -2967,6 +3417,7 @@ ${errors.join("\n")}`));
|
|
|
2967
3417
|
return { active: result.active, reactions };
|
|
2968
3418
|
}
|
|
2969
3419
|
async react(id, noteId, emoji) {
|
|
3420
|
+
this.assertWritable(id);
|
|
2970
3421
|
if (!REACTIONS.includes(emoji)) {
|
|
2971
3422
|
throw new Error(tr(`\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u0440\u0435\u0430\u043A\u0446\u0438\u044F ${emoji}: ${REACTIONS.join(", ")}`, `unknown reaction ${emoji}: ${REACTIONS.join(", ")}`));
|
|
2972
3423
|
}
|
|
@@ -2984,6 +3435,7 @@ ${errors.join("\n")}`));
|
|
|
2984
3435
|
return { active: result.active, reactions };
|
|
2985
3436
|
}
|
|
2986
3437
|
async uploadAttachment(id, input) {
|
|
3438
|
+
this.assertWritable(id);
|
|
2987
3439
|
const stored = this.store.getReview(id);
|
|
2988
3440
|
if (!stored) throw new Error(tr(`\u0440\u0435\u0432\u044C\u044E ${id} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E`, `review ${id} not found`));
|
|
2989
3441
|
const spec = attachmentSpec(String(input.name ?? ""), String(input.contentType ?? ""));
|
|
@@ -3027,6 +3479,7 @@ ${errors.join("\n")}`));
|
|
|
3027
3479
|
return { review, thread: thread ?? null, note: note ?? null };
|
|
3028
3480
|
}
|
|
3029
3481
|
async updateComment(id, noteId, body) {
|
|
3482
|
+
this.assertWritable(id);
|
|
3030
3483
|
const { review, note } = this.noteInReview(id, noteId);
|
|
3031
3484
|
if (!note) throw new Error(tr(`\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u044F ${noteId} \u043D\u0435\u0442 \u0432 \u044D\u0442\u043E\u043C \u0440\u0435\u0432\u044C\u044E`, `comment ${noteId} is not in this review`));
|
|
3032
3485
|
if (!review.user || note.author !== review.user.username) {
|
|
@@ -3048,6 +3501,7 @@ ${errors.join("\n")}`));
|
|
|
3048
3501
|
this.emit(id);
|
|
3049
3502
|
}
|
|
3050
3503
|
async deleteComment(id, noteId) {
|
|
3504
|
+
this.assertWritable(id);
|
|
3051
3505
|
const { review, note } = this.noteInReview(id, noteId);
|
|
3052
3506
|
if (!note) throw new Error(tr(`\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u044F ${noteId} \u043D\u0435\u0442 \u0432 \u044D\u0442\u043E\u043C \u0440\u0435\u0432\u044C\u044E`, `comment ${noteId} is not in this review`));
|
|
3053
3507
|
if (!review.user || note.author !== review.user.username) {
|
|
@@ -3065,6 +3519,7 @@ ${errors.join("\n")}`));
|
|
|
3065
3519
|
}
|
|
3066
3520
|
// ---------------------------------------------------------------- notes
|
|
3067
3521
|
addNote(id, input) {
|
|
3522
|
+
this.assertWritable(id);
|
|
3068
3523
|
const review = this.getReview(id);
|
|
3069
3524
|
if (!findNewLine(review.diff, input.file, input.line)) {
|
|
3070
3525
|
throw new Error(tr(`\u0441\u0442\u0440\u043E\u043A\u0430 ${input.file}:${input.line} \u043D\u0435 \u0432\u0445\u043E\u0434\u0438\u0442 \u0432 diff`, `line ${input.file}:${input.line} is not in the diff`));
|
|
@@ -3091,6 +3546,7 @@ ${errors.join("\n")}`));
|
|
|
3091
3546
|
return note;
|
|
3092
3547
|
}
|
|
3093
3548
|
updateNote(id, noteId, patch) {
|
|
3549
|
+
this.assertWritable(id);
|
|
3094
3550
|
const existing = this.store.listNotes(id).find((note) => note.id === noteId);
|
|
3095
3551
|
if (!existing) throw new Error(tr(`\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u044F ${noteId} \u043D\u0435\u0442`, `comment ${noteId} not found`));
|
|
3096
3552
|
const next = {
|
|
@@ -3111,6 +3567,7 @@ ${errors.join("\n")}`));
|
|
|
3111
3567
|
return next;
|
|
3112
3568
|
}
|
|
3113
3569
|
deleteNote(id, noteId) {
|
|
3570
|
+
this.assertWritable(id);
|
|
3114
3571
|
const existing = this.store.listNotes(id).find((note) => note.id === noteId);
|
|
3115
3572
|
if (!existing) return;
|
|
3116
3573
|
if (existing.posted) throw new Error(tr("\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0439 \u0443\u0436\u0435 \u043E\u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u043D: \u0443\u0434\u0430\u043B\u044F\u0442\u044C \u0435\u0433\u043E \u043D\u0443\u0436\u043D\u043E \u0432 \u043F\u043B\u0430\u0442\u0444\u043E\u0440\u043C\u0435", "the comment is already published: delete it in the platform"));
|
|
@@ -3209,6 +3666,7 @@ ${errors.join("\n")}`));
|
|
|
3209
3666
|
return { reviewId: id, kind, items, hash, createdAt: this.now().toISOString() };
|
|
3210
3667
|
}
|
|
3211
3668
|
approve(id, kind, ids, expectedHash) {
|
|
3669
|
+
this.assertWritable(id);
|
|
3212
3670
|
const preview = this.previewPublish(id, kind, ids);
|
|
3213
3671
|
if (preview.plan.hash !== expectedHash) {
|
|
3214
3672
|
throw new Error(tr("\u043D\u0430\u0431\u043E\u0440 \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439 \u0438\u0437\u043C\u0435\u043D\u0438\u043B\u0441\u044F \u043F\u043E\u0441\u043B\u0435 \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u044F: \u043E\u0431\u043D\u043E\u0432\u0438\u0442\u0435 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443 \u0438 \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u0435 \u0437\u0430\u043D\u043E\u0432\u043E", "the plan changed after confirmation: refresh and confirm again"));
|
|
@@ -3237,6 +3695,7 @@ ${errors.join("\n")}`));
|
|
|
3237
3695
|
return approval;
|
|
3238
3696
|
}
|
|
3239
3697
|
async publish(id, approvalId) {
|
|
3698
|
+
this.assertWritable(id);
|
|
3240
3699
|
const approval = this.store.getApproval(approvalId);
|
|
3241
3700
|
if (!approval) throw new Error(tr("\u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u0435 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E", "approval not found"));
|
|
3242
3701
|
if (approval.reviewId !== id) throw new Error(tr("\u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u0435 \u0432\u044B\u0434\u0430\u043D\u043E \u0434\u043B\u044F \u0434\u0440\u0443\u0433\u043E\u0433\u043E \u0440\u0435\u0432\u044C\u044E", "the approval belongs to another review"));
|
|
@@ -3393,16 +3852,21 @@ ${errors.join("\n")}`));
|
|
|
3393
3852
|
language
|
|
3394
3853
|
});
|
|
3395
3854
|
const maxBytes = config.rules.maxTotalBytes ?? 0;
|
|
3855
|
+
const agents = config.review?.agents ?? 3;
|
|
3856
|
+
const roles = effectiveRoleIds(agents, config.review?.roles ?? DEFAULT_REVIEW_ROLES).map((id2) => resolveReviewRole(id2, language, config.review?.customRoles ?? {})).filter((role) => Boolean(role));
|
|
3396
3857
|
return {
|
|
3397
3858
|
markdown: renderRules(effective, { language, maxBytes }),
|
|
3398
3859
|
configPath: effective.configPath,
|
|
3399
3860
|
warnings: effective.warnings,
|
|
3400
3861
|
checks: effective.checks,
|
|
3401
3862
|
language,
|
|
3402
|
-
maxBytes
|
|
3863
|
+
maxBytes,
|
|
3864
|
+
agents,
|
|
3865
|
+
roles
|
|
3403
3866
|
};
|
|
3404
3867
|
}
|
|
3405
3868
|
async runChecks(id, options) {
|
|
3869
|
+
this.assertWritable(id);
|
|
3406
3870
|
const stored = this.store.getReview(id);
|
|
3407
3871
|
if (!stored) throw new Error(tr(`\u0440\u0435\u0432\u044C\u044E ${id} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E`, `review ${id} not found`));
|
|
3408
3872
|
const { checks } = await this.rules(id);
|
|
@@ -3498,6 +3962,19 @@ ${stderr}`.trim()).slice(0, 2e4),
|
|
|
3498
3962
|
if (line === null) return null;
|
|
3499
3963
|
return snippetAround(this.diffFor(id), file, line, 4);
|
|
3500
3964
|
}
|
|
3965
|
+
isReadOnly(id) {
|
|
3966
|
+
return process.env.REVDECK_READ_ONLY === "1" || this.configOf(id)?.review?.readOnly === true;
|
|
3967
|
+
}
|
|
3968
|
+
assertWritable(id) {
|
|
3969
|
+
if (!this.isReadOnly(id)) return;
|
|
3970
|
+
throw new Error(tr("\u0440\u0435\u0432\u044C\u044E \u0432 \u0440\u0435\u0436\u0438\u043C\u0435 read-only: \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u0438 \u043F\u0443\u0431\u043B\u0438\u043A\u0430\u0446\u0438\u044F \u0437\u0430\u043F\u0440\u0435\u0449\u0435\u043D\u044B", "the review is read-only: changes and publishing are disabled"));
|
|
3971
|
+
}
|
|
3972
|
+
listVersions(id) {
|
|
3973
|
+
return this.store.listVersions(id);
|
|
3974
|
+
}
|
|
3975
|
+
getVersion(id, versionId) {
|
|
3976
|
+
return this.store.getVersion(id, versionId);
|
|
3977
|
+
}
|
|
3501
3978
|
configOf(id) {
|
|
3502
3979
|
return this.store.getReview(id)?.snapshot.config ?? null;
|
|
3503
3980
|
}
|
|
@@ -3575,6 +4052,14 @@ async function dispatch(service, method, params) {
|
|
|
3575
4052
|
if (params.refresh === true) await service.refreshReview(id);
|
|
3576
4053
|
return { review: service.getView(id), reviews: service.listReviews() };
|
|
3577
4054
|
}
|
|
4055
|
+
case "versions.list":
|
|
4056
|
+
return { versions: service.listVersions(String(params.review ?? "")) };
|
|
4057
|
+
case "versions.get":
|
|
4058
|
+
return { version: service.getVersion(String(params.review ?? ""), Number(params.id ?? 0)) };
|
|
4059
|
+
case "secrets.get":
|
|
4060
|
+
return service.secrets(String(params.review ?? ""));
|
|
4061
|
+
case "analytics.get":
|
|
4062
|
+
return service.analytics(String(params.review ?? ""));
|
|
3578
4063
|
case "reviews.remove":
|
|
3579
4064
|
service.removeReview(String(params.review ?? ""));
|
|
3580
4065
|
return { ok: true };
|
|
@@ -3938,6 +4423,27 @@ data: ${JSON.stringify(event)}
|
|
|
3938
4423
|
reply(res, 200, { ok: true, reactions: await service.reactions(review, noteIds) });
|
|
3939
4424
|
return;
|
|
3940
4425
|
}
|
|
4426
|
+
if (req.method === "GET" && url.pathname === "/api/versions") {
|
|
4427
|
+
const review = url.searchParams.get("review") ?? "";
|
|
4428
|
+
reply(res, 200, { ok: true, versions: service.listVersions(review) });
|
|
4429
|
+
return;
|
|
4430
|
+
}
|
|
4431
|
+
if (req.method === "GET" && url.pathname === "/api/version") {
|
|
4432
|
+
const review = url.searchParams.get("review") ?? "";
|
|
4433
|
+
const id = Number(url.searchParams.get("id") ?? 0);
|
|
4434
|
+
reply(res, 200, { ok: true, version: service.getVersion(review, id) });
|
|
4435
|
+
return;
|
|
4436
|
+
}
|
|
4437
|
+
if (req.method === "GET" && url.pathname === "/api/secrets") {
|
|
4438
|
+
const review = url.searchParams.get("review") ?? "";
|
|
4439
|
+
reply(res, 200, { ok: true, ...await service.secrets(review) });
|
|
4440
|
+
return;
|
|
4441
|
+
}
|
|
4442
|
+
if (req.method === "GET" && url.pathname === "/api/analytics") {
|
|
4443
|
+
const review = url.searchParams.get("review") ?? "";
|
|
4444
|
+
reply(res, 200, { ok: true, analytics: service.analytics(review) });
|
|
4445
|
+
return;
|
|
4446
|
+
}
|
|
3941
4447
|
if (req.method === "GET" && url.pathname === "/api/review-reactions") {
|
|
3942
4448
|
const review = url.searchParams.get("review") ?? "";
|
|
3943
4449
|
const view = service.getReview(review);
|