ccstatusline-zh 2.2.34 → 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.
@@ -0,0 +1,23 @@
1
+ import {
2
+ DEV_RELOAD_EXIT_CODE2,
3
+ getDevReloadMode2,
4
+ getDevReloadStateFile2,
5
+ writeDevReloadSnapshot2,
6
+ discardDevReloadSnapshot2,
7
+ readDevReloadSnapshot2,
8
+ requestDevReload2,
9
+ isDevReloadRequested2,
10
+ superviseDevReload2
11
+ } from "./ccstatusline-mkma8vq8.js";
12
+ import"./ccstatusline-er9fa25f.js";
13
+ export {
14
+ DEV_RELOAD_EXIT_CODE2 as DEV_RELOAD_EXIT_CODE,
15
+ discardDevReloadSnapshot2 as discardDevReloadSnapshot,
16
+ getDevReloadMode2 as getDevReloadMode,
17
+ getDevReloadStateFile2 as getDevReloadStateFile,
18
+ isDevReloadRequested2 as isDevReloadRequested,
19
+ readDevReloadSnapshot2 as readDevReloadSnapshot,
20
+ requestDevReload2 as requestDevReload,
21
+ superviseDevReload2 as superviseDevReload,
22
+ writeDevReloadSnapshot2 as writeDevReloadSnapshot
23
+ };
@@ -0,0 +1,159 @@
1
+ import"./ccstatusline-er9fa25f.js";
2
+ import {
3
+ loadClaudeSettings,
4
+ saveClaudeSettings,
5
+ getStatusLineConfigPath,
6
+ getExistingStatusLine,
7
+ getWidget,
8
+ getConfigPath
9
+ } from "./ccstatusline-abxfvbek.js";
10
+
11
+ // src/utils/hooks.ts
12
+ import * as fs from "node:fs";
13
+ var HOOK_TAG = "ccstatusline-managed";
14
+ var CCSTATUSLINE_HOOK_PATTERN = /ccstatusline.* --hook(?:\s|$)/;
15
+ function hasWidgetHooks(widget) {
16
+ return Boolean(widget && "getHooks" in widget && typeof widget.getHooks === "function");
17
+ }
18
+ function isCcstatuslineManagedEntry(entry) {
19
+ return entry._tag === HOOK_TAG;
20
+ }
21
+ function isLegacyCcstatuslineHookCommand(hook) {
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;
26
+ }
27
+ function stripManagedHookEntry(entry) {
28
+ if (isCcstatuslineManagedEntry(entry)) {
29
+ return null;
30
+ }
31
+ if (!Array.isArray(entry.hooks)) {
32
+ return entry;
33
+ }
34
+ const remainingHooks = entry.hooks.filter((hook) => !isLegacyCcstatuslineHookCommand(hook));
35
+ if (remainingHooks.length === entry.hooks.length) {
36
+ return entry;
37
+ }
38
+ if (remainingHooks.length === 0) {
39
+ return null;
40
+ }
41
+ return {
42
+ ...entry,
43
+ hooks: remainingHooks
44
+ };
45
+ }
46
+ function stripManagedHooks(hooks) {
47
+ for (const event of Object.keys(hooks)) {
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) {
65
+ Reflect.deleteProperty(hooks, event);
66
+ }
67
+ }
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
+ }
75
+ function getHookWidgets(settings) {
76
+ const widgets = new Set;
77
+ for (const line of settings.lines) {
78
+ for (const item of line) {
79
+ const widget = getWidget(item.type);
80
+ if (hasWidgetHooks(widget)) {
81
+ widgets.add(widget);
82
+ }
83
+ }
84
+ }
85
+ return [...widgets];
86
+ }
87
+ function getActiveHookDefs(widgets) {
88
+ const seen = new Set;
89
+ const defs = [];
90
+ for (const widget of widgets) {
91
+ for (const hook of widget.getHooks()) {
92
+ const key = `${hook.event}:${hook.matcher ?? ""}`;
93
+ if (!seen.has(key)) {
94
+ seen.add(key);
95
+ defs.push(hook);
96
+ }
97
+ }
98
+ }
99
+ return defs;
100
+ }
101
+ async function resolveHookConfigPath(configPath) {
102
+ try {
103
+ return await fs.promises.realpath(configPath);
104
+ } catch {
105
+ return configPath;
106
+ }
107
+ }
108
+ async function syncWidgetHooks(settings) {
109
+ const hookWidgets = getHookWidgets(settings);
110
+ const needed = getActiveHookDefs(hookWidgets);
111
+ const claudeSettings = await loadClaudeSettings({ logErrors: false });
112
+ const hooks = claudeSettings.hooks ?? {};
113
+ stripManagedHooks(hooks);
114
+ const statusCommand = await getExistingStatusLine();
115
+ if (!statusCommand?.includes("ccstatusline")) {
116
+ claudeSettings.hooks = Object.keys(hooks).length > 0 ? hooks : undefined;
117
+ await saveClaudeSettings(claudeSettings);
118
+ return statusCommand && needed.length > 0 ? { statusCommand, widgetNames: hookWidgets.map((widget) => widget.getDisplayName()) } : null;
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
+ }
131
+ const hookCommand = `${statusCommand} --hook`;
132
+ for (const def of needed) {
133
+ const entry = {
134
+ _tag: HOOK_TAG,
135
+ hooks: [{ type: "command", command: hookCommand }]
136
+ };
137
+ if (def.matcher) {
138
+ entry.matcher = def.matcher;
139
+ }
140
+ const list = hooks[def.event] ??= [];
141
+ list.push(entry);
142
+ }
143
+ claudeSettings.hooks = Object.keys(hooks).length > 0 ? hooks : undefined;
144
+ await saveClaudeSettings(claudeSettings);
145
+ return null;
146
+ }
147
+ function stripManagedHooksFromSettings(claudeSettings) {
148
+ const hooks = claudeSettings.hooks ?? {};
149
+ if (!hasManagedHooks(hooks)) {
150
+ return false;
151
+ }
152
+ stripManagedHooks(hooks);
153
+ claudeSettings.hooks = Object.keys(hooks).length > 0 ? hooks : undefined;
154
+ return true;
155
+ }
156
+ export {
157
+ stripManagedHooksFromSettings,
158
+ syncWidgetHooks
159
+ };