@jayyuen66/dsh-ocr-review 0.1.4 → 0.1.5-rc
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/README.md +40 -16
- package/README.zh-CN.md +40 -15
- package/client.js +344 -21
- package/cordis.patch.yml +6 -5
- package/host.js +596 -125
- package/package.json +8 -10
- package/scripts/get-cred.mjs +7 -6
package/host.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// GENERATED by build-host.mjs — edit host.ts / lib/*.ts, then run `node build-host.mjs`.
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import Schema from "@deepseek-ai/schemastery";
|
|
4
|
-
import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
4
|
+
import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync } from "node:fs";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
@@ -20,15 +20,16 @@ import { withFileLock, writeFileAtomic } from "@deepseek-ai/dsh-atomic-write";
|
|
|
20
20
|
const MESSAGES = {
|
|
21
21
|
zh: {
|
|
22
22
|
middleEllipsis: " …[中间省略]… ",
|
|
23
|
-
execTimedOut: "ocr 执行超时(实际生效 {minutes} 分钟 = min(请求, shell.maxTimeoutMs)):请缩小审查范围(exclude/--commit/更小改动)、调低 OCR 每组 --timeout
|
|
23
|
+
execTimedOut: "ocr 执行超时(实际生效 {minutes} 分钟 = min(请求, shell.maxTimeoutMs)):请缩小审查范围(exclude/--commit/更小改动)、调低 OCR 每组 --timeout,抬高 shell 执行器(bash-local/pwsh-local)设置项里的 maxTimeoutMs,或改用 wait=false 后台模式(默认不设时限)",
|
|
24
24
|
execAborted: "ocr 执行被中止",
|
|
25
25
|
execNotFound: "ocr 命令不存在:请先 `brew install open-code-review` 或 `npm i -g @alibaba-group/open-code-review`",
|
|
26
|
+
ocrBinaryMissing: "两条路都没找到 ocr:随包的 optionalDependencies 没装上(被跳过或没安装),PATH 上也没有可执行候选。装法:`brew install open-code-review` 或 `npm i -g @alibaba-group/open-code-review`;装完直接重试本工具即可,不必重启 dsh(每次调用都重新判一次,结果不缓存)。",
|
|
26
27
|
execFailed: "ocr 执行失败(exit={exitCode})",
|
|
27
28
|
detailSeparator: ":",
|
|
28
29
|
stdoutTruncated: "[ocr-review] 注意:输出超过 {limit} 字节上限已截断{spill}",
|
|
29
30
|
outputSpill: "(完整输出已落盘:{path})",
|
|
30
|
-
backgroundPolling: "先 job_output(job_id=<本回执的 jobId>) 读这条后台评审的实时输出与最终结局——按 id 走,启动即可读,一定有结果;要停它就 job_kill(job_id=<同一 id>)。会话落盘后再走 ocr_session:ocr_session(action=list) 找本仓库最新会话(启动几秒后出现,按 scanPaths/时间匹配);completed_files == selected_files 即已完成;再 ocr_session(action=comments, id) 取全部评论、ocr_session(action=show, id)
|
|
31
|
-
|
|
31
|
+
backgroundPolling: "先 job_output(job_id=<本回执的 jobId>) 读这条后台评审的实时输出与最终结局——按 id 走,启动即可读,一定有结果;要停它就 job_kill(job_id=<同一 id>)。会话落盘后再走 ocr_session:ocr_session(action=list) 找本仓库最新会话(启动几秒后出现,按 scanPaths/时间匹配);completed_files == selected_files 即已完成;再 ocr_session(action=comments, id) 取全部评论、ocr_session(action=show, id) 看元数据与逐文件检查点。后台评审不随工具调用结束而停止,默认也不设时限(ocrBackgroundMaxMs=0 表示无兜底窗口);只有 dsh 宿主退出、本会话被停止、插件卸载或显式 job_kill 才会结束。",
|
|
32
|
+
jobReasonSessionStopped: "ocr-review 会话已停止,回收在跑的后台评审",
|
|
32
33
|
jobReasonTimeout: "ocr-review 后台评审超过兜底窗口({minutes} 分钟),兜底回收",
|
|
33
34
|
jobReasonUnload: "ocr-review 插件卸载",
|
|
34
35
|
jobOutputGap: "\n[ocr-review] 注意:有一次输出读取失败,已按原游标重试(这段可能不完整)",
|
|
@@ -65,7 +66,7 @@ const MESSAGES = {
|
|
|
65
66
|
statusNone: "(无)",
|
|
66
67
|
ocrCommentsNotArray: "OCR 输出 comments 字段不是数组,无法确认评论完整性",
|
|
67
68
|
warningSeparator: ":",
|
|
68
|
-
reviewSummaryHint: "完整评论与逐文件失败详情请用 `
|
|
69
|
+
reviewSummaryHint: "完整评论与逐文件失败详情请用 `ocr_session(action=show/comments, id=<session_id>)` 查看;start_line=0 表示 OCR 未能锚定行号,可依据 suggestion/existing_code 在文件中定位。两套口径不要混:droppedCount 与 invalidCommentCount 同时为 0 只说明**本摘要**列全了 OCR 产出的评论(否则调大 maxComments 或置 0 后复核);而**这一场有没有审完**看 coverage(selected 是分母,completed/reused/failed/waived 是它的互斥划分;coverage 为 null 时退回看 warnings 与 status=partial)和 budgetExceeded(true = token 预算花完提前收工,status 里只写 partial,看不出这一层)。toolCalls.failure 大于 0 说明当前模型的工具调用没跑通,换模型比重试同一个更省 token。切勿把「本摘要无 critical」当作「代码干净」。",
|
|
69
70
|
lineZeroNote: "(line 0: 定位失败,按 existing_code 手动定位)",
|
|
70
71
|
parseFailedWithReason: "{tool} 输出解析失败:{message}\n原始内容前 {limit} 码元(已脱敏):\n{raw}",
|
|
71
72
|
parseFailedPlain: "{tool} 输出解析失败\n原始内容前 {limit} 码元(已脱敏):\n{raw}",
|
|
@@ -86,8 +87,12 @@ const MESSAGES = {
|
|
|
86
87
|
keyNotReachable: "provider {provider} 的 API key 存在于凭据层「{source}」,OCR 运行时取不到它:dsh 起 shell 会剥掉名字含 KEY/PASSWORD/SECRET/TOKEN 或 DSH_ 前缀的环境变量,get-cred 也刻意不读被审查仓库的 .env。请把 key 存入 dsh 托管凭据($DSH_HOME/.credentials.yaml 的 refs.{ref})或 $DSH_HOME/.env 后重试",
|
|
87
88
|
credScriptMissing: "get-cred 脚本缺失:{path}(api_key_cmd 无法工作)",
|
|
88
89
|
reaperDegraded: "[ocr-review] 宿主回收守护已降级:ps/pgrep 不可用(进程信息命令被沙箱拒绝),改由宿主管进程树。dsh 硬退出时 ocr 可能留孤儿进程。",
|
|
89
|
-
warningUnreadable: "(一条格式无法解析的 warning:既不是字符串,也没有 file/
|
|
90
|
+
warningUnreadable: "(一条格式无法解析的 warning:既不是字符串,也没有 file/message/type 字段)",
|
|
91
|
+
diagnosticUnreadable: "(OCR 的 {field} 字段形态不合,这一场的诊断数据读不出来)",
|
|
92
|
+
diagnosticOmitted: "(另有 {count} 条同类明细已省略,全量见 ocr_session 的 show/comments)",
|
|
90
93
|
commaInListItem: "{name} 的数组形式里有一项自身含逗号:{item}。数组与逗号字符串两条路径 join 后无法区分,而 glob 花括号({ts,tsx})恰好含逗号——静默拆成多项会改变审查/过滤范围。改用逗号字符串形式。",
|
|
94
|
+
probeNoVersion: "ocr version 跑通了(exit 0),但回执里读不出版本号:那通常是未发布构建。",
|
|
95
|
+
probeTimedOut: "ocr version 超时({seconds} 秒内没回来):那条进程已被收走。稍后重试,或直接在终端里跑 ocr version——本插件不会替它代跑安装或升级。",
|
|
91
96
|
providerModelRequired: "provider 与 model 必填",
|
|
92
97
|
bodyParseFailed: "body 解析失败:{message}",
|
|
93
98
|
reviewToolDescription: "用 open-code-review(ocr)对 Git 变更做深度学习代码审查:OCR 调用其自身配置的 LLM(provider/model 在 ocr-review 设置卡选择)独立审查,返回按严重度/类别聚合的评论摘要。scope=workspace 审工作区 staged+unstaged+untracked 变更(默认);scope=commit 审单个提交;scope=branch 用从/到分支对比(merge-base)。常用先 ocr_delegate_preview 看范围。effort 控制深度(low=1 轮/medium=2/high=3,越深越贵)。background 提供需求/业务上下文能显著提升质量。首次审查前确保 ocr 已配置且 'ocr llm test' 通过。",
|
|
@@ -138,28 +143,33 @@ const MESSAGES = {
|
|
|
138
143
|
- ocr_delegate_preview / ocr_delegate_rule:只取「文件清单 + 适配规则」的确定性脚手架(OCR 端零 LLM 消耗),
|
|
139
144
|
配合 git diff 由你自己完成审查——适合复用本会话模型能力、或先确认审查范围再决定是否跑 ocr_review。
|
|
140
145
|
- 审查前若不确定范围,先 ocr_delegate_preview(不花 token);范围过大时用 exclude 收敛或按 commit 拆。
|
|
141
|
-
- OCR 端点/provider/model 由「设置 → 插件 → ocr-review
|
|
142
|
-
|
|
146
|
+
- OCR 端点/provider/model 由「设置 → 插件 → ocr-review 卡片」从宿主设置服务的 provider 清单选择
|
|
147
|
+
(key 只按 api_key_cmd 动态读取,不落盘明文);也可在工具参数里用 provider/model 逐次覆盖。
|
|
143
148
|
- 调用 ocr_review / ocr_scan 前,先用 git log/diff/提交信息快速分析变更意图,提取 3-5 句业务上下文
|
|
144
149
|
传入 background(open-code-review 官方 skill 明确推荐"始终携带",是质量提升最有效的单一参数)。
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
- 读结果分两套口径,不要互相替代:coverage(selected 是分母)与 budgetExceeded 说「这一场有没有审完」,
|
|
151
|
+
droppedCount/invalidCommentCount 只说「本摘要有没有列全」。toolCalls.failure 大于 0 是当前模型不会调
|
|
152
|
+
工具——换支持原生工具调用的模型(sensenova、deepseek、glm、qwen 系),别重试同一个;OCR 以
|
|
153
|
+
--audience agent 运行时进度行被丢弃,"No tool calls parsed" 这类文本永远不会出现在输出里,
|
|
154
|
+
只能看这个字段。
|
|
155
|
+
- LLM 调用本身有重试:OCR 内置重试(429/408/409 与 5xx 自动退避重试);per-file 组失败被隔离,进
|
|
156
|
+
coverage.failedItems(产出里没有 manifest 时进 warnings),不整体重跑。
|
|
157
|
+
工具层超时(min(请求, shell 执行器自己设置项里的 maxTimeoutMs),缺省 10 分钟)或部分文件失败后,可
|
|
158
|
+
ocr_session 查 session_id、用 ocr_review --resume 恢复中断的区间/commit 评审。
|
|
150
159
|
`.trim()
|
|
151
160
|
},
|
|
152
161
|
en: {
|
|
153
162
|
middleEllipsis: " …[middle omitted]… ",
|
|
154
|
-
execTimedOut: "ocr timed out (effective {minutes} min = min(request, shell.maxTimeoutMs)): narrow the review scope (exclude / --commit / a smaller diff), lower OCR's per-group --timeout, raise
|
|
163
|
+
execTimedOut: "ocr timed out (effective {minutes} min = min(request, shell.maxTimeoutMs)): narrow the review scope (exclude / --commit / a smaller diff), lower OCR's per-group --timeout, raise maxTimeoutMs in the shell executor's own settings (bash-local/pwsh-local), or switch to background mode with wait=false (no time limit by default)",
|
|
155
164
|
execAborted: "ocr execution aborted",
|
|
156
165
|
execNotFound: "ocr command not found: install it first with `brew install open-code-review` or `npm i -g @alibaba-group/open-code-review`",
|
|
166
|
+
ocrBinaryMissing: "no ocr candidate on either path: the bundled optionalDependencies were skipped or not installed, and PATH has no executable candidate. Install it with `brew install open-code-review` or `npm i -g @alibaba-group/open-code-review`, then just retry this call - the verdict is re-read per call, so no dsh restart is needed",
|
|
157
167
|
execFailed: "ocr failed (exit={exitCode})",
|
|
158
168
|
detailSeparator: ": ",
|
|
159
169
|
stdoutTruncated: "[ocr-review] note: output exceeded the {limit}-byte cap and was truncated{spill}",
|
|
160
170
|
outputSpill: " (full output spilled to {path})",
|
|
161
|
-
backgroundPolling: "First read this background review's live output and final outcome with job_output(job_id=<the jobId in this receipt>) — that path goes by id, so it is readable immediately after start and always has a result; job_kill(job_id=<the same id>) stops it. Once the session has landed, use ocr_session: ocr_session(action=list) finds this repository's newest session (it appears a few seconds after start; match by scanPaths/time); completed_files == selected_files means it is done. Then ocr_session(action=comments, id) for all comments and ocr_session(action=show, id) for metadata and per-file checkpoints.
|
|
162
|
-
|
|
171
|
+
backgroundPolling: "First read this background review's live output and final outcome with job_output(job_id=<the jobId in this receipt>) — that path goes by id, so it is readable immediately after start and always has a result; job_kill(job_id=<the same id>) stops it. Once the session has landed, use ocr_session: ocr_session(action=list) finds this repository's newest session (it appears a few seconds after start; match by scanPaths/time); completed_files == selected_files means it is done. Then ocr_session(action=comments, id) for all comments and ocr_session(action=show, id) for metadata and per-file checkpoints. A background run does not stop when the tool call ends and has no time limit by default (ocrBackgroundMaxMs=0 means no backstop window); it ends only when the dsh host exits, this session is stopped, the plugin unloads, or you call job_kill.",
|
|
172
|
+
jobReasonSessionStopped: "the ocr-review session stopped; running background reviews were reclaimed",
|
|
163
173
|
jobReasonTimeout: "the ocr-review background review exceeded its backstop window ({minutes} minutes) and was reclaimed",
|
|
164
174
|
jobReasonUnload: "ocr-review plugin unloaded",
|
|
165
175
|
jobOutputGap: "\n[ocr-review] note: one output read failed and was retried from the same offset (this stretch may be incomplete)",
|
|
@@ -196,7 +206,7 @@ const MESSAGES = {
|
|
|
196
206
|
statusNone: "(none)",
|
|
197
207
|
ocrCommentsNotArray: "the comments field of the OCR output is not an array, comment completeness cannot be confirmed",
|
|
198
208
|
warningSeparator: ": ",
|
|
199
|
-
reviewSummaryHint: "Use `
|
|
209
|
+
reviewSummaryHint: "Use `ocr_session(action=show/comments, id=<session_id>)` for the full comments and per-file failure details; start_line=0 means OCR could not anchor a line — locate it via suggestion/existing_code. Keep the two notions apart: droppedCount and invalidCommentCount both being 0 only means THIS SUMMARY listed every comment OCR produced (otherwise raise maxComments, or set it to 0, and re-check). Whether the run itself covered everything is answered by coverage (selected is the denominator, completed/reused/failed/waived are its disjoint partition; fall back to warnings and status=partial when coverage is null) and by budgetExceeded (true = the token budget stopped the run early — status still only says partial). A toolCalls.failure above 0 means the current model's tool calls did not work: switch models instead of retrying the same one. Never treat \"no critical in this summary\" as \"the code is clean\".",
|
|
200
210
|
lineZeroNote: "(line 0: not anchored, locate it via existing_code)",
|
|
201
211
|
parseFailedWithReason: "{tool} output parsing failed: {message}\nfirst {limit} UTF-16 code units of the raw output (redacted):\n{raw}",
|
|
202
212
|
parseFailedPlain: "{tool} output parsing failed\nfirst {limit} UTF-16 code units of the raw output (redacted):\n{raw}",
|
|
@@ -217,8 +227,12 @@ const MESSAGES = {
|
|
|
217
227
|
keyNotReachable: "the API key of provider {provider} lives in the credential source \"{source}\", which OCR cannot reach at runtime: dsh strips variables named KEY/PASSWORD/SECRET/TOKEN or prefixed DSH_ from spawned shells, and get-cred deliberately does not read the reviewed repository's .env. Store the key in the dsh managed credentials ($DSH_HOME/.credentials.yaml refs.{ref}) or $DSH_HOME/.env and retry",
|
|
218
228
|
credScriptMissing: "get-cred script missing: {path} (api_key_cmd cannot work)",
|
|
219
229
|
reaperDegraded: "[ocr-review] host reaper degraded: ps/pgrep are unavailable (process-info commands denied by the sandbox), so the host manages the process tree. dsh may leave an orphaned ocr process.",
|
|
220
|
-
warningUnreadable: "(one unreadable warning entry: neither a string nor an object with file/
|
|
230
|
+
warningUnreadable: "(one unreadable warning entry: neither a string nor an object with file/message/type)",
|
|
231
|
+
diagnosticUnreadable: "(the {field} field of the OCR output is malformed; its diagnostics cannot be read for this run)",
|
|
232
|
+
diagnosticOmitted: "({count} more entries of the same kind were omitted; use ocr_session show/comments for the full list)",
|
|
221
233
|
commaInListItem: "an item of the array form of {name} contains a comma itself: {item}. The array form and the comma-joined string are indistinguishable after joining, and glob braces ({ts,tsx}) contain commas — silently splitting changes the review/filter scope. Use the comma-separated string form.",
|
|
234
|
+
probeNoVersion: "ocr version ran fine (exit 0), yet no version could be read from its output: that usually means an unreleased build",
|
|
235
|
+
probeTimedOut: "ocr version timed out (nothing back within {seconds}s): that process was reaped. Retry later, or run ocr version in a terminal yourself — this plugin never runs an install or upgrade on your behalf",
|
|
222
236
|
providerModelRequired: "provider and model are both required",
|
|
223
237
|
bodyParseFailed: "failed to parse the body: {message}",
|
|
224
238
|
reviewToolDescription: "Deep code review of Git changes with open-code-review (ocr): OCR runs its own configured LLM (provider/model picked in the ocr-review settings card) as an independent reviewer and returns comments aggregated by severity/category. scope=workspace reviews staged+unstaged+untracked changes (default); scope=commit reviews one commit; scope=branch compares from/to branches (merge-base). Commonly start with ocr_delegate_preview to see the scope. effort controls depth (low=1 pass / medium=2 / high=3, deeper costs more). Passing requirements/business context via background markedly improves quality. Before the first review make sure ocr is configured and 'ocr llm test' passes.",
|
|
@@ -271,18 +285,23 @@ const MESSAGES = {
|
|
|
271
285
|
or for confirming the scope before deciding to run ocr_review.
|
|
272
286
|
- Unsure about the scope? Run ocr_delegate_preview first (costs no tokens); if the scope is huge, narrow it with
|
|
273
287
|
exclude or split by commit.
|
|
274
|
-
- The OCR endpoint/provider/model comes from "Settings → Plugins → ocr-review card", fed by
|
|
275
|
-
|
|
288
|
+
- The OCR endpoint/provider/model comes from "Settings → Plugins → ocr-review card", fed by the provider list of
|
|
289
|
+
the host settings service (the key is read dynamically through api_key_cmd and never stored in plaintext);
|
|
290
|
+
provider/model can also be overridden per call.
|
|
276
291
|
- Before ocr_review / ocr_scan, analyse the change intent via git log/diff/commit messages and pass 3-5 sentences of
|
|
277
292
|
business context as background (the official open-code-review skill says "always carry it" — the single most
|
|
278
293
|
effective quality knob).
|
|
279
|
-
-
|
|
280
|
-
|
|
281
|
-
|
|
294
|
+
- Read the result through two separate notions, neither replaces the other: coverage (selected is the denominator)
|
|
295
|
+
and budgetExceeded say whether the run finished covering everything, while droppedCount/invalidCommentCount only
|
|
296
|
+
say whether this summary listed everything OCR produced. A toolCalls.failure above 0 means the current model does
|
|
297
|
+
not drive tool calls — switch to a model with native tool calls (sensenova, deepseek, glm, qwen families) instead
|
|
298
|
+
of retrying the same one; when OCR runs with --audience agent its progress lines are dropped, so text such as
|
|
299
|
+
"No tool calls parsed" can never show up in the output and this field is the only way to see it.
|
|
282
300
|
- LLM calls retry themselves: OCR has built-in backoff retries (429/408/409 and 5xx); per-file group failures are
|
|
283
|
-
isolated and land in warnings
|
|
284
|
-
|
|
285
|
-
|
|
301
|
+
isolated and land in coverage.failedItems (in warnings when the output carries no manifest) instead of re-running
|
|
302
|
+
everything. After a tool-layer timeout (min(request, the maxTimeoutMs setting of the shell executor itself,
|
|
303
|
+
10 minutes by default) or partial file failures, use ocr_session to find the session_id and ocr_review --resume
|
|
304
|
+
to continue an interrupted range/commit review.
|
|
286
305
|
`.trim()
|
|
287
306
|
}
|
|
288
307
|
};
|
|
@@ -399,6 +418,19 @@ const REDACTION = "***REDACTED***";
|
|
|
399
418
|
function redactKeyMaterial(text) {
|
|
400
419
|
return text.replaceAll(AUTH_HEADER_VALUE, `$<name>$<scheme>${REDACTION}`).replaceAll(BEARER_VALUE, `$<scheme>${REDACTION}`).replaceAll(KEY_ASSIGNMENT, `$<name>$<scheme>${REDACTION}`).replaceAll(STANDALONE_KEY, REDACTION);
|
|
401
420
|
}
|
|
421
|
+
/** ECMA-48 的 CSI 序列:ESC `[` + 参数位 + 中间位 + 终结位(SGR 颜色码就是终结位 `m`)。 */
|
|
422
|
+
const ANSI_CSI = new RegExp(`${String.fromCodePoint(27)}\\[[0-?]*[ -/]*[@-~]`, "gu");
|
|
423
|
+
/**
|
|
424
|
+
* 剥掉终端控制序列,只给**要显示给人复制**的那段输出用。
|
|
425
|
+
*
|
|
426
|
+
* 上游 launcher 那句「有新版本,跑这条命令」是硬编码 `console.error("\x1b[33m…")` 打到
|
|
427
|
+
* stderr 的,`--color never` 管不到它(那句在 JS 包装层打印,Go 那侧的旗标还没生效)。
|
|
428
|
+
* 留着这些字节,浏览器里看到的就是 `[33m[ocr] A new version …[0m` 这种噪声,而用户要选中
|
|
429
|
+
* 复制进终端的恰好是那条 `npm i -g …`——复制到的是带控制字符的脏命令。
|
|
430
|
+
*/
|
|
431
|
+
function stripAnsi(text) {
|
|
432
|
+
return text.replaceAll(ANSI_CSI, "");
|
|
433
|
+
}
|
|
402
434
|
/** 官方子集的迷你走查(path 限定违规位置,一次列全)。oneOf 语义与官方一致:
|
|
403
435
|
* 恰好一支命中,多支/零支都算违规。 */
|
|
404
436
|
function violationsOf(schema, value, path) {
|
|
@@ -632,7 +664,7 @@ function pushTextFlag(parts, flag, value, messages) {
|
|
|
632
664
|
if (text !== "") parts.push(flag, shq(text));
|
|
633
665
|
}
|
|
634
666
|
/** --exclude/--background/--provider/--model 等通用 flag。
|
|
635
|
-
* 注意:ocr 的 --exclude 是 String
|
|
667
|
+
* 注意:ocr 的 --exclude 是 String 类型(实测多个 flag 实例只认最后一个,
|
|
636
668
|
* 逗号分隔才生效)——多值必须合并为一个 flag 逗号连接,绝不能展开多个。
|
|
637
669
|
* resume 不在这里:它与 scope 是互斥语义(workspace 禁恢复),由
|
|
638
670
|
* buildReviewCommand 在拿到 scopeFlags 结果后前置校验。 */
|
|
@@ -704,11 +736,66 @@ function locateLauncher() {
|
|
|
704
736
|
} catch {}
|
|
705
737
|
return launcher;
|
|
706
738
|
}
|
|
739
|
+
/** 是不是一个普通文件(PATH 里恰好有个叫 ocr 的目录不算命中)。 */
|
|
740
|
+
function isRegularFile(candidate) {
|
|
741
|
+
try {
|
|
742
|
+
return statSync(candidate).isFile();
|
|
743
|
+
} catch {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* 只用文件系统的事实回答:`ocr` 这个候选在哪条路上找得到。
|
|
749
|
+
*
|
|
750
|
+
* 为什么需要:`ocrCommand()` 在随包入口缺席时**假设** PATH 上有裸 `ocr`,而这个假设
|
|
751
|
+
* 过去只有等子进程 exit 127 才暴露——用户看到的是「ocr 命令不存在」而不是「哪条路都
|
|
752
|
+
* 没找到」。本函数给设置页的状态行与工具的前置短路同一个可先问的判据。
|
|
753
|
+
*
|
|
754
|
+
* 四条口径:
|
|
755
|
+
* - 只回答「找不找得到」,不回答「跑不跑得起来」:丢执行位、入口是符号链接指向空缺
|
|
756
|
+
* 这类事实在真实 spawn 那一侧由子进程自己报(比 fs 侧猜权限准确得多),本判据也不
|
|
757
|
+
* 为此引入 `accessSync` 或 mode 位运算。
|
|
758
|
+
* - 因此误报方向是安全的:`none` 只在两条路都没有候选文件时给出,而前置短路只认
|
|
759
|
+
* `none`——不会把一套能跑的环境挡掉。
|
|
760
|
+
* - Windows 永不报 `bundled`:`ocrCommand()` 在那边刻意跳过随包入口(shebang 脚本
|
|
761
|
+
* pwsh/cmd 无法直执行),两处口径必须一致,否则状态说可用、命令却走另一条路。
|
|
762
|
+
* - 「包在但平台二进制缺失」不在这里判——那要读 OCR 自己的内部布局(平台子包名与
|
|
763
|
+
* bin 文件名),抄进本包就等于养一条随上游漂移的判据;那一档由 launcher 自己那句
|
|
764
|
+
* `[ERROR] OpenCodeReview binary not found`(exit 1)报出来。
|
|
765
|
+
* @param env - 进程环境(默认生产那一份;单测注入 stub 以构造 PATH 形态)。
|
|
766
|
+
* @param locate - 随包 launcher 的定位口(默认即 `ocrCommand()` 用的那一个)。
|
|
767
|
+
* @param platform - 平台(默认 `process.platform`;单测换成 stub 以覆盖分隔符与后缀)。
|
|
768
|
+
* @returns 来源与命中路径。
|
|
769
|
+
*/
|
|
770
|
+
function resolveOcrAvailability(env = process.env, locate = locateLauncher, platform = process.platform) {
|
|
771
|
+
const windows = platform === "win32";
|
|
772
|
+
if (!windows) {
|
|
773
|
+
const launcher = locate();
|
|
774
|
+
if (launcher !== null) return {
|
|
775
|
+
source: "bundled",
|
|
776
|
+
path: launcher
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
const dirs = (env["PATH"] ?? env["Path"] ?? "").split(windows ? ";" : ":").filter((dir) => dir !== "");
|
|
780
|
+
const suffixes = windows ? [.../* @__PURE__ */ new Set(["", ...(env["PATHEXT"] ?? "").split(";").filter(Boolean)])] : [""];
|
|
781
|
+
for (const dir of dirs) for (const suffix of suffixes) {
|
|
782
|
+
const candidate = path.resolve(dir, `ocr${suffix}`);
|
|
783
|
+
if (isRegularFile(candidate)) return {
|
|
784
|
+
source: "path",
|
|
785
|
+
path: candidate
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
return { source: "none" };
|
|
789
|
+
}
|
|
707
790
|
/** 进程级记忆槽(默认那一档):整包共用一次解析结果。 */
|
|
708
791
|
const memoBox = {};
|
|
709
792
|
/** 解析出的 `ocr` 命令词(已 shq 转义):随包入口的绝对路径,或 PATH 上的裸 `ocr`。
|
|
710
|
-
*
|
|
711
|
-
*
|
|
793
|
+
* 优先用**随包装上**的 `@alibaba-group/open-code-review` 入口:它经 optionalDependencies
|
|
794
|
+
* 带进来(平台二进制再由它自己的 optionalDependencies 选一),于是「装上本插件 = 工具可用」,
|
|
795
|
+
* 不必用户自己再 brew/npm i -g 一遍;解析不到(平台二进制装不上、或部署刻意不随包分发)才
|
|
796
|
+
* 回落到 PATH 上的裸 `ocr`,与本包一直以来的形态完全一致——两种装法都继续支持。
|
|
797
|
+
* 惰性求值 + 每进程记忆一次,与 dsh 核心解析 @vscode/ripgrep 同款:解析失败绝不在装载期抛,
|
|
798
|
+
* 否则整包会因为一个可选二进制而下线。
|
|
712
799
|
* 导出给同包的命令构造单测——它们按同一个解析结果写期望值,测试与生产同源,
|
|
713
800
|
* 而不是各自把「ocr 还是某个绝对路径」写死一遍。
|
|
714
801
|
* @param locate 随包 launcher 的定位口(默认实现即生产那一档)。
|
|
@@ -753,6 +840,28 @@ function buildLlmTestCommand() {
|
|
|
753
840
|
return `${ocrCommand()} llm test --color never`;
|
|
754
841
|
}
|
|
755
842
|
/**
|
|
843
|
+
* `ocr version` 命令词(设置页的状态探测专用)。与五个工具同一个解析源,理由与
|
|
844
|
+
* `llm test` 完全一致;也不套宿主回收守护——它是秒级本地打印,与
|
|
845
|
+
* delegate/session/llm test 同一档(`wrapWithHostReaper` 只管分钟级的 review/scan)。
|
|
846
|
+
*/
|
|
847
|
+
function buildVersionCommand() {
|
|
848
|
+
return `${ocrCommand()} version`;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* 从 `ocr version` 的回执里取版本号。上游那句自述是 `open-code-review <Version> <os>/<arch>`
|
|
852
|
+
* (`cmd/opencodereview/root.go` 的 versionString),而 `<Version>` 有两种**都在野外**的形态:
|
|
853
|
+
* 随包的 Go 构建把 git tag 整个塞进去,带 `v`(`open-code-review v1.12.13 (fabbdb29) darwin/arm64`),
|
|
854
|
+
* 包管理器装到 PATH 上那份没有(`open-code-review 1.12.13 darwin/arm64`)。上游自己那层 npm 包装
|
|
855
|
+
* 的 parseVersionOutput 只认带 `v` 的一种,本包两种都得读——按 PATH 装法的用户按下「检测版本」
|
|
856
|
+
* 却看到「没有版本号」,这个功能对他就是失效的。
|
|
857
|
+
* 锚在产品名上而不是「文本里第一个像版本号的串」:launcher 那句升级提示里也带一个版本号,
|
|
858
|
+
* 那是**可用的新版本**而非本机装的这份,抓错就把建议读成了现状。
|
|
859
|
+
* 读不出即 null:未发布构建的 `<Version>` 是 `dev`,没有版本号可报,猜一个等于编一个。
|
|
860
|
+
*/
|
|
861
|
+
function parseOcrVersion(text) {
|
|
862
|
+
return /open-code-review\s+v?(?<version>\d+\.\d+(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)/u.exec(text)?.groups?.["version"] ?? null;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
756
865
|
* 构造 `ocr review` 命令。--output 固定为调用方给定的临时文件路径(防截断),
|
|
757
866
|
* --audience agent --format json 是默认(结构化、无进度行)。
|
|
758
867
|
* outputPath 缺省(后台模式)省略 --output:结果以 OCR 会话记录为准。
|
|
@@ -790,7 +899,7 @@ function buildReviewCommand(args, outputPath, messages) {
|
|
|
790
899
|
}
|
|
791
900
|
/** 构造 `ocr scan` 命令(无 git diff 的全文件扫描)。
|
|
792
901
|
* 与 review 相同的坑:--path/--exclude 都是 String 类型,多值必须逗号连接
|
|
793
|
-
*
|
|
902
|
+
* (实测多个 flag 实例不生效),绝不能展开多个。
|
|
794
903
|
* outputPath 缺省(后台模式)省略 --output:结果以 OCR 会话记录为准。 */
|
|
795
904
|
function buildScanCommand(args, outputPath, messages) {
|
|
796
905
|
const repo = assertAbsoluteRoot(args.repo, messages);
|
|
@@ -965,16 +1074,21 @@ function aggregateComments(comments) {
|
|
|
965
1074
|
//#endregion
|
|
966
1075
|
//#region lib/parse.ts
|
|
967
1076
|
/**
|
|
968
|
-
* OCR 评审 JSON 的 status
|
|
969
|
-
*
|
|
1077
|
+
* OCR 评审 JSON 的 status 枚举(判据在 CLI 侧 `cmd/opencodereview/output.go` 的 jsonOutput
|
|
1078
|
+
* 装配与 `internal/session/manifest.go` 的 TerminalState)。
|
|
970
1079
|
* 白名单外的一律视为失败:exit 0 不等于评审成功——`{"error":"auth failed"}`
|
|
971
1080
|
* 这类「没有 status 的错误对象」若被当作 ok:true,模型会把「0 条评论」读成
|
|
972
|
-
*
|
|
1081
|
+
* 「代码干净」,是最坏的一类假阳性。`failed` 也刻意留在白名单外:CLI 的退出契约是
|
|
1082
|
+
* 「全场失败才非零」(`review_cmd.go` 的 reviewResultError),那份文档随非零退出
|
|
1083
|
+
* 一起被 shell 侧的失败详情拦下,本解析拿不到它。
|
|
973
1084
|
*
|
|
974
|
-
* partial 是 manifest
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
1085
|
+
* partial 是 manifest 终态之一:部分文件失败但整体有覆盖、以及 token 预算截断后仍有
|
|
1086
|
+
* 覆盖,都以 exit 0 + status "partial" 输出。此前白名单漏了它,整场已花费 token 的
|
|
1087
|
+
* 评审被误报成「status 非法」并丢弃全部评论。
|
|
1088
|
+
*
|
|
1089
|
+
* 有 manifest 时 status 就是它的终态(complete/partial/skipped),success 与
|
|
1090
|
+
* completed_with_warnings/completed_with_errors 只在没有 manifest 的产出上出现——
|
|
1091
|
+
* 逐文件失败在那两种形态下的落点也不同(前者在 coverage.failed,后者在 warnings)。
|
|
978
1092
|
*/
|
|
979
1093
|
const REVIEW_STATUSES = [
|
|
980
1094
|
"success",
|
|
@@ -991,11 +1105,6 @@ function str(value) {
|
|
|
991
1105
|
return "";
|
|
992
1106
|
}
|
|
993
1107
|
/**
|
|
994
|
-
* 数值字段解析:number 与「数字字符串」都接受(OCR 部分 provider 实测把
|
|
995
|
-
* start_line 输出成 "42",一律当 0 会把真实评论判成「未锚定」而被摘要丢掉),
|
|
996
|
-
* 空串/NaN/Infinity/其它类型回 0。
|
|
997
|
-
*/
|
|
998
|
-
/**
|
|
999
1108
|
* 行号与增删统计的有效域:有限、非负、整数。
|
|
1000
1109
|
*
|
|
1001
1110
|
* 为什么把负数和小数一起挡掉:行号出现 "-3" 会被下游当成「未锚定的评论」而丢弃
|
|
@@ -1008,6 +1117,9 @@ function nonNegativeInt(value) {
|
|
|
1008
1117
|
if (!Number.isSafeInteger(truncated) || truncated < 0) return 0;
|
|
1009
1118
|
return truncated;
|
|
1010
1119
|
}
|
|
1120
|
+
/** 数值字段解析:number 与「数字字符串」都接受(OCR 部分 provider 实测把 start_line
|
|
1121
|
+
* 输出成 "42",一律当 0 会把真实评论判成「未锚定」而被摘要丢掉),空串/NaN/Infinity/
|
|
1122
|
+
* 其它类型回 0。落进 `nonNegativeInt` 那道有效域。 */
|
|
1011
1123
|
function num(value) {
|
|
1012
1124
|
if (typeof value === "number") return nonNegativeInt(value);
|
|
1013
1125
|
if (typeof value === "string") {
|
|
@@ -1017,6 +1129,127 @@ function num(value) {
|
|
|
1017
1129
|
}
|
|
1018
1130
|
return 0;
|
|
1019
1131
|
}
|
|
1132
|
+
/**
|
|
1133
|
+
* 明细行上限:coverage.failed 与 tool_calls.failure_details 在大会话里可以是几百条,
|
|
1134
|
+
* 逐条铺开会把「省 token 的摘要」变成第二份原始输出,而模型只需要知道「有哪些文件没审成」。
|
|
1135
|
+
*/
|
|
1136
|
+
const DIAGNOSTIC_DETAIL_LIMIT = 8;
|
|
1137
|
+
/** 布尔字段:只认真布尔,缺省与非真值一律 false(OCR 用 omitempty 表示「没有发生」)。 */
|
|
1138
|
+
function boolOf(value) {
|
|
1139
|
+
return value === true;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* 明细行收尾:截断时补一条「另有 N 条已省略」,让读的人知道后面还有,而不是以为看到了全部。
|
|
1143
|
+
* @param lines - 已渲染的明细行
|
|
1144
|
+
* @param total - 该组的总条数
|
|
1145
|
+
* @param messages - 文案表
|
|
1146
|
+
* @returns 不超过上限的行数组
|
|
1147
|
+
*/
|
|
1148
|
+
function capLines(lines, total, messages) {
|
|
1149
|
+
if (lines.length >= total) return lines;
|
|
1150
|
+
return [...lines, format(messages.diagnosticOmitted, { count: String(total - lines.length) })];
|
|
1151
|
+
}
|
|
1152
|
+
/** 计数字段的合法形态:非负整数或纯十进制数字串(与 {@link num} 的取值域对齐,
|
|
1153
|
+
* 否则 "x" 或 -1 会被 num 折成 0,把「读不出」伪装成「零失败」)。 */
|
|
1154
|
+
function isCount(value) {
|
|
1155
|
+
if (typeof value === "number") return Number.isSafeInteger(value) && value >= 0;
|
|
1156
|
+
return typeof value === "string" && /^\d+$/u.test(value.trim());
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* 解析 `tool_calls`。字段缺失或为 null(这一场没有工具调用记录)返回 null;
|
|
1160
|
+
* 存在却读不出 total/failure 两个计数、或 failure_details 不是数组,同样返回 null,
|
|
1161
|
+
* 并交出 unreadable 让调用方把「读不出」这条挂进 warnings——诊断字段坏掉不该让整场
|
|
1162
|
+
* 评审作废(评论仍然有效),但也不能把它读成「零失败」。
|
|
1163
|
+
*/
|
|
1164
|
+
function toolCallsOf(raw, messages) {
|
|
1165
|
+
if (raw === void 0 || raw === null) return {
|
|
1166
|
+
view: null,
|
|
1167
|
+
unreadable: false
|
|
1168
|
+
};
|
|
1169
|
+
const doc = isRecord(raw) ? raw : void 0;
|
|
1170
|
+
const details = doc?.["failure_details"];
|
|
1171
|
+
if (doc === void 0 || !isCount(doc["total"]) || !isCount(doc["failure"]) || details !== void 0 && !Array.isArray(details)) return {
|
|
1172
|
+
view: null,
|
|
1173
|
+
unreadable: true
|
|
1174
|
+
};
|
|
1175
|
+
const rows = Array.isArray(details) ? details : [];
|
|
1176
|
+
const rendered = rows.filter((row) => isRecord(row)).map((row) => {
|
|
1177
|
+
const key = str(row["file_path"]);
|
|
1178
|
+
const tool = str(row["tool_name"]);
|
|
1179
|
+
const error = str(row["error"]);
|
|
1180
|
+
return `${tool || messages.statusNone}${key === "" ? "" : ` @ ${key}`}: ${error}`;
|
|
1181
|
+
});
|
|
1182
|
+
return {
|
|
1183
|
+
view: {
|
|
1184
|
+
total: num(doc["total"]),
|
|
1185
|
+
failure: num(doc["failure"]),
|
|
1186
|
+
failures: capLines(rendered.slice(0, DIAGNOSTIC_DETAIL_LIMIT), rows.length, messages)
|
|
1187
|
+
},
|
|
1188
|
+
unreadable: false
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
/** coverage 的一个集合:不是数组即读不出(undefined)。 */
|
|
1192
|
+
function setOf(coverage, key) {
|
|
1193
|
+
const items = coverage[key];
|
|
1194
|
+
return Array.isArray(items) ? items : void 0;
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* 解析 `manifest.coverage`。五个键与 CLI 侧 Coverage 结构一一对应:selected 是分母,
|
|
1198
|
+
* 其余四个是它的互斥划分。任一不是数组即整体读不出——宁可回 null 让模型看见「这里没有
|
|
1199
|
+
* 覆盖度数据」,也不要用 0 冒充「一个文件都没审」。
|
|
1200
|
+
* @param raw - `root["manifest"]`
|
|
1201
|
+
* @param messages - 文案表
|
|
1202
|
+
* @returns 覆盖度视图,与「manifest 存在但读不出」的标记
|
|
1203
|
+
*/
|
|
1204
|
+
function coverageOf(raw, messages) {
|
|
1205
|
+
if (raw === void 0 || raw === null) return {
|
|
1206
|
+
view: null,
|
|
1207
|
+
unreadable: false
|
|
1208
|
+
};
|
|
1209
|
+
const coverage = isRecord(raw) ? raw["coverage"] : void 0;
|
|
1210
|
+
if (!isRecord(coverage)) return {
|
|
1211
|
+
view: null,
|
|
1212
|
+
unreadable: true
|
|
1213
|
+
};
|
|
1214
|
+
const selected = setOf(coverage, "selected");
|
|
1215
|
+
const completed = setOf(coverage, "completed");
|
|
1216
|
+
const reused = setOf(coverage, "reused");
|
|
1217
|
+
const failedRows = setOf(coverage, "failed");
|
|
1218
|
+
const waived = setOf(coverage, "waived");
|
|
1219
|
+
if (selected === void 0 || completed === void 0 || reused === void 0 || failedRows === void 0 || waived === void 0) return {
|
|
1220
|
+
view: null,
|
|
1221
|
+
unreadable: true
|
|
1222
|
+
};
|
|
1223
|
+
const rendered = failedRows.filter((item) => isRecord(item)).map((item) => {
|
|
1224
|
+
const path = str(item["path"]);
|
|
1225
|
+
const classification = str(item["classification"]);
|
|
1226
|
+
const reason = str(item["reason"]);
|
|
1227
|
+
return `${path || messages.statusNone}${classification === "" ? "" : ` [${classification}]`}${reason === "" ? "" : ` ${reason}`}`;
|
|
1228
|
+
});
|
|
1229
|
+
return {
|
|
1230
|
+
view: {
|
|
1231
|
+
selected: selected.length,
|
|
1232
|
+
completed: completed.length,
|
|
1233
|
+
reused: reused.length,
|
|
1234
|
+
failed: failedRows.length,
|
|
1235
|
+
waived: waived.length,
|
|
1236
|
+
failedItems: capLines(rendered.slice(0, DIAGNOSTIC_DETAIL_LIMIT), failedRows.length, messages)
|
|
1237
|
+
},
|
|
1238
|
+
unreadable: false
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* 单条 warning 的渲染:字符串原样;`{file,message,type}` 拼成 `file:message [type]`;
|
|
1243
|
+
* 三者都读不出即落占位说明(空字符串条目会被模型读成「有一条空告警」,那不是事实)。
|
|
1244
|
+
*/
|
|
1245
|
+
function warningLineOf(warn, messages) {
|
|
1246
|
+
if (typeof warn === "string") return warn;
|
|
1247
|
+
if (!isRecord(warn)) return messages.warningUnreadable;
|
|
1248
|
+
const head = [str(warn["file"]), str(warn["message"])].filter(Boolean).join(messages.warningSeparator);
|
|
1249
|
+
const type = str(warn["type"]);
|
|
1250
|
+
const line = [head, type === "" ? "" : `[${type}]`].filter(Boolean).join(" ");
|
|
1251
|
+
return line === "" ? messages.warningUnreadable : line;
|
|
1252
|
+
}
|
|
1020
1253
|
function commentOf(raw) {
|
|
1021
1254
|
if (!isRecord(raw)) return null;
|
|
1022
1255
|
const content = str(raw["content"]);
|
|
@@ -1040,13 +1273,45 @@ function reviewFailure(status, message) {
|
|
|
1040
1273
|
message,
|
|
1041
1274
|
skipped: false,
|
|
1042
1275
|
summary: null,
|
|
1276
|
+
budgetExceeded: false,
|
|
1043
1277
|
comments: [],
|
|
1044
1278
|
warnings: [],
|
|
1279
|
+
toolCalls: null,
|
|
1280
|
+
coverage: null,
|
|
1045
1281
|
sessionId: "",
|
|
1046
1282
|
droppedComments: 0
|
|
1047
1283
|
};
|
|
1048
1284
|
}
|
|
1049
1285
|
/**
|
|
1286
|
+
* 三个诊断出口的合并:告警行、工具调用统计、运行覆盖度。
|
|
1287
|
+
*
|
|
1288
|
+
* warnings 条目是 `{file,message,type}`——CLI 侧的 AgentWarning 没有 `error` 这一项,
|
|
1289
|
+
* 照 error 读等于把失败原因整条丢掉、只留一个文件名。type 是 CLI 自己分类的依据
|
|
1290
|
+
* (subtask_error / scan_subtask_error 与其余),带出去才能让模型分清「哪个文件没审成」
|
|
1291
|
+
* 和「只是有个非致命提醒」。字段存在却不是数组、或条目既不是字符串也读不出任何内容
|
|
1292
|
+
* ⇒ 保留一条明确的「格式无法解析」占位,而不是静默清空。
|
|
1293
|
+
*
|
|
1294
|
+
* 诊断字段读不出来时**不判整场失败**(评论仍然有效、token 已经花掉),而是各补一条
|
|
1295
|
+
* 说明进同一个 warnings 出口——「这一路没有数据」必须看得见,但不能把结果作废。
|
|
1296
|
+
*/
|
|
1297
|
+
function diagnosticsOf(root, messages) {
|
|
1298
|
+
const warnings = [];
|
|
1299
|
+
const warningsRaw = root["warnings"];
|
|
1300
|
+
if (warningsRaw !== void 0) {
|
|
1301
|
+
if (Array.isArray(warningsRaw)) for (const warn of warningsRaw) warnings.push(warningLineOf(warn, messages));
|
|
1302
|
+
else warnings.push(messages.warningUnreadable);
|
|
1303
|
+
}
|
|
1304
|
+
const toolCalls = toolCallsOf(root["tool_calls"], messages);
|
|
1305
|
+
const coverage = coverageOf(root["manifest"], messages);
|
|
1306
|
+
if (toolCalls.unreadable) warnings.push(format(messages.diagnosticUnreadable, { field: "tool_calls" }));
|
|
1307
|
+
if (coverage.unreadable) warnings.push(format(messages.diagnosticUnreadable, { field: "manifest.coverage" }));
|
|
1308
|
+
return {
|
|
1309
|
+
warnings,
|
|
1310
|
+
toolCalls: toolCalls.view,
|
|
1311
|
+
coverage: coverage.view
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1050
1315
|
* 解析 review/scan JSON。text 应为 `ocr review --format json` 的完整 stdout/
|
|
1051
1316
|
* 输出文件内容。解析失败(非 JSON)或 status 不在白名单(含缺失,例如
|
|
1052
1317
|
* `{"error":"..."}` 这类 exit 0 的错误对象)返回 ok=false,由调用方报错。
|
|
@@ -1079,18 +1344,7 @@ function parseReviewOutput(text, messages) {
|
|
|
1079
1344
|
const skipped = status === "skipped";
|
|
1080
1345
|
const sumRaw = root["summary"];
|
|
1081
1346
|
const sum = isRecord(sumRaw) ? sumRaw : void 0;
|
|
1082
|
-
const
|
|
1083
|
-
let warningsArr;
|
|
1084
|
-
if (warningsRaw === void 0) warningsArr = [];
|
|
1085
|
-
else if (Array.isArray(warningsRaw)) warningsArr = warningsRaw.map((warn) => {
|
|
1086
|
-
if (typeof warn === "string") return warn;
|
|
1087
|
-
if (isRecord(warn)) {
|
|
1088
|
-
const joined = [str(warn["file"]), str(warn["error"])].filter(Boolean).join(messages.warningSeparator);
|
|
1089
|
-
if (joined !== "") return joined;
|
|
1090
|
-
}
|
|
1091
|
-
return messages.warningUnreadable;
|
|
1092
|
-
}).filter(Boolean);
|
|
1093
|
-
else warningsArr = [messages.warningUnreadable];
|
|
1347
|
+
const diagnostics = diagnosticsOf(root, messages);
|
|
1094
1348
|
return {
|
|
1095
1349
|
ok: true,
|
|
1096
1350
|
status,
|
|
@@ -1104,8 +1358,11 @@ function parseReviewOutput(text, messages) {
|
|
|
1104
1358
|
outputTokens: num(sum["output_tokens"]),
|
|
1105
1359
|
elapsed: str(sum["elapsed"])
|
|
1106
1360
|
} : null,
|
|
1361
|
+
budgetExceeded: sum === void 0 ? false : boolOf(sum["budget_exceeded"]),
|
|
1107
1362
|
comments,
|
|
1108
|
-
warnings:
|
|
1363
|
+
warnings: diagnostics.warnings,
|
|
1364
|
+
toolCalls: diagnostics.toolCalls,
|
|
1365
|
+
coverage: diagnostics.coverage,
|
|
1109
1366
|
sessionId: str(root["session_id"]),
|
|
1110
1367
|
droppedComments
|
|
1111
1368
|
};
|
|
@@ -1136,6 +1393,7 @@ function summarizeReview(parsed, messages, plan = DEFAULT_PLAN) {
|
|
|
1136
1393
|
skipped: parsed.skipped,
|
|
1137
1394
|
message: parsed.message || null,
|
|
1138
1395
|
summary: parsed.summary ?? null,
|
|
1396
|
+
budgetExceeded: parsed.budgetExceeded,
|
|
1139
1397
|
sessionId: parsed.sessionId || null,
|
|
1140
1398
|
aggregation: agg,
|
|
1141
1399
|
totalCommentCount: parsed.comments.length,
|
|
@@ -1149,6 +1407,8 @@ function summarizeReview(parsed, messages, plan = DEFAULT_PLAN) {
|
|
|
1149
1407
|
suggestion: comment.suggestionCode || null
|
|
1150
1408
|
})),
|
|
1151
1409
|
warnings: parsed.warnings,
|
|
1410
|
+
toolCalls: parsed.toolCalls,
|
|
1411
|
+
coverage: parsed.coverage,
|
|
1152
1412
|
hint: messages.reviewSummaryHint
|
|
1153
1413
|
};
|
|
1154
1414
|
}
|
|
@@ -1917,7 +2177,7 @@ function ocrHomeOverride(configured) {
|
|
|
1917
2177
|
* 组装设置页数据(绝不返回 key 明文;credentials 缺席时 hasKey 全 false 并给出原因,
|
|
1918
2178
|
* 让卡片显示「为什么不可用」而不是假装每个 provider 都没配 key)。
|
|
1919
2179
|
*/
|
|
1920
|
-
async function providersForCard(gateway, paths, messages) {
|
|
2180
|
+
async function providersForCard(gateway, paths, messages, endpointVerify) {
|
|
1921
2181
|
const { providers, source } = readProviders(gateway, messages);
|
|
1922
2182
|
const keyed = source.status === "ready" ? await markKeyFlags(gateway, providers) : withoutKeyFlags(providers);
|
|
1923
2183
|
const { current } = loadOcrConfig(readText(paths.ocrConfigJson));
|
|
@@ -1925,7 +2185,8 @@ async function providersForCard(gateway, paths, messages) {
|
|
|
1925
2185
|
providers: keyed,
|
|
1926
2186
|
current,
|
|
1927
2187
|
getCredReady: existsSync(credentialScriptPath(paths)),
|
|
1928
|
-
source
|
|
2188
|
+
source,
|
|
2189
|
+
endpointVerify
|
|
1929
2190
|
};
|
|
1930
2191
|
}
|
|
1931
2192
|
/**
|
|
@@ -2104,6 +2365,11 @@ async function ensureKeyScriptPointer(paths, messages) {
|
|
|
2104
2365
|
const PLUGIN_DIR = import.meta.dirname;
|
|
2105
2366
|
const MAX_TIMEOUT_REQUEST_MS = 2147483647;
|
|
2106
2367
|
const LLM_TEST_TIMEOUT_MS = 9e4;
|
|
2368
|
+
/** 状态探测(`ocr version`)的墙钟(毫秒)。CLI 自己那层 npm 包装给同一件事是 3 秒
|
|
2369
|
+
* (`scripts/update.js` 里 `spawnSync(bin, ["version"], {timeout: 3000})`),但那是
|
|
2370
|
+
* 直跑原生二进制;我们从 shell 起、还要过一层 JS launcher,故放宽到 15 秒。它只在
|
|
2371
|
+
* 人按下「检测」时跑,不进任何热路径,因此不做成设置项。 */
|
|
2372
|
+
const VERSION_PROBE_TIMEOUT_MS = 15e3;
|
|
2107
2373
|
const STDOUT_MAX_BYTES = 4e5;
|
|
2108
2374
|
/** 解析失败时回显给模型的原始内容长度上限(UTF-16 码元;已脱敏)。
|
|
2109
2375
|
* 单位写码元而不是"字符":本常量喂给 `echoRaw`→`truncateEnd`,那一刀按码元数计
|
|
@@ -2119,16 +2385,20 @@ const PROVIDERS_PATH = "/_dsh/ocr-review/providers";
|
|
|
2119
2385
|
const SELECT_PATH = "/_dsh/ocr-review/select";
|
|
2120
2386
|
const MIGRATE_PATH = "/_dsh/ocr-review/migrate";
|
|
2121
2387
|
const TEST_PATH = "/_dsh/ocr-review/test";
|
|
2388
|
+
const PROBE_PATH = "/_dsh/ocr-review/probe";
|
|
2122
2389
|
/** 官方注册表里本包作业的 kind;宿主据此签发的 id 形如 `ocr-review-N`。 */
|
|
2123
2390
|
const OCR_JOB_KIND = "ocr-review";
|
|
2124
2391
|
/**
|
|
2125
|
-
*
|
|
2126
|
-
*
|
|
2127
|
-
*
|
|
2128
|
-
*
|
|
2129
|
-
*
|
|
2392
|
+
* 后台评审的兜底回收窗口(毫秒);0 = 不设窗口,进程只由宿主退出、会话 dispose、插件卸载
|
|
2393
|
+
* 或显式 job_kill 结束。
|
|
2394
|
+
*
|
|
2395
|
+
* 本包刻意不套宿主 timeoutMs(`onExpiry: "none"`:外部 CLI 的正常时长跨度太大,套了就等于
|
|
2396
|
+
* 替用户砍掉长评审)。不设窗口的代价落在注册表上:未拥有作业共用一只 10 格的桶(实测
|
|
2397
|
+
* `running` 与 `stopping` 都计数,满员是**拒绝**后来的 start),一条挂死的 CLI 就永久占一格,
|
|
2398
|
+
* 连别的插件也起不来。要给这一格腾位的部署把本项设成非零毫秒数:到点经注册表收,记录推到
|
|
2399
|
+
* stopping,理由落进模型可见的 detail。
|
|
2130
2400
|
*/
|
|
2131
|
-
const OCR_BACKGROUND_MAX_MS =
|
|
2401
|
+
const OCR_BACKGROUND_MAX_MS = 0;
|
|
2132
2402
|
/** "仍在跑"的两枚官方状态:`stopping` 是取消已发出、进程还没收完。 */
|
|
2133
2403
|
function isLiveOcrStatus(status) {
|
|
2134
2404
|
return status === "running" || status === "stopping";
|
|
@@ -2171,10 +2441,13 @@ function startUnderOcrController(jobs, spec) {
|
|
|
2171
2441
|
* @param jobs 官方注册表
|
|
2172
2442
|
* @param id 这次后台评审的作业 id
|
|
2173
2443
|
* @param reason 到点回收时写进模型可见 detail 的理由
|
|
2444
|
+
* @param backgroundMaxMs 窗口毫秒数;`<= 0`(部署级设置项 `ocrBackgroundMaxMs` 的默认值)
|
|
2445
|
+
* 表示这条不设兜底窗口,直接返回、不去敲 `wait`
|
|
2174
2446
|
* @returns 等完这一条的兜底窗口;抛错一律就地收敛(记录没了就等于无事可做)
|
|
2175
2447
|
*/
|
|
2176
2448
|
async function enforceOcrDeadline(jobs, id, reason, backgroundMaxMs) {
|
|
2177
2449
|
try {
|
|
2450
|
+
if (backgroundMaxMs <= 0) return;
|
|
2178
2451
|
if ((await jobs.wait(id, backgroundMaxMs)).status === "running") jobs.kill(id, void 0, reason);
|
|
2179
2452
|
} catch {}
|
|
2180
2453
|
}
|
|
@@ -2215,7 +2488,7 @@ function hasMethods(value, methods) {
|
|
|
2215
2488
|
* 其上要调用的方法)。守卫仅压缩类型面、避开 `as unknown as HostCtx` 断言。
|
|
2216
2489
|
* settings 这里点名的两个方法都会被调用:configure 登记本页的页面策略、describe
|
|
2217
2490
|
* 跨命名空间读(provider 清单 + 官方 locale 偏好);inject 挂那条页面策略的 effect。
|
|
2218
|
-
*
|
|
2491
|
+
* settings 面没有 register/get,多点名一个就是永不成立的死分支。 */
|
|
2219
2492
|
function isOcrReviewHost(value) {
|
|
2220
2493
|
if (!isRecord(value)) return false;
|
|
2221
2494
|
const { settings, shell, tools, systemPrompt, inject, get } = value;
|
|
@@ -2226,7 +2499,7 @@ function resolveHost(ctx) {
|
|
|
2226
2499
|
if (!isOcrReviewHost(ctx)) throw new Error("ocr-review: 宿主缺少所需的 shell/tools/settings/systemPrompt/inject 服务界面(或其方法)");
|
|
2227
2500
|
return ctx;
|
|
2228
2501
|
}
|
|
2229
|
-
/** describe()
|
|
2502
|
+
/** describe() 行里按命名空间取解析值(跨命名空间读只有 describe() 一条路:
|
|
2230
2503
|
* `settings.get(ns)` 已删)。未注册该命名空间 → undefined,调用侧按默认值降级。
|
|
2231
2504
|
* @param rows - `ctx.settings.describe()` 的返回(全部条目的表单投影)。
|
|
2232
2505
|
* @param ns - 要读的命名空间(官方字段名是 `ns`,上游有改名 namespace 的 TODO)。
|
|
@@ -2315,6 +2588,7 @@ const REVIEW_OUTPUT_SCHEMA = { oneOf: [
|
|
|
2315
2588
|
"skipped",
|
|
2316
2589
|
"message",
|
|
2317
2590
|
"summary",
|
|
2591
|
+
"budgetExceeded",
|
|
2318
2592
|
"sessionId",
|
|
2319
2593
|
"aggregation",
|
|
2320
2594
|
"totalCommentCount",
|
|
@@ -2322,6 +2596,8 @@ const REVIEW_OUTPUT_SCHEMA = { oneOf: [
|
|
|
2322
2596
|
"invalidCommentCount",
|
|
2323
2597
|
"topComments",
|
|
2324
2598
|
"warnings",
|
|
2599
|
+
"toolCalls",
|
|
2600
|
+
"coverage",
|
|
2325
2601
|
"hint"
|
|
2326
2602
|
],
|
|
2327
2603
|
properties: {
|
|
@@ -2358,6 +2634,7 @@ const REVIEW_OUTPUT_SCHEMA = { oneOf: [
|
|
|
2358
2634
|
elapsed: { type: "string" }
|
|
2359
2635
|
}
|
|
2360
2636
|
}] },
|
|
2637
|
+
budgetExceeded: { type: "boolean" },
|
|
2361
2638
|
sessionId: NULLABLE_STRING,
|
|
2362
2639
|
aggregation: {
|
|
2363
2640
|
type: "object",
|
|
@@ -2418,6 +2695,46 @@ const REVIEW_OUTPUT_SCHEMA = { oneOf: [
|
|
|
2418
2695
|
type: "array",
|
|
2419
2696
|
items: { type: "string" }
|
|
2420
2697
|
},
|
|
2698
|
+
toolCalls: { oneOf: [{ type: "null" }, {
|
|
2699
|
+
type: "object",
|
|
2700
|
+
additionalProperties: false,
|
|
2701
|
+
required: [
|
|
2702
|
+
"total",
|
|
2703
|
+
"failure",
|
|
2704
|
+
"failures"
|
|
2705
|
+
],
|
|
2706
|
+
properties: {
|
|
2707
|
+
total: { type: "integer" },
|
|
2708
|
+
failure: { type: "integer" },
|
|
2709
|
+
failures: {
|
|
2710
|
+
type: "array",
|
|
2711
|
+
items: { type: "string" }
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
}] },
|
|
2715
|
+
coverage: { oneOf: [{ type: "null" }, {
|
|
2716
|
+
type: "object",
|
|
2717
|
+
additionalProperties: false,
|
|
2718
|
+
required: [
|
|
2719
|
+
"selected",
|
|
2720
|
+
"completed",
|
|
2721
|
+
"reused",
|
|
2722
|
+
"failed",
|
|
2723
|
+
"waived",
|
|
2724
|
+
"failedItems"
|
|
2725
|
+
],
|
|
2726
|
+
properties: {
|
|
2727
|
+
selected: { type: "integer" },
|
|
2728
|
+
completed: { type: "integer" },
|
|
2729
|
+
reused: { type: "integer" },
|
|
2730
|
+
failed: { type: "integer" },
|
|
2731
|
+
waived: { type: "integer" },
|
|
2732
|
+
failedItems: {
|
|
2733
|
+
type: "array",
|
|
2734
|
+
items: { type: "string" }
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
}] },
|
|
2421
2738
|
hint: { type: "string" }
|
|
2422
2739
|
}
|
|
2423
2740
|
},
|
|
@@ -2586,6 +2903,7 @@ async function runForeground(host, command, workdir, run, signal) {
|
|
|
2586
2903
|
timeoutMs: run.timeoutMs,
|
|
2587
2904
|
stdoutMaxBytes: run.stdoutMaxBytes,
|
|
2588
2905
|
signal,
|
|
2906
|
+
env: run.env,
|
|
2589
2907
|
sandboxPolicy: ocrSandboxPolicy(workdir)
|
|
2590
2908
|
});
|
|
2591
2909
|
const result = await (await host.shell.execute(spec)).result();
|
|
@@ -2668,13 +2986,8 @@ async function outcomeWhenSettled(proc) {
|
|
|
2668
2986
|
await proc.done;
|
|
2669
2987
|
return jobOutcomeOf(proc);
|
|
2670
2988
|
}
|
|
2671
|
-
/** 子进程落定后摘掉 abort 监听:fire-and-forget 的一臂,等的是收尾而不是启动。 */
|
|
2672
|
-
async function detachWhenSettled(proc, detach) {
|
|
2673
|
-
await proc.done;
|
|
2674
|
-
detach();
|
|
2675
|
-
}
|
|
2676
2989
|
/**
|
|
2677
|
-
* 后台启动:resolve 显式带 `onExpiry: "none"`,故不套宿主 deadline
|
|
2990
|
+
* 后台启动:resolve 显式带 `onExpiry: "none"`,故不套宿主 deadline(宿主
|
|
2678
2991
|
* bash-local 缺省是 'kill',不传就会被缺省 timeoutMs 杀掉),启动准备完成即返回,不等
|
|
2679
2992
|
* 运行结束、不写 --output。结果以 OCR 会话记录为准(增量落盘),由模型经
|
|
2680
2993
|
* ocr_session 工具轮询。dsh 无论优雅退出(teardown 组 TERM→KILL)还是硬退出
|
|
@@ -2686,20 +2999,18 @@ async function detachWhenSettled(proc, detach) {
|
|
|
2686
2999
|
* 工具的返回值是下面的结构化回执对象(canonical 值直返;作业面换装只动了"谁能看见
|
|
2687
3000
|
* 并停掉它",这份回执的内容自此未变——变的只是不再包一层 `{ text }` 字符串)。
|
|
2688
3001
|
*
|
|
2689
|
-
*
|
|
2690
|
-
* -
|
|
2691
|
-
*
|
|
2692
|
-
*
|
|
2693
|
-
*
|
|
2694
|
-
* `
|
|
2695
|
-
* 生产者的 `done` 结局再带一遍就是把同一句写两遍(`jobOutcomeOf` 因此刻意不带)。
|
|
3002
|
+
* 生命周期(任何模式下都可后台运行):
|
|
3003
|
+
* - 不接工具调用的中止信号:program 模式在程序结束时会对活跃调用发 abort,
|
|
3004
|
+
* 接上它就等于「后台评审随一次程序执行结束而停」,与后台语义矛盾;
|
|
3005
|
+
* - 结束只发生在四处:宿主退出(命令内的回收守护)、会话 dispose(apply 里那条
|
|
3006
|
+
* 效应)、插件卸载、或显式 `job_kill`;
|
|
3007
|
+
* - 可选时限由 `ocrBackgroundMaxMs` 给(0 = 无窗口,默认),到点经注册表 kill。
|
|
2696
3008
|
*
|
|
2697
3009
|
* @param host 宿主服务面
|
|
2698
3010
|
* @param job 这次后台评审的描述
|
|
2699
|
-
* @param signal 工具调用的中止信号
|
|
2700
3011
|
* @returns 后台启动回执(canonical 对象,模型侧契约)
|
|
2701
3012
|
*/
|
|
2702
|
-
async function startBackground(host, job
|
|
3013
|
+
async function startBackground(host, job) {
|
|
2703
3014
|
const registry = host.get("jobs");
|
|
2704
3015
|
if (registry === void 0) throw new Error("background review unavailable: the host provides no ctx.jobs (load @deepseek-ai/dsh-jobs-local); run it with wait:true instead");
|
|
2705
3016
|
const spec = host.shell.resolve({
|
|
@@ -2707,7 +3018,7 @@ async function startBackground(host, job, signal) {
|
|
|
2707
3018
|
workdir: job.workdir,
|
|
2708
3019
|
onExpiry: "none",
|
|
2709
3020
|
stdoutMaxBytes: job.stdoutMaxBytes,
|
|
2710
|
-
|
|
3021
|
+
env: job.env,
|
|
2711
3022
|
sandboxPolicy: ocrSandboxPolicy(job.workdir)
|
|
2712
3023
|
});
|
|
2713
3024
|
const proc = await host.shell.execute(spec);
|
|
@@ -2732,21 +3043,6 @@ async function startBackground(host, job, signal) {
|
|
|
2732
3043
|
}
|
|
2733
3044
|
const backstopMinutes = Math.round(job.backgroundMaxMs / 6e4);
|
|
2734
3045
|
enforceOcrDeadline(registry, jobId, format(messages.jobReasonTimeout, { minutes: String(backstopMinutes) }), job.backgroundMaxMs);
|
|
2735
|
-
const stop = () => {
|
|
2736
|
-
try {
|
|
2737
|
-
registry.kill(jobId, void 0, messages.jobReasonAborted);
|
|
2738
|
-
} catch {
|
|
2739
|
-
killProc(proc);
|
|
2740
|
-
}
|
|
2741
|
-
};
|
|
2742
|
-
const detach = () => {
|
|
2743
|
-
signal.removeEventListener("abort", stop);
|
|
2744
|
-
};
|
|
2745
|
-
if (signal.aborted) stop();
|
|
2746
|
-
else {
|
|
2747
|
-
signal.addEventListener("abort", stop, { once: true });
|
|
2748
|
-
detachWhenSettled(proc, detach);
|
|
2749
|
-
}
|
|
2750
3046
|
return {
|
|
2751
3047
|
started: true,
|
|
2752
3048
|
mode: "background",
|
|
@@ -2757,19 +3053,23 @@ async function startBackground(host, job, signal) {
|
|
|
2757
3053
|
polling: messages.backgroundPolling
|
|
2758
3054
|
};
|
|
2759
3055
|
}
|
|
2760
|
-
/** 只收集不抛错(llm test 等需要展示原始失败的命令)。输出必先脱敏(直通卡片)。
|
|
3056
|
+
/** 只收集不抛错(llm test 等需要展示原始失败的命令)。输出必先脱敏(直通卡片)。
|
|
3057
|
+
* `timedOut` 必须一起交回:被墙钟收走的那条进程没有退出码可报,只留 exitCode 的调用方
|
|
3058
|
+
* 会把「超时」写成「执行失败(exit=null)」,把用户指到不存在的那个退出码上。 */
|
|
2761
3059
|
async function runCollect(host, command, workdir, run) {
|
|
2762
3060
|
const spec = host.shell.resolve({
|
|
2763
3061
|
command,
|
|
2764
3062
|
workdir,
|
|
2765
3063
|
timeoutMs: run.timeoutMs,
|
|
2766
3064
|
stdoutMaxBytes: run.stdoutMaxBytes,
|
|
3065
|
+
env: run.env,
|
|
2767
3066
|
sandboxPolicy: ocrSandboxPolicy(workdir)
|
|
2768
3067
|
});
|
|
2769
3068
|
const result = await (await host.shell.execute(spec)).result();
|
|
2770
3069
|
const joined = result.stdout.text === "" || result.stderr.text === "" ? result.stdout.text + result.stderr.text : `${result.stdout.text}\n${result.stderr.text}`;
|
|
2771
3070
|
return {
|
|
2772
3071
|
exitCode: result.exitCode,
|
|
3072
|
+
timedOut: result.timedOut,
|
|
2773
3073
|
output: truncateEnd(redactKeyMaterial(joined), 8e3)
|
|
2774
3074
|
};
|
|
2775
3075
|
}
|
|
@@ -2801,12 +3101,24 @@ function readTimeoutMinutes(config) {
|
|
|
2801
3101
|
if (Number.isSafeInteger(num) && num > 0) return num * 6e4;
|
|
2802
3102
|
return MAX_TIMEOUT_REQUEST_MS;
|
|
2803
3103
|
}
|
|
2804
|
-
/**
|
|
2805
|
-
|
|
3104
|
+
/** 关掉上游自动更新的那一枚变量(`ocrNoAutoUpdate` 与状态探测共用同一个值)。 */
|
|
3105
|
+
const NO_UPDATE_ENV = { OCR_NO_UPDATE: "1" };
|
|
3106
|
+
/**
|
|
3107
|
+
* `ocrNoAutoUpdate` 落地的那一枚环境变量:开着就给 `{OCR_NO_UPDATE:"1"}`,关着给
|
|
3108
|
+
* undefined(不注入,维持上游行为)。每次现读并给新对象,不让执行器与本包共享同一份
|
|
3109
|
+
* 引用——被净化环境是宿主的事,本包只保证「这条命令带上/不带这个变量」。
|
|
3110
|
+
*/
|
|
3111
|
+
function ocrEnv(config) {
|
|
3112
|
+
return config.ocrNoAutoUpdate ? { ...NO_UPDATE_ENV } : void 0;
|
|
3113
|
+
}
|
|
3114
|
+
/** 一次前台执行的下发值:墙钟每次现读(`timeoutMinutes` 是 volatile 设置项),stdout 上限
|
|
3115
|
+
* 与自动更新开关取装载期 config(非 volatile)。后台与 llm test 各有各的墙钟来源,但那一枚
|
|
3116
|
+
* 开关三条路径都经 `ocrEnv` 现取,所以不会在某一条 spawn 上漏。 */
|
|
2806
3117
|
function tuningOf(config) {
|
|
2807
3118
|
return {
|
|
2808
3119
|
timeoutMs: readTimeoutMinutes(config),
|
|
2809
|
-
stdoutMaxBytes: config.stdoutMaxBytes
|
|
3120
|
+
stdoutMaxBytes: config.stdoutMaxBytes,
|
|
3121
|
+
env: ocrEnv(config)
|
|
2810
3122
|
};
|
|
2811
3123
|
}
|
|
2812
3124
|
/** parameters.required 的读取(本插件自己写的 schema,但门缺一即放行 = 副作用
|
|
@@ -2938,8 +3250,10 @@ const configSchema = Schema.object({
|
|
|
2938
3250
|
timeoutMinutes: Schema.natural().default(0).volatile(),
|
|
2939
3251
|
ocrConfigPath: Schema.string().volatile(),
|
|
2940
3252
|
llmTestTimeoutMs: Schema.natural().min(1).default(LLM_TEST_TIMEOUT_MS),
|
|
2941
|
-
|
|
2942
|
-
|
|
3253
|
+
startupVerify: Schema.boolean().default(true),
|
|
3254
|
+
ocrBackgroundMaxMs: Schema.natural().default(OCR_BACKGROUND_MAX_MS),
|
|
3255
|
+
stdoutMaxBytes: Schema.natural().min(1).default(STDOUT_MAX_BYTES),
|
|
3256
|
+
ocrNoAutoUpdate: Schema.boolean().default(false)
|
|
2943
3257
|
});
|
|
2944
3258
|
/** 设置项里的 ocrConfigPath:非字符串或空白一律视为「未覆盖」。 */
|
|
2945
3259
|
function readOcrConfigPath(config) {
|
|
@@ -2986,6 +3300,62 @@ async function healKeyScriptPointer(host, config) {
|
|
|
2986
3300
|
await ensureKeyScriptPointer(pluginPaths(config, messages), messages);
|
|
2987
3301
|
} catch {}
|
|
2988
3302
|
}
|
|
3303
|
+
/**
|
|
3304
|
+
* 探测失败的理由分三档,各说各的话:
|
|
3305
|
+
* - exit 127 说明连命令词都没找到,报「执行失败(exit=127)」是把用户往错方向指
|
|
3306
|
+
* (与 runForeground 里同一分工)。
|
|
3307
|
+
* - 超时那条进程是被墙钟收走的,压根没有退出码,报 `exit=null` 等于让用户去查一个
|
|
3308
|
+
* 不存在的返回值。
|
|
3309
|
+
* - 余下才是真退出码。随包入口在、平台二进制缺失那一档是 exit 1 带
|
|
3310
|
+
* `[ERROR] OpenCodeReview binary not found`,那句原文已在 output 里。
|
|
3311
|
+
* @param messages - 文案表(理由是人读文本,随官方 locale 偏好走)。
|
|
3312
|
+
* @param exitCode - 执行器交回的退出码(被杀为 null)。
|
|
3313
|
+
* @param timedOut - 执行器是否把它按超时收走。
|
|
3314
|
+
* @returns 给人看的那一句失败理由。
|
|
3315
|
+
*/
|
|
3316
|
+
function probeFailureReason(messages, exitCode, timedOut) {
|
|
3317
|
+
if (exitCode === 127) return messages.execNotFound;
|
|
3318
|
+
if (timedOut) return format(messages.probeTimedOut, { seconds: String(VERSION_PROBE_TIMEOUT_MS / 1e3) });
|
|
3319
|
+
return format(messages.execFailed, { exitCode: String(exitCode) });
|
|
3320
|
+
}
|
|
3321
|
+
/**
|
|
3322
|
+
* 跑一次 `ocr version`,把外部 CLI 的自述取回来给设置页。
|
|
3323
|
+
*
|
|
3324
|
+
* 两条必须写死的口径:
|
|
3325
|
+
* - 带 `OCR_NO_UPDATE=1`。不加这一条,「查一下版本」就顺带触发了 CLI 那层 npm 包装的
|
|
3326
|
+
* **全局安装**(`scripts/update.js` 见到更新版本就 spawnSync `npm i -g <pkg>@<latest>`,
|
|
3327
|
+
* 默认 18 分钟冷却一次)。状态读侧不该有写侧副作用,所以这条不受 `ocrNoAutoUpdate`
|
|
3328
|
+
* 那个部署开关影响,恒定带上。
|
|
3329
|
+
* - HOME 与五个工具走同一个重定向口。launcher 那句「自动更新没成功,请手工执行」的
|
|
3330
|
+
* 提示写在 `$HOME/.opencodereview/` 下,不带重定向就会去读另一个世界的状态,
|
|
3331
|
+
* 卡片报的与评审实际吃到的就不是同一份。
|
|
3332
|
+
* @param host 宿主服务面
|
|
3333
|
+
* @param config 本次 apply 的配置
|
|
3334
|
+
* @param messages 文案表(回执里给人看的理由)
|
|
3335
|
+
* @returns 是否取到版本、版本串(取不到为 null)、一手输出(已脱敏、已截断、已去色)、失败理由。
|
|
3336
|
+
*/
|
|
3337
|
+
async function runVersionProbe(host, config, messages) {
|
|
3338
|
+
const raw = await runCollect(host, withHomeEnv(buildVersionCommand(), ocrHome(config)), process.env["HOME"] ?? "/", {
|
|
3339
|
+
timeoutMs: VERSION_PROBE_TIMEOUT_MS,
|
|
3340
|
+
stdoutMaxBytes: config.stdoutMaxBytes,
|
|
3341
|
+
env: { ...NO_UPDATE_ENV }
|
|
3342
|
+
});
|
|
3343
|
+
const { exitCode, timedOut } = raw;
|
|
3344
|
+
const output = stripAnsi(raw.output);
|
|
3345
|
+
if (exitCode !== 0) return {
|
|
3346
|
+
ok: false,
|
|
3347
|
+
version: null,
|
|
3348
|
+
output,
|
|
3349
|
+
reason: probeFailureReason(messages, exitCode, timedOut)
|
|
3350
|
+
};
|
|
3351
|
+
const version = parseOcrVersion(output);
|
|
3352
|
+
return {
|
|
3353
|
+
ok: version !== null,
|
|
3354
|
+
version,
|
|
3355
|
+
output,
|
|
3356
|
+
reason: version === null ? messages.probeNoVersion : ""
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
2989
3359
|
/** 运行 ocr llm test 校验当前配置(select 后自动验证 / 手动测试共用)。
|
|
2990
3360
|
* 命令词与五个工具同一解析源(buildLlmTestCommand:随包 launcher 装法下 PATH 上
|
|
2991
3361
|
* 没有裸 `ocr`),HOME 随 ocrConfigPath 重定向。墙钟与输出上限都是 entry config
|
|
@@ -2993,7 +3363,8 @@ async function healKeyScriptPointer(host, config) {
|
|
|
2993
3363
|
async function runLlmTest(host, config) {
|
|
2994
3364
|
const { exitCode, output } = await runCollect(host, withHomeEnv(buildLlmTestCommand(), ocrHome(config)), process.env["HOME"] ?? "/", {
|
|
2995
3365
|
timeoutMs: config.llmTestTimeoutMs,
|
|
2996
|
-
stdoutMaxBytes: config.stdoutMaxBytes
|
|
3366
|
+
stdoutMaxBytes: config.stdoutMaxBytes,
|
|
3367
|
+
env: ocrEnv(config)
|
|
2997
3368
|
});
|
|
2998
3369
|
return {
|
|
2999
3370
|
ok: exitCode === 0,
|
|
@@ -3167,11 +3538,35 @@ async function sendSelectResponse(text, res, deps) {
|
|
|
3167
3538
|
});
|
|
3168
3539
|
}
|
|
3169
3540
|
}
|
|
3170
|
-
/**
|
|
3171
|
-
*
|
|
3541
|
+
/**
|
|
3542
|
+
* 跑一次状态探测并落成卡片吃得下的那份 JSON。
|
|
3543
|
+
*
|
|
3544
|
+
* `reason` 与 `output` 的分工:`output` 是外部 CLI 的一手回执(`runCollect` 已脱敏、
|
|
3545
|
+
* 已按码元截断),那句「自动更新没成功,请手工执行 npm i -g …」就原样活在里面——本包
|
|
3546
|
+
* 不去正则它,因为那句措辞归上游改,抄一份判据就多一处会跟着漂的地方;卡片把整段
|
|
3547
|
+
* 显示出来供人选中文本复制即可。`reason` 只说这一路为什么没取到版本。
|
|
3548
|
+
*/
|
|
3549
|
+
async function sendProbeResponse(res, deps) {
|
|
3550
|
+
try {
|
|
3551
|
+
const probe = await runVersionProbe(deps.host, deps.config, deps.messages());
|
|
3552
|
+
sendJson(res, 200, {
|
|
3553
|
+
ok: probe.ok,
|
|
3554
|
+
version: probe.version,
|
|
3555
|
+
output: probe.output,
|
|
3556
|
+
reason: probe.reason
|
|
3557
|
+
});
|
|
3558
|
+
} catch (error) {
|
|
3559
|
+
sendJson(res, 400, {
|
|
3560
|
+
ok: false,
|
|
3561
|
+
error: errorText(error)
|
|
3562
|
+
});
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
/** 注册 webServer 配置端点(卡片专用:providers/select/migrate/test/probe)。
|
|
3566
|
+
* csrf 为每次 apply 生成的会话内 token:GET providers 下发、四个写端点回填
|
|
3172
3567
|
* 校验(sec-fetch-site 只挡浏览器,挡不住能构造请求头的本地进程)。
|
|
3173
3568
|
* ctx 只用来挂释放器,给的是 `inject(["webServer"])` 子 fiber 的上下文。 */
|
|
3174
|
-
function registerConfigEndpoints(ctx, host, config, csrf) {
|
|
3569
|
+
function registerConfigEndpoints(ctx, host, config, csrf, extras) {
|
|
3175
3570
|
const webServer = host.get("webServer");
|
|
3176
3571
|
if (!webServer) return;
|
|
3177
3572
|
const servingNonLoopback = !isLoopbackBindAddress(webServer.host);
|
|
@@ -3184,9 +3579,10 @@ function registerConfigEndpoints(ctx, host, config, csrf) {
|
|
|
3184
3579
|
if (!guardTrust(req, res, { servingNonLoopback })) return;
|
|
3185
3580
|
try {
|
|
3186
3581
|
const msgs = messages();
|
|
3187
|
-
const payload = await providersForCard(gateway, pluginPaths(config, msgs), msgs);
|
|
3582
|
+
const payload = await providersForCard(gateway, pluginPaths(config, msgs), msgs, extras.verifyOf());
|
|
3188
3583
|
sendJson(res, 200, {
|
|
3189
3584
|
...payload,
|
|
3585
|
+
ocrBinary: extras.availability(),
|
|
3190
3586
|
csrf
|
|
3191
3587
|
});
|
|
3192
3588
|
} catch (error) {
|
|
@@ -3253,14 +3649,46 @@ function registerConfigEndpoints(ctx, host, config, csrf) {
|
|
|
3253
3649
|
}
|
|
3254
3650
|
}
|
|
3255
3651
|
});
|
|
3652
|
+
const disposeProbe = webServer.register({
|
|
3653
|
+
kind: "exact",
|
|
3654
|
+
path: PROBE_PATH,
|
|
3655
|
+
handler: async (req, res) => {
|
|
3656
|
+
if (!guardTrust(req, res, { servingNonLoopback })) return;
|
|
3657
|
+
if (await guardPost(req, res, csrf) === null) return;
|
|
3658
|
+
await sendProbeResponse(res, {
|
|
3659
|
+
config,
|
|
3660
|
+
host,
|
|
3661
|
+
messages
|
|
3662
|
+
});
|
|
3663
|
+
}
|
|
3664
|
+
});
|
|
3256
3665
|
ctx.effect(() => () => {
|
|
3257
3666
|
disposeProviders();
|
|
3258
3667
|
disposeSelect();
|
|
3259
3668
|
disposeMigrate();
|
|
3260
3669
|
disposeTest();
|
|
3670
|
+
disposeProbe();
|
|
3261
3671
|
}, "ocr-review: config endpoints");
|
|
3262
3672
|
}
|
|
3263
|
-
|
|
3673
|
+
/**
|
|
3674
|
+
* 生产侧的可用性现读口:每次调用问一次真实文件系统。
|
|
3675
|
+
* 单独具名导出是为了让它能被结构性地钉住(单测拿它和 `lib/cli.ts` 那份判据逐字比),
|
|
3676
|
+
* 而不必让任何用例去分支「这台机器恰好装没装 ocr」。
|
|
3677
|
+
*/
|
|
3678
|
+
const productionProbe = () => resolveOcrAvailability();
|
|
3679
|
+
/**
|
|
3680
|
+
* 两条路都没有候选时就地抛,让模型与用户看到的是「哪条路都没找到 + 怎么装」,
|
|
3681
|
+
* 而不是子进程 exit 127 之后那句反推出来的「ocr 命令不存在」。
|
|
3682
|
+
* 判据只回答「找不找得到」:丢执行位、随包平台二进制缺失这些「找到了但跑不起来」的事实
|
|
3683
|
+
* 仍由真实 spawn 报(lib/cli.ts 的 resolveOcrAvailability 头注释写了同一口径),
|
|
3684
|
+
* 所以 `execNotFound` 那条兜底文案必须留着。
|
|
3685
|
+
* @param status - 现读口交回的可用性判定。
|
|
3686
|
+
* @param messages - 文案表(拒绝理由是人读文本,随官方 locale 偏好走)。
|
|
3687
|
+
*/
|
|
3688
|
+
function assertOcrPresent(status, messages) {
|
|
3689
|
+
if (status.source === "none") throw new Error(messages.ocrBinaryMissing);
|
|
3690
|
+
}
|
|
3691
|
+
function registerReviewTool(host, config, probe) {
|
|
3264
3692
|
const msgs = localeMessages(host);
|
|
3265
3693
|
define(host, {
|
|
3266
3694
|
name: "ocr_review",
|
|
@@ -3334,6 +3762,7 @@ function registerReviewTool(host, config) {
|
|
|
3334
3762
|
schema: REVIEW_OUTPUT_SCHEMA,
|
|
3335
3763
|
run: async (args, exec) => {
|
|
3336
3764
|
const runMsgs = localeMessages(host);
|
|
3765
|
+
assertOcrPresent(probe(), runMsgs);
|
|
3337
3766
|
const repo = await canonicalReviewRoot(host, ocrRepo(args, exec, runMsgs));
|
|
3338
3767
|
const eff = effortOf(args["effort"], config, runMsgs);
|
|
3339
3768
|
const tmp = waitOf(args["wait"], runMsgs) ? mkdtempSync(path.join(tmpdir(), "ocr-review-")) : void 0;
|
|
@@ -3353,8 +3782,9 @@ function registerReviewTool(host, config) {
|
|
|
3353
3782
|
tool: "ocr_review",
|
|
3354
3783
|
repo,
|
|
3355
3784
|
stdoutMaxBytes: config.stdoutMaxBytes,
|
|
3356
|
-
backgroundMaxMs: config.ocrBackgroundMaxMs
|
|
3357
|
-
|
|
3785
|
+
backgroundMaxMs: config.ocrBackgroundMaxMs,
|
|
3786
|
+
env: ocrEnv(config)
|
|
3787
|
+
});
|
|
3358
3788
|
await runForeground(host, guarded, workdir, tuningOf(config), exec.signal);
|
|
3359
3789
|
const text = readOutFile(outPath, runMsgs);
|
|
3360
3790
|
const parsed = parseReviewOutput(text, runMsgs);
|
|
@@ -3374,7 +3804,7 @@ function registerReviewTool(host, config) {
|
|
|
3374
3804
|
}
|
|
3375
3805
|
});
|
|
3376
3806
|
}
|
|
3377
|
-
function registerScanTool(host, config) {
|
|
3807
|
+
function registerScanTool(host, config, probe) {
|
|
3378
3808
|
const msgs = localeMessages(host);
|
|
3379
3809
|
define(host, {
|
|
3380
3810
|
name: "ocr_scan",
|
|
@@ -3428,6 +3858,7 @@ function registerScanTool(host, config) {
|
|
|
3428
3858
|
schema: REVIEW_OUTPUT_SCHEMA,
|
|
3429
3859
|
run: async (args, exec) => {
|
|
3430
3860
|
const runMsgs = localeMessages(host);
|
|
3861
|
+
assertOcrPresent(probe(), runMsgs);
|
|
3431
3862
|
const repo = ocrRepo(args, exec, runMsgs);
|
|
3432
3863
|
const tmp = waitOf(args["wait"], runMsgs) ? mkdtempSync(path.join(tmpdir(), "ocr-scan-")) : void 0;
|
|
3433
3864
|
const outPath = tmp === void 0 ? void 0 : path.join(tmp, "out.json");
|
|
@@ -3445,8 +3876,9 @@ function registerScanTool(host, config) {
|
|
|
3445
3876
|
tool: "ocr_scan",
|
|
3446
3877
|
repo,
|
|
3447
3878
|
stdoutMaxBytes: config.stdoutMaxBytes,
|
|
3448
|
-
backgroundMaxMs: config.ocrBackgroundMaxMs
|
|
3449
|
-
|
|
3879
|
+
backgroundMaxMs: config.ocrBackgroundMaxMs,
|
|
3880
|
+
env: ocrEnv(config)
|
|
3881
|
+
});
|
|
3450
3882
|
await runForeground(host, guarded, workdir, tuningOf(config), exec.signal);
|
|
3451
3883
|
const text = readOutFile(outPath, runMsgs);
|
|
3452
3884
|
const parsed = parseReviewOutput(text, runMsgs);
|
|
@@ -3466,7 +3898,7 @@ function registerScanTool(host, config) {
|
|
|
3466
3898
|
}
|
|
3467
3899
|
});
|
|
3468
3900
|
}
|
|
3469
|
-
function registerDelegatePreviewTool(host, config) {
|
|
3901
|
+
function registerDelegatePreviewTool(host, config, probe) {
|
|
3470
3902
|
const msgs = localeMessages(host);
|
|
3471
3903
|
define(host, {
|
|
3472
3904
|
name: "ocr_delegate_preview",
|
|
@@ -3514,6 +3946,7 @@ function registerDelegatePreviewTool(host, config) {
|
|
|
3514
3946
|
schema: PREVIEW_OUTPUT_SCHEMA,
|
|
3515
3947
|
run: async (args, exec) => {
|
|
3516
3948
|
const runMsgs = localeMessages(host);
|
|
3949
|
+
assertOcrPresent(probe(), runMsgs);
|
|
3517
3950
|
const repo = ocrRepo(args, exec, runMsgs);
|
|
3518
3951
|
await healKeyScriptPointer(host, config);
|
|
3519
3952
|
const homeOverride = ocrHome(config);
|
|
@@ -3542,7 +3975,7 @@ function registerDelegatePreviewTool(host, config) {
|
|
|
3542
3975
|
}
|
|
3543
3976
|
});
|
|
3544
3977
|
}
|
|
3545
|
-
function registerDelegateRuleTool(host, config) {
|
|
3978
|
+
function registerDelegateRuleTool(host, config, probe) {
|
|
3546
3979
|
const msgs = localeMessages(host);
|
|
3547
3980
|
define(host, {
|
|
3548
3981
|
name: "ocr_delegate_rule",
|
|
@@ -3566,6 +3999,7 @@ function registerDelegateRuleTool(host, config) {
|
|
|
3566
3999
|
schema: RULES_OUTPUT_SCHEMA,
|
|
3567
4000
|
run: async (args, exec) => {
|
|
3568
4001
|
const runMsgs = localeMessages(host);
|
|
4002
|
+
assertOcrPresent(probe(), runMsgs);
|
|
3569
4003
|
const { command, workdir } = buildDelegateRuleCommand({
|
|
3570
4004
|
repo: ocrRepo(args, exec, runMsgs),
|
|
3571
4005
|
paths: args["paths"]
|
|
@@ -3590,7 +4024,7 @@ function registerDelegateRuleTool(host, config) {
|
|
|
3590
4024
|
}
|
|
3591
4025
|
});
|
|
3592
4026
|
}
|
|
3593
|
-
function registerSessionTool(host, config) {
|
|
4027
|
+
function registerSessionTool(host, config, probe) {
|
|
3594
4028
|
const msgs = localeMessages(host);
|
|
3595
4029
|
define(host, {
|
|
3596
4030
|
name: "ocr_session",
|
|
@@ -3625,6 +4059,7 @@ function registerSessionTool(host, config) {
|
|
|
3625
4059
|
schema: SESSION_OUTPUT_SCHEMA,
|
|
3626
4060
|
run: async (args, exec) => {
|
|
3627
4061
|
const runMsgs = localeMessages(host);
|
|
4062
|
+
assertOcrPresent(probe(), runMsgs);
|
|
3628
4063
|
const repo = await canonicalReviewRoot(host, ocrRepo(args, exec, runMsgs));
|
|
3629
4064
|
const { command, workdir } = buildSessionCommand({
|
|
3630
4065
|
...args,
|
|
@@ -3642,27 +4077,61 @@ function registerSessionTool(host, config) {
|
|
|
3642
4077
|
}
|
|
3643
4078
|
});
|
|
3644
4079
|
}
|
|
3645
|
-
|
|
4080
|
+
/** 装载期自检结论里保留的输出上限(字符):卡片只用来提示,留全量没有意义。 */
|
|
4081
|
+
const ENDPOINT_VERIFY_CHARS = 400;
|
|
4082
|
+
/** 装载期端点自检(fire-and-forget):跑一次 `ocr llm test`,把结论写进本次 apply 的闭包,
|
|
4083
|
+
* 经 GET providers 随载荷交给卡片。
|
|
4084
|
+
*
|
|
4085
|
+
* 为什么需要:卡片写盘只写 url/model/key 通道,**不验端点能力**。实测踩到过——网关强制
|
|
4086
|
+
* 要求一枚能力头,缺了它每个文件都 400,而模型侧看到的是「N 个文件审查失败」,与真因
|
|
4087
|
+
* (端点配置)隔着一层。自检失败不抛、不阻塞装载:它只负责让这件事早点可见。
|
|
4088
|
+
* @param host 宿主服务面
|
|
4089
|
+
* @param config 本次 apply 的配置
|
|
4090
|
+
* @param sink 本次 apply 的闭包槽(不是常驻状态)
|
|
4091
|
+
*/
|
|
4092
|
+
async function probeEndpointAtApply(host, config, sink) {
|
|
4093
|
+
const result = await runLlmTest(host, config);
|
|
4094
|
+
sink.value = result.ok ? {
|
|
4095
|
+
ok: true,
|
|
4096
|
+
message: ""
|
|
4097
|
+
} : {
|
|
4098
|
+
ok: false,
|
|
4099
|
+
message: result.output.trim().slice(0, ENDPOINT_VERIFY_CHARS)
|
|
4100
|
+
};
|
|
4101
|
+
}
|
|
4102
|
+
function apply(ctx, config, probe) {
|
|
3646
4103
|
const host = resolveHost(ctx);
|
|
4104
|
+
const endpointVerify = { value: null };
|
|
4105
|
+
if (config.startupVerify) probeEndpointAtApply(host, config, endpointVerify);
|
|
3647
4106
|
ctx.effect(() => () => {
|
|
3648
4107
|
const jobs = ctx.get("jobs");
|
|
3649
4108
|
if (jobs !== void 0) reclaimOcrJobs(jobs, localeMessages(ctx).jobReasonUnload);
|
|
3650
4109
|
}, "ocr-review: background jobs");
|
|
4110
|
+
ctx.effect(() => ctx.on("session/disposed", () => {
|
|
4111
|
+
const jobs = ctx.get("jobs");
|
|
4112
|
+
if (jobs === void 0) return;
|
|
4113
|
+
try {
|
|
4114
|
+
reclaimOcrJobs(jobs, localeMessages(ctx).jobReasonSessionStopped);
|
|
4115
|
+
} catch {}
|
|
4116
|
+
}), "ocr-review: session stop reaps background runs");
|
|
3651
4117
|
host.inject(["settings"], (child) => {
|
|
3652
4118
|
child.effect(() => child.settings.configure({ auto: false }, host.fiber));
|
|
3653
4119
|
});
|
|
3654
|
-
registerReviewTool(host, config);
|
|
3655
|
-
registerScanTool(host, config);
|
|
3656
|
-
registerDelegatePreviewTool(host, config);
|
|
3657
|
-
registerDelegateRuleTool(host, config);
|
|
3658
|
-
registerSessionTool(host, config);
|
|
4120
|
+
registerReviewTool(host, config, probe);
|
|
4121
|
+
registerScanTool(host, config, probe);
|
|
4122
|
+
registerDelegatePreviewTool(host, config, probe);
|
|
4123
|
+
registerDelegateRuleTool(host, config, probe);
|
|
4124
|
+
registerSessionTool(host, config, probe);
|
|
3659
4125
|
host.systemPrompt.section({
|
|
3660
4126
|
name: ROUTING_NAME,
|
|
3661
4127
|
order: ROUTING_ORDER,
|
|
3662
4128
|
text: localeMessages(host).routingText
|
|
3663
4129
|
});
|
|
3664
4130
|
host.inject(["webServer"], (child) => {
|
|
3665
|
-
registerConfigEndpoints(child, host, config, randomUUID()
|
|
4131
|
+
registerConfigEndpoints(child, host, config, randomUUID(), {
|
|
4132
|
+
verifyOf: () => endpointVerify.value,
|
|
4133
|
+
availability: probe
|
|
4134
|
+
});
|
|
3666
4135
|
});
|
|
3667
4136
|
}
|
|
3668
4137
|
var host_default = {
|
|
@@ -3673,7 +4142,9 @@ var host_default = {
|
|
|
3673
4142
|
"systemPrompt"
|
|
3674
4143
|
],
|
|
3675
4144
|
Config: configSchema,
|
|
3676
|
-
apply
|
|
4145
|
+
apply: (ctx, config) => {
|
|
4146
|
+
apply(ctx, config, productionProbe);
|
|
4147
|
+
}
|
|
3677
4148
|
};
|
|
3678
4149
|
//#endregion
|
|
3679
|
-
export { configSchema as Config, createGateway, host_default as default, isLoopbackBindAddress, ocrRepo, parseJsonBody, registerConfigEndpoints, requiredKeys };
|
|
4150
|
+
export { configSchema as Config, apply, assertOcrPresent, createGateway, host_default as default, isLoopbackBindAddress, ocrRepo, parseJsonBody, productionProbe, registerConfigEndpoints, requiredKeys };
|