ccstatusline-zh 2.2.35 → 2.2.36

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.
@@ -1,12 +1,15 @@
1
- import"./ccstatusline-88bs860s.js";
1
+ import"./ccstatusline-er9fa25f.js";
2
2
  import {
3
3
  loadClaudeSettings,
4
4
  saveClaudeSettings,
5
+ getStatusLineConfigPath,
5
6
  getExistingStatusLine,
6
- getWidget
7
- } from "./ccstatusline-98magj3t.js";
7
+ getWidget,
8
+ getConfigPath
9
+ } from "./ccstatusline-abxfvbek.js";
8
10
 
9
11
  // src/utils/hooks.ts
12
+ import * as fs from "node:fs";
10
13
  var HOOK_TAG = "ccstatusline-managed";
11
14
  var CCSTATUSLINE_HOOK_PATTERN = /ccstatusline.* --hook(?:\s|$)/;
12
15
  function hasWidgetHooks(widget) {
@@ -16,13 +19,16 @@ function isCcstatuslineManagedEntry(entry) {
16
19
  return entry._tag === HOOK_TAG;
17
20
  }
18
21
  function isLegacyCcstatuslineHookCommand(hook) {
19
- return CCSTATUSLINE_HOOK_PATTERN.test(hook.command);
22
+ return typeof hook === "object" && hook !== null && "command" in hook && typeof hook.command === "string" && CCSTATUSLINE_HOOK_PATTERN.test(hook.command);
23
+ }
24
+ function isHookEntry(entry) {
25
+ return typeof entry === "object" && entry !== null;
20
26
  }
21
27
  function stripManagedHookEntry(entry) {
22
28
  if (isCcstatuslineManagedEntry(entry)) {
23
29
  return null;
24
30
  }
25
- if (!entry.hooks) {
31
+ if (!Array.isArray(entry.hooks)) {
26
32
  return entry;
27
33
  }
28
34
  const remainingHooks = entry.hooks.filter((hook) => !isLegacyCcstatuslineHookCommand(hook));
@@ -39,12 +45,33 @@ function stripManagedHookEntry(entry) {
39
45
  }
40
46
  function stripManagedHooks(hooks) {
41
47
  for (const event of Object.keys(hooks)) {
42
- hooks[event] = (hooks[event] ?? []).map(stripManagedHookEntry).filter((entry) => entry !== null);
43
- if (hooks[event].length === 0) {
48
+ const entries = hooks[event];
49
+ if (!Array.isArray(entries)) {
50
+ continue;
51
+ }
52
+ const remaining = [];
53
+ for (const entry of entries) {
54
+ if (!isHookEntry(entry)) {
55
+ remaining.push(entry);
56
+ continue;
57
+ }
58
+ const stripped = stripManagedHookEntry(entry);
59
+ if (stripped) {
60
+ remaining.push(stripped);
61
+ }
62
+ }
63
+ hooks[event] = remaining;
64
+ if (remaining.length === 0) {
44
65
  Reflect.deleteProperty(hooks, event);
45
66
  }
46
67
  }
47
68
  }
69
+ function hasManagedHooks(hooks) {
70
+ return Object.keys(hooks).some((event) => {
71
+ const entries = hooks[event];
72
+ return Array.isArray(entries) && entries.some((entry) => isHookEntry(entry) && stripManagedHookEntry(entry) !== entry);
73
+ });
74
+ }
48
75
  function getHookWidgets(settings) {
49
76
  const widgets = new Set;
50
77
  for (const line of settings.lines) {
@@ -71,6 +98,13 @@ function getActiveHookDefs(widgets) {
71
98
  }
72
99
  return defs;
73
100
  }
101
+ async function resolveHookConfigPath(configPath) {
102
+ try {
103
+ return await fs.promises.realpath(configPath);
104
+ } catch {
105
+ return configPath;
106
+ }
107
+ }
74
108
  async function syncWidgetHooks(settings) {
75
109
  const hookWidgets = getHookWidgets(settings);
76
110
  const needed = getActiveHookDefs(hookWidgets);
@@ -83,6 +117,17 @@ async function syncWidgetHooks(settings) {
83
117
  await saveClaudeSettings(claudeSettings);
84
118
  return statusCommand && needed.length > 0 ? { statusCommand, widgetNames: hookWidgets.map((widget) => widget.getDisplayName()) } : null;
85
119
  }
120
+ const statusConfigPath = getStatusLineConfigPath(statusCommand);
121
+ if (statusConfigPath === null) {
122
+ return null;
123
+ }
124
+ const [statusTarget, editedTarget] = await Promise.all([
125
+ resolveHookConfigPath(statusConfigPath),
126
+ resolveHookConfigPath(getConfigPath())
127
+ ]);
128
+ if (statusTarget !== editedTarget) {
129
+ return null;
130
+ }
86
131
  const hookCommand = `${statusCommand} --hook`;
87
132
  for (const def of needed) {
88
133
  const entry = {
@@ -99,14 +144,16 @@ async function syncWidgetHooks(settings) {
99
144
  await saveClaudeSettings(claudeSettings);
100
145
  return null;
101
146
  }
102
- async function removeManagedHooks() {
103
- const claudeSettings = await loadClaudeSettings({ logErrors: false });
147
+ function stripManagedHooksFromSettings(claudeSettings) {
104
148
  const hooks = claudeSettings.hooks ?? {};
149
+ if (!hasManagedHooks(hooks)) {
150
+ return false;
151
+ }
105
152
  stripManagedHooks(hooks);
106
153
  claudeSettings.hooks = Object.keys(hooks).length > 0 ? hooks : undefined;
107
- await saveClaudeSettings(claudeSettings);
154
+ return true;
108
155
  }
109
156
  export {
110
- removeManagedHooks,
157
+ stripManagedHooksFromSettings,
111
158
  syncWidgetHooks
112
159
  };