@maccesar/titools 2.4.0 → 2.4.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.
Files changed (2) hide show
  1. package/lib/hooks.js +23 -8
  2. package/package.json +1 -1
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
- if (!Array.isArray(hooks)) return false;
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
- command: HOOK_COMMAND,
45
- timeout: HOOK_TIMEOUT,
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
- settings.hooks.SessionStart = settings.hooks.SessionStart.filter(
54
- (h) => h.command !== HOOK_COMMAND
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maccesar/titools",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Titanium SDK skills and agents for AI coding assistants (Claude Code, Gemini CLI, Codex CLI)",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",