cozempic 1.2.3 → 1.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/install.js +34 -3
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
const { spawnSync } = require("child_process");
|
|
5
|
-
const { existsSync } = require("fs");
|
|
5
|
+
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require("fs");
|
|
6
6
|
const { join } = require("path");
|
|
7
|
+
const os = require("os");
|
|
7
8
|
|
|
8
9
|
// ── 1. Install Python package ─────────────────────────────────────────────────
|
|
9
10
|
|
|
@@ -32,7 +33,37 @@ if (!alreadyInstalled) {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
// ── 2.
|
|
36
|
+
// ── 2. Wire global SessionStart hook in ~/.claude/settings.json ──────────────
|
|
37
|
+
// This ensures cozempic auto-configures on every Claude Code session the user
|
|
38
|
+
// opens — even in projects they haven't run `cozempic init` in yet.
|
|
39
|
+
|
|
40
|
+
const claudeDir = join(os.homedir(), ".claude");
|
|
41
|
+
const globalSettingsPath = join(claudeDir, "settings.json");
|
|
42
|
+
const hookCmd = "command -v cozempic >/dev/null 2>&1 || pip install cozempic --quiet; [ -d .claude ] && cozempic init --quiet 2>/dev/null; cozempic guard --daemon 2>/dev/null || true";
|
|
43
|
+
|
|
44
|
+
if (existsSync(claudeDir)) {
|
|
45
|
+
let settings = {};
|
|
46
|
+
if (existsSync(globalSettingsPath)) {
|
|
47
|
+
try { settings = JSON.parse(readFileSync(globalSettingsPath, "utf8")); } catch {}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
settings.hooks = settings.hooks || {};
|
|
51
|
+
settings.hooks.SessionStart = settings.hooks.SessionStart || [];
|
|
52
|
+
|
|
53
|
+
const alreadyWired = settings.hooks.SessionStart.some(h =>
|
|
54
|
+
(h.hooks || []).some(hh => hh.command && hh.command.includes("cozempic"))
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (!alreadyWired) {
|
|
58
|
+
settings.hooks.SessionStart.push({
|
|
59
|
+
hooks: [{ type: "command", command: hookCmd }]
|
|
60
|
+
});
|
|
61
|
+
writeFileSync(globalSettingsPath, JSON.stringify(settings, null, 2));
|
|
62
|
+
console.log("Global SessionStart hook wired — cozempic will auto-configure on every Claude Code session.");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── 3. Auto-configure if already inside a Claude Code project ────────────────
|
|
36
67
|
|
|
37
68
|
const cwd = process.env.INIT_CWD || process.cwd();
|
|
38
69
|
const isClaudeProject = existsSync(join(cwd, ".claude"));
|
|
@@ -46,5 +77,5 @@ if (isClaudeProject) {
|
|
|
46
77
|
console.log("cozempic init failed — run manually: cozempic init");
|
|
47
78
|
}
|
|
48
79
|
} else {
|
|
49
|
-
console.log("cozempic ready.
|
|
80
|
+
console.log("cozempic ready. Auto-guard will activate on your next Claude Code session.");
|
|
50
81
|
}
|