@a9n-shoji/rvw 0.2.0 → 0.2.2

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +28 -7
  3. package/dist/cli.mjs +492 -307
  4. package/dist/cli.mjs.map +3 -3
  5. package/dist/web/assets/{DocumentViewer-CNgHpCuL.js → DocumentViewer-ADzspLC4.js} +32 -32
  6. package/dist/web/assets/{markdown-source-map-_dS1q5Dg.js → MarkdownTable-DVJ0_MIC.js} +2 -2
  7. package/dist/web/assets/WalkthroughViewer-yQibj2tK.js +1 -0
  8. package/dist/web/assets/{abnfDiagram-N423BO3Z-0v-ndtqQ.js → abnfDiagram-N423BO3Z-6dQzEuPV.js} +1 -1
  9. package/dist/web/assets/architecture-TIHT7OUA-DEoBuEnc.js +1 -0
  10. package/dist/web/assets/{architectureDiagram-T3A2C74G-WSNJ-tZE.js → architectureDiagram-T3A2C74G-DP7hHV7T.js} +1 -1
  11. package/dist/web/assets/{blockDiagram-VBNYF7ZC-lmMbEUwI.js → blockDiagram-VBNYF7ZC-ZbwzVKWP.js} +1 -1
  12. package/dist/web/assets/{c4Diagram-5PPSVZJV-BrN5YVV8.js → c4Diagram-5PPSVZJV-HVD9_uV4.js} +1 -1
  13. package/dist/web/assets/channel-DjgdV-zW.js +1 -0
  14. package/dist/web/assets/{chunk-2GRJ4B5K-gt2JPyrH.js → chunk-2GRJ4B5K-Bkxs2d4J.js} +1 -1
  15. package/dist/web/assets/{chunk-4I5QYGJK-Cg5GZ_-7.js → chunk-4I5QYGJK-BJHE6zC_.js} +1 -1
  16. package/dist/web/assets/{chunk-5RXB4S5H-BdhRGvxW.js → chunk-5RXB4S5H-B-52dfCQ.js} +1 -1
  17. package/dist/web/assets/{chunk-6Q2QTUOP-B1DYWNVJ.js → chunk-6Q2QTUOP-BpD0vQ66.js} +1 -1
  18. package/dist/web/assets/{chunk-7Z6QIM7H-D2YImamZ.js → chunk-7Z6QIM7H-BTI1qgAO.js} +1 -1
  19. package/dist/web/assets/{chunk-GF5L2VYU-CWtwL_CM.js → chunk-GF5L2VYU-B8BxoCCx.js} +1 -1
  20. package/dist/web/assets/{chunk-I66GZJ75-DdoGlxMt.js → chunk-I66GZJ75-zwi-Xf01.js} +1 -1
  21. package/dist/web/assets/{chunk-JQJVKLGR-CVWAp3XP.js → chunk-JQJVKLGR-D9mKBWUz.js} +1 -1
  22. package/dist/web/assets/{chunk-KBJHAD2P-BBacwg3J.js → chunk-KBJHAD2P-Qmtir3qc.js} +1 -1
  23. package/dist/web/assets/{chunk-NSK5VX7P-1AsXiBV3.js → chunk-NSK5VX7P-SP2vZdAo.js} +1 -1
  24. package/dist/web/assets/{chunk-QR6OTTB3-DL2s5pNp.js → chunk-QR6OTTB3-uVDCHurs.js} +1 -1
  25. package/dist/web/assets/{chunk-UBXNYLIW-mu3fkNQI.js → chunk-UBXNYLIW-CtNzBWOU.js} +1 -1
  26. package/dist/web/assets/{chunk-W5SLKNZC-BAwhMBBb.js → chunk-W5SLKNZC-BPfDqbmK.js} +1 -1
  27. package/dist/web/assets/{chunk-WRU74C26-C7IeXZaP.js → chunk-WRU74C26-BZkEOexq.js} +1 -1
  28. package/dist/web/assets/classDiagram-JCYQIIEL-B6Qjam7Y.js +1 -0
  29. package/dist/web/assets/classDiagram-v2-OCEON4UE-B6Qjam7Y.js +1 -0
  30. package/dist/web/assets/{cynefin-VYW2F7L2-DNisGvNv.js → cynefin-VYW2F7L2-BRisCyqC.js} +1 -1
  31. package/dist/web/assets/{cynefinDiagram-MW4NZA55-BA27gOTz.js → cynefinDiagram-MW4NZA55-ClIrmCkB.js} +1 -1
  32. package/dist/web/assets/{dagre-VZM6K2ZE-vo_1YAuM.js → dagre-VZM6K2ZE-X31uC_JB.js} +1 -1
  33. package/dist/web/assets/{diagram-7IWD3JNH-DLLdUj0_.js → diagram-7IWD3JNH-DBQFjl0i.js} +1 -1
  34. package/dist/web/assets/{diagram-B4RE2ZJO-BV0WyNA-.js → diagram-B4RE2ZJO-BZ7934Wg.js} +1 -1
  35. package/dist/web/assets/{diagram-LBJQPF4R-DXxKSx2U.js → diagram-LBJQPF4R-CcJqH9aY.js} +1 -1
  36. package/dist/web/assets/{diagram-Q27KOJAE-DsQ2GzIK.js → diagram-Q27KOJAE-DzM7eiil.js} +1 -1
  37. package/dist/web/assets/{diagram-UB23O5K3-DfjElFP1.js → diagram-UB23O5K3-CVCV-d3m.js} +1 -1
  38. package/dist/web/assets/{ebnfDiagram-BXEA7PRR-cYu0XV1a.js → ebnfDiagram-BXEA7PRR-D8xb9FBp.js} +1 -1
  39. package/dist/web/assets/{erDiagram-JOGREHBK-DnsLBHaV.js → erDiagram-JOGREHBK-1l-G_PMG.js} +1 -1
  40. package/dist/web/assets/eventmodeling-45OFAUF4-ndNeUBOZ.js +1 -0
  41. package/dist/web/assets/flowDiagram-UKHOOZJN-BVxK_6Tu.js +1 -0
  42. package/dist/web/assets/{ganttDiagram-PKOTCBZU-CVD5gq3E.js → ganttDiagram-PKOTCBZU-CDJ9a1tp.js} +1 -1
  43. package/dist/web/assets/{gitGraph-TEB2WS4Q-C_j0n-Kw.js → gitGraph-TEB2WS4Q-DOeTh5wB.js} +1 -1
  44. package/dist/web/assets/{gitGraphDiagram-DS77QQ5N-qACevJmW.js → gitGraphDiagram-DS77QQ5N-DYLxc8Nz.js} +1 -1
  45. package/dist/web/assets/index-9cOaPesh.js +384 -0
  46. package/dist/web/assets/index-kK3hngnz.css +1 -0
  47. package/dist/web/assets/{info-DKCQHKI2-Cmkbz3Yi.js → info-DKCQHKI2-B5u97QuQ.js} +1 -1
  48. package/dist/web/assets/{infoDiagram-6WML65LV-CDrAem7M.js → infoDiagram-6WML65LV-zosKW2OD.js} +1 -1
  49. package/dist/web/assets/{ishikawaDiagram-WSZJBQD7-DXgCnFqW.js → ishikawaDiagram-WSZJBQD7-VYcc_au8.js} +1 -1
  50. package/dist/web/assets/{journeyDiagram-NVQOT4AX-1KW-I7DV.js → journeyDiagram-NVQOT4AX-C_nU8kP4.js} +1 -1
  51. package/dist/web/assets/{kanban-definition-27J2QSJJ-CCt75OuF.js → kanban-definition-27J2QSJJ-DybKaWfx.js} +1 -1
  52. package/dist/web/assets/{line-DQfkDi_r.js → line-DWsGplGj.js} +1 -1
  53. package/dist/web/assets/{mermaid-parser.core-B7TMMtY0.js → mermaid-parser.core-D_T_3oIQ.js} +3 -3
  54. package/dist/web/assets/{mermaid.core-B93x-7Mk.js → mermaid.core-BoLGzxB5.js} +4 -4
  55. package/dist/web/assets/{mindmap-definition-FAOFIHXS-Dyt28V6S.js → mindmap-definition-FAOFIHXS-CsdpqPIa.js} +1 -1
  56. package/dist/web/assets/{packet-7NZHBO7P-zQ0u35s3.js → packet-7NZHBO7P-CReAEF1h.js} +1 -1
  57. package/dist/web/assets/{pegDiagram-VL7TDLO6-et0KHGIE.js → pegDiagram-VL7TDLO6-CE9-NPMu.js} +1 -1
  58. package/dist/web/assets/{pie-RZYD4A2V-uur86LkQ.js → pie-RZYD4A2V-GYixXUka.js} +1 -1
  59. package/dist/web/assets/{pieDiagram-7S7Q4E2Y-c027WPTB.js → pieDiagram-7S7Q4E2Y-CqaAKNg2.js} +1 -1
  60. package/dist/web/assets/{quadrantDiagram-CIZ2JOQS-BtSV4E-0.js → quadrantDiagram-CIZ2JOQS-eRMHJqfj.js} +1 -1
  61. package/dist/web/assets/{radar-I7S5WNFK-B_g0VZMF.js → radar-I7S5WNFK-BwHxP0iK.js} +1 -1
  62. package/dist/web/assets/{railroad-3IZDKUUU-VFLsM_Em.js → railroad-3IZDKUUU-AHc3O4Oz.js} +1 -1
  63. package/dist/web/assets/railroad-abnf-AHOZXSZD-ZKY5olmV.js +1 -0
  64. package/dist/web/assets/railroad-ebnf-EBAXGLYW-CrG1UCMo.js +1 -0
  65. package/dist/web/assets/railroad-peg-LSFZ7HO6-CoY6MIbj.js +1 -0
  66. package/dist/web/assets/{railroadDiagram-AXF67PYL-uOtnxRbQ.js → railroadDiagram-AXF67PYL-BhAxCokG.js} +1 -1
  67. package/dist/web/assets/{requirementDiagram-LRYGKXZP-DGSZAsj4.js → requirementDiagram-LRYGKXZP-BRW-kYhg.js} +1 -1
  68. package/dist/web/assets/{sankeyDiagram-W5VNT64P-CCDk8Vxt.js → sankeyDiagram-W5VNT64P-DfnYLbDJ.js} +1 -1
  69. package/dist/web/assets/{sequenceDiagram-SI44F4Z6-Ce-Jzdk5.js → sequenceDiagram-SI44F4Z6-WEkIPSg8.js} +1 -1
  70. package/dist/web/assets/{stateDiagram-OKZ733FA-BYpYzyEa.js → stateDiagram-OKZ733FA-CdN7veIN.js} +1 -1
  71. package/dist/web/assets/stateDiagram-v2-UEYNNEHI-0xn0gbpn.js +1 -0
  72. package/dist/web/assets/{swimlanes-SLNWSIFB-BL-CUc6d.js → swimlanes-SLNWSIFB-g9wWLf5Y.js} +1 -1
  73. package/dist/web/assets/swimlanesDiagram-ULZ7WXOC-YJ3yh_d3.js +8 -0
  74. package/dist/web/assets/{timeline-definition-Z64GVDOM-p9pkof_K.js → timeline-definition-Z64GVDOM-DjkKZIPE.js} +1 -1
  75. package/dist/web/assets/{treeView-QDETBFTQ-dRhXTU9p.js → treeView-QDETBFTQ-WARa9r09.js} +1 -1
  76. package/dist/web/assets/{treemap-6X3UGDF4-CZHe3dIh.js → treemap-6X3UGDF4-CTFjdb6k.js} +1 -1
  77. package/dist/web/assets/{vennDiagram-T6HMQDX7-ipODJegx.js → vennDiagram-T6HMQDX7-CI9QrBwu.js} +1 -1
  78. package/dist/web/assets/{wardley-OPB4EBWU-CxHlVjkF.js → wardley-OPB4EBWU-Cfo_Nnla.js} +1 -1
  79. package/dist/web/assets/{wardleyDiagram-T6FBY63Y-YarkIncH.js → wardleyDiagram-T6FBY63Y-CzGJ4fzZ.js} +1 -1
  80. package/dist/web/assets/{xychartDiagram-ELKLHX3M-Cw1M-7a4.js → xychartDiagram-ELKLHX3M-BXCiD7gJ.js} +1 -1
  81. package/dist/web/index.html +2 -2
  82. package/migrations/010_comment_post_references.sql +17 -0
  83. package/package.json +2 -1
  84. package/skills/rvw/SKILL.md +79 -6
  85. package/skills/rvw-walkthrough/SKILL.md +1 -1
  86. package/skills/rvw-watch-comments/SKILL.md +217 -67
  87. package/skills/rvw-watch-comments/scripts/auto-ack.mjs +211 -0
  88. package/skills/rvw-watch-comments/scripts/preflight.mjs +108 -0
  89. package/skills/rvw-watch-comments/scripts/rvw-command.mjs +80 -0
  90. package/skills/rvw-watch-comments/scripts/watch-driver.mjs +272 -0
  91. package/skills/rvw-watch-comments/scripts/watch-state.mjs +223 -70
  92. package/dist/web/assets/WalkthroughViewer-BVB3ETHG.js +0 -1
  93. package/dist/web/assets/architecture-TIHT7OUA-BjGWtjPU.js +0 -1
  94. package/dist/web/assets/channel-DkH22XO0.js +0 -1
  95. package/dist/web/assets/classDiagram-JCYQIIEL-C6Z4rmZR.js +0 -1
  96. package/dist/web/assets/classDiagram-v2-OCEON4UE-C6Z4rmZR.js +0 -1
  97. package/dist/web/assets/eventmodeling-45OFAUF4-BUAcQ5NU.js +0 -1
  98. package/dist/web/assets/flowDiagram-UKHOOZJN-hAe9ojjP.js +0 -1
  99. package/dist/web/assets/index-Coye1BY5.js +0 -384
  100. package/dist/web/assets/index-DFdYNMZE.css +0 -1
  101. package/dist/web/assets/railroad-abnf-AHOZXSZD-TVRi9_2L.js +0 -1
  102. package/dist/web/assets/railroad-ebnf-EBAXGLYW-B5B-JrS4.js +0 -1
  103. package/dist/web/assets/railroad-peg-LSFZ7HO6-CfIpa6ba.js +0 -1
  104. package/dist/web/assets/stateDiagram-v2-UEYNNEHI-BJFG9cb2.js +0 -1
  105. package/dist/web/assets/swimlanesDiagram-ULZ7WXOC-BS8L8fb1.js +0 -8
package/dist/cli.mjs CHANGED
@@ -18754,12 +18754,23 @@ function mapPullRequest(row) {
18754
18754
  updatedAt: stringValue(row, "updated_at")
18755
18755
  };
18756
18756
  }
18757
- function mapCommentPost(row) {
18757
+ function mapCodeReference(row) {
18758
+ return {
18759
+ id: stringValue(row, "reference_id"),
18760
+ label: stringValue(row, "label"),
18761
+ path: stringValue(row, "file_path"),
18762
+ startLine: nullableNumber(row, "start_line"),
18763
+ endLine: nullableNumber(row, "end_line"),
18764
+ description: nullableString(row, "description")
18765
+ };
18766
+ }
18767
+ function mapCommentPost(row, references = []) {
18758
18768
  return {
18759
18769
  id: stringValue(row, "id"),
18760
18770
  commentId: stringValue(row, "comment_id"),
18761
18771
  body: stringValue(row, "body"),
18762
18772
  relatedCommitOid: nullableString(row, "related_commit_oid"),
18773
+ references,
18763
18774
  authorLabel: nullableString(row, "author_label"),
18764
18775
  isRoot: numberValue(row, "is_root") === 1,
18765
18776
  createdAt: stringValue(row, "created_at"),
@@ -19169,6 +19180,16 @@ var RvwDatabase = class {
19169
19180
  const posts = this.database.prepare(
19170
19181
  "SELECT count(*) AS count FROM comment_posts WHERE comment_id IN (SELECT id FROM comments WHERE pull_request_id = ?)"
19171
19182
  ).get(pullRequestId);
19183
+ const commentReferences = this.database.prepare(
19184
+ `SELECT count(*) AS count
19185
+ FROM comment_post_references
19186
+ WHERE post_id IN (
19187
+ SELECT posts.id
19188
+ FROM comment_posts AS posts
19189
+ JOIN comments ON comments.id = posts.comment_id
19190
+ WHERE comments.pull_request_id = ?
19191
+ )`
19192
+ ).get(pullRequestId);
19172
19193
  const targets = this.database.prepare(
19173
19194
  "SELECT count(*) AS count FROM comment_targets WHERE comment_id IN (SELECT id FROM comments WHERE pull_request_id = ?)"
19174
19195
  ).get(pullRequestId);
@@ -19179,6 +19200,7 @@ var RvwDatabase = class {
19179
19200
  return {
19180
19201
  comments: numberValue(comments, "count"),
19181
19202
  posts: numberValue(posts, "count"),
19203
+ commentReferences: numberValue(commentReferences, "count"),
19182
19204
  targets: numberValue(targets, "count"),
19183
19205
  walkthroughs: numberValue(walkthroughs, "count"),
19184
19206
  walkthroughReferences: numberValue(walkthroughReferences, "count"),
@@ -19189,17 +19211,34 @@ var RvwDatabase = class {
19189
19211
  this.database.prepare("DELETE FROM comments WHERE pull_request_id = ?").run(pullRequestId);
19190
19212
  this.database.prepare("DELETE FROM walkthroughs WHERE pull_request_id = ?").run(pullRequestId);
19191
19213
  }
19192
- listWalkthroughReferences(walkthroughId) {
19193
- return this.database.prepare(
19194
- "SELECT * FROM walkthrough_references WHERE walkthrough_id = ? ORDER BY sort_order ASC"
19195
- ).all(walkthroughId).map((row) => ({
19196
- id: stringValue(row, "reference_id"),
19197
- label: stringValue(row, "label"),
19198
- path: stringValue(row, "file_path"),
19199
- startLine: nullableNumber(row, "start_line"),
19200
- endLine: nullableNumber(row, "end_line"),
19201
- description: nullableString(row, "description")
19202
- }));
19214
+ codeReferenceStorage(kind) {
19215
+ return kind === "comment-post" ? { table: "comment_post_references", ownerColumn: "post_id" } : { table: "walkthrough_references", ownerColumn: "walkthrough_id" };
19216
+ }
19217
+ listCodeReferences(kind, ownerId) {
19218
+ const { table, ownerColumn } = this.codeReferenceStorage(kind);
19219
+ return this.database.prepare(`SELECT * FROM ${table} WHERE ${ownerColumn} = ? ORDER BY sort_order ASC`).all(ownerId).map(mapCodeReference);
19220
+ }
19221
+ insertCodeReferences(kind, ownerId, references) {
19222
+ if (references.length === 0) return;
19223
+ const { table, ownerColumn } = this.codeReferenceStorage(kind);
19224
+ const insertReference = this.database.prepare(
19225
+ `INSERT INTO ${table}(
19226
+ ${ownerColumn}, reference_id, label, file_path, start_line, end_line,
19227
+ description, sort_order
19228
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
19229
+ );
19230
+ references.forEach((reference, index2) => {
19231
+ insertReference.run(
19232
+ ownerId,
19233
+ reference.id,
19234
+ reference.label,
19235
+ reference.path,
19236
+ reference.startLine,
19237
+ reference.endLine,
19238
+ reference.description,
19239
+ index2
19240
+ );
19241
+ });
19203
19242
  }
19204
19243
  mapWalkthrough(row) {
19205
19244
  const id = stringValue(row, "id");
@@ -19212,7 +19251,7 @@ var RvwDatabase = class {
19212
19251
  body: stringValue(row, "body"),
19213
19252
  authorLabel: nullableString(row, "author_label"),
19214
19253
  diagramBindings: stringRecordValue(row, "diagram_bindings_json"),
19215
- references: this.listWalkthroughReferences(id),
19254
+ references: this.listCodeReferences("walkthrough", id),
19216
19255
  createdAt: stringValue(row, "created_at")
19217
19256
  };
19218
19257
  }
@@ -19258,7 +19297,7 @@ var RvwDatabase = class {
19258
19297
  JSON.stringify(input.diagramBindings),
19259
19298
  now
19260
19299
  );
19261
- this.insertWalkthroughReferences(id, input.references);
19300
+ this.insertCodeReferences("walkthrough", id, input.references);
19262
19301
  this.incrementChangeSequence();
19263
19302
  });
19264
19303
  const walkthrough = this.getWalkthrough(id);
@@ -19267,26 +19306,6 @@ var RvwDatabase = class {
19267
19306
  }
19268
19307
  return walkthrough;
19269
19308
  }
19270
- insertWalkthroughReferences(walkthroughId, references) {
19271
- const insertReference = this.database.prepare(
19272
- `INSERT INTO walkthrough_references(
19273
- walkthrough_id, reference_id, label, file_path, start_line, end_line,
19274
- description, sort_order
19275
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
19276
- );
19277
- references.forEach((reference, index2) => {
19278
- insertReference.run(
19279
- walkthroughId,
19280
- reference.id,
19281
- reference.label,
19282
- reference.path,
19283
- reference.startLine,
19284
- reference.endLine,
19285
- reference.description,
19286
- index2
19287
- );
19288
- });
19289
- }
19290
19309
  updateWalkthrough(id, input) {
19291
19310
  this.immediateTransaction(() => {
19292
19311
  const result = this.database.prepare(
@@ -19305,7 +19324,7 @@ var RvwDatabase = class {
19305
19324
  throw new RvwError("NOT_FOUND", "Walkthrough\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002", { status: 404 });
19306
19325
  }
19307
19326
  this.database.prepare("DELETE FROM walkthrough_references WHERE walkthrough_id = ?").run(id);
19308
- this.insertWalkthroughReferences(id, input.references);
19327
+ this.insertCodeReferences("walkthrough", id, input.references);
19309
19328
  this.incrementChangeSequence();
19310
19329
  });
19311
19330
  const walkthrough = this.getWalkthrough(id);
@@ -19363,8 +19382,17 @@ var RvwDatabase = class {
19363
19382
  ).run(id, input.pullRequestId, input.createdHeadOid, now, now);
19364
19383
  this.insertCommentTarget(id, input.target);
19365
19384
  this.database.prepare(
19366
- "INSERT INTO comment_posts(id, comment_id, body, related_commit_oid, author_label, is_root, created_at, updated_at) VALUES (?, ?, ?, NULL, ?, 1, ?, ?)"
19367
- ).run(postId, id, input.body, input.authorLabel ?? null, now, now);
19385
+ "INSERT INTO comment_posts(id, comment_id, body, related_commit_oid, author_label, is_root, created_at, updated_at) VALUES (?, ?, ?, ?, ?, 1, ?, ?)"
19386
+ ).run(
19387
+ postId,
19388
+ id,
19389
+ input.body,
19390
+ input.relatedCommitOid ?? null,
19391
+ input.authorLabel ?? null,
19392
+ now,
19393
+ now
19394
+ );
19395
+ this.insertCodeReferences("comment-post", postId, input.references ?? []);
19368
19396
  this.database.prepare(
19369
19397
  `INSERT INTO comment_post_events(
19370
19398
  post_id, comment_ref, pull_request_url, created_at
@@ -19520,6 +19548,7 @@ var RvwDatabase = class {
19520
19548
  commentId: comment.id,
19521
19549
  body: stringValue(row, "root_body"),
19522
19550
  relatedCommitOid: nullableString(row, "root_related_commit_oid"),
19551
+ references: [],
19523
19552
  authorLabel: nullableString(row, "root_author_label"),
19524
19553
  isRoot: true,
19525
19554
  createdAt: stringValue(row, "root_created_at"),
@@ -19533,7 +19562,14 @@ var RvwDatabase = class {
19533
19562
  listCommentPosts(commentId) {
19534
19563
  return this.database.prepare(
19535
19564
  "SELECT * FROM comment_posts WHERE comment_id = ? ORDER BY is_root DESC, created_at ASC, id ASC"
19536
- ).all(commentId).map(mapCommentPost);
19565
+ ).all(commentId).map((row) => {
19566
+ const postId = stringValue(row, "id");
19567
+ return mapCommentPost(row, this.listCodeReferences("comment-post", postId));
19568
+ });
19569
+ }
19570
+ getCommentPost(postId) {
19571
+ const row = this.database.prepare("SELECT * FROM comment_posts WHERE id = ?").get(postId);
19572
+ return row ? mapCommentPost(row, this.listCodeReferences("comment-post", postId)) : null;
19537
19573
  }
19538
19574
  insertReply(commentId, input, incrementSequence = true) {
19539
19575
  let result;
@@ -19553,7 +19589,8 @@ var RvwDatabase = class {
19553
19589
  commentId,
19554
19590
  body: input.body,
19555
19591
  relatedCommitOid,
19556
- authorLabel
19592
+ authorLabel,
19593
+ references: input.references ?? []
19557
19594
  })
19558
19595
  );
19559
19596
  if (idempotencyKeyHash !== null) {
@@ -19566,15 +19603,14 @@ var RvwDatabase = class {
19566
19603
  );
19567
19604
  }
19568
19605
  const postId = stringValue(existingRow, "post_id");
19569
- const postRow = this.database.prepare("SELECT * FROM comment_posts WHERE id = ?").get(postId);
19570
- if (!postRow) {
19606
+ const existing = this.getCommentPost(postId);
19607
+ if (!existing) {
19571
19608
  throw new RvwError(
19572
19609
  "IDEMPOTENCY_RESULT_DELETED",
19573
19610
  "\u3053\u306EidempotencyKey\u3067\u4F5C\u6210\u3057\u305Fcomment reply\u306F\u65E2\u306B\u524A\u9664\u3055\u308C\u3066\u3044\u307E\u3059\u3002",
19574
19611
  { details: { postId } }
19575
19612
  );
19576
19613
  }
19577
- const existing = mapCommentPost(postRow);
19578
19614
  result = existing;
19579
19615
  return;
19580
19616
  }
@@ -19584,6 +19620,7 @@ var RvwDatabase = class {
19584
19620
  this.database.prepare(
19585
19621
  "INSERT INTO comment_posts(id, comment_id, body, related_commit_oid, author_label, is_root, created_at, updated_at) VALUES (?, ?, ?, ?, ?, 0, ?, ?)"
19586
19622
  ).run(id, commentId, input.body, relatedCommitOid, authorLabel, now, now);
19623
+ this.insertCodeReferences("comment-post", id, input.references ?? []);
19587
19624
  this.database.prepare(
19588
19625
  `INSERT INTO comment_post_events(
19589
19626
  post_id, comment_ref, pull_request_url, created_at
@@ -19601,6 +19638,7 @@ var RvwDatabase = class {
19601
19638
  commentId,
19602
19639
  body: input.body,
19603
19640
  relatedCommitOid,
19641
+ references: input.references ?? [],
19604
19642
  authorLabel,
19605
19643
  isRoot: false,
19606
19644
  createdAt: now,
@@ -19612,7 +19650,7 @@ var RvwDatabase = class {
19612
19650
  if (!result) throw new RvwError("DATABASE_ERROR", "\u8FD4\u4FE1\u7D50\u679C\u3092\u8AAD\u307F\u51FA\u305B\u307E\u305B\u3093\u3002");
19613
19651
  return result;
19614
19652
  }
19615
- updateCommentPost(commentId, postId, body, relatedCommitOid) {
19653
+ updateCommentPost(commentId, postId, body, relatedCommitOid, references) {
19616
19654
  const now = (/* @__PURE__ */ new Date()).toISOString();
19617
19655
  this.immediateTransaction(() => {
19618
19656
  const result = relatedCommitOid === void 0 ? this.database.prepare(
@@ -19626,10 +19664,14 @@ var RvwDatabase = class {
19626
19664
  status: 404
19627
19665
  });
19628
19666
  }
19667
+ if (references !== void 0) {
19668
+ this.database.prepare("DELETE FROM comment_post_references WHERE post_id = ?").run(postId);
19669
+ this.insertCodeReferences("comment-post", postId, references);
19670
+ }
19629
19671
  this.database.prepare("UPDATE comments SET updated_at = ? WHERE id = ?").run(now, commentId);
19630
19672
  this.incrementChangeSequence();
19631
19673
  });
19632
- const post = this.listCommentPosts(commentId).find((candidate) => candidate.id === postId);
19674
+ const post = this.getCommentPost(postId);
19633
19675
  if (!post) {
19634
19676
  throw new RvwError("COMMENT_POST_NOT_FOUND", "\u30B3\u30E1\u30F3\u30C8\u6295\u7A3F\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002", {
19635
19677
  status: 404
@@ -19696,6 +19738,7 @@ var RvwDatabase = class {
19696
19738
  {
19697
19739
  body: update.reply,
19698
19740
  relatedCommitOid,
19741
+ references: update.references ?? [],
19699
19742
  authorLabel: update.authorLabel ?? "Agent",
19700
19743
  ...update.idempotencyKey === void 0 ? {} : { idempotencyKey: update.idempotencyKey },
19701
19744
  ...update.idempotencyRequestHash === void 0 ? {} : { idempotencyRequestHash: update.idempotencyRequestHash }
@@ -19716,8 +19759,8 @@ import path5 from "node:path";
19716
19759
  import { TextDecoder as TextDecoder2 } from "node:util";
19717
19760
 
19718
19761
  // src/shared/constants.ts
19719
- var APP_VERSION = "0.2.0";
19720
- var PROTOCOL_VERSION = 2;
19762
+ var APP_VERSION = "0.2.2";
19763
+ var PROTOCOL_VERSION = 3;
19721
19764
  var VIEWER_ID_HEADER = "x-rvw-viewer-id";
19722
19765
  var GIT_OBJECT_ID_PATTERN = /^[0-9a-f]{40,64}$/i;
19723
19766
  var MAX_TEXT_DOCUMENT_BYTES = 1024 * 1024;
@@ -19732,12 +19775,12 @@ var MAX_COMMENT_WATCH_LIMIT = 100;
19732
19775
  var DEFAULT_COMMENT_WATCH_INTERVAL_SECONDS = 10;
19733
19776
  var MAX_COMMENT_WATCH_INTERVAL_SECONDS = 300;
19734
19777
  var MAX_COMMENT_LIST_BODY_PREVIEW_BYTES = 512;
19778
+ var MAX_CODE_REFERENCES = 200;
19779
+ var MAX_CODE_REFERENCE_LABEL_CHARACTERS = 200;
19780
+ var MAX_CODE_REFERENCE_PATH_CHARACTERS = 4096;
19781
+ var MAX_CODE_REFERENCE_DESCRIPTION_CHARACTERS = 1e3;
19735
19782
  var MAX_WALKTHROUGH_BODY_BYTES = 256 * 1024;
19736
- var MAX_WALKTHROUGH_REFERENCES = 200;
19737
19783
  var MAX_WALKTHROUGH_TITLE_CHARACTERS = 200;
19738
- var MAX_WALKTHROUGH_REFERENCE_LABEL_CHARACTERS = 200;
19739
- var MAX_WALKTHROUGH_REFERENCE_PATH_CHARACTERS = 4096;
19740
- var MAX_WALKTHROUGH_REFERENCE_DESCRIPTION_CHARACTERS = 1e3;
19741
19784
  var MAX_SEARCH_QUERY_BYTES = 1024;
19742
19785
  var MAX_SEARCH_RESULTS = 500;
19743
19786
  var MAX_SEARCH_STDOUT_BYTES = 8 * 1024 * 1024;
@@ -27837,7 +27880,7 @@ function assertLinePair(startLine, endLine) {
27837
27880
  throw new RvwError("INVALID_INPUT", "\u884C\u7BC4\u56F2\u306F\u958B\u59CB\u884C\u3068\u7D42\u4E86\u884C\u3092\u4E21\u65B9\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
27838
27881
  }
27839
27882
  }
27840
- var walkthroughReferenceIdPattern = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
27883
+ var codeReferenceIdPattern = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
27841
27884
  var walkthroughDiagramNodePattern = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
27842
27885
  var mermaidIdentifierPattern = /[A-Za-z][A-Za-z0-9_-]{0,63}/g;
27843
27886
  var mermaidEdgePattern = /[<|o*x]*[-.=~]{2,}[|o*x>]*/g;
@@ -27931,7 +27974,7 @@ function addMermaidDiagramNodes(source, nodeIds) {
27931
27974
  }
27932
27975
  }
27933
27976
  }
27934
- function analyzeWalkthroughMarkdown(body) {
27977
+ function analyzeReferenceMarkdown(body) {
27935
27978
  const root = fromMarkdown(body);
27936
27979
  const definitions = /* @__PURE__ */ new Map();
27937
27980
  const visit = (node2, callback) => {
@@ -27960,9 +28003,9 @@ function analyzeWalkthroughMarkdown(body) {
27960
28003
  mermaidNodeIds
27961
28004
  };
27962
28005
  }
27963
- function assertWalkthroughPath(filePath) {
27964
- if (filePath.length > MAX_WALKTHROUGH_REFERENCE_PATH_CHARACTERS || filePath.includes("\\") || path6.posix.isAbsolute(filePath) || path6.posix.normalize(filePath) !== filePath || filePath === "." || filePath.startsWith("../")) {
27965
- throw new RvwError("INVALID_INPUT", `walkthrough\u306Epath\u304C\u4E0D\u6B63\u3067\u3059: ${filePath}`);
28006
+ function assertCodeReferencePath(filePath) {
28007
+ if (filePath.length > MAX_CODE_REFERENCE_PATH_CHARACTERS || filePath.includes("\\") || path6.posix.isAbsolute(filePath) || path6.posix.normalize(filePath) !== filePath || filePath === "." || filePath.startsWith("../")) {
28008
+ throw new RvwError("INVALID_INPUT", `code reference\u306Epath\u304C\u4E0D\u6B63\u3067\u3059: ${filePath}`);
27966
28009
  }
27967
28010
  }
27968
28011
  var RvwService = class {
@@ -28115,6 +28158,12 @@ var RvwService = class {
28115
28158
  `commentUpdates\u306B\u306Freply\u307E\u305F\u306Fresolve\u304C\u5FC5\u8981\u3067\u3059: ${update.commentRef}`
28116
28159
  );
28117
28160
  }
28161
+ if (!update.reply.trim() && (update.references?.length ?? 0) > 0) {
28162
+ throw new RvwError(
28163
+ "INVALID_INPUT",
28164
+ `reply\u306E\u306A\u3044comment update\u3078code reference\u306F\u8FFD\u52A0\u3067\u304D\u307E\u305B\u3093: ${update.commentRef}`
28165
+ );
28166
+ }
28118
28167
  if (update.reply.trim()) assertTextBody(update.reply);
28119
28168
  assertAuthorLabel(update.authorLabel);
28120
28169
  assertIdempotencyKey(update.idempotencyKey);
@@ -28123,6 +28172,7 @@ var RvwService = class {
28123
28172
  commentId,
28124
28173
  reply: update.reply,
28125
28174
  resolve: update.resolve,
28175
+ ...update.references === void 0 ? {} : { references: update.references },
28126
28176
  ...update.authorLabel === void 0 ? {} : { authorLabel: update.authorLabel },
28127
28177
  ...update.idempotencyKey === void 0 ? {} : { idempotencyKey: update.idempotencyKey },
28128
28178
  ...update.idempotencyKey === void 0 ? {} : {
@@ -28131,7 +28181,8 @@ var RvwService = class {
28131
28181
  commentId,
28132
28182
  reply: update.reply,
28133
28183
  resolve: update.resolve,
28134
- authorLabel
28184
+ authorLabel,
28185
+ references: update.references ?? []
28135
28186
  })
28136
28187
  }
28137
28188
  };
@@ -28157,6 +28208,19 @@ var RvwService = class {
28157
28208
  github.headOid
28158
28209
  );
28159
28210
  await this.git.ensureCommitRef(repository.worktreePath, github.number, github.headOid);
28211
+ for (const update of updates) {
28212
+ if (!update.reply.trim()) continue;
28213
+ const comment = this.database.getComment(update.commentId);
28214
+ if (!comment) {
28215
+ throw new RvwError("COMMENT_NOT_FOUND", "\u30B3\u30E1\u30F3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002");
28216
+ }
28217
+ await this.validateCodeReferences(this.getPullRequest(comment.pullRequestId), {
28218
+ sourceOid: github.headOid,
28219
+ body: update.reply,
28220
+ references: update.references ?? [],
28221
+ subject: "comment sync reply"
28222
+ });
28223
+ }
28160
28224
  const repositoryLocation = {
28161
28225
  localRepositoryPath: repository.worktreePath,
28162
28226
  gitCommonDir: repository.gitCommonDir
@@ -28393,6 +28457,90 @@ var RvwService = class {
28393
28457
  throw new RvwError("INVALID_INPUT", `${subject}\u306E\u884C\u7BC4\u56F2\u304C\u6587\u66F8\u5916\u3067\u3059\u3002`);
28394
28458
  }
28395
28459
  }
28460
+ async validateCodeReferences(pullRequest, input) {
28461
+ const markdown = analyzeReferenceMarkdown(input.body);
28462
+ if (input.references.length > MAX_CODE_REFERENCES) {
28463
+ throw new RvwError(
28464
+ "INVALID_INPUT",
28465
+ `${input.subject}\u306Ecode reference\u306F${MAX_CODE_REFERENCES}\u4EF6\u4EE5\u4E0B\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
28466
+ );
28467
+ }
28468
+ if ((input.references.length > 0 || markdown.referenceIds.length > 0) && !input.sourceOid) {
28469
+ throw new RvwError(
28470
+ "INVALID_INPUT",
28471
+ `${input.subject}\u3067code reference\u3092\u4F7F\u3046\u5834\u5408\u306Frelated commit\u304C\u5FC5\u8981\u3067\u3059\u3002`
28472
+ );
28473
+ }
28474
+ if (input.sourceOid) await this.assertCommitAvailable(pullRequest, input.sourceOid);
28475
+ const referenceIds = /* @__PURE__ */ new Set();
28476
+ for (const reference of input.references) {
28477
+ if (!codeReferenceIdPattern.test(reference.id) || referenceIds.has(reference.id)) {
28478
+ throw new RvwError(
28479
+ "INVALID_INPUT",
28480
+ `code reference ID\u304C\u4E0D\u6B63\u307E\u305F\u306F\u91CD\u8907\u3057\u3066\u3044\u307E\u3059: ${reference.id}`
28481
+ );
28482
+ }
28483
+ referenceIds.add(reference.id);
28484
+ assertCodeReferencePath(reference.path);
28485
+ if (reference.label.trim().length === 0 || reference.label.length > MAX_CODE_REFERENCE_LABEL_CHARACTERS) {
28486
+ throw new RvwError("INVALID_INPUT", `code reference label\u304C\u4E0D\u6B63\u3067\u3059: ${reference.id}`);
28487
+ }
28488
+ if (reference.description !== null && reference.description.length > MAX_CODE_REFERENCE_DESCRIPTION_CHARACTERS) {
28489
+ throw new RvwError(
28490
+ "INVALID_INPUT",
28491
+ `code reference description\u304C\u9577\u3059\u304E\u307E\u3059: ${reference.id}`
28492
+ );
28493
+ }
28494
+ const content3 = await this.getDocument({
28495
+ kind: "repository-file",
28496
+ pullRequestId: pullRequest.id,
28497
+ sourceOid: input.sourceOid,
28498
+ path: reference.path
28499
+ });
28500
+ if (content3.availability !== "available") {
28501
+ throw new RvwError("INVALID_INPUT", `code reference\u3092\u8868\u793A\u3067\u304D\u307E\u305B\u3093: ${reference.path}`);
28502
+ }
28503
+ this.validateLineRange(
28504
+ content3.text ?? "",
28505
+ reference.startLine,
28506
+ reference.endLine,
28507
+ `code reference ${reference.id}`
28508
+ );
28509
+ }
28510
+ const malformedReference = markdown.referenceIds.find(
28511
+ (referenceId) => !codeReferenceIdPattern.test(referenceId)
28512
+ );
28513
+ if (malformedReference !== void 0) {
28514
+ throw new RvwError(
28515
+ "INVALID_INPUT",
28516
+ `Markdown reference ID\u304C\u4E0D\u6B63\u3067\u3059: ${malformedReference || "(empty)"}`
28517
+ );
28518
+ }
28519
+ const missingReference = markdown.referenceIds.find(
28520
+ (referenceId) => !referenceIds.has(referenceId)
28521
+ );
28522
+ if (missingReference) {
28523
+ throw new RvwError(
28524
+ "INVALID_INPUT",
28525
+ `Markdown reference\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${missingReference}`
28526
+ );
28527
+ }
28528
+ const usedReferenceIds = /* @__PURE__ */ new Set([
28529
+ ...markdown.referenceIds,
28530
+ ...input.additionalUsedReferenceIds ?? []
28531
+ ]);
28532
+ const unusedReference = input.references.find(
28533
+ (reference) => !usedReferenceIds.has(reference.id)
28534
+ );
28535
+ if (unusedReference) {
28536
+ const usageSurface = input.additionalUsedReferenceIds === void 0 ? "\u672C\u6587" : "\u672C\u6587\u307E\u305F\u306Fbinding";
28537
+ throw new RvwError(
28538
+ "INVALID_INPUT",
28539
+ `code reference\u304C${usageSurface}\u304B\u3089\u53C2\u7167\u3055\u308C\u3066\u3044\u307E\u305B\u3093: ${unusedReference.id}`
28540
+ );
28541
+ }
28542
+ return markdown;
28543
+ }
28396
28544
  async prepareCommentTarget(pullRequest, target) {
28397
28545
  if (target.kind === "pull-request") return target;
28398
28546
  if (target.kind === "walkthrough") {
@@ -28454,13 +28602,24 @@ var RvwService = class {
28454
28602
  const pullRequest = this.getPullRequest(input.pullRequestId);
28455
28603
  const target = await this.prepareCommentTarget(pullRequest, input.target);
28456
28604
  assertAuthorLabel(input.authorLabel);
28457
- return this.database.createComment({
28605
+ const body = assertTextBody(input.body);
28606
+ const references = input.references ?? [];
28607
+ await this.validateCodeReferences(pullRequest, {
28608
+ sourceOid: input.relatedCommitOid ?? null,
28609
+ body,
28610
+ references,
28611
+ subject: "comment post"
28612
+ });
28613
+ const write = () => this.database.createComment({
28458
28614
  pullRequestId: pullRequest.id,
28459
28615
  createdHeadOid: pullRequest.latestHeadOid,
28460
28616
  target,
28461
- body: assertTextBody(input.body),
28617
+ body,
28618
+ ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
28619
+ references,
28462
28620
  ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel }
28463
28621
  });
28622
+ return input.relatedCommitOid ? await this.writeWithRetainedCommit(pullRequest, input.relatedCommitOid, "comment", write) : write();
28464
28623
  }
28465
28624
  async createCommentForReference(input) {
28466
28625
  const pullRequest = this.resolveStoredPullRequest(input.pullRequest);
@@ -28468,6 +28627,8 @@ var RvwService = class {
28468
28627
  pullRequestId: pullRequest.id,
28469
28628
  target: input.target,
28470
28629
  body: input.body,
28630
+ ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
28631
+ ...input.references === void 0 ? {} : { references: input.references },
28471
28632
  ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel }
28472
28633
  });
28473
28634
  }
@@ -28630,50 +28791,16 @@ var RvwService = class {
28630
28791
  `walkthrough\u672C\u6587\u306F1\u301C${MAX_WALKTHROUGH_BODY_BYTES} UTF-8 bytes\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
28631
28792
  );
28632
28793
  }
28633
- if (input.references.length === 0 || input.references.length > MAX_WALKTHROUGH_REFERENCES) {
28794
+ if (input.references.length === 0 || input.references.length > MAX_CODE_REFERENCES) {
28634
28795
  throw new RvwError(
28635
28796
  "INVALID_INPUT",
28636
- `walkthrough reference\u306F1\u301C${MAX_WALKTHROUGH_REFERENCES}\u4EF6\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
28797
+ `walkthrough reference\u306F1\u301C${MAX_CODE_REFERENCES}\u4EF6\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
28637
28798
  );
28638
28799
  }
28639
28800
  assertAuthorLabel(input.authorLabel);
28640
- const referenceIds = /* @__PURE__ */ new Set();
28641
- for (const reference of input.references) {
28642
- if (!walkthroughReferenceIdPattern.test(reference.id) || referenceIds.has(reference.id)) {
28643
- throw new RvwError(
28644
- "INVALID_INPUT",
28645
- `walkthrough reference ID\u304C\u4E0D\u6B63\u307E\u305F\u306F\u91CD\u8907\u3057\u3066\u3044\u307E\u3059: ${reference.id}`
28646
- );
28647
- }
28648
- referenceIds.add(reference.id);
28649
- assertWalkthroughPath(reference.path);
28650
- if (reference.label.trim().length === 0 || reference.label.length > MAX_WALKTHROUGH_REFERENCE_LABEL_CHARACTERS) {
28651
- throw new RvwError("INVALID_INPUT", `reference label\u304C\u4E0D\u6B63\u3067\u3059: ${reference.id}`);
28652
- }
28653
- if (reference.description !== null && reference.description.length > MAX_WALKTHROUGH_REFERENCE_DESCRIPTION_CHARACTERS) {
28654
- throw new RvwError("INVALID_INPUT", `reference description\u304C\u9577\u3059\u304E\u307E\u3059: ${reference.id}`);
28655
- }
28656
- const content3 = await this.getDocument({
28657
- kind: "repository-file",
28658
- pullRequestId: pullRequest.id,
28659
- sourceOid: input.sourceOid,
28660
- path: reference.path
28661
- });
28662
- if (content3.availability !== "available") {
28663
- throw new RvwError(
28664
- "INVALID_INPUT",
28665
- `walkthrough reference\u3092\u8868\u793A\u3067\u304D\u307E\u305B\u3093: ${reference.path}`
28666
- );
28667
- }
28668
- this.validateLineRange(
28669
- content3.text ?? "",
28670
- reference.startLine,
28671
- reference.endLine,
28672
- `walkthrough reference ${reference.id}`
28673
- );
28674
- }
28675
- const markdown = analyzeWalkthroughMarkdown(input.body);
28801
+ const markdown = analyzeReferenceMarkdown(input.body);
28676
28802
  const diagramBindings = input.diagramBindings ?? {};
28803
+ const referenceIds = new Set(input.references.map((reference) => reference.id));
28677
28804
  for (const [nodeId, referenceId] of Object.entries(diagramBindings)) {
28678
28805
  if (!walkthroughDiagramNodePattern.test(nodeId)) {
28679
28806
  throw new RvwError("INVALID_INPUT", `Mermaid node ID\u304C\u4E0D\u6B63\u3067\u3059: ${nodeId}`);
@@ -28691,35 +28818,13 @@ var RvwService = class {
28691
28818
  );
28692
28819
  }
28693
28820
  }
28694
- const markdownReferenceIds = markdown.referenceIds;
28695
- const malformedReference = markdownReferenceIds.find(
28696
- (referenceId) => !walkthroughReferenceIdPattern.test(referenceId)
28697
- );
28698
- if (malformedReference !== void 0) {
28699
- throw new RvwError(
28700
- "INVALID_INPUT",
28701
- `Markdown reference ID\u304C\u4E0D\u6B63\u3067\u3059: ${malformedReference || "(empty)"}`
28702
- );
28703
- }
28704
- const missingReference = markdownReferenceIds.find(
28705
- (referenceId) => !referenceIds.has(referenceId)
28706
- );
28707
- if (missingReference) {
28708
- throw new RvwError(
28709
- "INVALID_INPUT",
28710
- `Markdown reference\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${missingReference}`
28711
- );
28712
- }
28713
- const usedReferenceIds = /* @__PURE__ */ new Set([...markdownReferenceIds, ...Object.values(diagramBindings)]);
28714
- const unusedReference = input.references.find(
28715
- (reference) => !usedReferenceIds.has(reference.id)
28716
- );
28717
- if (unusedReference) {
28718
- throw new RvwError(
28719
- "INVALID_INPUT",
28720
- `walkthrough reference\u304C\u672C\u6587\u307E\u305F\u306FMermaid binding\u304B\u3089\u53C2\u7167\u3055\u308C\u3066\u3044\u307E\u305B\u3093: ${unusedReference.id}`
28721
- );
28722
- }
28821
+ await this.validateCodeReferences(pullRequest, {
28822
+ sourceOid: input.sourceOid,
28823
+ body: input.body,
28824
+ references: input.references,
28825
+ additionalUsedReferenceIds: Object.values(diagramBindings),
28826
+ subject: "Walkthrough"
28827
+ });
28723
28828
  return {
28724
28829
  sourceOid: input.sourceOid,
28725
28830
  title,
@@ -28729,7 +28834,7 @@ var RvwService = class {
28729
28834
  references: input.references
28730
28835
  };
28731
28836
  }
28732
- async writeWalkthroughWithRetainedCommit(pullRequest, sourceOid, write) {
28837
+ async writeWithRetainedCommit(pullRequest, sourceOid, subject, write) {
28733
28838
  const commitRef = await this.git.ensureCommitRef(
28734
28839
  pullRequest.localRepositoryPath,
28735
28840
  pullRequest.number,
@@ -28744,7 +28849,7 @@ var RvwService = class {
28744
28849
  } catch (cleanupError) {
28745
28850
  throw new RvwError(
28746
28851
  "LOCAL_STATE_INCONSISTENT",
28747
- "Walkthrough\u306E\u66F8\u304D\u8FBC\u307F\u5931\u6557\u5F8C\u306BGit ref\u3092\u5FA9\u5143\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002",
28852
+ `${subject}\u306E\u66F8\u304D\u8FBC\u307F\u5931\u6557\u5F8C\u306BGit ref\u3092\u5FA9\u5143\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002`,
28748
28853
  { cause: cleanupError }
28749
28854
  );
28750
28855
  }
@@ -28755,9 +28860,10 @@ var RvwService = class {
28755
28860
  async publishWalkthrough(input) {
28756
28861
  const pullRequest = this.resolveStoredPullRequest(input.pullRequest);
28757
28862
  const content3 = await this.validateWalkthroughContent(pullRequest, input);
28758
- return await this.writeWalkthroughWithRetainedCommit(
28863
+ return await this.writeWithRetainedCommit(
28759
28864
  pullRequest,
28760
28865
  content3.sourceOid,
28866
+ "Walkthrough",
28761
28867
  () => this.database.createWalkthrough({
28762
28868
  pullRequestId: pullRequest.id,
28763
28869
  ...content3
@@ -28770,9 +28876,10 @@ var RvwService = class {
28770
28876
  ...input,
28771
28877
  authorLabel: input.authorLabel === void 0 ? walkthrough.authorLabel : input.authorLabel
28772
28878
  });
28773
- return await this.writeWalkthroughWithRetainedCommit(
28879
+ return await this.writeWithRetainedCommit(
28774
28880
  pullRequest,
28775
28881
  content3.sourceOid,
28882
+ "Walkthrough",
28776
28883
  () => this.database.updateWalkthrough(walkthrough.id, content3)
28777
28884
  );
28778
28885
  }
@@ -28799,26 +28906,31 @@ var RvwService = class {
28799
28906
  throw new RvwError("COMMENT_NOT_FOUND", "\u30B3\u30E1\u30F3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002", { status: 404 });
28800
28907
  assertAuthorLabel(input.authorLabel);
28801
28908
  assertIdempotencyKey(input.idempotencyKey);
28802
- if (input.relatedCommitOid) {
28803
- await this.assertCommitAvailable(
28804
- this.getPullRequest(comment.pullRequestId),
28805
- input.relatedCommitOid
28806
- );
28807
- }
28909
+ const pullRequest = this.getPullRequest(comment.pullRequestId);
28808
28910
  const body = assertTextBody(input.body);
28809
- return this.database.insertReply(id, {
28911
+ const references = input.references ?? [];
28912
+ await this.validateCodeReferences(pullRequest, {
28913
+ sourceOid: input.relatedCommitOid ?? null,
28914
+ body,
28915
+ references,
28916
+ subject: "comment reply"
28917
+ });
28918
+ const write = () => this.database.insertReply(id, {
28810
28919
  ...input,
28811
28920
  body,
28921
+ references,
28812
28922
  ...input.idempotencyKey === void 0 ? {} : {
28813
28923
  idempotencyRequestHash: idempotencyRequestHash({
28814
28924
  operation: "comment.reply",
28815
28925
  commentId: id,
28816
28926
  body,
28817
28927
  relatedCommitOid: input.relatedCommitOid ?? null,
28818
- authorLabel: input.authorLabel ?? null
28928
+ authorLabel: input.authorLabel ?? null,
28929
+ references
28819
28930
  })
28820
28931
  }
28821
28932
  });
28933
+ return input.relatedCommitOid ? await this.writeWithRetainedCommit(pullRequest, input.relatedCommitOid, "comment", write) : write();
28822
28934
  }
28823
28935
  setCommentResolved(uriOrId, resolved) {
28824
28936
  const id = uriOrId.startsWith("rvw://") ? parseCommentUri(uriOrId) : uriOrId;
@@ -28828,8 +28940,19 @@ var RvwService = class {
28828
28940
  const id = uriOrId.startsWith("rvw://") ? parseCommentUri(uriOrId) : uriOrId;
28829
28941
  return this.database.deleteComment(id);
28830
28942
  }
28831
- updateCommentPost(commentId, postId, body) {
28832
- return this.database.updateCommentPost(commentId, postId, assertTextBody(body));
28943
+ async updateCommentPost(commentId, postId, body) {
28944
+ const comment = this.database.getComment(commentId);
28945
+ const post = comment?.posts.find((candidate) => candidate.id === postId);
28946
+ if (!comment || !post) {
28947
+ throw new RvwError("COMMENT_POST_NOT_FOUND", "\u30B3\u30E1\u30F3\u30C8\u6295\u7A3F\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002", {
28948
+ status: 404
28949
+ });
28950
+ }
28951
+ const usedReferenceIds = new Set(analyzeReferenceMarkdown(body).referenceIds);
28952
+ return await this.editCommentPost(commentId, postId, {
28953
+ body,
28954
+ references: post.references.filter((reference) => usedReferenceIds.has(reference.id))
28955
+ });
28833
28956
  }
28834
28957
  async editCommentPost(uriOrId, postId, input) {
28835
28958
  const commentId = uriOrId.startsWith("rvw://") ? parseCommentUri(uriOrId) : uriOrId;
@@ -28837,18 +28960,24 @@ var RvwService = class {
28837
28960
  if (!comment) {
28838
28961
  throw new RvwError("COMMENT_NOT_FOUND", "\u30B3\u30E1\u30F3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002", { status: 404 });
28839
28962
  }
28840
- if (input.relatedCommitOid) {
28841
- await this.assertCommitAvailable(
28842
- this.getPullRequest(comment.pullRequestId),
28843
- input.relatedCommitOid
28844
- );
28963
+ const post = comment.posts.find((candidate) => candidate.id === postId);
28964
+ if (!post) {
28965
+ throw new RvwError("COMMENT_POST_NOT_FOUND", "\u30B3\u30E1\u30F3\u30C8\u6295\u7A3F\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002", {
28966
+ status: 404
28967
+ });
28845
28968
  }
28846
- return this.database.updateCommentPost(
28847
- commentId,
28848
- postId,
28849
- assertTextBody(input.body),
28850
- input.relatedCommitOid
28851
- );
28969
+ const body = assertTextBody(input.body);
28970
+ const relatedCommitOid = input.relatedCommitOid === void 0 ? post.relatedCommitOid : input.relatedCommitOid;
28971
+ const references = input.references ?? post.references;
28972
+ const pullRequest = this.getPullRequest(comment.pullRequestId);
28973
+ await this.validateCodeReferences(pullRequest, {
28974
+ sourceOid: relatedCommitOid,
28975
+ body,
28976
+ references,
28977
+ subject: "comment post"
28978
+ });
28979
+ const write = () => this.database.updateCommentPost(commentId, postId, body, input.relatedCommitOid, references);
28980
+ return relatedCommitOid ? await this.writeWithRetainedCommit(pullRequest, relatedCommitOid, "comment", write) : write();
28852
28981
  }
28853
28982
  deleteReply(commentId, postId) {
28854
28983
  return this.database.deleteReply(commentId, postId);
@@ -32875,6 +33004,167 @@ var Hono2 = class extends Hono {
32875
33004
  }
32876
33005
  };
32877
33006
 
33007
+ // src/application/agent-command-schemas.ts
33008
+ var nonEmptyString = external_exports.string().min(1);
33009
+ var commentUri = external_exports.string().regex(/^rvw:\/\/comment\//);
33010
+ var walkthroughUri = external_exports.string().regex(/^rvw:\/\/walkthrough\//);
33011
+ var nullableCommentLine = external_exports.number().int().positive().nullable().optional().default(null);
33012
+ var idempotencyKey = external_exports.string().min(1).max(MAX_IDEMPOTENCY_KEY_CHARACTERS).optional();
33013
+ var commentTargetInputSchema = external_exports.union([
33014
+ external_exports.object({ kind: external_exports.literal("pull-request") }).strict(),
33015
+ external_exports.object({
33016
+ kind: external_exports.literal("walkthrough"),
33017
+ walkthroughId: external_exports.uuid(),
33018
+ startLine: nullableCommentLine,
33019
+ endLine: nullableCommentLine
33020
+ }).strict(),
33021
+ external_exports.object({
33022
+ kind: external_exports.literal("document"),
33023
+ documentKind: external_exports.literal("pull-request-markdown"),
33024
+ startLine: nullableCommentLine,
33025
+ endLine: nullableCommentLine
33026
+ }).strict(),
33027
+ external_exports.object({
33028
+ kind: external_exports.literal("document"),
33029
+ documentKind: external_exports.literal("repository-file"),
33030
+ sourceOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN),
33031
+ path: nonEmptyString,
33032
+ startLine: nullableCommentLine,
33033
+ endLine: nullableCommentLine
33034
+ }).strict()
33035
+ ]).superRefine((target, context) => {
33036
+ if (target.kind === "pull-request") return;
33037
+ if (target.startLine === null !== (target.endLine === null)) {
33038
+ context.addIssue({
33039
+ code: "custom",
33040
+ message: "startLine\u3068endLine\u306F\u4E21\u65B9\u6307\u5B9A\u3059\u308B\u304B\u3001\u4E21\u65B9\u7701\u7565\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33041
+ });
33042
+ return;
33043
+ }
33044
+ if (target.startLine !== null && target.endLine !== null && target.endLine < target.startLine) {
33045
+ context.addIssue({
33046
+ code: "custom",
33047
+ message: "endLine\u306FstartLine\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33048
+ });
33049
+ }
33050
+ });
33051
+ var codeReferenceInputSchema = external_exports.object({
33052
+ id: external_exports.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/),
33053
+ label: external_exports.string().min(1).max(MAX_CODE_REFERENCE_LABEL_CHARACTERS),
33054
+ path: external_exports.string().min(1).max(MAX_CODE_REFERENCE_PATH_CHARACTERS),
33055
+ startLine: external_exports.number().int().positive().nullable().optional().default(null),
33056
+ endLine: external_exports.number().int().positive().nullable().optional().default(null),
33057
+ description: external_exports.string().max(MAX_CODE_REFERENCE_DESCRIPTION_CHARACTERS).nullable()
33058
+ }).strict().superRefine((reference, context) => {
33059
+ if (reference.startLine === null !== (reference.endLine === null)) {
33060
+ context.addIssue({
33061
+ code: "custom",
33062
+ message: "startLine\u3068endLine\u306F\u4E21\u65B9\u6307\u5B9A\u3059\u308B\u304B\u3001\u4E21\u65B9\u7701\u7565\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33063
+ });
33064
+ return;
33065
+ }
33066
+ if (reference.startLine !== null && reference.endLine !== null && reference.endLine < reference.startLine) {
33067
+ context.addIssue({
33068
+ code: "custom",
33069
+ message: "endLine\u306FstartLine\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33070
+ });
33071
+ }
33072
+ });
33073
+ var optionalCodeReferences = external_exports.array(codeReferenceInputSchema).max(MAX_CODE_REFERENCES).optional();
33074
+ function requireRelatedCommitForReferences(input, context) {
33075
+ if ((input.references?.length ?? 0) > 0 && !input.relatedCommitOid) {
33076
+ context.addIssue({
33077
+ code: "custom",
33078
+ path: ["relatedCommitOid"],
33079
+ message: "code reference\u3092\u6301\u3064comment post\u306B\u306FrelatedCommitOid\u304C\u5FC5\u8981\u3067\u3059\u3002"
33080
+ });
33081
+ }
33082
+ }
33083
+ var commentCreateInputSchema = external_exports.object({
33084
+ pullRequest: nonEmptyString,
33085
+ target: commentTargetInputSchema,
33086
+ body: external_exports.string().min(1).refine((value) => value.trim().length > 0).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES, {
33087
+ message: `body\u306FUTF-8\u3067${MAX_COMMENT_BODY_BYTES} bytes\uFF0864 KiB\uFF09\u4EE5\u4E0B\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
33088
+ }),
33089
+ authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33090
+ relatedCommitOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN).nullable().optional(),
33091
+ references: optionalCodeReferences
33092
+ }).strict().superRefine(requireRelatedCommitForReferences);
33093
+ var commentReplyInputSchema = external_exports.object({
33094
+ body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES, {
33095
+ message: `body\u306FUTF-8\u3067${MAX_COMMENT_BODY_BYTES} bytes\uFF0864 KiB\uFF09\u4EE5\u4E0B\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
33096
+ }),
33097
+ authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33098
+ relatedCommitOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN).nullable().optional(),
33099
+ references: optionalCodeReferences,
33100
+ idempotencyKey
33101
+ }).strict().superRefine(requireRelatedCommitForReferences);
33102
+ var commentPostEditInputSchema = external_exports.object({
33103
+ body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES, {
33104
+ message: `body\u306FUTF-8\u3067${MAX_COMMENT_BODY_BYTES} bytes\uFF0864 KiB\uFF09\u4EE5\u4E0B\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
33105
+ }),
33106
+ relatedCommitOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN).nullable().optional(),
33107
+ references: optionalCodeReferences
33108
+ }).strict();
33109
+ var pullRequestSyncInputSchema = external_exports.object({
33110
+ pullRequest: nonEmptyString,
33111
+ commentUpdates: external_exports.array(
33112
+ external_exports.object({
33113
+ commentRef: commentUri,
33114
+ reply: external_exports.string().refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES, {
33115
+ message: `reply\u306FUTF-8\u3067${MAX_COMMENT_BODY_BYTES} bytes\uFF0864 KiB\uFF09\u4EE5\u4E0B\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
33116
+ }),
33117
+ resolve: external_exports.boolean(),
33118
+ references: optionalCodeReferences,
33119
+ idempotencyKey
33120
+ }).strict()
33121
+ ).max(500).optional()
33122
+ }).strict();
33123
+ var walkthroughContentInputSchema = external_exports.object({
33124
+ sourceOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN),
33125
+ title: external_exports.string().min(1).max(MAX_WALKTHROUGH_TITLE_CHARACTERS),
33126
+ body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_WALKTHROUGH_BODY_BYTES),
33127
+ authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33128
+ diagramBindings: external_exports.record(external_exports.string(), external_exports.string()).optional(),
33129
+ references: external_exports.array(codeReferenceInputSchema).min(1).max(MAX_CODE_REFERENCES)
33130
+ }).strict();
33131
+ var walkthroughPublishInputSchema = walkthroughContentInputSchema.extend({
33132
+ pullRequest: nonEmptyString
33133
+ });
33134
+ var walkthroughUpdateInputSchema = walkthroughContentInputSchema;
33135
+ var agentCommandInputSchemas = {
33136
+ doctor: external_exports.object({ cwd: nonEmptyString }).strict(),
33137
+ "pr.refresh": external_exports.object({ reference: nonEmptyString }).strict(),
33138
+ "pr.sync": pullRequestSyncInputSchema.extend({
33139
+ repositoryPath: nonEmptyString.optional(),
33140
+ allowUntracked: external_exports.boolean().default(false)
33141
+ }),
33142
+ "pr.attach": external_exports.object({ reference: nonEmptyString, repositoryPath: nonEmptyString }).strict(),
33143
+ "pr.reset.preview": external_exports.object({ reference: nonEmptyString }).strict(),
33144
+ "pr.reset": external_exports.object({ reference: nonEmptyString, confirmed: external_exports.literal(true) }).strict(),
33145
+ "comment.list": external_exports.object({
33146
+ reference: nonEmptyString,
33147
+ resolved: external_exports.boolean().optional(),
33148
+ limit: external_exports.number().int().min(1).max(MAX_COMMENT_LIST_LIMIT).default(DEFAULT_COMMENT_LIST_LIMIT),
33149
+ offset: external_exports.number().int().min(0).default(0)
33150
+ }).strict(),
33151
+ "comment.watch": external_exports.object({
33152
+ cursor: external_exports.string().min(1).max(512).optional(),
33153
+ limit: external_exports.number().int().min(1).max(MAX_COMMENT_WATCH_LIMIT)
33154
+ }).strict(),
33155
+ "comment.create": commentCreateInputSchema,
33156
+ "comment.get": external_exports.object({ uri: commentUri, live: external_exports.boolean().default(false) }).strict(),
33157
+ "comment.reply": external_exports.object({ uri: commentUri, reply: commentReplyInputSchema }).strict(),
33158
+ "comment.edit": external_exports.object({ uri: commentUri, postId: nonEmptyString, edit: commentPostEditInputSchema }).strict(),
33159
+ "comment.resolve": external_exports.object({ uri: commentUri }).strict(),
33160
+ "comment.reopen": external_exports.object({ uri: commentUri }).strict(),
33161
+ "walkthrough.get": external_exports.object({ uri: walkthroughUri }).strict(),
33162
+ "walkthrough.publish": walkthroughPublishInputSchema,
33163
+ "walkthrough.update": external_exports.object({ uri: walkthroughUri, content: walkthroughUpdateInputSchema }).strict(),
33164
+ "walkthrough.delete.preview": external_exports.object({ uri: walkthroughUri }).strict(),
33165
+ "walkthrough.delete": external_exports.object({ uri: walkthroughUri, confirmed: external_exports.literal(true) }).strict()
33166
+ };
33167
+
32878
33168
  // src/server/schemas.ts
32879
33169
  var nullableLine = external_exports.number().int().positive().nullable();
32880
33170
  var commentTargetSchema = external_exports.union([
@@ -32912,15 +33202,35 @@ var createCommentSchema = external_exports.object({
32912
33202
  pullRequestId: external_exports.uuid(),
32913
33203
  target: commentTargetSchema,
32914
33204
  body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES),
32915
- authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional()
33205
+ authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33206
+ relatedCommitOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN).nullable().optional(),
33207
+ references: external_exports.array(codeReferenceInputSchema).optional()
33208
+ }).superRefine((input, context) => {
33209
+ if ((input.references?.length ?? 0) > 0 && !input.relatedCommitOid) {
33210
+ context.addIssue({
33211
+ code: "custom",
33212
+ path: ["relatedCommitOid"],
33213
+ message: "code reference\u3092\u6301\u3064comment post\u306B\u306FrelatedCommitOid\u304C\u5FC5\u8981\u3067\u3059\u3002"
33214
+ });
33215
+ }
32916
33216
  });
32917
33217
  var replySchema = external_exports.object({
32918
33218
  body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES),
32919
33219
  relatedCommitOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN).nullable().optional(),
32920
- authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional()
33220
+ authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33221
+ references: external_exports.array(codeReferenceInputSchema).optional()
33222
+ }).superRefine((input, context) => {
33223
+ if ((input.references?.length ?? 0) > 0 && !input.relatedCommitOid) {
33224
+ context.addIssue({
33225
+ code: "custom",
33226
+ path: ["relatedCommitOid"],
33227
+ message: "code reference\u3092\u6301\u3064comment post\u306B\u306FrelatedCommitOid\u304C\u5FC5\u8981\u3067\u3059\u3002"
33228
+ });
33229
+ }
32921
33230
  });
32922
33231
  var editCommentPostSchema = external_exports.object({
32923
- body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES)
33232
+ body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES),
33233
+ references: external_exports.array(codeReferenceInputSchema).optional()
32924
33234
  });
32925
33235
 
32926
33236
  // src/server/app.ts
@@ -33172,6 +33482,8 @@ function createApp(service, options) {
33172
33482
  pullRequestId: input.pullRequestId,
33173
33483
  target: input.target,
33174
33484
  body: input.body,
33485
+ ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
33486
+ ...input.references === void 0 ? {} : { references: input.references },
33175
33487
  ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel }
33176
33488
  })
33177
33489
  },
@@ -33186,7 +33498,8 @@ function createApp(service, options) {
33186
33498
  post: await service.replyToComment(context.req.param("id"), {
33187
33499
  body: input.body,
33188
33500
  ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
33189
- ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel }
33501
+ ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel },
33502
+ ...input.references === void 0 ? {} : { references: input.references }
33190
33503
  })
33191
33504
  },
33192
33505
  201
@@ -33196,11 +33509,14 @@ function createApp(service, options) {
33196
33509
  const input = editCommentPostSchema.parse(await context.req.json());
33197
33510
  return context.json({
33198
33511
  ok: true,
33199
- post: service.updateCommentPost(
33512
+ post: input.references === void 0 ? await service.updateCommentPost(
33200
33513
  context.req.param("id"),
33201
33514
  context.req.param("postId"),
33202
33515
  input.body
33203
- )
33516
+ ) : await service.editCommentPost(context.req.param("id"), context.req.param("postId"), {
33517
+ body: input.body,
33518
+ references: input.references
33519
+ })
33204
33520
  });
33205
33521
  });
33206
33522
  app.delete(
@@ -33430,143 +33746,6 @@ import {
33430
33746
  import net from "node:net";
33431
33747
  import os4 from "node:os";
33432
33748
  import path9 from "node:path";
33433
-
33434
- // src/application/agent-command-schemas.ts
33435
- var nonEmptyString = external_exports.string().min(1);
33436
- var commentUri = external_exports.string().regex(/^rvw:\/\/comment\//);
33437
- var walkthroughUri = external_exports.string().regex(/^rvw:\/\/walkthrough\//);
33438
- var nullableCommentLine = external_exports.number().int().positive().nullable().optional().default(null);
33439
- var idempotencyKey = external_exports.string().min(1).max(MAX_IDEMPOTENCY_KEY_CHARACTERS).optional();
33440
- var commentTargetInputSchema = external_exports.union([
33441
- external_exports.object({ kind: external_exports.literal("pull-request") }).strict(),
33442
- external_exports.object({
33443
- kind: external_exports.literal("walkthrough"),
33444
- walkthroughId: external_exports.uuid(),
33445
- startLine: nullableCommentLine,
33446
- endLine: nullableCommentLine
33447
- }).strict(),
33448
- external_exports.object({
33449
- kind: external_exports.literal("document"),
33450
- documentKind: external_exports.literal("pull-request-markdown"),
33451
- startLine: nullableCommentLine,
33452
- endLine: nullableCommentLine
33453
- }).strict(),
33454
- external_exports.object({
33455
- kind: external_exports.literal("document"),
33456
- documentKind: external_exports.literal("repository-file"),
33457
- sourceOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN),
33458
- path: nonEmptyString,
33459
- startLine: nullableCommentLine,
33460
- endLine: nullableCommentLine
33461
- }).strict()
33462
- ]).superRefine((target, context) => {
33463
- if (target.kind === "pull-request") return;
33464
- if (target.startLine === null !== (target.endLine === null)) {
33465
- context.addIssue({
33466
- code: "custom",
33467
- message: "startLine\u3068endLine\u306F\u4E21\u65B9\u6307\u5B9A\u3059\u308B\u304B\u3001\u4E21\u65B9\u7701\u7565\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33468
- });
33469
- return;
33470
- }
33471
- if (target.startLine !== null && target.endLine !== null && target.endLine < target.startLine) {
33472
- context.addIssue({
33473
- code: "custom",
33474
- message: "endLine\u306FstartLine\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33475
- });
33476
- }
33477
- });
33478
- var commentCreateInputSchema = external_exports.object({
33479
- pullRequest: nonEmptyString,
33480
- target: commentTargetInputSchema,
33481
- body: external_exports.string().min(1).refine((value) => value.trim().length > 0).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES),
33482
- authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional()
33483
- }).strict();
33484
- var commentReplyInputSchema = external_exports.object({
33485
- body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES),
33486
- authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33487
- relatedCommitOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN).nullable().optional(),
33488
- idempotencyKey
33489
- }).strict();
33490
- var commentPostEditInputSchema = commentReplyInputSchema.pick({ body: true, relatedCommitOid: true }).strict();
33491
- var pullRequestSyncInputSchema = external_exports.object({
33492
- pullRequest: nonEmptyString,
33493
- commentUpdates: external_exports.array(
33494
- external_exports.object({
33495
- commentRef: commentUri,
33496
- reply: external_exports.string().refine((value) => Buffer.byteLength(value, "utf8") <= MAX_COMMENT_BODY_BYTES),
33497
- resolve: external_exports.boolean(),
33498
- idempotencyKey
33499
- }).strict()
33500
- ).max(500).optional()
33501
- }).strict();
33502
- var walkthroughReferenceInputSchema = external_exports.object({
33503
- id: external_exports.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/),
33504
- label: external_exports.string().min(1).max(MAX_WALKTHROUGH_REFERENCE_LABEL_CHARACTERS),
33505
- path: external_exports.string().min(1).max(MAX_WALKTHROUGH_REFERENCE_PATH_CHARACTERS),
33506
- startLine: external_exports.number().int().positive().nullable().optional().default(null),
33507
- endLine: external_exports.number().int().positive().nullable().optional().default(null),
33508
- description: external_exports.string().max(MAX_WALKTHROUGH_REFERENCE_DESCRIPTION_CHARACTERS).nullable()
33509
- }).strict().superRefine((reference, context) => {
33510
- if (reference.startLine === null !== (reference.endLine === null)) {
33511
- context.addIssue({
33512
- code: "custom",
33513
- message: "startLine\u3068endLine\u306F\u4E21\u65B9\u6307\u5B9A\u3059\u308B\u304B\u3001\u4E21\u65B9\u7701\u7565\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33514
- });
33515
- return;
33516
- }
33517
- if (reference.startLine !== null && reference.endLine !== null && reference.endLine < reference.startLine) {
33518
- context.addIssue({
33519
- code: "custom",
33520
- message: "endLine\u306FstartLine\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
33521
- });
33522
- }
33523
- });
33524
- var walkthroughContentInputSchema = external_exports.object({
33525
- sourceOid: external_exports.string().regex(GIT_OBJECT_ID_PATTERN),
33526
- title: external_exports.string().min(1).max(MAX_WALKTHROUGH_TITLE_CHARACTERS),
33527
- body: external_exports.string().min(1).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_WALKTHROUGH_BODY_BYTES),
33528
- authorLabel: external_exports.string().max(MAX_AUTHOR_LABEL_CHARACTERS).nullable().optional(),
33529
- diagramBindings: external_exports.record(external_exports.string(), external_exports.string()).optional(),
33530
- references: external_exports.array(walkthroughReferenceInputSchema).min(1).max(MAX_WALKTHROUGH_REFERENCES)
33531
- }).strict();
33532
- var walkthroughPublishInputSchema = walkthroughContentInputSchema.extend({
33533
- pullRequest: nonEmptyString
33534
- });
33535
- var walkthroughUpdateInputSchema = walkthroughContentInputSchema;
33536
- var agentCommandInputSchemas = {
33537
- doctor: external_exports.object({ cwd: nonEmptyString }).strict(),
33538
- "pr.refresh": external_exports.object({ reference: nonEmptyString }).strict(),
33539
- "pr.sync": pullRequestSyncInputSchema.extend({
33540
- repositoryPath: nonEmptyString.optional(),
33541
- allowUntracked: external_exports.boolean().default(false)
33542
- }),
33543
- "pr.attach": external_exports.object({ reference: nonEmptyString, repositoryPath: nonEmptyString }).strict(),
33544
- "pr.reset.preview": external_exports.object({ reference: nonEmptyString }).strict(),
33545
- "pr.reset": external_exports.object({ reference: nonEmptyString, confirmed: external_exports.literal(true) }).strict(),
33546
- "comment.list": external_exports.object({
33547
- reference: nonEmptyString,
33548
- resolved: external_exports.boolean().optional(),
33549
- limit: external_exports.number().int().min(1).max(MAX_COMMENT_LIST_LIMIT).default(DEFAULT_COMMENT_LIST_LIMIT),
33550
- offset: external_exports.number().int().min(0).default(0)
33551
- }).strict(),
33552
- "comment.watch": external_exports.object({
33553
- cursor: external_exports.string().min(1).max(512).optional(),
33554
- limit: external_exports.number().int().min(1).max(MAX_COMMENT_WATCH_LIMIT)
33555
- }).strict(),
33556
- "comment.create": commentCreateInputSchema,
33557
- "comment.get": external_exports.object({ uri: commentUri, live: external_exports.boolean().default(false) }).strict(),
33558
- "comment.reply": external_exports.object({ uri: commentUri, reply: commentReplyInputSchema }).strict(),
33559
- "comment.edit": external_exports.object({ uri: commentUri, postId: nonEmptyString, edit: commentPostEditInputSchema }).strict(),
33560
- "comment.resolve": external_exports.object({ uri: commentUri }).strict(),
33561
- "comment.reopen": external_exports.object({ uri: commentUri }).strict(),
33562
- "walkthrough.get": external_exports.object({ uri: walkthroughUri }).strict(),
33563
- "walkthrough.publish": walkthroughPublishInputSchema,
33564
- "walkthrough.update": external_exports.object({ uri: walkthroughUri, content: walkthroughUpdateInputSchema }).strict(),
33565
- "walkthrough.delete.preview": external_exports.object({ uri: walkthroughUri }).strict(),
33566
- "walkthrough.delete": external_exports.object({ uri: walkthroughUri, confirmed: external_exports.literal(true) }).strict()
33567
- };
33568
-
33569
- // src/server/agent-socket.ts
33570
33749
  var MAX_CLI_STDIN_BYTES = 40 * 1024 * 1024;
33571
33750
  var MAX_AGENT_MESSAGE_BYTES = MAX_CLI_STDIN_BYTES + 64 * 1024;
33572
33751
  var AGENT_SOCKET_PROTOCOL_VERSION = 1;
@@ -33724,7 +33903,8 @@ async function dispatchAgentSocketRequest(service, rawRequest) {
33724
33903
  const input = parseOperationInput("comment.edit", request.input);
33725
33904
  return await service.editCommentPost(input.uri, input.postId, {
33726
33905
  body: input.edit.body,
33727
- ...input.edit.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.edit.relatedCommitOid }
33906
+ ...input.edit.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.edit.relatedCommitOid },
33907
+ ...input.edit.references === void 0 ? {} : { references: input.edit.references }
33728
33908
  });
33729
33909
  }
33730
33910
  case "comment.resolve": {
@@ -34373,11 +34553,20 @@ var commentPlacementOutputSchema = external_exports.union([
34373
34553
  path: external_exports.string().nullable()
34374
34554
  }).strict()
34375
34555
  ]);
34556
+ var codeReferenceOutputSchema = external_exports.object({
34557
+ id: external_exports.string(),
34558
+ label: external_exports.string(),
34559
+ path: external_exports.string(),
34560
+ startLine: external_exports.number().int().nullable(),
34561
+ endLine: external_exports.number().int().nullable(),
34562
+ description: external_exports.string().nullable()
34563
+ }).strict();
34376
34564
  var commentPostOutputSchema = external_exports.object({
34377
34565
  id: external_exports.string(),
34378
34566
  commentId: external_exports.string(),
34379
34567
  body: external_exports.string(),
34380
34568
  relatedCommitOid: external_exports.string().nullable(),
34569
+ references: external_exports.array(codeReferenceOutputSchema),
34381
34570
  authorLabel: external_exports.string().nullable(),
34382
34571
  isRoot: external_exports.boolean(),
34383
34572
  createdAt: external_exports.string(),
@@ -34404,16 +34593,7 @@ var walkthroughOutputSchema = external_exports.object({
34404
34593
  body: external_exports.string(),
34405
34594
  authorLabel: external_exports.string().nullable(),
34406
34595
  diagramBindings: external_exports.record(external_exports.string(), external_exports.string()),
34407
- references: external_exports.array(
34408
- external_exports.object({
34409
- id: external_exports.string(),
34410
- label: external_exports.string(),
34411
- path: external_exports.string(),
34412
- startLine: external_exports.number().int().nullable(),
34413
- endLine: external_exports.number().int().nullable(),
34414
- description: external_exports.string().nullable()
34415
- }).strict()
34416
- ),
34596
+ references: external_exports.array(codeReferenceOutputSchema),
34417
34597
  createdAt: external_exports.string()
34418
34598
  }).strict();
34419
34599
  var sourceExcerptOutputSchema = external_exports.object({
@@ -35020,6 +35200,7 @@ function createProgram(runtimeFactory = defaultRuntimeFactory) {
35020
35200
  "comment.read",
35021
35201
  "comment.reply",
35022
35202
  "comment.edit",
35203
+ "comment.codeReferences",
35023
35204
  "comment.resolve",
35024
35205
  "comment.reopen",
35025
35206
  "pullRequest.sync",
@@ -35131,7 +35312,7 @@ function createProgram(runtimeFactory = defaultRuntimeFactory) {
35131
35312
  writeOutput(
35132
35313
  options,
35133
35314
  result2,
35134
- `\u524A\u9664\u5BFE\u8C61: \u30B3\u30E1\u30F3\u30C8${preview.counts.comments}\u3001\u8FD4\u4FE1${preview.counts.posts}\u3001\u5BFE\u8C61${preview.counts.targets}\u3001Walkthrough${preview.counts.walkthroughs}\u3001\u30B3\u30FC\u30C9\u53C2\u7167${preview.counts.walkthroughReferences}\u3001Git ref${preview.counts.gitRefs}
35315
+ `\u524A\u9664\u5BFE\u8C61: \u30B3\u30E1\u30F3\u30C8${preview.counts.comments}\u3001\u8FD4\u4FE1${preview.counts.posts}\u3001\u30B3\u30E1\u30F3\u30C8\u5185\u30B3\u30FC\u30C9\u53C2\u7167${preview.counts.commentReferences}\u3001\u5BFE\u8C61${preview.counts.targets}\u3001Walkthrough${preview.counts.walkthroughs}\u3001Walkthrough\u30B3\u30FC\u30C9\u53C2\u7167${preview.counts.walkthroughReferences}\u3001Git ref${preview.counts.gitRefs}
35135
35316
  \u7D9A\u884C\u3059\u308B\u306B\u306F --yes \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
35136
35317
  );
35137
35318
  process.exitCode = 2;
@@ -35277,7 +35458,9 @@ function createProgram(runtimeFactory = defaultRuntimeFactory) {
35277
35458
  pullRequest: input.pullRequest,
35278
35459
  target: input.target,
35279
35460
  body: input.body,
35280
- ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel }
35461
+ ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel },
35462
+ ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
35463
+ ...input.references === void 0 ? {} : { references: input.references }
35281
35464
  };
35282
35465
  const created = await callService(
35283
35466
  "comment.create",
@@ -35319,6 +35502,7 @@ function createProgram(runtimeFactory = defaultRuntimeFactory) {
35319
35502
  body: input.body,
35320
35503
  ...input.authorLabel === void 0 ? {} : { authorLabel: input.authorLabel },
35321
35504
  ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
35505
+ ...input.references === void 0 ? {} : { references: input.references },
35322
35506
  ...input.idempotencyKey === void 0 ? {} : { idempotencyKey: input.idempotencyKey }
35323
35507
  };
35324
35508
  const post = await callService(
@@ -35332,7 +35516,8 @@ function createProgram(runtimeFactory = defaultRuntimeFactory) {
35332
35516
  const input = commentPostEditInputSchema.parse(await readStdinJson());
35333
35517
  const edit = {
35334
35518
  body: input.body,
35335
- ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid }
35519
+ ...input.relatedCommitOid === void 0 ? {} : { relatedCommitOid: input.relatedCommitOid },
35520
+ ...input.references === void 0 ? {} : { references: input.references }
35336
35521
  };
35337
35522
  const post = await callService(
35338
35523
  "comment.edit",