revdeck 0.3.3 → 0.4.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/dist/daemon.js CHANGED
@@ -710,8 +710,7 @@ rename to ${newPath}
710
710
  await this.call(["--method", "PUT", this.endpoint(`/discussions/${encodeURIComponent(threadId)}`), "--input", file]);
711
711
  });
712
712
  }
713
- async reactions(noteId) {
714
- const base = this.endpoint(`/notes/${encodeURIComponent(noteId)}/award_emoji`);
713
+ async fetchAwards(base) {
715
714
  const items = await this.paged(base);
716
715
  const me = await this.currentUser();
717
716
  const grouped = /* @__PURE__ */ new Map();
@@ -728,8 +727,7 @@ rename to ${newPath}
728
727
  }
729
728
  return [...grouped.values()].sort((left, right) => left.name.localeCompare(right.name));
730
729
  }
731
- async react(noteId, emoji) {
732
- const base = this.endpoint(`/notes/${encodeURIComponent(noteId)}/award_emoji`);
730
+ async toggleAward(base, emoji) {
733
731
  const existing = await this.json([query(base, { per_page: 100 })]);
734
732
  const me = await this.currentUser();
735
733
  const mine = existing.find((item) => item.name === emoji && item.user?.username === me.username);
@@ -742,6 +740,26 @@ rename to ${newPath}
742
740
  });
743
741
  return { active: true };
744
742
  }
743
+ async reactions(noteId) {
744
+ return this.fetchAwards(this.endpoint(`/notes/${encodeURIComponent(noteId)}/award_emoji`));
745
+ }
746
+ async react(noteId, emoji) {
747
+ return this.toggleAward(this.endpoint(`/notes/${encodeURIComponent(noteId)}/award_emoji`), emoji);
748
+ }
749
+ async reviewReactions() {
750
+ return this.fetchAwards(this.endpoint("/award_emoji"));
751
+ }
752
+ async reactToReview(emoji) {
753
+ return this.toggleAward(this.endpoint("/award_emoji"), emoji);
754
+ }
755
+ async updateNote(noteId, body) {
756
+ await withTempJson({ body }, async (file) => {
757
+ await this.call(["--method", "PUT", this.endpoint(`/notes/${encodeURIComponent(noteId)}`), "--input", file]);
758
+ });
759
+ }
760
+ async deleteNote(noteId) {
761
+ await this.call(["--method", "DELETE", this.endpoint(`/notes/${encodeURIComponent(noteId)}`)]);
762
+ }
745
763
  async upload(input) {
746
764
  const endpoint = `projects/${this.projectRef}/uploads`;
747
765
  const uploaded = await this.json(["--method", "POST", endpoint, "--form", `file=@${input.path}`]);
@@ -1042,8 +1060,7 @@ rename to ${newPath}
1042
1060
  const mutation = resolved ? "mutation($id: ID!) { resolveReviewThread(input: { threadId: $id }) { thread { isResolved } } }" : "mutation($id: ID!) { unresolveReviewThread(input: { threadId: $id }) { thread { isResolved } } }";
1043
1061
  await this.graphql(mutation, { id: threadId });
1044
1062
  }
1045
- async reactions(noteId) {
1046
- const base = `repos/${this.repo}/pulls/comments/${encodeURIComponent(noteId)}/reactions`;
1063
+ async fetchReactions(base) {
1047
1064
  const items = await this.paged(base);
1048
1065
  const me = await this.currentUser();
1049
1066
  const grouped = /* @__PURE__ */ new Map();
@@ -1061,10 +1078,9 @@ rename to ${newPath}
1061
1078
  }
1062
1079
  return [...grouped.values()].sort((left, right) => left.name.localeCompare(right.name));
1063
1080
  }
1064
- async react(noteId, emoji) {
1081
+ async toggleReaction(base, emoji) {
1065
1082
  const content = REACTIONS2[emoji];
1066
1083
  if (!content) throw new ProviderError(tr(`GitHub \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0435\u0430\u043A\u0446\u0438\u044E ${emoji}`, `GitHub does not support reaction ${emoji}`));
1067
- const base = `repos/${this.repo}/pulls/comments/${noteId}/reactions`;
1068
1084
  const existing = await this.json([query(base, { per_page: 100 })]);
1069
1085
  const me = await this.currentUser();
1070
1086
  const mine = existing.find((item) => item.content === content && item.user?.login === me.username);
@@ -1077,6 +1093,26 @@ rename to ${newPath}
1077
1093
  });
1078
1094
  return { active: true };
1079
1095
  }
1096
+ async reactions(noteId) {
1097
+ return this.fetchReactions(`repos/${this.repo}/pulls/comments/${encodeURIComponent(noteId)}/reactions`);
1098
+ }
1099
+ async react(noteId, emoji) {
1100
+ return this.toggleReaction(`repos/${this.repo}/pulls/comments/${encodeURIComponent(noteId)}/reactions`, emoji);
1101
+ }
1102
+ async reviewReactions() {
1103
+ return this.fetchReactions(`repos/${this.repo}/issues/${this.ref.number}/reactions`);
1104
+ }
1105
+ async reactToReview(emoji) {
1106
+ return this.toggleReaction(`repos/${this.repo}/issues/${this.ref.number}/reactions`, emoji);
1107
+ }
1108
+ async updateNote(noteId, body) {
1109
+ await withTempJson({ body }, async (file) => {
1110
+ await this.call(["--method", "PATCH", `repos/${this.repo}/pulls/comments/${encodeURIComponent(noteId)}`, "--input", file]);
1111
+ });
1112
+ }
1113
+ async deleteNote(noteId) {
1114
+ await this.call(["--method", "DELETE", `repos/${this.repo}/pulls/comments/${encodeURIComponent(noteId)}`]);
1115
+ }
1080
1116
  async upload(_input) {
1081
1117
  throw new ProviderError(
1082
1118
  tr("GitHub \u043D\u0435 \u0434\u0430\u0451\u0442 \u043F\u0443\u0431\u043B\u0438\u0447\u043D\u043E\u0433\u043E API \u0434\u043B\u044F \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 \u0432\u043B\u043E\u0436\u0435\u043D\u0438\u0439", "GitHub has no public API for uploading attachments"),
@@ -1222,7 +1258,7 @@ async function writeFileAtomic(file, data, mode = 384) {
1222
1258
  init_redact();
1223
1259
 
1224
1260
  // src/version.ts
1225
- var VERSION = "0.3.3";
1261
+ var VERSION = "0.4.0";
1226
1262
  var PROTOCOL_VERSION = 1;
1227
1263
 
1228
1264
  // src/daemon/main.ts
@@ -1318,6 +1354,8 @@ var Store = class {
1318
1354
  review_id TEXT PRIMARY KEY REFERENCES reviews(id) ON DELETE CASCADE,
1319
1355
  diff_json TEXT NOT NULL,
1320
1356
  threads_json TEXT NOT NULL,
1357
+ reactions_json TEXT NOT NULL DEFAULT '[]',
1358
+ user_json TEXT NOT NULL DEFAULT 'null',
1321
1359
  config_json TEXT NOT NULL,
1322
1360
  config_path TEXT,
1323
1361
  errors_json TEXT NOT NULL,
@@ -1348,6 +1386,7 @@ var Store = class {
1348
1386
  published_at TEXT,
1349
1387
  decision TEXT,
1350
1388
  note TEXT NOT NULL,
1389
+ agent_note TEXT NOT NULL DEFAULT '',
1351
1390
  publish_error TEXT NOT NULL DEFAULT '',
1352
1391
  updated_at TEXT NOT NULL,
1353
1392
  PRIMARY KEY (review_id, id)
@@ -1411,6 +1450,17 @@ var Store = class {
1411
1450
  );
1412
1451
  CREATE INDEX IF NOT EXISTS audit_review ON audit(review_id, at);
1413
1452
  `);
1453
+ const findingColumns = this.db.prepare("PRAGMA table_info(findings)").all();
1454
+ if (!findingColumns.some((column) => text(column, "name") === "agent_note")) {
1455
+ this.db.exec("ALTER TABLE findings ADD COLUMN agent_note TEXT NOT NULL DEFAULT ''");
1456
+ }
1457
+ const dataColumns = this.db.prepare("PRAGMA table_info(review_data)").all();
1458
+ if (!dataColumns.some((column) => text(column, "name") === "reactions_json")) {
1459
+ this.db.exec("ALTER TABLE review_data ADD COLUMN reactions_json TEXT NOT NULL DEFAULT '[]'");
1460
+ }
1461
+ if (!dataColumns.some((column) => text(column, "name") === "user_json")) {
1462
+ this.db.exec("ALTER TABLE review_data ADD COLUMN user_json TEXT NOT NULL DEFAULT 'null'");
1463
+ }
1414
1464
  }
1415
1465
  saveReview(info, root, syncedAt = (/* @__PURE__ */ new Date()).toISOString()) {
1416
1466
  const id = reviewId(info.ref);
@@ -1440,16 +1490,18 @@ var Store = class {
1440
1490
  }
1441
1491
  saveSnapshot(id, snapshot) {
1442
1492
  this.db.prepare(
1443
- `INSERT INTO review_data (review_id, diff_json, threads_json, config_json, config_path, errors_json, synced_at)
1444
- VALUES (?, ?, ?, ?, ?, ?, ?)
1493
+ `INSERT INTO review_data (review_id, diff_json, threads_json, reactions_json, user_json, config_json, config_path, errors_json, synced_at)
1494
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
1445
1495
  ON CONFLICT(review_id) DO UPDATE SET
1446
1496
  diff_json = excluded.diff_json, threads_json = excluded.threads_json,
1447
- config_json = excluded.config_json, config_path = excluded.config_path,
1497
+ reactions_json = excluded.reactions_json, user_json = excluded.user_json, config_json = excluded.config_json, config_path = excluded.config_path,
1448
1498
  errors_json = excluded.errors_json, synced_at = excluded.synced_at`
1449
1499
  ).run(
1450
1500
  id,
1451
1501
  JSON.stringify(snapshot.diff),
1452
1502
  JSON.stringify(snapshot.threads),
1503
+ JSON.stringify(snapshot.reactions ?? []),
1504
+ JSON.stringify(snapshot.user ?? null),
1453
1505
  JSON.stringify(snapshot.config),
1454
1506
  snapshot.configPath,
1455
1507
  JSON.stringify(snapshot.errors),
@@ -1458,7 +1510,7 @@ var Store = class {
1458
1510
  this.db.prepare("UPDATE reviews SET synced_at = ? WHERE id = ?").run(snapshot.syncedAt, id);
1459
1511
  }
1460
1512
  listReviews() {
1461
- const rows = this.db.prepare("SELECT * FROM reviews ORDER BY synced_at DESC").all();
1513
+ const rows = this.db.prepare("SELECT * FROM reviews ORDER BY updated_at DESC, number DESC").all();
1462
1514
  return rows.map((row) => ({
1463
1515
  id: text(row, "id"),
1464
1516
  platform: text(row, "platform"),
@@ -1497,6 +1549,8 @@ var Store = class {
1497
1549
  snapshot: {
1498
1550
  diff: json(data, "diff_json", []),
1499
1551
  threads: json(data, "threads_json", []),
1552
+ reactions: json(data, "reactions_json", []),
1553
+ user: json(data, "user_json", null),
1500
1554
  config: json(data, "config_json", {}),
1501
1555
  configPath: data.config_path ? String(data.config_path) : null,
1502
1556
  errors: json(data, "errors_json", []),
@@ -1551,6 +1605,7 @@ var Store = class {
1551
1605
  publishedAt: row.published_at ? String(row.published_at) : null,
1552
1606
  decision: row.decision ? String(row.decision) : null,
1553
1607
  note: text(row, "note"),
1608
+ agentNote: text(row, "agent_note"),
1554
1609
  publishError: text(row, "publish_error")
1555
1610
  }));
1556
1611
  }
@@ -1558,8 +1613,8 @@ var Store = class {
1558
1613
  this.transaction(() => {
1559
1614
  this.db.prepare("DELETE FROM findings WHERE review_id = ?").run(id);
1560
1615
  const insert = this.db.prepare(
1561
- `INSERT INTO findings (review_id, id, fingerprint, level, file, line, end_line, title, body, comment, status, discussion_id, published_at, decision, note, publish_error, updated_at)
1562
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
1616
+ `INSERT INTO findings (review_id, id, fingerprint, level, file, line, end_line, title, body, comment, status, discussion_id, published_at, decision, note, agent_note, publish_error, updated_at)
1617
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
1563
1618
  );
1564
1619
  const now = (/* @__PURE__ */ new Date()).toISOString();
1565
1620
  for (const finding of findings) {
@@ -1579,6 +1634,7 @@ var Store = class {
1579
1634
  finding.publishedAt,
1580
1635
  finding.decision,
1581
1636
  finding.note,
1637
+ finding.agentNote ?? "",
1582
1638
  finding.publishError,
1583
1639
  now
1584
1640
  );
@@ -1588,7 +1644,7 @@ var Store = class {
1588
1644
  updateFinding(id, finding) {
1589
1645
  this.db.prepare(
1590
1646
  `UPDATE findings SET level = ?, file = ?, line = ?, end_line = ?, title = ?, body = ?, comment = ?,
1591
- status = ?, discussion_id = ?, published_at = ?, decision = ?, note = ?, publish_error = ?, updated_at = ?
1647
+ status = ?, discussion_id = ?, published_at = ?, decision = ?, note = ?, agent_note = ?, publish_error = ?, updated_at = ?
1592
1648
  WHERE review_id = ? AND id = ?`
1593
1649
  ).run(
1594
1650
  finding.level,
@@ -1603,6 +1659,7 @@ var Store = class {
1603
1659
  finding.publishedAt,
1604
1660
  finding.decision,
1605
1661
  finding.note,
1662
+ finding.agentNote ?? "",
1606
1663
  finding.publishError,
1607
1664
  (/* @__PURE__ */ new Date()).toISOString(),
1608
1665
  id,
@@ -2280,6 +2337,7 @@ function validateFinding(raw) {
2280
2337
  const title = typeof item.title === "string" ? item.title.trim() : "";
2281
2338
  const body = typeof item.body === "string" ? item.body.trim() : "";
2282
2339
  const comment = typeof item.comment === "string" ? item.comment.trim() : body;
2340
+ const agentNote = typeof item.agentNote === "string" ? item.agentNote.trim().slice(0, 8e3) : "";
2283
2341
  if (!file) return { value: null, error: tr("\u043D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D file", "file is required") };
2284
2342
  if (!title) return { value: null, error: tr("\u043D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D title", "title is required") };
2285
2343
  if (!comment) return { value: null, error: tr("\u043F\u0443\u0441\u0442\u043E\u0439 comment", "comment is empty") };
@@ -2302,7 +2360,8 @@ function validateFinding(raw) {
2302
2360
  endLine,
2303
2361
  title,
2304
2362
  body,
2305
- comment
2363
+ comment,
2364
+ agentNote
2306
2365
  },
2307
2366
  error: ""
2308
2367
  };
@@ -2332,6 +2391,7 @@ function mergeFindings(previous, incoming, options = {}) {
2332
2391
  body: draft.body,
2333
2392
  // Опубликованный текст не переписываем: он уже виден автору MR.
2334
2393
  comment: match.status === "published" ? match.comment : draft.comment,
2394
+ agentNote: draft.agentNote ?? match.agentNote ?? "",
2335
2395
  status: match.status === "stale" ? "draft" : match.status,
2336
2396
  fingerprint
2337
2397
  });
@@ -2354,6 +2414,7 @@ function mergeFindings(previous, incoming, options = {}) {
2354
2414
  publishedAt: null,
2355
2415
  decision: null,
2356
2416
  note: "",
2417
+ agentNote: draft.agentNote ?? "",
2357
2418
  publishError: ""
2358
2419
  });
2359
2420
  }
@@ -2643,11 +2704,25 @@ var ReviewService = class {
2643
2704
  } catch (error) {
2644
2705
  errors.push(`${tr("\u0442\u0440\u0435\u0434\u044B", "threads")}: ${redact(messageOf(error))}`);
2645
2706
  }
2707
+ let reactions = previous?.reactions ?? [];
2708
+ try {
2709
+ reactions = await provider.reviewReactions();
2710
+ } catch (error) {
2711
+ errors.push(`${tr("\u0440\u0435\u0430\u043A\u0446\u0438\u0438", "reactions")}: ${redact(messageOf(error))}`);
2712
+ }
2713
+ let user = previous?.user ?? null;
2714
+ try {
2715
+ user = await provider.currentUser();
2716
+ } catch (error) {
2717
+ errors.push(`${tr("\u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044C", "current user")}: ${redact(messageOf(error))}`);
2718
+ }
2646
2719
  info.stats = diffStats(diff);
2647
2720
  this.store.saveReview(info, root, syncedAt);
2648
2721
  this.store.saveSnapshot(id, {
2649
2722
  diff,
2650
2723
  threads,
2724
+ reactions,
2725
+ user,
2651
2726
  config: loaded.config,
2652
2727
  configPath: loaded.path,
2653
2728
  errors,
@@ -2698,12 +2773,13 @@ var ReviewService = class {
2698
2773
  info,
2699
2774
  diff: snapshot.diff,
2700
2775
  threads,
2776
+ reactions: snapshot.reactions,
2701
2777
  summary: this.store.getSummary(id),
2702
2778
  findings,
2703
2779
  drafts,
2704
2780
  notes: this.store.listNotes(id),
2705
2781
  decisions: this.store.listDecisions(id),
2706
- user: null,
2782
+ user: snapshot.user,
2707
2783
  syncedAt: snapshot.syncedAt,
2708
2784
  errors: snapshot.errors
2709
2785
  };
@@ -2852,6 +2928,24 @@ ${errors.join("\n")}`));
2852
2928
  }
2853
2929
  return result;
2854
2930
  }
2931
+ async reactToReview(id, emoji) {
2932
+ if (!REACTIONS.includes(emoji)) {
2933
+ throw new Error(tr(`\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u0440\u0435\u0430\u043A\u0446\u0438\u044F ${emoji}: ${REACTIONS.join(", ")}`, `unknown reaction ${emoji}: ${REACTIONS.join(", ")}`));
2934
+ }
2935
+ const provider = await this.providerFor(id);
2936
+ const previous = this.store.getReview(id)?.snapshot.reactions ?? [];
2937
+ const result = await provider.reactToReview(emoji);
2938
+ let reactions = previous;
2939
+ try {
2940
+ reactions = await provider.reviewReactions();
2941
+ } catch {
2942
+ }
2943
+ this.store.audit(id, "reaction.review", { emoji, active: result.active });
2944
+ const stored = this.store.getReview(id);
2945
+ if (stored) this.store.saveSnapshot(id, { ...stored.snapshot, reactions });
2946
+ this.emit(id);
2947
+ return { active: result.active, reactions };
2948
+ }
2855
2949
  async react(id, noteId, emoji) {
2856
2950
  if (!REACTIONS.includes(emoji)) {
2857
2951
  throw new Error(tr(`\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u0440\u0435\u0430\u043A\u0446\u0438\u044F ${emoji}: ${REACTIONS.join(", ")}`, `unknown reaction ${emoji}: ${REACTIONS.join(", ")}`));
@@ -2905,6 +2999,50 @@ ${errors.join("\n")}`));
2905
2999
  await rm2(dir, { recursive: true, force: true });
2906
3000
  }
2907
3001
  }
3002
+ // ---------------------------------------------------------------- comments
3003
+ noteInReview(id, noteId) {
3004
+ const review = this.getReview(id);
3005
+ const thread = review.threads.find((item) => item.notes.some((note2) => note2.id === noteId));
3006
+ const note = thread?.notes.find((item) => item.id === noteId);
3007
+ return { review, thread: thread ?? null, note: note ?? null };
3008
+ }
3009
+ async updateComment(id, noteId, body) {
3010
+ const { review, note } = this.noteInReview(id, noteId);
3011
+ if (!note) throw new Error(tr(`\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u044F ${noteId} \u043D\u0435\u0442 \u0432 \u044D\u0442\u043E\u043C \u0440\u0435\u0432\u044C\u044E`, `comment ${noteId} is not in this review`));
3012
+ if (!review.user || note.author !== review.user.username) {
3013
+ throw new Error(tr("\u043C\u043E\u0436\u043D\u043E \u0440\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0441\u0432\u043E\u0439 \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0439", "only your own comment can be edited"));
3014
+ }
3015
+ const check = sanitizeBody(body, review.info.ref.platform, { host: review.info.ref.host });
3016
+ if (!check.ok) throw new Error(check.reason);
3017
+ const provider = await this.providerFor(id);
3018
+ await provider.updateNote(noteId, check.text);
3019
+ const stored = this.store.getReview(id);
3020
+ if (stored) {
3021
+ const threads = stored.snapshot.threads.map((thread) => ({
3022
+ ...thread,
3023
+ notes: thread.notes.map((item) => item.id === noteId ? { ...item, body: check.text } : item)
3024
+ }));
3025
+ this.store.saveSnapshot(id, { ...stored.snapshot, threads });
3026
+ }
3027
+ this.store.audit(id, "comment.update", { noteId });
3028
+ this.emit(id);
3029
+ }
3030
+ async deleteComment(id, noteId) {
3031
+ const { review, note } = this.noteInReview(id, noteId);
3032
+ if (!note) throw new Error(tr(`\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u044F ${noteId} \u043D\u0435\u0442 \u0432 \u044D\u0442\u043E\u043C \u0440\u0435\u0432\u044C\u044E`, `comment ${noteId} is not in this review`));
3033
+ if (!review.user || note.author !== review.user.username) {
3034
+ throw new Error(tr("\u043C\u043E\u0436\u043D\u043E \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0441\u0432\u043E\u0439 \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0439", "only your own comment can be deleted"));
3035
+ }
3036
+ const provider = await this.providerFor(id);
3037
+ await provider.deleteNote(noteId);
3038
+ const stored = this.store.getReview(id);
3039
+ if (stored) {
3040
+ const threads = stored.snapshot.threads.map((thread) => ({ ...thread, notes: thread.notes.filter((item) => item.id !== noteId) })).filter((thread) => thread.notes.length > 0);
3041
+ this.store.saveSnapshot(id, { ...stored.snapshot, threads });
3042
+ }
3043
+ this.store.audit(id, "comment.delete", { noteId });
3044
+ this.emit(id);
3045
+ }
2908
3046
  // ---------------------------------------------------------------- notes
2909
3047
  addNote(id, input) {
2910
3048
  const review = this.getReview(id);
@@ -3432,6 +3570,14 @@ async function dispatch(service, method, params) {
3432
3570
  };
3433
3571
  case "reactions.toggle":
3434
3572
  return service.react(String(params.review ?? ""), String(params.noteId ?? ""), String(params.emoji ?? ""));
3573
+ case "reactions.reviewToggle":
3574
+ return service.reactToReview(String(params.review ?? ""), String(params.emoji ?? ""));
3575
+ case "comments.update":
3576
+ await service.updateComment(String(params.review ?? ""), String(params.noteId ?? ""), String(params.body ?? ""));
3577
+ return { ok: true };
3578
+ case "comments.delete":
3579
+ await service.deleteComment(String(params.review ?? ""), String(params.noteId ?? ""));
3580
+ return { ok: true };
3435
3581
  case "attachments.upload":
3436
3582
  return {
3437
3583
  attachment: await service.uploadAttachment(String(params.review ?? ""), {
@@ -3636,6 +3782,8 @@ async function startHttpServer(options) {
3636
3782
  const server = http.createServer(async (req, res) => {
3637
3783
  const port2 = server.address()?.port ?? 0;
3638
3784
  const expectedHosts = /* @__PURE__ */ new Set([`127.0.0.1:${port2}`, `localhost:${port2}`, `[::1]:${port2}`]);
3785
+ for (const name of options.allowedHosts ?? []) expectedHosts.add(`${name}:${port2}`);
3786
+ if (host !== "127.0.0.1" && host !== "localhost" && host !== "::1") expectedHosts.add(`host.docker.internal:${port2}`);
3639
3787
  if (!expectedHosts.has(String(req.headers.host ?? ""))) {
3640
3788
  reply(res, 403, { ok: false, error: "\u043D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0439 Host" });
3641
3789
  return;
@@ -3769,6 +3917,12 @@ data: ${JSON.stringify(event)}
3769
3917
  reply(res, 200, { ok: true, reactions: await service.reactions(review, noteIds) });
3770
3918
  return;
3771
3919
  }
3920
+ if (req.method === "GET" && url.pathname === "/api/review-reactions") {
3921
+ const review = url.searchParams.get("review") ?? "";
3922
+ const view = service.getReview(review);
3923
+ reply(res, 200, { ok: true, reactions: view.reactions });
3924
+ return;
3925
+ }
3772
3926
  if (req.method === "POST") {
3773
3927
  const body = await readBody(req);
3774
3928
  const review = String(body.review ?? "");
@@ -3791,6 +3945,13 @@ data: ${JSON.stringify(event)}
3791
3945
  reply(res, 200, { ok: true, review: service.getView(updated.id), reviews: service.listReviews() });
3792
3946
  return;
3793
3947
  }
3948
+ case "/api/comments": {
3949
+ const noteId = String(body.noteId ?? "");
3950
+ if (String(body.action ?? "") === "delete") await service.deleteComment(review, noteId);
3951
+ else await service.updateComment(review, noteId, String(body.body ?? ""));
3952
+ reply(res, 200, { ok: true });
3953
+ return;
3954
+ }
3794
3955
  case "/api/attachments": {
3795
3956
  const attachment = await service.uploadAttachment(review, {
3796
3957
  name: String(body.name ?? ""),
@@ -3805,6 +3966,11 @@ data: ${JSON.stringify(event)}
3805
3966
  reply(res, 200, { ok: true, ...result });
3806
3967
  return;
3807
3968
  }
3969
+ case "/api/review-reactions": {
3970
+ const result = await service.reactToReview(review, String(body.emoji ?? ""));
3971
+ reply(res, 200, { ok: true, ...result });
3972
+ return;
3973
+ }
3808
3974
  case "/api/drafts": {
3809
3975
  const draft = service.setDraft(review, String(body.threadId ?? ""), body.patch ?? {});
3810
3976
  reply(res, 200, { ok: true, draft });
@@ -3981,6 +4147,7 @@ async function main() {
3981
4147
  uiDir,
3982
4148
  ...values.port ? { port: Number(values.port) } : {},
3983
4149
  ...values.host ? { host: String(values.host) } : {},
4150
+ ...process.env.REVDECK_HTTP_ALLOWED_HOSTS ? { allowedHosts: process.env.REVDECK_HTTP_ALLOWED_HOSTS.split(",").map((item) => item.trim()).filter(Boolean) } : {},
3984
4151
  version: VERSION
3985
4152
  });
3986
4153
  const info = {