@copylee/dsh-computer-use 0.13.0 → 0.14.0

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/helper/Uia.cs CHANGED
@@ -112,25 +112,218 @@ namespace DshComputerUse
112
112
  if (!target.Current.IsEnabled)
113
113
  throw new Exception("The named target is disabled");
114
114
  object pattern = null;
115
- if (action == "invoke" && !target.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) return result;
116
- if (action == "focus" && !target.Current.IsKeyboardFocusable) return result;
117
- if (action != "invoke" && action != "focus") return result;
115
+ if (action == "invoke")
116
+ {
117
+ if (!target.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) return result;
118
+ }
119
+ else if (action == "focus")
120
+ {
121
+ if (!target.Current.IsKeyboardFocusable) return result;
122
+ }
123
+ else if (action == "set_checked")
124
+ {
125
+ if (!target.TryGetCurrentPattern(TogglePattern.Pattern, out pattern)) return result;
126
+ }
127
+ else if (action == "expand" || action == "collapse")
128
+ {
129
+ if (!target.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) return result;
130
+ }
131
+ else if (action == "select")
132
+ {
133
+ if (!target.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) return result;
134
+ }
135
+ else if (action == "set_value")
136
+ {
137
+ if (IsPasswordElement(target)) throw new Exception("Refused to set value on a password field");
138
+ if (!target.TryGetCurrentPattern(ValuePattern.Pattern, out pattern)) return result;
139
+ if (((ValuePattern)pattern).Current.IsReadOnly) throw new Exception("The named target is read-only");
140
+ }
141
+ else return result;
142
+
118
143
  if (!IsActionWindow(hwnd, pid, point))
119
144
  throw new Exception("The named target window changed");
120
145
 
121
146
  // A provider error after dispatch is indeterminate. Let it surface
122
147
  // rather than claiming the host can safely click again.
123
- if (action == "invoke") ((InvokePattern)pattern).Invoke();
124
- else
148
+ if (action == "invoke")
149
+ {
150
+ ((InvokePattern)pattern).Invoke();
151
+ }
152
+ else if (action == "focus")
125
153
  {
126
154
  target.SetFocus();
127
155
  for (int i = 0; i < 10 && !target.Current.HasKeyboardFocus; i++) Thread.Sleep(25);
128
156
  if (!target.Current.HasKeyboardFocus) throw new Exception("Could not verify focus on the named control");
129
157
  }
158
+ else if (action == "set_checked")
159
+ {
160
+ bool want = Args.Bool(r, "checked", true);
161
+ var tp = (TogglePattern)pattern;
162
+ bool isOn = tp.Current.ToggleState == ToggleState.On;
163
+ if (isOn != want) tp.Toggle();
164
+ result["changed"] = isOn != want;
165
+ result["checked"] = want;
166
+ }
167
+ else if (action == "expand" || action == "collapse")
168
+ {
169
+ var ec = (ExpandCollapsePattern)pattern;
170
+ var cur = ec.Current.ExpandCollapseState;
171
+ bool wantExpand = action == "expand";
172
+ bool already = wantExpand ? (cur == ExpandCollapseState.Expanded) : (cur == ExpandCollapseState.Collapsed);
173
+ if (!already)
174
+ {
175
+ if (wantExpand) ec.Expand();
176
+ else ec.Collapse();
177
+ }
178
+ result["changed"] = !already;
179
+ }
180
+ else if (action == "select")
181
+ {
182
+ var sp = (SelectionItemPattern)pattern;
183
+ bool already = sp.Current.IsSelected;
184
+ if (!already) sp.Select();
185
+ result["changed"] = !already;
186
+ }
187
+ else if (action == "set_value")
188
+ {
189
+ string val = Args.Str(r, "value", "");
190
+ ((ValuePattern)pattern).SetValue(val);
191
+ result["changed"] = true;
192
+ }
130
193
  result["performed"] = true;
131
194
  return result;
132
195
  }
133
196
 
197
+ static ControlType ControlTypeByName(string role)
198
+ {
199
+ if (string.IsNullOrEmpty(role)) return null;
200
+ string k = role.Trim().ToLowerInvariant();
201
+ if (k == "button") return ControlType.Button;
202
+ if (k == "edit" || k == "textbox" || k == "input") return ControlType.Edit;
203
+ if (k == "hyperlink" || k == "link") return ControlType.Hyperlink;
204
+ if (k == "menuitem") return ControlType.MenuItem;
205
+ if (k == "listitem") return ControlType.ListItem;
206
+ if (k == "tabitem" || k == "tab") return ControlType.TabItem;
207
+ if (k == "checkbox") return ControlType.CheckBox;
208
+ if (k == "radiobutton" || k == "radio") return ControlType.RadioButton;
209
+ if (k == "combobox") return ControlType.ComboBox;
210
+ if (k == "treeitem") return ControlType.TreeItem;
211
+ if (k == "text") return ControlType.Text;
212
+ if (k == "document") return ControlType.Document;
213
+ if (k == "slider") return ControlType.Slider;
214
+ if (k == "dataitem") return ControlType.DataItem;
215
+ return null;
216
+ }
217
+
218
+ /**
219
+ * Targeted UIA lookup in C#: pushes AutomationId / ControlType / Name
220
+ * predicates down into UI Automation so matching a control avoids
221
+ * serializing hundreds of unrelated nodes across stdio.
222
+ */
223
+ public static object Find(Dictionary<string, object> r)
224
+ {
225
+ IntPtr hwnd = Args.Has(r, "hwnd") ? new IntPtr(Convert.ToInt64(r["hwnd"])) : Native.GetForegroundWindow();
226
+ string automationId = Args.Str(r, "automationId", "").Trim();
227
+ string role = Args.Str(r, "role", "").Trim();
228
+ string exactName = Args.Str(r, "name", "").Trim();
229
+ string query = Args.Str(r, "query", "").Trim();
230
+ int maxMatches = Math.Max(1, Math.Min(120, Args.Int(r, "maxMatches", 24)));
231
+ List<object> result = null;
232
+ Exception error = null;
233
+
234
+ var worker = new Thread(delegate ()
235
+ {
236
+ try
237
+ {
238
+ WakeAccessibility(hwnd);
239
+ var conds = new List<Condition>();
240
+ conds.Add(new PropertyCondition(AutomationElement.IsOffscreenProperty, false));
241
+ var ct = ControlTypeByName(role);
242
+ if (ct != null) conds.Add(new PropertyCondition(AutomationElement.ControlTypeProperty, ct));
243
+ if (automationId.Length > 0) conds.Add(new PropertyCondition(AutomationElement.AutomationIdProperty, automationId));
244
+ if (exactName.Length > 0) conds.Add(new PropertyCondition(AutomationElement.NameProperty, exactName));
245
+ Condition cond = conds.Count == 1 ? conds[0] : new AndCondition(conds.ToArray());
246
+
247
+ var cache = new CacheRequest();
248
+ cache.Add(AutomationElement.NameProperty);
249
+ cache.Add(AutomationElement.ControlTypeProperty);
250
+ cache.Add(AutomationElement.ClassNameProperty);
251
+ cache.Add(AutomationElement.AutomationIdProperty);
252
+ cache.Add(AutomationElement.RuntimeIdProperty);
253
+ cache.Add(AutomationElement.BoundingRectangleProperty);
254
+ cache.Add(AutomationElement.IsEnabledProperty);
255
+ cache.Add(AutomationElement.IsKeyboardFocusableProperty);
256
+ cache.Add(AutomationElement.IsPasswordProperty);
257
+ cache.Add(AutomationElement.NativeWindowHandleProperty);
258
+ cache.Add(ValuePattern.ValueProperty);
259
+ cache.Add(TogglePattern.ToggleStateProperty);
260
+ cache.AutomationElementMode = AutomationElementMode.None;
261
+ cache.TreeScope = TreeScope.Element;
262
+
263
+ var root = AutomationElement.FromHandle(hwnd);
264
+ AutomationElementCollection found;
265
+ using (cache.Activate()) { found = root.FindAll(TreeScope.Descendants, cond); }
266
+
267
+ var list = new List<object>();
268
+ string qLower = query.ToLowerInvariant();
269
+ foreach (AutomationElement el in found)
270
+ {
271
+ if (list.Count >= maxMatches) break;
272
+ var rect = (System.Windows.Rect)el.GetCachedPropertyValue(AutomationElement.BoundingRectangleProperty);
273
+ if (rect.IsEmpty || rect.Width < 2 || rect.Height < 2) continue;
274
+ var type = (ControlType)el.GetCachedPropertyValue(AutomationElement.ControlTypeProperty);
275
+ string elName = (el.GetCachedPropertyValue(AutomationElement.NameProperty) as string) ?? "";
276
+ string elAid = (el.GetCachedPropertyValue(AutomationElement.AutomationIdProperty) as string) ?? "";
277
+ if (qLower.Length > 0
278
+ && elName.ToLowerInvariant().IndexOf(qLower, StringComparison.Ordinal) < 0
279
+ && elAid.ToLowerInvariant().IndexOf(qLower, StringComparison.Ordinal) < 0)
280
+ continue;
281
+
282
+ bool isPwd = false;
283
+ try
284
+ {
285
+ object pwdProp = el.GetCachedPropertyValue(AutomationElement.IsPasswordProperty, true);
286
+ if (pwdProp is bool && (bool)pwdProp) isPwd = true;
287
+ if (!isPwd)
288
+ {
289
+ object nhProp = el.GetCachedPropertyValue(AutomationElement.NativeWindowHandleProperty, true);
290
+ if (nhProp is int && (int)nhProp != 0 && IsWin32PasswordHwnd(new IntPtr((int)nhProp))) isPwd = true;
291
+ }
292
+ }
293
+ catch (Exception) { }
294
+
295
+ var d = new Dictionary<string, object>();
296
+ d["role"] = type.ProgrammaticName.Replace("ControlType.", "");
297
+ if (isPwd) d["password"] = true;
298
+ d["name"] = elName.Length > 120 ? elName.Substring(0, 120) + "…" : elName;
299
+ if (elAid.Length > 0) d["automationId"] = elAid;
300
+ var runtimeId = el.GetCachedPropertyValue(AutomationElement.RuntimeIdProperty, true) as int[];
301
+ if (runtimeId != null && runtimeId.Length > 0) d["runtimeId"] = String.Join(",", runtimeId);
302
+ d["focusable"] = (bool)el.GetCachedPropertyValue(AutomationElement.IsKeyboardFocusableProperty);
303
+ object value = el.GetCachedPropertyValue(ValuePattern.ValueProperty, true);
304
+ if (isPwd) d["value"] = "[password]";
305
+ else if (value is string && ((string)value).Length > 0) { var v = (string)value; d["value"] = v.Length > 120 ? v.Substring(0, 120) + "…" : v; }
306
+ object toggle = el.GetCachedPropertyValue(TogglePattern.ToggleStateProperty, true);
307
+ if (toggle is ToggleState) d["checked"] = (ToggleState)toggle == ToggleState.On;
308
+ if (!(bool)el.GetCachedPropertyValue(AutomationElement.IsEnabledProperty)) d["disabled"] = true;
309
+ d["x"] = (int)rect.X; d["y"] = (int)rect.Y; d["width"] = (int)rect.Width; d["height"] = (int)rect.Height;
310
+ d["windowHwnd"] = hwnd.ToInt64();
311
+ list.Add(d);
312
+ }
313
+ result = list;
314
+ }
315
+ catch (Exception ex) { error = ex; }
316
+ });
317
+ worker.IsBackground = true;
318
+ worker.SetApartmentState(ApartmentState.MTA);
319
+ worker.Start();
320
+ if (!worker.Join(Args.Int(r, "timeoutMs", 4000))) throw new Exception("UI Automation targeted lookup timed out");
321
+ if (error != null) throw error;
322
+ var outMap = Windows.Describe(hwnd);
323
+ outMap["elements"] = result ?? new List<object>();
324
+ return outMap;
325
+ }
326
+
134
327
  static bool BrowserChrome(AutomationElement element)
135
328
  {
136
329
  // Page content can supply arbitrary UIA names and IDs.
@@ -430,6 +623,22 @@ namespace DshComputerUse
430
623
 
431
624
  const int ReadLimit = 200000;
432
625
 
626
+ static bool IsAddressBar(AutomationElement el)
627
+ {
628
+ try
629
+ {
630
+ if (el.Current.ControlType != ControlType.Edit) return false;
631
+ string aid = el.Current.AutomationId ?? "";
632
+ if (aid.Equals("addressEditBox", StringComparison.OrdinalIgnoreCase)) return true;
633
+ string name = el.Current.Name ?? "";
634
+ return name.IndexOf("地址和搜索栏", StringComparison.OrdinalIgnoreCase) >= 0
635
+ || name.IndexOf("Address and search bar", StringComparison.OrdinalIgnoreCase) >= 0
636
+ || name.IndexOf("Search or enter web address", StringComparison.OrdinalIgnoreCase) >= 0
637
+ || name.IndexOf("搜索或输入网址", StringComparison.OrdinalIgnoreCase) >= 0;
638
+ }
639
+ catch (Exception) { return false; }
640
+ }
641
+
433
642
  static string Read(IntPtr hwnd, out string source)
434
643
  {
435
644
  var root = AutomationElement.FromHandle(hwnd);
@@ -444,6 +653,7 @@ namespace DshComputerUse
444
653
  if (++looked > 40) break;
445
654
  try
446
655
  {
656
+ if (IsAddressBar(el)) continue;
447
657
  var rect = el.Current.BoundingRectangle;
448
658
  double area = rect.IsEmpty ? 0 : rect.Width * rect.Height;
449
659
  if (area <= bestArea) continue;
@@ -457,7 +667,7 @@ namespace DshComputerUse
457
667
  }
458
668
  if (best.Length > 0) { source = "text"; return best; }
459
669
 
460
- // 2. The longest value of an edit or document control.
670
+ // 2. The longest value of an edit or document control (excluding browser URL address bars).
461
671
  var withValue = root.FindAll(TreeScope.Subtree, new AndCondition(visible, new PropertyCondition(AutomationElement.IsValuePatternAvailableProperty, true)));
462
672
  looked = 0;
463
673
  foreach (AutomationElement el in withValue)
@@ -465,7 +675,7 @@ namespace DshComputerUse
465
675
  if (++looked > 200) break;
466
676
  try
467
677
  {
468
- if (IsPasswordElement(el)) continue;
678
+ if (IsPasswordElement(el) || IsAddressBar(el)) continue;
469
679
  object pattern;
470
680
  if (!el.TryGetCurrentPattern(ValuePattern.Pattern, out pattern)) continue;
471
681
  string got = ((ValuePattern)pattern).Current.Value;
package/lib/client.js CHANGED
@@ -690,18 +690,33 @@ window.__ModuleLoader__.load({
690
690
  //#endregion
691
691
  //#region lib/types/client/skills-card.js
692
692
  /**
693
- * "应用技能" card: the per-app notes the agent keeps (see ../skills.ts). The
694
- * user can read, edit, add and delete them here; built-in skills can be
695
- * overridden and restored.
693
+ * "应用技能" card: per-app notes the agent keeps (see ../skills.ts).
694
+ * Compact collapsible list with live search & source filter, plus a centered
695
+ * modal dialog for viewing, editing, and creating skills.
696
696
  */
697
697
  const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
698
698
  const MAX_CHARS = 4e3;
699
699
  const h$1 = react.createElement;
700
+ const modalCss = `
701
+ @keyframes dshcu-backdrop-in{from{opacity:0}to{opacity:1}}
702
+ @keyframes dshcu-modal-in{from{opacity:0;transform:translateY(8px) scale(.97)}to{opacity:1;transform:translateY(0) scale(1)}}
703
+ .dshcu-skill-list{max-height:300px;overflow-y:auto;padding-right:2px;display:grid;gap:2px}
704
+ .dshcu-skill-row{display:flex;gap:10px;align-items:center;padding:9px 10px;border-radius:10px;border:1px solid transparent;transition:background .15s ease,border-color .15s ease}
705
+ .dshcu-skill-row:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.07));border-color:var(--dsw-alias-border-l2,rgba(127,127,127,.18))}
706
+ .dshcu-chip-tab{padding:4px 10px;border-radius:999px;font-size:12px;cursor:pointer;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#666);transition:background .15s ease,color .15s ease,border-color .15s ease}
707
+ .dshcu-chip-tab:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.08))}
708
+ .dshcu-chip-tab[data-active="true"]{background:var(--dshcu-accent-soft,rgba(217,119,87,.14));color:var(--dshcu-accent,#d97757);border-color:var(--dshcu-accent,#d97757);font-weight:600}
709
+ .dshcu-modal-backdrop{position:fixed;inset:0;z-index:9999;background:rgba(15,15,18,.48);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:20px;animation:dshcu-backdrop-in .16s ease}
710
+ .dshcu-modal{width:min(640px,100%);max-height:min(86vh,720px);display:flex;flex-direction:column;border-radius:16px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));box-shadow:0 24px 64px rgba(0,0,0,.28);overflow:hidden;animation:dshcu-modal-in .18s cubic-bezier(.16,1,.3,1)}
711
+ `;
700
712
  function SkillsCard({ S }) {
701
713
  const [skills, setSkills] = react.useState(null);
702
714
  const [dir, setDir] = react.useState("");
703
715
  const [draft, setDraft] = react.useState(null);
704
716
  const [busy, setBusy] = react.useState(false);
717
+ const [expanded, setExpanded] = react.useState(false);
718
+ const [query, setQuery] = react.useState("");
719
+ const [filter, setFilter] = react.useState("all");
705
720
  const [note, setNote] = react.useState(null);
706
721
  const call = react.useCallback(async (body) => {
707
722
  setBusy(true);
@@ -729,6 +744,14 @@ window.__ModuleLoader__.load({
729
744
  react.useEffect(() => {
730
745
  call();
731
746
  }, [call]);
747
+ react.useEffect(() => {
748
+ if (!draft) return;
749
+ const onKey = (e) => {
750
+ if (e.key === "Escape" && !busy) setDraft(null);
751
+ };
752
+ window.addEventListener("keydown", onKey);
753
+ return () => window.removeEventListener("keydown", onKey);
754
+ }, [draft, busy]);
732
755
  const edit = (skill) => {
733
756
  setNote(null);
734
757
  setDraft({
@@ -737,7 +760,20 @@ window.__ModuleLoader__.load({
737
760
  match: skill.match.join(", "),
738
761
  summary: skill.summary,
739
762
  content: skill.content,
740
- isNew: false
763
+ isNew: false,
764
+ source: skill.source,
765
+ overrides: skill.overrides
766
+ });
767
+ };
768
+ const openNew = () => {
769
+ setNote(null);
770
+ setDraft({
771
+ id: "",
772
+ app: "",
773
+ match: "",
774
+ summary: "",
775
+ content: "",
776
+ isNew: true
741
777
  });
742
778
  };
743
779
  const save = async () => {
@@ -771,26 +807,30 @@ window.__ModuleLoader__.load({
771
807
  });
772
808
  }
773
809
  };
774
- const reset = async (skill) => {
810
+ const reset = async (id, app) => {
775
811
  setNote(null);
776
812
  if (await call({
777
813
  op: "reset",
778
- id: skill.id
814
+ id
779
815
  })) {
780
- if (draft?.id === skill.id) setDraft(null);
816
+ if (draft?.id === id) setDraft(null);
781
817
  setNote({
782
818
  kind: "ok",
783
- text: `已恢复“${skill.app}”的内置版本`
819
+ text: `已恢复“${app}”的内置版本`
784
820
  });
785
821
  }
786
822
  };
787
- const row = {
788
- display: "flex",
789
- gap: 10,
790
- alignItems: "center",
791
- padding: "8px 0",
792
- borderTop: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
793
- };
823
+ const allSkills = skills ?? [];
824
+ const userCount = allSkills.filter((s) => s.source !== "builtin").length;
825
+ const builtinCount = allSkills.length - userCount;
826
+ const q = query.trim().toLowerCase();
827
+ const showList = expanded || q.length > 0;
828
+ const filtered = allSkills.filter((skill) => {
829
+ if (filter === "user" && skill.source === "builtin") return false;
830
+ if (filter === "builtin" && skill.source !== "builtin") return false;
831
+ if (!q) return true;
832
+ return skill.app.toLowerCase().includes(q) || skill.summary.toLowerCase().includes(q) || skill.match.some((m) => m.toLowerCase().includes(q));
833
+ });
794
834
  const small = {
795
835
  ...S.secondary,
796
836
  padding: "4px 10px",
@@ -805,9 +845,105 @@ window.__ModuleLoader__.load({
805
845
  whiteSpace: "nowrap"
806
846
  };
807
847
  const invalid = draft !== null && (draft.app.trim() === "" || draft.content.trim() === "" || draft.content.length > MAX_CHARS);
808
- return h$1("section", { style: S.card }, h$1("h3", { style: S.cardTitle }, "应用技能"), h$1("p", { style: S.hint }, "AI 对各个应用的操作笔记:每个应用一份,AI 摸索清楚一个不熟悉的应用后会自己记下来,以后打开这个应用时自动读取,不占用系统提示。你可以在这里查看、修改、删除或新建。"), skills === null ? h$1("p", { style: S.hint }, busy ? "正在读取…" : "无法读取应用技能。") : skills.length === 0 ? h$1("p", { style: S.hint }, "还没有应用技能。") : h$1("div", null, ...skills.map((skill) => h$1("div", {
848
+ return h$1("section", {
849
+ className: "dshcu-card",
850
+ style: S.card
851
+ }, h$1("style", null, modalCss), h$1("div", { style: {
852
+ display: "flex",
853
+ alignItems: "center",
854
+ justifyContent: "space-between",
855
+ gap: 10,
856
+ flexWrap: "wrap"
857
+ } }, h$1("div", { style: {
858
+ display: "flex",
859
+ alignItems: "center",
860
+ gap: 8,
861
+ flexWrap: "wrap"
862
+ } }, h$1("h3", { style: S.cardTitle }, "应用技能"), skills !== null ? h$1("span", {
863
+ className: "dshcu-badge",
864
+ style: tag
865
+ }, `共 ${allSkills.length} 项 · ${userCount} 自定义 / ${builtinCount} 内置`) : null), h$1("div", { style: {
866
+ display: "flex",
867
+ gap: 8,
868
+ alignItems: "center"
869
+ } }, h$1("button", {
870
+ type: "button",
871
+ className: "dshcu-btn",
872
+ style: small,
873
+ disabled: busy,
874
+ onClick: openNew
875
+ }, "+ 新建技能"), h$1("button", {
876
+ type: "button",
877
+ className: "dshcu-btn",
878
+ style: small,
879
+ disabled: busy,
880
+ onClick: () => setExpanded((prev) => !prev)
881
+ }, showList && !q ? "收起列表 ▴" : `展开列表 (${allSkills.length}) ▾`))), h$1("p", { style: S.hint }, "AI 对各个应用的操作笔记:打开应用时自动读取,不占用常规系统提示。支持实时搜索,点击「查看 / 编辑」在弹窗中修改。"), h$1("div", { style: {
882
+ display: "flex",
883
+ gap: 8,
884
+ alignItems: "center",
885
+ flexWrap: "wrap"
886
+ } }, h$1("div", { style: {
887
+ position: "relative",
888
+ flex: "1 1 220px",
889
+ minWidth: 180
890
+ } }, h$1("input", {
891
+ style: {
892
+ ...S.input,
893
+ width: "100%",
894
+ boxSizing: "border-box",
895
+ paddingRight: q ? 30 : 12
896
+ },
897
+ value: query,
898
+ placeholder: "搜索应用名、进程名或摘要(输入即可过滤)…",
899
+ onChange: (e) => setQuery(e.target.value)
900
+ }), q ? h$1("button", {
901
+ type: "button",
902
+ "aria-label": "清空搜索",
903
+ onClick: () => setQuery(""),
904
+ style: {
905
+ position: "absolute",
906
+ right: 8,
907
+ top: "50%",
908
+ transform: "translateY(-50%)",
909
+ border: "none",
910
+ background: "transparent",
911
+ color: "var(--dsw-alias-label-tertiary, #888)",
912
+ cursor: "pointer",
913
+ fontSize: 15,
914
+ lineHeight: 1,
915
+ padding: "2px 4px"
916
+ }
917
+ }, "×") : null), showList ? h$1("div", { style: {
918
+ display: "flex",
919
+ gap: 6,
920
+ alignItems: "center"
921
+ } }, h$1("button", {
922
+ type: "button",
923
+ className: "dshcu-chip-tab",
924
+ "data-active": String(filter === "all"),
925
+ onClick: () => setFilter("all")
926
+ }, `全部 (${allSkills.length})`), h$1("button", {
927
+ type: "button",
928
+ className: "dshcu-chip-tab",
929
+ "data-active": String(filter === "user"),
930
+ onClick: () => setFilter("user")
931
+ }, `自定义 (${userCount})`), h$1("button", {
932
+ type: "button",
933
+ className: "dshcu-chip-tab",
934
+ "data-active": String(filter === "builtin"),
935
+ onClick: () => setFilter("builtin")
936
+ }, `内置 (${builtinCount})`), h$1("button", {
937
+ type: "button",
938
+ className: "dshcu-btn",
939
+ style: small,
940
+ disabled: busy,
941
+ onClick: () => {
942
+ call();
943
+ }
944
+ }, "刷新")) : null), skills === null ? h$1("p", { style: S.hint }, busy ? "正在读取…" : "无法读取应用技能。") : !showList ? null : filtered.length === 0 ? h$1("p", { style: S.hint }, q ? `未找到包含「${query}」的应用技能。` : "当前分类下还没有应用技能。") : h$1("div", { className: "dshcu-skill-list" }, ...filtered.map((skill) => h$1("div", {
809
945
  key: skill.id,
810
- style: row
946
+ className: "dshcu-skill-row"
811
947
  }, h$1("div", { style: {
812
948
  flex: 1,
813
949
  minWidth: 0
@@ -824,27 +960,70 @@ window.__ModuleLoader__.load({
824
960
  whiteSpace: "nowrap"
825
961
  } }, `${skill.summary || "(无摘要)"} · ${skill.content.length} 字`)), h$1("button", {
826
962
  type: "button",
963
+ className: "dshcu-btn",
827
964
  style: small,
828
965
  disabled: busy,
829
966
  onClick: () => edit(skill)
830
967
  }, "查看 / 编辑"), skill.overrides ? h$1("button", {
831
968
  type: "button",
969
+ className: "dshcu-btn",
832
970
  style: small,
833
971
  disabled: busy,
834
972
  onClick: () => {
835
- reset(skill);
973
+ reset(skill.id, skill.app);
836
974
  }
837
975
  }, "恢复内置") : null, h$1("button", {
838
976
  type: "button",
977
+ className: "dshcu-btn",
839
978
  style: small,
840
979
  disabled: busy,
841
980
  onClick: () => {
842
981
  remove(skill);
843
982
  }
844
- }, "删除")))), draft === null ? null : h$1("div", { style: {
845
- display: "grid",
983
+ }, "删除")))), note !== null ? h$1("div", { style: {
984
+ fontSize: 12,
985
+ color: (note.kind === "ok" ? S.ok : S.error)?.color
986
+ } }, note.text) : null, showList && dir ? h$1("p", { style: S.hint }, `保存位置:${dir}(每个应用一个 .md 文件,也可直接编辑)。删除内置技能后,新建同名技能即可重新启用。`) : null, draft === null ? null : h$1("div", {
987
+ className: "dshcu-modal-backdrop",
988
+ onClick: (e) => {
989
+ if (e.target === e.currentTarget && !busy) setDraft(null);
990
+ }
991
+ }, h$1("div", {
992
+ className: "dshcu-modal",
993
+ role: "dialog",
994
+ "aria-modal": "true",
995
+ "aria-label": draft.isNew ? "新建应用技能" : `编辑应用技能 ${draft.app}`
996
+ }, h$1("div", { style: {
997
+ display: "flex",
998
+ alignItems: "center",
999
+ justifyContent: "space-between",
846
1000
  gap: 10,
847
- paddingTop: 4
1001
+ padding: "16px 20px",
1002
+ borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
1003
+ } }, h$1("div", { style: {
1004
+ display: "flex",
1005
+ alignItems: "center",
1006
+ gap: 8
1007
+ } }, h$1("strong", { style: { fontSize: 15 } }, draft.isNew ? "新建应用技能" : `编辑技能 · ${draft.app}`), !draft.isNew ? h$1("span", { style: tag }, draft.source === "builtin" ? "内置" : draft.overrides ? "已修改" : "AI / 自定义") : null), h$1("button", {
1008
+ type: "button",
1009
+ "aria-label": "关闭",
1010
+ disabled: busy,
1011
+ onClick: () => setDraft(null),
1012
+ style: {
1013
+ border: "none",
1014
+ background: "transparent",
1015
+ color: "var(--dsw-alias-label-secondary, #666)",
1016
+ cursor: "pointer",
1017
+ fontSize: 20,
1018
+ lineHeight: 1,
1019
+ padding: "2px 6px",
1020
+ borderRadius: 6
1021
+ }
1022
+ }, "×")), h$1("div", { style: {
1023
+ padding: "16px 20px",
1024
+ overflowY: "auto",
1025
+ display: "grid",
1026
+ gap: 12
848
1027
  } }, h$1("div", { style: S.grid2 }, h$1("label", { style: S.label }, "应用名称", h$1("input", {
849
1028
  style: S.input,
850
1029
  value: draft.app,
@@ -876,7 +1055,7 @@ window.__ModuleLoader__.load({
876
1055
  })), h$1("label", { style: S.label }, `内容(${draft.content.length} / ${MAX_CHARS} 字)`, h$1("textarea", {
877
1056
  style: {
878
1057
  ...S.input,
879
- minHeight: 200,
1058
+ minHeight: 240,
880
1059
  resize: "vertical",
881
1060
  fontFamily: "inherit",
882
1061
  lineHeight: 1.55
@@ -887,44 +1066,45 @@ window.__ModuleLoader__.load({
887
1066
  ...draft,
888
1067
  content: e.target.value
889
1068
  })
890
- })), h$1("div", { style: S.actions }, h$1("button", {
891
- type: "button",
892
- style: {
893
- ...S.primary,
894
- opacity: busy || invalid ? .5 : 1
895
- },
896
- disabled: busy || invalid,
897
- onClick: () => {
898
- save();
899
- }
900
- }, "保存技能"), h$1("button", {
901
- type: "button",
902
- style: S.secondary,
903
- disabled: busy,
904
- onClick: () => setDraft(null)
905
- }, "取消"), draft.content.length > MAX_CHARS ? h$1("span", { style: S.error }, "内容过长,请精简") : null)), h$1("div", { style: S.actions }, draft === null ? h$1("button", {
1069
+ })), draft.content.length > MAX_CHARS ? h$1("span", { style: S.error }, "内容过长,请精简至 4000 字以内") : null), h$1("div", { style: {
1070
+ display: "flex",
1071
+ alignItems: "center",
1072
+ justifyContent: "space-between",
1073
+ gap: 10,
1074
+ padding: "14px 20px",
1075
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
1076
+ } }, h$1("div", { style: {
1077
+ display: "flex",
1078
+ gap: 8
1079
+ } }, !draft.isNew && draft.overrides ? h$1("button", {
906
1080
  type: "button",
1081
+ className: "dshcu-btn",
907
1082
  style: S.secondary,
908
1083
  disabled: busy,
909
1084
  onClick: () => {
910
- setNote(null);
911
- setDraft({
912
- id: "",
913
- app: "",
914
- match: "",
915
- summary: "",
916
- content: "",
917
- isNew: true
918
- });
1085
+ reset(draft.id, draft.app);
919
1086
  }
920
- }, "新建技能") : null, h$1("button", {
1087
+ }, "恢复内置版本") : null), h$1("div", { style: {
1088
+ display: "flex",
1089
+ gap: 8
1090
+ } }, h$1("button", {
921
1091
  type: "button",
1092
+ className: "dshcu-btn",
922
1093
  style: S.secondary,
923
1094
  disabled: busy,
1095
+ onClick: () => setDraft(null)
1096
+ }, "取消"), h$1("button", {
1097
+ type: "button",
1098
+ className: "dshcu-btn",
1099
+ style: {
1100
+ ...S.primary,
1101
+ opacity: busy || invalid ? .5 : 1
1102
+ },
1103
+ disabled: busy || invalid,
924
1104
  onClick: () => {
925
- call();
1105
+ save();
926
1106
  }
927
- }, "刷新"), note === null ? null : h$1("span", { style: note.kind === "ok" ? S.ok : S.error }, note.text)), dir ? h$1("p", { style: S.hint }, `保存位置:${dir}(每个应用一个 .md 文件,也可以直接用编辑器改)。删除内置技能后,新建同名技能即可重新启用。`) : null);
1107
+ }, "保存技能"))))));
928
1108
  }
929
1109
  //#endregion
930
1110
  //#region lib/types/client/window-refs.js