revdeck 0.17.0 → 0.18.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 +50 -0
- package/README.md +24 -7
- package/README.ru.md +24 -7
- package/dist/cli.js +780 -80
- package/dist/cli.js.map +4 -4
- package/dist/daemon.js +484 -116
- package/dist/daemon.js.map +4 -4
- package/dist/mcp.js +30 -1
- package/dist/mcp.js.map +4 -4
- package/dist/ui/assets/{index-DNyhbjYn.js → index-D3hJTLAL.js} +14 -14
- package/dist/ui/assets/{index-Bd7WadZ2.css → index-ahIeys_y.css} +1 -1
- package/dist/ui/index.html +2 -2
- package/docs/capabilities.md +30 -4
- package/docs/protocol.md +1 -1
- package/docs/ru/capabilities.md +33 -4
- package/docs/ru/protocol.md +1 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -138,7 +138,7 @@ var init_errors = __esm({
|
|
|
138
138
|
// src/core/exec.ts
|
|
139
139
|
import { execFile } from "node:child_process";
|
|
140
140
|
import { access, constants as constants2 } from "node:fs/promises";
|
|
141
|
-
import
|
|
141
|
+
import os3 from "node:os";
|
|
142
142
|
import path3 from "node:path";
|
|
143
143
|
function scrubEnv(extra) {
|
|
144
144
|
const env = {};
|
|
@@ -170,10 +170,10 @@ async function resolveExecutable(command) {
|
|
|
170
170
|
if (cached) return cached;
|
|
171
171
|
const dirs = [
|
|
172
172
|
...(process.env.PATH ?? "").split(path3.delimiter),
|
|
173
|
-
path3.join(
|
|
174
|
-
path3.join(
|
|
175
|
-
path3.join(
|
|
176
|
-
path3.join(
|
|
173
|
+
path3.join(os3.homedir(), ".local", "bin"),
|
|
174
|
+
path3.join(os3.homedir(), ".local", "share", "mise", "shims"),
|
|
175
|
+
path3.join(os3.homedir(), ".asdf", "shims"),
|
|
176
|
+
path3.join(os3.homedir(), ".npm-global", "bin"),
|
|
177
177
|
"/opt/homebrew/bin",
|
|
178
178
|
"/usr/local/bin",
|
|
179
179
|
"/usr/bin",
|
|
@@ -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, path13) {
|
|
423
|
+
return files.find((file) => file.path === path13) ?? files.find((file) => file.oldPath === path13);
|
|
424
424
|
}
|
|
425
|
-
function findNewLine(files,
|
|
426
|
-
const file = findFile(files,
|
|
425
|
+
function findNewLine(files, path13, line) {
|
|
426
|
+
const file = findFile(files, path13);
|
|
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, path12, line) {
|
|
|
432
432
|
}
|
|
433
433
|
return void 0;
|
|
434
434
|
}
|
|
435
|
-
function snippetAround(files,
|
|
436
|
-
const file = findFile(files,
|
|
435
|
+
function snippetAround(files, path13, line, radius = 6) {
|
|
436
|
+
const file = findFile(files, path13);
|
|
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);
|
|
@@ -451,11 +451,11 @@ function snippetAt(flat, target, line, radius) {
|
|
|
451
451
|
}
|
|
452
452
|
function createSnippetReader(files) {
|
|
453
453
|
const cache = /* @__PURE__ */ new Map();
|
|
454
|
-
return (
|
|
454
|
+
return (path13, line, radius = 6) => {
|
|
455
455
|
if (line == null) return null;
|
|
456
|
-
let entry = cache.get(
|
|
456
|
+
let entry = cache.get(path13);
|
|
457
457
|
if (entry === void 0) {
|
|
458
|
-
const file = findFile(files,
|
|
458
|
+
const file = findFile(files, path13);
|
|
459
459
|
if (!file) {
|
|
460
460
|
entry = null;
|
|
461
461
|
} else {
|
|
@@ -467,7 +467,7 @@ function createSnippetReader(files) {
|
|
|
467
467
|
}
|
|
468
468
|
entry = { flat, byNewLine };
|
|
469
469
|
}
|
|
470
|
-
cache.set(
|
|
470
|
+
cache.set(path13, entry);
|
|
471
471
|
}
|
|
472
472
|
if (!entry) return null;
|
|
473
473
|
const target = entry.byNewLine.get(line);
|
|
@@ -475,9 +475,9 @@ function createSnippetReader(files) {
|
|
|
475
475
|
return snippetAt(entry.flat, target, line, radius);
|
|
476
476
|
};
|
|
477
477
|
}
|
|
478
|
-
function linePosition(files,
|
|
479
|
-
const file = findFile(files,
|
|
480
|
-
const found = findNewLine(files,
|
|
478
|
+
function linePosition(files, path13, line) {
|
|
479
|
+
const file = findFile(files, path13);
|
|
480
|
+
const found = findNewLine(files, path13, line);
|
|
481
481
|
if (!file || !found) return null;
|
|
482
482
|
return { newPath: file.path, newLine: line, oldPath: file.oldPath, oldLine: found.kind === " " ? found.oldLine : null };
|
|
483
483
|
}
|
|
@@ -535,8 +535,8 @@ async function withTempJson(data, fn) {
|
|
|
535
535
|
await rm(dir, { recursive: true, force: true });
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
|
-
function query(
|
|
539
|
-
const url = new URL(
|
|
538
|
+
function query(path13, params) {
|
|
539
|
+
const url = new URL(path13.startsWith("/") ? path13 : `/${path13}`, "http://local");
|
|
540
540
|
for (const [key, value] of Object.entries(params)) {
|
|
541
541
|
if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
542
542
|
}
|
|
@@ -699,8 +699,8 @@ rename to ${newPath}
|
|
|
699
699
|
}
|
|
700
700
|
return parseUnifiedDiff(chunks.join("\n"));
|
|
701
701
|
}
|
|
702
|
-
async fileContent(
|
|
703
|
-
const endpoint = `projects/${this.projectRef}/repository/files/${encodeURIComponent(
|
|
702
|
+
async fileContent(path13, ref) {
|
|
703
|
+
const endpoint = `projects/${this.projectRef}/repository/files/${encodeURIComponent(path13)}/raw`;
|
|
704
704
|
return this.call([query(endpoint, { ref })]);
|
|
705
705
|
}
|
|
706
706
|
async readiness() {
|
|
@@ -1105,8 +1105,8 @@ rename to ${newPath}
|
|
|
1105
1105
|
}
|
|
1106
1106
|
return parseUnifiedDiff(chunks.join("\n"));
|
|
1107
1107
|
}
|
|
1108
|
-
async fileContent(
|
|
1109
|
-
const encoded =
|
|
1108
|
+
async fileContent(path13, ref) {
|
|
1109
|
+
const encoded = path13.split("/").map(encodeURIComponent).join("/");
|
|
1110
1110
|
return this.call(["-H", "Accept: application/vnd.github.raw", query(`repos/${this.repo}/contents/${encoded}`, { ref })]);
|
|
1111
1111
|
}
|
|
1112
1112
|
async readiness() {
|
|
@@ -1341,9 +1341,9 @@ rename to ${newPath}
|
|
|
1341
1341
|
|
|
1342
1342
|
// src/daemon/main.ts
|
|
1343
1343
|
import { existsSync as existsSync5, readFileSync } from "node:fs";
|
|
1344
|
-
import { appendFile, open as open2, readFile as
|
|
1344
|
+
import { appendFile, open as open2, readFile as readFile4, rename as rename2, stat as stat3, unlink as unlink4 } from "node:fs/promises";
|
|
1345
1345
|
import net2 from "node:net";
|
|
1346
|
-
import
|
|
1346
|
+
import path12 from "node:path";
|
|
1347
1347
|
import { fileURLToPath } from "node:url";
|
|
1348
1348
|
import { parseArgs } from "node:util";
|
|
1349
1349
|
|
|
@@ -1500,12 +1500,85 @@ async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
|
|
|
1500
1500
|
init_redact();
|
|
1501
1501
|
|
|
1502
1502
|
// src/version.ts
|
|
1503
|
-
var VERSION = "0.
|
|
1503
|
+
var VERSION = "0.18.0";
|
|
1504
1504
|
var PROTOCOL_VERSION = 2;
|
|
1505
1505
|
|
|
1506
1506
|
// src/daemon/main.ts
|
|
1507
1507
|
init_locale();
|
|
1508
1508
|
|
|
1509
|
+
// src/cli/report.ts
|
|
1510
|
+
init_locale();
|
|
1511
|
+
import os2 from "node:os";
|
|
1512
|
+
function createPalette(stream) {
|
|
1513
|
+
const enabled = (() => {
|
|
1514
|
+
if (process.env.NO_COLOR) return false;
|
|
1515
|
+
const force = process.env.FORCE_COLOR;
|
|
1516
|
+
if (force === "0") return false;
|
|
1517
|
+
if (force !== void 0 && force !== "") return true;
|
|
1518
|
+
return Boolean(stream.isTTY) && process.env.TERM !== "dumb";
|
|
1519
|
+
})();
|
|
1520
|
+
const wrap = (open3, close) => (text2) => enabled ? `\x1B[${open3}m${text2}\x1B[${close}m` : text2;
|
|
1521
|
+
return {
|
|
1522
|
+
enabled,
|
|
1523
|
+
bold: wrap("1", "22"),
|
|
1524
|
+
dim: wrap("2", "22"),
|
|
1525
|
+
red: wrap("31", "39"),
|
|
1526
|
+
green: wrap("32", "39"),
|
|
1527
|
+
yellow: wrap("33", "39"),
|
|
1528
|
+
blue: wrap("34", "39"),
|
|
1529
|
+
magenta: wrap("35", "39"),
|
|
1530
|
+
cyan: wrap("36", "39"),
|
|
1531
|
+
link: (text2) => enabled ? `\x1B[4;34m${text2}\x1B[0m` : text2
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
var colors = createPalette(process.stdout);
|
|
1535
|
+
var errorColors = createPalette(process.stderr);
|
|
1536
|
+
function tildify(value, home = os2.homedir()) {
|
|
1537
|
+
if (!value || !home) return value;
|
|
1538
|
+
const prefix = home.replace(/[\\/]+$/, "");
|
|
1539
|
+
if (value === prefix) return "~";
|
|
1540
|
+
if (value.startsWith(`${prefix}/`) || value.startsWith(`${prefix}\\`)) return `~${value.slice(prefix.length)}`;
|
|
1541
|
+
return value;
|
|
1542
|
+
}
|
|
1543
|
+
function padEnd(value, width) {
|
|
1544
|
+
const length = [...value].length;
|
|
1545
|
+
return length >= width ? value : value + " ".repeat(width - length);
|
|
1546
|
+
}
|
|
1547
|
+
function rows(fields) {
|
|
1548
|
+
const width = Math.max(...fields.map(([label]) => [...label].length));
|
|
1549
|
+
return fields.map(([label, value]) => ` ${colors.dim(padEnd(label, width))} ${value}`);
|
|
1550
|
+
}
|
|
1551
|
+
function startTitle(mode) {
|
|
1552
|
+
if (mode === "restarted") return tr("\u0414\u0435\u043C\u043E\u043D \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0449\u0435\u043D", "Daemon restarted");
|
|
1553
|
+
if (mode === "running") return tr("\u0414\u0435\u043C\u043E\u043D \u0443\u0436\u0435 \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442", "Daemon already running");
|
|
1554
|
+
return tr("\u0414\u0435\u043C\u043E\u043D \u0437\u0430\u043F\u0443\u0449\u0435\u043D", "Daemon started");
|
|
1555
|
+
}
|
|
1556
|
+
var START_FOOTER = () => ` ${colors.dim(tr("\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441:", "Open the UI:"))} ${colors.cyan("revdeck ui --open")}`;
|
|
1557
|
+
function daemonStartedLines(view, mode = "started") {
|
|
1558
|
+
return [
|
|
1559
|
+
"",
|
|
1560
|
+
` ${colors.dim("revdeck")} ${colors.dim(view.version)}`,
|
|
1561
|
+
"",
|
|
1562
|
+
` ${colors.green("\u25CF")} ${colors.bold(startTitle(mode))} ${colors.dim(`\xB7 pid ${view.pid}`)}`,
|
|
1563
|
+
"",
|
|
1564
|
+
...rows([
|
|
1565
|
+
[tr("\u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441", "ui"), colors.link(view.url)],
|
|
1566
|
+
[tr("\u0441\u043E\u043A\u0435\u0442", "socket"), colors.dim(tildify(view.socket))],
|
|
1567
|
+
[tr("\u0434\u0430\u043D\u043D\u044B\u0435", "state"), colors.dim(tildify(view.stateDir))],
|
|
1568
|
+
[tr("\u043B\u043E\u0433", "log"), colors.dim(tildify(view.logPath))]
|
|
1569
|
+
]),
|
|
1570
|
+
"",
|
|
1571
|
+
START_FOOTER(),
|
|
1572
|
+
""
|
|
1573
|
+
];
|
|
1574
|
+
}
|
|
1575
|
+
function errorLine(message, hint) {
|
|
1576
|
+
return [
|
|
1577
|
+
`${errorColors.red("revdeck:")} ${message}`,
|
|
1578
|
+
...hint ? [` ${errorColors.dim(hint)}`] : []
|
|
1579
|
+
];
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1509
1582
|
// src/daemon/store.ts
|
|
1510
1583
|
import { DatabaseSync } from "node:sqlite";
|
|
1511
1584
|
import { mkdirSync } from "node:fs";
|
|
@@ -1942,7 +2015,7 @@ var Store = class {
|
|
|
1942
2015
|
return key;
|
|
1943
2016
|
}
|
|
1944
2017
|
listProjects() {
|
|
1945
|
-
const
|
|
2018
|
+
const rows2 = this.db.prepare(
|
|
1946
2019
|
`SELECT p.*,
|
|
1947
2020
|
(SELECT COUNT(*) FROM reviews r WHERE r.project_key = p.key) AS reviews,
|
|
1948
2021
|
(SELECT MAX(r.synced_at) FROM reviews r WHERE r.project_key = p.key) AS last_activity
|
|
@@ -1957,7 +2030,7 @@ var Store = class {
|
|
|
1957
2030
|
list.push(text(row, "root"));
|
|
1958
2031
|
rootsByProject.set(key, list);
|
|
1959
2032
|
}
|
|
1960
|
-
return
|
|
2033
|
+
return rows2.map((row) => {
|
|
1961
2034
|
const key = text(row, "key");
|
|
1962
2035
|
return {
|
|
1963
2036
|
key,
|
|
@@ -1977,14 +2050,14 @@ var Store = class {
|
|
|
1977
2050
|
return this.listProjects().find((project) => project.key === key) ?? null;
|
|
1978
2051
|
}
|
|
1979
2052
|
/**
|
|
1980
|
-
* Настройки UI. Порт
|
|
1981
|
-
* localStorage в браузере привязан к origin и
|
|
1982
|
-
*
|
|
2053
|
+
* Настройки UI. Порт обычно переиспользуется, но может смениться (занят,
|
|
2054
|
+
* --port, смена хоста), поэтому localStorage в браузере привязан к origin и
|
|
2055
|
+
* после перезапуска может быть пуст: надёжное место — база на хосте.
|
|
1983
2056
|
*/
|
|
1984
2057
|
uiSettings() {
|
|
1985
|
-
const
|
|
2058
|
+
const rows2 = this.db.prepare("SELECT key, value_json FROM ui_settings ORDER BY key").all();
|
|
1986
2059
|
const settings = {};
|
|
1987
|
-
for (const row of
|
|
2060
|
+
for (const row of rows2) {
|
|
1988
2061
|
try {
|
|
1989
2062
|
settings[text(row, "key")] = JSON.parse(text(row, "value_json"));
|
|
1990
2063
|
} catch {
|
|
@@ -2037,14 +2110,14 @@ var Store = class {
|
|
|
2037
2110
|
}
|
|
2038
2111
|
// ---------------------------------------------------------------- features
|
|
2039
2112
|
featureMembers(id) {
|
|
2040
|
-
const
|
|
2113
|
+
const rows2 = this.db.prepare(
|
|
2041
2114
|
`SELECT fr.role, fr.sort_order, fr.added_at, r.*
|
|
2042
2115
|
FROM feature_reviews fr
|
|
2043
2116
|
JOIN reviews r ON r.id = fr.review_id
|
|
2044
2117
|
WHERE fr.feature_id = ?
|
|
2045
2118
|
ORDER BY fr.sort_order ASC, fr.added_at ASC, r.number ASC`
|
|
2046
2119
|
).all(id);
|
|
2047
|
-
return
|
|
2120
|
+
return rows2.map((row) => ({
|
|
2048
2121
|
review: reviewItem(row),
|
|
2049
2122
|
role: text(row, "role"),
|
|
2050
2123
|
sortOrder: Number(row.sort_order),
|
|
@@ -2084,12 +2157,12 @@ var Store = class {
|
|
|
2084
2157
|
clauses.push("EXISTS (SELECT 1 FROM feature_reviews fr JOIN reviews r ON r.id = fr.review_id WHERE fr.feature_id = f.id AND r.project_key = ?)");
|
|
2085
2158
|
args.push(project);
|
|
2086
2159
|
}
|
|
2087
|
-
const
|
|
2088
|
-
return
|
|
2160
|
+
const rows2 = this.db.prepare(`SELECT f.* FROM features f WHERE ${clauses.join(" AND ")} ORDER BY f.updated_at DESC, f.title ASC`).all(...args);
|
|
2161
|
+
return rows2.map((row) => this.featureSummary(row, this.featureMembers(text(row, "id"))));
|
|
2089
2162
|
}
|
|
2090
2163
|
featureNotes(featureId) {
|
|
2091
|
-
const
|
|
2092
|
-
return
|
|
2164
|
+
const rows2 = this.db.prepare("SELECT * FROM feature_notes WHERE feature_id = ? ORDER BY created_at ASC, rowid ASC").all(featureId);
|
|
2165
|
+
return rows2.map((row) => ({
|
|
2093
2166
|
id: text(row, "id"),
|
|
2094
2167
|
featureId: text(row, "feature_id"),
|
|
2095
2168
|
kind: text(row, "kind") === "finding" ? "finding" : "note",
|
|
@@ -2141,13 +2214,13 @@ var Store = class {
|
|
|
2141
2214
|
this.touchFeature(featureId, now);
|
|
2142
2215
|
}
|
|
2143
2216
|
featuresForReview(reviewId2) {
|
|
2144
|
-
const
|
|
2217
|
+
const rows2 = this.db.prepare(
|
|
2145
2218
|
`SELECT f.* FROM features f
|
|
2146
2219
|
JOIN feature_reviews fr ON fr.feature_id = f.id
|
|
2147
2220
|
WHERE fr.review_id = ?
|
|
2148
2221
|
ORDER BY f.updated_at DESC, f.title ASC`
|
|
2149
2222
|
).all(reviewId2);
|
|
2150
|
-
return
|
|
2223
|
+
return rows2.map((row) => this.featureSummary(row, this.featureMembers(text(row, "id"))));
|
|
2151
2224
|
}
|
|
2152
2225
|
touchFeature(id, now) {
|
|
2153
2226
|
this.db.prepare("UPDATE features SET updated_at = ? WHERE id = ?").run(now, id);
|
|
@@ -2241,8 +2314,8 @@ var Store = class {
|
|
|
2241
2314
|
this.snapshotCache = null;
|
|
2242
2315
|
}
|
|
2243
2316
|
listReviews(project) {
|
|
2244
|
-
const
|
|
2245
|
-
return
|
|
2317
|
+
const rows2 = project ? this.db.prepare("SELECT * FROM reviews WHERE project_key = ? ORDER BY updated_at DESC, number DESC").all(project) : this.db.prepare("SELECT * FROM reviews ORDER BY updated_at DESC, number DESC").all();
|
|
2318
|
+
return rows2.map(reviewItem);
|
|
2246
2319
|
}
|
|
2247
2320
|
getReview(id) {
|
|
2248
2321
|
const row = this.db.prepare("SELECT * FROM reviews WHERE id = ?").get(id);
|
|
@@ -2299,8 +2372,8 @@ var Store = class {
|
|
|
2299
2372
|
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));
|
|
2300
2373
|
}
|
|
2301
2374
|
listVersions(id) {
|
|
2302
|
-
const
|
|
2303
|
-
return
|
|
2375
|
+
const rows2 = this.db.prepare("SELECT * FROM review_versions WHERE review_id = ? ORDER BY id DESC").all(id);
|
|
2376
|
+
return rows2.map((row) => {
|
|
2304
2377
|
const data = json(row, "data_json", {});
|
|
2305
2378
|
const stats = data.stats ?? {};
|
|
2306
2379
|
const files = Array.isArray(data.files) ? data.files.length : 0;
|
|
@@ -2383,8 +2456,8 @@ var Store = class {
|
|
|
2383
2456
|
}
|
|
2384
2457
|
// --- findings ---
|
|
2385
2458
|
listFindings(id) {
|
|
2386
|
-
const
|
|
2387
|
-
return
|
|
2459
|
+
const rows2 = this.db.prepare("SELECT * FROM findings WHERE review_id = ? ORDER BY rowid").all(id);
|
|
2460
|
+
return rows2.map((row) => ({
|
|
2388
2461
|
id: text(row, "id"),
|
|
2389
2462
|
fingerprint: text(row, "fingerprint"),
|
|
2390
2463
|
level: text(row, "level"),
|
|
@@ -2465,8 +2538,8 @@ var Store = class {
|
|
|
2465
2538
|
}
|
|
2466
2539
|
// --- drafts ---
|
|
2467
2540
|
listDrafts(id) {
|
|
2468
|
-
const
|
|
2469
|
-
return
|
|
2541
|
+
const rows2 = this.db.prepare("SELECT * FROM drafts WHERE review_id = ? ORDER BY rowid").all(id);
|
|
2542
|
+
return rows2.map((row) => ({
|
|
2470
2543
|
threadId: text(row, "thread_id"),
|
|
2471
2544
|
body: text(row, "body"),
|
|
2472
2545
|
resolve: Number(row.resolve) === 1,
|
|
@@ -2506,8 +2579,8 @@ var Store = class {
|
|
|
2506
2579
|
}
|
|
2507
2580
|
// --- notes ---
|
|
2508
2581
|
listNotes(id) {
|
|
2509
|
-
const
|
|
2510
|
-
return
|
|
2582
|
+
const rows2 = this.db.prepare("SELECT * FROM notes WHERE review_id = ? ORDER BY created_at").all(id);
|
|
2583
|
+
return rows2.map((row) => ({
|
|
2511
2584
|
id: text(row, "id"),
|
|
2512
2585
|
file: text(row, "file"),
|
|
2513
2586
|
line: Number(row.line),
|
|
@@ -2556,8 +2629,8 @@ var Store = class {
|
|
|
2556
2629
|
}
|
|
2557
2630
|
// --- agent messages ---
|
|
2558
2631
|
listAgentMessages(id) {
|
|
2559
|
-
const
|
|
2560
|
-
return
|
|
2632
|
+
const rows2 = this.db.prepare("SELECT * FROM agent_messages WHERE review_id = ? ORDER BY created_at, rowid").all(id);
|
|
2633
|
+
return rows2.map((row) => ({
|
|
2561
2634
|
id: text(row, "id"),
|
|
2562
2635
|
role: text(row, "role") === "agent" ? "agent" : "human",
|
|
2563
2636
|
text: text(row, "text"),
|
|
@@ -2569,9 +2642,9 @@ var Store = class {
|
|
|
2569
2642
|
}
|
|
2570
2643
|
// --- decisions ---
|
|
2571
2644
|
listDecisions(id) {
|
|
2572
|
-
const
|
|
2645
|
+
const rows2 = this.db.prepare("SELECT * FROM decisions WHERE review_id = ?").all(id);
|
|
2573
2646
|
const out = {};
|
|
2574
|
-
for (const row of
|
|
2647
|
+
for (const row of rows2) {
|
|
2575
2648
|
out[text(row, "finding_id")] = {
|
|
2576
2649
|
decision: row.decision ? String(row.decision) : null,
|
|
2577
2650
|
note: text(row, "note")
|
|
@@ -2641,8 +2714,8 @@ var Store = class {
|
|
|
2641
2714
|
params.push(to);
|
|
2642
2715
|
}
|
|
2643
2716
|
params.push(limit);
|
|
2644
|
-
const
|
|
2645
|
-
return
|
|
2717
|
+
const rows2 = this.db.prepare(`SELECT * FROM review_events WHERE ${clauses.join(" AND ")} ORDER BY id ASC LIMIT ?`).all(...params);
|
|
2718
|
+
return rows2.map((row) => ({
|
|
2646
2719
|
id: Number(row.id),
|
|
2647
2720
|
at: text(row, "at"),
|
|
2648
2721
|
reviewId: row.review_id ? String(row.review_id) : null,
|
|
@@ -2660,8 +2733,8 @@ var Store = class {
|
|
|
2660
2733
|
this.db.prepare("INSERT INTO audit (at, review_id, action, detail) VALUES (?, ?, ?, ?)").run((/* @__PURE__ */ new Date()).toISOString(), reviewId2, action, JSON.stringify(detail));
|
|
2661
2734
|
}
|
|
2662
2735
|
auditTail(limit = 100) {
|
|
2663
|
-
const
|
|
2664
|
-
return
|
|
2736
|
+
const rows2 = this.db.prepare("SELECT * FROM audit ORDER BY id DESC LIMIT ?").all(limit);
|
|
2737
|
+
return rows2.map((row) => ({
|
|
2665
2738
|
at: text(row, "at"),
|
|
2666
2739
|
reviewId: text(row, "review_id"),
|
|
2667
2740
|
action: text(row, "action"),
|
|
@@ -2740,8 +2813,8 @@ function globToRegExp(glob) {
|
|
|
2740
2813
|
function escapeRegExp(value) {
|
|
2741
2814
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2742
2815
|
}
|
|
2743
|
-
function classifyFile(
|
|
2744
|
-
const lower =
|
|
2816
|
+
function classifyFile(path13) {
|
|
2817
|
+
const lower = path13.toLowerCase();
|
|
2745
2818
|
if (/(^|\/)(node_modules|dist|build|coverage|vendor)\//.test(lower)) return "generated";
|
|
2746
2819
|
if (/\.(md|mdx|rst|txt|adoc)$/.test(lower) || /(^|\/)(docs?|adr)\//.test(lower)) return "docs";
|
|
2747
2820
|
if (/(^|\/)(__tests__|tests?|spec|e2e)\//.test(lower) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(lower) || /_test\.go$/.test(lower)) return "test";
|
|
@@ -3403,8 +3476,8 @@ var CLASS_LABEL = {
|
|
|
3403
3476
|
};
|
|
3404
3477
|
function computeGroups(diff, custom = []) {
|
|
3405
3478
|
const groups = /* @__PURE__ */ new Map();
|
|
3406
|
-
const add = (group,
|
|
3407
|
-
group.files.push(
|
|
3479
|
+
const add = (group, path13, additions, deletions) => {
|
|
3480
|
+
group.files.push(path13);
|
|
3408
3481
|
group.additions += additions;
|
|
3409
3482
|
group.deletions += deletions;
|
|
3410
3483
|
groups.set(group.id, group);
|
|
@@ -3454,15 +3527,15 @@ function parseCodeowners(text2) {
|
|
|
3454
3527
|
}
|
|
3455
3528
|
return entries;
|
|
3456
3529
|
}
|
|
3457
|
-
function matches(
|
|
3530
|
+
function matches(path13, pattern) {
|
|
3458
3531
|
const cleaned = pattern.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
3459
3532
|
if (!cleaned) return false;
|
|
3460
3533
|
if (!cleaned.includes("/")) {
|
|
3461
3534
|
const segment = cleaned.includes("*") || cleaned.includes("?") ? cleaned : cleaned.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3462
|
-
return new RegExp(`(^|/)${segment}(/|$)`).test(
|
|
3535
|
+
return new RegExp(`(^|/)${segment}(/|$)`).test(path13);
|
|
3463
3536
|
}
|
|
3464
|
-
if (globToRegExp(cleaned).test(
|
|
3465
|
-
return globToRegExp(`${cleaned}/**`).test(
|
|
3537
|
+
if (globToRegExp(cleaned).test(path13)) return true;
|
|
3538
|
+
return globToRegExp(`${cleaned}/**`).test(path13);
|
|
3466
3539
|
}
|
|
3467
3540
|
function codeownersFor(files, entries) {
|
|
3468
3541
|
const result = [];
|
|
@@ -3499,23 +3572,23 @@ function maskSecret(value) {
|
|
|
3499
3572
|
if (trimmed.length <= 8) return "***";
|
|
3500
3573
|
return `${trimmed.slice(0, 4)}\u2026${trimmed.slice(-2)}`;
|
|
3501
3574
|
}
|
|
3502
|
-
function isAllowlisted(
|
|
3575
|
+
function isAllowlisted(path13, rule, allowlist) {
|
|
3503
3576
|
return allowlist.some((entry) => {
|
|
3504
3577
|
const normalized = entry.trim();
|
|
3505
3578
|
if (!normalized) return false;
|
|
3506
3579
|
if (normalized === rule || normalized === `rule:${rule}`) return true;
|
|
3507
3580
|
if (normalized.startsWith("rule:")) return false;
|
|
3508
|
-
return globToRegExp(normalized).test(
|
|
3581
|
+
return globToRegExp(normalized).test(path13);
|
|
3509
3582
|
});
|
|
3510
3583
|
}
|
|
3511
|
-
function scanLines(
|
|
3512
|
-
if (!options.includeTests && classifyFile(
|
|
3584
|
+
function scanLines(path13, lines, options = {}) {
|
|
3585
|
+
if (!options.includeTests && classifyFile(path13) === "test") return [];
|
|
3513
3586
|
const allowlist = options.allowlist ?? [];
|
|
3514
3587
|
const findings = [];
|
|
3515
3588
|
for (const line of lines) {
|
|
3516
3589
|
let specific = false;
|
|
3517
3590
|
for (const pattern of PATTERNS) {
|
|
3518
|
-
if (isAllowlisted(
|
|
3591
|
+
if (isAllowlisted(path13, pattern.id, allowlist)) continue;
|
|
3519
3592
|
if (pattern.id === "generic-secret" && specific) continue;
|
|
3520
3593
|
pattern.regex.lastIndex = 0;
|
|
3521
3594
|
const match = pattern.regex.exec(line.text);
|
|
@@ -3524,7 +3597,7 @@ function scanLines(path12, lines, options = {}) {
|
|
|
3524
3597
|
findings.push({
|
|
3525
3598
|
rule: pattern.id,
|
|
3526
3599
|
title: pattern.title,
|
|
3527
|
-
file:
|
|
3600
|
+
file: path13,
|
|
3528
3601
|
line: line.number,
|
|
3529
3602
|
preview: maskSecret(match[0])
|
|
3530
3603
|
});
|
|
@@ -4497,7 +4570,7 @@ function parseOpenApi(text2) {
|
|
|
4497
4570
|
const info = isRecord2(document.info) ? document.info : {};
|
|
4498
4571
|
const paths = isRecord2(document.paths) ? document.paths : {};
|
|
4499
4572
|
const operations = [];
|
|
4500
|
-
for (const [
|
|
4573
|
+
for (const [path13, value] of Object.entries(paths)) {
|
|
4501
4574
|
if (!isRecord2(value)) continue;
|
|
4502
4575
|
for (const method of METHODS) {
|
|
4503
4576
|
const operation = value[method];
|
|
@@ -4508,7 +4581,7 @@ function parseOpenApi(text2) {
|
|
|
4508
4581
|
const media = isRecord2(firstMedia) ? firstMedia : {};
|
|
4509
4582
|
operations.push({
|
|
4510
4583
|
method: method.toUpperCase(),
|
|
4511
|
-
path:
|
|
4584
|
+
path: path13,
|
|
4512
4585
|
operationId: String(operation.operationId ?? ""),
|
|
4513
4586
|
summary: String(operation.summary ?? ""),
|
|
4514
4587
|
parameters: parametersOf(operation, document),
|
|
@@ -4560,9 +4633,9 @@ function renderOpenApiSummary(summary) {
|
|
|
4560
4633
|
}
|
|
4561
4634
|
return lines.join("\n");
|
|
4562
4635
|
}
|
|
4563
|
-
function openApiPathRegExp(
|
|
4564
|
-
if (
|
|
4565
|
-
const escaped =
|
|
4636
|
+
function openApiPathRegExp(path13) {
|
|
4637
|
+
if (path13 === "/") return /(?!)/;
|
|
4638
|
+
const escaped = path13.replace(/\{[^}]+\}/g, "\0").replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\u0000/g, "[^/?#\\s]+");
|
|
4566
4639
|
return new RegExp(`(?<![\\w-])${escaped}(?![\\w-])`);
|
|
4567
4640
|
}
|
|
4568
4641
|
|
|
@@ -5563,25 +5636,25 @@ ${t("\u2026 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u0444\u0438\u0447\
|
|
|
5563
5636
|
}
|
|
5564
5637
|
const side = found.status === "deleted" ? "base" : "head";
|
|
5565
5638
|
const sha = side === "head" ? info.commit.head : info.commit.base;
|
|
5566
|
-
const
|
|
5567
|
-
if (!sha || !
|
|
5639
|
+
const path13 = side === "head" ? found.path : found.oldPath || found.path;
|
|
5640
|
+
if (!sha || !path13) {
|
|
5568
5641
|
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 });
|
|
5569
5642
|
}
|
|
5570
|
-
const key = `${id}|${side}|${sha}|${
|
|
5643
|
+
const key = `${id}|${side}|${sha}|${path13}`;
|
|
5571
5644
|
const hit = this.fileContentCache.get(key);
|
|
5572
5645
|
if (hit && this.now().getTime() - hit.at < 10 * 6e4) return hit.value;
|
|
5573
5646
|
let text2;
|
|
5574
5647
|
try {
|
|
5575
5648
|
const provider = preview ? await this.providerFactory(preview.ref, preview.root) : await this.providerFor(id);
|
|
5576
5649
|
try {
|
|
5577
|
-
const result = await this.runImpl("git", ["show", `${sha}:${
|
|
5650
|
+
const result = await this.runImpl("git", ["show", `${sha}:${path13}`], {
|
|
5578
5651
|
cwd: root,
|
|
5579
5652
|
timeoutMs: 3e4,
|
|
5580
5653
|
maxBuffer: 16 * 1024 * 1024
|
|
5581
5654
|
});
|
|
5582
5655
|
text2 = result.stdout;
|
|
5583
5656
|
} catch {
|
|
5584
|
-
text2 = await provider.fileContent(
|
|
5657
|
+
text2 = await provider.fileContent(path13, sha);
|
|
5585
5658
|
}
|
|
5586
5659
|
} catch (error) {
|
|
5587
5660
|
throw Object.assign(
|
|
@@ -5597,7 +5670,7 @@ ${t("\u2026 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u0444\u0438\u0447\
|
|
|
5597
5670
|
const normalized = text2.replace(/\r\n/g, "\n");
|
|
5598
5671
|
const all = normalized === "" ? [] : (normalized.endsWith("\n") ? normalized.slice(0, -1) : normalized).split("\n");
|
|
5599
5672
|
const value = {
|
|
5600
|
-
path:
|
|
5673
|
+
path: path13,
|
|
5601
5674
|
side,
|
|
5602
5675
|
lines: all.slice(0, 2e4),
|
|
5603
5676
|
totalLines: all.length,
|
|
@@ -6443,12 +6516,13 @@ function fallbackInfo(row) {
|
|
|
6443
6516
|
|
|
6444
6517
|
// src/daemon/http.ts
|
|
6445
6518
|
init_redact();
|
|
6519
|
+
init_locale();
|
|
6446
6520
|
init_errors();
|
|
6447
6521
|
import http from "node:http";
|
|
6448
6522
|
import { createReadStream } from "node:fs";
|
|
6449
6523
|
import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
|
|
6450
6524
|
import path9 from "node:path";
|
|
6451
|
-
import { timingSafeEqual } from "node:crypto";
|
|
6525
|
+
import { randomBytes as randomBytes3, timingSafeEqual } from "node:crypto";
|
|
6452
6526
|
|
|
6453
6527
|
// src/daemon/rpc.ts
|
|
6454
6528
|
import net from "node:net";
|
|
@@ -6527,6 +6601,18 @@ async function probe(target, deps, token) {
|
|
|
6527
6601
|
return { error: redact(error?.message ?? error).replace(/\s+/g, " ").trim().slice(0, 300) };
|
|
6528
6602
|
}
|
|
6529
6603
|
}
|
|
6604
|
+
async function installHint(platform, resolve) {
|
|
6605
|
+
const bin = binaryFor(platform);
|
|
6606
|
+
const url = platform === "gitlab" ? "https://docs.gitlab.com/cli/installation/" : "https://cli.github.com/";
|
|
6607
|
+
if (await resolve("brew")) return { url, command: `brew install ${bin}` };
|
|
6608
|
+
if (process.platform === "linux" && await resolve("pacman")) {
|
|
6609
|
+
return { url, command: `sudo pacman -S ${platform === "gitlab" ? "glab" : "github-cli"}` };
|
|
6610
|
+
}
|
|
6611
|
+
if (platform === "github" && process.platform === "win32" && await resolve("winget")) {
|
|
6612
|
+
return { url, command: "winget install --id GitHub.cli" };
|
|
6613
|
+
}
|
|
6614
|
+
return { url };
|
|
6615
|
+
}
|
|
6530
6616
|
async function authStatus(target, deps = {}) {
|
|
6531
6617
|
const bin = binaryFor(target.platform);
|
|
6532
6618
|
const resolve = deps.resolve ?? resolveExecutable;
|
|
@@ -6535,9 +6621,10 @@ async function authStatus(target, deps = {}) {
|
|
|
6535
6621
|
return {
|
|
6536
6622
|
...base,
|
|
6537
6623
|
hint: tr(
|
|
6538
|
-
`${bin} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 PATH \u0434\u0435\u043C\u043E\u043D\u0430: \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0435\u0433\u043E \u0438\u043B\u0438 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 REVDECK_${bin.toUpperCase()}`,
|
|
6539
|
-
`${bin} is not in the daemon PATH: install it or set REVDECK_${bin.toUpperCase()}`
|
|
6540
|
-
)
|
|
6624
|
+
`${bin} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 PATH \u0434\u0435\u043C\u043E\u043D\u0430: \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0435\u0433\u043E \u043D\u0430 \u0445\u043E\u0441\u0442\u0435 \u0438 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435 \u0434\u0435\u043C\u043E\u043D \u0438\u043B\u0438 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 REVDECK_${bin.toUpperCase()}`,
|
|
6625
|
+
`${bin} is not in the daemon PATH: install it on the host and restart the daemon, or set REVDECK_${bin.toUpperCase()}`
|
|
6626
|
+
),
|
|
6627
|
+
install: await installHint(target.platform, resolve)
|
|
6541
6628
|
};
|
|
6542
6629
|
}
|
|
6543
6630
|
const result = await probe(target, deps);
|
|
@@ -7065,6 +7152,11 @@ var SECURITY_HEADERS = {
|
|
|
7065
7152
|
"referrer-policy": "no-referrer",
|
|
7066
7153
|
"content-security-policy": "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: http: https:; media-src 'self' http: https:; font-src 'self'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
|
|
7067
7154
|
};
|
|
7155
|
+
function hostAuthority(host) {
|
|
7156
|
+
if (host === "0.0.0.0") return "127.0.0.1";
|
|
7157
|
+
if (host === "::") return "[::1]";
|
|
7158
|
+
return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
7159
|
+
}
|
|
7068
7160
|
var COOKIE = "revdeck_session";
|
|
7069
7161
|
function safeEqual(left, right) {
|
|
7070
7162
|
const a = Buffer.from(left);
|
|
@@ -7102,12 +7194,208 @@ function reply(res, status, data) {
|
|
|
7102
7194
|
});
|
|
7103
7195
|
res.end(body);
|
|
7104
7196
|
}
|
|
7197
|
+
function escapeHtml(value) {
|
|
7198
|
+
return value.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[char]);
|
|
7199
|
+
}
|
|
7200
|
+
function pageLocale(header) {
|
|
7201
|
+
const first = String(header ?? "").split(",")[0]?.trim().toLowerCase() ?? "";
|
|
7202
|
+
if (first.startsWith("ru")) return "ru";
|
|
7203
|
+
if (first.startsWith("en")) return "en";
|
|
7204
|
+
return locale();
|
|
7205
|
+
}
|
|
7206
|
+
function launchPage(options) {
|
|
7207
|
+
const text2 = (ru, en) => options.locale === "ru" ? ru : en;
|
|
7208
|
+
const title = options.stale ? text2("\u0421\u0435\u0441\u0441\u0438\u044F \u0434\u0435\u043C\u043E\u043D\u0430 \u0443\u0441\u0442\u0430\u0440\u0435\u043B\u0430", "The daemon session expired") : text2("\u041D\u0443\u0436\u043D\u0430 \u0441\u0441\u044B\u043B\u043A\u0430 \u0437\u0430\u043F\u0443\u0441\u043A\u0430", "A launch link is required");
|
|
7209
|
+
const lead = options.stale ? text2(
|
|
7210
|
+
"\u0414\u0435\u043C\u043E\u043D \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430\u043B\u0441\u044F \u0438 \u0441\u043C\u0435\u043D\u0438\u043B launch-\u0442\u043E\u043A\u0435\u043D \u0438 \u043F\u043E\u0440\u0442. Cookie-\u0441\u0435\u0441\u0441\u0438\u044F \u044D\u0442\u043E\u0433\u043E \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0431\u043E\u043B\u044C\u0448\u0435 \u043D\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442.",
|
|
7211
|
+
"The daemon restarted and rotated its launch token and port. This browser\u2019s cookie session is no longer valid."
|
|
7212
|
+
) : text2(
|
|
7213
|
+
"\u0418\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043E\u0442\u043A\u0440\u044B\u0432\u0430\u0435\u0442\u0441\u044F \u043F\u043E \u043E\u0434\u043D\u043E\u0440\u0430\u0437\u043E\u0432\u043E\u0439 \u0441\u0441\u044B\u043B\u043A\u0435 \u0438\u0437 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0430: \u043E\u043D\u0430 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u0443\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438 \u043D\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043F\u0430\u0440\u043E\u043B\u044F.",
|
|
7214
|
+
"The interface opens from a one-time link in your terminal: it authorizes this browser and needs no password."
|
|
7215
|
+
);
|
|
7216
|
+
const command = "revdeck daemon start && revdeck ui --open";
|
|
7217
|
+
const labels = {
|
|
7218
|
+
copy: text2("\u041A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C", "Copy"),
|
|
7219
|
+
copied: text2("\u0421\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u043E", "Copied"),
|
|
7220
|
+
checking: text2("\u041F\u0440\u043E\u0432\u0435\u0440\u044F\u0435\u043C \u0434\u043E\u0441\u0442\u0443\u043F\u2026", "Checking access\u2026"),
|
|
7221
|
+
waiting: text2("\u041D\u0443\u0436\u043D\u0430 \u043D\u043E\u0432\u0430\u044F \u0441\u0441\u044B\u043B\u043A\u0430", "A new link is required"),
|
|
7222
|
+
ok: text2("\u0414\u043E\u0441\u0442\u0443\u043F \u0432\u043E\u0441\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D, \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0435\u043C\u2026", "Access restored, reloading\u2026"),
|
|
7223
|
+
offline: text2("\u0414\u0435\u043C\u043E\u043D \u043D\u0435 \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442", "The daemon is not responding")
|
|
7224
|
+
};
|
|
7225
|
+
const version = options.version ? `<span>revdeck ${escapeHtml(options.version)}</span>` : "<span>revdeck</span>";
|
|
7226
|
+
return `<!doctype html>
|
|
7227
|
+
<html lang="${options.locale}">
|
|
7228
|
+
<head>
|
|
7229
|
+
<meta charset="utf-8">
|
|
7230
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
7231
|
+
<meta name="referrer" content="no-referrer">
|
|
7232
|
+
<meta name="color-scheme" content="light dark">
|
|
7233
|
+
<title>revdeck \u2014 ${escapeHtml(title)}</title>
|
|
7234
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
7235
|
+
<style>
|
|
7236
|
+
:root {
|
|
7237
|
+
color-scheme: light dark;
|
|
7238
|
+
--bg: #f6f7f9; --panel: #ffffff; --border: #dfe3e8; --text: #16191d; --muted: #68707a;
|
|
7239
|
+
--accent: #3b6ef5; --accent-soft: #e6edff; --code: #f1f3f6; --ok: #1f8f4e; --warn: #b26a00; --danger: #c93838;
|
|
7240
|
+
--mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
|
|
7241
|
+
--sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', sans-serif;
|
|
7242
|
+
}
|
|
7243
|
+
@media (prefers-color-scheme: dark) {
|
|
7244
|
+
:root {
|
|
7245
|
+
--bg: #101216; --panel: #171a20; --border: #2a2f38; --text: #e6e9ee; --muted: #98a1ad;
|
|
7246
|
+
--accent: #6f95ff; --accent-soft: #1e2a4d; --code: #1f242c; --ok: #4cc27d; --warn: #e0a33a; --danger: #f07a7a;
|
|
7247
|
+
}
|
|
7248
|
+
}
|
|
7249
|
+
* { box-sizing: border-box; }
|
|
7250
|
+
body {
|
|
7251
|
+
margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 26px;
|
|
7252
|
+
background:
|
|
7253
|
+
radial-gradient(900px 520px at 12% -12%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 62%),
|
|
7254
|
+
radial-gradient(760px 460px at 112% 112%, color-mix(in srgb, #7c5cff 13%, transparent), transparent 60%),
|
|
7255
|
+
var(--bg);
|
|
7256
|
+
color: var(--text); font: 14px/1.55 var(--sans);
|
|
7257
|
+
}
|
|
7258
|
+
.card {
|
|
7259
|
+
width: 100%; max-width: 574px; background: var(--panel); border: 1px solid var(--border);
|
|
7260
|
+
border-radius: 18px; padding: 26px 30px 22px;
|
|
7261
|
+
box-shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 18px 50px rgb(16 24 40 / 10%);
|
|
7262
|
+
}
|
|
7263
|
+
.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
|
|
7264
|
+
.brand img { width: 24px; height: 24px; }
|
|
7265
|
+
.chip {
|
|
7266
|
+
margin-left: auto; padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px;
|
|
7267
|
+
color: var(--muted); font-size: 10.5px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase;
|
|
7268
|
+
}
|
|
7269
|
+
h1 { margin: 28px 0 10px; font-size: 25px; line-height: 1.2; letter-spacing: -0.025em; }
|
|
7270
|
+
.lead { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
|
|
7271
|
+
.command {
|
|
7272
|
+
display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px;
|
|
7273
|
+
background: var(--code); border: 1px solid var(--border); border-radius: 10px;
|
|
7274
|
+
}
|
|
7275
|
+
.command code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font: 12.5px/1.5 var(--mono); }
|
|
7276
|
+
.command button, .reload {
|
|
7277
|
+
border: 1px solid var(--border); background: var(--panel); color: var(--text);
|
|
7278
|
+
border-radius: 7px; padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 600;
|
|
7279
|
+
white-space: nowrap; cursor: pointer;
|
|
7280
|
+
}
|
|
7281
|
+
.command button:hover, .reload:hover { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
|
|
7282
|
+
.command button:focus, .reload:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
7283
|
+
.command button.copied { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
|
|
7284
|
+
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }
|
|
7285
|
+
.status {
|
|
7286
|
+
display: flex; align-items: center; gap: 8px; margin-top: 22px; padding-top: 15px;
|
|
7287
|
+
border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px;
|
|
7288
|
+
}
|
|
7289
|
+
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
|
|
7290
|
+
.status[data-state="checking"] .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
|
|
7291
|
+
.status[data-state="waiting"] .dot { background: var(--warn); }
|
|
7292
|
+
.status[data-state="ok"] .dot { background: var(--ok); }
|
|
7293
|
+
.status[data-state="offline"] .dot { background: var(--danger); }
|
|
7294
|
+
@keyframes pulse { 50% { opacity: 0.3; } }
|
|
7295
|
+
.actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
|
|
7296
|
+
.actions .hint { margin: 0; }
|
|
7297
|
+
.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 18px; color: var(--muted); font-size: 11.5px; }
|
|
7298
|
+
.origin { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
7299
|
+
@media (max-width: 480px) { .card { padding: 22px 20px 18px; } h1 { font-size: 22px; } .actions { flex-wrap: wrap; } }
|
|
7300
|
+
</style>
|
|
7301
|
+
</head>
|
|
7302
|
+
<body>
|
|
7303
|
+
<main class="card">
|
|
7304
|
+
<div class="brand"><img src="/favicon.svg" alt="">revdeck<span class="chip">${text2("\u043B\u043E\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u0434\u0435\u043C\u043E\u043D", "local daemon")}</span></div>
|
|
7305
|
+
<h1>${escapeHtml(title)}</h1>
|
|
7306
|
+
<p class="lead">${escapeHtml(lead)}</p>
|
|
7307
|
+
<div class="command">
|
|
7308
|
+
<code>${escapeHtml(command)}</code>
|
|
7309
|
+
<button id="copy" type="button">${escapeHtml(labels.copy)}</button>
|
|
7310
|
+
</div>
|
|
7311
|
+
<p class="hint">${text2(
|
|
7312
|
+
"\u041A\u043E\u043C\u0430\u043D\u0434\u0430 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442 \u0434\u0435\u043C\u043E\u043D, \u0435\u0441\u043B\u0438 \u043E\u043D \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D, \u0438 \u043E\u0442\u043A\u0440\u043E\u0435\u0442 \u0441\u0432\u0435\u0436\u0443\u044E \u0441\u0441\u044B\u043B\u043A\u0443. \u0414\u0430\u043D\u043D\u044B\u0435 \u043E\u0441\u0442\u0430\u044E\u0442\u0441\u044F \u043D\u0430 \u044D\u0442\u043E\u043C \u0445\u043E\u0441\u0442\u0435.",
|
|
7313
|
+
"The command starts the daemon if needed and opens a fresh link. Everything stays on this host."
|
|
7314
|
+
)}</p>
|
|
7315
|
+
<div class="status" id="status" data-state="checking" role="status" aria-live="polite">
|
|
7316
|
+
<span class="dot" aria-hidden="true"></span><span id="status-text">${escapeHtml(labels.checking)}</span>
|
|
7317
|
+
</div>
|
|
7318
|
+
<div class="actions">
|
|
7319
|
+
<button class="reload" id="reload" type="button">${text2("\u041F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u0441\u043D\u043E\u0432\u0430", "Check again")}</button>
|
|
7320
|
+
<span class="hint">${text2(
|
|
7321
|
+
"\u0412\u043A\u043B\u0430\u0434\u043A\u0430 \u043F\u0435\u0440\u0435\u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0438\u0442\u0441\u044F \u0441\u0430\u043C\u0430, \u043A\u043E\u0433\u0434\u0430 \u043F\u043E\u044F\u0432\u0438\u0442\u0441\u044F \u0434\u043E\u0441\u0442\u0443\u043F.",
|
|
7322
|
+
"This tab reconnects by itself once access is restored."
|
|
7323
|
+
)}</span>
|
|
7324
|
+
</div>
|
|
7325
|
+
<div class="foot">${version}<span class="origin" id="origin"></span></div>
|
|
7326
|
+
</main>
|
|
7327
|
+
<script nonce="${options.nonce}">
|
|
7328
|
+
(function () {
|
|
7329
|
+
var command = ${JSON.stringify(command)};
|
|
7330
|
+
var labels = ${JSON.stringify(labels)};
|
|
7331
|
+
var copyButton = document.getElementById('copy');
|
|
7332
|
+
var reloadButton = document.getElementById('reload');
|
|
7333
|
+
var status = document.getElementById('status');
|
|
7334
|
+
var statusText = document.getElementById('status-text');
|
|
7335
|
+
var origin = document.getElementById('origin');
|
|
7336
|
+
if (origin) origin.textContent = location.origin;
|
|
7337
|
+
copyButton.addEventListener('click', function () {
|
|
7338
|
+
function done() {
|
|
7339
|
+
copyButton.textContent = labels.copied;
|
|
7340
|
+
copyButton.classList.add('copied');
|
|
7341
|
+
setTimeout(function () {
|
|
7342
|
+
copyButton.textContent = labels.copy;
|
|
7343
|
+
copyButton.classList.remove('copied');
|
|
7344
|
+
}, 1800);
|
|
7345
|
+
}
|
|
7346
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
7347
|
+
navigator.clipboard.writeText(command).then(done, function () { fallback(); done(); });
|
|
7348
|
+
return;
|
|
7349
|
+
}
|
|
7350
|
+
fallback();
|
|
7351
|
+
done();
|
|
7352
|
+
function fallback() {
|
|
7353
|
+
var area = document.createElement('textarea');
|
|
7354
|
+
area.value = command;
|
|
7355
|
+
area.setAttribute('readonly', '');
|
|
7356
|
+
area.style.position = 'fixed';
|
|
7357
|
+
area.style.opacity = '0';
|
|
7358
|
+
document.body.appendChild(area);
|
|
7359
|
+
area.select();
|
|
7360
|
+
try { document.execCommand('copy'); } catch (error) {}
|
|
7361
|
+
area.remove();
|
|
7362
|
+
}
|
|
7363
|
+
});
|
|
7364
|
+
reloadButton.addEventListener('click', function () { location.reload(); });
|
|
7365
|
+
var checking = false;
|
|
7366
|
+
function probe() {
|
|
7367
|
+
if (checking) return;
|
|
7368
|
+
checking = true;
|
|
7369
|
+
fetch('/api/health', { credentials: 'same-origin', cache: 'no-store' }).then(function (response) {
|
|
7370
|
+
checking = false;
|
|
7371
|
+
if (response.ok) {
|
|
7372
|
+
status.dataset.state = 'ok';
|
|
7373
|
+
statusText.textContent = labels.ok;
|
|
7374
|
+
setTimeout(function () { location.reload(); }, 250);
|
|
7375
|
+
return;
|
|
7376
|
+
}
|
|
7377
|
+
status.dataset.state = 'waiting';
|
|
7378
|
+
statusText.textContent = labels.waiting;
|
|
7379
|
+
}, function () {
|
|
7380
|
+
checking = false;
|
|
7381
|
+
status.dataset.state = 'offline';
|
|
7382
|
+
statusText.textContent = labels.offline;
|
|
7383
|
+
});
|
|
7384
|
+
}
|
|
7385
|
+
setTimeout(probe, 1500);
|
|
7386
|
+
setInterval(probe, 5000);
|
|
7387
|
+
})();
|
|
7388
|
+
</script>
|
|
7389
|
+
</body>
|
|
7390
|
+
</html>`;
|
|
7391
|
+
}
|
|
7105
7392
|
async function startHttpServer(options) {
|
|
7106
7393
|
const { service, token } = options;
|
|
7107
7394
|
const host = options.host ?? "127.0.0.1";
|
|
7108
7395
|
const server = http.createServer(async (req, res) => {
|
|
7109
7396
|
const port2 = server.address()?.port ?? 0;
|
|
7110
7397
|
const expectedHosts = /* @__PURE__ */ new Set([`127.0.0.1:${port2}`, `localhost:${port2}`, `[::1]:${port2}`]);
|
|
7398
|
+
if (host !== "0.0.0.0" && host !== "::") expectedHosts.add(`${hostAuthority(host).toLowerCase()}:${port2}`);
|
|
7111
7399
|
for (const name of options.allowedHosts ?? []) expectedHosts.add(`${name}:${port2}`);
|
|
7112
7400
|
expectedHosts.add(`host.docker.internal:${port2}`);
|
|
7113
7401
|
if (!expectedHosts.has(String(req.headers.host ?? ""))) {
|
|
@@ -7140,7 +7428,7 @@ async function startHttpServer(options) {
|
|
|
7140
7428
|
if (req.method === "GET" && url.pathname === "/") {
|
|
7141
7429
|
const provided = url.searchParams.get("t");
|
|
7142
7430
|
if (provided && safeEqual(provided, token)) {
|
|
7143
|
-
const next = new URL(
|
|
7431
|
+
const next = new URL(url.href);
|
|
7144
7432
|
next.searchParams.delete("t");
|
|
7145
7433
|
res.writeHead(302, {
|
|
7146
7434
|
...SECURITY_HEADERS,
|
|
@@ -7151,8 +7439,14 @@ async function startHttpServer(options) {
|
|
|
7151
7439
|
return;
|
|
7152
7440
|
}
|
|
7153
7441
|
if (!authorized) {
|
|
7154
|
-
|
|
7155
|
-
res.
|
|
7442
|
+
const nonce = randomBytes3(16).toString("base64");
|
|
7443
|
+
res.writeHead(401, {
|
|
7444
|
+
...SECURITY_HEADERS,
|
|
7445
|
+
"content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; script-src 'nonce-${nonce}'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
|
|
7446
|
+
"content-type": "text/html; charset=utf-8",
|
|
7447
|
+
"cache-control": "no-store"
|
|
7448
|
+
});
|
|
7449
|
+
res.end(launchPage({ stale: presented !== "", nonce, version: options.version, locale: pageLocale(req.headers["accept-language"]) }));
|
|
7156
7450
|
return;
|
|
7157
7451
|
}
|
|
7158
7452
|
const html = await readFile2(path9.join(options.uiDir, "index.html"));
|
|
@@ -7547,7 +7841,7 @@ data: ${JSON.stringify(event)}
|
|
|
7547
7841
|
});
|
|
7548
7842
|
const port = server.address().port;
|
|
7549
7843
|
return {
|
|
7550
|
-
url: `http
|
|
7844
|
+
url: `http://${hostAuthority(host)}:${port}`,
|
|
7551
7845
|
port,
|
|
7552
7846
|
close: () => new Promise((resolve) => {
|
|
7553
7847
|
server.close(() => resolve());
|
|
@@ -7556,11 +7850,31 @@ data: ${JSON.stringify(event)}
|
|
|
7556
7850
|
};
|
|
7557
7851
|
}
|
|
7558
7852
|
|
|
7853
|
+
// src/daemon/port.ts
|
|
7854
|
+
import path10 from "node:path";
|
|
7855
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
7856
|
+
function portHintPath(state = stateDir()) {
|
|
7857
|
+
return path10.join(state, "daemon.port");
|
|
7858
|
+
}
|
|
7859
|
+
async function readPortHint(file = portHintPath()) {
|
|
7860
|
+
try {
|
|
7861
|
+
const value = Number((await readFile3(file, "utf8")).trim());
|
|
7862
|
+
return Number.isInteger(value) && value > 0 && value < 65536 ? value : null;
|
|
7863
|
+
} catch {
|
|
7864
|
+
return null;
|
|
7865
|
+
}
|
|
7866
|
+
}
|
|
7867
|
+
async function writePortHint(port, file = portHintPath()) {
|
|
7868
|
+
if (!Number.isInteger(port) || port <= 0 || port >= 65536) return;
|
|
7869
|
+
await writeFileAtomic(file, `${port}
|
|
7870
|
+
`, 384);
|
|
7871
|
+
}
|
|
7872
|
+
|
|
7559
7873
|
// src/daemon/bridge.ts
|
|
7560
7874
|
import { unlink as unlink3 } from "node:fs/promises";
|
|
7561
|
-
import
|
|
7875
|
+
import path11 from "node:path";
|
|
7562
7876
|
async function startDevcontainerBridge(service, info) {
|
|
7563
|
-
await ensureDir(
|
|
7877
|
+
await ensureDir(path11.dirname(devcontainerBridgeDir()), 448);
|
|
7564
7878
|
await ensureDir(devcontainerBridgeDir(), 448);
|
|
7565
7879
|
await ensureDir(devcontainerRunDir(), 493);
|
|
7566
7880
|
await ensureDir(devcontainerStateDir(), 493);
|
|
@@ -7613,26 +7927,39 @@ async function main() {
|
|
|
7613
7927
|
if (values["state-dir"]) process.env.REVDECK_STATE_DIR = values["state-dir"];
|
|
7614
7928
|
if (values["runtime-dir"]) process.env.REVDECK_RUNTIME_DIR = values["runtime-dir"];
|
|
7615
7929
|
const foreground = values.foreground === true;
|
|
7930
|
+
const file = logPath();
|
|
7931
|
+
const maxLogBytes = 1024 * 1024;
|
|
7932
|
+
let logSize = null;
|
|
7616
7933
|
const log = async (line) => {
|
|
7617
7934
|
const message = `${(/* @__PURE__ */ new Date()).toISOString()} ${redactLine(line, 4e3)}
|
|
7618
7935
|
`;
|
|
7619
7936
|
if (foreground) process.stderr.write(message);
|
|
7620
7937
|
try {
|
|
7621
|
-
|
|
7938
|
+
const bytes = Buffer.byteLength(message);
|
|
7939
|
+
logSize ??= (await stat3(file).catch(() => null))?.size ?? 0;
|
|
7940
|
+
if (logSize + bytes > maxLogBytes) {
|
|
7941
|
+
await rename2(file, `${file}.1`).catch(() => void 0);
|
|
7942
|
+
logSize = 0;
|
|
7943
|
+
}
|
|
7944
|
+
await appendFile(file, message, { mode: 384 });
|
|
7945
|
+
logSize += bytes;
|
|
7622
7946
|
} catch {
|
|
7623
7947
|
}
|
|
7624
7948
|
};
|
|
7625
7949
|
const existing = await runningDaemon();
|
|
7626
7950
|
if (existing) {
|
|
7627
|
-
process.stdout.write(
|
|
7628
|
-
`)
|
|
7951
|
+
process.stdout.write(
|
|
7952
|
+
` ${colors.green("\u25CF")} ${tr("\u0414\u0435\u043C\u043E\u043D \u0443\u0436\u0435 \u0437\u0430\u043F\u0443\u0449\u0435\u043D", "Daemon is already running")} ${colors.dim(`\xB7 pid ${existing.pid}`)}
|
|
7953
|
+
${colors.dim("revdeck ui --open")}
|
|
7954
|
+
`
|
|
7955
|
+
);
|
|
7629
7956
|
return;
|
|
7630
7957
|
}
|
|
7631
7958
|
await ensureDir(stateDir(), 448);
|
|
7632
7959
|
await ensureDir(runtimeDir(), 448);
|
|
7633
7960
|
const lock = await acquireLock();
|
|
7634
7961
|
if (!lock) {
|
|
7635
|
-
process.stdout.write(`
|
|
7962
|
+
process.stdout.write(` ${colors.dim("\u25CB")} ${tr("\u0414\u0435\u043C\u043E\u043D \u0443\u0436\u0435 \u0437\u0430\u043F\u0443\u0441\u043A\u0430\u0435\u0442\u0441\u044F \u0438\u043B\u0438 \u0437\u0430\u043F\u0443\u0449\u0435\u043D", "Daemon is already starting or running")}
|
|
7636
7963
|
`);
|
|
7637
7964
|
return;
|
|
7638
7965
|
}
|
|
@@ -7645,17 +7972,40 @@ async function main() {
|
|
|
7645
7972
|
});
|
|
7646
7973
|
const socket = socketPath();
|
|
7647
7974
|
const rpc = await startRpcServer(service, socket);
|
|
7648
|
-
const uiDir = values["ui-dir"] ?
|
|
7649
|
-
const
|
|
7975
|
+
const uiDir = values["ui-dir"] ? path12.resolve(values["ui-dir"]) : path12.join(packageRoot(), "dist", "ui");
|
|
7976
|
+
const requestedPort = parsePort(values.port);
|
|
7977
|
+
const preferredPort = requestedPort ?? await readPortHint();
|
|
7978
|
+
const listen = (port) => startHttpServer({
|
|
7650
7979
|
service,
|
|
7651
7980
|
token,
|
|
7652
7981
|
agentToken,
|
|
7653
7982
|
uiDir,
|
|
7654
|
-
...
|
|
7983
|
+
...port ? { port } : {},
|
|
7655
7984
|
...values.host ? { host: String(values.host) } : {},
|
|
7656
7985
|
...process.env.REVDECK_HTTP_ALLOWED_HOSTS ? { allowedHosts: process.env.REVDECK_HTTP_ALLOWED_HOSTS.split(",").map((item) => item.trim()).filter(Boolean) } : {},
|
|
7657
7986
|
version: VERSION
|
|
7658
7987
|
});
|
|
7988
|
+
let http2;
|
|
7989
|
+
try {
|
|
7990
|
+
http2 = await listen(preferredPort ?? void 0);
|
|
7991
|
+
} catch (error) {
|
|
7992
|
+
const code = error.code;
|
|
7993
|
+
if (requestedPort) {
|
|
7994
|
+
if (code === "EADDRINUSE" || code === "EACCES") {
|
|
7995
|
+
throw new Error(
|
|
7996
|
+
tr(
|
|
7997
|
+
`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043D\u044F\u0442\u044C \u043F\u043E\u0440\u0442 ${requestedPort}: ${code === "EADDRINUSE" ? "\u043E\u043D \u0437\u0430\u043D\u044F\u0442" : "\u043D\u0435\u0442 \u043F\u0440\u0430\u0432"}; \u0432\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0434\u0440\u0443\u0433\u043E\u0439 --port`,
|
|
7998
|
+
`cannot bind port ${requestedPort}: ${code === "EADDRINUSE" ? "already in use" : "permission denied"}; choose another --port`
|
|
7999
|
+
)
|
|
8000
|
+
);
|
|
8001
|
+
}
|
|
8002
|
+
throw error;
|
|
8003
|
+
}
|
|
8004
|
+
if (code !== "EADDRINUSE" && code !== "EACCES") throw error;
|
|
8005
|
+
await log(`port ${preferredPort} is busy, falling back to a random port`);
|
|
8006
|
+
http2 = await listen();
|
|
8007
|
+
}
|
|
8008
|
+
await writePortHint(http2.port).catch((error) => log(`cannot remember port: ${redactLine(error instanceof Error ? error.message : error)}`));
|
|
7659
8009
|
const info = {
|
|
7660
8010
|
pid: process.pid,
|
|
7661
8011
|
port: http2.port,
|
|
@@ -7677,13 +8027,18 @@ async function main() {
|
|
|
7677
8027
|
}
|
|
7678
8028
|
service.startSync();
|
|
7679
8029
|
process.stdout.write(
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
8030
|
+
`${daemonStartedLines(
|
|
8031
|
+
{
|
|
8032
|
+
version: VERSION,
|
|
8033
|
+
pid: process.pid,
|
|
8034
|
+
url: `${http2.url}/?t=${token}`,
|
|
8035
|
+
socket,
|
|
8036
|
+
stateDir: stateDir(),
|
|
8037
|
+
logPath: logPath()
|
|
8038
|
+
},
|
|
8039
|
+
"started"
|
|
8040
|
+
).join("\n")}
|
|
8041
|
+
`
|
|
7687
8042
|
);
|
|
7688
8043
|
await log(`daemon started pid=${process.pid} port=${http2.port}`);
|
|
7689
8044
|
let closing = false;
|
|
@@ -7699,7 +8054,7 @@ async function main() {
|
|
|
7699
8054
|
service.close();
|
|
7700
8055
|
await unlink4(daemonInfoPath()).catch(() => void 0);
|
|
7701
8056
|
await lock.close().catch(() => void 0);
|
|
7702
|
-
await unlink4(
|
|
8057
|
+
await unlink4(path12.join(stateDir(), "daemon.lock")).catch(() => void 0);
|
|
7703
8058
|
process.exit(0);
|
|
7704
8059
|
}
|
|
7705
8060
|
};
|
|
@@ -7710,10 +8065,18 @@ async function main() {
|
|
|
7710
8065
|
});
|
|
7711
8066
|
}
|
|
7712
8067
|
}
|
|
8068
|
+
function parsePort(value) {
|
|
8069
|
+
if (value === void 0) return null;
|
|
8070
|
+
const port = Number(value);
|
|
8071
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
8072
|
+
throw new Error(tr(`\u043D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u043F\u043E\u0440\u0442 ${value}: \u043D\u0443\u0436\u043D\u043E 1\u201365535`, `invalid port ${value}: expected 1\u201365535`));
|
|
8073
|
+
}
|
|
8074
|
+
return port;
|
|
8075
|
+
}
|
|
7713
8076
|
function packageRoot() {
|
|
7714
|
-
let dir =
|
|
8077
|
+
let dir = path12.dirname(fileURLToPath(import.meta.url));
|
|
7715
8078
|
for (; ; ) {
|
|
7716
|
-
const candidate =
|
|
8079
|
+
const candidate = path12.join(dir, "package.json");
|
|
7717
8080
|
if (existsSync5(candidate)) {
|
|
7718
8081
|
try {
|
|
7719
8082
|
const parsed = JSON.parse(readFileSync(candidate, "utf8"));
|
|
@@ -7721,7 +8084,7 @@ function packageRoot() {
|
|
|
7721
8084
|
} catch {
|
|
7722
8085
|
}
|
|
7723
8086
|
}
|
|
7724
|
-
const parent =
|
|
8087
|
+
const parent = path12.dirname(dir);
|
|
7725
8088
|
if (parent === dir) return process.cwd();
|
|
7726
8089
|
dir = parent;
|
|
7727
8090
|
}
|
|
@@ -7760,7 +8123,7 @@ async function runningDaemon() {
|
|
|
7760
8123
|
return reachable ? info : null;
|
|
7761
8124
|
}
|
|
7762
8125
|
async function acquireLock() {
|
|
7763
|
-
const file =
|
|
8126
|
+
const file = path12.join(stateDir(), "daemon.lock");
|
|
7764
8127
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
7765
8128
|
try {
|
|
7766
8129
|
const handle = await open2(file, "wx", 384);
|
|
@@ -7768,7 +8131,7 @@ async function acquireLock() {
|
|
|
7768
8131
|
return handle;
|
|
7769
8132
|
} catch (error) {
|
|
7770
8133
|
if (error.code !== "EEXIST") throw error;
|
|
7771
|
-
const pid = Number(await
|
|
8134
|
+
const pid = Number(await readFile4(file, "utf8").catch(() => ""));
|
|
7772
8135
|
if (pid) {
|
|
7773
8136
|
try {
|
|
7774
8137
|
process.kill(pid, 0);
|
|
@@ -7781,8 +8144,13 @@ async function acquireLock() {
|
|
|
7781
8144
|
}
|
|
7782
8145
|
return null;
|
|
7783
8146
|
}
|
|
8147
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
8148
|
+
stream.on("error", (error) => {
|
|
8149
|
+
if (error.code === "EPIPE") process.exit(0);
|
|
8150
|
+
});
|
|
8151
|
+
}
|
|
7784
8152
|
void main().catch((error) => {
|
|
7785
|
-
|
|
8153
|
+
for (const line of errorLine(redactLine(error instanceof Error ? error.message : error))) process.stderr.write(`${line}
|
|
7786
8154
|
`);
|
|
7787
8155
|
process.exit(1);
|
|
7788
8156
|
});
|