setup-cc-room 0.2.2 → 0.2.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/dist/chunk-3AMPTQ5K.js +20 -0
- package/dist/chunk-CVPLSBRZ.js +151 -0
- package/dist/chunk-DXODI3WA.js +151 -0
- package/dist/chunk-EF2H256X.js +131 -0
- package/dist/chunk-F5MDW7XR.js +123 -0
- package/dist/chunk-NHOFSPZ5.js +142 -0
- package/dist/chunk-RB72MUPN.js +125 -0
- package/dist/chunk-URM67EVS.js +123 -0
- package/dist/chunk-XX72CSJC.js +169 -0
- package/dist/chunk-Y4O4R4IQ.js +280 -0
- package/dist/chunk-Z3DH4ZOT.js +125 -0
- package/dist/daemon-resolver.d.ts +1 -2
- package/dist/daemon-resolver.js +1 -3
- package/dist/i18n.js +1 -1
- package/dist/index.js +9 -9
- package/dist/installer.js +5 -5
- package/dist/register-service.d.ts +8 -1
- package/dist/register-service.js +9 -4
- package/dist/settings-merger.d.ts +31 -1
- package/dist/settings-merger.js +9 -2
- package/dist/uninstaller.js +3 -3
- package/dist/validators.js +2 -2
- package/package.json +1 -1
- package/vendor/daemon/dist/index.js +20 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveDaemonCommand
|
|
3
|
+
} from "./chunk-CVPLSBRZ.js";
|
|
4
|
+
import {
|
|
5
|
+
t
|
|
6
|
+
} from "./chunk-Y4O4R4IQ.js";
|
|
7
|
+
import {
|
|
8
|
+
resolveCcRoomDir
|
|
9
|
+
} from "./chunk-WCEABGOA.js";
|
|
10
|
+
|
|
11
|
+
// src/register-service.ts
|
|
12
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
13
|
+
import { join } from "path";
|
|
14
|
+
import { homedir, platform } from "os";
|
|
15
|
+
import { execFileSync } from "child_process";
|
|
16
|
+
var CC_ROOM_DIR = resolveCcRoomDir();
|
|
17
|
+
function escapeXml(text) {
|
|
18
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
19
|
+
}
|
|
20
|
+
function sanitizeSystemdEnvValue(value) {
|
|
21
|
+
if (!value) return null;
|
|
22
|
+
if (/[\0\n\r"]/.test(value)) return null;
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function ccRoomHomeEnvXml() {
|
|
26
|
+
if (!process.env.CC_ROOM_HOME) return "";
|
|
27
|
+
return `
|
|
28
|
+
<key>CC_ROOM_HOME</key>
|
|
29
|
+
<string>${escapeXml(process.env.CC_ROOM_HOME)}</string>`;
|
|
30
|
+
}
|
|
31
|
+
function registerLaunchd() {
|
|
32
|
+
const plistDir = join(homedir(), "Library", "LaunchAgents");
|
|
33
|
+
const plistPath = join(plistDir, "dev.ccroom.daemon.plist");
|
|
34
|
+
const daemonBin = resolveDaemonCommand();
|
|
35
|
+
const logPath = join(CC_ROOM_DIR, "logs", "daemon.log");
|
|
36
|
+
mkdirSync(join(CC_ROOM_DIR, "logs"), { recursive: true });
|
|
37
|
+
mkdirSync(plistDir, { recursive: true });
|
|
38
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
39
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
40
|
+
<plist version="1.0">
|
|
41
|
+
<dict>
|
|
42
|
+
<key>Label</key>
|
|
43
|
+
<string>dev.ccroom.daemon</string>
|
|
44
|
+
<key>ProgramArguments</key>
|
|
45
|
+
<array>
|
|
46
|
+
<string>${escapeXml(daemonBin)}</string>
|
|
47
|
+
</array>
|
|
48
|
+
<key>KeepAlive</key>
|
|
49
|
+
<true/>
|
|
50
|
+
<key>RunAtLoad</key>
|
|
51
|
+
<true/>
|
|
52
|
+
<key>StandardOutPath</key>
|
|
53
|
+
<string>${escapeXml(logPath)}</string>
|
|
54
|
+
<key>StandardErrorPath</key>
|
|
55
|
+
<string>${escapeXml(logPath)}</string>
|
|
56
|
+
<key>EnvironmentVariables</key>
|
|
57
|
+
<dict>
|
|
58
|
+
<key>PATH</key>
|
|
59
|
+
<string>/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin</string>${ccRoomHomeEnvXml()}
|
|
60
|
+
</dict>
|
|
61
|
+
</dict>
|
|
62
|
+
</plist>
|
|
63
|
+
`;
|
|
64
|
+
writeFileSync(plistPath, plist, { mode: 420 });
|
|
65
|
+
try {
|
|
66
|
+
execFileSync("launchctl", ["unload", plistPath], { stdio: "pipe" });
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
execFileSync("launchctl", ["load", plistPath], { stdio: "pipe" });
|
|
71
|
+
console.log(t("svc.launchd_ok", { path: plistPath }));
|
|
72
|
+
} catch (err) {
|
|
73
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
74
|
+
console.log(t("svc.launchd_fail", { msg }));
|
|
75
|
+
console.log(t("svc.launchd_manual", { path: plistPath }));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function registerSystemd() {
|
|
79
|
+
const serviceDir = join(homedir(), ".config", "systemd", "user");
|
|
80
|
+
const servicePath = join(serviceDir, "cc-room-daemon.service");
|
|
81
|
+
const daemonBin = resolveDaemonCommand();
|
|
82
|
+
const logPath = join(CC_ROOM_DIR, "logs", "daemon.log");
|
|
83
|
+
mkdirSync(join(CC_ROOM_DIR, "logs"), { recursive: true });
|
|
84
|
+
mkdirSync(serviceDir, { recursive: true });
|
|
85
|
+
const rawHome = process.env.CC_ROOM_HOME;
|
|
86
|
+
const safeHome = rawHome ? sanitizeSystemdEnvValue(rawHome) : null;
|
|
87
|
+
if (rawHome && !safeHome) {
|
|
88
|
+
console.log(t("svc.cc_room_home_unsafe"));
|
|
89
|
+
}
|
|
90
|
+
const envLine = safeHome ? `Environment="CC_ROOM_HOME=${safeHome}"
|
|
91
|
+
` : "";
|
|
92
|
+
const unit = `[Unit]
|
|
93
|
+
Description=cc-room daemon
|
|
94
|
+
After=network.target
|
|
95
|
+
|
|
96
|
+
[Service]
|
|
97
|
+
ExecStart=${daemonBin}
|
|
98
|
+
Restart=on-failure
|
|
99
|
+
RestartSec=5
|
|
100
|
+
${envLine}StandardOutput=append:${logPath}
|
|
101
|
+
StandardError=append:${logPath}
|
|
102
|
+
|
|
103
|
+
[Install]
|
|
104
|
+
WantedBy=default.target
|
|
105
|
+
`;
|
|
106
|
+
writeFileSync(servicePath, unit, { mode: 420 });
|
|
107
|
+
try {
|
|
108
|
+
execFileSync("systemctl", ["--user", "daemon-reload"], { stdio: "pipe" });
|
|
109
|
+
execFileSync("systemctl", ["--user", "enable", "--now", "cc-room-daemon"], { stdio: "pipe" });
|
|
110
|
+
console.log(t("svc.systemd_ok", { path: servicePath }));
|
|
111
|
+
} catch (err) {
|
|
112
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
113
|
+
console.log(t("svc.systemd_fail", { msg }));
|
|
114
|
+
console.log(t("svc.systemd_manual"));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function registerService() {
|
|
118
|
+
const os = platform();
|
|
119
|
+
if (os === "darwin") {
|
|
120
|
+
registerLaunchd();
|
|
121
|
+
} else if (os === "linux") {
|
|
122
|
+
registerSystemd();
|
|
123
|
+
} else {
|
|
124
|
+
console.log(t("svc.unsupported", { os }));
|
|
125
|
+
}
|
|
126
|
+
const pidPath = join(CC_ROOM_DIR, "daemon.pid");
|
|
127
|
+
if (!existsSync(pidPath)) {
|
|
128
|
+
console.log(t("svc.waiting"));
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
130
|
+
}
|
|
131
|
+
if (existsSync(pidPath)) {
|
|
132
|
+
console.log(t("svc.started"));
|
|
133
|
+
} else {
|
|
134
|
+
console.log(t("svc.start_unconfirmed"));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
escapeXml,
|
|
140
|
+
sanitizeSystemdEnvValue,
|
|
141
|
+
registerService
|
|
142
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveDaemonSource
|
|
3
|
+
} from "./chunk-3AMPTQ5K.js";
|
|
4
|
+
import {
|
|
5
|
+
registerService
|
|
6
|
+
} from "./chunk-NHOFSPZ5.js";
|
|
7
|
+
import {
|
|
8
|
+
mergeSettings
|
|
9
|
+
} from "./chunk-CVPLSBRZ.js";
|
|
10
|
+
import {
|
|
11
|
+
t
|
|
12
|
+
} from "./chunk-Y4O4R4IQ.js";
|
|
13
|
+
import {
|
|
14
|
+
resolveCcRoomDir
|
|
15
|
+
} from "./chunk-WCEABGOA.js";
|
|
16
|
+
|
|
17
|
+
// src/installer.ts
|
|
18
|
+
import {
|
|
19
|
+
mkdirSync,
|
|
20
|
+
writeFileSync,
|
|
21
|
+
existsSync,
|
|
22
|
+
copyFileSync,
|
|
23
|
+
chmodSync,
|
|
24
|
+
unlinkSync
|
|
25
|
+
} from "fs";
|
|
26
|
+
import { join, dirname } from "path";
|
|
27
|
+
import { homedir } from "os";
|
|
28
|
+
import { execFileSync, spawnSync } from "child_process";
|
|
29
|
+
import { fileURLToPath } from "url";
|
|
30
|
+
import { stringify } from "yaml";
|
|
31
|
+
var CC_ROOM_DIR = resolveCcRoomDir();
|
|
32
|
+
var BIN_DIR = join(CC_ROOM_DIR, "bin");
|
|
33
|
+
var CONFIG_PATH = join(CC_ROOM_DIR, "config.yaml");
|
|
34
|
+
var COMMANDS_DIR = join(homedir(), ".claude", "commands");
|
|
35
|
+
var THIS_DIR = dirname(fileURLToPath(import.meta.url));
|
|
36
|
+
var SETUP_PACKAGE_ROOT = join(THIS_DIR, "..");
|
|
37
|
+
function getGitUserName() {
|
|
38
|
+
try {
|
|
39
|
+
return execFileSync("git", ["config", "user.name"], { encoding: "utf-8", stdio: "pipe" }).trim();
|
|
40
|
+
} catch {
|
|
41
|
+
return "unknown";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function resolveCommandSources(setupPackageRoot, locale) {
|
|
45
|
+
const candidates = [
|
|
46
|
+
join(setupPackageRoot, "vendor", "commands", "room", locale),
|
|
47
|
+
join(setupPackageRoot, "..", "commands", "room", locale),
|
|
48
|
+
// legacy flat layout (pre-i18n)
|
|
49
|
+
join(setupPackageRoot, "vendor", "commands", "room"),
|
|
50
|
+
join(setupPackageRoot, "..", "commands", "room")
|
|
51
|
+
];
|
|
52
|
+
for (const dir of candidates) {
|
|
53
|
+
if (existsSync(join(dir, "room.md"))) return dir;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
async function install(locale = "en") {
|
|
58
|
+
console.log(t("install.step1", { dir: CC_ROOM_DIR }));
|
|
59
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
60
|
+
const daemonSrc = resolveDaemonSource(SETUP_PACKAGE_ROOT);
|
|
61
|
+
const daemonDest = join(BIN_DIR, "cc-room-daemon");
|
|
62
|
+
if (daemonSrc) {
|
|
63
|
+
copyFileSync(daemonSrc, daemonDest);
|
|
64
|
+
chmodSync(daemonDest, 493);
|
|
65
|
+
console.log(t("install.copied", { path: daemonDest }));
|
|
66
|
+
} else {
|
|
67
|
+
const globalBin = spawnSync("which", ["cc-room-daemon"], { encoding: "utf-8" });
|
|
68
|
+
if (globalBin.status === 0) {
|
|
69
|
+
console.log(t("install.global_ok", { path: globalBin.stdout.trim() }));
|
|
70
|
+
} else {
|
|
71
|
+
console.log(` \x1B[33m\u26A0 ${t("daemon.missing")}\x1B[0m`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
console.log(t("install.step2", { path: CONFIG_PATH }));
|
|
75
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
76
|
+
const identity = getGitUserName();
|
|
77
|
+
const config = {
|
|
78
|
+
identity: { name: identity },
|
|
79
|
+
ui: { locale },
|
|
80
|
+
network: { port: 7331, http_port: 7332 },
|
|
81
|
+
trust: [],
|
|
82
|
+
sessions: { default_mode: "approve", share_files: true, share_context: true },
|
|
83
|
+
privacy: {
|
|
84
|
+
public_tools: ["room_context", "room_messages", "room_files", "room_status", "room_invite", "room_share"],
|
|
85
|
+
private_patterns: [],
|
|
86
|
+
redact_after_private_tool: true
|
|
87
|
+
},
|
|
88
|
+
summarizer: { model: "claude-haiku-4-5-20251001", interval_turns: 5, interval_seconds: 30 },
|
|
89
|
+
storage: { max_bytes: 524288e3, artifact_ttl_days: 30, context_ttl_days: 7, message_ttl_days: 14 }
|
|
90
|
+
};
|
|
91
|
+
writeFileSync(CONFIG_PATH, stringify(config), { mode: 384 });
|
|
92
|
+
console.log(t("install.config_created", { path: CONFIG_PATH, identity }));
|
|
93
|
+
} else {
|
|
94
|
+
console.log(t("install.config_skip", { path: CONFIG_PATH }));
|
|
95
|
+
}
|
|
96
|
+
console.log(t("install.step3", { locale }));
|
|
97
|
+
mkdirSync(COMMANDS_DIR, { recursive: true });
|
|
98
|
+
const commandFiles = ["room.md", "private.md", "show.md"];
|
|
99
|
+
const legacyFiles = ["invite.md", "join.md", "leave.md", "files.md", "remember.md", "share.md"];
|
|
100
|
+
const commandsSrcDir = resolveCommandSources(SETUP_PACKAGE_ROOT, locale);
|
|
101
|
+
if (!commandsSrcDir) {
|
|
102
|
+
throw new Error(`Command source directory not found for locale=${locale}`);
|
|
103
|
+
}
|
|
104
|
+
for (const cmd of commandFiles) {
|
|
105
|
+
const src = join(commandsSrcDir, cmd);
|
|
106
|
+
if (!existsSync(src)) throw new Error(`Command source file not found: ${src}`);
|
|
107
|
+
copyFileSync(src, join(COMMANDS_DIR, cmd));
|
|
108
|
+
}
|
|
109
|
+
for (const legacy of legacyFiles) {
|
|
110
|
+
const dest = join(COMMANDS_DIR, legacy);
|
|
111
|
+
if (existsSync(dest)) {
|
|
112
|
+
unlinkSync(dest);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
console.log(t("install.commands_ok", { count: commandFiles.length, dir: COMMANDS_DIR }));
|
|
116
|
+
console.log(t("install.step4"));
|
|
117
|
+
mergeSettings();
|
|
118
|
+
console.log(t("install.step5"));
|
|
119
|
+
await registerService();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
resolveCommandSources,
|
|
124
|
+
install
|
|
125
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
unmergeSettings
|
|
3
|
+
} from "./chunk-DXODI3WA.js";
|
|
4
|
+
import {
|
|
5
|
+
t
|
|
6
|
+
} from "./chunk-OYW7MM4W.js";
|
|
7
|
+
import {
|
|
8
|
+
resolveCcRoomDir
|
|
9
|
+
} from "./chunk-WCEABGOA.js";
|
|
10
|
+
|
|
11
|
+
// src/uninstaller.ts
|
|
12
|
+
import {
|
|
13
|
+
existsSync,
|
|
14
|
+
mkdirSync,
|
|
15
|
+
rmSync,
|
|
16
|
+
unlinkSync
|
|
17
|
+
} from "fs";
|
|
18
|
+
import { join } from "path";
|
|
19
|
+
import { homedir, platform } from "os";
|
|
20
|
+
import { execFileSync, spawnSync } from "child_process";
|
|
21
|
+
var COMMAND_FILES = ["room.md", "private.md", "show.md"];
|
|
22
|
+
function getLaunchdPlistPath(home = homedir()) {
|
|
23
|
+
return join(home, "Library", "LaunchAgents", "dev.ccroom.daemon.plist");
|
|
24
|
+
}
|
|
25
|
+
function getSystemdUnitPath(home = homedir()) {
|
|
26
|
+
return join(home, ".config", "systemd", "user", "cc-room-daemon.service");
|
|
27
|
+
}
|
|
28
|
+
function stopLaunchd(plistPath) {
|
|
29
|
+
if (!existsSync(plistPath)) {
|
|
30
|
+
console.log(t("un.launchd_none"));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
execFileSync("launchctl", ["unload", plistPath], { stdio: "pipe" });
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
unlinkSync(plistPath);
|
|
39
|
+
console.log(t("un.launchd_ok", { path: plistPath }));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
42
|
+
console.log(t("un.plist_fail", { msg }));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function stopSystemd(unitPath) {
|
|
46
|
+
try {
|
|
47
|
+
execFileSync("systemctl", ["--user", "disable", "--now", "cc-room-daemon"], { stdio: "pipe" });
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
if (existsSync(unitPath)) {
|
|
51
|
+
try {
|
|
52
|
+
unlinkSync(unitPath);
|
|
53
|
+
console.log(t("un.systemd_ok", { path: unitPath }));
|
|
54
|
+
} catch (err) {
|
|
55
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
56
|
+
console.log(t("un.unit_fail", { msg }));
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
console.log(t("un.systemd_none"));
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
execFileSync("systemctl", ["--user", "daemon-reload"], { stdio: "pipe" });
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function removeCommandFiles(commandsDir) {
|
|
67
|
+
mkdirSync(commandsDir, { recursive: true });
|
|
68
|
+
let removed = 0;
|
|
69
|
+
for (const name of COMMAND_FILES) {
|
|
70
|
+
const path = join(commandsDir, name);
|
|
71
|
+
if (existsSync(path)) {
|
|
72
|
+
unlinkSync(path);
|
|
73
|
+
removed++;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
console.log(t("un.commands_ok", { count: removed, dir: commandsDir }));
|
|
77
|
+
}
|
|
78
|
+
function removeCcRoomData(ccRoomDir) {
|
|
79
|
+
if (!existsSync(ccRoomDir)) {
|
|
80
|
+
console.log(t("un.data_skip", { dir: ccRoomDir }));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
rmSync(ccRoomDir, { recursive: true, force: true });
|
|
84
|
+
console.log(t("un.data_ok", { dir: ccRoomDir }));
|
|
85
|
+
}
|
|
86
|
+
function stopOrphanDaemon() {
|
|
87
|
+
if (platform() === "win32") {
|
|
88
|
+
spawnSync("taskkill", ["/F", "/IM", "cc-room-daemon.exe"], { stdio: "pipe" });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
spawnSync("pkill", ["-f", "cc-room-daemon"], { stdio: "pipe" });
|
|
92
|
+
}
|
|
93
|
+
async function uninstall() {
|
|
94
|
+
const ccRoomDir = resolveCcRoomDir();
|
|
95
|
+
const commandsDir = join(homedir(), ".claude", "commands");
|
|
96
|
+
const os = platform();
|
|
97
|
+
console.log(t("un.step1"));
|
|
98
|
+
if (os === "darwin") {
|
|
99
|
+
stopLaunchd(getLaunchdPlistPath());
|
|
100
|
+
} else if (os === "linux") {
|
|
101
|
+
stopSystemd(getSystemdUnitPath());
|
|
102
|
+
} else {
|
|
103
|
+
console.log(t("un.os_manual", { os }));
|
|
104
|
+
}
|
|
105
|
+
stopOrphanDaemon();
|
|
106
|
+
console.log(t("un.step2"));
|
|
107
|
+
removeCommandFiles(commandsDir);
|
|
108
|
+
console.log(t("un.step3"));
|
|
109
|
+
unmergeSettings();
|
|
110
|
+
console.log(t("un.step4"));
|
|
111
|
+
removeCcRoomData(ccRoomDir);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export {
|
|
115
|
+
getLaunchdPlistPath,
|
|
116
|
+
getSystemdUnitPath,
|
|
117
|
+
stopLaunchd,
|
|
118
|
+
stopSystemd,
|
|
119
|
+
removeCommandFiles,
|
|
120
|
+
removeCcRoomData,
|
|
121
|
+
stopOrphanDaemon,
|
|
122
|
+
uninstall
|
|
123
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
t
|
|
3
|
+
} from "./chunk-Y4O4R4IQ.js";
|
|
4
|
+
|
|
5
|
+
// src/validators.ts
|
|
6
|
+
import { execFileSync } from "child_process";
|
|
7
|
+
import { existsSync, readFileSync, accessSync, constants } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
function validateAll() {
|
|
11
|
+
const checks = [
|
|
12
|
+
checkNodeVersion(),
|
|
13
|
+
checkClaudeCodeInstalled(),
|
|
14
|
+
checkClaudeDir(),
|
|
15
|
+
checkSettingsWritable(),
|
|
16
|
+
checkHooksNotDisabled(),
|
|
17
|
+
checkMcpNotBlocked(),
|
|
18
|
+
checkSessionDir(),
|
|
19
|
+
checkGitUser()
|
|
20
|
+
];
|
|
21
|
+
const passed = checks.every((r) => r.ok);
|
|
22
|
+
return { passed, results: checks };
|
|
23
|
+
}
|
|
24
|
+
function printResults(results) {
|
|
25
|
+
console.log("\n Preflight checks:\n");
|
|
26
|
+
for (const r of results) {
|
|
27
|
+
const icon = r.ok ? "\x1B[32m\u2713\x1B[0m" : "\x1B[31m\u2717\x1B[0m";
|
|
28
|
+
console.log(` ${icon} ${r.message}`);
|
|
29
|
+
if (!r.ok && r.hint) {
|
|
30
|
+
console.log(` \x1B[33m\u2192 ${r.hint}\x1B[0m`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
console.log("");
|
|
34
|
+
}
|
|
35
|
+
function checkNodeVersion() {
|
|
36
|
+
const major = parseInt(process.versions.node.split(".")[0], 10);
|
|
37
|
+
if (major >= 20) {
|
|
38
|
+
return { ok: true, message: `Node.js ${process.versions.node}` };
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
ok: false,
|
|
42
|
+
message: t("val.node_bad", { version: process.versions.node }),
|
|
43
|
+
hint: t("val.node_hint")
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function checkClaudeCodeInstalled() {
|
|
47
|
+
try {
|
|
48
|
+
execFileSync("claude", ["--version"], { encoding: "utf-8", stdio: "pipe" });
|
|
49
|
+
return { ok: true, message: t("val.claude_ok") };
|
|
50
|
+
} catch {
|
|
51
|
+
return {
|
|
52
|
+
ok: false,
|
|
53
|
+
message: t("val.claude_missing"),
|
|
54
|
+
hint: t("val.claude_hint")
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function checkClaudeDir() {
|
|
59
|
+
const claudeDir = join(homedir(), ".claude");
|
|
60
|
+
if (existsSync(claudeDir)) {
|
|
61
|
+
return { ok: true, message: t("val.claude_dir_ok") };
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
message: t("val.claude_dir_missing"),
|
|
66
|
+
hint: t("val.claude_dir_hint")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function checkSettingsWritable() {
|
|
70
|
+
const settingsPath = join(homedir(), ".claude", "settings.json");
|
|
71
|
+
const settingsDir = join(homedir(), ".claude");
|
|
72
|
+
if (existsSync(settingsPath)) {
|
|
73
|
+
try {
|
|
74
|
+
accessSync(settingsPath, constants.W_OK);
|
|
75
|
+
return { ok: true, message: t("val.settings_writable") };
|
|
76
|
+
} catch {
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
message: t("val.settings_not_writable"),
|
|
80
|
+
hint: t("val.settings_chmod", { path: settingsPath })
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
accessSync(settingsDir, constants.W_OK);
|
|
86
|
+
return { ok: true, message: t("val.settings_creatable") };
|
|
87
|
+
} catch {
|
|
88
|
+
return {
|
|
89
|
+
ok: false,
|
|
90
|
+
message: t("val.claude_dir_not_writable"),
|
|
91
|
+
hint: t("val.claude_dir_chmod", { path: settingsDir })
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function checkHooksNotDisabled() {
|
|
96
|
+
const settingsPath = join(homedir(), ".claude", "settings.json");
|
|
97
|
+
if (!existsSync(settingsPath)) {
|
|
98
|
+
return { ok: true, message: t("val.hooks_unset") };
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
102
|
+
if (settings.hooks === false || settings.disableHooks === true) {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
message: t("val.hooks_disabled"),
|
|
106
|
+
hint: t("val.hooks_disabled_hint")
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return { ok: true, message: t("val.hooks_ok") };
|
|
110
|
+
} catch {
|
|
111
|
+
return { ok: true, message: t("val.hooks_unrestricted") };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function checkMcpNotBlocked() {
|
|
115
|
+
const settingsPath = join(homedir(), ".claude", "settings.json");
|
|
116
|
+
if (!existsSync(settingsPath)) {
|
|
117
|
+
return { ok: true, message: t("val.mcp_ok") };
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
121
|
+
if (settings.mcpServers === false || settings.disableMcp === true) {
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
message: t("val.mcp_disabled"),
|
|
125
|
+
hint: t("val.mcp_disabled_hint")
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return { ok: true, message: t("val.mcp_ok") };
|
|
129
|
+
} catch {
|
|
130
|
+
return { ok: true, message: t("val.mcp_ok") };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function checkSessionDir() {
|
|
134
|
+
const projectsDir = join(homedir(), ".claude", "projects");
|
|
135
|
+
if (existsSync(projectsDir)) {
|
|
136
|
+
return { ok: true, message: t("val.session_ok") };
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
ok: true,
|
|
140
|
+
message: t("val.session_pending")
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function checkGitUser() {
|
|
144
|
+
try {
|
|
145
|
+
const name = execFileSync("git", ["config", "user.name"], {
|
|
146
|
+
encoding: "utf-8",
|
|
147
|
+
stdio: "pipe"
|
|
148
|
+
}).trim();
|
|
149
|
+
if (name) {
|
|
150
|
+
return { ok: true, message: t("val.git_ok", { name }) };
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
message: t("val.git_no_name"),
|
|
155
|
+
hint: t("val.git_no_name_hint")
|
|
156
|
+
};
|
|
157
|
+
} catch {
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
message: t("val.git_missing"),
|
|
161
|
+
hint: t("val.git_hint")
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
validateAll,
|
|
168
|
+
printResults
|
|
169
|
+
};
|