codexmate 0.1.31 → 0.1.33
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 +8 -3
- package/README.vi.md +8 -3
- package/README.zh.md +8 -3
- package/cli/agents-files.js +18 -4
- package/cli/claude-proxy.js +2 -2
- package/cli/plugin-config.js +64 -0
- package/cli/prompt-history.js +19 -4
- package/cli/system-prompt-files.js +7 -2
- package/cli.js +200 -214
- package/lib/cli-config-engine.js +15 -4
- package/lib/cli-file-utils.js +6 -1
- package/lib/config-change-fs.js +132 -0
- package/lib/config-changes.js +293 -0
- package/lib/handoff-mcp.js +18 -2
- package/lib/local-feature-store.js +39 -0
- package/lib/session-bookmarks.js +72 -0
- package/lib/session-context-health.js +102 -0
- package/lib/session-context-records.js +153 -0
- package/lib/session-diagnostics.js +75 -0
- package/lib/session-feature-settings.js +21 -0
- package/lib/session-features.js +63 -0
- package/lib/session-handoff-draft.js +43 -0
- package/lib/session-projects.js +76 -0
- package/lib/session-search-index.js +188 -0
- package/lib/thread-handoff.js +8 -0
- package/lib/web-server.js +216 -0
- package/lib/web-startup-auth.js +5 -1
- package/package.json +1 -1
- package/plugins/prompt-templates/computed.mjs +3 -3
- package/plugins/prompt-templates/invocation.mjs +73 -0
- package/plugins/prompt-templates/methods.mjs +48 -3
- package/plugins/prompt-templates/overview.mjs +2 -0
- package/web-ui/app.js +32 -1
- package/web-ui/index.html +2 -0
- package/web-ui/logic.context-health.mjs +144 -0
- package/web-ui/logic.context-window.mjs +15 -0
- package/web-ui/modules/api.mjs +72 -39
- package/web-ui/modules/app.computed.prompts.mjs +11 -0
- package/web-ui/modules/app.methods.agents.mjs +25 -3
- package/web-ui/modules/app.methods.claude-config.mjs +2 -0
- package/web-ui/modules/app.methods.codex-config.mjs +9 -0
- package/web-ui/modules/app.methods.config-changes.mjs +124 -0
- package/web-ui/modules/app.methods.index.mjs +4 -0
- package/web-ui/modules/app.methods.kilocode-config.mjs +2 -0
- package/web-ui/modules/app.methods.openclaw-persist.mjs +2 -0
- package/web-ui/modules/app.methods.opencode-config.mjs +2 -0
- package/web-ui/modules/app.methods.pi-config.mjs +12 -3
- package/web-ui/modules/app.methods.provider-cache.mjs +9 -3
- package/web-ui/modules/app.methods.providers.mjs +6 -0
- package/web-ui/modules/app.methods.startup-claude.mjs +8 -47
- package/web-ui/modules/app.methods.system-prompt.mjs +17 -2
- package/web-ui/modules/config-change-actions.mjs +9 -0
- package/web-ui/modules/context-health.methods.mjs +70 -0
- package/web-ui/modules/i18n/locales/en.mjs +164 -4
- package/web-ui/modules/i18n/locales/ja.mjs +164 -4
- package/web-ui/modules/i18n/locales/vi.mjs +164 -4
- package/web-ui/modules/i18n/locales/zh-tw.mjs +164 -4
- package/web-ui/modules/i18n/locales/zh.mjs +164 -4
- package/web-ui/modules/plugins.methods.mjs +2 -0
- package/web-ui/modules/prompt-ecosystem.methods.mjs +136 -0
- package/web-ui/modules/request-deadline.mjs +33 -0
- package/web-ui/modules/session-features.mjs +279 -0
- package/web-ui/modules/thread-handoff.mjs +1 -1
- package/web-ui/partials/index/config-changes.html +25 -0
- package/web-ui/partials/index/context-health.html +45 -0
- package/web-ui/partials/index/context-window-reference.html +17 -0
- package/web-ui/partials/index/layout-header.html +7 -30
- package/web-ui/partials/index/modal-openclaw-config.html +0 -2
- package/web-ui/partials/index/modal-prompt-invocation.html +17 -0
- package/web-ui/partials/index/modal-skills.html +0 -1
- package/web-ui/partials/index/modals-basic.html +0 -8
- package/web-ui/partials/index/modals-pi-provider.html +0 -1
- package/web-ui/partials/index/panel-config-codex.html +0 -3
- package/web-ui/partials/index/panel-config-openclaw.html +16 -13
- package/web-ui/partials/index/panel-dashboard.html +0 -2
- package/web-ui/partials/index/panel-plugins.html +37 -10
- package/web-ui/partials/index/panel-prompts.html +18 -3
- package/web-ui/partials/index/panel-sessions.html +23 -11
- package/web-ui/partials/index/panel-settings.html +1 -12
- package/web-ui/partials/index/panel-trash.html +0 -1
- package/web-ui/partials/index/session-diagnostics.html +29 -0
- package/web-ui/partials/index/session-features.html +107 -0
- package/web-ui/partials/index/thread-handoff.html +6 -3
- package/web-ui/res/web-ui-render.precompiled.js +1863 -271
- package/web-ui/styles/config-changes.css +30 -0
- package/web-ui/styles/context-health.css +107 -0
- package/web-ui/styles/openclaw-structured.css +205 -189
- package/web-ui/styles/prompts-editor.css +23 -0
- package/web-ui/styles/session-features.css +148 -0
- package/web-ui/styles/sessions-preview.css +21 -0
- package/web-ui/styles/sub-tabs.css +181 -0
- package/web-ui/styles.css +5 -1
package/README.md
CHANGED
|
@@ -30,6 +30,10 @@ Codex Mate is a locally running CLI + Web tool for browsing, filtering, and expo
|
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
|
+
### Session workbench
|
|
34
|
+
|
|
35
|
+
The session page adds message bookmarks with notes and tags, an incremental local full-text index, evidence-linked handoff drafts, a read-only project workspace, and model-window references. Bookmarks do not modify source sessions. The index covers discovered candidates only; refresh it for new messages. Historical text ratios are not actual request utilization. Settings offers local diagnostics and redacted JSON/Markdown exports. Only selected checks probe the current Codex route or start selected MCP servers; no write tools are called. See the [session guide](https://sakurabytecore.github.io/codexmate/guide/sessions).
|
|
36
|
+
|
|
33
37
|
---
|
|
34
38
|
|
|
35
39
|
> [!TIP]
|
|
@@ -151,13 +155,14 @@ Use the handoff's returned ID for `<id>`, the same target agent for `<target>`,
|
|
|
151
155
|
## What's So Special?
|
|
152
156
|
|
|
153
157
|
After finding your conversations, manage the configuration, skills, and tasks used in your daily work:
|
|
154
|
-
- **Unified Session Browser**: Browse local sessions from Codex, Claude Code, Gemini CLI, CodeBuddy Code, WorkBuddy, Pi, OpenCode, and Zed in one place. Search, export, and deletion availability varies by source; see the [session guide (Chinese)](https://sakurabytecore.github.io/codexmate/guide/sessions).
|
|
158
|
+
- **Unified Session Browser**: Browse local sessions from Codex, Claude Code, Gemini CLI, CodeBuddy Code, WorkBuddy, Pi, OpenCode, and Zed in one place. Search, export, and deletion availability varies by source; see the [session guide (Chinese)](https://sakurabytecore.github.io/codexmate/guide/sessions). Session details show an always-visible five-category token breakdown, a composition bar, and a health rating.
|
|
155
159
|
- **OpenAI-Compatible Bridge**: Use Codex with any OpenAI-compatible UI by normalizing the Responses API; the built-in Codex conversion also fills and normalizes Codex fingerprint headers such as `User-Agent`, `Version`, `OpenAI-Beta`, and `Originator` so upstream providers see an official Codex CLI-shaped request.
|
|
156
160
|
- **Claude Provider Bridge**: Connect Claude Code to OpenAI Chat Completions-compatible providers and Ollama through the built-in local Claude-compatible proxy.
|
|
157
161
|
- **OpenCode Provider Control**: Manage OpenCode provider/model selection with a CodexMate-owned provider store under `~/.codexmate`, projecting only the active provider into native OpenCode config to avoid polluting or deleting user-owned settings.
|
|
158
162
|
- **KiloCode Config Bridge**: Configure KiloCode providers from the CLI or Web UI, writing to `~/.config/kilo/kilo.jsonc` while preserving stored API keys.
|
|
159
163
|
- **Pi Provider Config**: Manage Pi providers from the Web UI with lossless round-trip writes to `~/.pi/agent/models.json`, auto-fetched remote model lists, and one-click default provider/model switching via `~/.pi/agent/settings.json`.
|
|
160
164
|
- **Provider Health Cleanup**: Probe local Codex and Claude provider routes, surface failed configs in one modal, and bulk-clean selected broken providers without touching healthy or protected entries.
|
|
165
|
+
- **Configuration Preview and Undo**: Preview affected paths and redacted field changes before writing any of the six tools. Detect external edits since loading or preview, and undo the latest change per tool, including after a server restart. The existing preview setting controls the dialog; turning it off keeps conflict checks and undo.
|
|
161
166
|
- **Skills Marketplace**: A local-first market to share and import skills between different agent apps.
|
|
162
167
|
- **Prompt File Editor**: Unified editor for global and project-level `CLAUDE.md` and `AGENTS.md` (including OpenCode's `~/.config/opencode/AGENTS.md`) with auto-detection of project paths, plus a shared preset pool for reusable prompts.
|
|
163
168
|
- **Task Orchestrator**: Automatically advance existing workflows, persist progress and results, and request intervention only when blocked.
|
|
@@ -180,8 +185,8 @@ After finding your conversations, manage the configuration, skills, and tasks us
|
|
|
180
185
|
| **KiloCode Config Bridge** | ✅ | Configure KiloCode through `codexmate kilo config` or the Web UI, writing provider URL/model/API key data to `~/.config/kilo/kilo.jsonc` |
|
|
181
186
|
| **Pi Provider Config** | ✅ | Manage Pi providers in the Web UI writing to `~/.pi/agent/models.json` (unknown fields preserved) and switch the default provider/model in `~/.pi/agent/settings.json` |
|
|
182
187
|
| **Provider Health Check** | ✅ | Probe local Codex/Claude provider routes, highlight failed configs, and bulk-remove selected broken providers safely |
|
|
183
|
-
| **Prompt Templates** | ✅ |
|
|
184
|
-
| **Prompt File Editor** | ✅ | Edit global and project-level CLAUDE.md / AGENTS.md with
|
|
188
|
+
| **Prompt Templates** | ✅ | Variable-fill dialog on invocation, one-template JSON sharing, and versioned plugin template configuration with history Diff and rollback. `git_diff` is pasted text, not an executed command. |
|
|
189
|
+
| **Prompt File Editor** | ✅ | Edit global and project-level CLAUDE.md / AGENTS.md with a shared preset pool. Presets fill variables before updating the editor; save manually to write files. History shows version Diff; confirmed rollback writes the selected version with an atomic backup and concurrent-change checks. |
|
|
185
190
|
| **MCP Integration** | ✅ | Expose local tools and resources via MCP stdio |
|
|
186
191
|
| **Auto Update** | ✅ | Quick update CLI via `codexmate update` |
|
|
187
192
|
|
package/README.vi.md
CHANGED
|
@@ -30,6 +30,10 @@ Codex Mate là công cụ CLI + Web chạy cục bộ, giúp xem, lọc và xu
|
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
|
+
### Không gian làm việc phiên
|
|
34
|
+
|
|
35
|
+
Trang phiên bổ sung dấu trang tin nhắn với ghi chú và nhãn, chỉ mục toàn văn cục bộ cập nhật tăng dần, bản nháp bàn giao có bằng chứng, không gian dự án chỉ đọc và tham chiếu cửa sổ mô hình. Dấu trang không sửa phiên gốc. Chỉ mục chỉ bao gồm phiên đã phát hiện; cần cập nhật để tìm tin nhắn mới. Tỷ lệ văn bản lịch sử không phải mức sử dụng thực tế của yêu cầu. Cài đặt cung cấp chẩn đoán cục bộ và xuất JSON/Markdown đã ẩn bí mật. Chỉ mục kiểm tra được chọn mới truy cập tuyến Codex hiện tại hoặc khởi động MCP; không gọi công cụ ghi. Xem [hướng dẫn phiên](https://sakurabytecore.github.io/codexmate/guide/sessions).
|
|
36
|
+
|
|
33
37
|
---
|
|
34
38
|
|
|
35
39
|
> [!TIP]
|
|
@@ -151,9 +155,10 @@ Dùng mã bàn giao được trả về cho `<id>`, cùng tác nhân đích cho
|
|
|
151
155
|
## Điểm nổi bật
|
|
152
156
|
|
|
153
157
|
Sau khi tìm lại cuộc trò chuyện, bạn có thể quản lý cấu hình, skill và tác vụ phục vụ công việc hằng ngày:
|
|
154
|
-
- **Trình duyệt phiên thống nhất**: Xem phiên cục bộ từ Codex, Claude Code, Gemini CLI, CodeBuddy Code, WorkBuddy, Pi, OpenCode và Zed tại một nơi. Khả năng tìm kiếm, xuất và xóa tùy thuộc nguồn; xem [hướng dẫn phiên (tiếng Trung)](https://sakurabytecore.github.io/codexmate/guide/sessions).
|
|
158
|
+
- **Trình duyệt phiên thống nhất**: Xem phiên cục bộ từ Codex, Claude Code, Gemini CLI, CodeBuddy Code, WorkBuddy, Pi, OpenCode và Zed tại một nơi. Khả năng tìm kiếm, xuất và xóa tùy thuộc nguồn; xem [hướng dẫn phiên (tiếng Trung)](https://sakurabytecore.github.io/codexmate/guide/sessions). Chi tiết phiên luôn hiển thị ước tính token theo năm nhóm, thanh tỷ lệ và mức sức khỏe ngữ cảnh.
|
|
155
159
|
- **Bridge tương thích OpenAI**: Dùng Codex với bất kỳ UI nào hỗ trợ OpenAI bằng cách chuẩn hóa Responses API.
|
|
156
160
|
- **Dọn dẹp provider lỗi**: Kiểm tra route provider cục bộ của Codex/Claude, hiển thị cấu hình lỗi trong một modal và xóa hàng loạt các provider hỏng đã chọn mà không chạm vào mục khỏe mạnh hoặc được bảo vệ.
|
|
161
|
+
- **Xem trước và hoàn tác cấu hình**: Hiển thị đường dẫn và khác biệt trường đã ẩn thông tin xác thực trước khi ghi cả sáu công cụ. Phát hiện sửa đổi bên ngoài sau khi tải hoặc xem trước; hoàn tác thay đổi gần nhất của từng công cụ, kể cả sau khi khởi động lại dịch vụ. Tùy chọn xem trước điều khiển hộp thoại; khi tắt vẫn giữ kiểm tra xung đột và hoàn tác.
|
|
157
162
|
- **Chợ skill cục bộ**: Chia sẻ và nhập skill giữa các app agent khác nhau.
|
|
158
163
|
- **Điều phối tác vụ**: Tự động thực thi quy trình hiện có, lưu bền vững tiến độ và kết quả, chỉ yêu cầu can thiệp khi bị chặn.
|
|
159
164
|
|
|
@@ -172,8 +177,8 @@ Sau khi tìm lại cuộc trò chuyện, bạn có thể quản lý cấu hình,
|
|
|
172
177
|
| **Hàng đợi tác vụ** | ✅ | Quy trình tự động có phụ thuộc, lưu tiến độ, khôi phục an toàn và tổng kết kết quả |
|
|
173
178
|
| **Bridge OpenAI** | ✅ | Chuyển đổi Codex Responses API sang định dạng OpenAI chuẩn |
|
|
174
179
|
| **Kiểm tra sức khỏe Provider** | ✅ | Kiểm tra route provider Codex/Claude, đánh dấu cấu hình lỗi và xóa hàng loạt các provider hỏng đã chọn một cách an toàn |
|
|
175
|
-
| **Mẫu Prompt** | ✅ |
|
|
176
|
-
| **Trình sửa tệp prompt** | ✅ | Chỉnh sửa CLAUDE.md / AGENTS.md
|
|
180
|
+
| **Mẫu Prompt** | ✅ | Hộp thoại điền biến khi gọi, chia sẻ một mẫu bằng JSON, lịch sử Diff và khôi phục cấu hình mẫu plugin. `git_diff` là văn bản được dán, không thực thi lệnh. |
|
|
181
|
+
| **Trình sửa tệp prompt** | ✅ | Chỉnh sửa CLAUDE.md / AGENTS.md toàn cục và theo dự án với kho preset chung. Điền biến trước khi áp dụng preset; cần lưu thủ công để ghi tệp. Lịch sử hiển thị Diff; xác nhận khôi phục sẽ ghi phiên bản đã chọn với bản sao lưu nguyên tử và kiểm tra thay đổi bên ngoài. |
|
|
177
182
|
| **Tích hợp MCP** | ✅ | Expose tool và resource cục bộ qua MCP stdio |
|
|
178
183
|
| **Tự động cập nhật** | ✅ | Cập nhật nhanh qua `codexmate update` |
|
|
179
184
|
|
package/README.zh.md
CHANGED
|
@@ -30,6 +30,10 @@ Codex Mate 是本地运行的 CLI + Web 管理工具,在一个界面查看、
|
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
|
+
### 会话工作台
|
|
34
|
+
|
|
35
|
+
会话页新增消息收藏、备注与标签、本地增量全文索引、带来源证据的交接草稿、只读项目聚合与模型窗口参考。收藏保存在本机,不改原会话;索引仅覆盖已发现候选,新增消息需更新索引;历史文本占比不是实际请求窗口占用。设置页提供本地诊断与脱敏 JSON/Markdown 导出,勾选后才探测当前 Codex 路由或启动选定 MCP,不调用写工具。详见[会话指南](https://sakurabytecore.github.io/codexmate/guide/sessions)。
|
|
36
|
+
|
|
33
37
|
---
|
|
34
38
|
|
|
35
39
|
> [!TIP]
|
|
@@ -151,12 +155,13 @@ node cli.js thread ack <thread-id> --handoff <id> --agent <target> --evidence <s
|
|
|
151
155
|
## 有什么独特之处?
|
|
152
156
|
|
|
153
157
|
找回对话之后,还可以继续管理日常工作所需的配置、Skills 与任务:
|
|
154
|
-
- **统一会话浏览器**:集中浏览 Codex、Claude Code、Gemini CLI、CodeBuddy Code、WorkBuddy、Pi、OpenCode 与 Zed 的本地会话;检索、导出和删除的来源限制见[会话指南](https://sakurabytecore.github.io/codexmate/guide/sessions)
|
|
158
|
+
- **统一会话浏览器**:集中浏览 Codex、Claude Code、Gemini CLI、CodeBuddy Code、WorkBuddy、Pi、OpenCode 与 Zed 的本地会话;检索、导出和删除的来源限制见[会话指南](https://sakurabytecore.github.io/codexmate/guide/sessions)。会话详情默认显示五类预估 Token、构成条与健康评级,无需展开。
|
|
155
159
|
- **OpenAI 兼容桥接**:通过归一化 Responses API,让 Codex 能够与任何支持 OpenAI 格式的 UI 配合使用;内建 Codex 转换会补齐并规范化 `User-Agent`、`Version`、`OpenAI-Beta`、`Originator` 等 Codex 指纹,对上游伪装为官方 Codex CLI 请求。
|
|
156
160
|
- **Claude Provider 桥接**:通过内建本地 Claude 兼容代理,让 Claude Code 接入 OpenAI Chat Completions 兼容 provider 与 Ollama。
|
|
157
161
|
- **OpenCode Provider 控制**:在 `~/.codexmate` 下维护 CodexMate 自有的 OpenCode 多 provider 存储,只将当前选中的 provider 投影到 OpenCode 原生配置,避免污染或误删用户已有配置。
|
|
158
162
|
- **Pi Provider 配置**:在 Web UI 中管理 Pi 供应商,写入 `~/.pi/agent/models.json` 时无损保留未知字段,支持自动拉取远端模型列表,并可一键切换 `~/.pi/agent/settings.json` 中的默认供应商/模型。
|
|
159
163
|
- **Provider 健康清理**:探测本地 Codex 与 Claude provider 路由,在同一个弹窗里集中展示失败配置,并批量清理已选坏配置,不影响正常或受保护项。
|
|
164
|
+
- **配置变更预览与撤销**:六种工具写入前统一展示文件路径与脱敏字段差异;检测读取后及预览后的外部修改,支持撤销各工具最近一次变更,重启服务后仍可恢复。沿用设置中的预览开关,关闭后保留冲突检查与撤销。
|
|
160
165
|
- **Skills 市场**:本地优先的市场,支持在不同的智能体应用之间共享和导入 Skills。
|
|
161
166
|
- **提示词文件编辑器**:统一编辑全局和项目级 `CLAUDE.md` 与 `AGENTS.md`(含 OpenCode 的 `~/.config/opencode/AGENTS.md`),支持项目路径自动检测,并提供通用预设池复用 prompt。
|
|
162
167
|
- **任务编排器**:复用工作流定义自动推进任务,持久保存进度与结果,仅在阻塞时请求介入。
|
|
@@ -178,8 +183,8 @@ node cli.js thread ack <thread-id> --handoff <id> --agent <target> --evidence <s
|
|
|
178
183
|
| **OpenCode Provider 存储** | ✅ | 在 `~/.codexmate` 中保留多个 OpenCode provider,只将当前选中的 provider 投影到 OpenCode 原生配置 |
|
|
179
184
|
| **Pi Provider 配置** | ✅ | 在 Web UI 中管理 Pi 供应商,写入 `~/.pi/agent/models.json`(未知字段无损保留),并切换 `~/.pi/agent/settings.json` 中的默认供应商/模型 |
|
|
180
185
|
| **Provider 健康检查** | ✅ | 探测本地 Codex/Claude provider 路由,标记失败配置,并安全批量移除已选坏配置 |
|
|
181
|
-
| **提示词模板** | ✅ |
|
|
182
|
-
| **提示词文件编辑器** | ✅ |
|
|
186
|
+
| **提示词模板** | ✅ | 调用时弹窗填写变量,支持单模板 JSON 分享、插件模板配置历史 Diff 与回滚。`git_diff` 需粘贴差异文本,不执行命令。 |
|
|
187
|
+
| **提示词文件编辑器** | ✅ | 编辑全局及项目级 CLAUDE.md / AGENTS.md,支持通用预设池。应用预设先填写变量,只更新编辑器,需手动保存。历史支持版本 Diff;确认回滚后写入所选版本,保留原子备份,校验外部修改。 |
|
|
183
188
|
| **MCP 集成** | ✅ | 通过 MCP stdio 暴露本地工具与资源 |
|
|
184
189
|
| **自动更新** | ✅ | 通过 `codexmate update` 快速更新 CLI |
|
|
185
190
|
|
package/cli/agents-files.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
|
|
2
|
+
|
|
1
3
|
function createAgentsFileController(deps = {}) {
|
|
2
4
|
const {
|
|
3
5
|
fs,
|
|
@@ -162,11 +164,17 @@ function createAgentsFileController(deps = {}) {
|
|
|
162
164
|
if (content.length > 2 * 1024 * 1024) {
|
|
163
165
|
return { error: 'content too large (max 2MB)' };
|
|
164
166
|
}
|
|
167
|
+
if (typeof params.baseContent === 'string') {
|
|
168
|
+
const current = readClaudeMdFile(params);
|
|
169
|
+
if (current.error) return current;
|
|
170
|
+
if (current.content !== params.baseContent) return { error: '文件已被修改,请重新加载后再回滚' };
|
|
171
|
+
}
|
|
165
172
|
if (typeof backupPromptBeforeWrite === 'function') {
|
|
166
173
|
var bucket = resolved.isProject
|
|
167
174
|
? 'claude-project_' + sanitizeHistoryId(resolved.projectPath)
|
|
168
175
|
: 'claude-global';
|
|
169
|
-
backupPromptBeforeWrite(bucket, filePath);
|
|
176
|
+
const backup = backupPromptBeforeWrite(bucket, filePath);
|
|
177
|
+
if (backup && backup.error) return { error: backup.error };
|
|
170
178
|
resolved.historyBucket = bucket;
|
|
171
179
|
}
|
|
172
180
|
var lineEnding = params.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
@@ -174,7 +182,7 @@ function createAgentsFileController(deps = {}) {
|
|
|
174
182
|
var finalContent = ensureUtf8Bom(normalized);
|
|
175
183
|
try {
|
|
176
184
|
ensureDir(path.dirname(filePath));
|
|
177
|
-
|
|
185
|
+
writeTextAtomicWithBackup(filePath, finalContent, { fs });
|
|
178
186
|
var result = { success: true, path: filePath };
|
|
179
187
|
if (resolved.historyBucket) result.historyBucket = resolved.historyBucket;
|
|
180
188
|
if (resolved.isProject) {
|
|
@@ -236,12 +244,18 @@ function createAgentsFileController(deps = {}) {
|
|
|
236
244
|
if (content.length > 2 * 1024 * 1024) {
|
|
237
245
|
return { error: '内容过大(最大 2MB)' };
|
|
238
246
|
}
|
|
247
|
+
if (typeof params.baseContent === 'string') {
|
|
248
|
+
const current = readAgentsFile(params);
|
|
249
|
+
if (current.error) return current;
|
|
250
|
+
if (current.content !== params.baseContent) return { error: '文件已被修改,请重新加载后再回滚' };
|
|
251
|
+
}
|
|
239
252
|
let agentsHistoryBucket = '';
|
|
240
253
|
if (typeof backupPromptBeforeWrite === 'function') {
|
|
241
254
|
const explicitBucket = typeof params.historyBucket === 'string' ? params.historyBucket.trim() : '';
|
|
242
255
|
const bucket = explicitBucket
|
|
243
256
|
|| ('codex_' + sanitizeHistoryId(String(params.baseDir || '').trim() || 'global'));
|
|
244
|
-
backupPromptBeforeWrite(bucket, filePath);
|
|
257
|
+
const backup = backupPromptBeforeWrite(bucket, filePath);
|
|
258
|
+
if (backup && backup.error) return { error: backup.error };
|
|
245
259
|
agentsHistoryBucket = bucket;
|
|
246
260
|
}
|
|
247
261
|
const lineEnding = params.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
@@ -249,7 +263,7 @@ function createAgentsFileController(deps = {}) {
|
|
|
249
263
|
const finalContent = ensureUtf8Bom(normalized);
|
|
250
264
|
|
|
251
265
|
try {
|
|
252
|
-
|
|
266
|
+
writeTextAtomicWithBackup(filePath, finalContent, { fs });
|
|
253
267
|
const agentsResult = { success: true, path: filePath };
|
|
254
268
|
if (agentsHistoryBucket) agentsResult.historyBucket = agentsHistoryBucket;
|
|
255
269
|
return agentsResult;
|
package/cli/claude-proxy.js
CHANGED
|
@@ -1511,7 +1511,7 @@ function createBuiltinClaudeProxyRuntimeController(deps = {}) {
|
|
|
1511
1511
|
});
|
|
1512
1512
|
}
|
|
1513
1513
|
|
|
1514
|
-
async function startBuiltinClaudeProxyRuntime(payload = {}) {
|
|
1514
|
+
async function startBuiltinClaudeProxyRuntime(payload = {}, options = {}) {
|
|
1515
1515
|
if (runtime) {
|
|
1516
1516
|
return {
|
|
1517
1517
|
error: 'Claude 兼容代理已在运行',
|
|
@@ -1522,7 +1522,7 @@ function createBuiltinClaudeProxyRuntimeController(deps = {}) {
|
|
|
1522
1522
|
};
|
|
1523
1523
|
}
|
|
1524
1524
|
|
|
1525
|
-
const saveResult = saveBuiltinClaudeProxySettings(payload);
|
|
1525
|
+
const saveResult = saveBuiltinClaudeProxySettings(payload, options);
|
|
1526
1526
|
if (saveResult.error) {
|
|
1527
1527
|
return { error: saveResult.error };
|
|
1528
1528
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
|
|
5
|
+
const CONFIG_VERSION = 1;
|
|
6
|
+
const MAX_CONFIG_BYTES = 2 * 1024 * 1024;
|
|
7
|
+
const HISTORY_BUCKET = 'plugin_prompt_templates';
|
|
8
|
+
const TEMPLATE_FIELDS = ['id', 'name', 'description', 'template', 'createdAt', 'updatedAt', 'createdBy'];
|
|
9
|
+
|
|
10
|
+
function normalizeTemplates(input) {
|
|
11
|
+
if (!Array.isArray(input)) throw new Error('模板配置必须是数组');
|
|
12
|
+
const ids = new Set();
|
|
13
|
+
return input.filter((item) => item && item.isBuiltin !== true).map((item) => {
|
|
14
|
+
if (typeof item.id !== 'string' || !item.id || typeof item.name !== 'string' || !item.name.trim()
|
|
15
|
+
|| typeof item.template !== 'string' || ids.has(item.id)) throw new Error('模板配置条目无效');
|
|
16
|
+
ids.add(item.id);
|
|
17
|
+
const entry = Object.fromEntries(TEMPLATE_FIELDS.map((field) => [field, typeof item[field] === 'string' ? item[field] : '']));
|
|
18
|
+
entry.isBuiltin = false;
|
|
19
|
+
entry.maintainers = Array.isArray(item.maintainers) ? item.maintainers.filter((name) => typeof name === 'string') : [];
|
|
20
|
+
return entry;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function serializeTemplates(templates) {
|
|
25
|
+
const content = JSON.stringify({ version: CONFIG_VERSION, templates: normalizeTemplates(templates) }, null, 2) + '\n';
|
|
26
|
+
if (Buffer.byteLength(content, 'utf8') > MAX_CONFIG_BYTES) throw new Error('模板配置超过 2MB');
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createPluginConfigController({ fs, path, CONFIG_DIR, backupPromptBeforeWrite }) {
|
|
31
|
+
const filePath = path.join(CONFIG_DIR, 'codexmate-plugin-config.json');
|
|
32
|
+
function getPluginConfig() {
|
|
33
|
+
try {
|
|
34
|
+
const exists = fs.existsSync(filePath);
|
|
35
|
+
const raw = exists ? fs.readFileSync(filePath, 'utf8') : '';
|
|
36
|
+
const parsed = exists ? JSON.parse(raw) : { version: CONFIG_VERSION, templates: [] };
|
|
37
|
+
if (parsed.version !== CONFIG_VERSION) throw new Error('模板配置版本无效');
|
|
38
|
+
return {
|
|
39
|
+
exists, templates: normalizeTemplates(parsed.templates), historyBucket: HISTORY_BUCKET,
|
|
40
|
+
hash: crypto.createHash('sha256').update(raw).digest('hex')
|
|
41
|
+
};
|
|
42
|
+
} catch (error) { return { error: error.message }; }
|
|
43
|
+
}
|
|
44
|
+
function applyPluginConfig(params = {}) {
|
|
45
|
+
try {
|
|
46
|
+
const content = serializeTemplates(params.templates);
|
|
47
|
+
const current = getPluginConfig();
|
|
48
|
+
if (current.error) return current;
|
|
49
|
+
if (typeof params.baseHash !== 'string' || params.baseHash !== current.hash) {
|
|
50
|
+
return { error: '模板配置已被修改,请重新加载后再保存' };
|
|
51
|
+
}
|
|
52
|
+
if (!current.exists && Array.isArray(params.legacyTemplates) && params.legacyTemplates.length) {
|
|
53
|
+
writeTextAtomicWithBackup(filePath, serializeTemplates(params.legacyTemplates), { fs });
|
|
54
|
+
}
|
|
55
|
+
const backup = backupPromptBeforeWrite(HISTORY_BUCKET, filePath);
|
|
56
|
+
if (backup && backup.error) return { error: backup.error };
|
|
57
|
+
writeTextAtomicWithBackup(filePath, content, { fs });
|
|
58
|
+
return getPluginConfig();
|
|
59
|
+
} catch (error) { return { error: error.message }; }
|
|
60
|
+
}
|
|
61
|
+
return { getPluginConfig, applyPluginConfig };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { createPluginConfigController };
|
package/cli/prompt-history.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const { isConfigStaging } = require('../lib/config-change-fs');
|
|
5
|
+
const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
|
|
6
|
+
|
|
3
7
|
function createPromptHistoryController(deps = {}) {
|
|
4
8
|
const {
|
|
5
9
|
fs,
|
|
6
10
|
path,
|
|
7
11
|
CONFIG_DIR,
|
|
8
|
-
MAX_HISTORY = 20
|
|
12
|
+
MAX_HISTORY = 20,
|
|
13
|
+
now = Date.now
|
|
9
14
|
} = deps;
|
|
10
15
|
|
|
11
16
|
if (!fs) throw new Error('createPromptHistoryController 缺少 fs');
|
|
@@ -51,6 +56,7 @@ function createPromptHistoryController(deps = {}) {
|
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
function backupPromptBeforeWrite(bucket, currentFilePath) {
|
|
59
|
+
if (isConfigStaging()) return { backedUp: false, entries: [] };
|
|
54
60
|
const dir = resolveBucketDir(bucket);
|
|
55
61
|
const exists = fs.existsSync(currentFilePath);
|
|
56
62
|
if (!exists) return { backedUp: false, entries: listPromptHistory(bucket) };
|
|
@@ -61,10 +67,19 @@ function createPromptHistoryController(deps = {}) {
|
|
|
61
67
|
return { backedUp: false, error: '读取当前文件失败: ' + e.message };
|
|
62
68
|
}
|
|
63
69
|
ensureDirSync(dir);
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
let time = now();
|
|
71
|
+
let stamp = buildTimestamp(new Date(time));
|
|
72
|
+
let dest = path.join(dir, stamp + '.bak');
|
|
73
|
+
while (fs.existsSync(dest)) {
|
|
74
|
+
time += 1;
|
|
75
|
+
stamp = buildTimestamp(new Date(time));
|
|
76
|
+
dest = path.join(dir, stamp + '.bak');
|
|
77
|
+
}
|
|
66
78
|
try {
|
|
67
|
-
|
|
79
|
+
writeTextAtomicWithBackup(dest, raw, { fs });
|
|
80
|
+
const sourceHash = crypto.createHash('sha256').update(Buffer.from(raw, 'utf8')).digest('hex');
|
|
81
|
+
const backupHash = crypto.createHash('sha256').update(fs.readFileSync(dest)).digest('hex');
|
|
82
|
+
if (sourceHash !== backupHash) throw new Error('历史备份校验失败');
|
|
68
83
|
} catch (e) {
|
|
69
84
|
return { backedUp: false, error: '写入备份失败: ' + e.message };
|
|
70
85
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
|
|
4
|
+
|
|
3
5
|
function createSystemPromptFileController(deps = {}) {
|
|
4
6
|
const {
|
|
5
7
|
fs,
|
|
@@ -120,11 +122,12 @@ function createSystemPromptFileController(deps = {}) {
|
|
|
120
122
|
const bucket = 'system_' + target.scope + '_' + (target.scope === 'project'
|
|
121
123
|
? sanitizeSystemHistoryId(path.dirname(target.path))
|
|
122
124
|
: 'global');
|
|
123
|
-
backupPromptBeforeWrite(bucket, target.path);
|
|
125
|
+
const backup = backupPromptBeforeWrite(bucket, target.path);
|
|
126
|
+
if (backup && backup.error) return { error: backup.error };
|
|
124
127
|
sysHistoryBucket = bucket;
|
|
125
128
|
}
|
|
126
129
|
const finalContent = content.endsWith('\n') ? content : content + '\n';
|
|
127
|
-
|
|
130
|
+
writeTextAtomicWithBackup(target.path, finalContent, { fs });
|
|
128
131
|
try { fs.chmodSync(target.path, 0o600); } catch (_) {}
|
|
129
132
|
} catch (e) {
|
|
130
133
|
return { error: '写入 system prompt 失败: ' + e.message };
|
|
@@ -146,6 +149,8 @@ function createSystemPromptFileController(deps = {}) {
|
|
|
146
149
|
}
|
|
147
150
|
return {
|
|
148
151
|
...resolved,
|
|
152
|
+
historyBucket: 'system_' + resolved.scope + '_' + (resolved.scope === 'project'
|
|
153
|
+
? sanitizeSystemHistoryId(path.dirname(resolved.path)) : 'global'),
|
|
149
154
|
exists,
|
|
150
155
|
content,
|
|
151
156
|
hash: hashContent(content)
|