dsh-remote-vs 0.15.1 → 0.16.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/lib/client.js CHANGED
@@ -740,6 +740,14 @@ window.__ModuleLoader__.load({
740
740
  "scm.commitDiff": "提交差异",
741
741
  "scm.checkoutCommitTitle": "检出提交(分离头指针)",
742
742
  "scm.checkoutCommitText": "将把远端工作区切到 {hash},处于分离头指针状态。",
743
+ "scm.aiReview": "让 AI 审查此 diff(只追加到对话草稿,不会自动发送)",
744
+ "scm.aiReviewNoSession": "当前会话与这个远端工作区没有绑定:绑定后才能把 diff 交给 AI 审查",
745
+ "scm.aiReviewNoContext": "插件上下文尚未就绪,暂时无法写入对话草稿",
746
+ "scm.aiReviewNoChannel": "当前宿主没有可用的对话输入通道,无法写入草稿(宿主版本可能不兼容)",
747
+ "scm.aiReviewAdded": "已追加到对话草稿,请检查后发送",
748
+ "scm.aiReviewAddedSummary": "diff 较大(或已被截断),已按摘要方式追加到草稿,请检查后发送",
749
+ "scm.aiReviewAddedRead": "该文件没有可内嵌的 diff 文本(新增或未跟踪),已让 AI 自行读取,请检查后发送",
750
+ "scm.aiReviewFailed": "追加失败:当前会话的输入框不可用(可能正在发送或校验中),请稍后重试",
743
751
  "history.filter": "过滤提交(信息 / 作者 / 哈希)",
744
752
  "history.details": "提交详情",
745
753
  "history.content": "内容",
@@ -767,6 +775,8 @@ window.__ModuleLoader__.load({
767
775
  "history.copyMessage": "复制提交信息",
768
776
  "history.copyFilePatch": "复制该文件补丁",
769
777
  "history.copyCommitPatch": "复制整个补丁",
778
+ "history.aiReview": "让 AI 审查此提交(只追加到对话草稿,不会自动发送)",
779
+ "history.aiReviewNoPatch": "该提交的 patch 尚未加载完成,或没有可内嵌的文本 diff",
770
780
  "history.copiedMessage": "已复制提交信息",
771
781
  "history.copiedHash": "已复制完整哈希",
772
782
  "history.copiedSubject": "已复制提交标题",
@@ -1265,6 +1275,14 @@ window.__ModuleLoader__.load({
1265
1275
  "scm.commitDiff": "commit diff",
1266
1276
  "scm.checkoutCommitTitle": "Check out commit (detached HEAD)",
1267
1277
  "scm.checkoutCommitText": "The remote working tree switches to {hash} in detached HEAD state.",
1278
+ "scm.aiReview": "Ask AI to review this diff (appends to the conversation draft; nothing is sent automatically)",
1279
+ "scm.aiReviewNoSession": "No session is bound to this remote workspace — binding one is what lets the diff be handed to AI",
1280
+ "scm.aiReviewNoContext": "The plugin context is not ready yet, so the draft cannot be written",
1281
+ "scm.aiReviewNoChannel": "This host exposes no conversation input channel, so the draft cannot be written (the host version may be incompatible)",
1282
+ "scm.aiReviewAdded": "Appended to the conversation draft — check it, then send",
1283
+ "scm.aiReviewAddedSummary": "Large (or truncated) diff: appended as a summary — check it, then send",
1284
+ "scm.aiReviewAddedRead": "This file has no inline diff (added or untracked), so AI was asked to read it — check the draft, then send",
1285
+ "scm.aiReviewFailed": "Append failed: this session’s composer is not writable right now (it may be sending) — try again later",
1268
1286
  "history.filter": "Filter commits (message / author / hash)",
1269
1287
  "history.details": "Commit details",
1270
1288
  "history.content": "Contents",
@@ -1292,6 +1310,8 @@ window.__ModuleLoader__.load({
1292
1310
  "history.copyMessage": "Copy commit message",
1293
1311
  "history.copyFilePatch": "Copy file patch",
1294
1312
  "history.copyCommitPatch": "Copy whole patch",
1313
+ "history.aiReview": "Ask AI to review this commit (appends to the conversation draft; nothing is sent automatically)",
1314
+ "history.aiReviewNoPatch": "This commit’s patch is not loaded yet, or it has no inline textual diff",
1295
1315
  "history.copiedMessage": "Commit message copied",
1296
1316
  "history.copiedHash": "Full hash copied",
1297
1317
  "history.copiedSubject": "Subject copied",
@@ -37699,6 +37719,23 @@ window.__ModuleLoader__.load({
37699
37719
  }
37700
37720
  }
37701
37721
  /**
37722
+ * Whether this session has a usable draft-insert channel right now.
37723
+ *
37724
+ * A PREFLIGHT for surfaces that must not offer an action they cannot complete
37725
+ * (the diff view's "review this diff with AI" button): the conversation service
37726
+ * is a soft, version-dependent read (see {@link conversationOf}), so on a host
37727
+ * that does not expose it the button has to say so up front instead of failing
37728
+ * on click with a message about a busy composer — a wrong cause is worse than no
37729
+ * button.
37730
+ *
37731
+ * Read-only and side-effect free on purpose: it never calls
37732
+ * `input.for()` (resolving the facade could materialise a per-session input
37733
+ * shell), so it can run on every render of the owning view.
37734
+ */
37735
+ function canInsertDraft(ctx, sessionId) {
37736
+ return sessionScope(ctx, sessionId) !== void 0 && conversationOf(ctx) !== void 0;
37737
+ }
37738
+ /**
37702
37739
  * Mint one reference chip through the host's public `insertReference` facade —
37703
37740
  * the same method the native `@` picker's event listener calls, so the
37704
37741
  * composer shows a compact chip while the model receives `reference.text`.
@@ -40688,7 +40725,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
40688
40725
  const primary = host.querySelectorAll("[class*=\"rvs-ck-\"]").length;
40689
40726
  const fallback = host.querySelectorAll("span[class^=\"rvs-t-\"]").length;
40690
40727
  const count = primary > 0 ? primary : fallback;
40691
- console.info(`[dsh-remote-vs] build 1102-1023 · ${source} · colored tokens: ${count} (${propsRef.current.path})`);
40728
+ console.info(`[dsh-remote-vs] build 1103-1347 · ${source} · colored tokens: ${count} (${propsRef.current.path})`);
40692
40729
  propsRef.current.onTokens?.(count);
40693
40730
  };
40694
40731
  const armFallback = () => {
@@ -46020,6 +46057,317 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
46020
46057
  return (0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
46021
46058
  }
46022
46059
  //#endregion
46060
+ //#region src/client/ai-review.ts
46061
+ /**
46062
+ * "Review this diff with AI" (F6): the pure half — byte accounting, the size
46063
+ * tier decision and the prompt builder. No React, no DOM, no host access: the
46064
+ * button in `scm/DiffView.tsx` calls these and hands the result to
46065
+ * `appendToDraft` (`composer.ts`), the ONE delivery channel v1 uses.
46066
+ *
46067
+ * Why the byte accounting is not optional
46068
+ * ---------------------------------------
46069
+ * `git diff` runs through `capped()` in `git-ops.ts`: `| head -c GIT_CAP`, and
46070
+ * `RemoteExecResult` carries no `truncated` flag — the cut is SILENT. Sending
46071
+ * such a prefix as "the diff" produces a confident review of half a patch: a
46072
+ * wrong answer with no marker anywhere. So the caller compares BYTES against
46073
+ * `GIT_CAP`, and `pickReviewMode` refuses `full` for a capped diff even when the
46074
+ * prefix would fit the inline budget: a truncated diff can never be reviewed as
46075
+ * if it were complete.
46076
+ *
46077
+ * Two thresholds, two different jobs:
46078
+ * - `GIT_CAP` (2,000,000 B, `git-ops.ts`): the read was CUT, so the prompt's
46079
+ * FIRST line has to say so.
46080
+ * - `AI_REVIEW_MAX_BYTES` (32 KiB ≈ 8–10k tokens): above it the diff is not
46081
+ * inlined at all. The prompt carries the file, the scope and the `@@` hunk
46082
+ * headers, and tells the model to fetch the diff itself (a read or a
46083
+ * `git diff` on the remote host) instead of spending a whole context window
46084
+ * on one message — 2 MB would be ~550–700k tokens and could never be sent.
46085
+ *
46086
+ * The fence length is computed, never hardcoded: a file that CONTAINS ``` would
46087
+ * close a 3-backtick fence early and the rest of the patch would be read as
46088
+ * prose. One backtick more than the longest run inside makes that impossible.
46089
+ */
46090
+ /** Largest complete diff we inline into the prompt, in BYTES (≈8–10k tokens). */
46091
+ const AI_REVIEW_MAX_BYTES = 32 * 1024;
46092
+ /** UTF-8 byte length — the unit `head -c` and therefore `GIT_CAP` count. */
46093
+ function diffByteLength(diff) {
46094
+ return new TextEncoder().encode(diff).length;
46095
+ }
46096
+ /**
46097
+ * Which revision range a diff tab shows.
46098
+ *
46099
+ * `ref` wins over `staged`, and that order is load-bearing: a commit drill-down
46100
+ * tab is BOTH `staged: true` and `ref: hash` (`store.openCommitFile`), so asking
46101
+ * `staged` first would label a commit's diff as "staged changes" and point the
46102
+ * model at the index instead of the commit.
46103
+ */
46104
+ function reviewScopeOf(staged, ref) {
46105
+ if (ref !== void 0) return "commit";
46106
+ if (staged) return "staged";
46107
+ return "worktree";
46108
+ }
46109
+ /**
46110
+ * Which prompt shape this diff gets.
46111
+ *
46112
+ * Order matters. `pathOnly` answers "there is no diff text at all" (untracked /
46113
+ * binary / failed read) and outranks the rest because it needs no budget.
46114
+ * `capped` outranks the size test: a 1 KiB prefix of a 2 MB patch is not a
46115
+ * small diff, it is a CUT one. Only a complete, small diff earns `full`.
46116
+ */
46117
+ function pickReviewMode(input) {
46118
+ if (!input.hasDiff) return "pathOnly";
46119
+ if (input.capped) return "summary";
46120
+ if (input.bytes <= 32768) return "full";
46121
+ return "summary";
46122
+ }
46123
+ /** Longest unbroken run of backticks in `text` (0 when there is none). */
46124
+ function longestBacktickRun(text) {
46125
+ let longest = 0;
46126
+ for (const run of text.matchAll(/`+/g)) if (run[0].length > longest) longest = run[0].length;
46127
+ return longest;
46128
+ }
46129
+ /**
46130
+ * A code fence `diff` itself cannot close: one backtick longer than the longest
46131
+ * run inside it, never shorter than the usual three.
46132
+ */
46133
+ function diffFence(diff) {
46134
+ return "`".repeat(Math.max(3, longestBacktickRun(diff) + 1));
46135
+ }
46136
+ /**
46137
+ * The `@@ … @@` hunk headers of a unified diff, in order.
46138
+ *
46139
+ * A line starting with `@@` can only be a header: every content line of a
46140
+ * unified diff begins with ' ', '+' or '-', and the file-level lines begin with
46141
+ * `diff --git`, `index`, `---`, `+++`, `new file` or `deleted file`.
46142
+ */
46143
+ function hunkHeaders(diff) {
46144
+ return diff.split("\n").filter((line) => line.startsWith("@@"));
46145
+ }
46146
+ /** How the prompt names the revision range. */
46147
+ const SCOPE_LABEL = {
46148
+ zh: {
46149
+ worktree: "工作区未暂存的更改",
46150
+ staged: "已暂存的更改",
46151
+ commit: "提交"
46152
+ },
46153
+ en: {
46154
+ worktree: "unstaged working-tree changes",
46155
+ staged: "staged changes",
46156
+ commit: "commit"
46157
+ }
46158
+ };
46159
+ function scopeLabel(scope, commitRef, lang) {
46160
+ const base = SCOPE_LABEL[lang][scope];
46161
+ if (scope !== "commit" || commitRef === void 0) return base;
46162
+ return `${base} ${commitRef}`;
46163
+ }
46164
+ /**
46165
+ * The warning that must be the prompt's FIRST line when the diff was capped.
46166
+ *
46167
+ * The number comes from `GIT_CAP` itself, so the prompt cannot drift from the
46168
+ * command that did the cut. The language is the reviewer's, like the rest.
46169
+ */
46170
+ function cappedWarning(lang) {
46171
+ if (lang === "zh") return `⚠ 这份 diff 在 ${GIT_CAP} 字节处被静默截断:下面只是前缀,后面的文件与代码块可能缺失,请以远端实际内容为准。`;
46172
+ return `⚠ This diff was silently truncated at ${GIT_CAP} bytes: only a prefix is shown, so later files and hunks may be missing — rely on the real remote content.`;
46173
+ }
46174
+ /** The file/scope facts every prompt carries, right after the headline. */
46175
+ function contextLines(input) {
46176
+ const scope = scopeLabel(input.scope, input.commitRef, input.lang);
46177
+ if (input.lang === "zh") return [
46178
+ `目标文件:${input.fullPath}(仓库内相对路径 ${input.rel})`,
46179
+ `主机:${input.alias}`,
46180
+ `仓库根:${input.root}`,
46181
+ `差异范围:${scope}`
46182
+ ];
46183
+ return [
46184
+ `Target file: ${input.fullPath} (repository-relative path ${input.rel})`,
46185
+ `Host: ${input.alias}`,
46186
+ `Repository root: ${input.root}`,
46187
+ `Diff scope: ${scope}`
46188
+ ];
46189
+ }
46190
+ /**
46191
+ * The review instructions every prompt carries.
46192
+ *
46193
+ * Phrased as RULES rather than a persona because the receiver is a coding agent
46194
+ * with write access to the same host: this text lands in a normal draft and can
46195
+ * be sent as-is, so "change nothing" has to be explicit.
46196
+ */
46197
+ function reviewRules(lang) {
46198
+ if (lang === "zh") return [
46199
+ "1. 只做审查:不要修改、暂存、提交或删除任何文件,也不要运行会改变工作区的命令。",
46200
+ "2. 重点看正确性、边界条件(空值 / 超大输入 / 异常路径)与错误处理(是否吞掉失败),以及与仓库既有约定不一致的地方(命名、分层、注释风格)。",
46201
+ "3. 每条问题用「文件:行号」定位(变更后的行号),说明为什么是问题、建议怎么改。",
46202
+ "4. 不要复述 diff 内容,直接给结论;没有发现问题就明确说「未发现问题」。"
46203
+ ];
46204
+ return [
46205
+ "1. Review only: do not modify, stage, commit or delete any file, and do not run commands that change the working tree.",
46206
+ "2. Focus on correctness, boundary conditions (empty / huge input / unusual paths), swallowed failures, and anything that breaks the repository conventions (naming, layering, comment style).",
46207
+ "3. Locate every finding as \"file:line\" (line numbers AFTER the change) and say why it is a problem and how you would fix it.",
46208
+ "4. Do not restate the diff; give conclusions only, and say \"no issues found\" explicitly when there are none."
46209
+ ];
46210
+ }
46211
+ /** The fenced, verbatim diff of a completed read. */
46212
+ function fullBlock(input) {
46213
+ const intro = input.lang === "zh" ? "完整 diff:" : "Complete diff:";
46214
+ const body = input.diff.endsWith("\n") ? input.diff.slice(0, -1) : input.diff;
46215
+ const fence = diffFence(input.diff);
46216
+ return [
46217
+ intro,
46218
+ `${fence}diff`,
46219
+ body,
46220
+ fence
46221
+ ];
46222
+ }
46223
+ /**
46224
+ * The size-reduced prompt: no diff body, but the anchors a reviewer needs.
46225
+ *
46226
+ * The `@@` headers are the part of a large diff that is cheap and useful — they
46227
+ * say WHERE the changes are, so the model can read those regions instead of the
46228
+ * whole patch. The body is deliberately absent: shipping it would defeat the
46229
+ * budget this branch exists for.
46230
+ */
46231
+ function summaryBlock(input) {
46232
+ const headers = hunkHeaders(input.diff);
46233
+ const listed = headers.slice(0, 40);
46234
+ const omitted = headers.length - listed.length;
46235
+ const lines = [];
46236
+ if (input.lang === "zh") {
46237
+ lines.push(`diff 大小:${diffByteLength(input.diff)} 字节;超过 ${AI_REVIEW_MAX_BYTES} 字节的内嵌上限,所以没有内嵌全文(按块摘要见下)。`);
46238
+ lines.push("");
46239
+ lines.push(`变更块(从 diff 的 @@ 头提取,共 ${headers.length} 处,最多列出 40 处):`);
46240
+ } else {
46241
+ lines.push(`Diff size: ${diffByteLength(input.diff)} bytes; above the ${AI_REVIEW_MAX_BYTES}-byte inline limit, so the body is not included (per-hunk summary below).`);
46242
+ lines.push("");
46243
+ lines.push(`Changed hunks (taken from the diff's @@ headers; ${headers.length} in total, at most 40 listed):`);
46244
+ }
46245
+ if (listed.length === 0) lines.push(input.lang === "zh" ? "(没有解析到 @@ 头:这份 diff 可能不是标准 unified 输出)" : "(no @@ header found: the diff may not be standard unified output)");
46246
+ lines.push(...listed);
46247
+ if (omitted > 0) lines.push(input.lang === "zh" ? `(另有 ${omitted} 处变更块未列出)` : `(${omitted} more hunks not listed)`);
46248
+ lines.push("");
46249
+ if (input.lang === "zh") lines.push(`获取完整内容:请读取 ${input.fullPath},或在该主机(${input.alias})的仓库根 ${input.root} 上自行执行 git diff / git show 取回完整差异,再用上面的 @@ 头定位。`);
46250
+ else lines.push(`Get the full text: read ${input.fullPath}, or run git diff / git show yourself in the repository root ${input.root} on host ${input.alias}, then use the @@ headers above as anchors.`);
46251
+ return lines;
46252
+ }
46253
+ /**
46254
+ * The no-text prompt: untracked and binary files have no diff to send, so the
46255
+ * model is asked to read the file and obtain the diff itself — never an empty
46256
+ * fenced block, which reads as "the change is empty".
46257
+ */
46258
+ function pathOnlyBlock(input) {
46259
+ if (input.lang === "zh") return ["没有可内嵌的 diff 文本(未跟踪文件或二进制文件没有文本差异)。", `请在该主机上读取 ${input.fullPath} 并自行获取差异(git diff / git show),然后按下面的要求审查。`];
46260
+ return ["No diff text is available (an untracked or binary file has no textual diff).", `Read ${input.fullPath} on that host and obtain the diff yourself (git diff / git show), then review it against the requirements below.`];
46261
+ }
46262
+ /**
46263
+ * The prompt that goes into the composer draft.
46264
+ *
46265
+ * `mode` is what the caller decided (see {@link pickReviewMode}), but an empty
46266
+ * diff is normalized to `pathOnly` here as well: an empty file is not an empty
46267
+ * CHANGE, and an empty fenced block would answer the wrong question.
46268
+ */
46269
+ function buildReviewPrompt(input) {
46270
+ const mode = input.diff === "" ? "pathOnly" : input.mode;
46271
+ const lines = [];
46272
+ if (input.capped) lines.push(cappedWarning(input.lang));
46273
+ lines.push(input.lang === "zh" ? "请审查下面这个文件的改动。" : "Please review the change to the file below.");
46274
+ lines.push("");
46275
+ lines.push(...contextLines(input));
46276
+ lines.push("");
46277
+ let body;
46278
+ if (mode === "full") body = fullBlock(input);
46279
+ else if (mode === "summary") body = summaryBlock(input);
46280
+ else body = pathOnlyBlock(input);
46281
+ lines.push(...body);
46282
+ lines.push("");
46283
+ lines.push(input.lang === "zh" ? "审查要求:" : "Review requirements:");
46284
+ lines.push(...reviewRules(input.lang));
46285
+ return lines.join("\n");
46286
+ }
46287
+ /** `A\tsrc/a.ts`, or `R\tsrc/a.ts → src/b.ts` for a rename. */
46288
+ function commitFileLine(file) {
46289
+ if (file.origPath === void 0 || file.origPath === file.path) return `${file.status}\t${file.path}`;
46290
+ return `${file.status}\t${file.origPath} → ${file.path}`;
46291
+ }
46292
+ /** The commit's identity and files, in both languages. */
46293
+ function commitFacts(input) {
46294
+ const lines = [];
46295
+ if (input.lang === "zh") {
46296
+ lines.push(`提交:${input.hash}`, `标题:${input.subject}`);
46297
+ if (input.body.trim() !== "") lines.push(`提交说明:\n${input.body.trim()}`);
46298
+ lines.push(`主机:${input.alias}`, `仓库根:${input.root}`);
46299
+ } else {
46300
+ lines.push(`Commit: ${input.hash}`, `Subject: ${input.subject}`);
46301
+ if (input.body.trim() !== "") lines.push(`Commit message:\n${input.body.trim()}`);
46302
+ lines.push(`Host: ${input.alias}`, `Repository root: ${input.root}`);
46303
+ }
46304
+ if (input.files.length === 0) return lines;
46305
+ const listed = input.files.slice(0, 100);
46306
+ const omitted = input.files.length - listed.length;
46307
+ lines.push("");
46308
+ lines.push(input.lang === "zh" ? `改动文件(${input.files.length} 个,最多列出 100 个):` : `Changed files (${input.files.length} total, at most 100 listed):`);
46309
+ lines.push(...listed.map(commitFileLine));
46310
+ if (omitted > 0) lines.push(input.lang === "zh" ? `(另有 ${omitted} 个文件未列出)` : `(${omitted} more files not listed)`);
46311
+ return lines;
46312
+ }
46313
+ /** The fenced, verbatim `git show --patch` body. */
46314
+ function commitFullBlock(input) {
46315
+ const intro = input.lang === "zh" ? "完整 patch:" : "Complete patch:";
46316
+ const body = input.patch.endsWith("\n") ? input.patch.slice(0, -1) : input.patch;
46317
+ const fence = diffFence(input.patch);
46318
+ return [
46319
+ intro,
46320
+ `${fence}diff`,
46321
+ body,
46322
+ fence
46323
+ ];
46324
+ }
46325
+ /**
46326
+ * The size-reduced commit prompt: the file list above is the map, and the model
46327
+ * is told how to fetch the patch instead of being handed a truncated prefix.
46328
+ */
46329
+ function commitSummaryBlock(input) {
46330
+ const hunks = hunkHeaders(input.patch).length;
46331
+ const bytes = diffByteLength(input.patch);
46332
+ if (input.lang === "zh") return [`patch 大小:${bytes} 字节,共 ${hunks} 处变更块${input.capped ? "(已被截断)" : `(超过 ${AI_REVIEW_MAX_BYTES} 字节的内嵌上限)`},所以没有内嵌全文。`, `获取完整内容:请在该主机(${input.alias})的仓库根 ${input.root} 上执行 git show ${input.hash} 取回完整 patch,必要时再逐个读取上面列出的文件。`];
46333
+ return [`Patch size: ${bytes} bytes, ${hunks} hunks${input.capped ? " (truncated)" : ` (above the ${AI_REVIEW_MAX_BYTES}-byte inline limit)`}, so the body is not included.`, `Get the full text: run git show ${input.hash} in the repository root ${input.root} on host ${input.alias}, then read the files listed above as needed.`];
46334
+ }
46335
+ /** The no-text commit prompt (empty commit, binary-only change, merge). */
46336
+ function commitPathOnlyBlock(input) {
46337
+ if (input.lang === "zh") return ["该提交没有可内嵌的文本 diff(可能是空提交、仅二进制改动或合并提交)。", `请在该主机(${input.alias})的仓库根 ${input.root} 上执行 git show ${input.hash} 查看完整改动,然后按下面的要求审查。`];
46338
+ return ["This commit has no inline textual diff (empty commit, binary-only change, or a merge).", `Run git show ${input.hash} in the repository root ${input.root} on host ${input.alias}, then review it against the requirements below.`];
46339
+ }
46340
+ /** One rule that only makes sense for a WHOLE commit (cross-file coherence). */
46341
+ function commitRule(lang) {
46342
+ if (lang === "zh") return "5. 以整个提交为单位:核对提交信息与改动是否一致,以及多个文件之间的关联改动是否有遗漏或不一致。";
46343
+ return "5. Review the commit as a whole: does the message match the change, and are the related edits across files consistent and complete?";
46344
+ }
46345
+ /**
46346
+ * The prompt for reviewing a WHOLE commit from the history pane (F6 v2).
46347
+ *
46348
+ * Same byte discipline as the single-file prompt (a capped `git show --patch`
46349
+ * must never be presented as the complete change), but the shape differs: a
46350
+ * commit is a set of files, so the facts list the files and the model is told
46351
+ * how to fetch the patch. `mode` is what the caller decided; an empty patch is
46352
+ * normalized to `pathOnly` here as well.
46353
+ */
46354
+ function buildCommitReviewPrompt(input) {
46355
+ const mode = input.patch === "" ? "pathOnly" : input.mode;
46356
+ const lines = [];
46357
+ if (input.capped) lines.push(cappedWarning(input.lang));
46358
+ lines.push(input.lang === "zh" ? "请审查下面这个提交的改动。" : "Please review the changes in the commit below.");
46359
+ lines.push("");
46360
+ lines.push(...commitFacts(input));
46361
+ lines.push("");
46362
+ if (mode === "full") lines.push(...commitFullBlock(input));
46363
+ else if (mode === "summary") lines.push(...commitSummaryBlock(input));
46364
+ else lines.push(...commitPathOnlyBlock(input));
46365
+ lines.push("");
46366
+ lines.push(input.lang === "zh" ? "审查要求:" : "Review requirements:");
46367
+ lines.push(...reviewRules(input.lang), commitRule(input.lang));
46368
+ return lines.join("\n");
46369
+ }
46370
+ //#endregion
46023
46371
  //#region src/client/scm/DiffView.tsx
46024
46372
  /**
46025
46373
  * Side-by-side diff: full file on both sides, real line numbers, added /
@@ -46353,6 +46701,25 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
46353
46701
  const chat = useRemoteChatTarget(store.ctx);
46354
46702
  const viewedAliasPath = store.workspace !== void 0 ? store.aliasPaths[store.workspace.id] : void 0;
46355
46703
  const chatEnabled = chat.sessionId !== void 0 && chat.sessionWorkspacePath !== void 0 && viewedAliasPath !== void 0 && sameLocalDir(chat.sessionWorkspacePath, viewedAliasPath);
46704
+ /**
46705
+ * Why the "AI review" button cannot run, or `undefined` when it can.
46706
+ *
46707
+ * Three different absences, three different sentences, checked from the most
46708
+ * fundamental down:
46709
+ * - `store.ctx`: the shared store boots asynchronously, so before it lands
46710
+ * there is nothing to write into at all;
46711
+ * - `chatEnabled`: the same binding gate the selection popup uses — a prompt
46712
+ * that names a remote path means nothing in a session that does not live in
46713
+ * this binding;
46714
+ * - `canInsertDraft`: the conversation service is a SOFT, version-dependent
46715
+ * read. A host that does not expose it must say so up front instead of
46716
+ * failing on click with the "composer is busy" sentence, which would name
46717
+ * the wrong cause.
46718
+ */
46719
+ let reviewBlocked;
46720
+ if (store.ctx === void 0) reviewBlocked = t("scm.aiReviewNoContext");
46721
+ else if (!chatEnabled || chat.sessionId === void 0) reviewBlocked = t("scm.aiReviewNoSession");
46722
+ else if (!canInsertDraft(store.ctx, chat.sessionId)) reviewBlocked = t("scm.aiReviewNoChannel");
46356
46723
  (0, react.useEffect)(() => {
46357
46724
  if (mode !== "after" || tab.staged || tab.text !== "" || tab.loading) return;
46358
46725
  let cancelled = false;
@@ -46442,6 +46809,53 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
46442
46809
  if (!await store.saveTab(tab.id, text)) return;
46443
46810
  await store.reloadTab(tab.id);
46444
46811
  };
46812
+ /**
46813
+ * Append an AI-review prompt for THIS tab's diff to the composer draft (F6).
46814
+ *
46815
+ * v1 stops at the DRAFT on purpose: `appendToDraft` is the only delivery
46816
+ * channel used here — no `submit`/`send` call — so the user always sees the
46817
+ * exact prompt (and can edit or discard it) before anything costs a turn. The
46818
+ * host does expose submit facades (see `docs/.feasibility/review.md` §2);
46819
+ * wiring them is a separate, opt-in feature.
46820
+ *
46821
+ * The prompt is built on CLICK, not during render: `diffByteLength` encodes
46822
+ * the whole diff and the prompt can be tens of kilobytes, which must not be
46823
+ * recomputed per frame while the user scrolls the diff.
46824
+ */
46825
+ const reviewWithAi = () => {
46826
+ const ctx = store.ctx;
46827
+ const sessionId = chat.sessionId;
46828
+ if (reviewBlocked !== void 0 || ctx === void 0 || sessionId === void 0) {
46829
+ toast(reviewBlocked ?? t("scm.aiReviewNoSession"), true);
46830
+ return;
46831
+ }
46832
+ const diff = tab.diff?.diff ?? "";
46833
+ const bytes = diffByteLength(diff);
46834
+ const capped = bytes >= GIT_CAP;
46835
+ const mode = pickReviewMode({
46836
+ bytes,
46837
+ hasDiff: diff !== "",
46838
+ capped
46839
+ });
46840
+ if (!appendToDraft(ctx, sessionId, buildReviewPrompt({
46841
+ alias: store.alias,
46842
+ root: store.repoRoot ?? store.root,
46843
+ rel: tab.rel,
46844
+ fullPath: tab.fullPath,
46845
+ scope: reviewScopeOf(tab.staged, tab.ref),
46846
+ ...tab.ref === void 0 ? {} : { commitRef: tab.ref },
46847
+ diff,
46848
+ mode,
46849
+ capped,
46850
+ lang
46851
+ }))) {
46852
+ toast(t("scm.aiReviewFailed"), true);
46853
+ return;
46854
+ }
46855
+ if (mode === "full") toast(t("scm.aiReviewAdded"));
46856
+ else if (mode === "summary") toast(t("scm.aiReviewAddedSummary"));
46857
+ else toast(t("scm.aiReviewAddedRead"));
46858
+ };
46445
46859
  if (tab.error !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
46446
46860
  className: "rvs-diff",
46447
46861
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -46551,6 +46965,17 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
46551
46965
  ]
46552
46966
  }),
46553
46967
  busy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MiniSpinner, {}),
46968
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
46969
+ title: reviewBlocked ?? t("scm.aiReview"),
46970
+ onClick: reviewWithAi,
46971
+ disabled: reviewBlocked !== void 0,
46972
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
46973
+ className: "rvs-glyph",
46974
+ "aria-hidden": "true",
46975
+ style: { fontSize: 12 },
46976
+ children: "AI"
46977
+ })
46978
+ }),
46554
46979
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
46555
46980
  title: t("scm.reloadDiff"),
46556
46981
  onClick: () => {
@@ -47524,8 +47949,8 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
47524
47949
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConnectionStatusChip, { compact: true }),
47525
47950
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
47526
47951
  className: "rvs-build",
47527
- title: `dsh-remote-vs build 1102-1023`,
47528
- children: "1102-1023"
47952
+ title: `dsh-remote-vs build 1103-1347`,
47953
+ children: "1103-1347"
47529
47954
  }),
47530
47955
  tokenCount !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
47531
47956
  className: "rvs-build",
@@ -49766,6 +50191,51 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
49766
50191
  function moveToCommand(from, intoDir, name) {
49767
50192
  return `mv -- ${shQuote(assertAbsPath(from))} ${name === void 0 ? `${shQuote(assertAbsPath(intoDir))}/` : shQuote(joinAbs(intoDir, name))}`;
49768
50193
  }
50194
+ /**
50195
+ * Build one expander.
50196
+ *
50197
+ * @param onExpand - called ONCE per rest, after the delay, with the directory
50198
+ * that was still hovered when the timer fired.
50199
+ * @param scheduler - timer implementation (see {@link DragExpandScheduler}).
50200
+ * @param delayMs - rest time; defaults to {@link DRAG_EXPAND_DELAY_MS}.
50201
+ */
50202
+ function createDragExpander(onExpand, scheduler, delayMs = 650) {
50203
+ /** The directory a timer is running for; undefined = idle. */
50204
+ let candidate;
50205
+ /** The pending timer handle, or undefined when idle. */
50206
+ let timer;
50207
+ const clear = () => {
50208
+ if (timer !== void 0) {
50209
+ scheduler.clear(timer);
50210
+ timer = void 0;
50211
+ }
50212
+ };
50213
+ return {
50214
+ hover(dir) {
50215
+ if (candidate === dir && timer !== void 0) return;
50216
+ clear();
50217
+ candidate = dir;
50218
+ timer = scheduler.set(() => {
50219
+ if (candidate !== dir) return;
50220
+ candidate = void 0;
50221
+ timer = void 0;
50222
+ onExpand(dir);
50223
+ }, delayMs);
50224
+ },
50225
+ leave(dir) {
50226
+ if (candidate !== dir) return;
50227
+ clear();
50228
+ candidate = void 0;
50229
+ },
50230
+ reset() {
50231
+ clear();
50232
+ candidate = void 0;
50233
+ },
50234
+ pending() {
50235
+ return candidate;
50236
+ }
50237
+ };
50238
+ }
49769
50239
  //#endregion
49770
50240
  //#region src/client/listing-requests.ts
49771
50241
  var ListingRequests = class {
@@ -50571,6 +51041,29 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
50571
51041
  const uploadAbort = (0, react.useRef)(void 0);
50572
51042
  /** True while a remote WRITE batch is in flight (upload/paste/delete serialization). */
50573
51043
  const transferRef = (0, react.useRef)(false);
51044
+ /**
51045
+ * `expanded` readable SYNCHRONOUSLY by the window-capture drag listeners.
51046
+ *
51047
+ * Those listeners live outside React's tree and are re-attached per binding,
51048
+ * so reading the state value from inside them would be one render stale; the
51049
+ * spring-load decision ("is this directory already open?") has to answer for
51050
+ * the tree as the pointer sees it.
51051
+ */
51052
+ const expandedRef = (0, react.useRef)(expanded);
51053
+ expandedRef.current = expanded;
51054
+ /** The latest {@link springOpen}; the expander below is created once and reads through. */
51055
+ const springOpenRef = (0, react.useRef)(() => void 0);
51056
+ /**
51057
+ * Spring-loaded folders (see `drag-expand.ts`): one instance per mounted
51058
+ * panel. Both drag paths feed it — the row's own `onDragOver` (our rows =
51059
+ * move) and the window-capture `dragover` (OS files = upload) — because those
51060
+ * are two different event deliveries, not one.
51061
+ */
51062
+ const dragExpand = (0, react.useRef)(void 0);
51063
+ if (dragExpand.current === void 0) dragExpand.current = createDragExpander((dir) => springOpenRef.current(dir), {
51064
+ set: (callback, ms) => window.setTimeout(callback, ms),
51065
+ clear: (handle) => window.clearTimeout(handle)
51066
+ });
50574
51067
  /** Last handled "show this folder" request id (see `shouldConsumeReveal`). */
50575
51068
  const lastRevealId = (0, react.useRef)(0);
50576
51069
  const menu = useContextMenu();
@@ -50603,19 +51096,28 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
50603
51096
  const listingsApi = (0, react.useMemo)(() => new ListingRequests((dir) => dirKey(alias, dir), (dir) => api.fileOp.list(alias, dir), (key, entries) => {
50604
51097
  if (alive.current && aliasRef.current === alias) setListings((prev) => withListing(prev, key, entries));
50605
51098
  }), [alias]);
50606
- const loadDir = (0, react.useCallback)(async (dir, force = false) => {
50607
- if (alias === "") return;
50608
- if (offline) return;
51099
+ /**
51100
+ * List one directory into the tree cache.
51101
+ *
51102
+ * @returns whether the listing landed. Callers that act on the RESULT (the
51103
+ * spring-loaded expand, which has to collapse a directory it could not read)
51104
+ * need it; the many refresh callers ignore it.
51105
+ */
51106
+ const loadDir = (0, react.useCallback)(async (dir, force = false, silent = false) => {
51107
+ if (alias === "") return false;
51108
+ if (offline) return false;
50609
51109
  const key = dirKey(alias, dir);
50610
51110
  setLoading((prev) => {
50611
51111
  const next = new Set(prev);
50612
51112
  next.add(key);
50613
51113
  return next;
50614
51114
  });
51115
+ let listed = false;
50615
51116
  try {
50616
51117
  await listingsApi.request(dir, revisionRef.current, force);
51118
+ listed = true;
50617
51119
  } catch (error) {
50618
- if (!isConnectionFailure(error)) toast(error instanceof Error ? error.message : String(error), true);
51120
+ if (!silent && !isConnectionFailure(error)) toast(error instanceof Error ? error.message : String(error), true);
50619
51121
  } finally {
50620
51122
  setLoading((prev) => {
50621
51123
  const next = new Set(prev);
@@ -50623,6 +51125,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
50623
51125
  return next;
50624
51126
  });
50625
51127
  }
51128
+ return listed;
50626
51129
  }, [
50627
51130
  alias,
50628
51131
  listingsApi,
@@ -50762,10 +51265,19 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
50762
51265
  alive.current = true;
50763
51266
  return () => {
50764
51267
  alive.current = false;
51268
+ dragExpand.current?.reset();
50765
51269
  if (prefetchTimer.current !== void 0) window.clearTimeout(prefetchTimer.current);
50766
51270
  };
50767
51271
  }, []);
50768
51272
  /**
51273
+ * A binding change invalidates every drag candidate: `expanded` is re-keyed to
51274
+ * the new workspace, so a countdown armed on the old tree could open a path
51275
+ * that does not even exist on the host now bound.
51276
+ */
51277
+ (0, react.useEffect)(() => {
51278
+ dragExpand.current?.reset();
51279
+ }, [alias, root]);
51280
+ /**
50769
51281
  * One directory's visible, sorted rows, cached for the life of one
50770
51282
  * `listings`/`showHidden`/`alias` combination.
50771
51283
  *
@@ -50811,6 +51323,29 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
50811
51323
  });
50812
51324
  if (!isOpen) loadDir(entry.path);
50813
51325
  };
51326
+ springOpenRef.current = (0, react.useCallback)((dir) => {
51327
+ if (dir === "" || offline) return;
51328
+ setExpanded((prev) => {
51329
+ if (prev.has(dir)) return prev;
51330
+ const next = new Set(prev);
51331
+ next.add(dir);
51332
+ return next;
51333
+ });
51334
+ loadDir(dir, true, true).then((listed) => {
51335
+ if (listed) return;
51336
+ if (listingsRef.current[dirKey(alias, dir)] !== void 0) return;
51337
+ setExpanded((prev) => {
51338
+ if (!prev.has(dir)) return prev;
51339
+ const next = new Set(prev);
51340
+ next.delete(dir);
51341
+ return next;
51342
+ });
51343
+ });
51344
+ }, [
51345
+ alias,
51346
+ offline,
51347
+ loadDir
51348
+ ]);
50814
51349
  /** Open one path: previews for images, diffs for changed text files. */
50815
51350
  const openEntry = (0, react.useCallback)((entry) => {
50816
51351
  if (entry.isDir) {
@@ -51410,19 +51945,56 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
51410
51945
  event.stopPropagation();
51411
51946
  if (event.dataTransfer !== null) event.dataTransfer.dropEffect = "copy";
51412
51947
  };
51948
+ /**
51949
+ * The DIRECTORY row under the pointer, or undefined.
51950
+ *
51951
+ * Same hit stack as `dropDirFromEvent` (the shell paints a full-screen
51952
+ * "drop here" overlay during a file drag, so `event.target` is that
51953
+ * overlay, never the row), but this one answers "which closed directory is
51954
+ * the pointer resting on" for spring-loading. A FILE row answers undefined:
51955
+ * a drop there lands in its parent directory, which is already open.
51956
+ */
51957
+ const hoverDirOf = (event) => {
51958
+ const point = pointerOf(event);
51959
+ if (point === void 0) return void 0;
51960
+ for (const element of document.elementsFromPoint(point.x, point.y)) {
51961
+ const row = element.closest("[data-rvs-path]");
51962
+ if (row === null) continue;
51963
+ const path = row.getAttribute("data-rvs-path") ?? "";
51964
+ if (path === "") continue;
51965
+ return row.getAttribute("data-rvs-dir") === "1" ? path : void 0;
51966
+ }
51967
+ };
51968
+ /**
51969
+ * Feed the spring-load expander from an OS-file drag.
51970
+ *
51971
+ * `dragover` fires continuously while the pointer rests, which is exactly
51972
+ * the signal the expander wants: it ignores a repeat for the row already
51973
+ * counting down and only restarts when the pointer moves to another row.
51974
+ * RESET rather than `leave` on a file row or the pane background: the
51975
+ * pointer left the candidate and there is no path to name it by here.
51976
+ */
51977
+ const trackHover = (event) => {
51978
+ const dir = hoverDirOf(event);
51979
+ if (dir !== void 0 && !expandedRef.current.has(dir)) dragExpand.current?.hover(dir);
51980
+ else dragExpand.current?.reset();
51981
+ };
51413
51982
  const onDragEnter = (event) => {
51414
51983
  if (!isFileDrag(event.dataTransfer) || !overPane(event)) return;
51415
51984
  claim(event);
51416
51985
  setDropTarget(root);
51417
51986
  setDropHint(root);
51987
+ trackHover(event);
51418
51988
  };
51419
51989
  const onDragOver = (event) => {
51420
51990
  if (!isFileDrag(event.dataTransfer) || !overPane(event)) return;
51421
51991
  claim(event);
51422
51992
  setDropTarget(root);
51423
51993
  setDropHint(root);
51994
+ trackHover(event);
51424
51995
  };
51425
51996
  const onDrop = (event) => {
51997
+ dragExpand.current?.reset();
51426
51998
  dropLog("drop", {
51427
51999
  types: event.dataTransfer === null ? null : [...event.dataTransfer.types],
51428
52000
  overPane: overPane(event),
@@ -51442,7 +52014,21 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
51442
52014
  });
51443
52015
  };
51444
52016
  const onDragLeave = (event) => {
51445
- if (overPane(event)) return;
52017
+ if (overPane(event) && event.relatedTarget !== null) return;
52018
+ dragExpand.current?.reset();
52019
+ setDropTarget(void 0);
52020
+ setDropHint(void 0);
52021
+ };
52022
+ /**
52023
+ * The end of a drag whose SOURCE is in this document (our tree rows): a
52024
+ * drop, Esc, or a drop outside the pane. OS-file drags end in
52025
+ * `onDragLeave` instead (see there). Clearing `dragPaths` matters because a
52026
+ * cancelled move leaves the old selection in it, and the next drag would
52027
+ * then treat a stale row as its move source.
52028
+ */
52029
+ const onDragEnd = () => {
52030
+ dragExpand.current?.reset();
52031
+ dragPaths.current = [];
51446
52032
  setDropTarget(void 0);
51447
52033
  setDropHint(void 0);
51448
52034
  };
@@ -51450,11 +52036,14 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
51450
52036
  window.addEventListener("dragover", onDragOver, true);
51451
52037
  window.addEventListener("drop", onDrop, true);
51452
52038
  window.addEventListener("dragleave", onDragLeave, true);
52039
+ window.addEventListener("dragend", onDragEnd, true);
51453
52040
  return () => {
52041
+ dragExpand.current?.reset();
51454
52042
  window.removeEventListener("dragenter", onDragEnter, true);
51455
52043
  window.removeEventListener("dragover", onDragOver, true);
51456
52044
  window.removeEventListener("drop", onDrop, true);
51457
52045
  window.removeEventListener("dragleave", onDragLeave, true);
52046
+ window.removeEventListener("dragend", onDragEnd, true);
51458
52047
  };
51459
52048
  }, [
51460
52049
  root,
@@ -51797,17 +52386,22 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
51797
52386
  setDropHint(entry.isDir ? entry.path : entry.path.split("/").slice(0, -1).join("/") || "/");
51798
52387
  return;
51799
52388
  }
51800
- if (!entry.isDir) return;
51801
52389
  const source = dragPaths.current[0];
51802
- if (source === void 0) return;
51803
- if (entry.path === source || entry.path.startsWith(`${source}/`)) return;
51804
- e.preventDefault();
51805
- setDropTarget(entry.path);
52390
+ if (entry.isDir && source !== void 0 && e.dataTransfer !== null && [...e.dataTransfer.types].includes("text/plain") && entry.path !== source && !entry.path.startsWith(`${source}/`)) {
52391
+ e.preventDefault();
52392
+ setDropTarget(entry.path);
52393
+ if (expanded.has(entry.path)) dragExpand.current?.reset();
52394
+ else dragExpand.current?.hover(entry.path);
52395
+ return;
52396
+ }
52397
+ dragExpand.current?.reset();
51806
52398
  },
51807
52399
  dragLeave: (entry) => {
52400
+ dragExpand.current?.leave(entry.path);
51808
52401
  setDropTarget((current) => current === entry.path ? void 0 : current);
51809
52402
  },
51810
52403
  dropOn: (entry, e) => {
52404
+ dragExpand.current?.reset();
51811
52405
  if (isFileDrag(e.dataTransfer)) {
51812
52406
  const into = entry.isDir ? entry.path : entry.path.split("/").slice(0, -1).join("/") || "/";
51813
52407
  handleDrop(into, e);
@@ -53823,6 +54417,58 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
53823
54417
  };
53824
54418
  const blockRefs = (0, react.useRef)(/* @__PURE__ */ new Map());
53825
54419
  const menu = useContextMenu();
54420
+ /**
54421
+ * Hand THIS commit to the on-screen session as one review prompt (F6 v2).
54422
+ *
54423
+ * Same delivery rule as the single-file button in `DiffView`: draft only,
54424
+ * never sent, and the same three reasons a click is refused. The patch is
54425
+ * ALREADY in memory here (the 差异 tab renders with it), so this costs no
54426
+ * extra remote round trip; `patchTruncated` comes from the loader that
54427
+ * computed the byte cap — the one place that knows the read was cut.
54428
+ */
54429
+ const store = useExplorer();
54430
+ const chat = useRemoteChatTarget(store.ctx);
54431
+ const viewedAliasPath = store.workspace === void 0 ? void 0 : store.aliasPaths[store.workspace.id];
54432
+ const chatEnabled = chat.sessionId !== void 0 && chat.sessionWorkspacePath !== void 0 && viewedAliasPath !== void 0 && sameLocalDir(chat.sessionWorkspacePath, viewedAliasPath);
54433
+ let reviewBlocked;
54434
+ if (store.ctx === void 0) reviewBlocked = t("scm.aiReviewNoContext");
54435
+ else if (!chatEnabled || chat.sessionId === void 0) reviewBlocked = t("scm.aiReviewNoSession");
54436
+ else if (!canInsertDraft(store.ctx, chat.sessionId)) reviewBlocked = t("scm.aiReviewNoChannel");
54437
+ else if (props.patch === void 0 || props.patch === "") reviewBlocked = t("history.aiReviewNoPatch");
54438
+ const reviewCommit = () => {
54439
+ const ctx = store.ctx;
54440
+ const sessionId = chat.sessionId;
54441
+ if (reviewBlocked !== void 0 || ctx === void 0 || sessionId === void 0) {
54442
+ toast(reviewBlocked ?? t("scm.aiReviewNoSession"), true);
54443
+ return;
54444
+ }
54445
+ const patch = props.patch ?? "";
54446
+ const bytes = diffByteLength(patch);
54447
+ const capped = props.patchTruncated || bytes >= 2e6;
54448
+ const mode = pickReviewMode({
54449
+ bytes,
54450
+ hasDiff: patch !== "",
54451
+ capped
54452
+ });
54453
+ if (!appendToDraft(ctx, sessionId, buildCommitReviewPrompt({
54454
+ alias: store.alias,
54455
+ root: store.repoRoot ?? store.root,
54456
+ hash: props.commit.hash,
54457
+ subject: props.commit.subject,
54458
+ body: props.body,
54459
+ files: props.files ?? [],
54460
+ patch,
54461
+ mode,
54462
+ capped,
54463
+ lang: props.lang
54464
+ }))) {
54465
+ toast(t("scm.aiReviewFailed"), true);
54466
+ return;
54467
+ }
54468
+ if (mode === "full") toast(t("scm.aiReviewAdded"));
54469
+ else if (mode === "summary") toast(t("scm.aiReviewAddedSummary"));
54470
+ else toast(t("scm.aiReviewAddedRead"));
54471
+ };
53826
54472
  const resolvedFocus = props.focusPath === void 0 ? void 0 : blockForPath(model, props.focusPath);
53827
54473
  const currentPath = resolvedFocus ?? paths[0];
53828
54474
  const currentIndex = currentPath === void 0 ? -1 : paths.indexOf(currentPath);
@@ -53945,6 +54591,17 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
53945
54591
  onClick: copyAll,
53946
54592
  disabled: props.patch === void 0 || props.patch === "",
53947
54593
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconCopy, { size: 13 })
54594
+ }),
54595
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
54596
+ title: reviewBlocked ?? t("history.aiReview"),
54597
+ onClick: reviewCommit,
54598
+ disabled: reviewBlocked !== void 0,
54599
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
54600
+ className: "rvs-glyph",
54601
+ "aria-hidden": "true",
54602
+ style: { fontSize: 12 },
54603
+ children: "AI"
54604
+ })
53948
54605
  })
53949
54606
  ]
53950
54607
  }),