@kyun.si/codex-polish 0.0.1-beta.3 → 0.0.1-beta.4
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 +15 -0
- package/CONTRIBUTING.en.md +6 -6
- package/CONTRIBUTING.md +6 -6
- package/README.en.md +45 -17
- package/README.md +45 -17
- package/SECURITY.en.md +5 -3
- package/SECURITY.md +4 -2
- package/docs/technical.en.md +57 -41
- package/docs/technical.md +54 -34
- package/evaluation/README.en.md +1 -1
- package/evaluation/README.md +1 -1
- package/package.json +1 -1
- 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 +8 -6
- package/plugins/codex-polish/skills/codex-polish-setup/references/credentials.md +3 -3
- package/scripts/install.mjs +389 -123
- package/scripts/native_cache.mjs +5 -5
package/docs/technical.en.md
CHANGED
|
@@ -2,76 +2,94 @@
|
|
|
2
2
|
|
|
3
3
|
[简体中文](technical.md) · [Overview](../README.en.md)
|
|
4
4
|
|
|
5
|
-
Codex Polish `0.0.1-beta.
|
|
5
|
+
Codex Polish `0.0.1-beta.4` is a Codex plugin for macOS and Linux. Its local scripts use built-in Node.js modules and require Node.js 22.16 or newer. The automatic hook directs Codex to follow the [polishing workflow](../plugins/codex-polish/skills/codex-polish/WORKFLOW.md) once the draft is ready and show the result in the final reply. Explicit requests use the same workflow through the [rewrite skill](../plugins/codex-polish/skills/codex-polish/SKILL.md). The [setup skill](../plugins/codex-polish/skills/codex-polish-setup/SKILL.md) checks the environment and manages project settings.
|
|
6
6
|
|
|
7
|
-
## Project Settings
|
|
7
|
+
## Project Settings
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Settings live in the nearest Git repository’s root .codex directory. All directories in the same repository use those settings. Nested repositories and linked worktrees have their own settings. Outside Git, settings belong to the chosen folder.
|
|
10
10
|
|
|
11
11
|
| File | Values and Default | Behavior |
|
|
12
12
|
| --- | --- | --- |
|
|
13
13
|
| `.codex/codex-polish.mode` | `auto` (default), `manual`, `off` | Without a saved mode, the project uses `auto`. The trusted hook triggers polishing for ordinary questions. `manual` runs only on explicit requests. `off` skips rewrites even when requested. |
|
|
14
|
+
| `.codex/codex-polish.rewrite-mode` | `normal` (default), `turbo` | Once polishing is triggered, normal uses the saved Decisions setting. Turbo sends each eligible draft directly to Gemini. |
|
|
14
15
|
| `.codex/codex-polish.model` | Model ID, default `gemini-4-hydrogen` (Gemini 4 Hydrogen) | Stores the per-project Gemini model discovered from the signed-in Antigravity account over ACP. |
|
|
15
|
-
| `.codex/codex-polish.
|
|
16
|
-
| `.codex/codex-polish.
|
|
17
|
-
| `.codex/codex-polish.
|
|
16
|
+
| `.codex/codex-polish.prompt.md` | UTF-8 text, defaults to the active mode’s built-in prompt | Custom text takes effect on the next rewrite and carries over to new chats in the same project. |
|
|
17
|
+
| `.codex/codex-polish.history-turns` | Integer `0`–`10`, default `2` | Maximum completed exchanges to attach to a Gemini rewrite. Use `0` to omit earlier exchanges. Saving a value above `10` returns an error. An invalid or out-of-range setting disables history. Changes apply on the next rewrite. |
|
|
18
|
+
| `.codex/codex-polish.decisions` | `auto` (default), `off` | In normal mode, `auto` enables the OpenAI style check when `OPENAI_API_KEY` is set. `off` uses ACP only. This setting is independent of the trigger mode. |
|
|
19
|
+
| `.codex/codex-polish.language` | `auto` (default), `zh`, `en` | Sets the language for plugin prompts and setup checks. |
|
|
20
|
+
|
|
21
|
+
Say “Switch to turbo mode” or “Switch back to normal mode” to save the project preference. From a source checkout, run `node plugins/codex-polish/hooks/preferences.mjs set-rewrite-mode turbo --cwd /path/to/project`. Use `normal` to switch back. The `check --cwd /path/to/project` command reports the effective `rewrite_mode`. An invalid value pauses polishing locally until you save either mode.
|
|
22
|
+
|
|
23
|
+
“Use Turbo for this answer” applies to the current draft. “Have Gemini rewrite the answer about caching” uses Turbo on the selected earlier reply in the same chat. Codex interprets the request in context. A question like “What does Turbo do?” asks for an explanation. A one-time rewrite uses `--trigger turbo`, goes directly to ACP, and expires after the reply. Saving the project default takes a separate request. Explicit requests work in `manual` mode and are skipped in `off` mode.
|
|
18
24
|
|
|
19
25
|
When `.codex/codex-polish.language` is `auto`, chat prompts match the user's current message, falling back to the established chat language and then the system locale. Short replies such as menu numbers use the chat language. Terminal checks and the installer check the project setting first, then the system locale, and default to English.
|
|
20
26
|
|
|
27
|
+
### Show, set, or restore the polishing prompt
|
|
28
|
+
|
|
29
|
+
In chat, say “Show the polishing prompt”, “Set this project's polishing prompt to: Lead with the conclusion, then give the evidence”, or “Restore the default polishing prompt”. You can also run these commands locally from the root of a source checkout. Replace `/path/to/project` with the target project directory. The setter saves standard input verbatim, including line breaks and surrounding spaces. The reader returns the effective `text` and its `source` (`default` or `custom`). With no custom prompt, it returns the built-in text for the active rewrite mode. With a custom prompt, the returned `text` is the complete editing prompt for Gemini in both Normal and Turbo. The role file’s header configures the ACP session and tool access. Its body contains only that text.
|
|
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
|
+
You can edit the prompt file directly. Restoring the default removes the project prompt. Invalid UTF-8, whitespace-only contents, display controls or a suspected credential prevent polishing until the file is corrected or reset.
|
|
38
|
+
|
|
21
39
|
## Rewrite Routes, Stages, and Thresholds
|
|
22
40
|
|
|
23
|
-
- **Direct ACP.**
|
|
24
|
-
- **OpenAI Decisions and ACP.**
|
|
41
|
+
- **Direct ACP.** Turbo always uses this route, even with an OpenAI key. Its built-in prompt asks Gemini to actively rewrite each eligible draft. In normal mode, when `OPENAI_API_KEY` is missing, empty, or entirely whitespace, the plugin uses Gemini alone. Setting `codex-polish.decisions` to `off` has the same effect. Every eligible draft that passes local checks goes to Gemini, even if it already reads well.
|
|
42
|
+
- **OpenAI Decisions and ACP.** In normal mode with `codex-polish.decisions` set to `auto` and a nonblank key, the plugin checks the key’s format locally before contacting OpenAI. It sends one request to `gpt-6-luna` to decide whether the draft needs editing. [Decisions API](https://developers.openai.com/api/reference/resources/decisions/methods/create)
|
|
25
43
|
|
|
26
|
-
| Stage |
|
|
44
|
+
| Stage | Behavior |
|
|
27
45
|
| --- | --- |
|
|
28
|
-
| 1.
|
|
29
|
-
| 2. Style check | Direct ACP proceeds
|
|
30
|
-
| 3. ACP rewrite | The agent launches `agy acp` in a temporary workspace under a dedicated editor role, opens a session with the configured Antigravity identity, reads the live model list, and
|
|
31
|
-
| 4.
|
|
32
|
-
| 5. Meaning check and delivery | Direct ACP accepts the rewrite after local checks. With Decisions enabled, a changed candidate must also score `P(substantive change) <= 0.05` in the meaning check. Any stage failure returns the original draft, and user cancellation ends the turn. |
|
|
46
|
+
| 1. Local input checks | The plugin skips polishing if it detects a possible credential in the current question or draft, the user requests exact output such as JSON only, or the draft has an unsupported structure. |
|
|
47
|
+
| 2. Style check | Direct ACP proceeds after local checks. With Decisions enabled, OpenAI considers only the current question, draft, and any custom polishing prompt. Gemini rewrites when `P(needs rewrite) > 0.50`. |
|
|
48
|
+
| 3. ACP rewrite | Gemini loads the project’s effective prompt from the body of the editor role. The agent launches `agy acp` in a temporary workspace under a dedicated editor role, opens a session with the configured Antigravity identity, reads the live model list, and checks the project settings and selected model before sending. It rejects tool permission requests and collects only reply text from this session. The reply is ready to display once the agent has nonempty text and an `end_turn` matching the request ID. |
|
|
49
|
+
| 4. Display | Both modes format Gemini’s complete reply for display. The formatter ignores outer whitespace and line-ending differences when deciding whether to show one or both versions. |
|
|
33
50
|
|
|
34
|
-
During a rewrite, `agy` connects to Google. The plugin's Node.js scripts contact a provider only for the optional OpenAI
|
|
51
|
+
During a rewrite, `agy` connects to Google. The plugin's Node.js scripts contact a provider only for the optional OpenAI style check. The current Codex agent starts and cleans up the ACP process, selects the model, and exchanges protocol messages. [ACP operating instructions](../plugins/codex-polish/skills/codex-polish/references/acp.md)
|
|
35
52
|
|
|
36
53
|
The plugin requires the official Antigravity CLI 1.2.1 or later. By default it reuses the existing Antigravity sign-in on the machine and OS account running Codex. To use an AI Studio key or an enterprise identity, set `CODEX_POLISH_AGY_AUTH` to `gemini-api-key` or `agent-platform`, respectively. [Sign-in guide](../plugins/codex-polish/skills/codex-polish-setup/references/credentials.en.md) · [Google ACP authentication](https://antigravity.google/docs/ide/extensions/acp)
|
|
37
54
|
|
|
38
55
|
## What Appears in the Final Reply
|
|
39
56
|
|
|
40
|
-
When
|
|
57
|
+
When Gemini returns a changed reply, the final message starts with **Polished by Gemini**. In the Codex app, select “View original GPT draft” below the rewrite to expand the full draft. Select it again to collapse it. Drafts retain their Markdown formatting. When a draft contains disclosure tags or container delimiters, the expanded view shows its Markdown source so you can read those markers verbatim.
|
|
41
58
|
|
|
42
|
-
If Gemini returns identical text, the reply says it left the draft unchanged and shows the text once.
|
|
59
|
+
If Gemini returns identical text, the reply says it left the draft unchanged and shows the text once. If polishing is skipped before sending or the ACP request ends without a complete reply, the status explains what happened and the reply shows the original. Asking for “only the polished text” shows just Gemini’s text when the rewrite completes. Requests for plain JSON, a single command, or other exact output receive the requested content without labels or status.
|
|
60
|
+
|
|
61
|
+
When a visualization reference loses its delimiters in the ACP reply and unambiguously matches a reference in the draft, the formatter restores the delimiters. The formatter still displays Gemini’s reply if a reference changes or disappears. New visualization markers with no match in the draft appear as text.
|
|
43
62
|
|
|
44
63
|
## Outgoing Content, Hooks, and Limits
|
|
45
64
|
|
|
46
65
|
For automatic polishing, trust the plugin's `UserPromptSubmit` hook in Codex (**Settings → Hooks** or `/hooks` in the CLI), then start a fresh chat. Explicit requests to polish the current question and draft work without the hook in both automatic and manual mode. Including earlier exchanges requires the trusted hook in either mode. [Codex plugins](https://developers.openai.com/plugins/build/plugins) · [Codex hooks](https://learn.chatgpt.com/docs/hooks#where-codex-looks-for-hooks)
|
|
47
66
|
|
|
48
|
-
|
|
67
|
+
When the OpenAI style check runs, the plugin sends only the current `question`, `draft`, and any custom `editor_prompt` in `input_json.data`. Gemini receives the `question` and `draft` for the reply being rewritten and optional `history`. If the user gives editing directions for a one-time Turbo rewrite, the plugin includes them in `rewrite_request`. The Antigravity editor role supplies any custom project prompt. The question, draft, and history are sent as written, including code, commands, paths, links, quotations, and numbers.
|
|
68
|
+
|
|
69
|
+
The trusted hook records the transcript location and current turn locally so a user can select an earlier reply for rewriting. This record holds only metadata, even when history is set to zero. For an earlier rewrite, `question` and `draft` come from the same turn. If that turn showed both versions, the plugin uses the folded GPT draft. When the target is unclear or unavailable, Codex asks the user to identify it or supply the text.
|
|
49
70
|
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
Optional `history` comes from before the selected reply and is sent in chronological order. An exchange consists of a user prompt (including follow-up messages within that turn) and Codex's final reply. The plugin skips progress updates, tool output, incomplete exchanges, and exchanges with detected credentials or attachments. The target question and draft do not count toward the limit of 0–10 exchanges (default 2). With history at zero, an untrusted hook, no usable history, or a request to omit history for this rewrite, the ACP message omits `history`.
|
|
72
|
+
|
|
73
|
+
OpenAI caps each `input_json.data` at 256 KiB of compact UTF-8 JSON, 32 container levels, and 10,000 values. The plugin puts the current turn’s style check material in one such field and asks one predicate question. Oversized inputs go directly to Gemini in full. The `gpt-6-luna` model card separately lists a context window of 1,050,000 tokens. [Decisions API reference](https://developers.openai.com/api/reference/resources/decisions/methods/create) · [GPT-6 Luna model card](https://developers.openai.com/api/docs/models/gpt-6-luna)
|
|
74
|
+
|
|
75
|
+
On the Gemini API, the default `gemini-4-hydrogen` model shares a 1,048,576-token window across input, thinking, and output. On Antigravity, session overhead and the selected model also matter. For example, Antigravity lists a window of up to 512K tokens for Gemini 4 Neon. Google’s ACP documentation gives no exact byte limit for a Hydrogen rewrite prompt. Starting in version 1.5.8, `agy` reports context-window usage when it opens a session or changes models. [Hydrogen model card](https://aistudio.google.com/docs/models/gemini-4-hydrogen) · [Antigravity models](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)
|
|
52
76
|
|
|
53
77
|
The plugin never invokes `agy -p` and writes no draft logs of its own. Codex session logs and provider logs follow their own settings ([Google FAQ](https://antigravity.google/docs/faq)). The dedicated Antigravity editor role disables built-in tools ([Antigravity CLI 1.2.1](https://github.com/google-antigravity/antigravity-cli/releases/tag/1.2.1)), though global Antigravity hooks configured on the machine may still run.
|
|
54
78
|
|
|
55
|
-
##
|
|
79
|
+
## Handling failures
|
|
56
80
|
|
|
57
81
|
| Failure Class | Handling |
|
|
58
82
|
| --- | --- |
|
|
59
|
-
|
|
|
60
|
-
| Decisions
|
|
83
|
+
| Unsupported Google authentication, missing agy, Node.js or host process tools | Keep the original. The plugin looks for agy in PATH and ~/.local/bin. |
|
|
84
|
+
| Decisions unavailable, key invalid, response invalid, or input exceeds the provider limit | Continue to Gemini after local checks. Each turn makes its own routing decision. |
|
|
61
85
|
| ACP startup failure, auth failure, missing selected model, or mid-stream model switch | The agent aborts the rewrite, terminates the process, and delivers the original draft. |
|
|
62
|
-
|
|
|
63
|
-
| Modified numbers or units, dropped code, control characters, suspected credentials, or failed meaning check | Discards the entire candidate rewrite and delivers the original draft. |
|
|
86
|
+
| Slow or interrupted generation | Wait while the ACP process is running. On an explicit timeout, cancellation, disconnect or truncated result, discard incomplete output. A request is sent at most once. |
|
|
64
87
|
| Project disabled mid-turn, updated user instructions, or cancellation | Re-checks project mode before sending text out. The agent discards the old candidate on new instructions. User cancellation ends the turn. If only the server cancels while the user waits, the plugin returns the original draft. |
|
|
65
88
|
|
|
66
|
-
In automatic mode, service errors pause automatic rewrites for the current project within the active Codex profile.
|
|
67
|
-
|
|
68
|
-
- **60-second cooldown.** Triggered by connection failures, timeouts, rate limits, or transient service errors.
|
|
69
|
-
- **5-minute cooldown.** Triggered by authentication failures, explicit OpenAI quota exhaustion, or an unavailable selected Gemini model.
|
|
70
|
-
|
|
71
|
-
Exact-format skips, content refusals, and failed draft validation do not trigger a cooldown. Cooldown records store only a scope hash, a fixed error code, a timestamp, and a random token. An explicit request in a later turn can retry during a cooldown. If the cache is unavailable, a failed rewrite still returns the original draft. Saying `"Check Codex Polish setup"` shows missing dependencies and any active cooldown timer, while `"Test ACP connection"` runs a standalone handshake without sending a draft.
|
|
72
|
-
|
|
73
89
|
## Verification Status
|
|
74
90
|
|
|
91
|
+
In a live local test, a synthetic conversation had 10 earlier exchanges totaling 16 KiB and a saved custom polishing prompt. OpenAI received one request with just `question`, `draft`, and `editor_prompt` as evidence, and returned HTTP 200. Gemini 4 Hydrogen then received all 10 exchanges over ACP and completed the rewrite.
|
|
92
|
+
|
|
75
93
|
Run the offline test suite and synthetic report from the root of a full source checkout. The release archive ships both language versions of the evaluation guide. The test scripts, report generator, and sample data are available in the source checkout.
|
|
76
94
|
|
|
77
95
|
```sh
|
|
@@ -79,20 +97,16 @@ npm test
|
|
|
79
97
|
node evaluation/report.mjs evaluation/example.jsonl
|
|
80
98
|
```
|
|
81
99
|
|
|
82
|
-
The
|
|
83
|
-
|
|
84
|
-
```sh
|
|
85
|
-
CODEX_POLISH_TEST_LIVE_DECISIONS=1 node --test --test-name-pattern='live fidelity' tests/decisions.test.mjs
|
|
86
|
-
```
|
|
100
|
+
The Decisions tests use mock OpenAI responses to exercise the style threshold and API error handling.
|
|
87
101
|
|
|
88
102
|
### Verified on macOS
|
|
89
103
|
|
|
90
|
-
Using Node.js 22.16 and Antigravity CLI 1.5.12, the Codex agent selected `gemini-4-hydrogen` over ACP and requested a rewrite. The reply
|
|
104
|
+
Using Node.js 22.16 and Antigravity CLI 1.5.12, the Codex agent selected `gemini-4-hydrogen` over ACP and requested a rewrite. The reply reported that local tests passed and production verification was still pending. The test environment had no Python on PATH and no OpenAI key. The Node.js helpers made no network requests.
|
|
91
105
|
|
|
92
106
|
### Checks still open
|
|
93
107
|
|
|
94
|
-
- Verify a complete rewrite in the T3 chat interface. Exercise both routes with authorized, de-identified samples. Compare the tool trace with the selected model, completed output, and process cleanup. Check the status and section order in the native final message and again after reopening the chat.
|
|
95
|
-
- Run Chinese drafts over 4 KiB in two chats simultaneously and check that each keeps its own text
|
|
108
|
+
- Verify a complete rewrite in the T3 chat interface. Exercise both routes with authorized, de-identified samples. Compare the tool trace with the selected model, completed output, and process cleanup. Check the status and section order in the native final message and again after reopening the chat. In clients that support folding, verify that a new reply starts with the draft collapsed. Expand it and compare each body with its source.
|
|
109
|
+
- Run Chinese drafts over 4 KiB in two chats simultaneously and check that each keeps its own text and session ID. Check fallback for an unavailable model, a permission request, cancellation, and a truncated stream.
|
|
96
110
|
- Collect at least 200 delivered real samples across the calibration and blind splits. Use the blind split to measure preference rates, severe fact reversals, missed workflows, verbatim display match, and end-to-end latency. Current thresholds are initial defaults, and `evaluation/example.jsonl` contains synthetic records (`demo_only`). See the [evaluation specification](../evaluation/README.en.md) and [contribution guide](../CONTRIBUTING.en.md).
|
|
97
111
|
|
|
98
112
|
## Installation, Updates, and Uninstall
|
|
@@ -101,4 +115,6 @@ Once the beta is published to npm, install it with `npx @kyun.si/codex-polish@be
|
|
|
101
115
|
|
|
102
116
|
Both `setup` and `update` accept `--install-agy` to install the Google CLI when needed. Updates preserve `.codex` project settings and the plugin’s enabled state. Re-running `update` with the same version replaces the build or recovers an interrupted update.
|
|
103
117
|
|
|
104
|
-
|
|
118
|
+
The installer registers one local marketplace per Codex profile. Updates stage a verified snapshot, atomically switch the marketplace manifest to the new snapshot and refresh the native plugin cache. If the refresh fails, the installer restores the previous snapshot and enabled state. Codex checks the installed plugin’s contents when deciding hook trust. An update to a bundled prompt or setup guide can therefore require a new approval even when the hook command is unchanged. The installer and `doctor` read the current status from `hooks/list`.
|
|
119
|
+
|
|
120
|
+
If you packed version `0.0.1-beta.4` locally, you can also run `npx --yes file:./kyun.si-codex-polish-0.0.1-beta.4.tgz uninstall` in the directory containing the archive. Uninstall removes the plugin and its marketplace, clears session pointers for the active Codex profile, and prints the backup path for any manually edited installation files. It keeps shared `agy` binaries and project `.codex` files.
|
package/docs/technical.md
CHANGED
|
@@ -2,77 +2,101 @@
|
|
|
2
2
|
|
|
3
3
|
[English](technical.en.md) · [项目首页](../README.md)
|
|
4
4
|
|
|
5
|
-
`codex-polish`
|
|
5
|
+
`codex-polish` 的自动 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、单条命令及其他逐字输出按用户要求直接交付,不加标题或状态。
|
|
38
57
|
|
|
39
|
-
|
|
58
|
+
排版时,如果 ACP 回复中的图表引用丢失了分隔符,且能明确对应原稿中的引用,插件会补回分隔符。Gemini 更改或省略图表引用时,仍显示它返回的正文。无法对应原稿的新增图表标记以文本显示。
|
|
40
59
|
|
|
41
|
-
##
|
|
60
|
+
## 发送给服务商的内容与历史限制
|
|
42
61
|
|
|
43
|
-
|
|
62
|
+
启用 OpenAI Decisions 时,发给 OpenAI 的 `input_json.data` 只包含本轮 `question`、`draft`,以及项目已设置的 `editor_prompt`。发给 Gemini 的 ACP 消息包含待改回复对应的 `question`、`draft` 和可选的 `history`。如果用户在单次 Turbo 请求里另提了改写要求,`rewrite_request` 会把要求一并带给 Gemini。自定义提示词仍通过 Antigravity 编辑角色传入。问题、草稿和历史都按原文发送,包括其中的代码、命令、路径、链接、引文和数字。
|
|
44
63
|
|
|
45
|
-
|
|
64
|
+
受信任的 hook 在本机记录会话文件的位置和当前轮次,以便用户点名重写之前的回复。即使历史设为 0,这条定位记录也只含元数据。取旧回复时,`question` 和 `draft` 来自同一轮。该轮若展示过润色版和原稿,就取折叠的 GPT 原稿。无法确认目标时,先请用户指明或提供原文。
|
|
46
65
|
|
|
47
|
-
|
|
66
|
+
`history` 从待改回复之前的完整问答中选取,按时间顺序发送。每轮包括用户消息(含同轮补充)和 Codex 最终答复。工具输出、进度提示、含疑似凭据或附件的轮次均会跳过。目标问答不占历史名额。可附带 0 到 10 轮,默认 2 轮。历史设为 0、未信任 hook、没有可用历史或用户要求这次不带历史时,ACP 消息省略 `history`。
|
|
67
|
+
|
|
68
|
+
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)
|
|
69
|
+
|
|
70
|
+
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
71
|
|
|
49
72
|
插件自身不写草稿日志。Codex 宿主日志、服务商侧日志以及机器上全局配置的 Antigravity hooks 仍按各自的环境配置运行。服务商的数据处理遵循各自条款,与本项目的 Apache License 2.0 代码许可无关,可参阅 [Google 使用说明](https://antigravity.google/docs/faq)。
|
|
50
73
|
|
|
51
|
-
##
|
|
74
|
+
## 认证与故障处理
|
|
52
75
|
|
|
53
76
|
插件要求官方 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
77
|
|
|
55
78
|
| 故障类型 | 回退与限制行为 |
|
|
56
79
|
| --- | --- |
|
|
57
|
-
|
|
|
58
|
-
| Decisions
|
|
80
|
+
| Google 认证方式不支持、缺少 agy 或宿主工具不可用 | 保留原稿。插件依次在 PATH 和 ~/.local/bin 查找 agy。 |
|
|
81
|
+
| Decisions 不可用、密钥无效、响应无效或材料超过接口限额 | 通过本地检查后,直接交给 Gemini。每一轮独立判断。 |
|
|
59
82
|
| ACP 握手失败、未登录、账号无所选模型或中途切换模型 | 当前 agent 结束本次 ACP 请求,回收进程并交付原稿。 |
|
|
60
|
-
|
|
|
61
|
-
| 占位符错位、数值单位改动、出现疑似凭据或原意复核超标 | 整篇改稿丢弃并交付原稿,模型思考与其他会话消息不会混入正文。 |
|
|
83
|
+
| 生成耗时较长或中断 | 进程仍在运行时继续等待。宿主或服务端明确超时、取消、断流或返回不完整时丢弃候选,同一请求最多发送一次。 |
|
|
62
84
|
| 本轮中途停用、修改要求或取消 | 外发前重新核对项目模式。收到新要求时丢弃旧候选,按新要求作答。用户取消则结束本轮。若只有服务端取消,用户仍在等待,就交付原稿。 |
|
|
63
85
|
|
|
64
|
-
自动模式下,连接失败、超时、限流或服务异常会让当前 Codex 配置下的该项目暂停自动润色 **60 秒**。认证失败、明确的 OpenAI 配额耗尽或所选 Gemini 模型不可用会暂停 **5 分钟**。固定格式跳过、正常拒答和改稿校验驳回不会触发冷却。每条冷却记录只包含作用域哈希、固定故障码、时间戳和随机标记。用户在修好环境后可以随时在新一轮点名手动重试。
|
|
65
|
-
|
|
66
86
|
## 安装、更新和卸载
|
|
67
87
|
|
|
68
88
|
测试版发布到 npm 后,运行 `npx @kyun.si/codex-polish@beta setup` 即可安装。将最后一个参数换成 `update`、`doctor` 或 `uninstall` 即可更新、检查当前项目或卸载。从 GitHub 源码安装时,在仓库根目录运行 `node scripts/install.mjs setup`,其余子命令相同。[安装步骤](../README.md#三步快速开始)
|
|
69
89
|
|
|
70
90
|
`setup` 和 `update` 支持 `--install-agy`,在缺少 Antigravity CLI 时可自动安装。更新会保留项目设置与插件启用状态。同一版本号的新构建也能用 `update` 覆盖或重试中断的更新。
|
|
71
91
|
|
|
72
|
-
|
|
92
|
+
安装器为每份 Codex 配置注册一个本地市场。更新时先准备并校验新快照,然后原子替换市场清单,再请 Codex 刷新插件缓存。刷新失败时会恢复原快照和启用状态。Codex 判断 hook 信任时会核对已安装插件的内容,所以即使命令没变,内置提示词或配置指南的改动也可能触发重新确认。安装器和 `doctor` 都从 `hooks/list` 读取实际状态。
|
|
93
|
+
|
|
94
|
+
手头有本地打包的 `0.0.1-beta.4` 版时,也可以在压缩包所在目录运行 `npx --yes file:./kyun.si-codex-polish-0.0.1-beta.4.tgz uninstall`。卸载会清理该插件与专用市场,按当前 Codex 配置清除会话指针,保留各项目的 `.codex/` 配置和共用的 `agy`,并提示被手动修改过的安装文件备份位置。
|
|
73
95
|
|
|
74
96
|
## 已验证记录与真机验收
|
|
75
97
|
|
|
98
|
+
本机实测使用一份带有 10 轮虚构问答(合计 16 KiB)的会话,并保存了自定义润色提示词。OpenAI 收到一次请求,材料只有 `question`、`draft`、`editor_prompt`,返回 HTTP 200。随后 Gemini 4 Hydrogen 通过 ACP 收到全部 10 轮历史并完成了改写。
|
|
99
|
+
|
|
76
100
|
在完整源码的根目录运行以下离线测试和合成数据报告。发行包附带中英文评测说明,测试脚本、统计脚本和示例数据需从源码获取。参见 [源码测试与贡献指南](../CONTRIBUTING.md)。
|
|
77
101
|
|
|
78
102
|
```sh
|
|
@@ -80,18 +104,14 @@ npm test
|
|
|
80
104
|
node evaluation/report.mjs evaluation/example.jsonl
|
|
81
105
|
```
|
|
82
106
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```sh
|
|
86
|
-
CODEX_POLISH_TEST_LIVE_DECISIONS=1 node --test --test-name-pattern='live fidelity' tests/decisions.test.mjs
|
|
87
|
-
```
|
|
107
|
+
Decisions 测试使用模拟的 OpenAI 响应检查风格判定阈值和接口报错时的处理。
|
|
88
108
|
|
|
89
109
|
源码中的 `tests/fixture_acp.mjs` 是专供测试的模拟服务端,覆盖正常改写、认证失败、模型缺失、生成期换模型、权限请求、静默超时、断流和跨会话消息交错,不会安装到最终产物中。安装回归测试会在本机已装好 Codex CLI 和 npm 的前提下创建一次性 Codex 配置,打出发版压缩包,验证 macOS 双击脚本以及从 `.tgz` 安装、更新、检查和卸载的全流程,并通过 Codex CLI 确认 Setup 已启用、`UserPromptSubmit` 已注册且等待信任。本地 T3 Code Beta 的 Codex 配置中也能发现 `codex-polish` 和 `codex-polish-setup`,两者都显示已启用。T3 聊天界面从触发改写到显示最终回复的全流程仍待验收。
|
|
90
110
|
|
|
91
|
-
在 macOS 上用 Node.js 22.16 和官方 Antigravity CLI 1.5.12 做过一次真实改写。测试环境的 PATH 中没有 Python,也没有配置 OpenAI 密钥。当前 Codex agent 通过 ACP 选中了 `gemini-4-hydrogen
|
|
111
|
+
在 macOS 上用 Node.js 22.16 和官方 Antigravity CLI 1.5.12 做过一次真实改写。测试环境的 PATH 中没有 Python,也没有配置 OpenAI 密钥。当前 Codex agent 通过 ACP 选中了 `gemini-4-hydrogen`,改稿保留了本地测试通过、线上尚未验证的事实。Node 辅助脚本没有向网络发出请求。
|
|
92
112
|
|
|
93
113
|
真人偏好仍待盲评。可用已获授权并去除敏感信息的真实样本完成以下验收。
|
|
94
114
|
|
|
95
115
|
1. 分别在无 OpenAI 密钥和开启 Decisions 的项目中核对工具轨迹,确认只有当前 agent 持有 ACP 进程、模型选择准确且结束后进程回收干净。
|
|
96
|
-
2. 用超过 4 KiB 的中文长文在两个 Codex
|
|
97
|
-
3.
|
|
116
|
+
2. 用超过 4 KiB 的中文长文在两个 Codex 会话中并发运行,确认正文和会话 ID 不串线,并核对缺模型、权限请求、取消和断流时的回退表现。
|
|
117
|
+
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
|
@@ -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
|
+
}
|