iskills 0.2.27 → 0.2.40

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 (220) hide show
  1. package/README.md +8 -13
  2. package/bin/iskills.js +9 -0
  3. package/dist/src/cli.js +16 -17
  4. package/dist/src/cli.js.map +1 -1
  5. package/dist/src/commands/browser-actions.d.ts +5 -0
  6. package/dist/src/commands/browser-actions.js +345 -0
  7. package/dist/src/commands/browser-actions.js.map +1 -0
  8. package/dist/src/commands/index.d.ts +3 -6
  9. package/dist/src/commands/index.js +18 -131
  10. package/dist/src/commands/index.js.map +1 -1
  11. package/dist/src/commands/library.d.ts +0 -1
  12. package/dist/src/commands/library.js +40 -216
  13. package/dist/src/commands/library.js.map +1 -1
  14. package/dist/src/commands/search.js +32 -47
  15. package/dist/src/commands/search.js.map +1 -1
  16. package/dist/src/domain/collection-write.d.ts +22 -0
  17. package/dist/src/domain/collection-write.js +411 -0
  18. package/dist/src/domain/collection-write.js.map +1 -0
  19. package/dist/src/domain/core.d.ts +2 -10
  20. package/dist/src/domain/core.js +18 -261
  21. package/dist/src/domain/core.js.map +1 -1
  22. package/dist/src/domain/git.js +15 -25
  23. package/dist/src/domain/git.js.map +1 -1
  24. package/dist/src/domain/types.d.ts +7 -1
  25. package/dist/src/ui/browser/browser.d.ts +11 -0
  26. package/dist/src/ui/browser/browser.js +657 -0
  27. package/dist/src/ui/browser/browser.js.map +1 -0
  28. package/dist/src/ui/browser/detail.d.ts +12 -0
  29. package/dist/src/ui/browser/detail.js +47 -0
  30. package/dist/src/ui/browser/detail.js.map +1 -0
  31. package/dist/src/ui/browser/footer.d.ts +6 -0
  32. package/dist/src/ui/browser/footer.js +199 -0
  33. package/dist/src/ui/browser/footer.js.map +1 -0
  34. package/dist/src/ui/browser/format.d.ts +105 -0
  35. package/dist/src/ui/browser/format.js +421 -0
  36. package/dist/src/ui/browser/format.js.map +1 -0
  37. package/dist/src/ui/browser/index.d.ts +16 -0
  38. package/dist/src/ui/browser/index.js +176 -0
  39. package/dist/src/ui/browser/index.js.map +1 -0
  40. package/dist/src/ui/browser/layout.d.ts +31 -0
  41. package/dist/src/ui/browser/layout.js +55 -0
  42. package/dist/src/ui/browser/layout.js.map +1 -0
  43. package/dist/src/ui/browser/shortcut-help.d.ts +10 -0
  44. package/dist/src/ui/browser/shortcut-help.js +124 -0
  45. package/dist/src/ui/browser/shortcut-help.js.map +1 -0
  46. package/dist/src/ui/browser/store.d.ts +59 -0
  47. package/dist/src/ui/browser/store.js +81 -0
  48. package/dist/src/ui/browser/store.js.map +1 -0
  49. package/dist/src/ui/browser/types.d.ts +134 -0
  50. package/dist/src/ui/browser/types.js +2 -0
  51. package/dist/src/ui/browser/types.js.map +1 -0
  52. package/dist/src/ui/collection-match.d.ts +7 -0
  53. package/dist/src/ui/collection-match.js +15 -0
  54. package/dist/src/ui/collection-match.js.map +1 -0
  55. package/dist/src/ui/components/colors.d.ts +7 -0
  56. package/dist/src/ui/components/colors.js +10 -0
  57. package/dist/src/ui/components/colors.js.map +1 -0
  58. package/dist/src/ui/components/confirm.d.ts +6 -0
  59. package/dist/src/ui/components/confirm.js +22 -0
  60. package/dist/src/ui/components/confirm.js.map +1 -0
  61. package/dist/src/ui/components/framed-panel.d.ts +21 -0
  62. package/dist/src/ui/components/framed-panel.js +66 -0
  63. package/dist/src/ui/components/framed-panel.js.map +1 -0
  64. package/dist/src/ui/components/link.d.ts +7 -0
  65. package/dist/src/ui/components/link.js +12 -0
  66. package/dist/src/ui/components/link.js.map +1 -0
  67. package/dist/src/ui/components/modal.d.ts +16 -0
  68. package/dist/src/ui/components/modal.js +58 -0
  69. package/dist/src/ui/components/modal.js.map +1 -0
  70. package/dist/src/ui/components/mouse/bounds.d.ts +13 -0
  71. package/dist/src/ui/components/mouse/bounds.js +29 -0
  72. package/dist/src/ui/components/mouse/bounds.js.map +1 -0
  73. package/dist/src/ui/components/mouse/clickable.d.ts +10 -0
  74. package/dist/src/ui/components/mouse/clickable.js +14 -0
  75. package/dist/src/ui/components/mouse/clickable.js.map +1 -0
  76. package/dist/src/ui/components/mouse/index.d.ts +4 -0
  77. package/dist/src/ui/components/mouse/index.js +5 -0
  78. package/dist/src/ui/components/mouse/index.js.map +1 -0
  79. package/dist/src/ui/components/mouse/parse.d.ts +13 -0
  80. package/dist/src/ui/components/mouse/parse.js +54 -0
  81. package/dist/src/ui/components/mouse/parse.js.map +1 -0
  82. package/dist/src/ui/components/mouse/provider.d.ts +31 -0
  83. package/dist/src/ui/components/mouse/provider.js +114 -0
  84. package/dist/src/ui/components/mouse/provider.js.map +1 -0
  85. package/dist/src/ui/components/multi-select.d.ts +9 -0
  86. package/dist/src/ui/components/multi-select.js +49 -0
  87. package/dist/src/ui/components/multi-select.js.map +1 -0
  88. package/dist/src/ui/components/options.d.ts +20 -0
  89. package/dist/src/ui/components/options.js +47 -0
  90. package/dist/src/ui/components/options.js.map +1 -0
  91. package/dist/src/ui/components/select.d.ts +9 -0
  92. package/dist/src/ui/components/select.js +47 -0
  93. package/dist/src/ui/components/select.js.map +1 -0
  94. package/dist/src/ui/components/tabs.d.ts +18 -0
  95. package/dist/src/ui/components/tabs.js +38 -0
  96. package/dist/src/ui/components/tabs.js.map +1 -0
  97. package/dist/src/ui/components/tag-editor.d.ts +8 -0
  98. package/dist/src/ui/components/tag-editor.js +56 -0
  99. package/dist/src/ui/components/tag-editor.js.map +1 -0
  100. package/dist/src/ui/components/termcn.d.ts +12 -0
  101. package/dist/src/ui/components/termcn.js +12 -0
  102. package/dist/src/ui/components/termcn.js.map +1 -0
  103. package/dist/src/ui/components/terminal-layout.d.ts +4 -0
  104. package/dist/src/ui/components/terminal-layout.js +43 -0
  105. package/dist/src/ui/components/terminal-layout.js.map +1 -0
  106. package/dist/src/ui/components/text-input.d.ts +10 -0
  107. package/dist/src/ui/components/text-input.js +78 -0
  108. package/dist/src/ui/components/text-input.js.map +1 -0
  109. package/dist/src/ui/components/text.d.ts +2 -0
  110. package/dist/src/ui/components/text.js +8 -0
  111. package/dist/src/ui/components/text.js.map +1 -0
  112. package/dist/src/ui/components/use-input.d.ts +12 -0
  113. package/dist/src/ui/components/use-input.js +21 -0
  114. package/dist/src/ui/components/use-input.js.map +1 -0
  115. package/dist/src/ui/footer/resolve-footer.d.ts +8 -0
  116. package/dist/src/ui/footer/resolve-footer.js +178 -0
  117. package/dist/src/ui/footer/resolve-footer.js.map +1 -0
  118. package/dist/src/ui/footer/types.d.ts +63 -0
  119. package/dist/src/ui/footer/types.js +2 -0
  120. package/dist/src/ui/footer/types.js.map +1 -0
  121. package/dist/src/ui/import/index.d.ts +7 -0
  122. package/dist/src/ui/import/index.js +7 -0
  123. package/dist/src/ui/import/index.js.map +1 -0
  124. package/dist/src/ui/import/review.d.ts +9 -0
  125. package/dist/src/ui/import/review.js +98 -0
  126. package/dist/src/ui/import/review.js.map +1 -0
  127. package/dist/src/ui/import/skill-select.d.ts +15 -0
  128. package/dist/src/ui/import/skill-select.js +219 -0
  129. package/dist/src/ui/import/skill-select.js.map +1 -0
  130. package/dist/src/ui/import/types.d.ts +13 -0
  131. package/dist/src/ui/import/types.js +2 -0
  132. package/dist/src/ui/import/types.js.map +1 -0
  133. package/dist/src/ui/install/index.d.ts +6 -0
  134. package/dist/src/ui/install/index.js +6 -0
  135. package/dist/src/ui/install/index.js.map +1 -0
  136. package/dist/src/ui/install/review.d.ts +10 -0
  137. package/dist/src/ui/install/review.js +134 -0
  138. package/dist/src/ui/install/review.js.map +1 -0
  139. package/dist/src/ui/install/types.d.ts +15 -0
  140. package/dist/src/ui/install/types.js +6 -0
  141. package/dist/src/ui/install/types.js.map +1 -0
  142. package/dist/src/ui/overlay/bridge.d.ts +29 -0
  143. package/dist/src/ui/overlay/bridge.js +34 -0
  144. package/dist/src/ui/overlay/bridge.js.map +1 -0
  145. package/dist/src/ui/overlay/dialogs.d.ts +6 -0
  146. package/dist/src/ui/overlay/dialogs.js +31 -0
  147. package/dist/src/ui/overlay/dialogs.js.map +1 -0
  148. package/dist/src/ui/overlay/host.d.ts +30 -0
  149. package/dist/src/ui/overlay/host.js +164 -0
  150. package/dist/src/ui/overlay/host.js.map +1 -0
  151. package/dist/src/ui/overlay/index.d.ts +11 -0
  152. package/dist/src/ui/overlay/index.js +11 -0
  153. package/dist/src/ui/overlay/index.js.map +1 -0
  154. package/dist/src/ui/overlay/slot.d.ts +20 -0
  155. package/dist/src/ui/overlay/slot.js +50 -0
  156. package/dist/src/ui/overlay/slot.js.map +1 -0
  157. package/dist/src/ui/overlay/static.d.ts +13 -0
  158. package/dist/src/ui/overlay/static.js +34 -0
  159. package/dist/src/ui/overlay/static.js.map +1 -0
  160. package/dist/src/ui/overlay/types.d.ts +57 -0
  161. package/dist/src/ui/overlay/types.js +2 -0
  162. package/dist/src/ui/overlay/types.js.map +1 -0
  163. package/dist/src/ui/prompts/index.d.ts +5 -0
  164. package/dist/src/ui/prompts/index.js +6 -0
  165. package/dist/src/ui/prompts/index.js.map +1 -0
  166. package/dist/src/ui/prompts/present.d.ts +29 -0
  167. package/dist/src/ui/prompts/present.js +71 -0
  168. package/dist/src/ui/prompts/present.js.map +1 -0
  169. package/dist/src/ui/search/index.d.ts +4 -0
  170. package/dist/src/ui/{search.js → search/index.js} +20 -8
  171. package/dist/src/ui/search/index.js.map +1 -0
  172. package/dist/src/ui/search/types.d.ts +9 -0
  173. package/dist/src/ui/search/types.js +2 -0
  174. package/dist/src/ui/search/types.js.map +1 -0
  175. package/dist/src/ui/shell/app-shell.d.ts +22 -0
  176. package/dist/src/ui/shell/app-shell.js +46 -0
  177. package/dist/src/ui/shell/app-shell.js.map +1 -0
  178. package/dist/src/ui/shell/footer.d.ts +7 -0
  179. package/dist/src/ui/shell/footer.js +38 -0
  180. package/dist/src/ui/shell/footer.js.map +1 -0
  181. package/dist/src/ui/shell/run.d.ts +41 -0
  182. package/dist/src/ui/shell/run.js +201 -0
  183. package/dist/src/ui/shell/run.js.map +1 -0
  184. package/dist/src/{contracts → ui/shell}/terminal.d.ts +1 -0
  185. package/dist/src/{contracts → ui/shell}/terminal.js +1 -0
  186. package/dist/src/ui/shell/terminal.js.map +1 -0
  187. package/dist/src/ui/skill-labels.d.ts +10 -0
  188. package/dist/src/ui/skill-labels.js +11 -0
  189. package/dist/src/ui/skill-labels.js.map +1 -0
  190. package/package.json +20 -17
  191. package/dist/src/commands/browser.d.ts +0 -3
  192. package/dist/src/commands/browser.js +0 -413
  193. package/dist/src/commands/browser.js.map +0 -1
  194. package/dist/src/contracts/browser.d.ts +0 -68
  195. package/dist/src/contracts/browser.js +0 -2
  196. package/dist/src/contracts/browser.js.map +0 -1
  197. package/dist/src/contracts/search.d.ts +0 -7
  198. package/dist/src/contracts/search.js +0 -2
  199. package/dist/src/contracts/search.js.map +0 -1
  200. package/dist/src/contracts/terminal.js.map +0 -1
  201. package/dist/src/ui/browser-state.d.ts +0 -11
  202. package/dist/src/ui/browser-state.js +0 -17
  203. package/dist/src/ui/browser-state.js.map +0 -1
  204. package/dist/src/ui/browser.d.ts +0 -32
  205. package/dist/src/ui/browser.js +0 -786
  206. package/dist/src/ui/browser.js.map +0 -1
  207. package/dist/src/ui/prompts.d.ts +0 -20
  208. package/dist/src/ui/prompts.js +0 -49
  209. package/dist/src/ui/prompts.js.map +0 -1
  210. package/dist/src/ui/reviews.d.ts +0 -47
  211. package/dist/src/ui/reviews.js +0 -390
  212. package/dist/src/ui/reviews.js.map +0 -1
  213. package/dist/src/ui/search.d.ts +0 -5
  214. package/dist/src/ui/search.js.map +0 -1
  215. package/dist/src/ui/session.d.ts +0 -11
  216. package/dist/src/ui/session.js +0 -104
  217. package/dist/src/ui/session.js.map +0 -1
  218. package/dist/src/ui/termcn.d.ts +0 -58
  219. package/dist/src/ui/termcn.js +0 -303
  220. package/dist/src/ui/termcn.js.map +0 -1
@@ -1,786 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, Text, useInput, useStdout } from 'ink';
3
- import { Provider, useAtom, useAtomValue } from 'jotai';
4
- import { useEffect, useMemo, useRef, useState } from 'react';
5
- import { matchesSkill } from '../domain/skill-query.js';
6
- import { browserNavigationAtom, browserSelectionAtom, createBrowserStore, } from './browser-state.js';
7
- import { Select, Tabs, TextInput, termcnColors } from './termcn.js';
8
- const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
9
- function charWidth(char) {
10
- const code = char.codePointAt(0) ?? 0;
11
- if (code === 0)
12
- return 0;
13
- if (code < 0x20 || (code >= 0x7f && code < 0xa0))
14
- return 0;
15
- return ((code >= 0x1100 && code <= 0x115f) ||
16
- code === 0x2329 ||
17
- code === 0x232a ||
18
- (code >= 0x2e80 && code <= 0xa4cf && code !== 0x303f) ||
19
- (code >= 0xac00 && code <= 0xd7a3) ||
20
- (code >= 0xf900 && code <= 0xfaff) ||
21
- (code >= 0xfe10 && code <= 0xfe19) ||
22
- (code >= 0xfe30 && code <= 0xfe6f) ||
23
- (code >= 0xff00 && code <= 0xff60) ||
24
- (code >= 0xffe0 && code <= 0xffe6) ||
25
- (code >= 0x1f300 && code <= 0x1f64f) ||
26
- (code >= 0x1f900 && code <= 0x1f9ff) ||
27
- (code >= 0x20000 && code <= 0x3fffd)) ? 2 : 1;
28
- }
29
- function textWidth(value) {
30
- return [...value].reduce((width, char) => width + charWidth(char), 0);
31
- }
32
- function sliceColumns(value, start, end) {
33
- let column = 0;
34
- let result = '';
35
- for (const char of value) {
36
- const width = charWidth(char);
37
- const next = column + width;
38
- if (next > start && column < end)
39
- result += char;
40
- column = next;
41
- if (column >= end)
42
- break;
43
- }
44
- return result;
45
- }
46
- function padColumns(value, width) {
47
- return `${value}${' '.repeat(Math.max(0, width - textWidth(value)))}`;
48
- }
49
- function wrapColumns(value, width) {
50
- if (!value)
51
- return [''];
52
- const lines = [];
53
- let line = '';
54
- let columns = 0;
55
- for (const char of value) {
56
- const charColumns = charWidth(char);
57
- if (line && columns + charColumns > width) {
58
- lines.push(line);
59
- line = '';
60
- columns = 0;
61
- }
62
- line += char;
63
- columns += charColumns;
64
- }
65
- if (line)
66
- lines.push(line);
67
- return lines;
68
- }
69
- function useSpinner(active) {
70
- const [index, setIndex] = useState(0);
71
- useEffect(() => {
72
- if (!active)
73
- return undefined;
74
- const timer = setInterval(() => {
75
- setIndex((value) => (value + 1) % spinnerFrames.length);
76
- }, 80);
77
- return () => clearInterval(timer);
78
- }, [active]);
79
- return spinnerFrames[index] ?? '⠋';
80
- }
81
- function skillGroups(skill) {
82
- return [...new Set(skill.tags?.length ? skill.tags : ['未分组'])];
83
- }
84
- function groupedRows(skills, query) {
85
- if (query.trim()) {
86
- return skills
87
- .filter((skill) => matchesSkill(skill, query))
88
- .map((skill) => ({ type: 'skill', group: skillGroups(skill).join(' · '), skill }));
89
- }
90
- const groups = new Map();
91
- for (const skill of skills) {
92
- for (const tag of skillGroups(skill)) {
93
- const group = groups.get(tag) ?? [];
94
- group.push(skill);
95
- groups.set(tag, group);
96
- }
97
- }
98
- const sorted = [...groups].sort(([left], [right]) => {
99
- if (left === right)
100
- return 0;
101
- return left === '未分组' ? 1 : right === '未分组' ? -1 : left.localeCompare(right);
102
- });
103
- if (sorted.length === 1 && sorted[0]?.[0] === '未分组') {
104
- return sorted[0][1].map((skill) => ({ type: 'skill', group: '', skill }));
105
- }
106
- const rows = [];
107
- for (const [name, group] of sorted) {
108
- rows.push({ type: 'group', name, skills: group });
109
- rows.push(...group.map((skill) => ({ type: 'skill', group: name, skill })));
110
- }
111
- return rows;
112
- }
113
- function flatRows(skills, query) {
114
- return skills
115
- .filter((skill) => matchesSkill(skill, query))
116
- .map((skill) => ({ type: 'skill', group: '', skill }));
117
- }
118
- function selectableSkills(row) {
119
- return row.type === 'group' ? row.skills : [row.skill];
120
- }
121
- function paneHeight(rowCount, viewportHeight) {
122
- const visibleRows = Math.max(3, Math.min(rowCount, viewportHeight));
123
- return visibleRows + (rowCount > viewportHeight ? 1 : 0);
124
- }
125
- export function browserFrameDimensions({ rows, columns, projectRows, globalRows, collectionRows, hasProjectAgents, hasGlobalAgents, }) {
126
- const listViewportHeight = Math.max(3, (rows ?? 24) - 10);
127
- const tabContentHeight = Math.max(paneHeight(projectRows, listViewportHeight) + (hasProjectAgents ? 1 : 0), paneHeight(globalRows, listViewportHeight) + (hasGlobalAgents ? 1 : 0), paneHeight(collectionRows, listViewportHeight));
128
- return {
129
- frameHeight: tabContentHeight + 2,
130
- frameWidth: columns ?? 80,
131
- listViewportHeight,
132
- };
133
- }
134
- export function detailFrameDimensions(frameHeight, frameWidth, terminalRows) {
135
- return {
136
- height: Math.min(frameHeight, Math.max(5, (terminalRows ?? 24) - 4)),
137
- width: frameWidth,
138
- };
139
- }
140
- function detailFieldLines(label, value, width, muted = false) {
141
- const labelText = `${label} `;
142
- const indentation = ' '.repeat(textWidth(labelText));
143
- const valueWidth = Math.max(1, width - textWidth(labelText));
144
- return value
145
- .split(/\r?\n/)
146
- .flatMap((paragraph) => wrapColumns(paragraph, valueWidth))
147
- .map((line, index) => index === 0
148
- ? { label: labelText, value: line, muted }
149
- : { value: `${indentation}${line}`, muted });
150
- }
151
- function detailContentLines(skill, metadata, links, collection, source, frameWidth) {
152
- const width = Math.max(1, frameWidth - 4);
153
- const lines = detailFieldLines('描述', skill.description || '无描述', width, true);
154
- if (!collection)
155
- return [...lines, ...detailFieldLines('位置', skill.path, width)];
156
- lines.push(...detailFieldLines('标签', metadata.tags.length ? metadata.tags.join(', ') : '无', width), ...detailFieldLines('备注', metadata.note || '无', width), ...detailFieldLines('来源', source, width));
157
- if (metadata.source.path)
158
- lines.push(...detailFieldLines('路径', metadata.source.path, width));
159
- lines.push({ label: '关联位置', value: '' });
160
- if (!links.length)
161
- return [...lines, { value: ' 无', muted: true }];
162
- return [
163
- ...lines,
164
- ...links.flatMap((link) => detailFieldLines(link.kind === 'origin' ? ' 原始' : link.kind === 'usage' ? ' 使用' : ' 依赖', link.path, width, true)),
165
- ];
166
- }
167
- function framedLines(title, content, width) {
168
- const inner = width - 4;
169
- const titleWidth = textWidth(title);
170
- const body = content
171
- .flatMap((line) => wrapColumns(line, inner))
172
- .map((line) => padColumns(line, inner));
173
- return [
174
- `╭─${title}${'─'.repeat(Math.max(0, width - titleWidth - 3))}╮`,
175
- ...body.map((line) => `│ ${line} │`),
176
- `╰${'─'.repeat(width - 2)}╯`,
177
- ];
178
- }
179
- function shortcutHelpLines(width) {
180
- const content = [
181
- '↑/↓ 移动焦点或列表项',
182
- '←/→ 切换当前层级 Tab;收藏夹内 → 查看详情',
183
- 'Space 选择当前项或当前分组',
184
- 'Enter 查看、添加或提交当前选择',
185
- '/ 搜索技能',
186
- 'g 跳转到分组(当前项目/收藏夹有分组时)',
187
- 'i 加入收藏夹(当前项目/全局已选择本地技能时)',
188
- 't 批量加标签(收藏夹已选择技能时)',
189
- 's 同步 Git(收藏夹可同步时)',
190
- 'u 更新可更新的已选技能;无选择时更新当前技能',
191
- 'd/Delete 删除已选技能;无选择时删除当前技能',
192
- 'm 更多操作(当前项目引用可转换时)',
193
- 'q 退出 · Esc 取消当前上下文',
194
- '',
195
- 'Esc 关闭',
196
- ];
197
- return framedLines(' 完整快捷键 ', content, width);
198
- }
199
- function moreActionLines(scope, width) {
200
- return framedLines(' 更多操作 ', [scope, '', '› 将引用转为副本'], width);
201
- }
202
- function confirmationLines(confirmation, width) {
203
- return framedLines(` ${confirmation.title} `, [
204
- confirmation.message,
205
- ...(confirmation.details?.length ? confirmation.details : []),
206
- '(y/N)',
207
- ], width);
208
- }
209
- function PopupLine({ line, index, last, muteLastContent, }) {
210
- if (index === 0 || index === last) {
211
- return _jsx(Text, { color: termcnColors.primary, children: line });
212
- }
213
- const content = line.slice(2, -2);
214
- return (_jsxs(Text, { children: [_jsx(Text, { color: termcnColors.primary, children: "\u2502 " }), muteLastContent && index === last - 1 ? (_jsx(Text, { color: termcnColors.muted, children: content })) : (content), _jsx(Text, { color: termcnColors.primary, children: " \u2502" })] }));
215
- }
216
- function SkillPane({ rows, cursor, isActive, showShortcuts = false, preferNote = false, showSource = false, showReferences = false, showGroup = false, updates = new Set(), updatingSkillName, overlayLines, overlayMuteLastContent = true, viewportHeight, }) {
217
- const { stdout } = useStdout();
218
- const selected = useAtomValue(browserSelectionAtom);
219
- const height = viewportHeight ?? Math.max(3, (stdout.rows ?? 24) - 8);
220
- const active = Math.max(0, Math.min(cursor, rows.length - 1));
221
- const offset = Math.max(0, Math.min(active - Math.floor(height / 2), rows.length - height));
222
- const visible = rows.slice(offset, offset + height);
223
- const popupLines = overlayLines ?? (showShortcuts ? shortcutHelpLines(Math.min(76, Math.max(36, (stdout.columns ?? 80) - 6))) : undefined);
224
- const popupHeight = popupLines?.length ?? 0;
225
- const compositeHeight = popupLines ? Math.max(visible.length, popupHeight) : visible.length;
226
- const popupTop = Math.max(0, Math.floor((compositeHeight - popupHeight) / 2));
227
- const paneWidth = Math.max(20, (stdout.columns ?? 80) - 4);
228
- const popupWidth = textWidth(popupLines?.[0] ?? '');
229
- const popupLeft = Math.max(0, Math.floor((paneWidth - popupWidth) / 2));
230
- const rowText = (row, index) => {
231
- if (row.type === 'group') {
232
- const groupSkills = row.skills;
233
- const count = groupSkills.filter((skill) => selected.has(skill.path)).length;
234
- const marker = count === 0 ? '○' : count === groupSkills.length && groupSkills.length ? '●' : '◐';
235
- return `${isActive && index === active ? '›' : ' '} ${marker} ${row.name} (${row.skills.length})`;
236
- }
237
- const skill = row.skill;
238
- const summary = (preferNote && skill.note) || skill.description;
239
- const selectionMarker = selected.has(skill.path) ? '●' : '○';
240
- const name = showReferences && skill.isReference
241
- ? `引用 · ${skill.name}`
242
- : showSource && !skill.fromCollection
243
- ? `本地 · ${skill.name}`
244
- : skill.name;
245
- const group = showGroup && row.group ? `${row.group} / ` : '';
246
- const update = updatingSkillName === skill.name ? ' 更新中' : updates.has(skill.name) ? ' ↑' : '';
247
- return ` ${isActive && index === active ? '›' : ' '} ${selectionMarker} ${group}${name}${update}${summary ? ` — ${summary}` : ''}`;
248
- };
249
- const renderRow = (row, index) => {
250
- if (row.type === 'group') {
251
- const groupSkills = row.skills;
252
- const count = groupSkills.filter((skill) => selected.has(skill.path)).length;
253
- const marker = count === 0 ? '○' : count === groupSkills.length && groupSkills.length ? '●' : '◐';
254
- return (_jsx(Text, { bold: true, ...(isActive && index === active ? { color: termcnColors.primary } : {}), children: `${isActive && index === active ? '›' : ' '} ${marker} ${row.name} (${row.skills.length})` }, `group:${row.name}:${index}`));
255
- }
256
- const skill = row.skill;
257
- const summary = (preferNote && skill.note) || skill.description;
258
- const selectionMarker = selected.has(skill.path) ? '●' : '○';
259
- return (_jsxs(Text, { wrap: "truncate-end", ...(isActive && index === active ? { color: termcnColors.primary } : {}), children: [` ${isActive && index === active ? '›' : ' '} ${selectionMarker} `, showGroup && row.group && (_jsxs(Text, { color: termcnColors.muted, children: [row.group, " / "] })), showReferences && skill.isReference ? (_jsxs(_Fragment, { children: [_jsx(Text, { color: termcnColors.muted, children: "\u5F15\u7528 \u00B7 " }), _jsx(Text, { bold: isActive && index === active, children: skill.name })] })) : showSource && !skill.fromCollection ? (`本地 · ${skill.name}`) : (_jsx(Text, { bold: isActive && index === active, children: skill.name })), updatingSkillName === skill.name ? (_jsx(Text, { color: termcnColors.primary, children: " \u66F4\u65B0\u4E2D" })) : updates.has(skill.name) ? (_jsx(Text, { color: termcnColors.primary, children: " \u2191" })) : null, summary && (_jsxs(Text, { color: termcnColors.muted, children: [" \u2014 ", summary] }))] }, `${row.group}:${skill.path}:${index}`));
260
- };
261
- const renderRows = () => {
262
- if (!popupLines) {
263
- return visible.map((row, visibleIndex) => renderRow(row, offset + visibleIndex));
264
- }
265
- return Array.from({ length: compositeHeight }, (_, visibleIndex) => {
266
- const row = visible[visibleIndex];
267
- const index = offset + visibleIndex;
268
- const popupIndex = visibleIndex - popupTop;
269
- const popupLine = popupLines[popupIndex];
270
- if (popupLine === undefined) {
271
- return row ? renderRow(row, index) : _jsx(Text, { children: " " }, `shortcut-empty:${visibleIndex}`);
272
- }
273
- const base = row ? rowText(row, index) : '';
274
- const prefix = padColumns(sliceColumns(base, 0, popupLeft), popupLeft);
275
- const suffix = sliceColumns(base, popupLeft + popupWidth, paneWidth);
276
- return (_jsxs(Text, { wrap: "truncate-end", children: [prefix, _jsx(PopupLine, { line: popupLine, index: popupIndex, last: popupLines.length - 1, muteLastContent: overlayLines ? overlayMuteLastContent : true }), suffix] }, `shortcut-overlay:${visibleIndex}`));
277
- });
278
- };
279
- return (_jsxs(Box, { flexDirection: "column", minHeight: 3, children: [rows.length || popupLines ? (renderRows()) : (_jsx(Text, { color: termcnColors.muted, children: "\u6CA1\u6709\u5339\u914D\u7684\u6280\u80FD" })), rows.length > height && (_jsxs(Text, { color: termcnColors.muted, children: [offset + 1, "\u2013", Math.min(offset + height, rows.length), " / ", rows.length] }))] }));
280
- }
281
- function AgentTabs({ groups, agent, focused, }) {
282
- return (_jsx(Box, { paddingLeft: 1, children: groups.map((group, index) => (_jsxs(Box, { children: [_jsxs(Text, { color: group.agent === agent ? termcnColors.primary : termcnColors.muted, bold: group.agent === agent, underline: group.agent === agent, inverse: focused && group.agent === agent, children: [group.agent, " (", group.skills.length, ")"] }), index < groups.length - 1 && _jsx(Text, { color: termcnColors.border, children: " \u2502 " })] }, group.agent))) }));
283
- }
284
- function visibleAgentGroups(groups) {
285
- return groups.filter((group) => group.skills.length > 0);
286
- }
287
- function BrowserContent({ projectGroups, collection, globalGroups, canSync, status, transientStatus, checkUpdates, updatingSkillName, updatingProgress, workingAction = '更新', confirmation, finish, }) {
288
- const [navigation, setNavigation] = useAtom(browserNavigationAtom);
289
- const { tab, query, cursor, agent, focus } = navigation;
290
- const [visibleStatus, setVisibleStatus] = useState(status);
291
- const visibleProjectGroups = useMemo(() => visibleAgentGroups(projectGroups), [projectGroups]);
292
- const visibleGlobalGroups = useMemo(() => visibleAgentGroups(globalGroups), [globalGroups]);
293
- const activeProjectAgent = visibleProjectGroups.some((group) => group.agent === agent)
294
- ? agent
295
- : visibleProjectGroups[0]?.agent ?? '';
296
- const activeGlobalAgent = visibleGlobalGroups.some((group) => group.agent === agent)
297
- ? agent
298
- : visibleGlobalGroups[0]?.agent ?? '';
299
- const activeAgent = tab === 'global' ? activeGlobalAgent : activeProjectAgent;
300
- const currentAgentGroups = tab === 'project' ? visibleProjectGroups : tab === 'global' ? visibleGlobalGroups : [];
301
- const hasAgentTabs = currentAgentGroups.length > 0;
302
- const project = projectGroups.flatMap((group) => group.skills);
303
- const projectGroup = visibleProjectGroups.find((group) => group.agent === activeProjectAgent) ??
304
- visibleProjectGroups[0];
305
- const projectRows = useMemo(() => groupedRows(projectGroup?.skills ?? [], query), [projectGroup, query]);
306
- const collectionRows = useMemo(() => groupedRows(collection, query), [collection, query]);
307
- const globalGroup = visibleGlobalGroups.find((group) => group.agent === activeGlobalAgent) ??
308
- visibleGlobalGroups[0];
309
- const globalRows = useMemo(() => flatRows(globalGroup?.skills ?? [], query), [globalGroup, query]);
310
- const rows = tab === 'project' ? projectRows : tab === 'global' ? globalRows : collectionRows;
311
- const cursorRef = useRef(cursor);
312
- cursorRef.current = cursor;
313
- const setTab = (value) => {
314
- setNavigation((current) => ({ ...current, tab: value }));
315
- };
316
- const setQuery = (value) => {
317
- setNavigation((current) => ({ ...current, query: value }));
318
- };
319
- const setAgent = (value) => {
320
- setNavigation((current) => ({ ...current, agent: value }));
321
- };
322
- const setFocus = (value) => {
323
- setNavigation((current) => ({ ...current, focus: value }));
324
- };
325
- const setCursor = (value) => {
326
- setNavigation((current) => {
327
- const cursor = typeof value === 'function' ? value(current.cursor) : value;
328
- cursorRef.current = cursor;
329
- return { ...current, cursor };
330
- });
331
- };
332
- const [searching, setSearching] = useState(false);
333
- const [choosingGroup, setChoosingGroup] = useState(false);
334
- const [showShortcuts, setShowShortcuts] = useState(false);
335
- const [showActions, setShowActions] = useState(false);
336
- const [removeConfirmation, setRemoveConfirmation] = useState();
337
- const [queryBeforeSearch, setQueryBeforeSearch] = useState(query);
338
- const [cursorBeforeSearch, setCursorBeforeSearch] = useState(0);
339
- const [selected, setSelected] = useAtom(browserSelectionAtom);
340
- const [updateCheck, setUpdateCheck] = useState({ checking: false, updates: new Set(), failed: 0 });
341
- const updateSpinner = useSpinner(Boolean(updatingSkillName));
342
- useEffect(() => {
343
- setVisibleStatus(status);
344
- if (!status || !transientStatus)
345
- return undefined;
346
- const timer = setTimeout(() => setVisibleStatus(''), 3500);
347
- return () => clearTimeout(timer);
348
- }, [status, transientStatus]);
349
- const selectedCollection = collection.filter((skill) => selected.has(skill.path));
350
- const selectedUpdates = selectedCollection.filter((skill) => updateCheck.updates.has(skill.name));
351
- const selectedProject = project.filter((skill) => selected.has(skill.path));
352
- const selectedGlobal = globalGroups.flatMap((group) => group.skills.filter((skill) => selected.has(skill.path)));
353
- const selectedProjectLocal = project.filter((skill) => selected.has(skill.path) && !skill.fromCollection);
354
- const selectedGlobalLocal = globalGroups.flatMap((group) => group.skills.filter((skill) => selected.has(skill.path) && !skill.fromCollection));
355
- const currentRow = rows[cursor];
356
- const actionSkills = tab === 'project'
357
- ? selectedProject.length
358
- ? selectedProject
359
- : currentRow?.type === 'skill'
360
- ? [currentRow.skill]
361
- : []
362
- : [];
363
- const canOpenActions = !updatingSkillName &&
364
- focus === 'list' &&
365
- actionSkills.length > 0 &&
366
- actionSkills.every((skill) => skill.isReference);
367
- const groupRows = useMemo(() => groupedRows(tab === 'project' ? project : collection, ''), [collection, project, tab]);
368
- const groups = groupRows.filter((row) => row.type === 'group');
369
- const previousTab = useRef(tab);
370
- useEffect(() => {
371
- if (previousTab.current !== tab) {
372
- setCursor(0);
373
- setSelected(new Set());
374
- previousTab.current = tab;
375
- }
376
- }, [tab]);
377
- const previousAgent = useRef(agent);
378
- useEffect(() => {
379
- if (previousAgent.current !== agent) {
380
- setCursor(0);
381
- previousAgent.current = agent;
382
- }
383
- }, [agent]);
384
- useEffect(() => {
385
- if (focus === 'agents' && !hasAgentTabs)
386
- setFocus('list');
387
- }, [focus, hasAgentTabs]);
388
- const checkedUpdates = useRef(false);
389
- useEffect(() => {
390
- if (tab !== 'collection' || checkedUpdates.current)
391
- return;
392
- checkedUpdates.current = true;
393
- let active = true;
394
- setUpdateCheck((current) => ({ ...current, checking: true }));
395
- void checkUpdates(collection)
396
- .then(({ updates, failed }) => {
397
- if (active)
398
- setUpdateCheck({ checking: false, updates, failed });
399
- })
400
- .catch(() => {
401
- if (active)
402
- setUpdateCheck({ checking: false, updates: new Set(), failed: collection.length });
403
- });
404
- return () => {
405
- active = false;
406
- };
407
- }, [checkUpdates, collection, tab]);
408
- const browserState = () => ({
409
- tab,
410
- query,
411
- cursor: cursorRef.current,
412
- selected: [...selected],
413
- agent: activeAgent,
414
- focus,
415
- });
416
- const openDetail = (skill, collection) => finish({
417
- ...browserState(),
418
- type: 'open',
419
- skill,
420
- collection,
421
- frameHeight: frame.frameHeight,
422
- frameWidth: frame.frameWidth,
423
- });
424
- const localConfirmation = removeConfirmation
425
- ? removeConfirmation.scope === 'collection'
426
- ? {
427
- title: '删除收藏',
428
- message: removeConfirmation.skills.length === 1
429
- ? `从收藏夹移除 ${removeConfirmation.skills[0]?.name ?? ''} 吗?`
430
- : `从收藏夹移除 ${removeConfirmation.skills.length} 个技能吗?`,
431
- details: removeConfirmation.skills.length > 1
432
- ? [`技能:${removeConfirmation.skills.map((skill) => skill.name).join(', ')}`]
433
- : [],
434
- onConfirm: () => finish({
435
- ...browserState(),
436
- type: 'removeCollection',
437
- skills: removeConfirmation.skills,
438
- }),
439
- onCancel: () => setRemoveConfirmation(undefined),
440
- }
441
- : {
442
- title: '删除技能',
443
- message: removeConfirmation.skills.length === 1
444
- ? `删除 ${removeConfirmation.skills[0]?.name ?? ''} 的当前位置吗?`
445
- : `删除所选 ${removeConfirmation.skills.length} 个技能位置吗?`,
446
- details: [
447
- '将永久删除以下位置;收藏夹内容(如有)保留。',
448
- ...removeConfirmation.skills.map((skill) => skill.path),
449
- ],
450
- onConfirm: () => finish({
451
- ...browserState(),
452
- type: 'removeLocations',
453
- skills: removeConfirmation.skills,
454
- }),
455
- onCancel: () => setRemoveConfirmation(undefined),
456
- }
457
- : undefined;
458
- const activeConfirmation = confirmation ?? localConfirmation;
459
- const { stdout } = useStdout();
460
- const frame = browserFrameDimensions({
461
- rows: stdout.rows,
462
- columns: stdout.columns,
463
- projectRows: projectRows.length,
464
- globalRows: globalRows.length,
465
- collectionRows: collectionRows.length,
466
- hasProjectAgents: visibleProjectGroups.length > 0,
467
- hasGlobalAgents: visibleGlobalGroups.length > 0,
468
- });
469
- const overlayLines = activeConfirmation
470
- ? confirmationLines(activeConfirmation, Math.min(76, Math.max(36, (stdout.columns ?? 80) - 6)))
471
- : showActions
472
- ? moreActionLines(selectedProject.length
473
- ? `已选择 ${actionSkills.length} 个技能`
474
- : `技能:${actionSkills[0]?.name ?? ''}`, Math.min(64, Math.max(36, (stdout.columns ?? 80) - 6)))
475
- : undefined;
476
- useInput((input, key) => {
477
- const choice = input.trim().toLowerCase();
478
- if (choice === 'y')
479
- return activeConfirmation?.onConfirm();
480
- if (choice === 'n' || key.return || key.escape) {
481
- return activeConfirmation?.onCancel();
482
- }
483
- }, { isActive: Boolean(activeConfirmation) });
484
- useInput((input, key) => {
485
- if (key.escape)
486
- return setShowActions(false);
487
- if (key.return || input.includes('\r') || input.includes('\n')) {
488
- return finish({ ...browserState(), type: 'materialize', skills: actionSkills });
489
- }
490
- }, { isActive: showActions && !activeConfirmation });
491
- useInput((input, key) => {
492
- if (key.escape) {
493
- setShowShortcuts(false);
494
- }
495
- }, { isActive: showShortcuts && !activeConfirmation });
496
- useInput((input, key) => {
497
- if (input === '?')
498
- return setShowShortcuts(true);
499
- if (key.escape || input === 'q')
500
- return finish({ type: 'quit' });
501
- if (input === '/') {
502
- setQueryBeforeSearch(query);
503
- setCursorBeforeSearch(cursorRef.current);
504
- return setSearching(true);
505
- }
506
- if (input === 'g' && tab !== 'global' && groups.length) {
507
- return setChoosingGroup(true);
508
- }
509
- if (input === 's' && tab === 'collection' && canSync) {
510
- return finish({ ...browserState(), type: 'sync' });
511
- }
512
- if (focus === 'tabs') {
513
- if (key.downArrow)
514
- return setFocus(hasAgentTabs ? 'agents' : 'list');
515
- if (key.leftArrow || key.rightArrow) {
516
- const order = ['project', 'global', 'collection'];
517
- const index = order.indexOf(tab);
518
- const next = order[index + (key.leftArrow ? -1 : 1)];
519
- if (next)
520
- setTab(next);
521
- }
522
- return;
523
- }
524
- if (focus === 'agents') {
525
- if (key.upArrow)
526
- return setFocus('tabs');
527
- if (key.downArrow)
528
- return setFocus('list');
529
- if (key.leftArrow || key.rightArrow) {
530
- const names = currentAgentGroups.map((group) => group.agent);
531
- const index = names.indexOf(activeAgent);
532
- const next = names[index + (key.leftArrow ? -1 : 1)];
533
- if (next)
534
- setAgent(next);
535
- }
536
- return;
537
- }
538
- const row = rows[cursorRef.current];
539
- if (input === 'm' && canOpenActions)
540
- return setShowActions(true);
541
- if (input === 'u' && tab === 'collection') {
542
- const updateable = selectedCollection.length
543
- ? selectedUpdates
544
- : row?.type === 'skill' && updateCheck.updates.has(row.skill.name)
545
- ? [row.skill]
546
- : [];
547
- if (updateable.length) {
548
- return finish({ ...browserState(), type: 'update', skills: updateable });
549
- }
550
- }
551
- if (input === 't' && tab === 'collection' && selectedCollection.length) {
552
- return finish({ ...browserState(), type: 'tags', skills: selectedCollection });
553
- }
554
- const removableCollection = tab === 'collection'
555
- ? selectedCollection.length
556
- ? selectedCollection
557
- : row?.type === 'skill'
558
- ? [row.skill]
559
- : []
560
- : [];
561
- const removableLocations = tab === 'project'
562
- ? selectedProject.length
563
- ? selectedProject
564
- : row?.type === 'skill'
565
- ? [row.skill]
566
- : []
567
- : tab === 'global'
568
- ? selectedGlobal.length
569
- ? selectedGlobal
570
- : row?.type === 'skill'
571
- ? [row.skill]
572
- : []
573
- : [];
574
- if ((input === 'd' || key.delete) && removableCollection.length) {
575
- setShowShortcuts(false);
576
- return setRemoveConfirmation({ scope: 'collection', skills: removableCollection });
577
- }
578
- if ((input === 'd' || key.delete) && removableLocations.length) {
579
- setShowShortcuts(false);
580
- return setRemoveConfirmation({ scope: 'location', skills: removableLocations });
581
- }
582
- const selectedLocal = tab === 'project' ? selectedProjectLocal : selectedGlobalLocal;
583
- if (input === 'i' && tab !== 'collection' && selectedLocal.length) {
584
- return finish({ ...browserState(), type: 'import', skills: selectedLocal });
585
- }
586
- if (key.upArrow) {
587
- if (cursorRef.current === 0)
588
- return setFocus(hasAgentTabs ? 'agents' : 'tabs');
589
- return setCursor((index) => index - 1);
590
- }
591
- if (key.downArrow) {
592
- return setCursor((index) => Math.min(Math.max(0, rows.length - 1), index + 1));
593
- }
594
- if (input === ' ' && row) {
595
- const paths = selectableSkills(row).map((skill) => skill.path);
596
- if (!paths.length)
597
- return;
598
- return setSelected((previous) => {
599
- const next = new Set(previous);
600
- const allSelected = paths.every((path) => previous.has(path));
601
- for (const path of paths)
602
- allSelected ? next.delete(path) : next.add(path);
603
- return next;
604
- });
605
- }
606
- if (key.rightArrow && row?.type === 'skill') {
607
- if (tab === 'collection')
608
- return openDetail(row.skill, true);
609
- if (row.skill.fromCollection)
610
- return openDetail(row.skill, true);
611
- }
612
- if (key.return || input.includes('\r') || input.includes('\n')) {
613
- if (tab === 'collection' && selectedCollection.length) {
614
- return finish({ ...browserState(), type: 'add', skills: selectedCollection });
615
- }
616
- if (tab !== 'collection') {
617
- if (row?.type === 'skill')
618
- openDetail(row.skill, false);
619
- }
620
- }
621
- }, {
622
- isActive: !searching &&
623
- !choosingGroup &&
624
- !showShortcuts &&
625
- !showActions &&
626
- !updatingSkillName &&
627
- !activeConfirmation,
628
- });
629
- useInput((input, key) => {
630
- if (key.escape || input === 'q') {
631
- setChoosingGroup(false);
632
- }
633
- }, { isActive: choosingGroup });
634
- const tabs = [
635
- {
636
- key: 'project',
637
- label: `当前项目 ${project.length}`,
638
- content: (_jsxs(Box, { flexDirection: "column", minHeight: frame.frameHeight - 2, children: [_jsx(AgentTabs, { groups: visibleProjectGroups, agent: activeProjectAgent, focused: focus === 'agents' }), _jsx(SkillPane, { rows: projectRows, cursor: cursor, isActive: focus === 'list', viewportHeight: frame.listViewportHeight, showShortcuts: showShortcuts, overlayLines: overlayLines, overlayMuteLastContent: Boolean(activeConfirmation), showSource: true, showReferences: true, showGroup: Boolean(query.trim()) })] })),
639
- },
640
- {
641
- key: 'global',
642
- label: `全局 ${globalGroups.reduce((count, group) => count + group.skills.length, 0)}`,
643
- content: (_jsxs(Box, { flexDirection: "column", minHeight: frame.frameHeight - 2, children: [_jsx(AgentTabs, { groups: visibleGlobalGroups, agent: activeGlobalAgent, focused: focus === 'agents' }), _jsx(SkillPane, { rows: globalRows, cursor: cursor, isActive: focus === 'list', viewportHeight: frame.listViewportHeight, showShortcuts: showShortcuts, overlayLines: overlayLines, overlayMuteLastContent: Boolean(activeConfirmation), showSource: true })] })),
644
- },
645
- {
646
- key: 'collection',
647
- label: `收藏夹 ${collection.length}`,
648
- content: (_jsx(Box, { flexDirection: "column", minHeight: frame.frameHeight - 2, children: _jsx(SkillPane, { rows: collectionRows, cursor: cursor, isActive: focus === 'list', viewportHeight: frame.listViewportHeight, showShortcuts: showShortcuts, overlayLines: overlayLines, overlayMuteLastContent: Boolean(activeConfirmation), preferNote: true, showGroup: Boolean(query.trim()), updates: updateCheck.updates, updatingSkillName: updatingSkillName }) })),
649
- },
650
- ];
651
- if (choosingGroup) {
652
- return (_jsx(Select, { label: "\u8DF3\u8F6C\u5230\u5206\u7EC4\uFF1A", numbered: true, options: groups.map((group) => ({
653
- label: `${group.name} (${group.skills.length})`,
654
- value: group.name,
655
- })), onSubmit: (name) => {
656
- setQuery('');
657
- setCursor(groupRows.findIndex((row) => row.type === 'group' && row.name === name));
658
- setFocus('list');
659
- setChoosingGroup(false);
660
- } }));
661
- }
662
- const canViewWithRightArrow = currentRow?.type === 'skill' && (tab === 'collection' || currentRow.skill.fromCollection);
663
- const canViewWithEnter = currentRow?.type === 'skill' && tab !== 'collection' && !canViewWithRightArrow;
664
- const canDelete = (tab === 'collection' && selectedCollection.length > 0) ||
665
- (tab === 'project' && selectedProject.length > 0) ||
666
- (tab === 'global' && selectedGlobal.length > 0) ||
667
- currentRow?.type === 'skill';
668
- const actions = updatingSkillName ? [] : [
669
- canOpenActions ? 'm 更多操作' : '',
670
- tab === 'project' && selectedProjectLocal.length ? 'i 加入收藏夹' : '',
671
- tab === 'global' && selectedGlobalLocal.length ? 'i 加入收藏夹' : '',
672
- tab === 'collection' && selectedCollection.length ? 'Enter 添加 · t 批量加标签' : '',
673
- tab === 'collection' && !updatingSkillName && selectedCollection.length && selectedUpdates.length
674
- ? `u 更新可更新的已选技能 (${selectedUpdates.length})`
675
- : tab === 'collection' && !updatingSkillName && !selectedCollection.length
676
- && currentRow?.type === 'skill' && updateCheck.updates.has(currentRow.skill.name)
677
- ? 'u 更新当前技能'
678
- : '',
679
- ].filter(Boolean);
680
- const activity = [
681
- updatingSkillName
682
- ? `${updateSpinner} 正在${workingAction}${updatingProgress &&
683
- (workingAction === '转换' || updatingProgress.total > 1)
684
- ? ` ${updatingProgress.current}/${updatingProgress.total}`
685
- : ''}:${updatingSkillName}`
686
- : '',
687
- updateCheck.checking ? '正在检查更新…' : '',
688
- !updateCheck.checking && updateCheck.failed ? `${updateCheck.failed} 个技能检查失败` : '',
689
- visibleStatus,
690
- query ? `搜索:${query}` : '',
691
- ].filter(Boolean);
692
- return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Tabs, { tabs: tabs, activeTab: tab, onTabChange: (key) => setTab(key), isActive: !searching && !showShortcuts && !showActions && focus === 'tabs', enableArrowNav: false, focused: !searching && !showShortcuts && focus === 'tabs' }), searching ? (_jsx(TextInput, { label: "\u641C\u7D22\u6280\u80FD\uFF08Enter \u786E\u8BA4\uFF0CEsc \u53D6\u6D88\uFF09", initialValue: query, onChange: (value) => {
693
- setQuery(value);
694
- setCursor(0);
695
- }, onCancel: () => {
696
- setQuery(queryBeforeSearch);
697
- setCursor(cursorBeforeSearch);
698
- setSearching(false);
699
- }, onSubmit: (value) => {
700
- setQuery(value);
701
- setSearching(false);
702
- } })) : (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: termcnColors.muted, wrap: "truncate-end", children: updatingSkillName
703
- ? `正在${workingAction} · 请稍候`
704
- : activeConfirmation
705
- ? '等待确认'
706
- : showActions
707
- ? 'Enter 执行 · Esc 返回'
708
- : showShortcuts
709
- ? 'Esc 关闭'
710
- : focus === 'tabs'
711
- ? '←/→ 切换 Tab · ↓ 进入 · / 搜索 · ? 快捷键 · q 退出'
712
- : focus === 'agents'
713
- ? '←/→ 切换 Agent · ↑ 返回 · ↓ 进入 · / 搜索 · ? 快捷键 · q 退出'
714
- : canViewWithRightArrow
715
- ? '→ 查看 · d 删除 · / 搜索 · ? 快捷键 · q 退出'
716
- : canViewWithEnter
717
- ? 'Enter 查看 · d 删除 · / 搜索 · ? 快捷键 · q 退出'
718
- : canDelete
719
- ? 'd 删除 · / 搜索 · ? 快捷键 · q 退出'
720
- : '/ 搜索 · ? 快捷键 · q 退出' }), (selected.size > 0 || actions.length > 0) && (_jsxs(_Fragment, { children: [_jsx(Text, { children: " " }), _jsx(Text, { color: termcnColors.muted, wrap: "truncate-end", children: [selected.size ? `已选 ${selected.size}` : '', ...actions].filter(Boolean).join(' · ') })] })), activity.length > 0 && (_jsx(Text, { color: updateCheck.failed ? termcnColors.error : termcnColors.muted, wrap: "truncate-end", children: activity.join(' · ') }))] }))] }));
721
- }
722
- function Browser({ state, ...props }) {
723
- const [store] = useState(() => {
724
- const agents = [...props.projectGroups, ...props.globalGroups]
725
- .filter((group) => group.skills.length > 0)
726
- .map((group) => group.agent);
727
- const agent = agents.includes(state.agent) ? state.agent : agents[0] ?? '';
728
- return createBrowserStore({ ...state, agent });
729
- });
730
- return (_jsx(Provider, { store: store, children: _jsx(BrowserContent, { ...props }) }));
731
- }
732
- function Detail({ skill, metadata, links, collection, frameHeight, frameWidth, finish, }) {
733
- const { stdout } = useStdout();
734
- const detailFrame = detailFrameDimensions(frameHeight, frameWidth, stdout.rows);
735
- const [detailOffset, setDetailOffset] = useState(0);
736
- const source = metadata.source.url
737
- ? `${metadata.source.url}${metadata.source.ref ? ` @ ${metadata.source.ref}` : ''}`
738
- : metadata.source.type;
739
- const lines = detailContentLines(skill, metadata, links, collection, source, detailFrame.width);
740
- const viewportHeight = Math.max(1, detailFrame.height - 2);
741
- const maxOffset = Math.max(0, lines.length - viewportHeight);
742
- const offset = Math.min(detailOffset, maxOffset);
743
- const visibleLines = lines.slice(offset, offset + viewportHeight);
744
- useInput((input, key) => {
745
- if (key.upArrow && maxOffset) {
746
- setDetailOffset((current) => Math.max(0, current - 1));
747
- return;
748
- }
749
- if (key.downArrow && maxOffset) {
750
- setDetailOffset((current) => Math.min(maxOffset, current + 1));
751
- return;
752
- }
753
- if (key.escape ||
754
- key.leftArrow ||
755
- input === 'b' ||
756
- input === 'q') {
757
- return finish('back');
758
- }
759
- if (collection && input === 'n')
760
- return finish('note');
761
- if (collection && input === 't')
762
- return finish('tags');
763
- if (collection && input === 's')
764
- return finish('source');
765
- });
766
- return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: termcnColors.primary, bold: true, children: ["\u2039 ", skill.name] }), _jsx(Box, { flexDirection: "column", borderStyle: "round", borderColor: termcnColors.border, paddingX: 1, height: detailFrame.height, width: detailFrame.width, overflow: "hidden", children: visibleLines.map((line, index) => (_jsxs(Text, { ...(line.muted ? { color: termcnColors.muted } : {}), children: [line.label && _jsx(Text, { bold: true, children: line.label }), line.value] }, `${offset + index}:${line.label ?? ''}:${line.value}`))) }), _jsx(Text, { color: termcnColors.muted, children: `${maxOffset ? '↑/↓ 滚动 · ' : ''}${collection ? 'n 备注 · t 标签 · s 来源 · Esc 返回' : 'Esc 返回'}` })] }));
767
- }
768
- export function browseSkillDetail(skill, metadata, links, collection, frameHeight, frameWidth, session) {
769
- return session.show('back', (finish) => (_jsx(Detail, { skill: skill, metadata: metadata, links: links, collection: collection, frameHeight: frameHeight, frameWidth: frameWidth, finish: finish })), false);
770
- }
771
- export function browseSkills(input, session) {
772
- return session.show({ type: 'quit' }, (finish) => (_jsx(Browser, { ...input, finish: finish })), false);
773
- }
774
- export function confirmBrowseAction(input, session, { message, details = [], title = '确认' }) {
775
- return session.show(false, (finish) => (_jsx(Browser, { ...input, confirmation: {
776
- title,
777
- message,
778
- details,
779
- onConfirm: () => finish(true),
780
- onCancel: () => finish(false),
781
- }, finish: () => undefined })), false);
782
- }
783
- export function displayBrowseSkills(input, session, onInterrupt) {
784
- session.display(_jsx(Browser, { ...input, finish: () => undefined }), onInterrupt);
785
- }
786
- //# sourceMappingURL=browser.js.map