@promptcellar/pc 0.5.0 → 0.5.2
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/bin/pc.js +5 -1
- package/package.json +1 -1
- package/src/commands/setup.js +44 -6
package/bin/pc.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { program } from 'commander';
|
|
4
|
+
import { createRequire } from 'module';
|
|
4
5
|
import { login } from '../src/commands/login.js';
|
|
5
6
|
import { logout } from '../src/commands/logout.js';
|
|
6
7
|
import { status } from '../src/commands/status.js';
|
|
@@ -10,10 +11,13 @@ import { push } from '../src/commands/push.js';
|
|
|
10
11
|
import { config } from '../src/commands/config.js';
|
|
11
12
|
import { update } from '../src/commands/update.js';
|
|
12
13
|
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
const pkg = require('../package.json');
|
|
16
|
+
|
|
13
17
|
program
|
|
14
18
|
.name('pc')
|
|
15
19
|
.description('PromptCellar CLI - sync prompts between your terminal and the cloud')
|
|
16
|
-
.version(
|
|
20
|
+
.version(pkg.version);
|
|
17
21
|
|
|
18
22
|
program
|
|
19
23
|
.command('login')
|
package/package.json
CHANGED
package/src/commands/setup.js
CHANGED
|
@@ -64,6 +64,23 @@ function isClaudeHookInstalled(settings) {
|
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// Check for legacy Stop hook (pre-0.5.0)
|
|
68
|
+
function hasLegacyClaudeHook(settings) {
|
|
69
|
+
const stopMatchers = settings.hooks?.Stop || [];
|
|
70
|
+
return stopMatchers.some(matcher =>
|
|
71
|
+
matcher.hooks?.some(hook => hook.command?.includes(HOOK_SCRIPT_NAME))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Remove legacy Stop hook if present
|
|
76
|
+
function removeLegacyClaudeHook(settings) {
|
|
77
|
+
if (settings.hooks?.Stop) {
|
|
78
|
+
settings.hooks.Stop = settings.hooks.Stop.filter(matcher =>
|
|
79
|
+
!matcher.hooks?.some(hook => hook.command?.includes(HOOK_SCRIPT_NAME))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
67
84
|
// Codex config (TOML)
|
|
68
85
|
function getCodexConfig() {
|
|
69
86
|
if (existsSync(CODEX_CONFIG_PATH)) {
|
|
@@ -168,8 +185,10 @@ async function setupClaudeCode() {
|
|
|
168
185
|
console.log(chalk.cyan('\nConfiguring Claude Code...'));
|
|
169
186
|
|
|
170
187
|
const settings = getClaudeSettings();
|
|
188
|
+
const hasLegacy = hasLegacyClaudeHook(settings);
|
|
189
|
+
const hasCurrent = isClaudeHookInstalled(settings);
|
|
171
190
|
|
|
172
|
-
if (
|
|
191
|
+
if (hasCurrent) {
|
|
173
192
|
console.log(chalk.yellow(' Hook already installed.'));
|
|
174
193
|
|
|
175
194
|
const { reinstall } = await inquirer.prompt([{
|
|
@@ -180,6 +199,12 @@ async function setupClaudeCode() {
|
|
|
180
199
|
}]);
|
|
181
200
|
|
|
182
201
|
if (!reinstall) {
|
|
202
|
+
// Still remove legacy hook if present
|
|
203
|
+
if (hasLegacy) {
|
|
204
|
+
removeLegacyClaudeHook(settings);
|
|
205
|
+
saveClaudeSettings(settings);
|
|
206
|
+
console.log(chalk.green(' Removed legacy Stop hook.'));
|
|
207
|
+
}
|
|
183
208
|
return;
|
|
184
209
|
}
|
|
185
210
|
|
|
@@ -187,8 +212,13 @@ async function setupClaudeCode() {
|
|
|
187
212
|
settings.hooks.UserPromptSubmit = (settings.hooks.UserPromptSubmit || []).filter(matcher =>
|
|
188
213
|
!matcher.hooks?.some(hook => hook.command?.includes(HOOK_SCRIPT_NAME))
|
|
189
214
|
);
|
|
215
|
+
} else if (hasLegacy) {
|
|
216
|
+
console.log(chalk.yellow(' Migrating from legacy Stop hook to UserPromptSubmit...'));
|
|
190
217
|
}
|
|
191
218
|
|
|
219
|
+
// Always remove legacy Stop hook if present
|
|
220
|
+
removeLegacyClaudeHook(settings);
|
|
221
|
+
|
|
192
222
|
// Ensure hooks.UserPromptSubmit exists
|
|
193
223
|
if (!settings.hooks) {
|
|
194
224
|
settings.hooks = {};
|
|
@@ -313,12 +343,20 @@ export async function unsetup() {
|
|
|
313
343
|
|
|
314
344
|
let removed = false;
|
|
315
345
|
|
|
316
|
-
// Remove Claude hook
|
|
346
|
+
// Remove Claude hook (both current and legacy)
|
|
317
347
|
const claudeSettings = getClaudeSettings();
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
348
|
+
const hasCurrent = isClaudeHookInstalled(claudeSettings);
|
|
349
|
+
const hasLegacy = hasLegacyClaudeHook(claudeSettings);
|
|
350
|
+
|
|
351
|
+
if (hasCurrent || hasLegacy) {
|
|
352
|
+
if (hasCurrent) {
|
|
353
|
+
claudeSettings.hooks.UserPromptSubmit = (claudeSettings.hooks.UserPromptSubmit || []).filter(matcher =>
|
|
354
|
+
!matcher.hooks?.some(hook => hook.command?.includes(HOOK_SCRIPT_NAME))
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
if (hasLegacy) {
|
|
358
|
+
removeLegacyClaudeHook(claudeSettings);
|
|
359
|
+
}
|
|
322
360
|
saveClaudeSettings(claudeSettings);
|
|
323
361
|
console.log(chalk.green(' Removed Claude Code hook.'));
|
|
324
362
|
removed = true;
|