@maccesar/titools 2.4.0 → 2.4.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/lib/commands/auto-update.js +6 -3
- package/lib/hooks.js +23 -8
- package/package.json +1 -1
|
@@ -51,6 +51,7 @@ export async function autoUpdateCommand(options) {
|
|
|
51
51
|
|
|
52
52
|
// Step 1: Check cache
|
|
53
53
|
if (!shouldCheck(cacheDir)) {
|
|
54
|
+
log(chalk.green('✔'), `Up to date (v${PACKAGE_VERSION})`);
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -81,16 +82,18 @@ export async function autoUpdateCommand(options) {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
// Step 5: Update CLI (skip in dev mode)
|
|
85
|
+
spinner.succeed(`Update available: v${PACKAGE_VERSION} → ${latestVersion}`);
|
|
86
|
+
|
|
84
87
|
if (isDevMode()) {
|
|
85
|
-
spinner.info(`Dev mode — skipping npm update
|
|
88
|
+
spinner.info(`Dev mode — skipping npm update`);
|
|
86
89
|
} else {
|
|
87
|
-
spinner.start(`
|
|
90
|
+
spinner.start(`Downloading and installing v${latestVersion}...`);
|
|
88
91
|
try {
|
|
89
92
|
execFileSync('npm', ['update', '-g', '@maccesar/titools'], {
|
|
90
93
|
stdio: 'pipe',
|
|
91
94
|
timeout: 60000,
|
|
92
95
|
});
|
|
93
|
-
spinner.succeed(`Updated to ${latestVersion}`);
|
|
96
|
+
spinner.succeed(`Updated to v${latestVersion}`);
|
|
94
97
|
} catch (error) {
|
|
95
98
|
spinner.fail(`npm update failed: ${error.message}`);
|
|
96
99
|
return;
|
package/lib/hooks.js
CHANGED
|
@@ -7,7 +7,6 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
|
7
7
|
import { join } from 'path';
|
|
8
8
|
|
|
9
9
|
const HOOK_COMMAND = 'titools auto-update --silent';
|
|
10
|
-
const HOOK_TIMEOUT = 30000;
|
|
11
10
|
const SETTINGS_FILE = 'settings.json';
|
|
12
11
|
|
|
13
12
|
function readSettings(claudeDir) {
|
|
@@ -28,11 +27,22 @@ function writeSettings(claudeDir, settings) {
|
|
|
28
27
|
);
|
|
29
28
|
}
|
|
30
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Find the hook entry that contains our command
|
|
32
|
+
* Claude Code hook format: { hooks: [{ type: "command", command: "..." }] }
|
|
33
|
+
*/
|
|
34
|
+
function findHookEntry(sessionStartHooks) {
|
|
35
|
+
if (!Array.isArray(sessionStartHooks)) return -1;
|
|
36
|
+
return sessionStartHooks.findIndex((entry) =>
|
|
37
|
+
Array.isArray(entry.hooks) &&
|
|
38
|
+
entry.hooks.some((h) => h.type === 'command' && h.command === HOOK_COMMAND)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
export function hasHook(claudeDir) {
|
|
32
43
|
const settings = readSettings(claudeDir);
|
|
33
44
|
const hooks = settings.hooks?.SessionStart;
|
|
34
|
-
|
|
35
|
-
return hooks.some((h) => h.command === HOOK_COMMAND);
|
|
45
|
+
return findHookEntry(hooks) !== -1;
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
export function installHook(claudeDir) {
|
|
@@ -41,8 +51,12 @@ export function installHook(claudeDir) {
|
|
|
41
51
|
if (!settings.hooks) settings.hooks = {};
|
|
42
52
|
if (!Array.isArray(settings.hooks.SessionStart)) settings.hooks.SessionStart = [];
|
|
43
53
|
settings.hooks.SessionStart.push({
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
hooks: [
|
|
55
|
+
{
|
|
56
|
+
type: 'command',
|
|
57
|
+
command: HOOK_COMMAND,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
46
60
|
});
|
|
47
61
|
writeSettings(claudeDir, settings);
|
|
48
62
|
}
|
|
@@ -50,9 +64,10 @@ export function installHook(claudeDir) {
|
|
|
50
64
|
export function removeHook(claudeDir) {
|
|
51
65
|
if (!hasHook(claudeDir)) return;
|
|
52
66
|
const settings = readSettings(claudeDir);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
const idx = findHookEntry(settings.hooks.SessionStart);
|
|
68
|
+
if (idx !== -1) {
|
|
69
|
+
settings.hooks.SessionStart.splice(idx, 1);
|
|
70
|
+
}
|
|
56
71
|
writeSettings(claudeDir, settings);
|
|
57
72
|
}
|
|
58
73
|
|