karajan-code 4.29.0 → 4.29.1
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/package.json +1 -1
- package/scripts/postinstall.js +35 -15
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -27,12 +27,28 @@ async function writeJson(file, obj) {
|
|
|
27
27
|
await fs.writeFile(file, `${JSON.stringify(obj, null, 2)}\n`, "utf8");
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const CLAUDE_JSON_PATH = path.join(os.homedir(), ".claude.json");
|
|
31
|
+
|
|
32
|
+
// KJC-BUG-0179 (#1730): a home INSIDE the npm package is the old default
|
|
33
|
+
// this script wrote itself — wiped on every reinstall, never where `kj init`
|
|
34
|
+
// stores kj.config.yml. Such a value is stale, not a user choice.
|
|
35
|
+
const isPackageDirHome = (home) => /node_modules[\\/]karajan-code[\\/]\.karajan[\\/]?$/.test(home);
|
|
36
|
+
|
|
37
|
+
/** The home a previous registration carried, if the user (not this script) set it. */
|
|
38
|
+
function homeFromExistingEntry(entry) {
|
|
39
|
+
const previous = entry?.env?.KARAJAN_HOME || entry?.env?.KJ_HOME;
|
|
40
|
+
return previous && !isPackageDirHome(previous) ? previous : null;
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Precedence: KARAJAN_HOME → KJ_HOME (deprecated) → the existing entry's home
|
|
45
|
+
* → the instances registry → `~/.karajan` (where the CLI defaults, KJC-BUG-0179).
|
|
46
|
+
*/
|
|
47
|
+
async function resolveKjHome(existingEntry) {
|
|
48
|
+
if (process.env.KARAJAN_HOME) return process.env.KARAJAN_HOME;
|
|
49
|
+
if (process.env.KJ_HOME) return process.env.KJ_HOME;
|
|
50
|
+
const previous = homeFromExistingEntry(existingEntry);
|
|
51
|
+
if (previous) return previous;
|
|
36
52
|
try {
|
|
37
53
|
const registry = await readJson(REGISTRY_PATH);
|
|
38
54
|
const names = Object.keys(registry.instances || {});
|
|
@@ -43,28 +59,31 @@ async function resolveKjHomeFromRegistry() {
|
|
|
43
59
|
} catch {
|
|
44
60
|
// No registry yet — use default
|
|
45
61
|
}
|
|
46
|
-
return
|
|
62
|
+
return path.join(os.homedir(), ".karajan");
|
|
47
63
|
}
|
|
48
64
|
|
|
49
|
-
async function
|
|
50
|
-
const claudeJsonPath = path.join(os.homedir(), ".claude.json");
|
|
51
|
-
let config = {};
|
|
65
|
+
async function readClaudeConfig() {
|
|
52
66
|
try {
|
|
53
|
-
|
|
67
|
+
return await readJson(CLAUDE_JSON_PATH);
|
|
54
68
|
} catch {
|
|
55
|
-
|
|
69
|
+
return {};
|
|
56
70
|
}
|
|
71
|
+
}
|
|
57
72
|
|
|
73
|
+
async function setupClaudeMcp(config, kjHome) {
|
|
58
74
|
config.mcpServers = config.mcpServers || {};
|
|
75
|
+
// Keep every env key the user added to the entry; only the home is ours,
|
|
76
|
+
// and it is written under the current name (KJ_HOME is deprecated).
|
|
77
|
+
const { KJ_HOME: _stale, ...userEnv } = config.mcpServers["karajan-mcp"]?.env || {};
|
|
59
78
|
config.mcpServers["karajan-mcp"] = {
|
|
60
79
|
type: "stdio",
|
|
61
80
|
command: "node",
|
|
62
81
|
args: [path.join(ROOT_DIR, "src", "mcp", "server.js")],
|
|
63
82
|
cwd: ROOT_DIR,
|
|
64
|
-
env: {
|
|
83
|
+
env: { ...userEnv, KARAJAN_HOME: kjHome }
|
|
65
84
|
};
|
|
66
85
|
|
|
67
|
-
await writeJson(
|
|
86
|
+
await writeJson(CLAUDE_JSON_PATH, config);
|
|
68
87
|
}
|
|
69
88
|
|
|
70
89
|
function upsertCodexMcpBlock(toml, block) {
|
|
@@ -96,7 +115,7 @@ async function setupCodexMcp(kjHome) {
|
|
|
96
115
|
`args = [${tomlPath(path.join(ROOT_DIR, "src", "mcp", "server.js"))}]`,
|
|
97
116
|
`cwd = ${tomlPath(ROOT_DIR)}`,
|
|
98
117
|
'[mcp_servers."karajan-mcp".env]',
|
|
99
|
-
`
|
|
118
|
+
`KARAJAN_HOME = ${tomlPath(kjHome)}`
|
|
100
119
|
].join("\n");
|
|
101
120
|
|
|
102
121
|
const updated = upsertCodexMcpBlock(toml, block);
|
|
@@ -105,9 +124,10 @@ async function setupCodexMcp(kjHome) {
|
|
|
105
124
|
}
|
|
106
125
|
|
|
107
126
|
async function main() {
|
|
108
|
-
const
|
|
127
|
+
const claudeConfig = await readClaudeConfig();
|
|
128
|
+
const kjHome = await resolveKjHome(claudeConfig.mcpServers?.["karajan-mcp"]);
|
|
109
129
|
|
|
110
|
-
await setupClaudeMcp(kjHome);
|
|
130
|
+
await setupClaudeMcp(claudeConfig, kjHome);
|
|
111
131
|
await setupCodexMcp(kjHome);
|
|
112
132
|
|
|
113
133
|
console.log("karajan-mcp registered in Claude Code and Codex.");
|