codexmate 0.1.32 → 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 +5 -0
- package/README.vi.md +5 -0
- package/README.zh.md +5 -0
- package/cli/claude-proxy.js +2 -2
- package/cli/prompt-history.js +2 -0
- package/cli.js +165 -213
- package/lib/cli-config-engine.js +6 -1
- 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 +23 -3
- 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/package.json +1 -1
- package/web-ui/app.js +7 -1
- package/web-ui/index.html +1 -0
- package/web-ui/logic.context-window.mjs +15 -0
- package/web-ui/modules/api.mjs +72 -39
- package/web-ui/modules/app.methods.agents.mjs +5 -0
- 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.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/config-change-actions.mjs +9 -0
- package/web-ui/modules/i18n/locales/en.mjs +131 -4
- package/web-ui/modules/i18n/locales/ja.mjs +131 -4
- package/web-ui/modules/i18n/locales/vi.mjs +131 -4
- package/web-ui/modules/i18n/locales/zh-tw.mjs +131 -4
- package/web-ui/modules/i18n/locales/zh.mjs +131 -4
- 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-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-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 +0 -1
- package/web-ui/partials/index/panel-prompts.html +0 -1
- package/web-ui/partials/index/panel-sessions.html +9 -0
- 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 +1077 -135
- package/web-ui/styles/config-changes.css +30 -0
- package/web-ui/styles/openclaw-structured.css +205 -189
- package/web-ui/styles/session-features.css +148 -0
- package/web-ui/styles.css +3 -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]
|
|
@@ -158,6 +162,7 @@ After finding your conversations, manage the configuration, skills, and tasks us
|
|
|
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.
|
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]
|
|
@@ -154,6 +158,7 @@ Sau khi tìm lại cuộc trò chuyện, bạn có thể quản lý cấu hình,
|
|
|
154
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
|
|
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]
|
|
@@ -157,6 +161,7 @@ node cli.js thread ack <thread-id> --handoff <id> --agent <target> --evidence <s
|
|
|
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
|
- **任务编排器**:复用工作流定义自动推进任务,持久保存进度与结果,仅在阻塞时请求介入。
|
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
|
}
|
package/cli/prompt-history.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
|
+
const { isConfigStaging } = require('../lib/config-change-fs');
|
|
4
5
|
const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
|
|
5
6
|
|
|
6
7
|
function createPromptHistoryController(deps = {}) {
|
|
@@ -55,6 +56,7 @@ function createPromptHistoryController(deps = {}) {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function backupPromptBeforeWrite(bucket, currentFilePath) {
|
|
59
|
+
if (isConfigStaging()) return { backedUp: false, entries: [] };
|
|
58
60
|
const dir = resolveBucketDir(bucket);
|
|
59
61
|
const exists = fs.existsSync(currentFilePath);
|
|
60
62
|
if (!exists) return { backedUp: false, entries: listPromptHistory(bucket) };
|
package/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs');
|
|
2
|
+
const { fs, isConfigStaging, stageConfigWrites } = require('./lib/config-change-fs');
|
|
3
|
+
const { createConfigChanges } = require('./lib/config-changes');
|
|
3
4
|
const path = require('path');
|
|
4
5
|
const os = require('os');
|
|
5
6
|
const crypto = require('crypto');
|
|
@@ -96,6 +97,7 @@ const {
|
|
|
96
97
|
executeWorkflowDefinition
|
|
97
98
|
} = require('./lib/workflow-engine');
|
|
98
99
|
const { createWorkflowRunner } = require('./lib/workflow-runner');
|
|
100
|
+
const { createWebServerLifecycle } = require('./lib/web-server');
|
|
99
101
|
const {
|
|
100
102
|
ALLOWED_EVENTS: WEBHOOK_ALLOWED_EVENTS,
|
|
101
103
|
defaultConfigPath: defaultWebhookConfigPath,
|
|
@@ -140,6 +142,9 @@ const {
|
|
|
140
142
|
} = require('./cli/prompt-history');
|
|
141
143
|
const { createPluginConfigController } = require('./cli/plugin-config');
|
|
142
144
|
const { createSessionContextHealthController } = require('./lib/session-context-health');
|
|
145
|
+
const { createSessionFeatures } = require('./lib/session-features');
|
|
146
|
+
const { listHandoffs } = require('./lib/thread-handoff');
|
|
147
|
+
const { discoverServers, probeServer } = require('./lib/handoff-mcp');
|
|
143
148
|
const {
|
|
144
149
|
createArchiveHelperController
|
|
145
150
|
} = require('./cli/archive-helpers');
|
|
@@ -1293,6 +1298,74 @@ function getApiToolConfigWriteTarget(action) {
|
|
|
1293
1298
|
return '';
|
|
1294
1299
|
}
|
|
1295
1300
|
|
|
1301
|
+
const CONFIG_CHANGE_ACTIONS = Object.freeze({
|
|
1302
|
+
'apply-config-template': 'codex', 'add-provider': 'codex', 'update-provider': 'codex',
|
|
1303
|
+
'delete-provider': 'codex', 'reset-config': 'codex', 'add-model': 'codex', 'delete-model': 'codex',
|
|
1304
|
+
'apply-claude-settings-raw': 'claude', 'apply-claude-config': 'claude',
|
|
1305
|
+
'apply-opencode-config': 'opencode', 'update-opencode-selection': 'opencode',
|
|
1306
|
+
'apply-kilocode-config': 'kilocode', 'apply-openclaw-config': 'openclaw',
|
|
1307
|
+
'write-pi-models': 'pi', 'write-pi-settings': 'pi', 'apply-pi-config-history': 'pi'
|
|
1308
|
+
});
|
|
1309
|
+
const CONFIG_CHANGE_READERS = Object.freeze({
|
|
1310
|
+
'get-config-template': { target: 'codex', read: getConfigTemplate },
|
|
1311
|
+
'get-claude-settings-raw': { target: 'claude', read: readClaudeSettingsRaw },
|
|
1312
|
+
'get-openclaw-config': { target: 'openclaw', read: params => readOpenclawConfigFile(params) },
|
|
1313
|
+
'get-opencode-config': { target: 'opencode', read: readOpencodeConfigInfo },
|
|
1314
|
+
'get-kilocode-config': { target: 'kilocode', read: readKilocodeConfigInfo },
|
|
1315
|
+
'read-pi-models': { target: 'pi', read: readPiModels },
|
|
1316
|
+
'read-pi-settings': { target: 'pi', read: readPiSettings }
|
|
1317
|
+
});
|
|
1318
|
+
const configChanges = createConfigChanges({
|
|
1319
|
+
journalPath: path.join(CODEXMATE_DIR, 'config-change-last.json'),
|
|
1320
|
+
getTarget: action => Object.prototype.hasOwnProperty.call(CONFIG_CHANGE_ACTIONS, action) ? CONFIG_CHANGE_ACTIONS[action] : '',
|
|
1321
|
+
isTarget: target => TOOL_CONFIG_PERMISSION_TARGETS.has(target),
|
|
1322
|
+
isAllowed: isToolConfigWriteAllowed,
|
|
1323
|
+
isPathAllowed(filePath) {
|
|
1324
|
+
if (OPENCODE_CONFIG_ENV_FILE && filePath === OPENCODE_CONFIG_ENV_FILE) return true;
|
|
1325
|
+
const roots = [CONFIG_DIR, CODEXMATE_DIR, CLAUDE_DIR, OPENCLAW_DIR, OPENCODE_CONFIG_DIR, KILOCODE_CONFIG_DIR, getPiAgentDir()];
|
|
1326
|
+
return roots.some(root => {
|
|
1327
|
+
const relative = path.relative(root, filePath);
|
|
1328
|
+
return relative && !relative.startsWith('..' + path.sep) && relative !== '..' && !path.isAbsolute(relative);
|
|
1329
|
+
});
|
|
1330
|
+
},
|
|
1331
|
+
execute(action, params) {
|
|
1332
|
+
const handlers = {
|
|
1333
|
+
'apply-config-template': applyConfigTemplate,
|
|
1334
|
+
'add-provider': values => addProviderToConfig({ ...values, requireModel: true }),
|
|
1335
|
+
'update-provider': updateProviderInConfig, 'delete-provider': deleteProviderFromConfig,
|
|
1336
|
+
'reset-config': resetConfigToDefault,
|
|
1337
|
+
'add-model': values => { cmdAddModel(values.model, true); return { success: true }; },
|
|
1338
|
+
'delete-model': values => { cmdDeleteModel(values.model, true); return { success: true }; },
|
|
1339
|
+
'apply-claude-settings-raw': applyClaudeSettingsRaw,
|
|
1340
|
+
'apply-claude-config': values => applyToClaudeSettings(values.config),
|
|
1341
|
+
'apply-opencode-config': applyOpencodeConfigRaw, 'update-opencode-selection': updateOpencodeSelection,
|
|
1342
|
+
'apply-kilocode-config': applyKilocodeConfig, 'apply-openclaw-config': applyOpenclawConfig,
|
|
1343
|
+
'write-pi-models': writePiModels, 'write-pi-settings': writePiSettings,
|
|
1344
|
+
'apply-pi-config-history': applyPiConfigHistory
|
|
1345
|
+
};
|
|
1346
|
+
return handlers[action](params);
|
|
1347
|
+
},
|
|
1348
|
+
beforeWrite(plan, entry) {
|
|
1349
|
+
if (plan.target !== 'pi') return;
|
|
1350
|
+
const bucket = path.basename(entry.path) === 'models.json' ? 'pi-models' : 'pi-settings';
|
|
1351
|
+
const backup = historyBackup(bucket, entry.path);
|
|
1352
|
+
if (backup && backup.error) throw new Error('保存 Pi 历史备份失败');
|
|
1353
|
+
},
|
|
1354
|
+
runtimeState(plan) {
|
|
1355
|
+
return plan.action === 'apply-claude-config' ? { running: getBuiltinClaudeProxyStatus().running === true } : null;
|
|
1356
|
+
},
|
|
1357
|
+
async reconcileRuntime(plan, rollback, state) {
|
|
1358
|
+
if (plan.action !== 'apply-claude-config') return;
|
|
1359
|
+
await stopBuiltinClaudeProxyRuntime();
|
|
1360
|
+
const saved = readJsonObjectFromFile(BUILTIN_CLAUDE_PROXY_SETTINGS_FILE, DEFAULT_BUILTIN_CLAUDE_PROXY_SETTINGS);
|
|
1361
|
+
if (!saved.ok) throw new Error('读取 Claude 兼容代理配置失败');
|
|
1362
|
+
if (rollback ? state && state.running : saved.data.enabled) {
|
|
1363
|
+
const result = await startBuiltinClaudeProxyRuntime(saved.data, { skipWrite: true });
|
|
1364
|
+
if (result.error) throw new Error('恢复 Claude 兼容代理失败');
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1296
1369
|
function getPiAgentDir() {
|
|
1297
1370
|
const homeDir = (typeof os.homedir === 'function' ? os.homedir() : null) || process.env.HOME || process.env.USERPROFILE || '';
|
|
1298
1371
|
return path.join(homeDir, '.pi', 'agent');
|
|
@@ -8099,6 +8172,9 @@ const {
|
|
|
8099
8172
|
});
|
|
8100
8173
|
|
|
8101
8174
|
const {
|
|
8175
|
+
saveBuiltinClaudeProxySettings,
|
|
8176
|
+
buildBuiltinClaudeProxyListenUrl,
|
|
8177
|
+
resolveBuiltinClaudeProxyUpstream,
|
|
8102
8178
|
startBuiltinClaudeProxyRuntime,
|
|
8103
8179
|
stopBuiltinClaudeProxyRuntime,
|
|
8104
8180
|
getBuiltinClaudeProxyStatus
|
|
@@ -9826,10 +9902,33 @@ async function extractMessagesFromFile(filePath, source, options = {}) {
|
|
|
9826
9902
|
return state;
|
|
9827
9903
|
}
|
|
9828
9904
|
|
|
9829
|
-
const { readSessionContextHealth, readSessionContextNode } = createSessionContextHealthController({
|
|
9905
|
+
const { readSessionContextHealth, readSessionContextNode, iterateSessionContextNodes } = createSessionContextHealthController({
|
|
9830
9906
|
fs, normalizeSessionSourceName, resolveSessionFilePath, queryOpencodeSessionMessages, queryZedSessionMessages
|
|
9831
9907
|
});
|
|
9832
9908
|
|
|
9909
|
+
const sessionFeatures = createSessionFeatures({ root: path.join(CODEXMATE_DIR, 'session-features'),
|
|
9910
|
+
readNode: readSessionContextNode, nodes: iterateSessionContextNodes,
|
|
9911
|
+
diagnostics: {
|
|
9912
|
+
home: os.homedir(),
|
|
9913
|
+
secrets: () => [readServerToken()],
|
|
9914
|
+
local: async () => {
|
|
9915
|
+
const report = await buildDoctorReport({ remote: false, includeInstall: false, includeUsage: false }, {
|
|
9916
|
+
getStatusPayload: buildMcpStatusPayload, buildConfigHealthReport, listSkills });
|
|
9917
|
+
return { ok: report.ok, issues: report.issues.map((item) => ({ id: item.id, severity: item.severity,
|
|
9918
|
+
problem: item.problem, impact: item.impact, actions: item.actions })),
|
|
9919
|
+
command: 'codexmate doctor --format md' };
|
|
9920
|
+
},
|
|
9921
|
+
provider: async () => {
|
|
9922
|
+
const report = await buildConfigHealthReport({ remote: true });
|
|
9923
|
+
return { ok: report.ok, issues: (report.issues || []).map((item) => ({ code: item.code, statusCode: item.statusCode })),
|
|
9924
|
+
command: 'codexmate doctor --format md' };
|
|
9925
|
+
},
|
|
9926
|
+
mcp: (name, options) => probeServer(name, options),
|
|
9927
|
+
mcpTargets: (cwd) => discoverServers({ cwd, allServers: true }).map((server) => server.name)
|
|
9928
|
+
},
|
|
9929
|
+
handoffs: (threadId) => listHandoffs(threadId),
|
|
9930
|
+
inventory: (source, limit) => listSessionInventoryBySource(source, limit, { scanCount: limit, maxFilesScanned: limit * 4 }, { forceRefresh: true }) });
|
|
9931
|
+
|
|
9833
9932
|
async function readSessionDetail(params = {}) {
|
|
9834
9933
|
const source = normalizeSessionSourceName(params.source, '');
|
|
9835
9934
|
if (!source) {
|
|
@@ -12373,9 +12472,9 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12373
12472
|
error: 'chat_completions 模式需要显式的上游 Base URL 或可解析的 provider 名称'
|
|
12374
12473
|
};
|
|
12375
12474
|
}
|
|
12376
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12475
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12377
12476
|
const proxyToken = crypto.randomBytes(24).toString('hex');
|
|
12378
|
-
|
|
12477
|
+
const proxyPayload = {
|
|
12379
12478
|
enabled: true,
|
|
12380
12479
|
host: DEFAULT_BUILTIN_CLAUDE_PROXY_SETTINGS.host,
|
|
12381
12480
|
provider: upstreamProviderName,
|
|
@@ -12385,9 +12484,18 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12385
12484
|
upstreamProviderName,
|
|
12386
12485
|
...(configuredBaseUrl ? { upstreamBaseUrl: configuredBaseUrl } : {}),
|
|
12387
12486
|
upstreamApiKey: apiKey
|
|
12388
|
-
}
|
|
12487
|
+
};
|
|
12488
|
+
if (isConfigStaging()) {
|
|
12489
|
+
const saved = saveBuiltinClaudeProxySettings(proxyPayload);
|
|
12490
|
+
if (saved.error) return { error: saved.error };
|
|
12491
|
+
const upstream = configuredBaseUrl ? null : resolveBuiltinClaudeProxyUpstream(saved.settings);
|
|
12492
|
+
if (upstream && upstream.error) return { error: upstream.error };
|
|
12493
|
+
proxyResult = { success: true, listenUrl: buildBuiltinClaudeProxyListenUrl(saved.settings), upstreamProvider: upstreamProviderName };
|
|
12494
|
+
} else {
|
|
12495
|
+
proxyResult = await startBuiltinClaudeProxyRuntime(proxyPayload);
|
|
12496
|
+
}
|
|
12389
12497
|
if (!proxyResult || proxyResult.error || proxyResult.success === false || !proxyResult.listenUrl) {
|
|
12390
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12498
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12391
12499
|
resetBuiltinClaudeProxySavedSettingsToResponses();
|
|
12392
12500
|
return {
|
|
12393
12501
|
success: false,
|
|
@@ -12399,14 +12507,14 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12399
12507
|
settingsBaseUrl = proxyResult.listenUrl;
|
|
12400
12508
|
settingsApiKey = proxyToken;
|
|
12401
12509
|
} else {
|
|
12402
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12510
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12403
12511
|
resetBuiltinClaudeProxySavedSettingsToResponses();
|
|
12404
12512
|
}
|
|
12405
12513
|
|
|
12406
12514
|
const readResult = readJsonObjectFromFile(CLAUDE_SETTINGS_FILE, {});
|
|
12407
12515
|
if (!readResult.ok) {
|
|
12408
12516
|
if (proxyStarted) {
|
|
12409
|
-
await stopBuiltinClaudeProxyRuntime();
|
|
12517
|
+
if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime();
|
|
12410
12518
|
resetBuiltinClaudeProxySavedSettingsToResponses();
|
|
12411
12519
|
}
|
|
12412
12520
|
return { success: false, mode: 'settings-file', error: readResult.error };
|
|
@@ -12469,7 +12577,7 @@ async function applyToClaudeSettings(config = {}) {
|
|
|
12469
12577
|
return result;
|
|
12470
12578
|
} catch (e) {
|
|
12471
12579
|
if (proxyStarted) {
|
|
12472
|
-
try { await stopBuiltinClaudeProxyRuntime(); } catch (_) {}
|
|
12580
|
+
try { if (!isConfigStaging()) await stopBuiltinClaudeProxyRuntime(); } catch (_) {}
|
|
12473
12581
|
try { resetBuiltinClaudeProxySavedSettingsToResponses(); } catch (_) {}
|
|
12474
12582
|
}
|
|
12475
12583
|
return {
|
|
@@ -14196,137 +14304,11 @@ const PUBLIC_WEB_UI_STATIC_ASSETS = new Set([
|
|
|
14196
14304
|
]);
|
|
14197
14305
|
|
|
14198
14306
|
function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser }) {
|
|
14199
|
-
|
|
14307
|
+
|
|
14200
14308
|
const startupAuth = createStartupAuth(readServerToken());
|
|
14201
14309
|
const httpToken = startupAuth.token;
|
|
14202
14310
|
const accessControlMiddleware = createWebAccessControlMiddleware(host);
|
|
14203
|
-
const probeWebUiReadiness = (callback) => {
|
|
14204
|
-
const payload = JSON.stringify({ action: 'health-check', params: {} });
|
|
14205
|
-
const requestOptions = {
|
|
14206
|
-
hostname: openHost,
|
|
14207
|
-
port,
|
|
14208
|
-
path: '/api',
|
|
14209
|
-
method: 'POST',
|
|
14210
|
-
headers: {
|
|
14211
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
14212
|
-
'Content-Length': Buffer.byteLength(payload, 'utf-8'),
|
|
14213
|
-
...(httpToken ? { Authorization: `Bearer ${httpToken}` } : {})
|
|
14214
|
-
}
|
|
14215
|
-
};
|
|
14216
|
-
let settled = false;
|
|
14217
|
-
const finish = (ready) => {
|
|
14218
|
-
if (settled) return;
|
|
14219
|
-
settled = true;
|
|
14220
|
-
callback(ready);
|
|
14221
|
-
};
|
|
14222
|
-
const req = http.request(requestOptions, (probeRes) => {
|
|
14223
|
-
if (typeof probeRes.resume === 'function') {
|
|
14224
|
-
probeRes.resume();
|
|
14225
|
-
}
|
|
14226
|
-
probeRes.on('end', () => {
|
|
14227
|
-
finish(probeRes.statusCode === 200);
|
|
14228
|
-
});
|
|
14229
|
-
});
|
|
14230
|
-
req.on('error', () => finish(false));
|
|
14231
|
-
req.setTimeout(1000, () => {
|
|
14232
|
-
try { req.destroy(); } catch (_) { }
|
|
14233
|
-
finish(false);
|
|
14234
|
-
});
|
|
14235
|
-
req.end(payload, 'utf-8');
|
|
14236
|
-
};
|
|
14237
|
-
const probeWebUiAssetReadiness = (callback) => {
|
|
14238
|
-
const requestOptions = {
|
|
14239
|
-
hostname: openHost,
|
|
14240
|
-
port,
|
|
14241
|
-
path: '/web-ui/app.js',
|
|
14242
|
-
method: 'GET',
|
|
14243
|
-
headers: httpToken ? { Authorization: `Bearer ${httpToken}` } : {}
|
|
14244
|
-
};
|
|
14245
|
-
let settled = false;
|
|
14246
|
-
const finish = (ready) => {
|
|
14247
|
-
if (settled) return;
|
|
14248
|
-
settled = true;
|
|
14249
|
-
callback(ready);
|
|
14250
|
-
};
|
|
14251
|
-
const req = http.request(requestOptions, (probeRes) => {
|
|
14252
|
-
if (typeof probeRes.resume === 'function') {
|
|
14253
|
-
probeRes.resume();
|
|
14254
|
-
}
|
|
14255
|
-
probeRes.on('end', () => {
|
|
14256
|
-
finish(probeRes.statusCode === 200);
|
|
14257
|
-
});
|
|
14258
|
-
});
|
|
14259
|
-
req.on('error', () => finish(false));
|
|
14260
|
-
req.setTimeout(1000, () => {
|
|
14261
|
-
try { req.destroy(); } catch (_) { }
|
|
14262
|
-
finish(false);
|
|
14263
|
-
});
|
|
14264
|
-
req.end();
|
|
14265
|
-
};
|
|
14266
|
-
const openBrowserAfterReady = (url) => {
|
|
14267
|
-
// Some environments may start the listener before the bundled web-ui assets
|
|
14268
|
-
// are ready for the first browser hit; wait until both API and assets respond.
|
|
14269
|
-
const maxAttempts = 120;
|
|
14270
|
-
const retryDelayMs = 200;
|
|
14271
|
-
let finished = false;
|
|
14272
|
-
|
|
14273
|
-
const finish = (ready) => {
|
|
14274
|
-
if (finished) return;
|
|
14275
|
-
finished = true;
|
|
14276
|
-
if (!ready) {
|
|
14277
|
-
console.warn('! Web UI 就绪探测超时,未自动打开浏览器,请手动访问:', url);
|
|
14278
|
-
return;
|
|
14279
|
-
}
|
|
14280
14311
|
|
|
14281
|
-
const platform = process.platform;
|
|
14282
|
-
const commandSpec = platform === 'win32'
|
|
14283
|
-
? { command: 'cmd', args: ['/c', 'start', '', url] }
|
|
14284
|
-
: (platform === 'darwin'
|
|
14285
|
-
? { command: 'open', args: [url] }
|
|
14286
|
-
: { command: 'xdg-open', args: [url] });
|
|
14287
|
-
|
|
14288
|
-
try {
|
|
14289
|
-
const child = spawn(commandSpec.command, commandSpec.args, {
|
|
14290
|
-
stdio: 'ignore',
|
|
14291
|
-
detached: true,
|
|
14292
|
-
windowsHide: true
|
|
14293
|
-
});
|
|
14294
|
-
child.on('error', () => {
|
|
14295
|
-
console.warn('无法自动打开浏览器,请手动访问:', url);
|
|
14296
|
-
});
|
|
14297
|
-
if (typeof child.unref === 'function') {
|
|
14298
|
-
child.unref();
|
|
14299
|
-
}
|
|
14300
|
-
} catch (_) {
|
|
14301
|
-
console.warn('无法自动打开浏览器,请手动访问:', url);
|
|
14302
|
-
}
|
|
14303
|
-
};
|
|
14304
|
-
const scheduleProbe = (attempt) => {
|
|
14305
|
-
probeWebUiReadiness((apiReady) => {
|
|
14306
|
-
if (!apiReady) {
|
|
14307
|
-
if (attempt >= maxAttempts) {
|
|
14308
|
-
finish(false);
|
|
14309
|
-
return;
|
|
14310
|
-
}
|
|
14311
|
-
setTimeout(() => scheduleProbe(attempt + 1), retryDelayMs);
|
|
14312
|
-
return;
|
|
14313
|
-
}
|
|
14314
|
-
probeWebUiAssetReadiness((assetReady) => {
|
|
14315
|
-
if (assetReady) {
|
|
14316
|
-
finish(true);
|
|
14317
|
-
return;
|
|
14318
|
-
}
|
|
14319
|
-
if (attempt >= maxAttempts) {
|
|
14320
|
-
finish(false);
|
|
14321
|
-
return;
|
|
14322
|
-
}
|
|
14323
|
-
setTimeout(() => scheduleProbe(attempt + 1), retryDelayMs);
|
|
14324
|
-
});
|
|
14325
|
-
});
|
|
14326
|
-
};
|
|
14327
|
-
|
|
14328
|
-
scheduleProbe(1);
|
|
14329
|
-
};
|
|
14330
14312
|
const writeWebUiAssetError = (res, requestPath, error) => {
|
|
14331
14313
|
const message = error && error.message ? error.message : String(error);
|
|
14332
14314
|
console.error(`! Web UI 资源读取失败 [${requestPath}]:`, message);
|
|
@@ -14462,10 +14444,31 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
14462
14444
|
let result;
|
|
14463
14445
|
|
|
14464
14446
|
const guardedToolConfigTarget = getApiToolConfigWriteTarget(action);
|
|
14465
|
-
if (guardedToolConfigTarget &&
|
|
14447
|
+
if (guardedToolConfigTarget && configChanges.isBusy()) {
|
|
14448
|
+
result = { error: '已有配置变更正在执行', errorCode: 'config-change-busy' };
|
|
14449
|
+
} else if (guardedToolConfigTarget && !isToolConfigWriteAllowed(guardedToolConfigTarget)) {
|
|
14466
14450
|
result = buildToolConfigWriteDeniedPayload(guardedToolConfigTarget);
|
|
14451
|
+
} else if (Object.prototype.hasOwnProperty.call(CONFIG_CHANGE_READERS, action)) {
|
|
14452
|
+
const reader = CONFIG_CHANGE_READERS[action];
|
|
14453
|
+
const observed = await stageConfigWrites(() => reader.read(params || {}), { maxFileBytes: Infinity, allowSymlinks: true });
|
|
14454
|
+
result = { ...observed.result, configChangeTarget: reader.target, configChangeBaseline: observed.files.map(entry => ({ path: entry.path, exists: entry.before.exists, hash: entry.before.hash, mode: entry.before.mode })) };
|
|
14467
14455
|
} else {
|
|
14468
14456
|
switch (action) {
|
|
14457
|
+
case 'preview-config-change':
|
|
14458
|
+
result = await configChanges.preview(params || {});
|
|
14459
|
+
break;
|
|
14460
|
+
case 'apply-config-change':
|
|
14461
|
+
result = await configChanges.apply(params || {});
|
|
14462
|
+
if (result.change && result.change.action === 'apply-claude-config') {
|
|
14463
|
+
notifyWebhook('provider-switch', 'Claude provider configuration applied', { changeId: result.change.id }).catch(function () { });
|
|
14464
|
+
}
|
|
14465
|
+
break;
|
|
14466
|
+
case 'get-last-config-change':
|
|
14467
|
+
result = configChanges.last(params || {});
|
|
14468
|
+
break;
|
|
14469
|
+
case 'undo-config-change':
|
|
14470
|
+
result = await configChanges.undo(params || {});
|
|
14471
|
+
break;
|
|
14469
14472
|
case 'health-check':
|
|
14470
14473
|
result = { ok: true };
|
|
14471
14474
|
break;
|
|
@@ -15049,6 +15052,27 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
15049
15052
|
case 'thread-handoff-ack':
|
|
15050
15053
|
result = await handleThreadAction(action, params || {});
|
|
15051
15054
|
break;
|
|
15055
|
+
case 'session-diagnostics-targets':
|
|
15056
|
+
case 'session-diagnostics-start':
|
|
15057
|
+
case 'session-diagnostics-status':
|
|
15058
|
+
case 'session-diagnostics-cancel':
|
|
15059
|
+
case 'session-feature-settings-get':
|
|
15060
|
+
case 'session-feature-settings-save':
|
|
15061
|
+
case 'session-projects':
|
|
15062
|
+
case 'session-project-map':
|
|
15063
|
+
case 'session-project-prompt':
|
|
15064
|
+
case 'session-handoff-draft':
|
|
15065
|
+
case 'session-index-status':
|
|
15066
|
+
case 'session-index-refresh':
|
|
15067
|
+
case 'session-index-cancel':
|
|
15068
|
+
case 'session-index-search':
|
|
15069
|
+
case 'session-index-node':
|
|
15070
|
+
case 'session-bookmarks-list':
|
|
15071
|
+
case 'session-bookmark-save':
|
|
15072
|
+
case 'session-bookmark-remove':
|
|
15073
|
+
case 'session-bookmark-locate':
|
|
15074
|
+
result = await sessionFeatures.handle(action, params || {});
|
|
15075
|
+
break;
|
|
15052
15076
|
case 'session-context-health':
|
|
15053
15077
|
result = await readSessionContextHealth(params || {});
|
|
15054
15078
|
break;
|
|
@@ -15414,83 +15438,11 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
|
|
|
15414
15438
|
handleRequest(req, res);
|
|
15415
15439
|
}));
|
|
15416
15440
|
});
|
|
15417
|
-
|
|
15418
|
-
|
|
15419
|
-
|
|
15420
|
-
|
|
15421
|
-
});
|
|
15422
|
-
|
|
15423
|
-
const printPortOverrideHint = () => {
|
|
15424
|
-
const examplePort = port === 8080 ? 8081 : 8080;
|
|
15425
|
-
console.error(` 临时换端口(macOS/Linux): CODEXMATE_PORT=${examplePort} codexmate run`);
|
|
15426
|
-
console.error(` 临时换端口(Windows PowerShell): $env:CODEXMATE_PORT=${examplePort}; codexmate run`);
|
|
15427
|
-
console.error(` 临时换端口(Windows CMD): set CODEXMATE_PORT=${examplePort} && codexmate run`);
|
|
15428
|
-
};
|
|
15429
|
-
|
|
15430
|
-
server.once('error', (err) => {
|
|
15431
|
-
if (err && err.code === 'EADDRINUSE') {
|
|
15432
|
-
console.error(`! 启动失败: 端口 ${port} 已被占用,可能有残留的 codexmate run 实例。`);
|
|
15433
|
-
console.error(' 请先停止旧实例或更换端口后重试。');
|
|
15434
|
-
printPortOverrideHint();
|
|
15435
|
-
} else if (err && err.code === 'EACCES') {
|
|
15436
|
-
console.error(`! 启动失败: 没有权限监听 ${host}:${port}。`);
|
|
15437
|
-
console.error(' 请检查系统/安全软件限制,或更换端口后重试。');
|
|
15438
|
-
printPortOverrideHint();
|
|
15439
|
-
} else {
|
|
15440
|
-
console.error('! 启动 Web UI 失败:', err && err.message ? err.message : err);
|
|
15441
|
-
}
|
|
15442
|
-
process.exit(1);
|
|
15443
|
-
});
|
|
15444
|
-
|
|
15445
|
-
const openHost = host === '::'
|
|
15446
|
-
? '::1'
|
|
15447
|
-
: (host === '0.0.0.0' ? DEFAULT_WEB_OPEN_HOST : host);
|
|
15448
|
-
const openUrl = `http://${formatHostForUrl(openHost)}:${port}/?token=${encodeURIComponent(httpToken)}`;
|
|
15449
|
-
server.listen(port, host, () => {
|
|
15450
|
-
getUnattendedWorkflowRunner().recover();
|
|
15451
|
-
console.log('\n✓ Web UI 已启动');
|
|
15452
|
-
const willOpenBrowser = !!openBrowser && !process.env.CODEXMATE_NO_BROWSER;
|
|
15453
|
-
console.log(` ${willOpenBrowser ? '已打开' : '待访问'}: ${openUrl}`);
|
|
15454
|
-
if (host && host !== openHost) {
|
|
15455
|
-
console.log(' 监听地址:', host);
|
|
15456
|
-
}
|
|
15457
|
-
console.log(' 退出: Ctrl+C\n');
|
|
15458
|
-
if (isAnyAddressHost(host)) {
|
|
15459
|
-
console.warn('! 安全提示: 当前监听所有网卡,局域网访问需要访问令牌。');
|
|
15460
|
-
console.warn(' 远程 /bridge/ 请求需携带 Authorization: Bearer <访问令牌>。');
|
|
15461
|
-
const allowedIps = (process.env.CODEXMATE_ALLOWED_IPS || '').trim();
|
|
15462
|
-
if (allowedIps) {
|
|
15463
|
-
console.warn(` 已启用的来源 IP 白名单: ${allowedIps}`);
|
|
15464
|
-
}
|
|
15465
|
-
}
|
|
15466
|
-
|
|
15467
|
-
if (willOpenBrowser) {
|
|
15468
|
-
openBrowserAfterReady(openUrl);
|
|
15469
|
-
}
|
|
15441
|
+
return createWebServerLifecycle({ server, host, port, httpToken, openBrowser }, {
|
|
15442
|
+
http, process, console, setTimeout, formatHostForUrl, DEFAULT_WEB_OPEN_HOST, isAnyAddressHost,
|
|
15443
|
+
spawn: (...args) => spawn(...args),
|
|
15444
|
+
getUnattendedWorkflowRunner: () => getUnattendedWorkflowRunner()
|
|
15470
15445
|
});
|
|
15471
|
-
|
|
15472
|
-
const stop = () => new Promise((resolve) => {
|
|
15473
|
-
let done = false;
|
|
15474
|
-
const finish = () => {
|
|
15475
|
-
if (done) return;
|
|
15476
|
-
done = true;
|
|
15477
|
-
for (const socket of connections) {
|
|
15478
|
-
try { socket.destroy(); } catch (_) { }
|
|
15479
|
-
}
|
|
15480
|
-
connections.clear();
|
|
15481
|
-
resolve();
|
|
15482
|
-
};
|
|
15483
|
-
|
|
15484
|
-
if (!server.listening) {
|
|
15485
|
-
finish();
|
|
15486
|
-
return;
|
|
15487
|
-
}
|
|
15488
|
-
|
|
15489
|
-
server.close(() => finish());
|
|
15490
|
-
setTimeout(() => finish(), 800);
|
|
15491
|
-
});
|
|
15492
|
-
|
|
15493
|
-
return { server, stop };
|
|
15494
15446
|
}
|
|
15495
15447
|
|
|
15496
15448
|
// Region markers are used by unit tests that extract these helpers directly.
|
package/lib/cli-config-engine.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const crypto = require('crypto');
|
|
2
|
-
const fs = require('fs');
|
|
2
|
+
const { fs, isConfigStaging } = require('./config-change-fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const toml = require('@iarna/toml');
|
|
5
5
|
|
|
@@ -144,6 +144,7 @@ function writeBufferAtomically(filePath, buffer, mode, fsImpl) {
|
|
|
144
144
|
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}-${crypto.randomBytes(4).toString('hex')}`;
|
|
145
145
|
try {
|
|
146
146
|
fsImpl.writeFileSync(tmpPath, buffer, { encoding: 'utf-8', mode });
|
|
147
|
+
fsImpl.chmodSync(tmpPath, mode);
|
|
147
148
|
syncFile(tmpPath, fsImpl);
|
|
148
149
|
fsImpl.renameSync(tmpPath, filePath);
|
|
149
150
|
} catch (error) {
|
|
@@ -177,6 +178,10 @@ function writeTextAtomicWithBackup(filePath, content, options = {}) {
|
|
|
177
178
|
const fsImpl = options.fs || fs;
|
|
178
179
|
const now = options.now instanceof Date ? options.now : new Date();
|
|
179
180
|
const text = typeof content === 'string' ? content : String(content || '');
|
|
181
|
+
if (isConfigStaging() && fsImpl === fs) {
|
|
182
|
+
fsImpl.writeFileSync(filePath, text, 'utf8');
|
|
183
|
+
return { path: filePath, backupPath: '', backupCreated: false };
|
|
184
|
+
}
|
|
180
185
|
fsImpl.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
181
186
|
const targetExists = fsImpl.existsSync(filePath);
|
|
182
187
|
const originalBuffer = targetExists ? fsImpl.readFileSync(filePath) : null;
|
package/lib/cli-file-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
1
|
+
const { fs, isConfigStaging } = require('./config-change-fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
function ensureDir(dirPath) {
|
|
@@ -85,6 +85,7 @@ function formatTimestampForFileName(value) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function backupFileIfNeededOnce(filePath, backupPrefix = 'codexmate-backup') {
|
|
88
|
+
if (isConfigStaging()) return '';
|
|
88
89
|
if (!fs.existsSync(filePath)) {
|
|
89
90
|
return '';
|
|
90
91
|
}
|
|
@@ -106,6 +107,10 @@ function backupFileIfNeededOnce(filePath, backupPrefix = 'codexmate-backup') {
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
function writeJsonAtomic(filePath, data) {
|
|
110
|
+
if (isConfigStaging()) {
|
|
111
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
109
114
|
const dirPath = path.dirname(filePath);
|
|
110
115
|
ensureDir(dirPath);
|
|
111
116
|
|