@linxin666/dsh-liangshen 0.4.10 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,164 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/client/settings/RangeBubble.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Coarse adjustment for a bounded number: resting the pointer on the control
4
+ * (or moving focus into it) raises a small bubble holding a slider across the
5
+ * field's whole range, so a large change is one drag instead of many presses
6
+ * or a retyped value. The control itself stays the precise entry.
7
+ *
8
+ * The bubble belongs to the anchor's subtree, so moving from the control onto
9
+ * the bubble never counts as leaving. It opens after a short rest and closes a
10
+ * moment after the pointer and focus have both gone, so crossing the control
11
+ * on the way elsewhere does not flash it. While a drag is in progress the
12
+ * bubble stays put even if the pointer strays off it.
13
+ *
14
+ * Dragging reports each value through `onInput`, so the field shows it live;
15
+ * releasing the thumb, or a key press on it, reports `onCommit` once. The
16
+ * bubble opens on the side of the control that has room inside the nearest
17
+ * scrolling ancestor, so a row near the top of a settings page does not hang
18
+ * its bubble under the page edge.
19
+ */
20
+
21
+ import { useEffect, useRef, useState, type ChangeEvent, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react'
22
+ import css from './settings-card.module.css'
23
+
24
+ /** Rest on the control before the bubble opens. */
25
+ const OPEN_DELAY_MS = 220
26
+ /** Grace after pointer and focus have left before the bubble closes. */
27
+ const CLOSE_DELAY_MS = 200
28
+ /** Room the bubble needs between the control and the scroller's edge. */
29
+ const BUBBLE_ROOM_PX = 64
30
+
31
+ /** Props of {@link RangeBubble}. */
32
+ export interface RangeBubbleProps {
33
+ /** Lowest value the slider reaches. */
34
+ min: number
35
+ /** Highest value the slider reaches. */
36
+ max: number
37
+ /** Slider granularity. */
38
+ step: number
39
+ /** Current value; a value outside the range parks the thumb at the nearer end. */
40
+ value: number
41
+ /** Accessible name of the slider. */
42
+ label: string
43
+ /** Disables the bubble along with the control. */
44
+ disabled?: boolean
45
+ /** Each value while the thumb moves. */
46
+ onInput: (value: number) => void
47
+ /** The value the thumb was released on, once per drag or key press. */
48
+ onCommit: (value: number) => void
49
+ /** The precise control the bubble hangs off. */
50
+ children: ReactNode
51
+ }
52
+
53
+ /** The nearest ancestor that scrolls vertically, or the viewport's root. */
54
+ function scroller(node: HTMLElement): HTMLElement {
55
+ for (let parent = node.parentElement; parent !== null; parent = parent.parentElement) {
56
+ const overflow = getComputedStyle(parent).overflowY
57
+ if (overflow === 'auto' || overflow === 'scroll') return parent
58
+ }
59
+ return node.ownerDocument.documentElement
60
+ }
61
+
62
+ /**
63
+ * Render the control with its coarse-adjustment bubble.
64
+ * @param props - the range, the value and the two report callbacks.
65
+ * @returns the anchor holding the control and the bubble.
66
+ */
67
+ export function RangeBubble(props: RangeBubbleProps): ReactNode {
68
+ const { min, max, step, disabled = false } = props
69
+ const [open, setOpen] = useState(false)
70
+ const [side, setSide] = useState<'above' | 'below'>('above')
71
+ const [live, setLive] = useState<number | null>(null)
72
+ const anchorRef = useRef<HTMLDivElement | null>(null)
73
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
74
+ const hovered = useRef(false)
75
+ const focused = useRef(false)
76
+ const dragging = useRef(false)
77
+
78
+ useEffect(() => () => { clearTimeout(timer.current) }, [])
79
+ useEffect(() => {
80
+ if (disabled) {
81
+ clearTimeout(timer.current)
82
+ setOpen(false)
83
+ }
84
+ }, [disabled])
85
+
86
+ const show = (): void => {
87
+ const anchor = anchorRef.current
88
+ if (anchor !== null) {
89
+ const room = anchor.getBoundingClientRect().top - scroller(anchor).getBoundingClientRect().top
90
+ setSide(room >= BUBBLE_ROOM_PX ? 'above' : 'below')
91
+ }
92
+ setOpen(true)
93
+ }
94
+ const schedule = (): void => {
95
+ clearTimeout(timer.current)
96
+ if (disabled) return
97
+ if (hovered.current || focused.current || dragging.current) {
98
+ if (!open) timer.current = setTimeout(show, focused.current ? 0 : OPEN_DELAY_MS)
99
+ return
100
+ }
101
+ timer.current = setTimeout(() => { setOpen(false) }, CLOSE_DELAY_MS)
102
+ }
103
+
104
+ const commit = (value: number): void => {
105
+ dragging.current = false
106
+ setLive(null)
107
+ props.onCommit(value)
108
+ schedule()
109
+ }
110
+ const onChange = (event: ChangeEvent<HTMLInputElement>): void => {
111
+ const value = Number(event.target.value)
112
+ setLive(value)
113
+ props.onInput(value)
114
+ }
115
+ const onKeyUp = (event: KeyboardEvent<HTMLInputElement>): void => {
116
+ if (live !== null) commit(live)
117
+ if (event.key === 'Escape') {
118
+ clearTimeout(timer.current)
119
+ setOpen(false)
120
+ }
121
+ }
122
+ const shown = live ?? Math.min(max, Math.max(min, props.value))
123
+
124
+ return (
125
+ <div
126
+ ref={anchorRef}
127
+ className={css.rangeAnchor}
128
+ onPointerEnter={() => { hovered.current = true; schedule() }}
129
+ onPointerLeave={() => { hovered.current = false; schedule() }}
130
+ onFocus={() => { focused.current = true; schedule() }}
131
+ onBlur={(event) => {
132
+ if (event.currentTarget.contains(event.relatedTarget as Node | null)) return
133
+ focused.current = false
134
+ if (live !== null) commit(live)
135
+ else schedule()
136
+ }}
137
+ >
138
+ {props.children}
139
+ <div className={css.rangeBubble} data-open={open ? '' : undefined} data-side={side}>
140
+ <input
141
+ type="range"
142
+ className={css.rangeSlider}
143
+ min={min}
144
+ max={max}
145
+ step={step}
146
+ value={shown}
147
+ aria-label={props.label}
148
+ tabIndex={open ? 0 : -1}
149
+ disabled={disabled}
150
+ style={{ '--range-fill': `${((shown - min) / (max - min)) * 100}%` } as CSSProperties}
151
+ onPointerDown={() => { dragging.current = true }}
152
+ onPointerUp={(event) => { commit(Number(event.currentTarget.value)) }}
153
+ onPointerCancel={(event) => { commit(Number(event.currentTarget.value)) }}
154
+ onChange={onChange}
155
+ onKeyUp={onKeyUp}
156
+ />
157
+ <span className={css.rangeEnds} aria-hidden="true">
158
+ <span>{min}</span>
159
+ <span>{max}</span>
160
+ </span>
161
+ </div>
162
+ </div>
163
+ )
164
+ }
@@ -0,0 +1,93 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/client/settings/SegmentGroup.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * The family's segmented control: a quiet track whose options share one
4
+ * highlight that slides to the pressed option, instead of each option fading
5
+ * its own background out and the next one in. The settings fields' small
6
+ * choices and the Web Extensions TAB strip both render through it, so the two
7
+ * read as one control.
8
+ *
9
+ * The caller builds the option buttons and marks the pressed one with
10
+ * `data-active`; the group measures that button after every render and writes
11
+ * its box as four custom properties, and the stylesheet draws the highlight
12
+ * there (`.segmentGroup[data-pill]::before`). Attribute and first placement
13
+ * land in the same task, so the highlight appears in place and only later
14
+ * changes slide. A ResizeObserver re-measures when the group or an option
15
+ * changes size: a longer locale, a font arriving, a container growing, a
16
+ * strip wrapping onto a second line.
17
+ */
18
+
19
+ import { Children, useLayoutEffect, useRef, type HTMLAttributes, type ReactNode } from 'react'
20
+ import css from './settings-card.module.css'
21
+
22
+ /** The attribute marking a group whose highlight has been placed. */
23
+ const PILL_ATTR = 'data-pill'
24
+ /** The pressed option, relative to the group. */
25
+ const ACTIVE_SELECTOR = ':scope > [data-active]'
26
+ const PILL_PROPERTIES = ['--segment-pill-x', '--segment-pill-y', '--segment-pill-w', '--segment-pill-h'] as const
27
+
28
+ /** Props of {@link SegmentGroup}: the track's own attributes and the option buttons. */
29
+ export interface SegmentGroupProps extends HTMLAttributes<HTMLDivElement> {
30
+ /** The option buttons; the pressed one carries `data-active`. */
31
+ children: ReactNode
32
+ }
33
+
34
+ /**
35
+ * Write the highlight's box from the pressed option's box, or take the
36
+ * highlight off when nothing is pressed or the group has no layout yet.
37
+ * The two boxes are read in viewport pixels and turned back into the group's
38
+ * own CSS pixels, so a dialog that opens through a scale transform still
39
+ * lands the highlight on its option.
40
+ */
41
+ function placePill(group: HTMLElement): void {
42
+ const item = group.querySelector<HTMLElement>(ACTIVE_SELECTOR)
43
+ const box = group.getBoundingClientRect()
44
+ if (item === null || group.offsetWidth === 0 || box.width === 0) {
45
+ group.removeAttribute(PILL_ATTR)
46
+ for (const property of PILL_PROPERTIES) group.style.removeProperty(property)
47
+ return
48
+ }
49
+ const scale = box.width / group.offsetWidth
50
+ const itemBox = item.getBoundingClientRect()
51
+ const values = [
52
+ (itemBox.left - box.left) / scale - group.clientLeft,
53
+ (itemBox.top - box.top) / scale - group.clientTop,
54
+ itemBox.width / scale,
55
+ itemBox.height / scale,
56
+ ]
57
+ values.forEach((value, index) => {
58
+ group.style.setProperty(PILL_PROPERTIES[index], `${Math.round(value * 100) / 100}px`)
59
+ })
60
+ if (!group.hasAttribute(PILL_ATTR)) group.setAttribute(PILL_ATTR, '')
61
+ }
62
+
63
+ /**
64
+ * Render a segmented track around the caller's option buttons.
65
+ * @param props - the track's attributes (role, accessible name, key handler) and its options.
66
+ * @returns the track.
67
+ */
68
+ export function SegmentGroup(props: SegmentGroupProps): ReactNode {
69
+ const { children, className, ...rest } = props
70
+ const group = useRef<HTMLDivElement | null>(null)
71
+ const count = Children.count(children)
72
+
73
+ // Placed before the frame is painted, after every render: a press moves the
74
+ // pressed mark and the highlight follows it in the same frame.
75
+ useLayoutEffect(() => {
76
+ if (group.current !== null) placePill(group.current)
77
+ })
78
+
79
+ useLayoutEffect(() => {
80
+ const element = group.current
81
+ if (element === null || typeof ResizeObserver === 'undefined') return undefined
82
+ const observer = new ResizeObserver(() => { placePill(element) })
83
+ observer.observe(element)
84
+ for (const item of Array.from(element.children)) observer.observe(item)
85
+ return () => { observer.disconnect() }
86
+ }, [count])
87
+
88
+ return (
89
+ <div {...rest} ref={group} className={className === undefined ? css.segmentGroup : `${css.segmentGroup} ${className}`}>
90
+ {children}
91
+ </div>
92
+ )
93
+ }
@@ -22,32 +22,28 @@ export const zh = {
22
22
  'burst.line1': '三秒,三辈子的代码',
23
23
  'burst.line2': '文言文 · 二进制 · 摩斯电码',
24
24
  'settings.title': '梁神模式',
25
- 'settings.description': '控制本插件与工具面呈现方式。',
26
- 'settings.enabled': '启用梁神模式',
27
- 'settings.enabledHint': '关闭后不声明预设、也不发 agent 公告。',
28
- 'settings.announceToAgent': '向 agent 公告本插件',
29
- 'settings.announceToAgentHint': '开启后向每一轮 agent 系统提示注入本插件公告;默认关闭以保持提示词干净。',
30
- 'settings.presentation': '工具面呈现方式',
31
- 'settings.presentationHint': '写入本插件声明的预设的 tool-catalog 行:ptc(出厂默认)把 wire 收拢为 run_code,其余工具经生成的 SDK 调用;native 保持原生工具清单。改动立即生效,但已开始的会话保持其已声明的组合。',
32
- 'settings.dispatcher': '调度者身份',
33
- 'settings.dispatcherHint': '开启后本模式按调度 Agent 工作:先分诊复杂度(L0/L1 直接执行,L2 走完整流程),L2 任务先澄清访谈再规划,由主代理派发子代理并逐层审查与验收。与工具面呈现方式无关,只决定身份与流程纪律。出厂默认开启;关闭后回到仅含工作纪律的极简 persona。',
25
+ 'settings.description': '梁神模式的开关、工具面与调度身份。',
26
+ 'settings.enabled': '总开关',
27
+ 'settings.enabledHint': '关掉后不再声明预设。',
28
+ 'settings.announceToAgent': '公告给 agent',
29
+ 'settings.announceToAgentHint': '每一轮系统提示都带上本插件公告。',
30
+ 'settings.presentation': '工具面',
31
+ 'settings.presentationHint': 'ptc 把工具收进 run_code,native 保留原生清单。',
32
+ 'settings.dispatcher': '调度身份',
33
+ 'settings.dispatcherHint': '按调度 Agent 工作:分诊、访谈、派发子代理。',
34
34
  'settings.on': '开',
35
35
  'settings.off': '关',
36
- 'settings.inherit': '继承(跟随部署默认)',
37
- 'settings.overridden': '已覆盖',
38
- 'settings.reset': '重置',
39
- 'settings.notExposed': '当前 DSH 版本未向设置页暴露本插件的配置命名空间,表单不可用。可编辑 ~/.dsh/settings.yaml 直接配置,或将本命名空间加入 Host 设置白名单后重启。',
40
- 'settings.readOnly': '当前部署的设置只读。',
36
+ 'settings.inherit': '继承',
37
+ 'settings.overridden': '已修改',
38
+ 'settings.reset': '恢复默认',
39
+ 'settings.notExposed': '这个版本的 DSH 没有开放梁神模式的设置。',
40
+ 'settings.readOnly': '设置只读。',
41
41
  'settings.expand': '展开设置',
42
42
  'settings.collapse': '收起设置',
43
- 'settings.save': '保存',
44
- 'settings.saving': '保存中…',
45
- 'settings.discard': '放弃',
46
- 'settings.unsaved': '未保存',
47
- 'settings.saveFailed': '部署未接受这些值,已保留供你修改。',
48
- 'settings.invalidValue': '该取值不被接受',
49
- 'presentation.ptc': 'ptc(仅 run_code)',
50
- 'presentation.native': 'native(原生工具清单)',
43
+ 'settings.saveFailed': '没有保存成功。',
44
+ 'settings.invalidValue': '填一个可用的值。',
45
+ 'presentation.ptc': 'ptc',
46
+ 'presentation.native': 'native',
51
47
  }
52
48
 
53
49
  /** English counterpart; the key set mirrors {@link zh} exactly. */
@@ -68,32 +64,28 @@ export const en: Record<keyof typeof zh, string> = {
68
64
  'burst.line1': 'Three seconds, three lifetimes of code',
69
65
  'burst.line2': 'Classical Chinese · Binary · Morse code',
70
66
  'settings.title': 'LiangShen mode',
71
- 'settings.description': 'Controls this plugin and the wire presentation.',
72
- 'settings.enabled': 'Enable LiangShen mode',
73
- 'settings.enabledHint': 'When off, the preset is not declared and the agent announcement does not run.',
74
- 'settings.announceToAgent': 'Announce this plugin to agents',
75
- 'settings.announceToAgentHint': 'Adds this plugin announcement to every agent system prompt; off by default so prompts stay clean.',
76
- 'settings.presentation': 'Wire presentation',
77
- 'settings.presentationHint': 'Written into the tool-catalog row of the preset this plugin declares: ptc (the shipped default) collapses the wire to run_code with every other tool reached through the generated SDK; native keeps the native roster. A change re-declares the preset immediately; sessions that already started keep the composition they declared.',
78
- 'settings.dispatcher': 'Dispatcher identity',
79
- 'settings.dispatcherHint': 'When on, the mode works as a dispatcher agent: it triages complexity first (L0/L1 work is done directly, an L2 task runs the full flow), clarifies an L2 task through an interview before planning, and the lead agent dispatches subagents and reviews and accepts them layer by layer. It is unrelated to the wire presentation and decides identity and process discipline only. On by default; switching it off returns the prompt to the bare persona with its working discipline.',
67
+ 'settings.description': 'The mode switch, the wire presentation and the dispatcher identity.',
68
+ 'settings.enabled': 'Master switch',
69
+ 'settings.enabledHint': 'When off, the preset is no longer declared.',
70
+ 'settings.announceToAgent': 'Announce to agents',
71
+ 'settings.announceToAgentHint': 'Every system prompt carries this plugin note.',
72
+ 'settings.presentation': 'Wire',
73
+ 'settings.presentationHint': 'ptc folds tools into run_code; native keeps the native roster.',
74
+ 'settings.dispatcher': 'Dispatcher',
75
+ 'settings.dispatcherHint': 'Works as a dispatcher: triage, interview, then dispatch subagents.',
80
76
  'settings.on': 'On',
81
77
  'settings.off': 'Off',
82
- 'settings.inherit': 'Inherit (deployment default)',
83
- 'settings.overridden': 'Overridden',
84
- 'settings.reset': 'Reset',
85
- 'settings.notExposed': "This DSH version does not expose this plugin's settings namespace to the configuration page, so the form is unavailable. Edit ~/.dsh/settings.yaml directly, or add the namespace to the Host settings allowlist and restart.",
86
- 'settings.readOnly': 'This deployment serves settings read-only.',
78
+ 'settings.inherit': 'Inherit',
79
+ 'settings.overridden': 'Changed',
80
+ 'settings.reset': 'Reset to default',
81
+ 'settings.notExposed': 'This DSH version does not open the LiangShen settings.',
82
+ 'settings.readOnly': 'Settings are read-only.',
87
83
  'settings.expand': 'Show settings',
88
84
  'settings.collapse': 'Hide settings',
89
- 'settings.save': 'Save',
90
- 'settings.saving': 'Saving…',
91
- 'settings.discard': 'Discard',
92
- 'settings.unsaved': 'Unsaved',
93
- 'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
94
- 'settings.invalidValue': 'The value is not accepted',
95
- 'presentation.ptc': 'ptc (run_code only)',
96
- 'presentation.native': 'native (native tool roster)',
85
+ 'settings.saveFailed': 'Not saved.',
86
+ 'settings.invalidValue': 'Enter a value this field accepts.',
87
+ 'presentation.ptc': 'ptc',
88
+ 'presentation.native': 'native',
97
89
  }
98
90
 
99
91
  /** Every key in the locale catalog. */
@@ -52,6 +52,8 @@ export const FAMILY_GROUP_SERVICE = 'webUiSettings'
52
52
  export interface PluginCardSlots {
53
53
  /** Contribution of one card entry. */
54
54
  register(options: never, component: never): unknown
55
+ /** Declaration probe: a target seat may appear after this plugin applies. */
56
+ spec?(key: string): unknown
55
57
  }
56
58
 
57
59
  /** The slice of the client context a card contribution needs. */
@@ -154,6 +156,10 @@ export function installPluginCard(ctx: PluginCardContext, seat: PluginCardSeat):
154
156
  if (reconciling) return
155
157
  const target = familyGroupLoaded(ctx) ? FAMILY_PLUGIN_CARD_SEAT : OFFICIAL_PLUGIN_CARD_SEAT
156
158
  if (current === target) return
159
+ // The group's child seat can be declared after this card applies (the
160
+ // parent mounts its pages through the extension service). Wait for the
161
+ // declaration instead of logging a refused registration on every boot.
162
+ if (typeof slots.spec === 'function' && slots.spec(target) === undefined) return
157
163
  reconciling = true
158
164
  const previous = dispose
159
165
  dispose = undefined