revdeck 0.12.2 → 0.14.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 +39 -0
- package/README.md +20 -9
- package/README.ru.md +20 -7
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +2 -2
- package/dist/daemon.js +247 -2
- package/dist/daemon.js.map +4 -4
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +2 -2
- package/dist/ui/assets/index-BOklczb0.js +19 -0
- package/dist/ui/assets/index-CZsZ7zAv.css +1 -0
- package/dist/ui/index.html +2 -2
- package/docs/architecture.md +7 -1
- package/docs/capabilities.md +20 -3
- package/docs/configuration.md +1 -0
- package/docs/protocol.md +2 -0
- package/docs/ru/architecture.md +9 -2
- package/docs/ru/capabilities.md +20 -3
- package/docs/ru/configuration.md +1 -0
- package/docs/ru/protocol.md +2 -0
- package/docs/ru/threat-model.md +1 -0
- package/docs/threat-model.md +1 -0
- package/package.json +1 -1
- package/dist/ui/assets/index-BzmUV1qC.js +0 -19
- package/dist/ui/assets/index-CPJbq_MG.css +0 -1
package/dist/daemon.js
CHANGED
|
@@ -698,6 +698,10 @@ rename to ${newPath}
|
|
|
698
698
|
}
|
|
699
699
|
return parseUnifiedDiff(chunks.join("\n"));
|
|
700
700
|
}
|
|
701
|
+
async fileContent(path12, ref) {
|
|
702
|
+
const endpoint = `projects/${this.projectRef}/repository/files/${encodeURIComponent(path12)}/raw`;
|
|
703
|
+
return this.call([query(endpoint, { ref })]);
|
|
704
|
+
}
|
|
701
705
|
async threads() {
|
|
702
706
|
const discussions = await this.paged(this.endpoint("/discussions"));
|
|
703
707
|
const threads = [];
|
|
@@ -1057,6 +1061,10 @@ rename to ${newPath}
|
|
|
1057
1061
|
}
|
|
1058
1062
|
return parseUnifiedDiff(chunks.join("\n"));
|
|
1059
1063
|
}
|
|
1064
|
+
async fileContent(path12, ref) {
|
|
1065
|
+
const encoded = path12.split("/").map(encodeURIComponent).join("/");
|
|
1066
|
+
return this.call(["-H", "Accept: application/vnd.github.raw", query(`repos/${this.repo}/contents/${encoded}`, { ref })]);
|
|
1067
|
+
}
|
|
1060
1068
|
async threads() {
|
|
1061
1069
|
const nodes = [];
|
|
1062
1070
|
let after = null;
|
|
@@ -1405,7 +1413,7 @@ async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
|
|
|
1405
1413
|
init_redact();
|
|
1406
1414
|
|
|
1407
1415
|
// src/version.ts
|
|
1408
|
-
var VERSION = "0.
|
|
1416
|
+
var VERSION = "0.14.0";
|
|
1409
1417
|
var PROTOCOL_VERSION = 2;
|
|
1410
1418
|
|
|
1411
1419
|
// src/daemon/main.ts
|
|
@@ -3778,6 +3786,147 @@ function toReviewView(review, now = Date.now()) {
|
|
|
3778
3786
|
};
|
|
3779
3787
|
}
|
|
3780
3788
|
|
|
3789
|
+
// src/daemon/update.ts
|
|
3790
|
+
init_errors();
|
|
3791
|
+
|
|
3792
|
+
// src/core/update.ts
|
|
3793
|
+
function parseVersion(value) {
|
|
3794
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(value.trim());
|
|
3795
|
+
if (!match) return null;
|
|
3796
|
+
return {
|
|
3797
|
+
major: Number(match[1]),
|
|
3798
|
+
minor: Number(match[2]),
|
|
3799
|
+
patch: Number(match[3]),
|
|
3800
|
+
prerelease: match[4] ? match[4].split(".") : []
|
|
3801
|
+
};
|
|
3802
|
+
}
|
|
3803
|
+
function comparePrerelease(left, right) {
|
|
3804
|
+
if (!left.length && !right.length) return 0;
|
|
3805
|
+
if (!left.length) return 1;
|
|
3806
|
+
if (!right.length) return -1;
|
|
3807
|
+
const length = Math.max(left.length, right.length);
|
|
3808
|
+
for (let index = 0; index < length; index += 1) {
|
|
3809
|
+
const a = left[index];
|
|
3810
|
+
const b = right[index];
|
|
3811
|
+
if (a === void 0) return -1;
|
|
3812
|
+
if (b === void 0) return 1;
|
|
3813
|
+
const aNumeric = /^\d+$/.test(a);
|
|
3814
|
+
const bNumeric = /^\d+$/.test(b);
|
|
3815
|
+
if (aNumeric && bNumeric) {
|
|
3816
|
+
const delta = Number(a) - Number(b);
|
|
3817
|
+
if (delta !== 0) return delta < 0 ? -1 : 1;
|
|
3818
|
+
} else if (aNumeric !== bNumeric) {
|
|
3819
|
+
return aNumeric ? -1 : 1;
|
|
3820
|
+
} else {
|
|
3821
|
+
const delta = a < b ? -1 : a > b ? 1 : 0;
|
|
3822
|
+
if (delta !== 0) return delta;
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
return 0;
|
|
3826
|
+
}
|
|
3827
|
+
function compareVersions(left, right) {
|
|
3828
|
+
const a = parseVersion(left);
|
|
3829
|
+
const b = parseVersion(right);
|
|
3830
|
+
if (!a || !b) return 0;
|
|
3831
|
+
const delta = a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
|
3832
|
+
if (delta !== 0) return delta < 0 ? -1 : 1;
|
|
3833
|
+
return comparePrerelease(a.prerelease, b.prerelease);
|
|
3834
|
+
}
|
|
3835
|
+
function isNewerVersion(latest, current2) {
|
|
3836
|
+
return compareVersions(latest, current2) > 0;
|
|
3837
|
+
}
|
|
3838
|
+
|
|
3839
|
+
// src/daemon/update.ts
|
|
3840
|
+
init_locale();
|
|
3841
|
+
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
3842
|
+
var ERROR_TTL_MS = 5 * 60 * 1e3;
|
|
3843
|
+
var REQUEST_TIMEOUT_MS = 5e3;
|
|
3844
|
+
var DIST_TAGS_URL = "https://registry.npmjs.org/-/package/revdeck/dist-tags";
|
|
3845
|
+
var RELEASE_TAG_URL = "https://github.com/katrov/revdeck/releases/tag/v";
|
|
3846
|
+
var UpdateChecker = class {
|
|
3847
|
+
currentVersion;
|
|
3848
|
+
fetchImpl;
|
|
3849
|
+
now;
|
|
3850
|
+
ttlMs;
|
|
3851
|
+
enabled;
|
|
3852
|
+
cache = null;
|
|
3853
|
+
pending = null;
|
|
3854
|
+
constructor(options = {}) {
|
|
3855
|
+
this.currentVersion = options.currentVersion ?? VERSION;
|
|
3856
|
+
this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
3857
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
3858
|
+
this.ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
3859
|
+
this.enabled = (options.env ?? process.env).REVDECK_UPDATE_CHECK !== "0";
|
|
3860
|
+
}
|
|
3861
|
+
base() {
|
|
3862
|
+
return {
|
|
3863
|
+
enabled: this.enabled,
|
|
3864
|
+
current: this.currentVersion,
|
|
3865
|
+
latest: null,
|
|
3866
|
+
updateAvailable: false,
|
|
3867
|
+
releaseUrl: null,
|
|
3868
|
+
checkedAt: null
|
|
3869
|
+
};
|
|
3870
|
+
}
|
|
3871
|
+
async check(force = false) {
|
|
3872
|
+
if (!this.enabled) return this.base();
|
|
3873
|
+
const now = this.now().getTime();
|
|
3874
|
+
if (!force && this.cache) {
|
|
3875
|
+
const ttl = this.cache.info.error ? ERROR_TTL_MS : this.ttlMs;
|
|
3876
|
+
if (now - this.cache.at < ttl) return this.cache.info;
|
|
3877
|
+
}
|
|
3878
|
+
if (this.pending) return this.pending;
|
|
3879
|
+
this.pending = this.fetchLatest().then((latest) => this.success(latest)).catch((error) => this.failure(error)).finally(() => {
|
|
3880
|
+
this.pending = null;
|
|
3881
|
+
});
|
|
3882
|
+
return this.pending;
|
|
3883
|
+
}
|
|
3884
|
+
async fetchLatest() {
|
|
3885
|
+
const response = await this.fetchImpl(DIST_TAGS_URL, {
|
|
3886
|
+
headers: {
|
|
3887
|
+
accept: "application/json",
|
|
3888
|
+
"user-agent": `revdeck/${this.currentVersion}`
|
|
3889
|
+
},
|
|
3890
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
3891
|
+
});
|
|
3892
|
+
if (!response.ok) {
|
|
3893
|
+
throw new Error(`npm registry: HTTP ${response.status}`);
|
|
3894
|
+
}
|
|
3895
|
+
const data = await response.json();
|
|
3896
|
+
const latest = typeof data.latest === "string" ? data.latest.trim().replace(/^v/, "") : "";
|
|
3897
|
+
if (!parseVersion(latest)) {
|
|
3898
|
+
throw new Error(tr("npm registry: \u043D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F \u0432 dist-tags", "npm registry: invalid version in dist-tags"));
|
|
3899
|
+
}
|
|
3900
|
+
return latest;
|
|
3901
|
+
}
|
|
3902
|
+
success(latest) {
|
|
3903
|
+
const updateAvailable = isNewerVersion(latest, this.currentVersion);
|
|
3904
|
+
const info = {
|
|
3905
|
+
enabled: true,
|
|
3906
|
+
current: this.currentVersion,
|
|
3907
|
+
latest,
|
|
3908
|
+
updateAvailable,
|
|
3909
|
+
releaseUrl: updateAvailable ? `${RELEASE_TAG_URL}${latest}` : null,
|
|
3910
|
+
checkedAt: this.now().toISOString()
|
|
3911
|
+
};
|
|
3912
|
+
this.cache = { info, at: this.now().getTime() };
|
|
3913
|
+
return info;
|
|
3914
|
+
}
|
|
3915
|
+
failure(error) {
|
|
3916
|
+
const previous = this.cache?.info;
|
|
3917
|
+
const info = {
|
|
3918
|
+
...this.base(),
|
|
3919
|
+
latest: previous?.latest ?? null,
|
|
3920
|
+
updateAvailable: previous?.updateAvailable ?? false,
|
|
3921
|
+
releaseUrl: previous?.releaseUrl ?? null,
|
|
3922
|
+
checkedAt: previous?.checkedAt ?? null,
|
|
3923
|
+
error: tr(`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F: ${messageOf(error)}`, `could not check for updates: ${messageOf(error)}`).slice(0, 400)
|
|
3924
|
+
};
|
|
3925
|
+
this.cache = { info, at: this.now().getTime() };
|
|
3926
|
+
return info;
|
|
3927
|
+
}
|
|
3928
|
+
};
|
|
3929
|
+
|
|
3781
3930
|
// src/cli/format.ts
|
|
3782
3931
|
init_redact();
|
|
3783
3932
|
init_locale();
|
|
@@ -4298,12 +4447,15 @@ var ReviewService = class {
|
|
|
4298
4447
|
now;
|
|
4299
4448
|
refreshTtlMs;
|
|
4300
4449
|
syncIntervalMs;
|
|
4450
|
+
updates;
|
|
4301
4451
|
timer = null;
|
|
4302
4452
|
syncing = false;
|
|
4303
4453
|
/** Ревью, которые уже обновляются: не запускаем параллельный refresh из UI и sync. */
|
|
4304
4454
|
refreshing = /* @__PURE__ */ new Set();
|
|
4305
4455
|
/** Временные снимки для просмотра MR/PR без создания ревью. */
|
|
4306
4456
|
previews = /* @__PURE__ */ new Map();
|
|
4457
|
+
/** Полные файлы для раскрытия diff; ключ включает head/base, коммит и путь. */
|
|
4458
|
+
fileContentCache = /* @__PURE__ */ new Map();
|
|
4307
4459
|
constructor(options) {
|
|
4308
4460
|
this.store = options.store;
|
|
4309
4461
|
this.runImpl = options.runImpl ?? run;
|
|
@@ -4311,6 +4463,10 @@ var ReviewService = class {
|
|
|
4311
4463
|
this.refreshTtlMs = options.refreshTtlMs ?? 6e4;
|
|
4312
4464
|
this.syncIntervalMs = options.syncIntervalMs ?? 12e4;
|
|
4313
4465
|
this.providerFactory = options.providerFactory ?? (async (ref, root) => createProvider(ref, { root }));
|
|
4466
|
+
this.updates = new UpdateChecker({
|
|
4467
|
+
now: this.now,
|
|
4468
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
4469
|
+
});
|
|
4314
4470
|
this.events.setMaxListeners(50);
|
|
4315
4471
|
}
|
|
4316
4472
|
close() {
|
|
@@ -4631,7 +4787,7 @@ var ReviewService = class {
|
|
|
4631
4787
|
readOnly: true
|
|
4632
4788
|
};
|
|
4633
4789
|
const view = toReviewView(review, this.now().getTime());
|
|
4634
|
-
this.previews.set(id, { ref, view, diff, at: this.now().getTime() });
|
|
4790
|
+
this.previews.set(id, { ref, view, diff, root, at: this.now().getTime() });
|
|
4635
4791
|
while (this.previews.size > 8) {
|
|
4636
4792
|
const oldest = [...this.previews.entries()].sort((left, right) => left[1].at - right[1].at)[0];
|
|
4637
4793
|
if (!oldest) break;
|
|
@@ -5098,6 +5254,83 @@ ${t("\u2026 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u0444\u0438\u0447\
|
|
|
5098
5254
|
if (!found) return null;
|
|
5099
5255
|
return { path: found.path, status: found.status, binary: found.binary, hunks: found.hunks };
|
|
5100
5256
|
}
|
|
5257
|
+
/** Последняя версия revdeck в npm; force=true — ручная проверка из настроек. */
|
|
5258
|
+
async updateInfo(force = false) {
|
|
5259
|
+
return this.updates.check(force);
|
|
5260
|
+
}
|
|
5261
|
+
/**
|
|
5262
|
+
* Полный файл на head (или base для удалённого файла), чтобы UI раскрывал
|
|
5263
|
+
* скрытые между hunks строки. Локальный git дешевле API платформы, но
|
|
5264
|
+
* коммит может быть ещё не загружен в рабочую копию — тогда читаем raw у
|
|
5265
|
+
* провайдера. Путь берётся только из сохранённого diff.
|
|
5266
|
+
*/
|
|
5267
|
+
async fileContent(id, file) {
|
|
5268
|
+
const cachedPreview = this.previews.get(id);
|
|
5269
|
+
const preview = cachedPreview && this.now().getTime() - cachedPreview.at < 60 * 6e4 ? cachedPreview : null;
|
|
5270
|
+
const stored = preview ? null : this.store.getReview(id);
|
|
5271
|
+
if (!preview && !stored) {
|
|
5272
|
+
throw Object.assign(new Error(tr(`\u0440\u0435\u0432\u044C\u044E ${id} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E`, `review ${id} not found`)), { status: 404 });
|
|
5273
|
+
}
|
|
5274
|
+
const diff = preview?.diff ?? stored.snapshot.diff;
|
|
5275
|
+
const info = preview?.view.info ?? this.store.info(id) ?? (stored ? fallbackInfo(stored.row) : null);
|
|
5276
|
+
const root = preview?.root ?? stored.row.root;
|
|
5277
|
+
const found = diff.find((item) => item.path === file || item.oldPath === file);
|
|
5278
|
+
if (!found || !info) {
|
|
5279
|
+
throw Object.assign(new Error(tr("\u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442 \u0432 diff", "the file is not in the diff")), { status: 404 });
|
|
5280
|
+
}
|
|
5281
|
+
if (found.binary) {
|
|
5282
|
+
throw Object.assign(new Error(tr("\u0431\u0438\u043D\u0430\u0440\u043D\u044B\u0439 \u0444\u0430\u0439\u043B: \u0441\u043A\u0440\u044B\u0442\u044B\u0445 \u0441\u0442\u0440\u043E\u043A \u043D\u0435\u0442", "binary file: there are no hidden lines")), { status: 400 });
|
|
5283
|
+
}
|
|
5284
|
+
const side = found.status === "deleted" ? "base" : "head";
|
|
5285
|
+
const sha = side === "head" ? info.commit.head : info.commit.base;
|
|
5286
|
+
const path12 = side === "head" ? found.path : found.oldPath || found.path;
|
|
5287
|
+
if (!sha || !path12) {
|
|
5288
|
+
throw Object.assign(new Error(tr("\u043D\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043D \u043A\u043E\u043C\u043C\u0438\u0442 \u0444\u0430\u0439\u043B\u0430", "the file commit is unknown")), { status: 404 });
|
|
5289
|
+
}
|
|
5290
|
+
const key = `${id}|${side}|${sha}|${path12}`;
|
|
5291
|
+
const hit = this.fileContentCache.get(key);
|
|
5292
|
+
if (hit && this.now().getTime() - hit.at < 10 * 6e4) return hit.value;
|
|
5293
|
+
let text2;
|
|
5294
|
+
try {
|
|
5295
|
+
const provider = preview ? await this.providerFactory(preview.ref, preview.root) : await this.providerFor(id);
|
|
5296
|
+
try {
|
|
5297
|
+
const result = await this.runImpl("git", ["show", `${sha}:${path12}`], {
|
|
5298
|
+
cwd: root,
|
|
5299
|
+
timeoutMs: 3e4,
|
|
5300
|
+
maxBuffer: 16 * 1024 * 1024
|
|
5301
|
+
});
|
|
5302
|
+
text2 = result.stdout;
|
|
5303
|
+
} catch {
|
|
5304
|
+
text2 = await provider.fileContent(path12, sha);
|
|
5305
|
+
}
|
|
5306
|
+
} catch (error) {
|
|
5307
|
+
throw Object.assign(
|
|
5308
|
+
new Error(
|
|
5309
|
+
tr(
|
|
5310
|
+
`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u0442\u044C \u0444\u0430\u0439\u043B: ${redact(messageOf(error))}`,
|
|
5311
|
+
`could not read the file: ${redact(messageOf(error))}`
|
|
5312
|
+
)
|
|
5313
|
+
),
|
|
5314
|
+
{ status: 502 }
|
|
5315
|
+
);
|
|
5316
|
+
}
|
|
5317
|
+
const normalized = text2.replace(/\r\n/g, "\n");
|
|
5318
|
+
const all = normalized === "" ? [] : (normalized.endsWith("\n") ? normalized.slice(0, -1) : normalized).split("\n");
|
|
5319
|
+
const value = {
|
|
5320
|
+
path: path12,
|
|
5321
|
+
side,
|
|
5322
|
+
lines: all.slice(0, 2e4),
|
|
5323
|
+
totalLines: all.length,
|
|
5324
|
+
truncated: all.length > 2e4
|
|
5325
|
+
};
|
|
5326
|
+
this.fileContentCache.set(key, { value, at: this.now().getTime() });
|
|
5327
|
+
while (this.fileContentCache.size > 32) {
|
|
5328
|
+
const oldest = this.fileContentCache.keys().next().value;
|
|
5329
|
+
if (oldest === void 0) break;
|
|
5330
|
+
this.fileContentCache.delete(oldest);
|
|
5331
|
+
}
|
|
5332
|
+
return value;
|
|
5333
|
+
}
|
|
5101
5334
|
// ---------------------------------------------------------------- summary
|
|
5102
5335
|
setSummary(id, input, actor = "system") {
|
|
5103
5336
|
this.requireReview(id);
|
|
@@ -6531,6 +6764,11 @@ data: ${JSON.stringify(event)}
|
|
|
6531
6764
|
reply(res, 401, { ok: false, error: "\u043D\u0435\u0442 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u0438" });
|
|
6532
6765
|
return;
|
|
6533
6766
|
}
|
|
6767
|
+
if (req.method === "GET" && url.pathname === "/api/update") {
|
|
6768
|
+
const update = await service.updateInfo(url.searchParams.get("refresh") === "1");
|
|
6769
|
+
reply(res, 200, { ok: true, update });
|
|
6770
|
+
return;
|
|
6771
|
+
}
|
|
6534
6772
|
if (req.method === "GET" && url.pathname === "/api/health") {
|
|
6535
6773
|
reply(res, 200, { ok: true, version: options.version ?? "dev", reviews: service.listReviews().length });
|
|
6536
6774
|
return;
|
|
@@ -6566,6 +6804,13 @@ data: ${JSON.stringify(event)}
|
|
|
6566
6804
|
reply(res, 200, { ok: true, file: diff });
|
|
6567
6805
|
return;
|
|
6568
6806
|
}
|
|
6807
|
+
if (req.method === "GET" && url.pathname === "/api/file") {
|
|
6808
|
+
const review = url.searchParams.get("review") ?? "";
|
|
6809
|
+
const file = url.searchParams.get("file") ?? "";
|
|
6810
|
+
const content = await service.fileContent(review, file);
|
|
6811
|
+
reply(res, 200, { ok: true, file: content });
|
|
6812
|
+
return;
|
|
6813
|
+
}
|
|
6569
6814
|
if (req.method === "GET" && url.pathname === "/api/rules") {
|
|
6570
6815
|
const review = url.searchParams.get("review") ?? "";
|
|
6571
6816
|
reply(res, 200, { ok: true, rules: await service.rules(review) });
|