Files
NetMesh/electron/bridges/aiBridge/sdk/claudeConfig.cjs
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

75 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
/**
* Repair ~/.claude.json before the claude-agent-sdk subprocess reads it.
* 1:1 port of craft options.ts ensureClaudeConfig(): a missing/empty/BOM-
* prefixed/corrupted config (or a stale .backup / .corrupted.* sibling) makes
* the Claude Code binary write plain-text recovery messages to stdout, which
* the SDK transport rejects as "CLI output was not valid JSON".
*/
const { join } = require("node:path");
const { homedir } = require("node:os");
const { existsSync, readFileSync, writeFileSync, unlinkSync, readdirSync } = require("node:fs");
const UTF8_BOM = "";
let claudeConfigChecked = false;
function writeConfigSafe(configPath, content) {
try {
writeFileSync(configPath, content, "utf-8");
} catch (err) {
const code = err && err.code;
if (process.platform === "win32" && (code === "EBUSY" || code === "EPERM")) {
const start = Date.now();
while (Date.now() - start < 100) { /* brief busy wait, runs once at startup */ }
try { writeFileSync(configPath, content, "utf-8"); } catch { /* best effort */ }
}
}
}
function ensureClaudeConfig() {
if (claudeConfigChecked) return;
claudeConfigChecked = true;
const configPath = join(homedir(), ".claude.json");
const backupPath = `${configPath}.backup`;
if (existsSync(backupPath)) {
try { unlinkSync(backupPath); } catch { /* best effort */ }
}
try {
const homeDir = homedir();
for (const file of readdirSync(homeDir)) {
if (file.startsWith(".claude.json.corrupted.")) {
try { unlinkSync(join(homeDir, file)); } catch { /* best effort */ }
}
}
} catch { /* ignore — main repair below still runs */ }
if (!existsSync(configPath)) {
writeConfigSafe(configPath, "{}");
return;
}
try {
const raw = readFileSync(configPath, "utf-8");
const content = raw.startsWith(UTF8_BOM) ? raw.slice(1) : raw;
const hasBom = raw !== content;
if (content.trim().length === 0) {
writeConfigSafe(configPath, "{}");
return;
}
JSON.parse(content);
if (hasBom) writeConfigSafe(configPath, content);
} catch {
writeConfigSafe(configPath, "{}");
}
}
function resetClaudeConfigCheck() {
claudeConfigChecked = false;
}
module.exports = { ensureClaudeConfig, resetClaudeConfigCheck };