revdeck 0.6.0 → 0.8.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 +66 -1
- package/CONTRIBUTING.md +5 -1
- package/README.md +57 -17
- package/README.ru.md +59 -21
- package/SECURITY.md +1 -1
- package/dist/cli.js +485 -263
- package/dist/cli.js.map +4 -4
- package/dist/daemon.js +428 -121
- package/dist/daemon.js.map +4 -4
- package/dist/mcp.js +76 -28
- package/dist/mcp.js.map +4 -4
- package/dist/ui/assets/index-BIVPy49b.css +1 -0
- package/dist/ui/assets/index-BcvEWwhI.js +18 -0
- package/dist/ui/favicon.svg +8 -3
- package/dist/ui/icon-128.png +0 -0
- package/dist/ui/icon-32.png +0 -0
- package/dist/ui/index.html +4 -2
- package/docs/README.md +3 -0
- package/docs/architecture.md +10 -6
- package/docs/assets/brand/README.md +49 -0
- package/docs/assets/brand/icon-1024.png +0 -0
- package/docs/assets/brand/icon-128.png +0 -0
- package/docs/assets/brand/icon-256.png +0 -0
- package/docs/assets/brand/icon-32.png +0 -0
- package/docs/assets/brand/icon-512.png +0 -0
- package/docs/assets/brand/icon-64.png +0 -0
- package/docs/assets/brand/icon.svg +9 -0
- package/docs/assets/brand/logo-dark.png +0 -0
- package/docs/assets/brand/logo-dark.svg +13 -0
- package/docs/assets/brand/logo.png +0 -0
- package/docs/assets/brand/logo.svg +13 -0
- package/docs/capabilities.md +23 -11
- package/docs/configuration.md +25 -8
- package/docs/integrations.md +30 -16
- package/docs/protocol.md +34 -13
- package/docs/ru/README.md +3 -0
- package/docs/ru/architecture.md +10 -6
- package/docs/ru/capabilities.md +24 -10
- package/docs/ru/configuration.md +21 -6
- package/docs/ru/integrations.md +29 -16
- package/docs/ru/protocol.md +33 -12
- package/docs/ru/threat-model.md +6 -5
- package/docs/threat-model.md +10 -8
- package/package.json +5 -2
- package/skills/revdeck/en/Feedback.md +3 -2
- package/skills/revdeck/en/Review.md +3 -2
- package/skills/revdeck/ru/Feedback.md +3 -2
- package/skills/revdeck/ru/Review.md +2 -2
- package/dist/ui/assets/index-BH0dNFhd.css +0 -1
- package/dist/ui/assets/index-Wz1DYbiv.js +0 -14
package/dist/daemon.js
CHANGED
|
@@ -139,7 +139,7 @@ var init_errors = __esm({
|
|
|
139
139
|
import { execFile } from "node:child_process";
|
|
140
140
|
import { access, constants as constants2 } from "node:fs/promises";
|
|
141
141
|
import os2 from "node:os";
|
|
142
|
-
import
|
|
142
|
+
import path3 from "node:path";
|
|
143
143
|
function scrubEnv(extra) {
|
|
144
144
|
const env = {};
|
|
145
145
|
for (const [key, value] of Object.entries(process.env)) {
|
|
@@ -169,11 +169,11 @@ async function resolveExecutable(command) {
|
|
|
169
169
|
const cached = RESOLVED.get(command);
|
|
170
170
|
if (cached) return cached;
|
|
171
171
|
const dirs = [
|
|
172
|
-
...(process.env.PATH ?? "").split(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
172
|
+
...(process.env.PATH ?? "").split(path3.delimiter),
|
|
173
|
+
path3.join(os2.homedir(), ".local", "bin"),
|
|
174
|
+
path3.join(os2.homedir(), ".local", "share", "mise", "shims"),
|
|
175
|
+
path3.join(os2.homedir(), ".asdf", "shims"),
|
|
176
|
+
path3.join(os2.homedir(), ".npm-global", "bin"),
|
|
177
177
|
"/opt/homebrew/bin",
|
|
178
178
|
"/usr/local/bin",
|
|
179
179
|
"/usr/bin",
|
|
@@ -182,7 +182,7 @@ async function resolveExecutable(command) {
|
|
|
182
182
|
const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
|
|
183
183
|
for (const dir of [...new Set(dirs)]) {
|
|
184
184
|
for (const extension of extensions) {
|
|
185
|
-
const candidate =
|
|
185
|
+
const candidate = path3.join(dir, `${command}${extension}`);
|
|
186
186
|
try {
|
|
187
187
|
await access(candidate, constants2.X_OK);
|
|
188
188
|
RESOLVED.set(command, candidate);
|
|
@@ -419,11 +419,11 @@ function diffStats(files) {
|
|
|
419
419
|
function changedPaths(files) {
|
|
420
420
|
return files.map((file) => file.path);
|
|
421
421
|
}
|
|
422
|
-
function findFile(files,
|
|
423
|
-
return files.find((file) => file.path ===
|
|
422
|
+
function findFile(files, path12) {
|
|
423
|
+
return files.find((file) => file.path === path12) ?? files.find((file) => file.oldPath === path12);
|
|
424
424
|
}
|
|
425
|
-
function findNewLine(files,
|
|
426
|
-
const file = findFile(files,
|
|
425
|
+
function findNewLine(files, path12, line) {
|
|
426
|
+
const file = findFile(files, path12);
|
|
427
427
|
if (!file) return void 0;
|
|
428
428
|
for (const hunk of file.hunks) {
|
|
429
429
|
for (const item of hunk.lines) {
|
|
@@ -432,8 +432,8 @@ function findNewLine(files, path11, line) {
|
|
|
432
432
|
}
|
|
433
433
|
return void 0;
|
|
434
434
|
}
|
|
435
|
-
function snippetAround(files,
|
|
436
|
-
const file = findFile(files,
|
|
435
|
+
function snippetAround(files, path12, line, radius = 6) {
|
|
436
|
+
const file = findFile(files, path12);
|
|
437
437
|
if (!file || line == null) return null;
|
|
438
438
|
const flat = file.hunks.flatMap((hunk) => hunk.lines);
|
|
439
439
|
const target = flat.findIndex((item) => item.newLine === line);
|
|
@@ -446,9 +446,9 @@ function snippetAround(files, path11, line, radius = 6) {
|
|
|
446
446
|
target: item.newLine === line
|
|
447
447
|
}));
|
|
448
448
|
}
|
|
449
|
-
function linePosition(files,
|
|
450
|
-
const file = findFile(files,
|
|
451
|
-
const found = findNewLine(files,
|
|
449
|
+
function linePosition(files, path12, line) {
|
|
450
|
+
const file = findFile(files, path12);
|
|
451
|
+
const found = findNewLine(files, path12, line);
|
|
452
452
|
if (!file || !found) return null;
|
|
453
453
|
return { newPath: file.path, newLine: line, oldPath: file.oldPath, oldLine: found.kind === " " ? found.oldLine : null };
|
|
454
454
|
}
|
|
@@ -465,7 +465,7 @@ var init_diff = __esm({
|
|
|
465
465
|
// src/providers/util.ts
|
|
466
466
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
467
467
|
import { tmpdir } from "node:os";
|
|
468
|
-
import
|
|
468
|
+
import path7 from "node:path";
|
|
469
469
|
function parseJson(stdout, source) {
|
|
470
470
|
const text2 = stdout.trim();
|
|
471
471
|
if (!text2) throw new ProviderError(tr(`${source}: \u043F\u0443\u0441\u0442\u043E\u0439 \u043E\u0442\u0432\u0435\u0442`, `${source}: empty response`));
|
|
@@ -496,8 +496,8 @@ function cliError(error, platform, host) {
|
|
|
496
496
|
throw new ProviderError(`${platform}: ${message || tr("\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0430\u0441\u044C \u0441 \u043E\u0448\u0438\u0431\u043A\u043E\u0439", "the command failed")}`);
|
|
497
497
|
}
|
|
498
498
|
async function withTempJson(data, fn) {
|
|
499
|
-
const dir = await mkdtemp(
|
|
500
|
-
const file =
|
|
499
|
+
const dir = await mkdtemp(path7.join(tmpdir(), "revdeck-"));
|
|
500
|
+
const file = path7.join(dir, "payload.json");
|
|
501
501
|
try {
|
|
502
502
|
await writeFile(file, JSON.stringify(data), { mode: 384, flag: "wx" });
|
|
503
503
|
return await fn(file);
|
|
@@ -505,8 +505,8 @@ async function withTempJson(data, fn) {
|
|
|
505
505
|
await rm(dir, { recursive: true, force: true });
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
|
-
function query(
|
|
509
|
-
const url = new URL(
|
|
508
|
+
function query(path12, params) {
|
|
509
|
+
const url = new URL(path12.startsWith("/") ? path12 : `/${path12}`, "http://local");
|
|
510
510
|
for (const [key, value] of Object.entries(params)) {
|
|
511
511
|
if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
512
512
|
}
|
|
@@ -1158,16 +1158,16 @@ rename to ${newPath}
|
|
|
1158
1158
|
});
|
|
1159
1159
|
|
|
1160
1160
|
// src/daemon/main.ts
|
|
1161
|
-
import { existsSync as
|
|
1161
|
+
import { existsSync as existsSync5, readFileSync } from "node:fs";
|
|
1162
1162
|
import { appendFile, open as open2, readFile as readFile3, unlink as unlink4 } from "node:fs/promises";
|
|
1163
1163
|
import net2 from "node:net";
|
|
1164
|
-
import
|
|
1164
|
+
import path11 from "node:path";
|
|
1165
1165
|
import { fileURLToPath } from "node:url";
|
|
1166
1166
|
import { parseArgs } from "node:util";
|
|
1167
1167
|
|
|
1168
1168
|
// src/core/paths.ts
|
|
1169
1169
|
import { constants, existsSync } from "node:fs";
|
|
1170
|
-
import { lstat, mkdir, open, realpath, rename, unlink } from "node:fs/promises";
|
|
1170
|
+
import { lstat, mkdir, open, realpath, rename, stat, unlink } from "node:fs/promises";
|
|
1171
1171
|
import path from "node:path";
|
|
1172
1172
|
import os from "node:os";
|
|
1173
1173
|
function findRepoRoot(start = process.cwd()) {
|
|
@@ -1259,30 +1259,40 @@ async function readTextNoFollow(file, maxBytes = 4 * 1024 * 1024) {
|
|
|
1259
1259
|
await handle.close();
|
|
1260
1260
|
}
|
|
1261
1261
|
}
|
|
1262
|
-
async function
|
|
1262
|
+
async function openInsideRoot(root, target) {
|
|
1263
|
+
const resolvedTarget = path.resolve(target);
|
|
1263
1264
|
const realRoot = await realpath(path.resolve(root));
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1265
|
+
let handle;
|
|
1266
|
+
try {
|
|
1267
|
+
handle = await open(resolvedTarget, process.platform === "win32" ? "r" : constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
1268
|
+
} catch (error) {
|
|
1269
|
+
if (error.code === "ELOOP") {
|
|
1270
|
+
throw new Error(`${path.basename(target)}: path escapes the repository`);
|
|
1271
|
+
}
|
|
1272
|
+
throw error;
|
|
1267
1273
|
}
|
|
1268
|
-
return realTarget;
|
|
1269
|
-
}
|
|
1270
|
-
async function readTextPrefixNoFollow(file, maxBytes = 4 * 1024 * 1024) {
|
|
1271
|
-
const info = await lstat(file);
|
|
1272
|
-
if (info.isSymbolicLink()) throw new Error(`${path.basename(file)}: symbolic link, read refused`);
|
|
1273
|
-
if (!info.isFile()) throw new Error(`${path.basename(file)}: not a regular file`);
|
|
1274
|
-
const limit = Math.max(1, Math.min(Math.floor(maxBytes), 16 * 1024 * 1024));
|
|
1275
|
-
const flags = process.platform === "win32" ? "r" : constants.O_RDONLY | constants.O_NOFOLLOW;
|
|
1276
|
-
const handle = await open(file, flags);
|
|
1277
1274
|
try {
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1275
|
+
const info = await handle.stat();
|
|
1276
|
+
if (!info.isFile()) throw new Error(`${path.basename(target)}: not a regular file`);
|
|
1277
|
+
if (process.platform === "linux") {
|
|
1278
|
+
const actual = await realpath(`/proc/self/fd/${handle.fd}`);
|
|
1279
|
+
if (!isInside(realRoot, actual)) {
|
|
1280
|
+
throw new Error(`${path.basename(target)}: path escapes the repository`);
|
|
1281
|
+
}
|
|
1282
|
+
} else {
|
|
1283
|
+
const actual = await realpath(resolvedTarget);
|
|
1284
|
+
if (!isInside(realRoot, actual)) {
|
|
1285
|
+
throw new Error(`${path.basename(target)}: path escapes the repository`);
|
|
1286
|
+
}
|
|
1287
|
+
const onDisk = await stat(actual);
|
|
1288
|
+
if (onDisk.dev !== info.dev || onDisk.ino !== info.ino) {
|
|
1289
|
+
throw new Error(`${path.basename(target)}: path changed during read`);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return handle;
|
|
1293
|
+
} catch (error) {
|
|
1285
1294
|
await handle.close();
|
|
1295
|
+
throw error;
|
|
1286
1296
|
}
|
|
1287
1297
|
}
|
|
1288
1298
|
async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
|
|
@@ -1308,8 +1318,8 @@ async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
|
|
|
1308
1318
|
init_redact();
|
|
1309
1319
|
|
|
1310
1320
|
// src/version.ts
|
|
1311
|
-
var VERSION = "0.
|
|
1312
|
-
var PROTOCOL_VERSION =
|
|
1321
|
+
var VERSION = "0.8.0";
|
|
1322
|
+
var PROTOCOL_VERSION = 2;
|
|
1313
1323
|
|
|
1314
1324
|
// src/daemon/main.ts
|
|
1315
1325
|
init_locale();
|
|
@@ -1730,6 +1740,34 @@ var Store = class {
|
|
|
1730
1740
|
getProject(key) {
|
|
1731
1741
|
return this.listProjects().find((project) => project.key === key) ?? null;
|
|
1732
1742
|
}
|
|
1743
|
+
/** Переименование проекта и явное управление root'ами рабочих копий. */
|
|
1744
|
+
updateProject(key, patch, now = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1745
|
+
const current2 = this.getProject(key);
|
|
1746
|
+
if (!current2) return null;
|
|
1747
|
+
const title = (patch.title ?? current2.title).trim();
|
|
1748
|
+
if (!title) throw new Error(tr("\u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u043F\u0443\u0441\u0442\u044B\u043C", "project title cannot be empty"));
|
|
1749
|
+
const roots = patch.roots === void 0 ? null : [...new Set(patch.roots.map((root) => root.trim()).filter(Boolean))];
|
|
1750
|
+
this.transaction(() => {
|
|
1751
|
+
this.db.prepare("UPDATE projects SET title = ?, updated_at = ? WHERE key = ?").run(title.slice(0, 120), now, key);
|
|
1752
|
+
if (roots !== null) {
|
|
1753
|
+
this.db.prepare("DELETE FROM project_roots WHERE project_key = ?").run(key);
|
|
1754
|
+
const insert = this.db.prepare("INSERT INTO project_roots (project_key, root, last_seen_at) VALUES (?, ?, ?)");
|
|
1755
|
+
for (const root of roots) insert.run(key, root, now);
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
return this.getProject(key);
|
|
1759
|
+
}
|
|
1760
|
+
/** Удаляет проект вместе с его локальными ревью; платформа не затрагивается. */
|
|
1761
|
+
removeProject(key) {
|
|
1762
|
+
const countRow = this.db.prepare("SELECT COUNT(*) AS count FROM reviews WHERE project_key = ?").get(key);
|
|
1763
|
+
const reviews = Number(countRow?.count ?? 0);
|
|
1764
|
+
this.transaction(() => {
|
|
1765
|
+
this.db.prepare("DELETE FROM approvals WHERE review_id IN (SELECT id FROM reviews WHERE project_key = ?)").run(key);
|
|
1766
|
+
this.db.prepare("DELETE FROM reviews WHERE project_key = ?").run(key);
|
|
1767
|
+
this.db.prepare("DELETE FROM projects WHERE key = ?").run(key);
|
|
1768
|
+
});
|
|
1769
|
+
return reviews;
|
|
1770
|
+
}
|
|
1733
1771
|
// ---------------------------------------------------------------- features
|
|
1734
1772
|
featureMembers(id) {
|
|
1735
1773
|
const rows = this.db.prepare(
|
|
@@ -2291,14 +2329,14 @@ import { EventEmitter } from "node:events";
|
|
|
2291
2329
|
import { createHash as createHash2, randomBytes as randomBytes2 } from "node:crypto";
|
|
2292
2330
|
import { mkdtemp as mkdtemp2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
2293
2331
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
2294
|
-
import
|
|
2332
|
+
import path8 from "node:path";
|
|
2295
2333
|
|
|
2296
2334
|
// src/core/config.ts
|
|
2297
2335
|
import { z } from "zod";
|
|
2298
2336
|
init_errors();
|
|
2299
2337
|
import { parse as parseYaml } from "yaml";
|
|
2300
2338
|
import { existsSync as existsSync2 } from "node:fs";
|
|
2301
|
-
import
|
|
2339
|
+
import path4 from "node:path";
|
|
2302
2340
|
|
|
2303
2341
|
// src/core/glob.ts
|
|
2304
2342
|
function globToRegExp(glob) {
|
|
@@ -2344,8 +2382,8 @@ function globToRegExp(glob) {
|
|
|
2344
2382
|
function escapeRegExp(value) {
|
|
2345
2383
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2346
2384
|
}
|
|
2347
|
-
function classifyFile(
|
|
2348
|
-
const lower =
|
|
2385
|
+
function classifyFile(path12) {
|
|
2386
|
+
const lower = path12.toLowerCase();
|
|
2349
2387
|
if (/(^|\/)(node_modules|dist|build|coverage|vendor)\//.test(lower)) return "generated";
|
|
2350
2388
|
if (/\.(md|mdx|rst|txt|adoc)$/.test(lower) || /(^|\/)(docs?|adr)\//.test(lower)) return "docs";
|
|
2351
2389
|
if (/(^|\/)(__tests__|tests?|spec|e2e)\//.test(lower) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(lower) || /_test\.go$/.test(lower)) return "test";
|
|
@@ -2490,6 +2528,19 @@ function roleCriteriaText(role) {
|
|
|
2490
2528
|
return role.criteria.length ? `\xA7${role.criteria.join(", \xA7")}` : "";
|
|
2491
2529
|
}
|
|
2492
2530
|
|
|
2531
|
+
// src/core/git-files.ts
|
|
2532
|
+
init_exec();
|
|
2533
|
+
async function gitTrackState(root, relative) {
|
|
2534
|
+
try {
|
|
2535
|
+
const { stdout } = await run("git", ["-C", root, "ls-files", "--error-unmatch", "--", relative], {
|
|
2536
|
+
timeoutMs: 1e4
|
|
2537
|
+
});
|
|
2538
|
+
return stdout.trim() ? "tracked" : "unknown";
|
|
2539
|
+
} catch (error) {
|
|
2540
|
+
return error.code === 1 ? "untracked" : "unknown";
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2493
2544
|
// src/core/config.ts
|
|
2494
2545
|
var matchSchema = z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]);
|
|
2495
2546
|
var customRoleSchema = z.object({
|
|
@@ -2627,10 +2678,30 @@ function mergeConfigData(base, local) {
|
|
|
2627
2678
|
}
|
|
2628
2679
|
async function loadConfig(root = findRepoRoot()) {
|
|
2629
2680
|
const warnings = [];
|
|
2681
|
+
if (!existsSync2(root)) {
|
|
2682
|
+
warnings.push(
|
|
2683
|
+
tr(
|
|
2684
|
+
`\u043A\u0430\u0442\u0430\u043B\u043E\u0433 ${root} \u043D\u0435 \u0432\u0438\u0434\u0435\u043D \u0442\u043E\u043C\u0443, \u043A\u0442\u043E \u0447\u0438\u0442\u0430\u0435\u0442 \u043A\u043E\u043D\u0444\u0438\u0433: \u0432 devcontainer \u0434\u0435\u043C\u043E\u043D \u043D\u0430 \u0445\u043E\u0441\u0442\u0435 \u043D\u0435 \u0432\u0438\u0434\u0438\u0442 \u043F\u0443\u0442\u044C \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u0430 \u2014 \u0432\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u0435 revdeck devcontainer --write \u0438\u043B\u0438 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 REVDECK_HOST_ROOT`,
|
|
2685
|
+
`the directory ${root} is not visible to the config reader: in a devcontainer the host daemon cannot see the container path \u2014 run revdeck devcontainer --write or set REVDECK_HOST_ROOT`
|
|
2686
|
+
)
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2630
2689
|
const file = findConfigFile(root);
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2690
|
+
let localFile = findLocalConfigFile(root);
|
|
2691
|
+
if (localFile && existsSync2(path4.join(root, ".git"))) {
|
|
2692
|
+
const state = await gitTrackState(root, path4.relative(root, localFile));
|
|
2693
|
+
if (state !== "untracked") {
|
|
2694
|
+
warnings.push(
|
|
2695
|
+
tr(
|
|
2696
|
+
".revdeck.local.yml \u043E\u0442\u0441\u043B\u0435\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F git: \u0444\u0430\u0439\u043B \u0438\u0437 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F \u0438\u0433\u043D\u043E\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u043A\u0430\u043A \u043B\u0438\u0447\u043D\u044B\u0439",
|
|
2697
|
+
".revdeck.local.yml is tracked by git: a repository file is ignored as personal overrides"
|
|
2698
|
+
)
|
|
2699
|
+
);
|
|
2700
|
+
localFile = null;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
const baseData = file ? parseYamlData(await readTextNoFollow(file), path4.relative(root, file) || file) : {};
|
|
2704
|
+
const localData = localFile ? parseYamlData(await readTextNoFollow(localFile), path4.relative(root, localFile) || localFile) : {};
|
|
2634
2705
|
if (!file && !localFile) {
|
|
2635
2706
|
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"));
|
|
2636
2707
|
}
|
|
@@ -2640,7 +2711,7 @@ async function loadConfig(root = findRepoRoot()) {
|
|
|
2640
2711
|
const localReadOnly = isRecord(localData) && isRecord(localData.review) && localData.review.readOnly === true;
|
|
2641
2712
|
config.review.readOnly = baseReadOnly || localReadOnly;
|
|
2642
2713
|
if (!config.rules.sources.length && !config.rules.map.length) {
|
|
2643
|
-
const found = DISCOVERED_SOURCES.filter((item) => existsSync2(
|
|
2714
|
+
const found = DISCOVERED_SOURCES.filter((item) => existsSync2(path4.join(root, item)));
|
|
2644
2715
|
config.rules.sources = found;
|
|
2645
2716
|
if (!found.length) {
|
|
2646
2717
|
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"));
|
|
@@ -2655,22 +2726,38 @@ async function loadConfig(root = findRepoRoot()) {
|
|
|
2655
2726
|
}
|
|
2656
2727
|
function assertConfigPath(root, relative) {
|
|
2657
2728
|
const cleaned = relative.split("#")[0];
|
|
2658
|
-
const resolved =
|
|
2659
|
-
const rel =
|
|
2660
|
-
if (rel.startsWith("..") ||
|
|
2729
|
+
const resolved = path4.resolve(root, cleaned);
|
|
2730
|
+
const rel = path4.relative(root, resolved);
|
|
2731
|
+
if (rel.startsWith("..") || path4.isAbsolute(rel)) {
|
|
2661
2732
|
throw new ConfigError(tr(`\u043F\u0443\u0442\u044C ${relative} \u0432\u044B\u0445\u043E\u0434\u0438\u0442 \u0437\u0430 \u043F\u0440\u0435\u0434\u0435\u043B\u044B \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F`, `path ${relative} escapes the repository`));
|
|
2662
2733
|
}
|
|
2663
2734
|
return resolved;
|
|
2664
2735
|
}
|
|
2665
2736
|
async function readConfigFile(root, relative, maxBytes = 4 * 1024 * 1024) {
|
|
2666
|
-
const
|
|
2667
|
-
|
|
2668
|
-
|
|
2737
|
+
const handle = await openInsideRoot(root, assertConfigPath(root, relative));
|
|
2738
|
+
try {
|
|
2739
|
+
const info = await handle.stat();
|
|
2740
|
+
if (info.size > maxBytes) {
|
|
2741
|
+
throw new Error(`${path4.basename(relative)}: file is larger than ${Math.round(maxBytes / 1024)} KB`);
|
|
2742
|
+
}
|
|
2743
|
+
return await handle.readFile({ encoding: "utf8" });
|
|
2744
|
+
} finally {
|
|
2745
|
+
await handle.close();
|
|
2746
|
+
}
|
|
2669
2747
|
}
|
|
2670
2748
|
async function readConfigPrefix(root, relative, maxBytes = 4 * 1024 * 1024) {
|
|
2671
|
-
const
|
|
2672
|
-
|
|
2673
|
-
|
|
2749
|
+
const handle = await openInsideRoot(root, assertConfigPath(root, relative));
|
|
2750
|
+
try {
|
|
2751
|
+
const limit = Math.max(1, Math.min(Math.floor(maxBytes), 16 * 1024 * 1024));
|
|
2752
|
+
const buffer = Buffer.allocUnsafe(limit + 1);
|
|
2753
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
2754
|
+
return {
|
|
2755
|
+
text: buffer.subarray(0, Math.min(bytesRead, limit)).toString("utf8"),
|
|
2756
|
+
truncated: bytesRead > limit
|
|
2757
|
+
};
|
|
2758
|
+
} finally {
|
|
2759
|
+
await handle.close();
|
|
2760
|
+
}
|
|
2674
2761
|
}
|
|
2675
2762
|
function checksForPaths(config, paths) {
|
|
2676
2763
|
return config.checks.map((check) => {
|
|
@@ -2679,6 +2766,37 @@ function checksForPaths(config, paths) {
|
|
|
2679
2766
|
});
|
|
2680
2767
|
}
|
|
2681
2768
|
|
|
2769
|
+
// src/core/doc-policy.ts
|
|
2770
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
2771
|
+
import path5 from "node:path";
|
|
2772
|
+
init_errors();
|
|
2773
|
+
init_locale();
|
|
2774
|
+
var DOC_EXTENSION = /\.(md|mdx|rst|txt|adoc)$/i;
|
|
2775
|
+
var PROFILE_EXTENSION = /\.(md|mdx|rst|txt|adoc|ya?ml|json)$/i;
|
|
2776
|
+
var SECRET_PATH = /(^|\/)(\.env(\..*)?|\.npmrc|\.git(\/.*)?|\.revdeck\.local\.(ya?ml)|id_(rsa|ed25519|ecdsa)(\.pub)?|.*\.(pem|key|p12|pfx|jks|keystore|tfvars|tfstate))$/i;
|
|
2777
|
+
async function assertSafeDocument(root, relative, kind = "rules") {
|
|
2778
|
+
const clean = relative.split("#")[0];
|
|
2779
|
+
const resolved = assertConfigPath(root, clean);
|
|
2780
|
+
if (SECRET_PATH.test(clean)) {
|
|
2781
|
+
throw new ConfigError(tr(`${relative}: \u0441\u0435\u043A\u0440\u0435\u0442\u043D\u044B\u0439 \u0444\u0430\u0439\u043B \u043D\u0435\u043B\u044C\u0437\u044F \u0447\u0438\u0442\u0430\u0442\u044C \u043A\u0430\u043A \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442`, `${relative}: secret files cannot be read as documents`));
|
|
2782
|
+
}
|
|
2783
|
+
if (!(kind === "profile" ? PROFILE_EXTENSION : DOC_EXTENSION).test(clean)) {
|
|
2784
|
+
throw new ConfigError(tr(`${relative}: \u043D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0439 \u0442\u0438\u043F \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430`, `${relative}: unsupported document type`));
|
|
2785
|
+
}
|
|
2786
|
+
if (existsSync3(path5.join(root, ".git"))) {
|
|
2787
|
+
const state = await gitTrackState(root, clean);
|
|
2788
|
+
if (state !== "tracked") {
|
|
2789
|
+
throw new ConfigError(
|
|
2790
|
+
tr(
|
|
2791
|
+
`${relative}: \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442 \u043D\u0435 \u043E\u0442\u0441\u043B\u0435\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F git (\u0438\u043B\u0438 git \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D)`,
|
|
2792
|
+
`${relative}: document is not tracked by git (or git is unavailable)`
|
|
2793
|
+
)
|
|
2794
|
+
);
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
return resolved;
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2682
2800
|
// src/core/git.ts
|
|
2683
2801
|
init_exec();
|
|
2684
2802
|
var SSH_SCP = /^(?:ssh:\/\/)?(?:[^@/]+@)?([^:/]+)(?::(\d+))?[:/](.+?)(?:\.git)?\/?$/;
|
|
@@ -2725,8 +2843,8 @@ async function currentBranch(root) {
|
|
|
2725
2843
|
}
|
|
2726
2844
|
|
|
2727
2845
|
// src/core/rules.ts
|
|
2728
|
-
import
|
|
2729
|
-
import { existsSync as
|
|
2846
|
+
import path6 from "node:path";
|
|
2847
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
2730
2848
|
init_redact();
|
|
2731
2849
|
var MAX_READ_BYTES = 16 * 1024 * 1024;
|
|
2732
2850
|
async function buildEffectiveRules(options) {
|
|
@@ -2746,14 +2864,14 @@ async function buildEffectiveRules(options) {
|
|
|
2746
2864
|
const relative = rawPath;
|
|
2747
2865
|
let resolved;
|
|
2748
2866
|
try {
|
|
2749
|
-
resolved =
|
|
2867
|
+
resolved = await assertSafeDocument(root, relative, "rules");
|
|
2750
2868
|
} catch (error) {
|
|
2751
|
-
warnings.push(
|
|
2869
|
+
warnings.push(error.message);
|
|
2752
2870
|
return { path: relative, exists: false, sections: [], excerpt: "", truncated: false };
|
|
2753
2871
|
}
|
|
2754
2872
|
let cached = cache.get(resolved);
|
|
2755
2873
|
if (!cached) {
|
|
2756
|
-
if (!
|
|
2874
|
+
if (!existsSync4(resolved)) {
|
|
2757
2875
|
cached = { exists: false, text: "", truncated: false };
|
|
2758
2876
|
warnings.push(`${t("\u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442", "document")} ${relative} ${t("\u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D", "not found")}`);
|
|
2759
2877
|
} else {
|
|
@@ -2806,7 +2924,7 @@ async function buildEffectiveRules(options) {
|
|
|
2806
2924
|
scopes.push({ file: "", kind: "other", documents });
|
|
2807
2925
|
}
|
|
2808
2926
|
return {
|
|
2809
|
-
configPath: configPath ?
|
|
2927
|
+
configPath: configPath ? path6.relative(root, configPath) : null,
|
|
2810
2928
|
scopes,
|
|
2811
2929
|
checks: checksForPaths(config, files),
|
|
2812
2930
|
warnings: [...new Set(warnings)]
|
|
@@ -2927,8 +3045,8 @@ var CLASS_LABEL = {
|
|
|
2927
3045
|
};
|
|
2928
3046
|
function computeGroups(diff, custom = []) {
|
|
2929
3047
|
const groups = /* @__PURE__ */ new Map();
|
|
2930
|
-
const add = (group,
|
|
2931
|
-
group.files.push(
|
|
3048
|
+
const add = (group, path12, additions, deletions) => {
|
|
3049
|
+
group.files.push(path12);
|
|
2932
3050
|
group.additions += additions;
|
|
2933
3051
|
group.deletions += deletions;
|
|
2934
3052
|
groups.set(group.id, group);
|
|
@@ -2989,23 +3107,23 @@ function maskSecret(value) {
|
|
|
2989
3107
|
if (trimmed.length <= 8) return "***";
|
|
2990
3108
|
return `${trimmed.slice(0, 4)}\u2026${trimmed.slice(-2)}`;
|
|
2991
3109
|
}
|
|
2992
|
-
function isAllowlisted(
|
|
3110
|
+
function isAllowlisted(path12, rule, allowlist) {
|
|
2993
3111
|
return allowlist.some((entry) => {
|
|
2994
3112
|
const normalized = entry.trim();
|
|
2995
3113
|
if (!normalized) return false;
|
|
2996
3114
|
if (normalized === rule || normalized === `rule:${rule}`) return true;
|
|
2997
3115
|
if (normalized.startsWith("rule:")) return false;
|
|
2998
|
-
return globToRegExp(normalized).test(
|
|
3116
|
+
return globToRegExp(normalized).test(path12);
|
|
2999
3117
|
});
|
|
3000
3118
|
}
|
|
3001
|
-
function scanLines(
|
|
3002
|
-
if (!options.includeTests && classifyFile(
|
|
3119
|
+
function scanLines(path12, lines, options = {}) {
|
|
3120
|
+
if (!options.includeTests && classifyFile(path12) === "test") return [];
|
|
3003
3121
|
const allowlist = options.allowlist ?? [];
|
|
3004
3122
|
const findings = [];
|
|
3005
3123
|
for (const line of lines) {
|
|
3006
3124
|
let specific = false;
|
|
3007
3125
|
for (const pattern of PATTERNS) {
|
|
3008
|
-
if (isAllowlisted(
|
|
3126
|
+
if (isAllowlisted(path12, pattern.id, allowlist)) continue;
|
|
3009
3127
|
if (pattern.id === "generic-secret" && specific) continue;
|
|
3010
3128
|
pattern.regex.lastIndex = 0;
|
|
3011
3129
|
const match = pattern.regex.exec(line.text);
|
|
@@ -3014,7 +3132,7 @@ function scanLines(path11, lines, options = {}) {
|
|
|
3014
3132
|
findings.push({
|
|
3015
3133
|
rule: pattern.id,
|
|
3016
3134
|
title: pattern.title,
|
|
3017
|
-
file:
|
|
3135
|
+
file: path12,
|
|
3018
3136
|
line: line.number,
|
|
3019
3137
|
preview: maskSecret(match[0])
|
|
3020
3138
|
});
|
|
@@ -3668,7 +3786,7 @@ function parseOpenApi(text2) {
|
|
|
3668
3786
|
const info = isRecord2(document.info) ? document.info : {};
|
|
3669
3787
|
const paths = isRecord2(document.paths) ? document.paths : {};
|
|
3670
3788
|
const operations = [];
|
|
3671
|
-
for (const [
|
|
3789
|
+
for (const [path12, value] of Object.entries(paths)) {
|
|
3672
3790
|
if (!isRecord2(value)) continue;
|
|
3673
3791
|
for (const method of METHODS) {
|
|
3674
3792
|
const operation = value[method];
|
|
@@ -3679,7 +3797,7 @@ function parseOpenApi(text2) {
|
|
|
3679
3797
|
const media = isRecord2(firstMedia) ? firstMedia : {};
|
|
3680
3798
|
operations.push({
|
|
3681
3799
|
method: method.toUpperCase(),
|
|
3682
|
-
path:
|
|
3800
|
+
path: path12,
|
|
3683
3801
|
operationId: String(operation.operationId ?? ""),
|
|
3684
3802
|
summary: String(operation.summary ?? ""),
|
|
3685
3803
|
parameters: parametersOf(operation, document),
|
|
@@ -3731,9 +3849,9 @@ function renderOpenApiSummary(summary) {
|
|
|
3731
3849
|
}
|
|
3732
3850
|
return lines.join("\n");
|
|
3733
3851
|
}
|
|
3734
|
-
function openApiPathRegExp(
|
|
3735
|
-
if (
|
|
3736
|
-
const escaped =
|
|
3852
|
+
function openApiPathRegExp(path12) {
|
|
3853
|
+
if (path12 === "/") return /(?!)/;
|
|
3854
|
+
const escaped = path12.replace(/\{[^}]+\}/g, "\0").replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\u0000/g, "[^/?#\\s]+");
|
|
3737
3855
|
return new RegExp(`(?<![\\w-])${escaped}(?![\\w-])`);
|
|
3738
3856
|
}
|
|
3739
3857
|
|
|
@@ -4046,8 +4164,30 @@ var ReviewService = class {
|
|
|
4046
4164
|
const loaded = await loadConfig(root);
|
|
4047
4165
|
const context = await projectContext(root, loaded.config);
|
|
4048
4166
|
const key = this.store.registerProject(context, root, this.now().toISOString());
|
|
4167
|
+
this.store.audit(null, "project.register", { key, root });
|
|
4168
|
+
this.events.emit("project", { key, at: this.now().toISOString() });
|
|
4049
4169
|
return this.store.getProject(key);
|
|
4050
4170
|
}
|
|
4171
|
+
updateProject(keyInput, patch) {
|
|
4172
|
+
const key = keyInput.trim();
|
|
4173
|
+
if (!this.store.getProject(key)) throw new Error(tr(`\u043F\u0440\u043E\u0435\u043A\u0442 ${key} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D`, `project ${key} not found`));
|
|
4174
|
+
const project = this.store.updateProject(key, patch, this.now().toISOString());
|
|
4175
|
+
this.store.audit(null, "project.update", {
|
|
4176
|
+
key,
|
|
4177
|
+
...patch.title === void 0 ? {} : { title: patch.title },
|
|
4178
|
+
...patch.roots === void 0 ? {} : { roots: patch.roots.length }
|
|
4179
|
+
});
|
|
4180
|
+
this.events.emit("project", { key, at: this.now().toISOString() });
|
|
4181
|
+
return project;
|
|
4182
|
+
}
|
|
4183
|
+
removeProject(keyInput) {
|
|
4184
|
+
const key = keyInput.trim();
|
|
4185
|
+
if (!this.store.getProject(key)) throw new Error(tr(`\u043F\u0440\u043E\u0435\u043A\u0442 ${key} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D`, `project ${key} not found`));
|
|
4186
|
+
const reviews = this.store.removeProject(key);
|
|
4187
|
+
this.store.audit(null, "project.remove", { key, reviews });
|
|
4188
|
+
this.events.emit("project", { key, at: this.now().toISOString() });
|
|
4189
|
+
return reviews;
|
|
4190
|
+
}
|
|
4051
4191
|
async projectForRoot(rootInput) {
|
|
4052
4192
|
const root = findRepoRoot(rootInput);
|
|
4053
4193
|
const loaded = await loadConfig(root);
|
|
@@ -4222,6 +4362,7 @@ ${t("\u2026 \u043A\u043E\u043D\u0442\u0440\u0430\u043A\u0442 \u043E\u0431\u0440\
|
|
|
4222
4362
|
break;
|
|
4223
4363
|
}
|
|
4224
4364
|
try {
|
|
4365
|
+
await assertSafeDocument(member.review.root, source, "profile");
|
|
4225
4366
|
const content = await readConfigPrefix(member.review.root, source, remaining);
|
|
4226
4367
|
const profileText = content.text.trim().slice(0, remaining);
|
|
4227
4368
|
remaining -= profileText.length;
|
|
@@ -4531,8 +4672,8 @@ ${errors.join("\n")}`));
|
|
|
4531
4672
|
if (!matchesSignature(buffer, spec.contentType)) {
|
|
4532
4673
|
throw new Error(tr("\u0432\u043B\u043E\u0436\u0435\u043D\u0438\u0435: \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0435 \u043D\u0435 \u0441\u043E\u0432\u043F\u0430\u0434\u0430\u0435\u0442 \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043D\u0438\u0435\u043C", "attachment: content does not match the extension"));
|
|
4533
4674
|
}
|
|
4534
|
-
const dir = await mkdtemp2(
|
|
4535
|
-
const file =
|
|
4675
|
+
const dir = await mkdtemp2(path8.join(tmpdir4(), "revdeck-attachment-"));
|
|
4676
|
+
const file = path8.join(dir, spec.name);
|
|
4536
4677
|
try {
|
|
4537
4678
|
await writeFile2(file, buffer, { mode: 384, flag: "wx" });
|
|
4538
4679
|
const uploaded = await provider.upload({ path: file, name: spec.name, contentType: spec.contentType });
|
|
@@ -5082,8 +5223,8 @@ init_redact();
|
|
|
5082
5223
|
init_errors();
|
|
5083
5224
|
import http from "node:http";
|
|
5084
5225
|
import { createReadStream } from "node:fs";
|
|
5085
|
-
import { readFile as readFile2, stat } from "node:fs/promises";
|
|
5086
|
-
import
|
|
5226
|
+
import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
|
|
5227
|
+
import path9 from "node:path";
|
|
5087
5228
|
import { timingSafeEqual } from "node:crypto";
|
|
5088
5229
|
|
|
5089
5230
|
// src/daemon/rpc.ts
|
|
@@ -5092,6 +5233,50 @@ import { chmod, unlink as unlink2 } from "node:fs/promises";
|
|
|
5092
5233
|
init_redact();
|
|
5093
5234
|
init_errors();
|
|
5094
5235
|
init_exec();
|
|
5236
|
+
|
|
5237
|
+
// src/daemon/capabilities.ts
|
|
5238
|
+
var AGENT_METHODS = /* @__PURE__ */ new Set([
|
|
5239
|
+
"ping",
|
|
5240
|
+
"projects.list",
|
|
5241
|
+
"reviews.list",
|
|
5242
|
+
"reviews.get",
|
|
5243
|
+
"reviews.open",
|
|
5244
|
+
"reviews.refresh",
|
|
5245
|
+
"reviews.remoteList",
|
|
5246
|
+
"versions.list",
|
|
5247
|
+
"versions.get",
|
|
5248
|
+
"secrets.get",
|
|
5249
|
+
"analytics.get",
|
|
5250
|
+
"diff.get",
|
|
5251
|
+
"rules.get",
|
|
5252
|
+
"features.list",
|
|
5253
|
+
"features.get",
|
|
5254
|
+
"features.context",
|
|
5255
|
+
"features.forReview",
|
|
5256
|
+
"features.addNote",
|
|
5257
|
+
"features.updateNote",
|
|
5258
|
+
"features.deleteNote",
|
|
5259
|
+
"drafts.put",
|
|
5260
|
+
"findings.put",
|
|
5261
|
+
"findings.list",
|
|
5262
|
+
"summary.put",
|
|
5263
|
+
"notes.add",
|
|
5264
|
+
"notes.update",
|
|
5265
|
+
"notes.delete",
|
|
5266
|
+
"publish.preview"
|
|
5267
|
+
]);
|
|
5268
|
+
var AGENT_POLICY = {
|
|
5269
|
+
name: "agent",
|
|
5270
|
+
capabilities: /* @__PURE__ */ new Set(["read", "draft"]),
|
|
5271
|
+
allows: (method) => AGENT_METHODS.has(method)
|
|
5272
|
+
};
|
|
5273
|
+
var HUMAN_POLICY = {
|
|
5274
|
+
name: "human",
|
|
5275
|
+
capabilities: /* @__PURE__ */ new Set(["read", "draft", "publish", "checks", "admin"]),
|
|
5276
|
+
allows: () => true
|
|
5277
|
+
};
|
|
5278
|
+
|
|
5279
|
+
// src/daemon/rpc.ts
|
|
5095
5280
|
var MAX_LINE = 40 * 1024 * 1024;
|
|
5096
5281
|
function featureReviewInput(value) {
|
|
5097
5282
|
if (typeof value === "string") return { review: value };
|
|
@@ -5101,11 +5286,36 @@ function featureReviewInput(value) {
|
|
|
5101
5286
|
...typeof item.role === "string" ? { role: item.role } : {}
|
|
5102
5287
|
};
|
|
5103
5288
|
}
|
|
5104
|
-
|
|
5289
|
+
function assertAgentFeatureNote(service, featureId, noteId, policy) {
|
|
5290
|
+
if (policy.name !== "agent") return;
|
|
5291
|
+
const note = service.getFeature(featureId).notes.find((item) => item.id === noteId);
|
|
5292
|
+
if (!note || note.author !== "agent") {
|
|
5293
|
+
throw new MrReviewError(
|
|
5294
|
+
"\u0430\u0433\u0435\u043D\u0442 \u043C\u043E\u0436\u0435\u0442 \u0438\u0437\u043C\u0435\u043D\u044F\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0441\u0432\u043E\u0438 feature-\u0437\u0430\u043C\u0435\u0442\u043A\u0438",
|
|
5295
|
+
"CAPABILITY",
|
|
5296
|
+
"\u0437\u0430\u043C\u0435\u0442\u043A\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0440\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u0443\u0435\u0442 \u0438 \u0443\u0434\u0430\u043B\u044F\u0435\u0442 \u0447\u0435\u043B\u043E\u0432\u0435\u043A \u0432 UI/CLI"
|
|
5297
|
+
);
|
|
5298
|
+
}
|
|
5299
|
+
}
|
|
5300
|
+
async function dispatch(service, method, params, policy = HUMAN_POLICY) {
|
|
5301
|
+
if (!policy.allows(method)) {
|
|
5302
|
+
throw new MrReviewError(
|
|
5303
|
+
`\u043C\u0435\u0442\u043E\u0434 ${method} \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u044D\u0442\u043E\u043C\u0443 \u043A\u043B\u0438\u0435\u043D\u0442\u0443`,
|
|
5304
|
+
"CAPABILITY",
|
|
5305
|
+
policy.name === "agent" ? "\u043F\u0443\u0431\u043B\u0438\u043A\u0430\u0446\u0438\u044F, checks, \u0440\u0435\u0448\u0435\u043D\u0438\u044F \u0438 \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0432\u044B\u043F\u043E\u043B\u043D\u044F\u044E\u0442\u0441\u044F \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u043E\u043C \u0432 UI \u0438\u043B\u0438 CLI \u043D\u0430 \u0445\u043E\u0441\u0442\u0435" : void 0
|
|
5306
|
+
);
|
|
5307
|
+
}
|
|
5105
5308
|
switch (method) {
|
|
5106
5309
|
case "ping": {
|
|
5107
5310
|
const [glab, gh, git] = await Promise.all(["glab", "gh", "git"].map((name) => resolveExecutable(name)));
|
|
5108
|
-
return {
|
|
5311
|
+
return {
|
|
5312
|
+
ok: true,
|
|
5313
|
+
version: VERSION,
|
|
5314
|
+
protocol: PROTOCOL_VERSION,
|
|
5315
|
+
pid: process.pid,
|
|
5316
|
+
capabilities: [...policy.capabilities],
|
|
5317
|
+
binaries: { glab, gh, git }
|
|
5318
|
+
};
|
|
5109
5319
|
}
|
|
5110
5320
|
case "projects.list":
|
|
5111
5321
|
return { projects: service.listProjects() };
|
|
@@ -5115,6 +5325,23 @@ async function dispatch(service, method, params) {
|
|
|
5115
5325
|
const project = await service.registerProject(root);
|
|
5116
5326
|
return { project, projects: service.listProjects() };
|
|
5117
5327
|
}
|
|
5328
|
+
case "projects.update": {
|
|
5329
|
+
const project = String(params.project ?? "");
|
|
5330
|
+
if (!project) throw new MrReviewError("\u043D\u0443\u0436\u0435\u043D \u043A\u043B\u044E\u0447 \u043F\u0440\u043E\u0435\u043A\u0442\u0430");
|
|
5331
|
+
return {
|
|
5332
|
+
project: service.updateProject(project, {
|
|
5333
|
+
...typeof params.title === "string" ? { title: params.title } : {},
|
|
5334
|
+
...Array.isArray(params.roots) ? { roots: params.roots.map(String) } : {}
|
|
5335
|
+
}),
|
|
5336
|
+
projects: service.listProjects()
|
|
5337
|
+
};
|
|
5338
|
+
}
|
|
5339
|
+
case "projects.remove": {
|
|
5340
|
+
const project = String(params.project ?? "");
|
|
5341
|
+
if (!project) throw new MrReviewError("\u043D\u0443\u0436\u0435\u043D \u043A\u043B\u044E\u0447 \u043F\u0440\u043E\u0435\u043A\u0442\u0430");
|
|
5342
|
+
const removedReviews = service.removeProject(project);
|
|
5343
|
+
return { removedReviews, projects: service.listProjects() };
|
|
5344
|
+
}
|
|
5118
5345
|
case "features.list": {
|
|
5119
5346
|
const project = typeof params.project === "string" && params.project.trim() ? params.project.trim() : void 0;
|
|
5120
5347
|
return { features: service.listFeatures(project, params.includeArchived === true) };
|
|
@@ -5155,28 +5382,38 @@ async function dispatch(service, method, params) {
|
|
|
5155
5382
|
Array.isArray(params.reviews) ? params.reviews.map(String) : []
|
|
5156
5383
|
)
|
|
5157
5384
|
};
|
|
5158
|
-
case "features.addNote":
|
|
5385
|
+
case "features.addNote": {
|
|
5386
|
+
const featureId = String(params.feature ?? "");
|
|
5159
5387
|
return {
|
|
5160
|
-
note: service.addFeatureNote(
|
|
5388
|
+
note: service.addFeatureNote(featureId, {
|
|
5161
5389
|
...params.kind === "finding" || params.kind === "note" ? { kind: params.kind } : {},
|
|
5162
5390
|
...typeof params.level === "string" ? { level: params.level } : {},
|
|
5163
5391
|
title: String(params.title ?? ""),
|
|
5164
5392
|
body: String(params.body ?? ""),
|
|
5165
|
-
|
|
5393
|
+
author: policy.name === "agent" ? "agent" : params.author === "agent" || params.author === "human" ? params.author : "human"
|
|
5166
5394
|
})
|
|
5167
5395
|
};
|
|
5168
|
-
|
|
5396
|
+
}
|
|
5397
|
+
case "features.updateNote": {
|
|
5398
|
+
const featureId = String(params.feature ?? "");
|
|
5399
|
+
const noteId = String(params.note ?? "");
|
|
5400
|
+
assertAgentFeatureNote(service, featureId, noteId, policy);
|
|
5169
5401
|
return {
|
|
5170
|
-
note: service.updateFeatureNote(
|
|
5402
|
+
note: service.updateFeatureNote(featureId, noteId, {
|
|
5171
5403
|
...params.kind === "finding" || params.kind === "note" ? { kind: params.kind } : {},
|
|
5172
5404
|
...typeof params.level === "string" ? { level: params.level } : {},
|
|
5173
5405
|
...typeof params.title === "string" ? { title: params.title } : {},
|
|
5174
5406
|
...typeof params.body === "string" ? { body: params.body } : {}
|
|
5175
5407
|
})
|
|
5176
5408
|
};
|
|
5177
|
-
|
|
5178
|
-
|
|
5409
|
+
}
|
|
5410
|
+
case "features.deleteNote": {
|
|
5411
|
+
const featureId = String(params.feature ?? "");
|
|
5412
|
+
const noteId = String(params.note ?? "");
|
|
5413
|
+
assertAgentFeatureNote(service, featureId, noteId, policy);
|
|
5414
|
+
service.deleteFeatureNote(featureId, noteId);
|
|
5179
5415
|
return { ok: true };
|
|
5416
|
+
}
|
|
5180
5417
|
case "features.delete":
|
|
5181
5418
|
service.deleteFeature(String(params.feature ?? ""));
|
|
5182
5419
|
return { ok: true };
|
|
@@ -5278,8 +5515,16 @@ async function dispatch(service, method, params) {
|
|
|
5278
5515
|
toAgent: params.toAgent !== false
|
|
5279
5516
|
})
|
|
5280
5517
|
};
|
|
5281
|
-
case "notes.update":
|
|
5282
|
-
|
|
5518
|
+
case "notes.update": {
|
|
5519
|
+
const patch = { ...params.patch ?? {} };
|
|
5520
|
+
if (policy.name === "agent") {
|
|
5521
|
+
delete patch.posted;
|
|
5522
|
+
delete patch.discussionId;
|
|
5523
|
+
delete patch.noteId;
|
|
5524
|
+
delete patch.error;
|
|
5525
|
+
}
|
|
5526
|
+
return { note: service.updateNote(String(params.review ?? ""), String(params.noteId ?? ""), patch) };
|
|
5527
|
+
}
|
|
5283
5528
|
case "notes.delete":
|
|
5284
5529
|
service.deleteNote(String(params.review ?? ""), String(params.noteId ?? ""));
|
|
5285
5530
|
return { ok: true };
|
|
@@ -5336,7 +5581,7 @@ async function startRpcServer(service, socketFile, options = {}) {
|
|
|
5336
5581
|
const request = parseRequest(line);
|
|
5337
5582
|
queue = queue.then(async () => {
|
|
5338
5583
|
if (!request) return;
|
|
5339
|
-
const response = await respond(service, request);
|
|
5584
|
+
const response = await respond(service, request, options.policy ?? HUMAN_POLICY);
|
|
5340
5585
|
if (!socket.destroyed) socket.write(`${JSON.stringify(response)}
|
|
5341
5586
|
`);
|
|
5342
5587
|
});
|
|
@@ -5372,11 +5617,11 @@ function parseRequest(line) {
|
|
|
5372
5617
|
return null;
|
|
5373
5618
|
}
|
|
5374
5619
|
}
|
|
5375
|
-
async function respond(service, request) {
|
|
5620
|
+
async function respond(service, request, policy) {
|
|
5376
5621
|
const id = request.id ?? null;
|
|
5377
5622
|
if (typeof request.method !== "string") return { id, error: { message: "\u043D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D method" } };
|
|
5378
5623
|
try {
|
|
5379
|
-
const result = await dispatch(service, request.method, request.params ?? {});
|
|
5624
|
+
const result = await dispatch(service, request.method, request.params ?? {}, policy);
|
|
5380
5625
|
return { id, result };
|
|
5381
5626
|
} catch (error) {
|
|
5382
5627
|
return {
|
|
@@ -5464,9 +5709,24 @@ async function startHttpServer(options) {
|
|
|
5464
5709
|
reply(res, 403, { ok: false, error: "\u043D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0439 Origin" });
|
|
5465
5710
|
return;
|
|
5466
5711
|
}
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5712
|
+
let url;
|
|
5713
|
+
let jar;
|
|
5714
|
+
try {
|
|
5715
|
+
url = new URL(req.url ?? "/", `http://127.0.0.1:${port2}`);
|
|
5716
|
+
jar = cookies(req.headers.cookie);
|
|
5717
|
+
} catch {
|
|
5718
|
+
reply(res, 400, { ok: false, error: "\u043D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0437\u0430\u043F\u0440\u043E\u0441" });
|
|
5719
|
+
return;
|
|
5720
|
+
}
|
|
5721
|
+
const presented = String(jar[COOKIE] ?? "");
|
|
5722
|
+
const isHuman = safeEqual(presented, token);
|
|
5723
|
+
const isAgent = Boolean(options.agentToken) && safeEqual(presented, options.agentToken);
|
|
5724
|
+
const authorized = isHuman || isAgent;
|
|
5725
|
+
const isRpc = req.method === "POST" && url.pathname === "/api/rpc";
|
|
5726
|
+
if (authorized && !isHuman && !isRpc) {
|
|
5727
|
+
reply(res, 403, { ok: false, error: "\u0430\u0433\u0435\u043D\u0442\u0441\u043A\u0438\u0439 \u0442\u043E\u043A\u0435\u043D: \u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0442\u043E\u043B\u044C\u043A\u043E /api/rpc" });
|
|
5728
|
+
return;
|
|
5729
|
+
}
|
|
5470
5730
|
try {
|
|
5471
5731
|
if (req.method === "GET" && url.pathname === "/") {
|
|
5472
5732
|
const provided = url.searchParams.get("t");
|
|
@@ -5486,26 +5746,26 @@ async function startHttpServer(options) {
|
|
|
5486
5746
|
res.end('<meta charset="utf-8"><h1>\u041D\u0443\u0436\u043D\u0430 \u0441\u0441\u044B\u043B\u043A\u0430 \u0437\u0430\u043F\u0443\u0441\u043A\u0430</h1><p>\u041E\u0442\u043A\u0440\u043E\u0439\u0442\u0435 \u0430\u0434\u0440\u0435\u0441 \u0438\u0437 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0430: \u043E\u043D \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u0442 \u043E\u0434\u043D\u043E\u0440\u0430\u0437\u043E\u0432\u044B\u0439 \u0442\u043E\u043A\u0435\u043D.</p>');
|
|
5487
5747
|
return;
|
|
5488
5748
|
}
|
|
5489
|
-
const html = await readFile2(
|
|
5749
|
+
const html = await readFile2(path9.join(options.uiDir, "index.html"));
|
|
5490
5750
|
res.writeHead(200, { ...SECURITY_HEADERS, "content-type": MIME[".html"], "cache-control": "no-store" });
|
|
5491
5751
|
res.end(html);
|
|
5492
5752
|
return;
|
|
5493
5753
|
}
|
|
5494
5754
|
if (req.method === "GET" && (url.pathname.startsWith("/assets/") || url.pathname === "/favicon.svg")) {
|
|
5495
5755
|
const relative = url.pathname === "/favicon.svg" ? "favicon.svg" : url.pathname.slice("/assets/".length);
|
|
5496
|
-
const target =
|
|
5497
|
-
if (!target.startsWith(
|
|
5756
|
+
const target = path9.resolve(options.uiDir, url.pathname === "/favicon.svg" ? "" : "assets", relative);
|
|
5757
|
+
if (!target.startsWith(path9.resolve(options.uiDir) + path9.sep) || relative.includes("..")) {
|
|
5498
5758
|
reply(res, 404, { ok: false, error: "\u043D\u0435\u0442 \u0444\u0430\u0439\u043B\u0430" });
|
|
5499
5759
|
return;
|
|
5500
5760
|
}
|
|
5501
|
-
const info = await
|
|
5761
|
+
const info = await stat2(target).catch(() => null);
|
|
5502
5762
|
if (!info?.isFile()) {
|
|
5503
5763
|
reply(res, 404, { ok: false, error: "\u043D\u0435\u0442 \u0444\u0430\u0439\u043B\u0430" });
|
|
5504
5764
|
return;
|
|
5505
5765
|
}
|
|
5506
5766
|
res.writeHead(200, {
|
|
5507
5767
|
...SECURITY_HEADERS,
|
|
5508
|
-
"content-type": MIME[
|
|
5768
|
+
"content-type": MIME[path9.extname(target)] ?? "application/octet-stream",
|
|
5509
5769
|
"cache-control": "public, max-age=31536000, immutable"
|
|
5510
5770
|
});
|
|
5511
5771
|
createReadStream(target).pipe(res);
|
|
@@ -5540,16 +5800,24 @@ data: ${JSON.stringify(event)}
|
|
|
5540
5800
|
res.write(`event: feature
|
|
5541
5801
|
data: ${JSON.stringify(event)}
|
|
5542
5802
|
|
|
5803
|
+
`);
|
|
5804
|
+
};
|
|
5805
|
+
const projectListener = (event) => {
|
|
5806
|
+
res.write(`event: project
|
|
5807
|
+
data: ${JSON.stringify(event)}
|
|
5808
|
+
|
|
5543
5809
|
`);
|
|
5544
5810
|
};
|
|
5545
5811
|
service.events.on("review", reviewListener);
|
|
5546
5812
|
service.events.on("feature", featureListener);
|
|
5813
|
+
service.events.on("project", projectListener);
|
|
5547
5814
|
const heartbeat = setInterval(() => res.write(": ping\n\n"), 25e3);
|
|
5548
5815
|
heartbeat.unref?.();
|
|
5549
5816
|
req.on("close", () => {
|
|
5550
5817
|
clearInterval(heartbeat);
|
|
5551
5818
|
service.events.off("review", reviewListener);
|
|
5552
5819
|
service.events.off("feature", featureListener);
|
|
5820
|
+
service.events.off("project", projectListener);
|
|
5553
5821
|
});
|
|
5554
5822
|
return;
|
|
5555
5823
|
}
|
|
@@ -5640,6 +5908,23 @@ data: ${JSON.stringify(event)}
|
|
|
5640
5908
|
reply(res, 200, { ok: true, project, projects: service.listProjects() });
|
|
5641
5909
|
return;
|
|
5642
5910
|
}
|
|
5911
|
+
case "/api/projects/update": {
|
|
5912
|
+
const project = String(body.project ?? "");
|
|
5913
|
+
if (!project) throw Object.assign(new Error("\u043D\u0443\u0436\u0435\u043D \u043A\u043B\u044E\u0447 \u043F\u0440\u043E\u0435\u043A\u0442\u0430"), { status: 400 });
|
|
5914
|
+
const updated = service.updateProject(project, {
|
|
5915
|
+
...typeof body.title === "string" ? { title: body.title } : {},
|
|
5916
|
+
...Array.isArray(body.roots) ? { roots: body.roots.map(String) } : {}
|
|
5917
|
+
});
|
|
5918
|
+
reply(res, 200, { ok: true, project: updated, projects: service.listProjects() });
|
|
5919
|
+
return;
|
|
5920
|
+
}
|
|
5921
|
+
case "/api/projects/remove": {
|
|
5922
|
+
const project = String(body.project ?? "");
|
|
5923
|
+
if (!project) throw Object.assign(new Error("\u043D\u0443\u0436\u0435\u043D \u043A\u043B\u044E\u0447 \u043F\u0440\u043E\u0435\u043A\u0442\u0430"), { status: 400 });
|
|
5924
|
+
const removedReviews = service.removeProject(project);
|
|
5925
|
+
reply(res, 200, { ok: true, removedReviews, projects: service.listProjects() });
|
|
5926
|
+
return;
|
|
5927
|
+
}
|
|
5643
5928
|
case "/api/reviews/open": {
|
|
5644
5929
|
const root = String(body.root ?? "");
|
|
5645
5930
|
if (!root) throw Object.assign(new Error("\u043D\u0443\u0436\u0435\u043D root \u0440\u0430\u0431\u043E\u0447\u0435\u0439 \u043A\u043E\u043F\u0438\u0438"), { status: 400 });
|
|
@@ -5752,7 +6037,12 @@ data: ${JSON.stringify(event)}
|
|
|
5752
6037
|
return;
|
|
5753
6038
|
}
|
|
5754
6039
|
case "/api/rpc": {
|
|
5755
|
-
const result = await dispatch(
|
|
6040
|
+
const result = await dispatch(
|
|
6041
|
+
service,
|
|
6042
|
+
String(body.method ?? ""),
|
|
6043
|
+
body.params ?? {},
|
|
6044
|
+
isHuman ? HUMAN_POLICY : AGENT_POLICY
|
|
6045
|
+
);
|
|
5756
6046
|
reply(res, 200, { ok: true, result });
|
|
5757
6047
|
return;
|
|
5758
6048
|
}
|
|
@@ -5789,15 +6079,29 @@ data: ${JSON.stringify(event)}
|
|
|
5789
6079
|
|
|
5790
6080
|
// src/daemon/bridge.ts
|
|
5791
6081
|
import { unlink as unlink3 } from "node:fs/promises";
|
|
5792
|
-
import
|
|
6082
|
+
import path10 from "node:path";
|
|
5793
6083
|
async function startDevcontainerBridge(service, info) {
|
|
5794
|
-
await ensureDir(
|
|
6084
|
+
await ensureDir(path10.dirname(devcontainerBridgeDir()), 448);
|
|
5795
6085
|
await ensureDir(devcontainerBridgeDir(), 448);
|
|
5796
6086
|
await ensureDir(devcontainerRunDir(), 493);
|
|
5797
6087
|
await ensureDir(devcontainerStateDir(), 493);
|
|
5798
|
-
const rpc = await startRpcServer(service, devcontainerSocketPath(), {
|
|
6088
|
+
const rpc = await startRpcServer(service, devcontainerSocketPath(), {
|
|
6089
|
+
mode: 438,
|
|
6090
|
+
dirMode: 493,
|
|
6091
|
+
policy: AGENT_POLICY
|
|
6092
|
+
});
|
|
5799
6093
|
try {
|
|
5800
|
-
const payload = {
|
|
6094
|
+
const payload = {
|
|
6095
|
+
pid: info.pid,
|
|
6096
|
+
port: info.port,
|
|
6097
|
+
url: info.url,
|
|
6098
|
+
socket: devcontainerSocketPath(),
|
|
6099
|
+
startedAt: info.startedAt,
|
|
6100
|
+
version: info.version,
|
|
6101
|
+
protocol: info.protocol,
|
|
6102
|
+
capabilities: [...AGENT_POLICY.capabilities],
|
|
6103
|
+
agentToken: info.agentToken
|
|
6104
|
+
};
|
|
5801
6105
|
await writeFileAtomic(devcontainerInfoPath(), `${JSON.stringify(payload, null, 2)}
|
|
5802
6106
|
`, 420, 493);
|
|
5803
6107
|
} catch (error) {
|
|
@@ -5854,6 +6158,7 @@ async function main() {
|
|
|
5854
6158
|
return;
|
|
5855
6159
|
}
|
|
5856
6160
|
const token = (await import("node:crypto")).randomBytes(32).toString("hex");
|
|
6161
|
+
const agentToken = (await import("node:crypto")).randomBytes(32).toString("hex");
|
|
5857
6162
|
const store = new Store(databasePath());
|
|
5858
6163
|
const service = new ReviewService({
|
|
5859
6164
|
store,
|
|
@@ -5861,10 +6166,11 @@ async function main() {
|
|
|
5861
6166
|
});
|
|
5862
6167
|
const socket = socketPath();
|
|
5863
6168
|
const rpc = await startRpcServer(service, socket);
|
|
5864
|
-
const uiDir = values["ui-dir"] ?
|
|
6169
|
+
const uiDir = values["ui-dir"] ? path11.resolve(values["ui-dir"]) : path11.join(packageRoot(), "dist", "ui");
|
|
5865
6170
|
const http2 = await startHttpServer({
|
|
5866
6171
|
service,
|
|
5867
6172
|
token,
|
|
6173
|
+
agentToken,
|
|
5868
6174
|
uiDir,
|
|
5869
6175
|
...values.port ? { port: Number(values.port) } : {},
|
|
5870
6176
|
...values.host ? { host: String(values.host) } : {},
|
|
@@ -5875,6 +6181,7 @@ async function main() {
|
|
|
5875
6181
|
pid: process.pid,
|
|
5876
6182
|
port: http2.port,
|
|
5877
6183
|
token,
|
|
6184
|
+
agentToken,
|
|
5878
6185
|
url: http2.url,
|
|
5879
6186
|
socket,
|
|
5880
6187
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -5913,7 +6220,7 @@ async function main() {
|
|
|
5913
6220
|
service.close();
|
|
5914
6221
|
await unlink4(daemonInfoPath()).catch(() => void 0);
|
|
5915
6222
|
await lock.close().catch(() => void 0);
|
|
5916
|
-
await unlink4(
|
|
6223
|
+
await unlink4(path11.join(stateDir(), "daemon.lock")).catch(() => void 0);
|
|
5917
6224
|
process.exit(0);
|
|
5918
6225
|
}
|
|
5919
6226
|
};
|
|
@@ -5925,24 +6232,24 @@ async function main() {
|
|
|
5925
6232
|
}
|
|
5926
6233
|
}
|
|
5927
6234
|
function packageRoot() {
|
|
5928
|
-
let dir =
|
|
6235
|
+
let dir = path11.dirname(fileURLToPath(import.meta.url));
|
|
5929
6236
|
for (; ; ) {
|
|
5930
|
-
const candidate =
|
|
5931
|
-
if (
|
|
6237
|
+
const candidate = path11.join(dir, "package.json");
|
|
6238
|
+
if (existsSync5(candidate)) {
|
|
5932
6239
|
try {
|
|
5933
6240
|
const parsed = JSON.parse(readFileSync(candidate, "utf8"));
|
|
5934
6241
|
if (parsed.name === "revdeck") return dir;
|
|
5935
6242
|
} catch {
|
|
5936
6243
|
}
|
|
5937
6244
|
}
|
|
5938
|
-
const parent =
|
|
6245
|
+
const parent = path11.dirname(dir);
|
|
5939
6246
|
if (parent === dir) return process.cwd();
|
|
5940
6247
|
dir = parent;
|
|
5941
6248
|
}
|
|
5942
6249
|
}
|
|
5943
6250
|
async function runningDaemon() {
|
|
5944
6251
|
const infoPath = daemonInfoPath();
|
|
5945
|
-
if (!
|
|
6252
|
+
if (!existsSync5(infoPath)) return null;
|
|
5946
6253
|
let info;
|
|
5947
6254
|
try {
|
|
5948
6255
|
info = JSON.parse(readFileSync(infoPath, "utf8"));
|
|
@@ -5974,7 +6281,7 @@ async function runningDaemon() {
|
|
|
5974
6281
|
return reachable ? info : null;
|
|
5975
6282
|
}
|
|
5976
6283
|
async function acquireLock() {
|
|
5977
|
-
const file =
|
|
6284
|
+
const file = path11.join(stateDir(), "daemon.lock");
|
|
5978
6285
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
5979
6286
|
try {
|
|
5980
6287
|
const handle = await open2(file, "wx", 384);
|