@kyun.si/codex-polish 0.0.1-beta.3 → 0.0.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/CONTRIBUTING.en.md +6 -6
- package/CONTRIBUTING.md +6 -6
- package/README.md +34 -64
- package/SECURITY.en.md +6 -4
- package/SECURITY.md +5 -3
- package/docs/README.zh-CN.md +56 -0
- package/docs/technical.en.md +66 -44
- package/docs/technical.md +62 -38
- package/evaluation/README.en.md +1 -1
- package/evaluation/README.md +1 -1
- package/package.json +1 -2
- package/plugins/codex-polish/.codex-plugin/plugin.json +1 -1
- package/plugins/codex-polish/hooks/editor_prompt.mjs +51 -0
- package/plugins/codex-polish/hooks/history.mjs +107 -66
- package/plugins/codex-polish/hooks/preferences.mjs +137 -114
- package/plugins/codex-polish/hooks/project_setting.mjs +40 -30
- package/plugins/codex-polish/hooks/recovery.mjs +2 -69
- package/plugins/codex-polish/hooks/rewrite_mode.mjs +19 -0
- package/plugins/codex-polish/skills/codex-polish/SKILL.md +3 -33
- package/plugins/codex-polish/skills/codex-polish/WORKFLOW.md +47 -0
- package/plugins/codex-polish/skills/codex-polish/references/acp.md +30 -17
- package/plugins/codex-polish/skills/codex-polish/references/codex-polish-editor.md +4 -2
- package/plugins/codex-polish/skills/codex-polish/scripts/acp_models.mjs +31 -6
- package/plugins/codex-polish/skills/codex-polish/scripts/acp_payload.mjs +55 -30
- package/plugins/codex-polish/skills/codex-polish/scripts/cli_io.mjs +2 -2
- package/plugins/codex-polish/skills/codex-polish/scripts/decisions.mjs +49 -58
- package/plugins/codex-polish/skills/codex-polish/scripts/editor_role.mjs +48 -0
- package/plugins/codex-polish/skills/codex-polish/scripts/format_reply.mjs +171 -0
- package/plugins/codex-polish/skills/codex-polish/scripts/previous_reply.mjs +31 -0
- package/plugins/codex-polish/skills/codex-polish/scripts/rewrite_material.mjs +28 -0
- package/plugins/codex-polish/skills/codex-polish/scripts/text_guard.mjs +65 -166
- package/plugins/codex-polish/skills/codex-polish-setup/SKILL.md +37 -11
- package/plugins/codex-polish/skills/codex-polish-setup/references/credentials.en.md +10 -8
- package/plugins/codex-polish/skills/codex-polish-setup/references/credentials.md +7 -5
- package/scripts/install.mjs +389 -123
- package/scripts/native_cache.mjs +5 -5
- package/README.en.md +0 -84
package/docs/technical.md
CHANGED
|
@@ -1,78 +1,106 @@
|
|
|
1
1
|
# 技术参考
|
|
2
2
|
|
|
3
|
-
[English](technical.en.md) · [项目首页](
|
|
3
|
+
[English](technical.en.md) · [项目首页](README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Codex Polish 支持 macOS 和 Linux,本地脚本使用 Node.js 22.16 或更高版本的内置模块。自动 hook 让 Codex 在原稿写完后直接执行[润色流程](../plugins/codex-polish/skills/codex-polish/WORKFLOW.md),只在最终回复中展示结果。用户点名润色时,[改写技能](../plugins/codex-polish/skills/codex-polish/SKILL.md) 执行同一份流程。[设置技能](../plugins/codex-polish/skills/codex-polish-setup/SKILL.md) 检查运行环境并保存项目设置。
|
|
6
6
|
|
|
7
7
|
## 模式、配置文件与查找规则
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Git 项目的设置保存在最近的仓库根目录的 `.codex/`。同一仓库的子目录共用这份设置,嵌套仓库和独立工作树分别保存。没有 Git 仓库时,设置保存在所选目录。
|
|
10
10
|
|
|
11
11
|
| 配置文件 | 取值范围与默认值 | 运行行为 |
|
|
12
12
|
| --- | --- | --- |
|
|
13
13
|
| `.codex/codex-polish.mode` | `auto`(默认)、`manual`、`off` | 未保存模式时使用 `auto`。在 Codex 的 **设置 → Hooks** 或 CLI `/hooks` 中信任插件的 `UserPromptSubmit`,再新开聊天,普通提问就会触发润色流程。`manual` 仅在点名时触发。两种模式都可以点名润色本轮问答,无需 hook。`off` 跳过所有润色请求。 |
|
|
14
|
+
| `.codex/codex-polish.rewrite-mode` | `normal`(默认)、`turbo` | 决定触发后如何改写。`normal` 沿用项目的 Decisions 设置,`turbo` 将符合条件的草稿直接交给 Gemini。 |
|
|
14
15
|
| `.codex/codex-polish.model` | 模型 ID,默认 `gemini-4-hydrogen`(Gemini 4 Hydrogen) | 保存当前项目选用的 Gemini 模型。选项在运行时通过 ACP 从当前登录的 Antigravity 账号实时读取,不同账号返回的列表可能不同。仅查看模型菜单不会发送草稿或历史。下次改写时会核对所选模型,若已下线则本轮保留原稿。 |
|
|
15
|
-
| `.codex/codex-polish.
|
|
16
|
-
| `.codex/codex-polish.
|
|
17
|
-
| `.codex/codex-polish.
|
|
16
|
+
| `.codex/codex-polish.prompt.md` | UTF-8 纯文本,默认使用当前模式的内置提示词 | 自定义文本从下一次改写起生效。同一项目中新开的聊天沿用该设置。 |
|
|
17
|
+
| `.codex/codex-polish.history-turns` | `0`–`10` 的整数,默认 `2` | 控制 Gemini 改写时附带的最近完整问答轮数,从下次改写起生效。设为 `0` 就不附历史问答。保存大于 `10` 的值会报错。文件中的值不在范围内或格式无效时,本轮不带历史。无论手动还是自动模式,读取历史都需要受信任的 `UserPromptSubmit` hook。 |
|
|
18
|
+
| `.codex/codex-polish.decisions` | `auto`(默认)、`off` | 普通改写模式使用此设置。`auto` 按 `OPENAI_API_KEY` 决定是否调用 OpenAI,`off` 始终只用 ACP。 |
|
|
19
|
+
| `.codex/codex-polish.language` | `auto`(默认)、`zh`、`en` | 控制插件设置与终端提示语言。`auto` 下,设置对话优先跟随本条消息所用的中文或英文。只点击菜单或回复数字时沿用对话语言。两者都无法判断时使用系统语言。终端也使用系统语言,未识别出中文或英文时用英文。 |
|
|
20
|
+
|
|
21
|
+
在聊天中说“切换到 Turbo 模式”或“恢复普通模式”即可保存项目偏好。要从源码目录切换,可运行 `node plugins/codex-polish/hooks/preferences.mjs set-rewrite-mode turbo --cwd /path/to/project`,恢复时将 `turbo` 换为 `normal`。用 `check --cwd /path/to/project` 查看生效的 `rewrite_mode`。无效设置会在本地停止润色,重新选择任一模式即可恢复。
|
|
22
|
+
|
|
23
|
+
“这题用 Turbo”只对当前回复生效。“让 Gemini 重写刚才讲缓存的那条”会用 Turbo 处理同一聊天里指定的旧回复。Codex 根据整句话判断用户是否在要求改写,以及指的是哪一条。例如“解释一下 Turbo”只是在提问。单次请求使用 `--trigger turbo`,直接走 ACP,项目的 `rewrite-mode` 文件只在用户要求修改默认模式时写入。项目处于 `manual` 时可以点名改写,`off` 时会跳过。
|
|
18
24
|
|
|
19
25
|
有关 Codex 如何加载插件、注册 hook 以及取得用户信任,参见 [Codex 插件与 hook](https://developers.openai.com/plugins/build/plugins) 和 [项目 hook 和信任机制](https://learn.chatgpt.com/docs/hooks#where-codex-looks-for-hooks)。
|
|
20
26
|
|
|
27
|
+
### 查看、设置或恢复润色提示词
|
|
28
|
+
|
|
29
|
+
可以在聊天中说“查看润色提示词”“把项目润色提示词设为:先写结论,再讲依据。”或“恢复默认润色提示词”。也可以在源码根目录执行下面的本地命令,将 `/path/to/project` 换成目标项目的路径。`set-prompt` 从标准输入逐字保存文本,包括换行和首尾空格。`prompt` 返回当前生效的文本 `text` 及其来源 `source`(`default` 或 `custom`)。没有自定义提示词时,返回当前改写模式的内置文本。设定自定义提示词后,普通和 Turbo 模式都以 `text` 原文作为 Gemini 的全部编辑指令。角色文件头部配置 ACP 会话与工具权限,正文只有这段原文。
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
node plugins/codex-polish/hooks/preferences.mjs prompt --cwd /path/to/project
|
|
33
|
+
node plugins/codex-polish/hooks/preferences.mjs set-prompt --cwd /path/to/project < my-prompt.md
|
|
34
|
+
node plugins/codex-polish/hooks/preferences.mjs set-prompt --reset --cwd /path/to/project
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
可以直接编辑项目提示词文件。恢复默认会删除该文件。无效 UTF-8、纯空白、受限控制字符或疑似凭据会让润色暂停,更正提示词或恢复默认即可。
|
|
38
|
+
|
|
21
39
|
## 改写流程与判定阈值
|
|
22
40
|
|
|
23
|
-
插件支持直接 ACP 和 OpenAI Decisions 加 ACP
|
|
41
|
+
插件支持直接 ACP 和 OpenAI Decisions 加 ACP 两条路径。Turbo 始终跳过 OpenAI,将每份符合条件的草稿直接交给 Gemini。其内置提示词要求 Gemini 主动改写。普通模式下,当 `OPENAI_API_KEY` 未设置、为空或仅含空白字符,或项目已关闭风格检查时,插件直接使用 ACP。此时由 `agy` 联系 Google,本地 Node.js 脚本不发网络请求。开启 Decisions 时,Node.js 脚本只在改写前调用一次 OpenAI `gpt-6-luna`,判断草稿是否需要润色。每轮最多提交一次含草稿的 ACP 请求。当前 Codex agent 负责启动和回收进程,并在同一会话中收发协议消息。[ACP 操作步骤](../plugins/codex-polish/skills/codex-polish/references/acp.md)
|
|
24
42
|
|
|
25
|
-
| 阶段 |
|
|
43
|
+
| 阶段 | 行为 |
|
|
26
44
|
| --- | --- |
|
|
27
|
-
| 1.
|
|
28
|
-
| 2. 风格判定 | 直接 ACP
|
|
29
|
-
| 3. ACP 改写 |
|
|
30
|
-
| 4.
|
|
31
|
-
| 5. 原意复核与交付 | 直接 ACP 路径通过本地校验即采用改稿。开启 Decisions 时,有改动的候选还需满足 `P(实质变化) ≤ 0.05`。任一阶段未通过均回退原稿,用户取消则直接结束本轮。 |
|
|
45
|
+
| 1. 本地输入检查 | 检查本轮问题和草稿中的疑似凭据。检测到疑似凭据、用户要求固定格式(如仅输出 JSON 或命令),或草稿结构不适合改写时,直接交付原稿。 |
|
|
46
|
+
| 2. 风格判定 | 直接 ACP 路径在本地检查通过后进入改写。开启 Decisions 时,OpenAI 只根据本轮问题、草稿和已设置的自定义润色提示词判断是否需要改写,只有 `P(需要改写) > 0.50` 才进入改写。 |
|
|
47
|
+
| 3. ACP 改写 | Gemini 从编辑角色正文加载项目当前生效的提示词。在临时工作区关闭默认内置工具,使用已配置的 Antigravity 身份建立会话,发送前核对项目设置和所选模型。Codex 拒绝权限请求,只拼接本次会话的回复正文。收到非空正文和请求 ID 匹配的 `end_turn` 后进入显示阶段。 |
|
|
48
|
+
| 4. 显示回复 | 两种模式都将 Gemini 返回的完整正文直接排版交付。比较两版时忽略首尾空白和换行符差异,只用于决定显示一份还是两份。 |
|
|
32
49
|
|
|
33
50
|
相关接口规范见 [Google ACP 认证](https://antigravity.google/docs/ide/extensions/acp)、[Decisions API](https://developers.openai.com/api/reference/resources/decisions/methods/create) 与 [Antigravity 角色的工具配置](https://github.com/google-antigravity/antigravity-cli/releases/tag/1.2.1)。
|
|
34
51
|
|
|
35
52
|
## 最终回复如何显示
|
|
36
53
|
|
|
37
|
-
|
|
54
|
+
Gemini 返回的正文有改动时,Codex 在同一条最终消息中先显示 **Gemini 润色版**。在 Codex App 中,点击下方的“查看 GPT 原稿”即可展开完整原稿,再点一次收起。普通原稿保留 Markdown 排版。原稿包含折叠标签或容器分隔符时,展开后显示 Markdown 源文,方便逐字查看这些标记。
|
|
55
|
+
|
|
56
|
+
如果 Gemini 确实返回了相同的文字,回复会说明 Gemini 返回了原文,正文只显示一次。发送前跳过润色,或 ACP 请求未能取得完整正文时,回复说明可确认的原因,并显示原稿。明确要求“只给润色后的正文”时,改写完成后只显示 Gemini 正文。JSON、单条命令及其他逐字输出按用户要求直接交付,不加标题或状态。
|
|
57
|
+
|
|
58
|
+
用户选中一段文字或指定改写之前的 Gemini 版本时,折叠标题为“查看原文”。这种请求会附上对应的问题和本次改写要求,省略额外的历史问答。
|
|
38
59
|
|
|
39
|
-
|
|
60
|
+
排版时,如果 ACP 回复中的图表引用丢失了分隔符,且能明确对应原稿中的引用,插件会补回分隔符。Gemini 更改或省略图表引用时,仍显示它返回的正文。无法对应原稿的新增图表标记以文本显示。
|
|
40
61
|
|
|
41
|
-
##
|
|
62
|
+
## 发送给服务商的内容与历史限制
|
|
42
63
|
|
|
43
|
-
|
|
64
|
+
启用 OpenAI Decisions 时,发给 OpenAI 的 `input_json.data` 只包含本轮 `question`、`draft`,以及项目已设置的 `editor_prompt`。发给 Gemini 的 ACP 消息包含待改回复对应的 `question`、`draft` 和可选的 `history`。如果用户在单次 Turbo 请求里另提了改写要求,`rewrite_request` 会把要求一并带给 Gemini。自定义提示词仍通过 Antigravity 编辑角色传入。问题、草稿和历史都按原文发送,包括其中的代码、命令、路径、链接、引文和数字。
|
|
44
65
|
|
|
45
|
-
|
|
66
|
+
受信任的 hook 在本机记录会话文件的位置和当前轮次,以便用户点名重写之前的回复。即使历史设为 0,这条定位记录也只含元数据。取旧回复时,`question` 和 `draft` 来自同一轮。该轮若展示过润色版和原稿,就取折叠的 GPT 原稿。无法确认目标时,先请用户指明或提供原文。
|
|
46
67
|
|
|
47
|
-
|
|
68
|
+
`history` 从待改回复之前的完整问答中选取,按时间顺序发送。每轮包括用户消息(含同轮补充)和 Codex 最终答复。工具输出、进度提示、含疑似凭据或附件的轮次均会跳过。目标问答不占历史名额。可附带 0 到 10 轮,默认 2 轮。历史设为 0、未信任 hook、没有可用历史或用户要求这次不带历史时,ACP 消息省略 `history`。
|
|
69
|
+
|
|
70
|
+
OpenAI 对每个 `input_json.data` 规定 256 KiB 的紧凑 UTF-8 JSON、最多 32 层容器和 10,000 个值。插件在一个这样的字段中提交本轮的风格检查材料,一次只问一个判断题。超过接口大小限制的材料会完整交给 Gemini。`gpt-6-luna` 模型卡另列 1,050,000 token 的上下文窗口。[Decisions 接口](https://developers.openai.com/api/reference/resources/decisions/methods/create) · [GPT-6 Luna 模型卡](https://developers.openai.com/api/docs/models/gpt-6-luna)
|
|
71
|
+
|
|
72
|
+
Google 为默认模型 `gemini-4-hydrogen` 的 Gemini API 公布了 1,048,576 token 的共享窗口,输入、推理和最终输出均占用这个窗口。使用 Antigravity 时还要考虑会话本身的开销和所选模型,例如 Antigravity 对 Gemini 4 Neon 明列最多 512K token。Google 的 ACP 文档未给出 Hydrogen 单条润色请求的确切字节上限。`agy` 1.5.8 起会在创建会话和切换模型后报告会话窗口用量。[Hydrogen 模型卡](https://aistudio.google.com/docs/models/gemini-4-hydrogen) · [Antigravity 模型说明](https://antigravity.google/docs/models#gemini-4-neon) · [Antigravity CLI 1.5.8](https://github.com/google-antigravity/antigravity-cli/releases/tag/1.5.8)
|
|
48
73
|
|
|
49
74
|
插件自身不写草稿日志。Codex 宿主日志、服务商侧日志以及机器上全局配置的 Antigravity hooks 仍按各自的环境配置运行。服务商的数据处理遵循各自条款,与本项目的 Apache License 2.0 代码许可无关,可参阅 [Google 使用说明](https://antigravity.google/docs/faq)。
|
|
50
75
|
|
|
51
|
-
##
|
|
76
|
+
## 认证与故障处理
|
|
52
77
|
|
|
53
78
|
插件要求官方 Antigravity CLI(`agy`)1.2.1 或更高版本,先在 Codex 的 `PATH` 中查找 `agy`,再查 `~/.local/bin/agy`。默认通过 `agy acp` 复用本机已有登录,无需配置 Gemini API 密钥,也从不调用 `agy -p`。旧配置如需沿用 AI Studio 密钥可设 `CODEX_POLISH_AGY_AUTH=gemini-api-key`,企业环境可设 `agent-platform`。凭据必须配置在运行 Codex 的机器和对应系统用户下,详见 [首次配置指南](../plugins/codex-polish/skills/codex-polish-setup/references/credentials.md)。
|
|
54
79
|
|
|
55
80
|
| 故障类型 | 回退与限制行为 |
|
|
56
81
|
| --- | --- |
|
|
57
|
-
|
|
|
58
|
-
| Decisions
|
|
82
|
+
| Google 认证方式不支持、缺少 agy 或宿主工具不可用 | 保留原稿。插件依次在 PATH 和 ~/.local/bin 查找 agy。 |
|
|
83
|
+
| Decisions 不可用、密钥无效、响应无效或材料超过接口限额 | 通过本地检查后,直接交给 Gemini。每一轮独立判断。 |
|
|
59
84
|
| ACP 握手失败、未登录、账号无所选模型或中途切换模型 | 当前 agent 结束本次 ACP 请求,回收进程并交付原稿。 |
|
|
60
|
-
|
|
|
61
|
-
| 占位符错位、数值单位改动、出现疑似凭据或原意复核超标 | 整篇改稿丢弃并交付原稿,模型思考与其他会话消息不会混入正文。 |
|
|
85
|
+
| 生成耗时较长或中断 | 进程仍在运行时继续等待。宿主或服务端明确超时、取消、断流或返回不完整时丢弃候选,同一请求最多发送一次。 |
|
|
62
86
|
| 本轮中途停用、修改要求或取消 | 外发前重新核对项目模式。收到新要求时丢弃旧候选,按新要求作答。用户取消则结束本轮。若只有服务端取消,用户仍在等待,就交付原稿。 |
|
|
63
87
|
|
|
64
|
-
自动模式下,连接失败、超时、限流或服务异常会让当前 Codex 配置下的该项目暂停自动润色 **60 秒**。认证失败、明确的 OpenAI 配额耗尽或所选 Gemini 模型不可用会暂停 **5 分钟**。固定格式跳过、正常拒答和改稿校验驳回不会触发冷却。每条冷却记录只包含作用域哈希、固定故障码、时间戳和随机标记。用户在修好环境后可以随时在新一轮点名手动重试。
|
|
65
|
-
|
|
66
88
|
## 安装、更新和卸载
|
|
67
89
|
|
|
68
|
-
|
|
90
|
+
在项目目录运行 `npx @kyun.si/codex-polish@beta setup` 即可安装。将最后一个参数换成 `update`、`doctor` 或 `uninstall` 即可更新、检查当前项目或卸载。从 GitHub 源码安装时,在仓库根目录运行 `node scripts/install.mjs setup`,其余子命令相同。[安装步骤](README.zh-CN.md#快速开始)
|
|
91
|
+
|
|
92
|
+
在 macOS 上也可以解压仓库,在 Finder 中双击[安装回复润色.command](../安装回复润色.command),按提示选择要配置的项目。
|
|
69
93
|
|
|
70
94
|
`setup` 和 `update` 支持 `--install-agy`,在缺少 Antigravity CLI 时可自动安装。更新会保留项目设置与插件启用状态。同一版本号的新构建也能用 `update` 覆盖或重试中断的更新。
|
|
71
95
|
|
|
72
|
-
|
|
96
|
+
安装器为每份 Codex 配置注册一个本地市场。更新时先准备并校验新快照,然后原子替换市场清单,再请 Codex 刷新插件缓存。刷新失败时会恢复原快照和启用状态。Codex 判断 hook 信任时会核对已安装插件的内容,所以即使命令没变,内置提示词或配置指南的改动也可能触发重新确认。安装器和 `doctor` 都从 `hooks/list` 读取实际状态。
|
|
97
|
+
|
|
98
|
+
手头有本地打包的 `0.0.1-beta.5` 版时,也可以在压缩包所在目录运行 `npx --yes file:./kyun.si-codex-polish-0.0.1-beta.5.tgz uninstall`。卸载会清理该插件与专用市场,按当前 Codex 配置清除会话指针,保留各项目的 `.codex/` 配置和共用的 `agy`,并提示被手动修改过的安装文件备份位置。
|
|
73
99
|
|
|
74
100
|
## 已验证记录与真机验收
|
|
75
101
|
|
|
102
|
+
本机实测使用一份带有 10 轮虚构问答(合计 16 KiB)的会话,并保存了自定义润色提示词。OpenAI 收到一次请求,材料只有 `question`、`draft`、`editor_prompt`,返回 HTTP 200。随后 Gemini 4 Hydrogen 通过 ACP 收到全部 10 轮历史并完成了改写。
|
|
103
|
+
|
|
76
104
|
在完整源码的根目录运行以下离线测试和合成数据报告。发行包附带中英文评测说明,测试脚本、统计脚本和示例数据需从源码获取。参见 [源码测试与贡献指南](../CONTRIBUTING.md)。
|
|
77
105
|
|
|
78
106
|
```sh
|
|
@@ -80,18 +108,14 @@ npm test
|
|
|
80
108
|
node evaluation/report.mjs evaluation/example.jsonl
|
|
81
109
|
```
|
|
82
110
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```sh
|
|
86
|
-
CODEX_POLISH_TEST_LIVE_DECISIONS=1 node --test --test-name-pattern='live fidelity' tests/decisions.test.mjs
|
|
87
|
-
```
|
|
111
|
+
Decisions 测试使用模拟的 OpenAI 响应检查风格判定阈值和接口报错时的处理。
|
|
88
112
|
|
|
89
|
-
源码中的 `tests/fixture_acp.mjs`
|
|
113
|
+
源码中的 `tests/fixture_acp.mjs` 是专供测试的模拟服务端,覆盖正常改写、认证失败、模型缺失、生成期换模型、权限请求、取消无响应的生成、断流和跨会话消息交错,不会安装到最终产物中。安装回归测试会在本机已装好 Codex CLI 和 npm 的前提下创建一次性 Codex 配置,打出发版压缩包,验证 macOS 双击脚本以及从 `.tgz` 安装、更新、检查和卸载的全流程,并通过 Codex CLI 确认 Setup 已启用、`UserPromptSubmit` 已注册且等待信任。本地 T3 Code Beta 的 Codex 配置中也能发现 `codex-polish` 和 `codex-polish-setup`,两者都显示已启用。一次 T3 Code 实测中,用户要求用单次 Turbo 重写当前对话里可见的上一条答复。Codex 通过 ACP 调用 Gemini 4 Hydrogen,最终消息包含改稿和原稿。
|
|
90
114
|
|
|
91
|
-
在 macOS 上用 Node.js 22.16 和官方 Antigravity CLI 1.5.12 做过一次真实改写。测试环境的 PATH 中没有 Python,也没有配置 OpenAI 密钥。当前 Codex agent 通过 ACP 选中了 `gemini-4-hydrogen
|
|
115
|
+
在 macOS 上用 Node.js 22.16 和官方 Antigravity CLI 1.5.12 做过一次真实改写。测试环境的 PATH 中没有 Python,也没有配置 OpenAI 密钥。当前 Codex agent 通过 ACP 选中了 `gemini-4-hydrogen`,改稿保留了本地测试通过、线上尚未验证的事实。Node 辅助脚本没有向网络发出请求。
|
|
92
116
|
|
|
93
117
|
真人偏好仍待盲评。可用已获授权并去除敏感信息的真实样本完成以下验收。
|
|
94
118
|
|
|
95
|
-
1.
|
|
96
|
-
2. 用超过 4 KiB 的中文长文在两个 Codex
|
|
97
|
-
3.
|
|
119
|
+
1. 在 T3 Code 的普通模式下,分别在无 OpenAI 密钥和开启 Decisions 的项目中核对工具记录,确认只有当前 agent 持有 ACP 进程、模型选择准确且结束后进程回收干净。
|
|
120
|
+
2. 用超过 4 KiB 的中文长文在两个 Codex 会话中并发运行,确认正文和会话 ID 不串线,并核对缺模型、权限请求、取消和断流时的回退表现。
|
|
121
|
+
3. 在原生最终消息和重开会话后的记录中核对状态、两版顺序及正文。在支持折叠的客户端,确认新回复里的原稿默认收起,展开后对照原稿,并将润色版与 Gemini 返回的改稿逐字核对。统计盲评偏好、严重事实反转、漏调率、选定正文的逐字一致率和端到端延迟。统计门槛要求校准集和盲评集合计至少 200 个已交付的真实样本。[验收数据格式和指标](../evaluation/README.md)
|
package/evaluation/README.en.md
CHANGED
|
@@ -25,7 +25,7 @@ node --test tests/evaluation.test.mjs
|
|
|
25
25
|
| `needs_rewrite` | `true` when human review judges that the original draft needs rewriting |
|
|
26
26
|
| `workflow_expected`, `workflow_ran` | Whether the turn should run through the plugin, and whether the host trace shows it actually ran. Turns skipped by rule can be `false` |
|
|
27
27
|
| `triggered` | `true` when the check decides to trigger an external rewrite, even if a failure happens afterward |
|
|
28
|
-
| `outcome` | `original` when
|
|
28
|
+
| `outcome` | `original` when the draft is delivered without triggering a rewrite, `adopted` when Gemini’s complete reply is delivered (including unchanged text), `fallback` when a workflow failure prevents a complete reply and the original is delivered, `cancelled` when the user cancels and nothing is delivered |
|
|
29
29
|
| `selected_text`, `final_text` | Take the first from the chosen rewrite or original draft. Independently take the second from its corresponding body in the native final message. Use the polished body when both versions appear, or the sole body when one appears. Exclude plugin labels and status. Preserve punctuation, spaces, and newlines within the body. Omit or set to `null` when cancelled |
|
|
30
30
|
| `elapsed_ms` | Total milliseconds from draft ready to native final message display. Set to `null` when unmeasured or cancelled |
|
|
31
31
|
| `severe_fact_reversal` | Human fact-check result for the delivered reply. Set `true` if a severe reversal is found, `false` if checked and none is found, or `null` if unchecked or cancelled |
|
package/evaluation/README.md
CHANGED
|
@@ -25,7 +25,7 @@ node --test tests/evaluation.test.mjs
|
|
|
25
25
|
| `needs_rewrite` | 人工判断原稿需要改写时为 `true` |
|
|
26
26
|
| `workflow_expected`、`workflow_ran` | 该回合是否应走插件,以及从宿主轨迹观察到是否实际运行。按约定跳过的回合可填 `false` |
|
|
27
27
|
| `triggered` | 判定触发外部改写时为 `true`,即使随后发生故障 |
|
|
28
|
-
| `outcome` | `original`
|
|
28
|
+
| `outcome` | `original` 未触发改写并交付原稿,`adopted` 交付 Gemini 返回的完整正文(包括返回原文),`fallback` 工作流因故障未取得完整回复并交付原稿,`cancelled` 用户取消且本轮未交付 |
|
|
29
29
|
| `selected_text`、`final_text` | 前者取自选定的改稿或原稿,后者独立取自原生最终消息中对应的正文。双版本回复只取润色版正文,单版本回复取唯一正文。排除插件添加的标签和状态,保留正文自身的标点、空格和换行。取消时省略或填 `null` |
|
|
30
30
|
| `elapsed_ms` | 草稿就绪到原生最终消息显示的总毫秒数。缺测或取消填 `null` |
|
|
31
31
|
| `severe_fact_reversal` | 对已交付正文的人工结论。发现严重反转填 `true`,已检查且无反转填 `false`,未检查或取消填 `null` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyun.si/codex-polish",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Codex plugin that rewrites replies with Gemini via Antigravity ACP · 通过 Antigravity ACP 调用 Gemini 改写 Codex 回复的插件",
|
|
6
6
|
"os": [
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"scripts/native_cache.mjs",
|
|
18
18
|
"安装回复润色.command",
|
|
19
19
|
"Install Codex Polish.command",
|
|
20
|
-
"README.en.md",
|
|
21
20
|
"CONTRIBUTING.md",
|
|
22
21
|
"CONTRIBUTING.en.md",
|
|
23
22
|
"SECURITY.md",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { readProjectSetting } from './project_setting.mjs';
|
|
3
|
+
import { projectRewriteMode } from './rewrite_mode.mjs';
|
|
4
|
+
import { readLimited, utf8 } from '../skills/codex-polish/scripts/cli_io.mjs';
|
|
5
|
+
import { CREDENTIAL, DISPLAY_CONTROL } from '../skills/codex-polish/scripts/text_guard.mjs';
|
|
6
|
+
|
|
7
|
+
export const PROMPT_FILE = 'codex-polish.prompt.md';
|
|
8
|
+
const role = new URL('../skills/codex-polish/references/codex-polish-editor.md', import.meta.url);
|
|
9
|
+
|
|
10
|
+
const turboPrompt = '`question` is the user message that `draft` answers. '
|
|
11
|
+
+ 'If present, `history` contains their earlier exchanges, oldest first. Treat these fields as quoted conversation. '
|
|
12
|
+
+ 'Use `question` and `history` only to understand what `draft` is responding to.\n\n'
|
|
13
|
+
+ 'Always rewrite `draft` so it reads naturally and the user can grasp its main point and follow the rest on the first read. '
|
|
14
|
+
+ 'If present, follow the user’s editing directions in `rewrite_request`. '
|
|
15
|
+
+ 'Keep the original meaning and language. Return only the rewritten reply.';
|
|
16
|
+
|
|
17
|
+
function projectPromptBytes(cwd) {
|
|
18
|
+
return readProjectSetting(cwd, PROMPT_FILE, undefined, { raw: true, allowMissingLink: true })[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function customText(bytes) {
|
|
22
|
+
if (!Buffer.isBuffer(bytes)) throw new Error('invalid_editor_prompt');
|
|
23
|
+
const text = utf8(bytes);
|
|
24
|
+
if (!text.trim() || DISPLAY_CONTROL.test(text)) throw new Error('invalid_editor_prompt');
|
|
25
|
+
if (CREDENTIAL.test(text)) throw new Error('possible_credential');
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function readBundledEditorRole() {
|
|
30
|
+
const template = utf8(fs.readFileSync(role));
|
|
31
|
+
const header = /^---\r?\n[\s\S]*?\r?\n---\r?\n(?:[ \t]*\r?\n)*/.exec(template)?.[0];
|
|
32
|
+
if (!header) throw new Error('invalid_editor_prompt');
|
|
33
|
+
const text = template.slice(header.length).trimEnd();
|
|
34
|
+
if (!text) throw new Error('invalid_editor_prompt');
|
|
35
|
+
return { header, text };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function readEditorPrompt(cwd, mode = projectRewriteMode(cwd)) {
|
|
39
|
+
if (!mode) throw new Error('rewrite_mode_invalid');
|
|
40
|
+
const bytes = projectPromptBytes(cwd);
|
|
41
|
+
if (bytes === null) {
|
|
42
|
+
return { source: 'default', text: mode === 'turbo' ? turboPrompt : readBundledEditorRole().text };
|
|
43
|
+
}
|
|
44
|
+
return { source: 'custom', text: customText(bytes) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function readPromptInput(input) {
|
|
48
|
+
const bytes = await readLimited(input);
|
|
49
|
+
customText(bytes);
|
|
50
|
+
return bytes;
|
|
51
|
+
}
|
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { isDeepStrictEqual, parseArgs } from 'node:util';
|
|
5
|
-
import {
|
|
5
|
+
import { originalReplyText } from '../skills/codex-polish/scripts/format_reply.mjs';
|
|
6
|
+
import { CREDENTIAL, DISPLAY_CONTROL } from '../skills/codex-polish/scripts/text_guard.mjs';
|
|
6
7
|
import { DEFAULT_HISTORY_TURNS, MAX_HISTORY_TURNS } from './preferences.mjs';
|
|
7
8
|
|
|
8
|
-
export const MAX_HISTORY_BYTES = 16 * 1024;
|
|
9
|
-
export const MAX_SCAN_BYTES = 4 * 1024 * 1024;
|
|
10
|
-
const MAX_HEADER_BYTES = 1024 * 1024;
|
|
11
9
|
const HOST_TEXT = /^\s*(?:<\/?(?:environment_context|system-reminder|subagent_notification|turn_aborted|user_shell_command|task-notification|user_instructions|skills_instructions|permissions|developer_instructions|instructions|goal_context|ide_context|local-command-[\w-]+|agent_message|skill|t3_code_[\w-]+)(?:[\s>/])|# AGENTS\.md instructions\b|# (?:Context from my IDE setup|Files mentioned by the user):|Subagent completed:)/im;
|
|
12
10
|
const ATTACHMENTS = ['images', 'file_ids', 'local_images', 'audio', 'audio_references', 'local_audio'];
|
|
13
11
|
|
|
14
12
|
function safeText(text) {
|
|
15
|
-
return typeof text === 'string' && text.trim() !== '' && text.
|
|
16
|
-
!CREDENTIAL.test(text) && !DISPLAY_CONTROL.test(text) && !HOST_TEXT.test(text)
|
|
13
|
+
return typeof text === 'string' && text.trim() !== '' && text.isWellFormed() &&
|
|
14
|
+
!CREDENTIAL.test(text) && !DISPLAY_CONTROL.test(text) && !HOST_TEXT.test(text);
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
function textMessage(parts, kind) {
|
|
@@ -28,15 +26,22 @@ function present(value) {
|
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
class Turn {
|
|
31
|
-
constructor(start) {
|
|
29
|
+
constructor(start, interrupted) {
|
|
32
30
|
this.id = start.turn_id;
|
|
33
31
|
this.events = [];
|
|
34
32
|
this.messages = [];
|
|
35
33
|
this.answer = null;
|
|
34
|
+
this.previousInput = [];
|
|
35
|
+
this.turnIds = new Set([this.id]);
|
|
36
36
|
const source = start.turn_attribution ?? {};
|
|
37
37
|
this.ordinary = typeof source === 'object' && !Array.isArray(source) &&
|
|
38
|
-
[undefined, null, 'user', 'exec'].includes(source.turn_trigger) &&
|
|
39
|
-
!source.initiating_agent_path && !source.parent_turn_id && (start.root_turn_id ?? this.id) === this.id
|
|
38
|
+
[undefined, null, 'user', 'exec', 'composer', 'resume_interrupted_task'].includes(source.turn_trigger) &&
|
|
39
|
+
!source.initiating_agent_path && !source.parent_turn_id && (start.root_turn_id ?? this.id) === this.id &&
|
|
40
|
+
(source.root_turn_id ?? this.id) === this.id && (source.turn_id ?? this.id) === this.id;
|
|
41
|
+
if (this.ordinary && source.turn_trigger === 'resume_interrupted_task' && interrupted?.ordinary) {
|
|
42
|
+
this.previousInput = interrupted.userInput();
|
|
43
|
+
this.turnIds = new Set([...interrupted.turnIds, this.id]);
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
read(kind, item) {
|
|
@@ -64,92 +69,128 @@ class Turn {
|
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
userInput() {
|
|
73
|
+
return this.previousInput.concat(this.events.length ? this.events : this.messages);
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
finish(completed) {
|
|
68
|
-
const messages = this.
|
|
69
|
-
if (completed.last_agent_message !== this.answer || !safeText(this.answer) || !messages.every(safeText)) return null;
|
|
70
|
-
|
|
71
|
-
if (Buffer.byteLength(user) + Buffer.byteLength(this.answer) > MAX_HISTORY_BYTES) return null;
|
|
72
|
-
return { user, assistant: this.answer };
|
|
77
|
+
const messages = this.userInput();
|
|
78
|
+
if (completed.last_agent_message !== this.answer || !safeText(this.answer) || !messages.length || !messages.every(safeText)) return null;
|
|
79
|
+
return { user: messages.join('\n\n'), assistant: this.answer };
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
|
|
76
|
-
|
|
83
|
+
// Snapshot the size at open and stream complete JSONL records. Only the current
|
|
84
|
+
// turn and the configured number of completed exchanges stay in memory.
|
|
85
|
+
function* records(fd, size) {
|
|
86
|
+
const chunkSize = 64 * 1024;
|
|
87
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
88
|
+
let pending = [];
|
|
89
|
+
for (let pos = 0; pos < size;) {
|
|
90
|
+
const chunk = Buffer.allocUnsafe(Math.min(chunkSize, size - pos));
|
|
91
|
+
const count = fs.readSync(fd, chunk, 0, chunk.length, pos);
|
|
92
|
+
if (!count) throw new Error('truncated transcript');
|
|
93
|
+
pos += count;
|
|
94
|
+
const raw = chunk.subarray(0, count);
|
|
95
|
+
let start = 0;
|
|
96
|
+
for (let newline = raw.indexOf(10); newline !== -1; newline = raw.indexOf(10, start)) {
|
|
97
|
+
const part = raw.subarray(start, newline);
|
|
98
|
+
const line = pending.length ? Buffer.concat([...pending, part]) : part;
|
|
99
|
+
pending = [];
|
|
100
|
+
yield JSON.parse(decoder.decode(line));
|
|
101
|
+
start = newline + 1;
|
|
102
|
+
}
|
|
103
|
+
if (start < raw.length) pending.push(raw.subarray(start));
|
|
104
|
+
}
|
|
105
|
+
if (pending.length) throw new Error('incomplete transcript');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function completedExchanges(rows, sessionId, turnId, limit, { previous = false, through = Infinity } = {}) {
|
|
77
109
|
const last = [];
|
|
110
|
+
let count = 0;
|
|
111
|
+
let header = false;
|
|
78
112
|
let active = null;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (typeof kind !== 'string') return
|
|
113
|
+
let interrupted = null;
|
|
114
|
+
for (const { type: kind, payload: item } of rows) {
|
|
115
|
+
if (typeof kind !== 'string' || (!header && kind !== 'session_meta')) return null;
|
|
82
116
|
if (!['session_meta', 'event_msg', 'response_item'].includes(kind)) continue;
|
|
83
|
-
if (!item || typeof item !== 'object' || Array.isArray(item)) return
|
|
117
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) return null;
|
|
84
118
|
if (kind === 'session_meta') {
|
|
85
|
-
if (item.id !== sessionId
|
|
119
|
+
if (header || item.id !== sessionId || item.parent_thread_id || item.forked_from_id ||
|
|
120
|
+
item.source?.subagent || (item.thread_source != null && item.thread_source !== 'user')) return null;
|
|
121
|
+
header = true;
|
|
86
122
|
} else if (kind === 'event_msg' && item.type === 'task_started') {
|
|
87
|
-
active = typeof item.turn_id === 'string' && item.turn_id ? new Turn(item) : null;
|
|
88
|
-
|
|
123
|
+
active = typeof item.turn_id === 'string' && item.turn_id ? new Turn(item, interrupted) : null;
|
|
124
|
+
interrupted = null;
|
|
125
|
+
} else if (kind === 'event_msg' && item.type === 'turn_aborted') {
|
|
126
|
+
interrupted = item.reason === 'interrupted' && active?.id === item.turn_id ? active : null;
|
|
89
127
|
active = null;
|
|
90
|
-
|
|
128
|
+
} else if (kind === 'event_msg' && item.type === 'thread_rolled_back') {
|
|
129
|
+
interrupted = active = null;
|
|
130
|
+
count = 0;
|
|
131
|
+
last.length = 0;
|
|
91
132
|
} else if (kind === 'event_msg' && item.type === 'task_complete') {
|
|
92
|
-
if (active?.ordinary && active.
|
|
93
|
-
(
|
|
94
|
-
|
|
95
|
-
|
|
133
|
+
if (active?.ordinary && !active.turnIds.has(turnId) && item.turn_id === active.id &&
|
|
134
|
+
(item.last_agent_message || (previous && active.answer != null)) &&
|
|
135
|
+
(previous || (!present(item.error) && active.userInput().length))) {
|
|
136
|
+
count++;
|
|
137
|
+
if (limit && count <= through) {
|
|
138
|
+
last.push(present(item.error) ? null : active.finish(item));
|
|
139
|
+
if (last.length > limit) last.shift();
|
|
140
|
+
}
|
|
96
141
|
}
|
|
97
|
-
active = null;
|
|
142
|
+
active = interrupted = null;
|
|
98
143
|
} else {
|
|
99
144
|
active?.read(kind, item);
|
|
100
145
|
}
|
|
101
146
|
}
|
|
102
|
-
if (!active?.ordinary || (turnId !== null && active.
|
|
103
|
-
|
|
104
|
-
const result = [];
|
|
105
|
-
for (const exchange of last.reverse()) {
|
|
106
|
-
if (!exchange) continue;
|
|
107
|
-
budget -= Buffer.byteLength(exchange.user) + Buffer.byteLength(exchange.assistant);
|
|
108
|
-
if (budget < 0) break;
|
|
109
|
-
result.push(exchange);
|
|
110
|
-
}
|
|
111
|
-
return result.reverse();
|
|
147
|
+
if (!active?.ordinary || (turnId !== null && !active.turnIds.has(turnId))) return null;
|
|
148
|
+
return { last, count };
|
|
112
149
|
}
|
|
113
150
|
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
let count = 0;
|
|
117
|
-
while (count < length) {
|
|
118
|
-
const n = fs.readSync(fd, raw, count, length - count, start + count);
|
|
119
|
-
if (!n) break;
|
|
120
|
-
count += n;
|
|
121
|
-
}
|
|
122
|
-
return raw.subarray(0, count);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function readHistory(file, sessionId, turnId = null, turns = DEFAULT_HISTORY_TURNS) {
|
|
126
|
-
if (!Number.isInteger(turns) || turns <= 0 || !sessionId || typeof file !== 'string' || !path.isAbsolute(file)) return [];
|
|
151
|
+
function withTranscript(file, read) {
|
|
152
|
+
if (typeof file !== 'string' || !path.isAbsolute(file)) return null;
|
|
127
153
|
try {
|
|
128
154
|
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK | fs.constants.O_NOFOLLOW);
|
|
129
155
|
try {
|
|
130
156
|
const info = fs.fstatSync(fd);
|
|
131
|
-
if (!info.isFile()) return
|
|
132
|
-
|
|
133
|
-
const headerEnd = head.indexOf(10) + 1;
|
|
134
|
-
if (!headerEnd || info.size <= headerEnd) return [];
|
|
135
|
-
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
136
|
-
const { type, payload } = JSON.parse(decoder.decode(head.subarray(0, headerEnd)));
|
|
137
|
-
if (type !== 'session_meta' || payload?.id !== sessionId || payload.parent_thread_id || payload.forked_from_id) return [];
|
|
138
|
-
const start = Math.max(headerEnd, info.size - MAX_SCAN_BYTES);
|
|
139
|
-
let raw = readRange(fd, start, info.size - start);
|
|
140
|
-
if (raw.length !== info.size - start || raw.at(-1) !== 10) return [];
|
|
141
|
-
// Drop the truncated first line before decoding, since it may start mid-codepoint.
|
|
142
|
-
if (start > headerEnd) raw = raw.subarray(raw.indexOf(10) + 1);
|
|
143
|
-
if (!raw.length) return [];
|
|
144
|
-
return completedExchanges(decoder.decode(raw.subarray(0, -1)), sessionId, turnId, turns);
|
|
157
|
+
if (!info.isFile()) return null;
|
|
158
|
+
return read(() => records(fd, info.size));
|
|
145
159
|
} finally {
|
|
146
160
|
fs.closeSync(fd);
|
|
147
161
|
}
|
|
148
162
|
} catch {
|
|
149
|
-
return
|
|
163
|
+
return null;
|
|
150
164
|
}
|
|
151
165
|
}
|
|
152
166
|
|
|
167
|
+
export function readHistory(file, sessionId, turnId = null, turns = DEFAULT_HISTORY_TURNS) {
|
|
168
|
+
if (!Number.isInteger(turns) || turns <= 0 || !sessionId) return [];
|
|
169
|
+
const exchanges = withTranscript(file, rows =>
|
|
170
|
+
completedExchanges(rows(), sessionId, turnId, Math.min(turns, MAX_HISTORY_TURNS)));
|
|
171
|
+
return exchanges?.last.filter(Boolean) ?? [];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function readPreviousReply(file, sessionId, turnId, turns = DEFAULT_HISTORY_TURNS, turnsBack = 1) {
|
|
175
|
+
if (!turnId || !sessionId || !Number.isSafeInteger(turnsBack) || turnsBack < 1 ||
|
|
176
|
+
!Number.isInteger(turns) || turns < 0 || turns > MAX_HISTORY_TURNS) return null;
|
|
177
|
+
return withTranscript(file, rows => {
|
|
178
|
+
let through = Infinity;
|
|
179
|
+
if (turnsBack > 1) {
|
|
180
|
+
// Find the selected ordinal without retaining every intervening answer.
|
|
181
|
+
const scan = completedExchanges(rows(), sessionId, turnId, 0, { previous: true });
|
|
182
|
+
if (!scan || scan.count < turnsBack) return null;
|
|
183
|
+
through = scan.count - turnsBack + 1;
|
|
184
|
+
}
|
|
185
|
+
const scan = completedExchanges(rows(), sessionId, turnId, turns + 1, { previous: true, through });
|
|
186
|
+
const target = scan?.last.pop();
|
|
187
|
+
if (!target) return null;
|
|
188
|
+
const draft = originalReplyText(target.assistant);
|
|
189
|
+
if (!safeText(draft)) return null;
|
|
190
|
+
return { question: target.user, draft, history: scan.last.filter(Boolean) };
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
153
194
|
if (process.argv[1] && fs.existsSync(process.argv[1]) && fs.realpathSync(process.argv[1]) === import.meta.filename) {
|
|
154
195
|
try {
|
|
155
196
|
const { values } = parseArgs({ options: {
|