@linxin666/dsh-liangshen 0.4.15 → 0.4.17

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/lib/client.js CHANGED
@@ -722,6 +722,137 @@ window.__ModuleLoader__.load({
722
722
  * scrolling ancestor, so a row near the top of a settings page does not hang
723
723
  * its bubble under the page edge.
724
724
  */
725
+ /** Rest on the control before the bubble opens. */
726
+ const OPEN_DELAY_MS = 220;
727
+ /** Grace after pointer and focus have left before the bubble closes. */
728
+ const CLOSE_DELAY_MS = 200;
729
+ /** Room the bubble needs between the control and the scroller's edge. */
730
+ const BUBBLE_ROOM_PX = 64;
731
+ /** The nearest ancestor that scrolls vertically, or the viewport's root. */
732
+ function scroller(node) {
733
+ for (let parent = node.parentElement; parent !== null; parent = parent.parentElement) {
734
+ const overflow = getComputedStyle(parent).overflowY;
735
+ if (overflow === "auto" || overflow === "scroll") return parent;
736
+ }
737
+ return node.ownerDocument.documentElement;
738
+ }
739
+ /**
740
+ * Render the control with its coarse-adjustment bubble.
741
+ * @param props - the range, the value and the two report callbacks.
742
+ * @returns the anchor holding the control and the bubble.
743
+ */
744
+ function RangeBubble(props) {
745
+ const { min, max, step, disabled = false } = props;
746
+ const [open, setOpen] = (0, react.useState)(false);
747
+ const [side, setSide] = (0, react.useState)("above");
748
+ const [live, setLive] = (0, react.useState)(null);
749
+ const anchorRef = (0, react.useRef)(null);
750
+ const timer = (0, react.useRef)(void 0);
751
+ const hovered = (0, react.useRef)(false);
752
+ const focused = (0, react.useRef)(false);
753
+ const dragging = (0, react.useRef)(false);
754
+ (0, react.useEffect)(() => () => {
755
+ clearTimeout(timer.current);
756
+ }, []);
757
+ (0, react.useEffect)(() => {
758
+ if (disabled) {
759
+ clearTimeout(timer.current);
760
+ setOpen(false);
761
+ }
762
+ }, [disabled]);
763
+ const show = () => {
764
+ const anchor = anchorRef.current;
765
+ if (anchor !== null) {
766
+ const room = anchor.getBoundingClientRect().top - scroller(anchor).getBoundingClientRect().top;
767
+ setSide(room >= BUBBLE_ROOM_PX ? "above" : "below");
768
+ }
769
+ setOpen(true);
770
+ };
771
+ const schedule = () => {
772
+ clearTimeout(timer.current);
773
+ if (disabled) return;
774
+ if (hovered.current || focused.current || dragging.current) {
775
+ if (!open) timer.current = setTimeout(show, focused.current ? 0 : OPEN_DELAY_MS);
776
+ return;
777
+ }
778
+ timer.current = setTimeout(() => {
779
+ setOpen(false);
780
+ }, CLOSE_DELAY_MS);
781
+ };
782
+ const commit = (value) => {
783
+ dragging.current = false;
784
+ setLive(null);
785
+ props.onCommit(value);
786
+ schedule();
787
+ };
788
+ const onChange = (event) => {
789
+ const value = Number(event.target.value);
790
+ setLive(value);
791
+ props.onInput(value);
792
+ };
793
+ const onKeyUp = (event) => {
794
+ if (live !== null) commit(live);
795
+ if (event.key === "Escape") {
796
+ clearTimeout(timer.current);
797
+ setOpen(false);
798
+ }
799
+ };
800
+ const shown = live ?? Math.min(max, Math.max(min, props.value));
801
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
802
+ ref: anchorRef,
803
+ className: settings_card_module_css_default.rangeAnchor,
804
+ onPointerEnter: () => {
805
+ hovered.current = true;
806
+ schedule();
807
+ },
808
+ onPointerLeave: () => {
809
+ hovered.current = false;
810
+ schedule();
811
+ },
812
+ onFocus: () => {
813
+ focused.current = true;
814
+ schedule();
815
+ },
816
+ onBlur: (event) => {
817
+ if (event.currentTarget.contains(event.relatedTarget)) return;
818
+ focused.current = false;
819
+ if (live !== null) commit(live);
820
+ else schedule();
821
+ },
822
+ children: [props.children, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
823
+ className: settings_card_module_css_default.rangeBubble,
824
+ "data-open": open ? "" : void 0,
825
+ "data-side": side,
826
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
827
+ type: "range",
828
+ className: settings_card_module_css_default.rangeSlider,
829
+ min,
830
+ max,
831
+ step,
832
+ value: shown,
833
+ "aria-label": props.label,
834
+ tabIndex: open ? 0 : -1,
835
+ disabled,
836
+ style: { "--range-fill": `${(shown - min) / (max - min) * 100}%` },
837
+ onPointerDown: () => {
838
+ dragging.current = true;
839
+ },
840
+ onPointerUp: (event) => {
841
+ commit(Number(event.currentTarget.value));
842
+ },
843
+ onPointerCancel: (event) => {
844
+ commit(Number(event.currentTarget.value));
845
+ },
846
+ onChange,
847
+ onKeyUp
848
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
849
+ className: settings_card_module_css_default.rangeEnds,
850
+ "aria-hidden": "true",
851
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: min }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: max })]
852
+ })]
853
+ })]
854
+ });
855
+ }
725
856
  //#endregion
726
857
  //#region src/client/SegmentGroup.tsx
727
858
  /**
@@ -985,6 +1116,97 @@ window.__ModuleLoader__.load({
985
1116
  ] })) : null]
986
1117
  });
987
1118
  }
1119
+ /**
1120
+ * A typed value field. Its draft is written after a pause in typing, at once on
1121
+ * Enter or when focus leaves, and Escape puts the stored value back. `numeric`
1122
+ * only hints the keypad: which drafts a field accepts is decided by its spec.
1123
+ * A field given a `range` also offers the coarse slider bubble: dragging fills
1124
+ * the draft live and releasing writes it.
1125
+ */
1126
+ function ValueField(props) {
1127
+ const apply = (0, react.useContext)(CardApply);
1128
+ const settledByKey = (0, react.useRef)(false);
1129
+ const onKeyDown = (event) => {
1130
+ if (apply === null || event.key !== "Enter" && event.key !== "Escape") return;
1131
+ event.preventDefault();
1132
+ settledByKey.current = true;
1133
+ if (event.key === "Enter") apply.commit();
1134
+ else apply.revert();
1135
+ event.currentTarget.blur();
1136
+ };
1137
+ const input = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1138
+ id: props.id,
1139
+ className: props.invalid ? settings_card_module_css_default.inputInvalid : settings_card_module_css_default.input,
1140
+ type: "text",
1141
+ ...props.numeric === true ? { inputMode: "numeric" } : {},
1142
+ ...props.invalid ? { "aria-invalid": true } : {},
1143
+ value: props.text,
1144
+ placeholder: props.placeholder ?? "",
1145
+ disabled: props.disabled,
1146
+ onChange: (event) => {
1147
+ props.onEdit(event.target.value);
1148
+ },
1149
+ onKeyDown,
1150
+ onFocus: () => {
1151
+ settledByKey.current = false;
1152
+ },
1153
+ onBlur: () => {
1154
+ if (settledByKey.current) {
1155
+ settledByKey.current = false;
1156
+ return;
1157
+ }
1158
+ apply?.commit();
1159
+ }
1160
+ });
1161
+ const { range } = props;
1162
+ const typed = Number(props.text);
1163
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1164
+ className: settings_card_module_css_default.field,
1165
+ children: [
1166
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1167
+ className: settings_card_module_css_default.head,
1168
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1169
+ className: settings_card_module_css_default.label,
1170
+ htmlFor: props.id,
1171
+ children: props.label
1172
+ }), props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1173
+ className: settings_card_module_css_default.badges,
1174
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1175
+ className: settings_card_module_css_default.badge,
1176
+ children: props.overriddenLabel
1177
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1178
+ type: "button",
1179
+ className: settings_card_module_css_default.reset,
1180
+ disabled: props.disabled,
1181
+ onClick: props.onReset,
1182
+ children: props.resetLabel
1183
+ })]
1184
+ }) : null]
1185
+ }),
1186
+ range === void 0 ? input : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RangeBubble, {
1187
+ min: range.min,
1188
+ max: range.max,
1189
+ step: range.step,
1190
+ value: props.text.trim() === "" || Number.isNaN(typed) ? range.min : typed,
1191
+ label: `${props.label} ${range.min}–${range.max}`,
1192
+ disabled: props.disabled,
1193
+ onInput: (value) => {
1194
+ props.onEdit(String(value));
1195
+ },
1196
+ onCommit: (value) => {
1197
+ props.onEdit(String(value));
1198
+ apply?.commit();
1199
+ },
1200
+ children: input
1201
+ }),
1202
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1203
+ className: props.invalid ? settings_card_module_css_default.invalid : settings_card_module_css_default.hint,
1204
+ title: props.hintTitle,
1205
+ children: props.invalid ? props.invalidLabel : props.hint
1206
+ })
1207
+ ]
1208
+ });
1209
+ }
988
1210
  const NON_SKIN_BODY_MARKERS = /* @__PURE__ */ new Set(["dshSkinCenter", "dshSidebarCollapsed"]);
989
1211
  function isSkinActive() {
990
1212
  return Object.keys(document.body.dataset).some((key) => key.startsWith("dsh") && !NON_SKIN_BODY_MARKERS.has(key));
@@ -1320,6 +1542,24 @@ window.__ModuleLoader__.load({
1320
1542
  ]
1321
1543
  });
1322
1544
  }
1545
+ /**
1546
+ * A free-text field. An empty draft clears the field. `entry` is `pick` when
1547
+ * the text arrives whole from a picker (a preset or a reasoning level).
1548
+ */
1549
+ function textField(field, entry = "type") {
1550
+ return {
1551
+ field,
1552
+ entry,
1553
+ format: (value) => typeof value === "string" ? value : "",
1554
+ parse: (text) => {
1555
+ const trimmed = text.trim();
1556
+ return trimmed === "" ? { kind: "clear" } : {
1557
+ kind: "set",
1558
+ value: trimmed
1559
+ };
1560
+ }
1561
+ };
1562
+ }
1323
1563
  /** A boolean field, edited through true/false draft text. */
1324
1564
  function booleanField(field) {
1325
1565
  return {
@@ -1657,6 +1897,27 @@ window.__ModuleLoader__.load({
1657
1897
  };
1658
1898
  //#endregion
1659
1899
  //#region src/client/LiangShenSettingsCard.tsx
1900
+ /** A tool family entry: a prefix ending in exactly one trailing star. */
1901
+ const FAMILY_ENTRY_RE = /^[^*]+\*$/;
1902
+ /**
1903
+ * The on-demand tool family list: comma separated entries, each a prefix with
1904
+ * one trailing star. Blank clears the field; any malformed entry holds the
1905
+ * draft unwritten.
1906
+ */
1907
+ function pagedToolPatternsField(field) {
1908
+ return {
1909
+ ...textField(field),
1910
+ parse: (text) => {
1911
+ const entries = text.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
1912
+ if (entries.length === 0) return { kind: "clear" };
1913
+ if (!entries.every((entry) => FAMILY_ENTRY_RE.test(entry))) return void 0;
1914
+ return {
1915
+ kind: "set",
1916
+ value: entries.join(", ")
1917
+ };
1918
+ }
1919
+ };
1920
+ }
1660
1921
  /** Wire presentations the tool catalog accepts (mirrors the Host schema). */
1661
1922
  const PRESENTATION_CHOICES = ["ptc", "native"];
1662
1923
  /** Bridges the `liangshen` settings form onto the card's staged form. */
@@ -1669,7 +1930,8 @@ window.__ModuleLoader__.load({
1669
1930
  booleanField("enabled"),
1670
1931
  booleanField("announceToAgent"),
1671
1932
  choiceField("presentation", PRESENTATION_CHOICES),
1672
- booleanField("dispatcher")
1933
+ booleanField("dispatcher"),
1934
+ pagedToolPatternsField("pagedToolPatterns")
1673
1935
  ]);
1674
1936
  this.store = this.form.bind(() => this.projection());
1675
1937
  }
@@ -1679,7 +1941,8 @@ window.__ModuleLoader__.load({
1679
1941
  enabled: this.form.field("enabled"),
1680
1942
  announceToAgent: this.form.field("announceToAgent"),
1681
1943
  presentation: this.form.field("presentation"),
1682
- dispatcher: this.form.field("dispatcher")
1944
+ dispatcher: this.form.field("dispatcher"),
1945
+ pagedToolPatterns: this.form.field("pagedToolPatterns")
1683
1946
  };
1684
1947
  }
1685
1948
  /**
@@ -1786,6 +2049,21 @@ window.__ModuleLoader__.load({
1786
2049
  onReset: () => {
1787
2050
  props.resetField("dispatcher");
1788
2051
  }
2052
+ }),
2053
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ValueField, {
2054
+ id: "settings-liangshen-paged-tool-patterns",
2055
+ label: t("settings.pagedToolPatterns"),
2056
+ hint: t("settings.pagedToolPatternsHint"),
2057
+ placeholder: "browser_*, task_board_*",
2058
+ ...fieldProps,
2059
+ invalidLabel: t("settings.pagedToolPatternsInvalid"),
2060
+ ...state.pagedToolPatterns,
2061
+ onEdit: (text) => {
2062
+ props.edit("pagedToolPatterns", text);
2063
+ },
2064
+ onReset: () => {
2065
+ props.resetField("pagedToolPatterns");
2066
+ }
1789
2067
  })
1790
2068
  ]
1791
2069
  });
@@ -1824,6 +2102,9 @@ window.__ModuleLoader__.load({
1824
2102
  "settings.presentationHint": "ptc 把工具收进 run_code,native 保留原生清单。",
1825
2103
  "settings.dispatcher": "调度身份",
1826
2104
  "settings.dispatcherHint": "按调度 Agent 工作:分诊、访谈、派发子代理。",
2105
+ "settings.pagedToolPatterns": "按需工具族",
2106
+ "settings.pagedToolPatternsHint": "逗号分隔,每项以单个 * 结尾。命中这些前缀的工具默认不进上下文,需要时用 tool_activate 按需加载。留空继承出厂 7 项:mcp__*, browser_*, task_board_*, team_*, squad*, ui_*, ssh_*。",
2107
+ "settings.pagedToolPatternsInvalid": "每项须是非空前缀并以单个 * 结尾,逗号分隔,例如 task_board_*。",
1827
2108
  "settings.on": "开",
1828
2109
  "settings.off": "关",
1829
2110
  "settings.inherit": "继承",
@@ -1865,6 +2146,9 @@ window.__ModuleLoader__.load({
1865
2146
  "settings.presentationHint": "ptc folds tools into run_code; native keeps the native roster.",
1866
2147
  "settings.dispatcher": "Dispatcher",
1867
2148
  "settings.dispatcherHint": "Works as a dispatcher: triage, interview, then dispatch subagents.",
2149
+ "settings.pagedToolPatterns": "On-demand tool families",
2150
+ "settings.pagedToolPatternsHint": "Comma separated, each entry ending in a single *. Tools matching these prefixes stay out of context by default; load them with tool_activate when needed. Leave empty to inherit the 7 factory entries: mcp__*, browser_*, task_board_*, team_*, squad*, ui_*, ssh_*.",
2151
+ "settings.pagedToolPatternsInvalid": "Each entry must be a non-empty prefix ending in a single *, comma separated, for example task_board_*.",
1868
2152
  "settings.on": "On",
1869
2153
  "settings.off": "Off",
1870
2154
  "settings.inherit": "Inherit",