@linxin666/dsh-liangshen 0.3.23 → 0.3.24
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/README.i18n.yaml +2 -2
- package/README.md +45 -38
- package/README.zh.md +44 -37
- package/lib/client.js +1058 -11
- package/lib/client.js.map +1 -1
- package/lib/index.js +105 -22
- package/lib/types/client/LiangShenSettingsCard.d.ts +61 -0
- package/lib/types/client/PluginSettingsCard.d.ts +133 -0
- package/lib/types/client/index.d.ts +34 -0
- package/lib/types/client/locales.d.ts +27 -1
- package/lib/types/client/plugin-card-seat.d.ts +96 -0
- package/lib/types/client/settings-form.d.ts +197 -0
- package/lib/types/core/lever.d.ts +6 -3
- package/lib/types/index.d.ts +23 -11
- package/lib/types/sync.d.ts +29 -2
- package/package.json +6 -2
- package/presets/liangshen/NOTICE +4 -4
- package/presets/liangshen/agent.cordis.yml +130 -119
- package/presets/liangshen/minimal-prompt.mjs +71 -36
- package/presets/liangshen/paging.mjs +232 -0
- package/presets/liangshen/tool-activate.mjs +176 -0
- package/presets/liangshen/tool-catalog.mjs +610 -218
- package/presets/liangshen/working-context.mjs +214 -0
- package/src/client/LiangShenLever.tsx +4 -1
- package/src/client/LiangShenSettingsCard.tsx +149 -0
- package/src/client/PluginSettingsCard.tsx +550 -0
- package/src/client/index.ts +60 -1
- package/src/client/locales.ts +53 -1
- package/src/client/plugin-card-seat.ts +185 -0
- package/src/client/settings-card.module.css +418 -0
- package/src/client/settings-form.ts +439 -0
- package/src/core/lever.ts +7 -4
- package/src/index.ts +35 -14
- package/src/sync.test.ts +86 -7
- package/src/sync.ts +108 -6
- package/tools/benchmark-live-run.mjs +24 -33
- package/presets/liangshen/custom-bash.mjs +0 -213
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["css"],"sources":["../../../packages/dsh-liangshen/src/client/LiangShenLever.tsx","../../../packages/dsh-liangshen/src/core/lever.ts","../../../packages/dsh-liangshen/src/client/lever-controller.ts","../../../packages/dsh-liangshen/src/client/locales.ts","../../../packages/dsh-liangshen/src/client/index.ts"],"sourcesContent":["/**\n * The homepage lever: a slot-machine arm beside the model selector.\n *\n * Pull it down and the session about to start becomes LiangShen mode; push it\n * up and the preset the user was on comes back. The arm tracks the real preset\n * (never a local guess), and the theatrical part — flash, shockwave, sparks,\n * and the three-language jackpot banner — plays only once the switch actually\n * landed, so a refused switch never celebrates.\n *\n * The component is pure: every fact and verb arrives through the injected face.\n * A pointer drag past {@link DRAG_THRESHOLD_PX} counts as a pull or a push; a\n * plain click or a keyboard activation toggles instead.\n */\n\nimport { useEffect, useRef, useState, useSyncExternalStore, type PointerEvent as ReactPointerEvent, type ReactElement } from 'react'\nimport type { LeverFace } from './lever-controller.ts'\nimport css from './LiangShenLever.module.css'\n\n/** Vertical travel that separates a pull or push from a plain click. */\nconst DRAG_THRESHOLD_PX = 14\n\n/** How long the burst overlay stays mounted, matching its CSS duration. */\nconst BURST_MS = 2200\n\n/** Jackpot lines that read the same in every language. */\nconst BINARY = '01001100 01001001 01000001 01001110 01000111'\nconst MORSE = '-.. . . .--. ... . . -.- / .... .- .-. -. . ... ...'\n\n/** One spark per spoke of the burst. */\nconst SPARKS = Array.from({ length: 14 }, (_, index) => index)\n\n/** Slot entry for `conversation.input.right` (left of the model selector). */\nexport function LiangShenLever(face: LeverFace): ReactElement | null {\n const snapshot = useSyncExternalStore(face.store.subscribe, face.store.getSnapshot)\n const { state, restoreLabel, busy, error, burst } = snapshot\n const [burstKey, setBurstKey] = useState(0)\n const seen = useRef(burst)\n const drag = useRef<{ y: number, fired: boolean } | undefined>(undefined)\n const actionable = !busy && (state === 'on' || state === 'off')\n const on = state === 'on'\n const errorText = error === undefined\n ? undefined\n : error.kind === 'locked'\n ? face.t('lever.failed.locked')\n : error.kind === 'missing'\n ? face.t('lever.failed.missing')\n : error.kind === 'timeout'\n ? face.t('lever.failed.timeout')\n : face.t('lever.failed.failed', { reason: error.reason })\n\n // The burst is driven by the controller's counter, so a reload or a refresh\n // can never replay it and a refused switch can never start it.\n useEffect(() => {\n if (burst > seen.current) setBurstKey(burst)\n seen.current = burst\n }, [burst])\n\n useEffect(() => {\n if (burstKey === 0) return\n const timer = setTimeout(() => { setBurstKey(0) }, BURST_MS)\n return () => { clearTimeout(timer) }\n }, [burstKey])\n\n // The lever exists only while the preset can still change, which is the\n // blank-session window: a started session reports `locked`, a deployment\n // without the preset reports `missing`, and both mean the row renders\n // nothing instead of a dead control in the composer of a running session.\n if (state === 'locked' || state === 'missing') return null\n\n const toggle = (): void => {\n if (!actionable) return\n if (on) face.push()\n else face.pull()\n }\n\n const onPointerDown = (event: ReactPointerEvent<HTMLButtonElement>): void => {\n if (!actionable) return\n drag.current = { y: event.clientY, fired: false }\n event.currentTarget.setPointerCapture?.(event.pointerId)\n }\n\n const onPointerMove = (event: ReactPointerEvent<HTMLButtonElement>): void => {\n const pending = drag.current\n if (pending === undefined || pending.fired) return\n const travel = event.clientY - pending.y\n if (travel >= DRAG_THRESHOLD_PX) {\n pending.fired = true\n face.pull()\n } else if (travel <= -DRAG_THRESHOLD_PX) {\n pending.fired = true\n face.push()\n }\n }\n\n const onPointerUp = (): void => {\n const pending = drag.current\n drag.current = undefined\n // A drag already fired its verb; a click without travel still toggles.\n if (pending === undefined || pending.fired) return\n toggle()\n }\n\n return (\n <span\n className={css.lever}\n data-dsh-plugin=\"liangshen\"\n data-dsh-part=\"lever\"\n data-state={state}\n data-busy={busy ? 'true' : undefined}\n >\n <button\n type=\"button\"\n role=\"switch\"\n aria-checked={on}\n aria-label={face.t('lever.a11y')}\n aria-busy={busy}\n title={hint(face, state, restoreLabel)}\n className={css.control}\n disabled={!actionable}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n // Keyboard and assistive activation arrives as a detail-less click;\n // pointer activation is already handled on pointerup.\n onClick={(event) => { if (event.detail === 0) toggle() }}\n >\n <span className={css.track} data-dsh-part=\"lever-track\" aria-hidden=\"true\">\n <svg className={css.arm} data-dsh-part=\"lever-arm\" viewBox=\"0 0 16 26\" aria-hidden=\"true\">\n <rect className={css.rod} x=\"6.5\" y=\"3.5\" width=\"3\" height=\"21\" rx=\"1.5\" />\n <circle className={css.knob} cx=\"8\" cy=\"4\" r=\"3.4\" />\n </svg>\n </span>\n <span className={css.readout}>{busy ? face.t('lever.busy') : on ? face.t('lever.state.on') : face.t('lever.state.off')}</span>\n </button>\n {errorText !== undefined && (\n <span className={css.error} role=\"status\" title={errorText}>{errorText}</span>\n )}\n {burstKey !== 0 && <Burst key={burstKey} face={face} />}\n </span>\n )\n}\n\n/** The hover hint: what this gesture would do right now. */\nfunction hint(face: LeverFace, state: string, restoreLabel: string): string {\n if (state === 'locked') return face.t('lever.hint.locked')\n if (state === 'missing') return face.t('lever.hint.missing')\n if (state === 'on') return face.t('lever.hint.push', { preset: restoreLabel === '' ? face.t('lever.state.off') : restoreLabel })\n return face.t('lever.hint.pull')\n}\n\n/** The jackpot overlay: flash, shockwave rings, sparks, and the banner. */\nfunction Burst({ face }: { face: LeverFace }): ReactElement {\n return (\n <span className={css.burst} data-dsh-part=\"lever-burst\" aria-hidden=\"true\">\n <span className={css.flash} />\n <span className={css.ring} />\n <span className={css.ring} />\n <span className={css.ring} />\n <span className={css.banner} data-dsh-part=\"lever-banner\">\n <span className={css.bannerName}>{face.t('lever.name')}</span>\n <span className={css.line}>{face.t('burst.line1')}</span>\n <span className={css.line}>{face.t('burst.line2')}</span>\n <span className={css.code}>{BINARY}</span>\n <span className={css.code}>{MORSE}</span>\n </span>\n <span className={css.sparks}>\n {SPARKS.map(spoke => (\n // `rotate` is its own property so the keyframes' translate runs along\n // the spoke after the rotation composes with it.\n <i key={spoke} className={css.spark} style={{ rotate: `${spoke * (360 / SPARKS.length)}deg` }} />\n ))}\n </span>\n </span>\n )\n}\n","/**\n * LiangShen lever logic — framework-free, no DOM, compiled by both programs.\n *\n * The lever is a homepage control beside the model selector: pulling it down\n * turns the current session's preset into LiangShen mode, pushing it up\n * restores the preset the user was on before. The facts it needs are the\n * current session's preset, whether that session may still change preset at\n * all, and the preset roster; the decisions are pure so they can be tested\n * without the browser runtime.\n *\n * A preset is fixed once a session starts (the host refuses the switch with\n * `agent-preset/locked`), so the lever is only meaningful while the session is\n * blank — which is exactly the new-session screen it renders on.\n */\n\n/** The preset id this lever turns on; also the preset directory name. */\nexport const LIANGSHEN_PRESET_ID = 'liangshen'\n\n/** What the lever currently reports. */\nexport type LeverState =\n /** LiangShen mode is the current preset. */\n | 'on'\n /** Another preset is current and the session may still switch. */\n | 'off'\n /** The session has started; the preset can no longer change. */\n | 'locked'\n /** The deployment does not supply the LiangShen preset. */\n | 'missing'\n\n/** The facts one lever decision reads. */\nexport interface LeverFacts {\n /** Whether the current session may still change preset (blank). */\n blank: boolean\n /** The preset the current session runs, when the session reports one. */\n agentPreset?: string\n /** Ids every usable roster row supplies, in roster order. */\n available: readonly string[]\n /** The deployment default preset id, when the roster names one. */\n fallback?: string\n /** The preset the user ran before the last pull-down, remembered by the client. */\n previous?: string\n}\n\n/** Resolve what the lever shows for one set of facts. */\nexport function leverState(facts: LeverFacts): LeverState {\n if (!facts.available.includes(LIANGSHEN_PRESET_ID)) return 'missing'\n if (!facts.blank) return 'locked'\n return facts.agentPreset === LIANGSHEN_PRESET_ID ? 'on' : 'off'\n}\n\n/**\n * The preset a push-up restores: the preset the user was on before pulling the\n * lever, else the deployment default. A candidate is skipped when it is the\n * LiangShen preset itself (restoring it would be a no-op) or when the roster\n * no longer supplies it.\n */\nexport function restoreTarget(facts: LeverFacts): string | undefined {\n for (const candidate of [facts.previous, facts.fallback]) {\n if (candidate === undefined || candidate === LIANGSHEN_PRESET_ID) continue\n if (facts.available.includes(candidate)) return candidate\n }\n return undefined\n}\n\n/** Whether the lever can act at all in its current state. */\nexport function isActionable(state: LeverState): boolean {\n return state === 'on' || state === 'off'\n}\n","/**\n * Lever controller: the business face behind the homepage lever.\n *\n * The view stays pure; every fact and verb comes from here. The roster arrives\n * over the agent-preset Remote namespace (the same one the official surfaces\n * read), the current session comes from the browser sessions service, and the\n * switch goes through `agentPresets.select`, which the host accepts only while\n * the session is still blank.\n *\n * Nothing is cached across reloads except in memory: the lever reads the\n * session's `agentPreset` projection, so a page reload still shows the true\n * state, while `previous` (the preset a push-up restores) is remembered for\n * the length of the page visit and otherwise falls back to the deployment\n * default.\n */\n\nimport type { Context as ClientContext } from '@deepseek-ai/cordis'\nimport type { AgentPresetRoster } from '@deepseek-ai/dsh-agent-presets/types'\nimport type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client'\nimport type { RemoteResult } from '@deepseek-ai/dsh-api-remotes/client'\nimport { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'\nimport { LIANGSHEN_PRESET_ID, isActionable, leverState, restoreTarget, type LeverFacts, type LeverState } from '../core/lever.ts'\nimport type { LiangShenKey } from './locales.ts'\n\n/**\n * Why the last switch was refused, mapped from the Remote failure code so the\n * view can render localized copy instead of a host message.\n */\nexport type LeverError =\n /** The session already started; its composition is fixed. */\n | { kind: 'locked' }\n /** The deployment supplies no such preset. */\n | { kind: 'missing' }\n /**\n * The switch outlived its ceiling. A Remote answer can be lost on the way\n * back even though the host committed the change, so the lever must stop\n * claiming to be busy and let the next session read report the truth.\n */\n | { kind: 'timeout' }\n /** Anything else, carrying the host's own reason. */\n | { kind: 'failed'; reason: string }\n\n/** How long one preset switch may stay in flight before it is reported as timed out. */\nexport const SELECT_TIMEOUT_MS = 10_000\n\n/** What the lever view renders. */\nexport interface LeverSnapshot {\n /** Resolved lever state. */\n state: LeverState\n /** Display name of the preset a push-up restores; empty when there is none. */\n restoreLabel: string\n /** A switch is in flight. */\n busy: boolean\n /** The last refusal, cleared by the next attempt. */\n error?: LeverError\n /** Increments when a pull-down landed, so the view replays the burst once. */\n burst: number\n}\n\n/**\n * The two agent-preset Remote calls this plugin makes. Spelled locally: the\n * generated namespace merge belongs to the SDK's own client packages, and this\n * browser bundle only needs the two members it calls.\n */\nexport interface AgentPresetRemote {\n list(): Promise<RemoteResult<AgentPresetRoster>>\n select(sessionId: string, agentPreset: string): Promise<RemoteResult<string>>\n}\n\n/** The injected face the lever view consumes. */\nexport interface LeverFace {\n /** The snapshot store the view subscribes to. */\n store: SnapshotStore<LeverSnapshot>\n /** Pull the lever down: turn LiangShen mode on. */\n pull: () => void\n /** Push the lever up: restore the previous preset. */\n push: () => void\n /** Translate one lever key. */\n t: (key: LiangShenKey, vars?: Record<string, string | number>) => string\n}\n\n/** Read the preset a session summary reports, when it reports one. */\nfunction presetOf(session: { projectionValues?: Record<string, unknown> } | undefined): string | undefined {\n const value = session?.projectionValues?.['agentPreset']\n return typeof value === 'string' ? value : undefined\n}\n\n/** The lever controller: roster read, session facts, and the preset switch. */\nexport class LeverController {\n private readonly store: SnapshotStore<LeverSnapshot>\n\n /**\n * The browser services this controller reads, resolved defensively: the\n * context proxy throws on any service the fiber did not inject, so a\n * deployment that cannot answer one of them must leave the lever inert\n * rather than take the plugin (and the composer row) down with it.\n */\n private readonly sessions: ISessions | undefined\n\n private readonly remote: AgentPresetRemote | undefined\n\n /** Roster rows as last read; empty until the first read lands. */\n private rows: AgentPresetRoster['presets'] = []\n\n /** The preset the user was on before the last pull-down. */\n private previous: string | undefined\n\n private loading = false\n\n /** Ceiling on one in-flight switch, so a lost Remote answer cannot hang the row. */\n private readonly selectTimeoutMs: number\n\n private readonly disposers: (() => void)[] = []\n\n constructor(private readonly ctx: ClientContext, options: LeverControllerOptions = {}) {\n this.selectTimeoutMs = options.selectTimeoutMs ?? SELECT_TIMEOUT_MS\n this.sessions = readService<ISessions>(() => (ctx as unknown as { sessions: ISessions }).sessions)\n this.remote = readService<AgentPresetRemote>(\n () => (ctx as unknown as { remote: { agentPresets: AgentPresetRemote } }).remote.agentPresets,\n )\n this.store = createSnapshotStore<LeverSnapshot>({\n state: 'off',\n restoreLabel: '',\n busy: false,\n burst: 0,\n })\n }\n\n /** The snapshot store the view subscribes to. */\n snapshot(): SnapshotStore<LeverSnapshot> {\n return this.store\n }\n\n /** Follow the roster and the current session, then read the roster once. */\n start(): void {\n const list = this.sessions?.list\n if (list !== undefined) {\n this.disposers.push(list.subscribe(() => { this.refresh() }))\n }\n const remote = readService<{ $on?: (event: string, listener: (ns: string) => void) => () => void }>(\n () => (this.ctx as unknown as { remote: { $on: (event: string, listener: (ns: string) => void) => () => void } }).remote,\n )\n if (typeof remote?.$on === 'function') {\n this.disposers.push(remote.$on('settings/document-updated', (ns: string) => {\n if (ns === 'agent-presets') void this.load()\n }))\n }\n this.refresh()\n if (this.remote !== undefined) void this.load()\n }\n\n /** Release every subscription. Idempotent. */\n dispose(): void {\n for (const dispose of this.disposers.splice(0)) dispose()\n }\n\n /** The inject face handed to the slot entry. */\n face(): LeverFace {\n return {\n store: this.store,\n pull: () => { void this.toggle('down') },\n push: () => { void this.toggle('up') },\n t: (key, vars) => {\n const translate = readService<(key: LiangShenKey, vars?: Record<string, string | number>) => string>(\n () => this.ctx.locale.bind('liangshen'),\n )\n return translate === undefined ? key : translate(key, vars)\n },\n }\n }\n\n /** Read the roster; a refusal leaves the lever as it was. */\n async load(): Promise<void> {\n if (this.loading) return\n const remote = this.remote\n if (remote === undefined) return\n this.loading = true\n try {\n const result = await remote.list()\n if (result.ok) this.rows = result.value.presets\n } catch {\n // A carrier failure leaves the roster empty; the view reports `missing`.\n } finally {\n this.loading = false\n this.refresh()\n }\n }\n\n /**\n * Recompute the snapshot from the current session and the last roster read.\n * Only the derived fields are written: an in-flight switch, the last refusal,\n * and the burst counter belong to the gesture, not to a session refresh.\n */\n refresh(): void {\n const facts = this.facts()\n const snapshot = this.store.getSnapshot()\n const state = leverState(facts)\n const target = restoreTarget(facts)\n const restoreLabel = target === undefined ? '' : this.labelOf(target)\n if (snapshot.state === state && snapshot.restoreLabel === restoreLabel) return\n this.store.set({ ...snapshot, state, restoreLabel })\n }\n\n /** The verb behind one gesture direction. */\n private async toggle(direction: 'down' | 'up'): Promise<void> {\n const snapshot = this.store.getSnapshot()\n if (snapshot.busy) return\n const remote = this.remote\n if (remote === undefined) return\n const facts = this.facts()\n if (!isActionable(leverState(facts))) return\n const target = direction === 'down' ? LIANGSHEN_PRESET_ID : restoreTarget(facts)\n const sessionId = this.currentSessionId()\n if (target === undefined || sessionId === undefined) return\n if (facts.agentPreset === target) {\n // Already there: a gesture on the current state is a no-op, not a switch.\n this.refresh()\n return\n }\n this.store.set({ ...snapshot, busy: true, error: undefined })\n let result: RemoteResult<string>\n try {\n result = await withTimeout(remote.select(sessionId, target), this.selectTimeoutMs)\n } catch (error) {\n // A timeout is its own copy: the host may well have committed the change\n // even though its answer never arrived, so this reports the wait, and the\n // next session read (or the next gesture) shows what actually happened.\n const mapped: LeverError = error instanceof SwitchTimeout\n ? { kind: 'timeout' }\n : { kind: 'failed', reason: message(error) }\n this.store.set({ ...this.store.getSnapshot(), busy: false, error: mapped })\n this.refresh()\n return\n }\n if (!result.ok) {\n this.store.set({ ...this.store.getSnapshot(), busy: false, error: refusal(result.error) })\n this.refresh()\n return\n }\n // The switch landed: remember where to return, then celebrate only the\n // pull that turned the mode on.\n this.previous = direction === 'down' ? facts.agentPreset : undefined\n const next = this.store.getSnapshot()\n this.store.set({ ...next, busy: false, error: undefined, burst: direction === 'down' ? next.burst + 1 : next.burst })\n this.refresh()\n }\n\n /** The facts one decision reads, from the live session and the roster. */\n private facts(): LeverFacts {\n const summary = this.currentSession()\n const available = this.rows.filter(row => row.broken === undefined).map(row => row.id)\n const fallback = this.rows.find(row => row.isDefault)?.id\n return {\n blank: summary?.blank === true,\n agentPreset: presetOf(summary),\n available,\n fallback,\n previous: this.previous,\n }\n }\n\n private currentSessionId(): string | undefined {\n const current = this.sessions?.list.getSnapshot().current\n return current === undefined ? undefined : String(current)\n }\n\n private currentSession(): { blank?: boolean, projectionValues?: Record<string, unknown> } | undefined {\n const state = this.sessions?.list.getSnapshot()\n const current = state?.current\n if (state === undefined || current === undefined) return undefined\n return state.byId[current] as unknown as { blank?: boolean, projectionValues?: Record<string, unknown> } | undefined\n }\n\n /** Display name of one preset id, falling back to the id itself. */\n private labelOf(id: string): string {\n const row = this.rows.find(candidate => candidate.id === id)\n return row?.name ?? id\n }\n}\n\n/** The face constructor options; tests narrow the switch ceiling. */\nexport interface LeverControllerOptions {\n /** Override {@link SELECT_TIMEOUT_MS}. */\n selectTimeoutMs?: number\n}\n\n/** Raised when one switch outlives {@link SELECT_TIMEOUT_MS}. */\nclass SwitchTimeout extends Error {\n constructor() {\n super('the preset switch did not answer in time')\n this.name = 'SwitchTimeout'\n }\n}\n\n/** Resolve with `work`, or reject with a {@link SwitchTimeout} after `ms`. */\nfunction withTimeout<T>(work: Promise<T>, ms: number): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => { reject(new SwitchTimeout()) }, ms)\n work.then(\n (value) => { clearTimeout(timer); resolve(value) },\n (error: unknown) => { clearTimeout(timer); reject(error instanceof Error ? error : new Error(String(error))) },\n )\n })\n}\n\n/**\n * Read one context service, treating the proxy's \"without inject\" refusal (and\n * any other resolution fault) as the service being absent.\n */\nfunction readService<T>(read: () => T): T | undefined {\n try {\n return read()\n } catch {\n return undefined\n }\n}\n\n/** The host's own reason for a refusal, mapped to lever copy. */\nfunction refusal(error: { code?: string, message?: string, details?: unknown }): LeverError {\n if (error.code === 'agent-preset/locked') return { kind: 'locked' }\n if (error.code === 'agent-preset/not-found') return { kind: 'missing' }\n const details = error.details\n if (typeof details === 'object' && details !== null && typeof (details as { reason?: unknown }).reason === 'string') {\n return { kind: 'failed', reason: (details as { reason: string }).reason }\n }\n return { kind: 'failed', reason: error.message ?? error.code ?? 'unknown' }\n}\n\nfunction message(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n","/**\n * Lever copy: zh-first dictionary with an English counterpart. The zh side is\n * the key-set source of truth; `packages/dsh-i18n` mirrors the keys into the\n * centralized ru dictionary and `pnpm i18n:check` enforces the parity.\n */\n\n/** Lever copy, key source of truth. */\nexport const zh = {\n 'lever.a11y': '梁神模式拨杆',\n 'lever.name': '梁神模式',\n 'lever.hint.pull': '拨下拨杆:开启「梁神模式」',\n 'lever.hint.push': '上拨拨杆:返回「{preset}」',\n 'lever.hint.locked': '会话已开始,模式不可再更改',\n 'lever.hint.missing': '未找到「梁神模式」预设,请先启用该插件行',\n 'lever.state.on': '梁神模式',\n 'lever.state.off': '普通模式',\n 'lever.busy': '正在切换…',\n 'lever.failed.locked': '会话已经开始,模式已锁定',\n 'lever.failed.missing': '没有找到「梁神模式」预设',\n 'lever.failed.timeout': '切换超时,请重试',\n 'lever.failed.failed': '切换失败:{reason}',\n 'burst.line1': '三秒,三辈子的代码',\n 'burst.line2': '文言文 · 二进制 · 摩斯电码',\n}\n\n/** English counterpart; the key set mirrors {@link zh} exactly. */\nexport const en: Record<keyof typeof zh, string> = {\n 'lever.a11y': 'LiangShen mode lever',\n 'lever.name': 'LiangShen mode',\n 'lever.hint.pull': 'Pull the lever down to turn on LiangShen mode',\n 'lever.hint.push': 'Push the lever up to return to \"{preset}\"',\n 'lever.hint.locked': 'The session has started, so its mode can no longer change',\n 'lever.hint.missing': 'The LiangShen preset is not installed; enable that plugin row first',\n 'lever.state.on': 'LiangShen',\n 'lever.state.off': 'Standard',\n 'lever.busy': 'Switching…',\n 'lever.failed.locked': 'The session already started, so the mode is locked',\n 'lever.failed.missing': 'The LiangShen preset was not found',\n 'lever.failed.timeout': 'The switch timed out; try again',\n 'lever.failed.failed': 'Switch failed: {reason}',\n 'burst.line1': 'Three seconds, three lifetimes of code',\n 'burst.line2': 'Classical Chinese · Binary · Morse code',\n}\n\n/** One lever copy key. */\nexport type LiangShenKey = keyof typeof zh\n","/**\n * dsh-liangshen browser half: the LiangShen lever in the composer tool row.\n *\n * The slot is `conversation.input.right` — \"compact controls before the\n * composer submit action\", which renders immediately left of the model\n * selector (`conversation.input.model`) inside the same composer card, on the\n * homepage's new-session hero as well as in a session. The lever lives only\n * while the session is still blank, because that is the only window in which a\n * preset can change at all: `agentPresets.select` refuses an already-started\n * session, and the arm would have nothing to do in one.\n *\n * This half talks to the host over the agent-preset Remote namespace rather\n * than through the official preset package's browser module: cross-plugin\n * collaboration here goes through cordis services and Remote surfaces, not\n * value imports.\n *\n * Failure policy: a missing slot or a refused Remote call is handled, never\n * thrown — one external plugin must not take the GUI boot down.\n */\n\nimport type { Context as ClientContext } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-client-ui-renderer/client'\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\n// Type-only: pulls the ui-conversation SlotMap merge (the composer tool row).\nimport type {} from '@deepseek-ai/dsh-client-ui-conversation/client'\nimport type {} from '@deepseek-ai/dsh-client-ui-slots'\nimport { LiangShenLever } from './LiangShenLever.tsx'\nimport { LeverController } from './lever-controller.ts'\nimport { en, zh, type LiangShenKey } from './locales.ts'\n\n/** Locale namespace this half owns. */\nexport const NS = 'liangshen'\n\n/**\n * Required client services: the slot registry, locale, sessions, and the roster\n * Remote. Both `remote` and `remote.agentPresets` are declared: the context\n * proxy refuses an uninjected service, and a nested service name does not imply\n * its parent, so reading `ctx.remote.agentPresets` needs `remote` as well.\n */\nexport const inject = ['slots', 'locale', 'sessions', 'remote', 'remote.agentPresets']\n\ndeclare module '@deepseek-ai/dsh-client-ui-slots' {\n interface LocaleNamespaceMap {\n /** The LiangShen lever copy. */\n 'liangshen': LiangShenKey\n }\n}\n\nexport { LiangShenLever } from './LiangShenLever.tsx'\nexport { LeverController, type LeverFace, type LeverSnapshot } from './lever-controller.ts'\nexport { LIANGSHEN_PRESET_ID, leverState, restoreTarget, type LeverFacts, type LeverState } from '../core/lever.ts'\n\n/**\n * Mount the lever: register the copy, follow the roster and the current\n * session, and claim the composer tool row.\n * @param ctx - the browser plugin context.\n */\nexport function apply(ctx: ClientContext): void {\n ctx.effect(() => {\n try {\n return ctx.locale.register(NS, { zh, en })\n } catch {\n return () => {}\n }\n }, 'liangshen: lever dictionaries')\n\n const controller = new LeverController(ctx)\n ctx.effect(() => () => controller.dispose(), 'liangshen: lever controller')\n try {\n controller.start()\n } catch {\n // An unavailable sessions or Remote service leaves the lever inert; the\n // view still renders and reports what it knows.\n }\n\n ctx.slots.inject('conversation.input.right', () => {\n try {\n const unregister = ctx.slots.register({\n name: 'conversation.input.right',\n id: 'liangshen-lever',\n order: 20,\n inject: () => controller.face(),\n }, LiangShenLever)\n return () => { unregister() }\n } catch {\n return () => {}\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBA,MAAM,oBAAoB;;EAG1B,MAAM,WAAW;;EAGjB,MAAM,SAAS;EACf,MAAM,QAAQ;;EAGd,MAAM,SAAS,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,KAAK;;EAG7D,SAAgB,eAAe,MAAsC;GAEnE,MAAM,EAAE,OAAO,cAAc,MAAM,OAAO,WAAA,GAAA,MAAA,qBAAA,CADJ,KAAK,MAAM,WAAW,KAAK,MAAM,WACZ;GAC3D,MAAM,CAAC,UAAU,gBAAA,GAAA,MAAA,SAAA,CAAwB,CAAC;GAC1C,MAAM,QAAA,GAAA,MAAA,OAAA,CAAc,KAAK;GACzB,MAAM,QAAA,GAAA,MAAA,OAAA,CAAyD,KAAA,CAAS;GACxE,MAAM,aAAa,CAAC,SAAS,UAAU,QAAQ,UAAU;GACzD,MAAM,KAAK,UAAU;GACrB,MAAM,YAAY,UAAU,KAAA,IACxB,KAAA,IACA,MAAM,SAAS,WACb,KAAK,EAAE,qBAAqB,IAC5B,MAAM,SAAS,YACb,KAAK,EAAE,sBAAsB,IAC7B,MAAM,SAAS,YACb,KAAK,EAAE,sBAAsB,IAC7B,KAAK,EAAE,uBAAuB,EAAE,QAAQ,MAAM,OAAO,CAAC;GAIhE,CAAA,GAAA,MAAA,UAAA,OAAgB;IACd,IAAI,QAAQ,K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IAC3C,QAAQ;KACN,aAAa,CAAC;IAChB;GACF,GAAG,+BAA+B;GAElC,MAAM,aAAa,IAAI,gBAAgB,GAAG;GAC1C,IAAI,mBAAmB,WAAW,QAAQ,GAAG,6BAA6B;GAC1E,IAAI;IACF,WAAW,MAAM;GACnB,QAAQ,CAGR;GAEA,IAAI,MAAM,OAAO,kCAAkC;IACjD,IAAI;KACF,MAAM,aAAa,IAAI,MAAM,SAAS;MACpC,MAAM;MACN,IAAI;MACJ,OAAO;MACP,cAAc,WAAW,KAAK;KAChC,GAAG,cAAc;KACjB,aAAa;MAAE,WAAW;KAAE;IAC9B,QAAQ;KACN,aAAa,CAAC;IAChB;GACF,CAAC;EACH"}
|
|
1
|
+
{"version":3,"file":"client.js","names":["css","css"],"sources":["../../../packages/dsh-liangshen/src/client/LiangShenLever.tsx","../../../packages/dsh-liangshen/src/core/lever.ts","../../../packages/dsh-liangshen/src/client/lever-controller.ts","../../../packages/dsh-liangshen/src/client/PluginSettingsCard.tsx","../../../packages/dsh-liangshen/src/client/settings-form.ts","../../../packages/dsh-liangshen/src/client/LiangShenSettingsCard.tsx","../../../packages/dsh-liangshen/src/client/locales.ts","../../../packages/dsh-liangshen/src/client/plugin-card-seat.ts","../../../packages/dsh-liangshen/src/client/index.ts"],"sourcesContent":["/**\n * The homepage lever: a slot-machine arm beside the model selector.\n *\n * Pull it down and the session about to start becomes LiangShen mode; push it\n * up and the preset the user was on comes back. The arm tracks the real preset\n * (never a local guess), and the theatrical part — flash, shockwave, sparks,\n * and the three-language jackpot banner — plays only once the switch actually\n * landed, so a refused switch never celebrates.\n *\n * The component is pure: every fact and verb arrives through the injected face.\n * A pointer drag past {@link DRAG_THRESHOLD_PX} counts as a pull or a push; a\n * plain click or a keyboard activation toggles instead.\n */\n\nimport { useEffect, useRef, useState, useSyncExternalStore, type PointerEvent as ReactPointerEvent, type ReactElement } from 'react'\nimport type { LeverFace } from './lever-controller.ts'\nimport css from './LiangShenLever.module.css'\n\n/** Vertical travel that separates a pull or push from a plain click. */\nconst DRAG_THRESHOLD_PX = 14\n\n/** How long the burst overlay stays mounted, matching its CSS duration. */\nconst BURST_MS = 2200\n\n/** Jackpot lines that read the same in every language. */\nconst BINARY = '01001100 01001001 01000001 01001110 01000111'\nconst MORSE = '-.. . . .--. ... . . -.- / .... .- .-. -. . ... ...'\n\n/** One spark per spoke of the burst. */\nconst SPARKS = Array.from({ length: 14 }, (_, index) => index)\n\n/** Slot entry for `conversation.input.right` (left of the model selector). */\nexport function LiangShenLever(face: LeverFace): ReactElement | null {\n const snapshot = useSyncExternalStore(face.store.subscribe, face.store.getSnapshot)\n const { state, restoreLabel, busy, error, burst } = snapshot\n const [burstKey, setBurstKey] = useState(0)\n const seen = useRef(burst)\n const drag = useRef<{ y: number, fired: boolean } | undefined>(undefined)\n const actionable = !busy && (state === 'on' || state === 'off')\n const on = state === 'on'\n const errorText = error === undefined\n ? undefined\n : error.kind === 'locked'\n ? face.t('lever.failed.locked')\n : error.kind === 'missing'\n ? face.t('lever.failed.missing')\n : error.kind === 'timeout'\n ? face.t('lever.failed.timeout')\n : face.t('lever.failed.failed', { reason: error.reason })\n\n // The burst is driven by the controller's counter, so a reload or a refresh\n // can never replay it and a refused switch can never start it.\n useEffect(() => {\n if (burst > seen.current) setBurstKey(burst)\n seen.current = burst\n }, [burst])\n\n useEffect(() => {\n if (burstKey === 0) return\n const timer = setTimeout(() => { setBurstKey(0) }, BURST_MS)\n return () => { clearTimeout(timer) }\n }, [burstKey])\n\n // The lever exists only while the preset can still change, which is the\n // blank-session window: a started session reports `locked`, a deployment\n // without the preset reports `missing`, and both mean the row renders\n // nothing instead of a dead control in the composer of a running session.\n // An `on` lever with an empty restore label has nothing to return to either\n // (the roster supplies no other usable preset), so a push there would be the\n // same dead control: render nothing rather than a switch that eats gestures.\n if (state === 'locked' || state === 'missing' || (state === 'on' && restoreLabel === '')) return null\n\n const toggle = (): void => {\n if (!actionable) return\n if (on) face.push()\n else face.pull()\n }\n\n const onPointerDown = (event: ReactPointerEvent<HTMLButtonElement>): void => {\n if (!actionable) return\n drag.current = { y: event.clientY, fired: false }\n event.currentTarget.setPointerCapture?.(event.pointerId)\n }\n\n const onPointerMove = (event: ReactPointerEvent<HTMLButtonElement>): void => {\n const pending = drag.current\n if (pending === undefined || pending.fired) return\n const travel = event.clientY - pending.y\n if (travel >= DRAG_THRESHOLD_PX) {\n pending.fired = true\n face.pull()\n } else if (travel <= -DRAG_THRESHOLD_PX) {\n pending.fired = true\n face.push()\n }\n }\n\n const onPointerUp = (): void => {\n const pending = drag.current\n drag.current = undefined\n // A drag already fired its verb; a click without travel still toggles.\n if (pending === undefined || pending.fired) return\n toggle()\n }\n\n return (\n <span\n className={css.lever}\n data-dsh-plugin=\"liangshen\"\n data-dsh-part=\"lever\"\n data-state={state}\n data-busy={busy ? 'true' : undefined}\n >\n <button\n type=\"button\"\n role=\"switch\"\n aria-checked={on}\n aria-label={face.t('lever.a11y')}\n aria-busy={busy}\n title={hint(face, state, restoreLabel)}\n className={css.control}\n disabled={!actionable}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n // Keyboard and assistive activation arrives as a detail-less click;\n // pointer activation is already handled on pointerup.\n onClick={(event) => { if (event.detail === 0) toggle() }}\n >\n <span className={css.track} data-dsh-part=\"lever-track\" aria-hidden=\"true\">\n <svg className={css.arm} data-dsh-part=\"lever-arm\" viewBox=\"0 0 16 26\" aria-hidden=\"true\">\n <rect className={css.rod} x=\"6.5\" y=\"3.5\" width=\"3\" height=\"21\" rx=\"1.5\" />\n <circle className={css.knob} cx=\"8\" cy=\"4\" r=\"3.4\" />\n </svg>\n </span>\n <span className={css.readout}>{busy ? face.t('lever.busy') : on ? face.t('lever.state.on') : face.t('lever.state.off')}</span>\n </button>\n {errorText !== undefined && (\n <span className={css.error} role=\"status\" title={errorText}>{errorText}</span>\n )}\n {burstKey !== 0 && <Burst key={burstKey} face={face} />}\n </span>\n )\n}\n\n/** The hover hint: what this gesture would do right now. */\nfunction hint(face: LeverFace, state: string, restoreLabel: string): string {\n if (state === 'locked') return face.t('lever.hint.locked')\n if (state === 'missing') return face.t('lever.hint.missing')\n if (state === 'on') return face.t('lever.hint.push', { preset: restoreLabel === '' ? face.t('lever.state.off') : restoreLabel })\n return face.t('lever.hint.pull')\n}\n\n/** The jackpot overlay: flash, shockwave rings, sparks, and the banner. */\nfunction Burst({ face }: { face: LeverFace }): ReactElement {\n return (\n <span className={css.burst} data-dsh-part=\"lever-burst\" aria-hidden=\"true\">\n <span className={css.flash} />\n <span className={css.ring} />\n <span className={css.ring} />\n <span className={css.ring} />\n <span className={css.banner} data-dsh-part=\"lever-banner\">\n <span className={css.bannerName}>{face.t('lever.name')}</span>\n <span className={css.line}>{face.t('burst.line1')}</span>\n <span className={css.line}>{face.t('burst.line2')}</span>\n <span className={css.code}>{BINARY}</span>\n <span className={css.code}>{MORSE}</span>\n </span>\n <span className={css.sparks}>\n {SPARKS.map(spoke => (\n // `rotate` is its own property so the keyframes' translate runs along\n // the spoke after the rotation composes with it.\n <i key={spoke} className={css.spark} style={{ rotate: `${spoke * (360 / SPARKS.length)}deg` }} />\n ))}\n </span>\n </span>\n )\n}\n","/**\n * LiangShen lever logic — framework-free, no DOM, compiled by both programs.\n *\n * The lever is a homepage control beside the model selector: pulling it down\n * turns the current session's preset into LiangShen mode, pushing it up\n * restores the preset the user was on before. The facts it needs are the\n * current session's preset, whether that session may still change preset at\n * all, and the preset roster; the decisions are pure so they can be tested\n * without the browser runtime.\n *\n * A preset is fixed once a session starts (the host refuses the switch with\n * `agent-preset/locked`), so the lever is only meaningful while the session is\n * blank — which is exactly the new-session screen it renders on.\n */\n\n/** The preset id this lever turns on; also the preset directory name. */\nexport const LIANGSHEN_PRESET_ID = 'liangshen'\n\n/** What the lever currently reports. */\nexport type LeverState =\n /** LiangShen mode is the current preset. */\n | 'on'\n /** Another preset is current and the session may still switch. */\n | 'off'\n /** The session has started; the preset can no longer change. */\n | 'locked'\n /** The deployment does not supply the LiangShen preset. */\n | 'missing'\n\n/** The facts one lever decision reads. */\nexport interface LeverFacts {\n /** Whether the current session may still change preset (blank). */\n blank: boolean\n /** The preset the current session runs, when the session reports one. */\n agentPreset?: string\n /** Ids every usable roster row supplies, in roster order. */\n available: readonly string[]\n /** The deployment default preset id, when the roster names one. */\n fallback?: string\n /** The preset the user ran before the last pull-down, remembered by the client. */\n previous?: string\n}\n\n/** Resolve what the lever shows for one set of facts. */\nexport function leverState(facts: LeverFacts): LeverState {\n if (!facts.available.includes(LIANGSHEN_PRESET_ID)) return 'missing'\n if (!facts.blank) return 'locked'\n return facts.agentPreset === LIANGSHEN_PRESET_ID ? 'on' : 'off'\n}\n\n/**\n * The preset a push-up restores: the preset the user was on before pulling the\n * lever, else the deployment default, else the first usable roster row that is\n * not the LiangShen preset. A candidate is skipped when it is the LiangShen\n * preset itself (restoring it would be a no-op) or when the roster no longer\n * supplies it. That last resort is what keeps the push direction alive when the\n * deployment default IS LiangShen mode: `fallback` is skipped then, and after a\n * reload `previous` is gone, so without it the gesture would have no target.\n */\nexport function restoreTarget(facts: LeverFacts): string | undefined {\n for (const candidate of [facts.previous, facts.fallback]) {\n if (candidate === undefined || candidate === LIANGSHEN_PRESET_ID) continue\n if (facts.available.includes(candidate)) return candidate\n }\n return facts.available.find(candidate => candidate !== LIANGSHEN_PRESET_ID)\n}\n\n/** Whether the lever can act at all in its current state. */\nexport function isActionable(state: LeverState): boolean {\n return state === 'on' || state === 'off'\n}\n","/**\n * Lever controller: the business face behind the homepage lever.\n *\n * The view stays pure; every fact and verb comes from here. The roster arrives\n * over the agent-preset Remote namespace (the same one the official surfaces\n * read), the current session comes from the browser sessions service, and the\n * switch goes through `agentPresets.select`, which the host accepts only while\n * the session is still blank.\n *\n * Nothing is cached across reloads except in memory: the lever reads the\n * session's `agentPreset` projection, so a page reload still shows the true\n * state, while `previous` (the preset a push-up restores) is remembered for\n * the length of the page visit and otherwise falls back to the deployment\n * default.\n */\n\nimport type { Context as ClientContext } from '@deepseek-ai/cordis'\nimport type { AgentPresetRoster } from '@deepseek-ai/dsh-agent-presets/types'\nimport type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client'\nimport type { RemoteResult } from '@deepseek-ai/dsh-api-remotes/client'\nimport { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'\nimport { LIANGSHEN_PRESET_ID, isActionable, leverState, restoreTarget, type LeverFacts, type LeverState } from '../core/lever.ts'\nimport type { LiangShenKey } from './locales.ts'\n\n/**\n * Why the last switch was refused, mapped from the Remote failure code so the\n * view can render localized copy instead of a host message.\n */\nexport type LeverError =\n /** The session already started; its composition is fixed. */\n | { kind: 'locked' }\n /** The deployment supplies no such preset. */\n | { kind: 'missing' }\n /**\n * The switch outlived its ceiling. A Remote answer can be lost on the way\n * back even though the host committed the change, so the lever must stop\n * claiming to be busy and let the next session read report the truth.\n */\n | { kind: 'timeout' }\n /** Anything else, carrying the host's own reason. */\n | { kind: 'failed'; reason: string }\n\n/** How long one preset switch may stay in flight before it is reported as timed out. */\nexport const SELECT_TIMEOUT_MS = 10_000\n\n/** What the lever view renders. */\nexport interface LeverSnapshot {\n /** Resolved lever state. */\n state: LeverState\n /** Display name of the preset a push-up restores; empty when there is none. */\n restoreLabel: string\n /** A switch is in flight. */\n busy: boolean\n /** The last refusal, cleared by the next attempt. */\n error?: LeverError\n /** Increments when a pull-down landed, so the view replays the burst once. */\n burst: number\n}\n\n/**\n * The two agent-preset Remote calls this plugin makes. Spelled locally: the\n * generated namespace merge belongs to the SDK's own client packages, and this\n * browser bundle only needs the two members it calls.\n */\nexport interface AgentPresetRemote {\n list(): Promise<RemoteResult<AgentPresetRoster>>\n select(sessionId: string, agentPreset: string): Promise<RemoteResult<string>>\n}\n\n/** The injected face the lever view consumes. */\nexport interface LeverFace {\n /** The snapshot store the view subscribes to. */\n store: SnapshotStore<LeverSnapshot>\n /** Pull the lever down: turn LiangShen mode on. */\n pull: () => void\n /** Push the lever up: restore the previous preset. */\n push: () => void\n /** Translate one lever key. */\n t: (key: LiangShenKey, vars?: Record<string, string | number>) => string\n}\n\n/** Read the preset a session summary reports, when it reports one. */\nfunction presetOf(session: { projectionValues?: Record<string, unknown> } | undefined): string | undefined {\n const value = session?.projectionValues?.['agentPreset']\n return typeof value === 'string' ? value : undefined\n}\n\n/** The lever controller: roster read, session facts, and the preset switch. */\nexport class LeverController {\n private readonly store: SnapshotStore<LeverSnapshot>\n\n /**\n * The browser services this controller reads, resolved defensively: the\n * context proxy throws on any service the fiber did not inject, so a\n * deployment that cannot answer one of them must leave the lever inert\n * rather than take the plugin (and the composer row) down with it.\n */\n private readonly sessions: ISessions | undefined\n\n private readonly remote: AgentPresetRemote | undefined\n\n /** Roster rows as last read; empty until the first read lands. */\n private rows: AgentPresetRoster['presets'] = []\n\n /** The preset the user was on before the last pull-down. */\n private previous: string | undefined\n\n private loading = false\n\n /** Ceiling on one in-flight switch, so a lost Remote answer cannot hang the row. */\n private readonly selectTimeoutMs: number\n\n private readonly disposers: (() => void)[] = []\n\n constructor(private readonly ctx: ClientContext, options: LeverControllerOptions = {}) {\n this.selectTimeoutMs = options.selectTimeoutMs ?? SELECT_TIMEOUT_MS\n this.sessions = readService<ISessions>(() => (ctx as unknown as { sessions: ISessions }).sessions)\n this.remote = readService<AgentPresetRemote>(\n () => (ctx as unknown as { remote: { agentPresets: AgentPresetRemote } }).remote.agentPresets,\n )\n this.store = createSnapshotStore<LeverSnapshot>({\n state: 'off',\n restoreLabel: '',\n busy: false,\n burst: 0,\n })\n }\n\n /** The snapshot store the view subscribes to. */\n snapshot(): SnapshotStore<LeverSnapshot> {\n return this.store\n }\n\n /** Follow the roster and the current session, then read the roster once. */\n start(): void {\n const list = this.sessions?.list\n if (list !== undefined) {\n this.disposers.push(list.subscribe(() => { this.refresh() }))\n }\n const remote = readService<{ $on?: (event: string, listener: (ns: string) => void) => () => void }>(\n () => (this.ctx as unknown as { remote: { $on: (event: string, listener: (ns: string) => void) => () => void } }).remote,\n )\n if (typeof remote?.$on === 'function') {\n this.disposers.push(remote.$on('settings/document-updated', (ns: string) => {\n if (ns === 'agent-presets') void this.load()\n }))\n }\n this.refresh()\n if (this.remote !== undefined) void this.load()\n }\n\n /** Release every subscription. Idempotent. */\n dispose(): void {\n for (const dispose of this.disposers.splice(0)) dispose()\n }\n\n /** The inject face handed to the slot entry. */\n face(): LeverFace {\n return {\n store: this.store,\n pull: () => { void this.toggle('down') },\n push: () => { void this.toggle('up') },\n t: (key, vars) => {\n const translate = readService<(key: LiangShenKey, vars?: Record<string, string | number>) => string>(\n () => this.ctx.locale.bind('liangshen'),\n )\n return translate === undefined ? key : translate(key, vars)\n },\n }\n }\n\n /** Read the roster; a refusal leaves the lever as it was. */\n async load(): Promise<void> {\n if (this.loading) return\n const remote = this.remote\n if (remote === undefined) return\n this.loading = true\n try {\n const result = await remote.list()\n if (result.ok) this.rows = result.value.presets\n } catch {\n // A carrier failure leaves the roster empty; the view reports `missing`.\n } finally {\n this.loading = false\n this.refresh()\n }\n }\n\n /**\n * Recompute the snapshot from the current session and the last roster read.\n * Only the derived fields are written: an in-flight switch, the last refusal,\n * and the burst counter belong to the gesture, not to a session refresh.\n */\n refresh(): void {\n const facts = this.facts()\n const snapshot = this.store.getSnapshot()\n const state = leverState(facts)\n const target = restoreTarget(facts)\n const restoreLabel = target === undefined ? '' : this.labelOf(target)\n if (snapshot.state === state && snapshot.restoreLabel === restoreLabel) return\n this.store.set({ ...snapshot, state, restoreLabel })\n }\n\n /** The verb behind one gesture direction. */\n private async toggle(direction: 'down' | 'up'): Promise<void> {\n const snapshot = this.store.getSnapshot()\n if (snapshot.busy) return\n const remote = this.remote\n if (remote === undefined) return\n const facts = this.facts()\n if (!isActionable(leverState(facts))) return\n const target = direction === 'down' ? LIANGSHEN_PRESET_ID : restoreTarget(facts)\n const sessionId = this.currentSessionId()\n if (target === undefined || sessionId === undefined) return\n if (facts.agentPreset === target) {\n // Already there: a gesture on the current state is a no-op, not a switch.\n this.refresh()\n return\n }\n this.store.set({ ...snapshot, busy: true, error: undefined })\n let result: RemoteResult<string>\n try {\n result = await withTimeout(remote.select(sessionId, target), this.selectTimeoutMs)\n } catch (error) {\n // A timeout is its own copy: the host may well have committed the change\n // even though its answer never arrived, so this reports the wait, and the\n // next session read (or the next gesture) shows what actually happened.\n const mapped: LeverError = error instanceof SwitchTimeout\n ? { kind: 'timeout' }\n : { kind: 'failed', reason: message(error) }\n this.store.set({ ...this.store.getSnapshot(), busy: false, error: mapped })\n this.refresh()\n return\n }\n if (!result.ok) {\n this.store.set({ ...this.store.getSnapshot(), busy: false, error: refusal(result.error) })\n this.refresh()\n return\n }\n // The switch landed: remember where to return, then celebrate only the\n // pull that turned the mode on.\n this.previous = direction === 'down' ? facts.agentPreset : undefined\n const next = this.store.getSnapshot()\n this.store.set({ ...next, busy: false, error: undefined, burst: direction === 'down' ? next.burst + 1 : next.burst })\n this.refresh()\n }\n\n /** The facts one decision reads, from the live session and the roster. */\n private facts(): LeverFacts {\n const summary = this.currentSession()\n const available = this.rows.filter(row => row.broken === undefined).map(row => row.id)\n const fallback = this.rows.find(row => row.isDefault)?.id\n return {\n blank: summary?.blank === true,\n agentPreset: presetOf(summary),\n available,\n fallback,\n previous: this.previous,\n }\n }\n\n private currentSessionId(): string | undefined {\n const current = this.sessions?.list.getSnapshot().current\n return current === undefined ? undefined : String(current)\n }\n\n private currentSession(): { blank?: boolean, projectionValues?: Record<string, unknown> } | undefined {\n const state = this.sessions?.list.getSnapshot()\n const current = state?.current\n if (state === undefined || current === undefined) return undefined\n return state.byId[current] as unknown as { blank?: boolean, projectionValues?: Record<string, unknown> } | undefined\n }\n\n /** Display name of one preset id, falling back to the id itself. */\n private labelOf(id: string): string {\n const row = this.rows.find(candidate => candidate.id === id)\n return row?.name ?? id\n }\n}\n\n/** The face constructor options; tests narrow the switch ceiling. */\nexport interface LeverControllerOptions {\n /** Override {@link SELECT_TIMEOUT_MS}. */\n selectTimeoutMs?: number\n}\n\n/** Raised when one switch outlives {@link SELECT_TIMEOUT_MS}. */\nclass SwitchTimeout extends Error {\n constructor() {\n super('the preset switch did not answer in time')\n this.name = 'SwitchTimeout'\n }\n}\n\n/** Resolve with `work`, or reject with a {@link SwitchTimeout} after `ms`. */\nfunction withTimeout<T>(work: Promise<T>, ms: number): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => { reject(new SwitchTimeout()) }, ms)\n work.then(\n (value) => { clearTimeout(timer); resolve(value) },\n (error: unknown) => { clearTimeout(timer); reject(error instanceof Error ? error : new Error(String(error))) },\n )\n })\n}\n\n/**\n * Read one context service, treating the proxy's \"without inject\" refusal (and\n * any other resolution fault) as the service being absent.\n */\nfunction readService<T>(read: () => T): T | undefined {\n try {\n return read()\n } catch {\n return undefined\n }\n}\n\n/** The host's own reason for a refusal, mapped to lever copy. */\nfunction refusal(error: { code?: string, message?: string, details?: unknown }): LeverError {\n if (error.code === 'agent-preset/locked') return { kind: 'locked' }\n if (error.code === 'agent-preset/not-found') return { kind: 'missing' }\n const details = error.details\n if (typeof details === 'object' && details !== null && typeof (details as { reason?: unknown }).reason === 'string') {\n return { kind: 'failed', reason: (details as { reason: string }).reason }\n }\n return { kind: 'failed', reason: error.message ?? error.code ?? 'unknown' }\n}\n\nfunction message(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n","// Generated by scripts/sync-shared.mjs from shared/client/settings/PluginSettingsCard.tsx. Do not edit this copy; edit the shared source and run \"node scripts/sync-shared.mjs\".\n/**\n * Family-shared chrome for plugin settings cards: a disclosure header naming\n * the plugin and what its settings govern, the controls inside, and the save\n * that writes them. Renders nothing while the namespace is unavailable — a\n * deployment that does not compose the owning plugin should show no trace of\n * it. Inlined into each consumer's client bundle; mirrors the official\n * ui-plugin-config PluginCard in a self-contained slice.\n */\n\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'\nimport type { CardShell } from './settings-form.ts'\nimport css from './settings-card.module.css'\n\n/** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */\nexport const CARD_COPY_KEYS = [\n 'settings.collapse',\n 'settings.expand',\n 'settings.notExposed',\n 'settings.unsaved',\n 'settings.readOnly',\n 'settings.saveFailed',\n 'settings.discard',\n 'settings.save',\n 'settings.saving',\n] as const\n\n/** Copy key the card chrome itself reads. */\nexport type CardCopyKey = (typeof CARD_COPY_KEYS)[number]\n\n/** Key domain for the plugin's own copy (inferred per consumer). */\nexport type SettingsCardKey<TKey extends string = string> = TKey | CardCopyKey\n\n/** Card chrome shared by every plugin settings card. */\nexport interface PluginSettingsCardProps<TKey extends string = string> {\n /** Locale reader for this card's copy. */\n t: (key: SettingsCardKey<TKey>, params?: Record<string, string | number>) => string\n /** Locale key of the plugin's name. */\n titleKey: TKey\n /** Locale key of the line describing what this plugin's settings govern. */\n descriptionKey: TKey\n /** Optional rich header description rendered instead of the plain t(descriptionKey) text (the plain text stays as the tooltip). */\n descriptionNode?: ReactNode\n /** The card's form state: availability, writability, and what a save would do. */\n state: CardShell\n /** Write every staged edit. */\n onSave: () => void\n /** Drop every staged edit. */\n onDiscard: () => void\n /**\n * Render the controls expanded on arrival (still collapsible). Defaults to\n * true: promoted first-level sections show their settings immediately.\n */\n defaultOpen?: boolean\n /**\n * Render without the collapse affordance: a static header and an always\n * visible body. Used by first-level settings sections whose nav entry\n * already provides the selection.\n */\n alwaysOpen?: boolean\n /**\n * Hide the save/discard footer: cards whose body applies its own changes\n * immediately (an embedded external settings section) have no staged\n * edits, so the footer would sit there permanently disabled.\n */\n hideFooter?: boolean\n /** The plugin's controls. */\n children: ReactNode\n}\n\n/**\n * Render one plugin settings card.\n * @param props - the plugin's copy keys, its form state, and its controls.\n * @returns the card, or nothing while the namespace is still loading.\n */\nexport function PluginSettingsCard<TKey extends string = string>(props: PluginSettingsCardProps<TKey>) {\n const [open, setOpen] = useState(props.defaultOpen ?? true)\n const { state, alwaysOpen } = props\n if (!state.available) return null\n const title = props.t(props.titleKey)\n const description = props.t(props.descriptionKey)\n const blocked = !state.dirty || state.invalid || state.saving\n const expanded = alwaysOpen === true || open\n const cardClass = expanded ? `${css.cardOpen} ${css.card}` : css.card\n // With alwaysOpen the nav entry already provides the selection, so the\n // header is a static title row instead of a disclosure button.\n const header = alwaysOpen === true\n ? (\n <div className={css.headerStatic}>\n <span className={css.headText}>\n <span className={css.name} title={title}>{title}</span>\n <span className={css.description} title={description}>{props.descriptionNode ?? description}</span>\n </span>\n {state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}\n </div>\n )\n : (\n <button\n type=\"button\"\n className={css.header}\n aria-expanded={open}\n aria-label={`${props.t(open ? 'settings.collapse' : 'settings.expand')}: ${title}`}\n onClick={() => { setOpen(!open) }}\n >\n <span className={css.headText}>\n <span className={css.name} title={title}>{title}</span>\n <span className={css.description} title={description}>{props.descriptionNode ?? description}</span>\n </span>\n {state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 14 14\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className={open ? `${css.chevron} ${css.chevronOpen}` : css.chevron}\n >\n <path\n d=\"M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z\"\n fill=\"currentColor\"\n />\n </svg>\n </button>\n )\n // The namespace exists but the Host does not serve it to this client (the\n // official settings allowlist omits third-party namespaces): show a card\n // that explains the gap instead of vanishing, so a missing card never\n // reads as a missing plugin.\n if (!state.exposed) {\n return (\n <li className={cardClass}>\n {header}\n {expanded\n ? (\n <div className={css.body}>\n <p className={css.notExposed} role=\"status\">{props.t('settings.notExposed')}</p>\n </div>\n )\n : null}\n </li>\n )\n }\n return (\n <li className={cardClass}>\n {header}\n {expanded\n ? (\n <div className={css.body}>\n {!state.writable ? <p className={css.readOnly} role=\"status\">{props.t('settings.readOnly')}</p> : null}\n {props.children}\n {props.hideFooter === true\n ? null\n : (\n <div className={css.footer}>\n {state.failed\n ? (\n <p className={css.failed} role=\"status\">\n {props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}\n </p>\n )\n : null}\n <button\n type=\"button\"\n className={css.discard}\n disabled={!state.dirty || state.saving}\n onClick={props.onDiscard}\n >\n {props.t('settings.discard')}\n </button>\n <button\n type=\"button\"\n className={css.save}\n disabled={blocked}\n onClick={props.onSave}\n >\n {props.t(!state.saving ? 'settings.save' : 'settings.saving')}\n </button>\n </div>\n )}\n </div>\n )\n : null}\n </li>\n )\n}\n\n/** Props every field control needs regardless of its value type. */\nexport interface FieldProps {\n /** Stable id associating the label with its control. */\n id: string\n /** Visible label. */\n label: string\n /** One-line explanation rendered under the control. */\n hint: string\n /** Draft text this control renders. */\n text: string\n /** True when saving would leave a user-layer entry for this field. */\n overridden: boolean\n /** True when the draft is not a value this field accepts. */\n invalid: boolean\n /** Copy for the overridden badge. */\n overriddenLabel: string\n /** Copy for the reset control. */\n resetLabel: string\n /** Copy shown in place of the hint while the draft is invalid. */\n invalidLabel: string\n /** Disables every control (read-only document, or an unavailable namespace). */\n disabled: boolean\n /** Stage draft text. */\n onEdit: (text: string) => void\n /** Stage a clear so the field re-inherits the composition layer. */\n onReset: () => void\n}\n\n/** A staged value field. `numeric` only hints the keypad: which drafts a field accepts is decided by its spec. */\nexport function ValueField(props: FieldProps & {\n /** Hints a numeric keypad without narrowing what the control accepts. */\n numeric?: boolean\n /** Placeholder shown while the draft is empty. */\n placeholder?: string\n}) {\n return (\n <div className={css.field}>\n <div className={css.head}>\n <label className={css.label} htmlFor={props.id}>{props.label}</label>\n {props.overridden\n ? (\n <span className={css.badges}>\n <span className={css.badge}>{props.overriddenLabel}</span>\n <button\n type=\"button\"\n className={css.reset}\n disabled={props.disabled}\n onClick={props.onReset}\n >\n {props.resetLabel}\n </button>\n </span>\n )\n : null}\n </div>\n <input\n id={props.id}\n className={props.invalid ? css.inputInvalid : css.input}\n type=\"text\"\n {...props.numeric === true ? { inputMode: 'numeric' as const } : {}}\n {...props.invalid ? { 'aria-invalid': true } : {}}\n value={props.text}\n placeholder={props.placeholder ?? ''}\n disabled={props.disabled}\n onChange={(event) => { props.onEdit(event.target.value) }}\n />\n <p className={props.invalid ? css.invalid : css.hint}>\n {props.invalid ? props.invalidLabel : props.hint}\n </p>\n </div>\n )\n}\n\nconst NON_SKIN_BODY_MARKERS = new Set(['dshSkinCenter', 'dshSidebarCollapsed'])\n// 检测使用使用皮肤,用了皮肤退回原生select样式,防止样式冲突。默认外观下使用优化后的select样式。\nfunction isSkinActive(): boolean {\n const datasetList = Object.keys(document.body.dataset)\n const isActive = datasetList.some(key => key.startsWith('dsh') && !NON_SKIN_BODY_MARKERS.has(key))\n return isActive\n}\n\ninterface SelectOption {\n value: string\n label: string\n}\n\nconst SELECT_CLOSE_MS = 100\n\n/**\n * The shared dual-mode select control. While an appearance skin is active it\n * renders the legacy native `<select>` untouched, so element-level skin\n * selectors keep working; under the default appearance it renders a\n * self-drawn `role=\"listbox\"` popup whose open/close is transition-animated.\n * Staged cards reach it through BooleanField/ChoiceField; immediate-apply\n * editors (the side-card prefs) bind it directly through onEdit.\n * 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。\n */\nexport function SelectField(props: {\n id: string\n options: ReadonlyArray<SelectOption>\n value: string\n disabled: boolean\n invalid: boolean\n onEdit: (text: string) => void\n}) {\n const { id, options, value } = props\n const [open, setOpen] = useState(false)\n const [closing, setClosing] = useState(false)\n const [phase, setPhase] = useState<'initial' | 'open'>('initial')\n const [activeIndex, setActiveIndex] = useState(0)\n const closeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n const wrapRef = useRef<HTMLDivElement | null>(null)\n const popupRef = useRef<HTMLDivElement | null>(null)\n\n const currentIndex = () => {\n const index = options.findIndex(option => option.value === value)\n return index >= 0 ? index : 0\n }\n\n const close = useCallback(() => {\n if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)\n setClosing(true)\n closeTimer.current = setTimeout(() => {\n setClosing(false)\n setOpen(false)\n }, SELECT_CLOSE_MS)\n }, [])\n\n const openPopup = () => {\n if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)\n setActiveIndex(currentIndex())\n setPhase('initial')\n setClosing(false)\n setOpen(true)\n }\n\n const commit = (index: number) => {\n const option = options[index]\n if (option) props.onEdit(option.value)\n close()\n }\n\n const onTriggerClick = () => {\n if (props.disabled) return\n if (open && !closing) close()\n else openPopup()\n }\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (props.disabled) return\n const count = options.length\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n case 'Enter':\n case ' ':\n event.preventDefault()\n if (!open) {\n openPopup()\n } else if (!closing) {\n if (event.key === 'ArrowDown') setActiveIndex(index => (index + 1) % count)\n else if (event.key === 'ArrowUp') setActiveIndex(index => (index - 1 + count) % count)\n else commit(activeIndex)\n }\n break\n case 'Escape':\n if (open) {\n event.preventDefault()\n event.stopPropagation()\n close()\n }\n break\n case 'Tab':\n if (open) close()\n break\n }\n }\n\n useEffect(() => () => {\n if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)\n }, [])\n useLayoutEffect(() => {\n if (open && !closing && phase === 'initial') {\n void popupRef.current?.offsetHeight\n setPhase('open')\n }\n }, [open, closing, phase])\n\n useEffect(() => {\n if (!open) return\n const onPointerDown = (event: PointerEvent) => {\n const target = event.target\n if (target instanceof Node && !wrapRef.current?.contains(target)) close()\n }\n document.addEventListener('pointerdown', onPointerDown)\n return () => document.removeEventListener('pointerdown', onPointerDown)\n }, [open, close])\n\n useEffect(() => {\n if (props.disabled && open) close()\n }, [props.disabled, open, close])\n\n // 使用了皮肤则退回原生select样式防止样式冲突。\n if (isSkinActive()) {\n return (\n <select\n id={id}\n className={css.select}\n value={value}\n disabled={props.disabled}\n onChange={(event) => { props.onEdit(event.target.value) }}\n >\n {options.map(option => (\n <option key={option.value} value={option.value}>{option.label}</option>\n ))}\n </select>\n )\n }\n\n const label = options.find(option => option.value === value)?.label ?? ''\n const popupClass = closing\n ? `${css.selectPopup} ${css.selectPopupClose}`\n : phase === 'open'\n ? `${css.selectPopup} ${css.selectPopupOpen}`\n : css.selectPopup\n return (\n <div className={css.selectWrap} ref={wrapRef}>\n <button\n type=\"button\"\n id={id}\n className={`${css.select} ${css.selectButton}`}\n disabled={props.disabled}\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-activedescendant={open ? `${id}-o${activeIndex}` : undefined}\n aria-invalid={props.invalid || undefined}\n onClick={onTriggerClick}\n onKeyDown={onKeyDown}\n >\n <span className={css.selectLabel}>{label}</span>\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 14 14\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className={open ? `${css.selectChevron} ${css.selectChevronOpen}` : css.selectChevron}\n aria-hidden=\"true\"\n >\n <path\n d=\"M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z\"\n fill=\"currentColor\"\n />\n </svg>\n </button>\n {open\n ? (\n <div className={popupClass} role=\"listbox\" ref={popupRef}>\n {options.map((option, index) => (\n <div\n key={option.value}\n id={`${id}-o${index}`}\n role=\"option\"\n aria-selected={option.value === value}\n className={`${css.selectOption}${option.value === value ? ` ${css.selectOptionSelected}` : ''}${index === activeIndex && !closing ? ` ${css.selectOptionActive}` : ''}`}\n onClick={() => { commit(index) }}\n >\n {option.label}\n </div>\n ))}\n </div>\n )\n : null}\n </div>\n )\n}\n\n/** A staged boolean field: 继承 / 开 / 关. */\nexport function BooleanField(props: FieldProps & {\n /** Copy for the inherit option. */\n inheritLabel: string\n /** Copy for the on option. */\n onLabel: string\n /** Copy for the off option. */\n offLabel: string\n}) {\n return (\n <div className={css.field}>\n <div className={css.head}>\n <label className={css.label} htmlFor={props.id}>{props.label}</label>\n {props.overridden\n ? (\n <span className={css.badges}>\n <span className={css.badge}>{props.overriddenLabel}</span>\n <button\n type=\"button\"\n className={css.reset}\n disabled={props.disabled}\n onClick={props.onReset}\n >\n {props.resetLabel}\n </button>\n </span>\n )\n : null}\n </div>\n <SelectField\n id={props.id}\n options={[\n { value: '', label: props.inheritLabel },\n { value: 'true', label: props.onLabel },\n { value: 'false', label: props.offLabel },\n ]}\n value={props.text}\n disabled={props.disabled}\n invalid={props.invalid}\n onEdit={props.onEdit}\n />\n <p className={css.hint}>{props.hint}</p>\n </div>\n )\n}\n\n/** A staged enumerated field rendered as a select. */\nexport function ChoiceField(props: FieldProps & {\n /** Copy for the inherit option (draft text is the empty string). */\n inheritLabel: string\n /** Choices rendered in order; `value` is the draft/stored text. */\n choices: ReadonlyArray<{ value: string; label: string }>\n}) {\n return (\n <div className={css.field}>\n <div className={css.head}>\n <label className={css.label} htmlFor={props.id}>{props.label}</label>\n {props.overridden\n ? (\n <span className={css.badges}>\n <span className={css.badge}>{props.overriddenLabel}</span>\n <button\n type=\"button\"\n className={css.reset}\n disabled={props.disabled}\n onClick={props.onReset}\n >\n {props.resetLabel}\n </button>\n </span>\n )\n : null}\n </div>\n <SelectField\n id={props.id}\n options={[{ value: '', label: props.inheritLabel }, ...props.choices]}\n value={props.text}\n disabled={props.disabled}\n invalid={props.invalid}\n onEdit={props.onEdit}\n />\n <p className={props.invalid ? css.invalid : css.hint}>\n {props.invalid ? props.invalidLabel : props.hint}\n </p>\n </div>\n )\n}\n","// Generated by scripts/sync-shared.mjs from shared/client/settings/settings-form.ts. Do not edit this copy; edit the shared source and run \"node scripts/sync-shared.mjs\".\n/**\n * Staged form model behind the plugin settings card. A card stages what the\n * user types and writes it only when they save — the settings write is a\n * durable, revision-fenced document mutation, so staging keeps what is on\n * screen exactly what a save would store. Family-shared slice inlined into\n * each plugin's client bundle; mirrors the official ui-plugin-config\n * card-store pattern.\n */\n\nimport type { SettingsScope, SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'\nimport type { SnapshotStore } from '@deepseek-ai/dsh-client-store'\nimport { createSnapshotStore } from '@deepseek-ai/dsh-client-store'\n\n/** The write one field's staged text performs when the card is saved. */\nexport type FieldWrite =\n | { kind: 'set'; value: unknown }\n | { kind: 'clear' }\n\n/** How one field converts between its stored value and its draft text. */\nexport interface FieldSpec {\n /** Field name inside the namespace section. */\n field: string\n /**\n * Whether the Host treats this field as a secret and redacts its value from\n * the read-back (role('secret') in the section schema). Redacted secrets are\n * never compared against the draft on save: the Host strips them from every\n * wire view layer, so the settled snapshot carries nothing to read back. A\n * staged secret set is judged by the mutation settling; the rest of its\n * batch, when one exists, is still judged by read-back, and the atomic\n * mutation lands every write or none.\n */\n secret?: boolean\n /** Render a stored value as draft text; the empty string when the section carries none. */\n format: (value: unknown) => string\n /**\n * The write this draft text stages, or undefined when the text is not a\n * value this field accepts — which blocks the save rather than discarding it.\n */\n parse: (text: string) => FieldWrite | undefined\n}\n\n/** One field as the card renders it. */\nexport interface FieldState {\n /** Draft text the control renders. */\n text: string\n /** Whether saving would leave a user-layer entry for this field. */\n overridden: boolean\n /** Whether the draft is not a value this field accepts, which blocks saving. */\n invalid: boolean\n}\n\n/** Form state every plugin settings card shares. */\nexport interface CardShell {\n /** False while the namespace is still loading; the card renders nothing. */\n available: boolean\n /**\n * Whether the namespace is actually served to this client. False when the\n * Host deployment does not expose it (e.g. the owning plugin's settings\n * domain is not mounted): the card renders an explanation\n * instead of its form, so a missing namespace never looks like a missing\n * plugin.\n */\n exposed: boolean\n /** Whether the Host document accepts writes. */\n writable: boolean\n /** Whether the form holds edits that a save would write. */\n dirty: boolean\n /** Whether any staged draft is invalid, which blocks the save. */\n invalid: boolean\n /** Whether a save is crossing the wire. */\n saving: boolean\n /** Whether the last save did not land as staged; cleared by the next edit or save. */\n failed: boolean\n /**\n * The rejection code/message the Host returned for the last failed save,\n * surfaced next to the generic failure text. Undefined while no save has\n * failed (or the failure carried no server reason).\n */\n failedReason?: string\n}\n\n/** The write actions the card's slot entry injects. */\nexport interface CardActions {\n /** Stage draft text for one field. */\n edit: (field: string, text: string) => void\n /** Stage a clear, so saving lets the field re-inherit the composition layer. */\n resetField: (field: string) => void\n /** Write every staged edit, then re-seed from what the Host accepted. */\n save: () => void\n /** Drop every staged edit. */\n discard: () => void\n}\n\n/** One field's staged edit. */\ninterface StagedEdit {\n /** Draft text the control renders. */\n text: string\n /** True when this edit clears the field whatever text it shows. */\n clear: boolean\n}\n\n/** One staged edit resolved into the write a save performs. */\ninterface PlannedWrite {\n /** Field this entry writes. */\n field: string\n /** The durable write this entry performs, inside the save's one atomic mutation. */\n op: BatchedWrite\n /**\n * Read the settled snapshot back and report whether the Host holds this\n * write's effect. Undefined when the draft is not a value the field\n * accepts: there is nothing to write, and the entry blocks the save.\n */\n judge: (() => boolean) | undefined\n}\n\n/** One durable write inside the save's atomic scope mutation. */\nexport interface BatchedWrite {\n /** Field this entry writes. */\n field: string\n /** set stores a value; unset drops the leaf. */\n op: 'set' | 'unset'\n /** Value for op set (absent for unset). */\n value?: unknown\n}\n\n/** Constraints a numeric field's accepted drafts must satisfy, mirroring the host schema. */\nexport interface NumberConstraints {\n /** The accepted value must be a whole number. */\n integer?: boolean\n /** The accepted value must be at least this. */\n min?: number\n}\n\n/** A whole- or decimal-number field. An empty draft clears the field; any other draft that is not a finite number within the constraints blocks the save. */\nexport function numberField(field: string, constraints: NumberConstraints = {}): FieldSpec {\n const { integer = false, min } = constraints\n return {\n field,\n format: value => typeof value === 'number' ? String(value) : '',\n parse: (text) => {\n const trimmed = text.trim()\n if (trimmed === '') return { kind: 'clear' }\n const parsed = Number(trimmed)\n if (!Number.isFinite(parsed)) return undefined\n if (integer && !Number.isInteger(parsed)) return undefined\n if (min !== undefined && parsed < min) return undefined\n return { kind: 'set', value: parsed }\n },\n }\n}\n\n/** A free-text field. An empty draft clears the field. */\nexport function textField(field: string): FieldSpec {\n return {\n field,\n format: value => typeof value === 'string' ? value : '',\n parse: (text) => {\n const trimmed = text.trim()\n return trimmed === '' ? { kind: 'clear' } : { kind: 'set', value: trimmed }\n },\n }\n}\n\n/**\n * A free-text field the Host treats as a secret and redacts from the read-back\n * (role('secret') in the section schema). The card still edits it like text,\n * but a save never compares the redacted value back: the staged set is judged\n * by the mutation settling (see {@link FieldSpec.secret}).\n */\nexport function secretField(field: string): FieldSpec {\n return { ...textField(field), secret: true }\n}\n\n/** A boolean field, edited through true/false draft text. */\nexport function booleanField(field: string): FieldSpec {\n return {\n field,\n format: value => typeof value === 'boolean' ? String(value) : '',\n parse: (text) => {\n const trimmed = text.trim()\n if (trimmed === '') return { kind: 'clear' }\n if (trimmed === 'true') return { kind: 'set', value: true }\n if (trimmed === 'false') return { kind: 'set', value: false }\n return undefined\n },\n }\n}\n\n/** An enumerated string field; only the listed choices are accepted. An empty draft clears the field. */\nexport function choiceField(field: string, choices: readonly string[]): FieldSpec {\n return {\n field,\n format: value => typeof value === 'string' && choices.includes(value) ? value : '',\n parse: (text) => {\n if (text === '') return { kind: 'clear' }\n return choices.includes(text) ? { kind: 'set', value: text } : undefined\n },\n }\n}\n\n/**\n * Stages one card's edits over one settings namespace and writes them on save.\n *\n * The Host is the only authority on whether a value was accepted — its\n * validators own the constraints no schema can express — so the outcome is\n * read back from the section rather than predicted here. A save that did not\n * land keeps its drafts, so the user can correct them instead of retyping.\n */\nexport class CardForm<T> {\n private readonly specs: Map<string, FieldSpec>\n private readonly staged = new Map<string, StagedEdit>()\n private readonly listeners = new Set<() => void>()\n /** The scope subscription installed in the constructor; released by dispose(). */\n private readonly disposeScope: () => void\n private disposed = false\n private saving = false\n private failed = false\n private failedReason: string | undefined\n\n /** @param scope - the bound settings scope for this card's namespace. */\n constructor(\n private readonly scope: SettingsScope<T>,\n specs: FieldSpec[],\n ) {\n this.specs = new Map(specs.map(spec => [spec.field, spec]))\n this.disposeScope = scope.subscribe(() => { this.publish() })\n }\n\n /**\n * Release the scope subscription and every bound store listener. The card\n * must call this on teardown; later calls are no-ops.\n */\n dispose(): void {\n if (this.disposed) return\n this.disposed = true\n this.disposeScope()\n this.listeners.clear()\n }\n\n /** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */\n bind<S>(project: () => S): SnapshotStore<S> {\n const store = createSnapshotStore(project())\n this.listeners.add(() => { store.set(project()) })\n return store\n }\n\n /** Read the card-level state: what the Host serves, and what a save would do. */\n shell(): CardShell {\n const snapshot = this.scope.getSnapshot()\n const plan = this.plan()\n return {\n available: snapshot.status !== 'loading',\n exposed: snapshot.status === 'ready',\n writable: snapshot.writable,\n dirty: plan.length > 0,\n invalid: plan.some(item => item.judge === undefined),\n saving: this.saving,\n failed: this.failed,\n ...this.failedReason === undefined ? {} : { failedReason: this.failedReason },\n }\n }\n\n /** Read one field's state from the effective section and its staged draft. */\n field(field: string): FieldState {\n const spec = this.specOf(field)\n const staged = this.staged.get(field)\n if (staged === undefined) {\n return { text: spec.format(this.sectionValue(field)), overridden: this.stored(field), invalid: false }\n }\n const write = staged.clear ? { kind: 'clear' as const } : spec.parse(staged.text)\n return {\n text: staged.text,\n overridden: write?.kind === 'set',\n invalid: write === undefined,\n }\n }\n\n /** The actions the card's slot registration injects. */\n actions(): CardActions {\n return {\n edit: (field, text) => { this.stage(field, { text, clear: false }) },\n resetField: (field) => {\n this.stage(field, { text: this.specOf(field).format(this.baseValue(field)), clear: true })\n },\n save: () => { void this.save() },\n discard: () => {\n if (this.staged.size === 0 && !this.failed) return\n this.staged.clear()\n this.failed = false\n this.failedReason = undefined\n this.publish()\n },\n }\n }\n\n /**\n * Write every staged edit in one atomic scope mutation, then re-seed from\n * what the Host accepted.\n *\n * The whole batch rides one mutate, so cross-field validate hooks\n * (baseURL+model) judge it as a unit: the Host either applies every write\n * or refuses the batch. The 0.1.2 scope contract never rejects a refused\n * mutation — the scope recovers with a fresh Host view and resolves — so\n * resolution alone proves nothing: the outcome is judged by reading the\n * settled snapshot back, one planned write at a time, and one missed write\n * fails the whole save. A scope that still rejects on refusal (the dsh-web\n * bridge scope) reports through the same failure path with its rejection\n * message. A save that did not land keeps its drafts, so the user can\n * correct them instead of retyping.\n * @returns settlement after the mutation and the read-back.\n */\n async save(): Promise<void> {\n const plan = this.plan()\n const valid = plan.filter((item): item is PlannedWrite & { judge: () => boolean } => item.judge !== undefined)\n if (plan.length === 0 || this.saving || valid.length !== plan.length) return\n // Snapshot the staged entries this save writes, so an edit staged while it\n // is in flight (which replaces the same key) survives: only delete the key\n // when the entry is still the one this save started from.\n const pending = new Map<string, StagedEdit | undefined>()\n for (const item of plan) pending.set(item.field, this.staged.get(item.field))\n this.saving = true\n this.failed = false\n this.failedReason = undefined\n this.publish()\n // One atomic namespace mutation: the 0.1.2 scope contract takes ordered\n // path operations, so the whole staged batch is validated, persisted, and\n // recovered together — either every write lands or none does.\n const ops: Array<{ op: 'set'; path: string[]; value: string | number | boolean } | { op: 'unset'; path: string[] }> = valid.map(item => item.op.op === 'set'\n ? { op: 'set', path: [item.field], value: (item.op as { value: string | number | boolean }).value }\n : { op: 'unset', path: [item.field] })\n let failedReason: string | undefined\n try {\n await this.scope.mutate(ops)\n } catch (error) {\n failedReason = error instanceof Error ? error.message : String(error)\n }\n // The 0.1.2 scope resolves even a refused mutation (it recovers with a\n // fresh view instead of throwing), so resolution alone proves nothing:\n // judge every planned write against the settled snapshot. The mutation is\n // atomic, so one missed write fails the whole save and keeps the drafts.\n const landed = failedReason === undefined && valid.every(item => item.judge())\n for (const [field, before] of pending) {\n if (landed && this.staged.get(field) === before) this.staged.delete(field)\n }\n this.saving = false\n this.failed = !landed\n // A read-back failure carries no server reason: the card surfaces its\n // generic failure copy; a rejecting scope (the bridge) adds its message.\n this.failedReason = failedReason\n this.publish()\n }\n\n /**\n * Every staged edit a save would write. An entry whose draft is not a value\n * its field accepts carries no write: the form is still dirty, and the save\n * refuses rather than dropping the edit. A staged edit that matches the\n * effective section is not a write at all.\n * @returns the planned writes, in the order the fields were staged.\n */\n private plan(): PlannedWrite[] {\n const plan: PlannedWrite[] = []\n for (const [field, staged] of this.staged) {\n const spec = this.specOf(field)\n if (staged.clear) {\n if (this.stored(field)) plan.push({ field, op: { field, op: 'unset' }, judge: () => this.landedUnset(field) })\n continue\n }\n if (staged.text === spec.format(this.sectionValue(field))) continue\n const write = spec.parse(staged.text)\n if (write === undefined) plan.push({ field, op: { field, op: 'unset' }, judge: undefined })\n else if (write.kind === 'clear') plan.push({ field, op: { field, op: 'unset' }, judge: () => this.landedUnset(field) })\n else plan.push({ field, op: { field, op: 'set', value: write.value }, judge: () => this.landedSet(field, write.value) })\n }\n return plan\n }\n\n /**\n * Read-back judgment for a planned set: the user layer must hold the\n * intended value once the mutation has settled.\n */\n private landedSet(field: string, value: unknown): boolean {\n // A redacted secret never appears in any wire view layer: the Host strips\n // role('secret') fields and reports them through a sidecar the scope\n // snapshot does not expose, so there is nothing to compare the draft\n // against. Settling is the only signal the form has; the rest of the\n // batch, when one exists, still carries the atomic verdict by read-back.\n if (this.specOf(field).secret) return true\n return this.userLayer()?.[field] === value\n }\n\n /**\n * Read-back judgment for a planned unset: the field must be gone from the\n * user layer once the mutation has settled.\n */\n private landedUnset(field: string): boolean {\n return !this.stored(field)\n }\n\n private stage(field: string, edit: StagedEdit): void {\n this.staged.set(field, edit)\n this.failed = false\n this.failedReason = undefined\n this.publish()\n }\n\n private specOf(field: string): FieldSpec {\n const spec = this.specs.get(field)\n // Every call site names a field this card declared; a missing one is a\n // wiring mistake that must not degrade into a silently inert control.\n if (spec === undefined) throw new Error(`settings card has no field ${field}`)\n return spec\n }\n\n private snapshotOf(): SettingsScopeSnapshot<T> {\n return this.scope.getSnapshot()\n }\n\n private sectionValue(field: string): unknown {\n return (this.snapshotOf().value as Record<string, unknown> | undefined)?.[field]\n }\n\n private baseValue(field: string): unknown {\n return (this.snapshotOf().base as Record<string, unknown> | undefined)?.[field]\n }\n\n private userLayer(): Record<string, unknown> | undefined {\n return this.snapshotOf().user as Record<string, unknown> | undefined\n }\n\n private stored(field: string): boolean {\n const user = this.userLayer()\n return user !== undefined && Object.hasOwn(user, field)\n }\n\n private publish(): void {\n for (const listener of this.listeners) listener()\n }\n}\n","/**\n * LiangShen settings card: availability and the wire presentation. Registers\n * into the `web-ui.plugin.item` child slot the Web UI plugin group renders,\n * bound to the `dsh-liangshen` namespace.\n *\n * The presentation field does not act on this client half: the Host writes it\n * into the synced preset composition, so a session reads it from its preset.\n * This card is the operator's only handle on it, which is why every field the\n * Host schema carries appears here.\n */\n\nimport type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'\nimport type { SnapshotStore } from '@deepseek-ai/dsh-client-store'\nimport type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'\nimport { BooleanField, ChoiceField, PluginSettingsCard } from './PluginSettingsCard.tsx'\nimport { CardForm, booleanField, choiceField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'\n\n/** Wire presentations the tool catalog accepts (mirrors the Host schema). */\nexport const PRESENTATION_CHOICES = ['ptc', 'native', 'both'] as const\n\n/** The LiangShen fields this card edits (the namespace's full schema). */\nexport interface LiangShenSettings {\n /** Master switch for the plugin. */\n enabled?: boolean\n /** Whether the plugin announces itself in every agent's system prompt. */\n announceToAgent?: boolean\n /** Wire presentation written into the synced preset. */\n presentation?: string\n}\n\n/** What the LiangShen card renders. */\nexport interface LiangShenSettingsCardState extends CardShell {\n enabled: CardFieldState\n announceToAgent: CardFieldState\n presentation: CardFieldState\n}\n\n/** The registration-side face the card's slot entry injects. */\nexport interface LiangShenSettingsCardFace extends CardActions {\n hooks: {\n /** Card snapshot bound by the renderer as useLiangShenSettingsCard. */\n liangShenSettingsCard: SnapshotStore<LiangShenSettingsCardState>\n }\n}\n\n/** Bridges the `dsh-liangshen` scope onto the card's staged form. */\nexport class LiangShenSettingsCardController {\n private readonly form: CardForm<LiangShenSettings>\n private readonly store: SnapshotStore<LiangShenSettingsCardState>\n\n /** @param scope - the bound settings scope for the `dsh-liangshen` namespace. */\n constructor(scope: SettingsScope<LiangShenSettings>) {\n this.form = new CardForm(scope, [\n booleanField('enabled'),\n booleanField('announceToAgent'),\n choiceField('presentation', PRESENTATION_CHOICES),\n ])\n this.store = this.form.bind(() => this.projection())\n }\n\n private projection(): LiangShenSettingsCardState {\n return {\n ...this.form.shell(),\n enabled: this.form.field('enabled'),\n announceToAgent: this.form.field('announceToAgent'),\n presentation: this.form.field('presentation'),\n }\n }\n\n /**\n * Build the face the card's slot registration injects.\n * @returns the card's snapshot and its form actions.\n */\n inject(): LiangShenSettingsCardFace {\n return { hooks: { liangShenSettingsCard: this.store }, ...this.form.actions() }\n }\n\n /** Release the card's scope subscription and bound stores. */\n dispose(): void {\n this.form.dispose()\n }\n}\n\n/** Props the renderer binds for the LiangShen card. */\nexport type LiangShenSettingsCardProps =\n PropsRuntime<'web-ui.plugin.item'>\n & PropsLocale<'liangshen'>\n & InjectFace<LiangShenSettingsCardFace>\n\n/**\n * Render the LiangShen card.\n * @param props - locale copy, the card snapshot, and its form actions.\n * @returns the card.\n */\nexport function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {\n const { t } = props\n const state = props.useLiangShenSettingsCard((snapshot: LiangShenSettingsCardState) => snapshot)\n const fieldProps = {\n overriddenLabel: t('settings.overridden'),\n resetLabel: t('settings.reset'),\n invalidLabel: t('settings.invalidValue'),\n disabled: !state.writable,\n inheritLabel: t('settings.inherit'),\n }\n return (\n <PluginSettingsCard\n t={t}\n titleKey=\"settings.title\"\n descriptionKey=\"settings.description\"\n defaultOpen={false}\n state={state}\n onSave={props.save}\n onDiscard={props.discard}\n >\n <BooleanField\n id=\"settings-liangshen-enabled\"\n label={t('settings.enabled')}\n hint={t('settings.enabledHint')}\n onLabel={t('settings.on')}\n offLabel={t('settings.off')}\n {...fieldProps}\n {...state.enabled}\n onEdit={(text) => { props.edit('enabled', text) }}\n onReset={() => { props.resetField('enabled') }}\n />\n <BooleanField\n id=\"settings-liangshen-announce\"\n label={t('settings.announceToAgent')}\n hint={t('settings.announceToAgentHint')}\n onLabel={t('settings.on')}\n offLabel={t('settings.off')}\n {...fieldProps}\n {...state.announceToAgent}\n onEdit={(text) => { props.edit('announceToAgent', text) }}\n onReset={() => { props.resetField('announceToAgent') }}\n />\n <ChoiceField\n id=\"settings-liangshen-presentation\"\n label={t('settings.presentation')}\n hint={t('settings.presentationHint')}\n choices={PRESENTATION_CHOICES.map(choice => ({ value: choice, label: t(`presentation.${choice}`) }))}\n {...fieldProps}\n {...state.presentation}\n onEdit={(text) => { props.edit('presentation', text) }}\n onReset={() => { props.resetField('presentation') }}\n />\n </PluginSettingsCard>\n )\n}\n","/**\n * Lever copy: zh-first dictionary with an English counterpart. The zh side is\n * the key-set source of truth; `packages/dsh-i18n` mirrors the keys into the\n * centralized ru dictionary and `pnpm i18n:check` enforces the parity.\n */\n\n/** Lever copy, key source of truth. */\nexport const zh = {\n 'lever.a11y': '梁神模式拨杆',\n 'lever.name': '梁神模式',\n 'lever.hint.pull': '拨下拨杆:开启「梁神模式」',\n 'lever.hint.push': '上拨拨杆:返回「{preset}」',\n 'lever.hint.locked': '会话已开始,模式不可再更改',\n 'lever.hint.missing': '未找到「梁神模式」预设,请先启用该插件行',\n 'lever.state.on': '梁神模式',\n 'lever.state.off': '普通模式',\n 'lever.busy': '正在切换…',\n 'lever.failed.locked': '会话已经开始,模式已锁定',\n 'lever.failed.missing': '没有找到「梁神模式」预设',\n 'lever.failed.timeout': '切换超时,请重试',\n 'lever.failed.failed': '切换失败:{reason}',\n 'burst.line1': '三秒,三辈子的代码',\n 'burst.line2': '文言文 · 二进制 · 摩斯电码',\n 'settings.title': '梁神模式',\n 'settings.description': '控制本插件与工具面呈现方式。',\n 'settings.enabled': '启用梁神模式',\n 'settings.enabledHint': '关闭后预设同步与 agent 公告都不执行。',\n 'settings.announceToAgent': '向 agent 公告本插件',\n 'settings.announceToAgentHint': '开启后向每一轮 agent 系统提示注入本插件公告;默认关闭以保持提示词干净。',\n 'settings.presentation': '工具面呈现方式',\n 'settings.presentationHint': '写入同步后的预设:ptc 把 wire 收拢为 run_code;native 保持原生工具清单;both 让两者同驻。改动需重启 DSH 生效。',\n 'settings.on': '开',\n 'settings.off': '关',\n 'settings.inherit': '继承(跟随部署默认)',\n 'settings.overridden': '已覆盖',\n 'settings.reset': '重置',\n 'settings.notExposed': '当前 DSH 版本未向设置页暴露本插件的配置命名空间,表单不可用。可编辑 ~/.dsh/settings.yaml 直接配置,或将本命名空间加入 Host 设置白名单后重启。',\n 'settings.readOnly': '当前部署的设置只读。',\n 'settings.expand': '展开设置',\n 'settings.collapse': '收起设置',\n 'settings.save': '保存',\n 'settings.saving': '保存中…',\n 'settings.discard': '放弃',\n 'settings.unsaved': '未保存',\n 'settings.saveFailed': '部署未接受这些值,已保留供你修改。',\n 'settings.invalidValue': '该取值不被接受',\n 'presentation.ptc': 'ptc(仅 run_code)',\n 'presentation.native': 'native(原生工具清单)',\n 'presentation.both': 'both(两者同驻)',\n}\n\n/** English counterpart; the key set mirrors {@link zh} exactly. */\nexport const en: Record<keyof typeof zh, string> = {\n 'lever.a11y': 'LiangShen mode lever',\n 'lever.name': 'LiangShen mode',\n 'lever.hint.pull': 'Pull the lever down to turn on LiangShen mode',\n 'lever.hint.push': 'Push the lever up to return to \"{preset}\"',\n 'lever.hint.locked': 'The session has started, so its mode can no longer change',\n 'lever.hint.missing': 'The LiangShen preset is not installed; enable that plugin row first',\n 'lever.state.on': 'LiangShen',\n 'lever.state.off': 'Standard',\n 'lever.busy': 'Switching…',\n 'lever.failed.locked': 'The session already started, so the mode is locked',\n 'lever.failed.missing': 'The LiangShen preset was not found',\n 'lever.failed.timeout': 'The switch timed out; try again',\n 'lever.failed.failed': 'Switch failed: {reason}',\n 'burst.line1': 'Three seconds, three lifetimes of code',\n 'burst.line2': 'Classical Chinese · Binary · Morse code',\n 'settings.title': 'LiangShen mode',\n 'settings.description': 'Controls this plugin and the wire presentation.',\n 'settings.enabled': 'Enable LiangShen mode',\n 'settings.enabledHint': 'When off, neither preset sync nor the agent announcement runs.',\n 'settings.announceToAgent': 'Announce this plugin to agents',\n 'settings.announceToAgentHint': 'Adds this plugin announcement to every agent system prompt; off by default so prompts stay clean.',\n 'settings.presentation': 'Wire presentation',\n 'settings.presentationHint': 'Written into the synced preset: ptc collapses the wire to run_code; native keeps the native roster; both keeps them co-resident. Restart DSH for a change to take effect.',\n 'settings.on': 'On',\n 'settings.off': 'Off',\n 'settings.inherit': 'Inherit (deployment default)',\n 'settings.overridden': 'Overridden',\n 'settings.reset': 'Reset',\n '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.\",\n 'settings.readOnly': 'This deployment serves settings read-only.',\n 'settings.expand': 'Show settings',\n 'settings.collapse': 'Hide settings',\n 'settings.save': 'Save',\n 'settings.saving': 'Saving…',\n 'settings.discard': 'Discard',\n 'settings.unsaved': 'Unsaved',\n 'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',\n 'settings.invalidValue': 'The value is not accepted',\n 'presentation.ptc': 'ptc (run_code only)',\n 'presentation.native': 'native (native tool roster)',\n 'presentation.both': 'both (both co-resident)',\n}\n\n/** Every key in the locale catalog. */\nexport type LiangShenKey = keyof typeof zh\n","// Generated by scripts/sync-shared.mjs from shared/client/settings/plugin-card-seat.ts. Do not edit this copy; edit the shared source and run \"node scripts/sync-shared.mjs\".\n/**\n * Family plugin-card seat.\n *\n * A family plugin contributes its settings card to whichever plugin-card seat\n * the running host actually renders:\n *\n * - `web-ui.plugin.item` — the list seat declared by the dsh-web-settings\n * group section (this family's own first-level \"Web UI plugins\" section);\n * - `settings.plugin.item` — the official keyed seat of the harness's\n * `ui-settings-plugins` tab, keyed by the settings namespace the card edits.\n *\n * SEAT SELECTION IS NOT A DECLARATION PROBE. The official `ui-settings-plugins`\n * row belongs to the harness bundle and its `configurable` tab always declares\n * `settings.plugin.item` before any external plugin's `apply()` runs, so\n * \"is the official seat declared?\" answers yes even in the deployment whose\n * whole point is the family group. Choosing on that probe sends every family\n * card to the official Plugins tab and leaves the group's own section\n * permanently empty — the family of reports where the section renders its\n * heading and zero cards.\n *\n * The signal that actually distinguishes the two deployments is whether\n * dsh-web-settings is loaded: it is the package that owns the group section and\n * it publishes the `webUiSettings` service during `apply()`, which every\n * family plugin already reads for its settings scope. Group loaded -> the family\n * seat; group absent -> the official seat.\n *\n * The decision is re-evaluated on every `slots/changed` because the group may\n * apply after this plugin (the family aggregate orders it first, a profile that\n * installs the group separately need not): the initial contribution goes to the\n * official seat, then moves to the family seat the moment the group's section\n * registers. The entry is disposed before the replacement is registered, so a\n * card is never in two seats at once.\n *\n * The shared tree has no client-SDK dependency, so this module reads its\n * context through the structural shape below; callers pass the plugin's own\n * `ctx`.\n */\n\n/** The family list seat key. */\nexport const FAMILY_PLUGIN_CARD_SEAT = 'web-ui.plugin.item'\n\n/** The official keyed plugin-card seat key. */\nexport const OFFICIAL_PLUGIN_CARD_SEAT = 'settings.plugin.item'\n\n/** The service dsh-web-settings publishes while it is loaded. */\nexport const FAMILY_GROUP_SERVICE = 'webUiSettings'\n\n/** The slot-registry member this helper uses (structurally satisfied by ctx.slots). */\nexport interface PluginCardSlots {\n /** Contribution of one card entry. */\n register(options: never, component: never): unknown\n}\n\n/** The slice of the client context a card contribution needs. */\nexport interface PluginCardContext {\n slots: PluginCardSlots\n /** Service lookup; absent on a context double that only models the slots. */\n get?(name: string): unknown\n /** Event subscription seat; absent on an event-less test double. */\n on?(event: string, listener: (...args: never[]) => void): unknown\n}\n\n/** Owner share of a plugin card (both seats supply nothing). */\nexport interface SettingsPluginItemOwnerProps {\n /** Marker field: card owner props are intentionally empty. */\n children?: never\n}\n\n/** One family plugin's card contribution. */\nexport interface PluginCardSeat {\n /** Settings namespace the card edits (the official seat's dispatch key). */\n namespace: string\n /** Family list-seat entry id. */\n id: string\n /** Family list-seat sort order. */\n order?: number\n /** Family list-seat display label; the official keyed seat carries none. */\n label?: () => string\n /** Locale namespace the card renders with. */\n locale: string\n /** Business-face factory of the registration. */\n inject?: () => object\n /**\n * The card component. Its props type is the seat's composed shape, which is\n * chosen at runtime, so the helper takes it erased; the registrant keeps its\n * own precise typing at the call site.\n */\n component: unknown\n}\n\n/**\n * Whether the family group (dsh-web-settings) is loaded in this page. The\n * service is the group package's own contract, so the probe cannot be fooled\n * by a harness release that starts declaring the official seat differently.\n */\nexport function familyGroupLoaded(ctx: PluginCardContext): boolean {\n const get = ctx.get\n if (typeof get !== 'function') return false\n try {\n return get.call(ctx, FAMILY_GROUP_SERVICE) !== undefined\n } catch {\n // A context that refuses the lookup: treat the group as absent, which\n // falls back to the official seat the harness declares.\n return false\n }\n}\n\n/** Report a refused registration instead of leaving the user with no card. */\nfunction warnRefusedSeat(seat: string, error: unknown): void {\n try {\n console.warn(`[dsh-web] plugin card registration into \"${seat}\" was refused; the card will not render`, error)\n } catch {\n // Best-effort console write; a failed warning must not break the plugin.\n }\n}\n\n/**\n * Contribute one family plugin card to the seat this host renders, following\n * the group if it loads later. The entry is disposed and re-registered on a\n * seat change, never duplicated.\n * @param ctx - client context (its slot registry decides the seat).\n * @param seat - the card contribution.\n */\nexport function installPluginCard(ctx: PluginCardContext, seat: PluginCardSeat): void {\n const slots = ctx.slots\n const component = seat.component as never\n const inject = seat.inject as never\n\n let dispose: (() => void) | undefined\n let current: string | undefined\n /**\n * Re-entrancy latch. The registry emits a change event synchronously from\n * inside both `register` and the previous entry's disposer, so an unguarded\n * reconcile would re-enter itself mid-move and register the card twice into\n * the seat it is leaving (\"already has an entry for key ...\").\n */\n let reconciling = false\n\n /** Reconcile the contribution with the currently live seat (no-op when unchanged). */\n const reconcile = (): void => {\n if (reconciling) return\n const target = familyGroupLoaded(ctx) ? FAMILY_PLUGIN_CARD_SEAT : OFFICIAL_PLUGIN_CARD_SEAT\n if (current === target) return\n reconciling = true\n const previous = dispose\n dispose = undefined\n current = undefined\n previous?.()\n try {\n dispose = slots.register((target === FAMILY_PLUGIN_CARD_SEAT\n ? {\n name: FAMILY_PLUGIN_CARD_SEAT,\n id: seat.id,\n ...(seat.order === undefined ? {} : { order: seat.order }),\n ...(seat.label === undefined ? {} : { label: seat.label }),\n locale: seat.locale,\n ...(seat.inject === undefined ? {} : { inject }),\n }\n : {\n name: OFFICIAL_PLUGIN_CARD_SEAT,\n key: seat.namespace,\n locale: seat.locale,\n ...(seat.inject === undefined ? {} : { inject }),\n }) as never, component) as () => void\n current = target\n } catch (error) {\n warnRefusedSeat(target, error)\n } finally {\n reconciling = false\n }\n }\n\n if (typeof ctx.on === 'function') {\n try {\n ctx.on('slots/changed', () => { reconcile() })\n } catch {\n // An event seat that refuses the subscription leaves the initial\n // decision in place; the card still renders in the seat chosen below.\n }\n }\n // The initial decision: the group, when it is already loaded (the aggregate\n // order), otherwise the official seat the harness declares.\n reconcile()\n}\n","/**\n * dsh-liangshen browser half: the LiangShen lever in the composer tool row.\n *\n * The slot is `conversation.input.right` — \"compact controls before the\n * composer submit action\", which renders immediately left of the model\n * selector (`conversation.input.model`) inside the same composer card, on the\n * homepage's new-session hero as well as in a session. The lever lives only\n * while the session is still blank, because that is the only window in which a\n * preset can change at all: `agentPresets.select` refuses an already-started\n * session, and the arm would have nothing to do in one.\n *\n * This half talks to the host over the agent-preset Remote namespace rather\n * than through the official preset package's browser module: cross-plugin\n * collaboration here goes through cordis services and Remote surfaces, not\n * value imports.\n *\n * Failure policy: a missing slot or a refused Remote call is handled, never\n * thrown — one external plugin must not take the GUI boot down.\n */\n\nimport type { Context as ClientContext } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-client-ui-renderer/client'\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\n// Type-only: pulls the ui-conversation SlotMap merge (the composer tool row).\nimport type {} from '@deepseek-ai/dsh-client-ui-conversation/client'\nimport type {} from '@deepseek-ai/dsh-client-ui-slots'\nimport type { SettingsScopeSpec } from '@deepseek-ai/dsh-client-ui-settings/client'\n// Type-only: pulls the settings-surface Context merge (ctx.settingsScope).\nimport type {} from '@deepseek-ai/dsh-client-ui-settings/client'\nimport { LiangShenLever } from './LiangShenLever.tsx'\nimport { LeverController } from './lever-controller.ts'\nimport { LiangShenSettingsCard, LiangShenSettingsCardController, type LiangShenSettings } from './LiangShenSettingsCard.tsx'\nimport { en, zh, type LiangShenKey } from './locales.ts'\nimport { installPluginCard } from './plugin-card-seat.ts'\n\n/** Locale namespace this half owns. */\nexport const NS = 'liangshen'\n\n/** Settings namespace the settings card edits (the Host plugin registers it). */\nexport const SETTINGS_NAMESPACE = 'dsh-liangshen'\n\n/** Owner share of a plugin card (the section supplies nothing). */\nexport interface SettingsPluginItemOwnerProps {\n /** Marker field: card owner props are intentionally empty. */\n children?: never\n}\n\ndeclare module '@deepseek-ai/dsh-client-ui-slots' {\n interface SlotMap {\n /**\n * The child slot the Web UI plugin group declares; this card registers into\n * the group instead of the top-level `settings.plugin.item` list. Declared\n * here so this package needs no dependency on the sibling UI package.\n */\n 'web-ui.plugin.item': { kind: 'list'; scope: 'root'; owner: SettingsPluginItemOwnerProps }\n }\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n /**\n * Optional compatibility binder provided by dsh-web-settings; absent when\n * that group plugin is not installed, so callers fall back to the official\n * settings scope.\n */\n webUiSettings?: { bind<S>(spec: SettingsScopeSpec<S>): import('@deepseek-ai/dsh-client-ui-settings/client').SettingsScope<S> }\n }\n}\n\n/**\n * Required client services: the slot registry, locale, sessions, and the roster\n * Remote. Both `remote` and `remote.agentPresets` are declared: the context\n * proxy refuses an uninjected service, and a nested service name does not imply\n * its parent, so reading `ctx.remote.agentPresets` needs `remote` as well.\n */\nexport const inject = ['slots', 'locale', 'sessions', 'settingsScope', 'remote', 'remote.agentPresets']\n\ndeclare module '@deepseek-ai/dsh-client-ui-slots' {\n interface LocaleNamespaceMap {\n /** The LiangShen lever copy. */\n 'liangshen': LiangShenKey\n }\n}\n\nexport { LiangShenLever } from './LiangShenLever.tsx'\nexport { LeverController, type LeverFace, type LeverSnapshot } from './lever-controller.ts'\nexport { LIANGSHEN_PRESET_ID, leverState, restoreTarget, type LeverFacts, type LeverState } from '../core/lever.ts'\n\n/**\n * Mount the lever: register the copy, follow the roster and the current\n * session, and claim the composer tool row.\n * @param ctx - the browser plugin context.\n */\nexport function apply(ctx: ClientContext): void {\n ctx.effect(() => {\n try {\n return ctx.locale.register(NS, { zh, en })\n } catch {\n return () => {}\n }\n }, 'liangshen: lever dictionaries')\n\n const controller = new LeverController(ctx)\n ctx.effect(() => () => controller.dispose(), 'liangshen: lever controller')\n try {\n controller.start()\n } catch {\n // An unavailable sessions or Remote service leaves the lever inert; the\n // view still renders and reports what it knows.\n }\n\n // Plugin configuration card: one staged form over the `dsh-liangshen`\n // settings namespace, contributed to the Web UI plugin group beside the\n // remote-access and task-board cards.\n try {\n const binder = ctx.get('webUiSettings') ?? ctx.settingsScope\n const settingsScope = binder.bind<LiangShenSettings>({ namespace: SETTINGS_NAMESPACE })\n const settingsCard = new LiangShenSettingsCardController(settingsScope)\n // Card seat: the family group's list seat, or the official keyed seat of\n // the plugin-configuration tab when the group is not installed (issue #1589).\n installPluginCard(ctx, {\n namespace: SETTINGS_NAMESPACE,\n id: 'liangshen',\n order: 120,\n locale: NS,\n inject: () => settingsCard.inject(),\n component: LiangShenSettingsCard,\n })\n ctx.effect(() => () => { settingsCard.dispose() }, 'liangshen: settings card')\n } catch {\n // A missing settings surface leaves the lever working and the card absent;\n // one unavailable service must not take the browser half down.\n }\n\n ctx.slots.inject('conversation.input.right', () => {\n try {\n const unregister = ctx.slots.register({\n name: 'conversation.input.right',\n id: 'liangshen-lever',\n order: 20,\n inject: () => controller.face(),\n }, LiangShenLever)\n return () => { unregister() }\n } catch {\n return () => {}\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBA,MAAM,oBAAoB;;EAG1B,MAAM,WAAW;;EAGjB,MAAM,SAAS;EACf,MAAM,QAAQ;;EAGd,MAAM,SAAS,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,KAAK;;EAG7D,SAAgB,eAAe,MAAsC;GAEnE,MAAM,EAAE,OAAO,cAAc,MAAM,OAAO,WAAA,GAAA,MAAA,qBAAA,CADJ,KAAK,MAAM,WAAW,KAAK,MAAM,WACZ;GAC3D,MAAM,CAAC,UAAU,gBAAA,GAAA,MAAA,SAAA,CAAwB,CAAC;GAC1C,MAAM,QAAA,GAAA,MAAA,OAAA,CAAc,KAAK;GACzB,MAAM,QAAA,GAAA,MAAA,OAAA,CAAyD,KAAA,CAAS;GACxE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IACD,IAAI,mBAAmB;KAAE,aAAa,QAAQ;IAAE,GAAG,0BAA0B;GAC/E,QAAQ,CAGR;GAEA,IAAI,MAAM,OAAO,kCAAkC;IACjD,IAAI;KACF,MAAM,aAAa,IAAI,MAAM,SAAS;MACpC,MAAM;MACN,IAAI;MACJ,OAAO;MACP,cAAc,WAAW,KAAK;KAChC,GAAG,cAAc;KACjB,aAAa;MAAE,WAAW;KAAE;IAC9B,QAAQ;KACN,aAAa,CAAC;IAChB;GACF,CAAC;EACH"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, utimesSync } from "node:fs";
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, isAbsolute, join, relative } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import z from "schemastery";
|
|
@@ -235,23 +235,83 @@ function copyTreeSync(sourceDir, targetDir) {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Replace one indented `key: <value>` line inside the block of `- id: <row>`.
|
|
240
|
+
*
|
|
241
|
+
* Strings render single-quoted and booleans render bare: YAML reads an unquoted
|
|
242
|
+
* `false` as a boolean, while `'false'` would be a truthy string and silently
|
|
243
|
+
* invert the switch.
|
|
244
|
+
*/
|
|
245
|
+
function setRowValue(text, rowId, key, value) {
|
|
246
|
+
if (value === void 0) return text;
|
|
247
|
+
const literal = typeof value === "boolean" ? String(value) : `'${value}'`;
|
|
248
|
+
const rowStart = text.indexOf(`- id: ${rowId}
|
|
249
|
+
`);
|
|
250
|
+
if (rowStart < 0) return text;
|
|
251
|
+
const afterRow = rowStart + `- id: ${rowId}
|
|
252
|
+
`.length;
|
|
253
|
+
const rest = text.slice(afterRow);
|
|
254
|
+
const boundary = rest.search(/^\S/m);
|
|
255
|
+
const body = boundary < 0 ? rest : rest.slice(0, boundary);
|
|
256
|
+
const tail = boundary < 0 ? "" : rest.slice(boundary);
|
|
257
|
+
const pattern = new RegExp(`^(\\s*)${key}:\\s*.*$`, "m");
|
|
258
|
+
const rewritten = pattern.test(body) ? body.replace(pattern, `$1${key}: ${literal}`) : body;
|
|
259
|
+
return text.slice(0, afterRow) + rewritten + tail;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Render `agent.cordis.yml` with the settings overrides applied.
|
|
263
|
+
*
|
|
264
|
+
* Rows are matched by their `- id:` marker, so the transform does not depend on
|
|
265
|
+
* line numbers or on the values the shipped file happens to carry. A row or key
|
|
266
|
+
* the source does not contain is left alone rather than invented: the overlay
|
|
267
|
+
* narrows the shipped configuration, it never adds a mount the preset did not
|
|
268
|
+
* have.
|
|
269
|
+
* @param text - the bundled preset composition.
|
|
270
|
+
* @param overrides - the operator's settings-surface choices.
|
|
271
|
+
* @returns the composition to write into the synced tree.
|
|
272
|
+
*/
|
|
273
|
+
function renderPresetOverrides(text, overrides) {
|
|
274
|
+
let out = text;
|
|
275
|
+
out = setRowValue(out, "tool-catalog", "presentation", overrides.presentation);
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
238
278
|
/** Copy `sourceRoot/<id>` into `targetRoot/<id>`, idempotently. */
|
|
239
|
-
function syncOnePreset(sourceDir, targetDir) {
|
|
279
|
+
function syncOnePreset(sourceDir, targetDir, overrides = {}) {
|
|
240
280
|
const sourceFiles = filesUnder(sourceDir);
|
|
241
281
|
const sourceSet = new Set(sourceFiles.map((file) => relative(sourceDir, file)));
|
|
242
282
|
if (existsSync(targetDir) && !statSync(targetDir).isDirectory()) rmSync(targetDir, {
|
|
243
283
|
recursive: true,
|
|
244
284
|
force: true
|
|
245
285
|
});
|
|
286
|
+
const applyOverrides = () => {
|
|
287
|
+
const agentFile = join(targetDir, "agent.cordis.yml");
|
|
288
|
+
if (!existsSync(agentFile)) return;
|
|
289
|
+
const rendered = renderPresetOverrides(readFileSync(agentFile, "utf8"), overrides);
|
|
290
|
+
if (rendered !== readFileSync(agentFile, "utf8")) writeFileSync(agentFile, rendered);
|
|
291
|
+
};
|
|
246
292
|
if (!existsSync(targetDir)) {
|
|
247
293
|
copyTreeSync(sourceDir, targetDir);
|
|
248
294
|
pruneExtras(targetDir, sourceSet);
|
|
295
|
+
applyOverrides();
|
|
249
296
|
return "synced";
|
|
250
297
|
}
|
|
298
|
+
const agentEntry = join(sourceDir, "agent.cordis.yml");
|
|
299
|
+
const expectedAgent = existsSync(agentEntry) ? Buffer.from(renderPresetOverrides(readFileSync(agentEntry, "utf8"), overrides)) : void 0;
|
|
251
300
|
let dirty = false;
|
|
252
301
|
for (const file of sourceFiles) {
|
|
253
302
|
const dest = join(targetDir, relative(sourceDir, file));
|
|
254
|
-
if (!existsSync(dest)
|
|
303
|
+
if (!existsSync(dest)) {
|
|
304
|
+
dirty = true;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
if (file === agentEntry) {
|
|
308
|
+
if (expectedAgent === void 0 || !expectedAgent.equals(readFileSync(dest))) {
|
|
309
|
+
dirty = true;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (!sameFile(file, dest)) {
|
|
255
315
|
dirty = true;
|
|
256
316
|
break;
|
|
257
317
|
}
|
|
@@ -262,10 +322,19 @@ function syncOnePreset(sourceDir, targetDir) {
|
|
|
262
322
|
break;
|
|
263
323
|
}
|
|
264
324
|
}
|
|
265
|
-
if (!dirty)
|
|
325
|
+
if (!dirty) {
|
|
326
|
+
const before = readFileSync(join(targetDir, "agent.cordis.yml"), "utf8");
|
|
327
|
+
const after = renderPresetOverrides(before, overrides);
|
|
328
|
+
if (after !== before) {
|
|
329
|
+
writeFileSync(join(targetDir, "agent.cordis.yml"), after);
|
|
330
|
+
return "synced";
|
|
331
|
+
}
|
|
332
|
+
return "current";
|
|
333
|
+
}
|
|
266
334
|
pruneExtras(targetDir, sourceSet);
|
|
267
335
|
copyTreeSync(sourceDir, targetDir);
|
|
268
336
|
pruneExtras(targetDir, sourceSet);
|
|
337
|
+
applyOverrides();
|
|
269
338
|
return "synced";
|
|
270
339
|
}
|
|
271
340
|
/**
|
|
@@ -282,7 +351,7 @@ function syncOnePreset(sourceDir, targetDir) {
|
|
|
282
351
|
* @param targetRoot - dsh agent-presets discovery root (e.g. <home>/.dsh/.agent-presets).
|
|
283
352
|
* @param retire - previously bundled preset ids to remove when absent from the source.
|
|
284
353
|
*/
|
|
285
|
-
function syncPresetTrees(sourceRoot, targetRoot, retire = []) {
|
|
354
|
+
function syncPresetTrees(sourceRoot, targetRoot, retire = [], overrides = {}) {
|
|
286
355
|
const result = {
|
|
287
356
|
synced: [],
|
|
288
357
|
current: [],
|
|
@@ -297,7 +366,7 @@ function syncPresetTrees(sourceRoot, targetRoot, retire = []) {
|
|
|
297
366
|
const targetDir = join(targetRoot, id);
|
|
298
367
|
let outcome;
|
|
299
368
|
try {
|
|
300
|
-
outcome = syncOnePreset(source, targetDir);
|
|
369
|
+
outcome = syncOnePreset(source, targetDir, overrides);
|
|
301
370
|
} catch (error) {
|
|
302
371
|
result.failed.push({
|
|
303
372
|
id,
|
|
@@ -387,16 +456,20 @@ function mountOnce(packageName, fn) {
|
|
|
387
456
|
* surface (plugin config) or the profile patch. No browser half, no routes,
|
|
388
457
|
* no agent tools — the preset itself provides the tools.
|
|
389
458
|
*
|
|
390
|
-
* The preset combines a minimal persona with a
|
|
391
|
-
* the system prompt keeps a minimal persona with standing
|
|
392
|
-
* and workspace instructions, the
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
459
|
+
* The preset combines a minimal persona with a lifetime-declared tool
|
|
460
|
+
* presentation: the system prompt keeps a minimal persona with standing
|
|
461
|
+
* working discipline and workspace instructions, and the wire runs the SDK's
|
|
462
|
+
* 'ptc' presentation by default — the wire collapses to the `run_code`
|
|
463
|
+
* transport and every other tool is reached through the generated SDK,
|
|
464
|
+
* declared once per session instead of staged across a turn boundary
|
|
465
|
+
* ('native' and 'both' are one-line opt-outs). High-fan-out tool families
|
|
466
|
+
* (default `mcp__*`) stay paged out of the executed surface through the
|
|
467
|
+
* host's scoped tool restriction until the preset's own `tool_activate` tool
|
|
468
|
+
* loads their namespace (LRU cap three), with the activation state replayed
|
|
469
|
+
* from the durable session event stream. The tool catalog — listing exactly
|
|
470
|
+
* the tools the request carries plus the paged-out namespace summaries — and a
|
|
471
|
+
* one-line working-context projection travel as durable user messages,
|
|
472
|
+
* republished only on change.
|
|
400
473
|
*/
|
|
401
474
|
/** Stable cordis plugin name. */
|
|
402
475
|
const name = "liangshen";
|
|
@@ -404,16 +477,24 @@ const name = "liangshen";
|
|
|
404
477
|
const LIANGSHEN_SETTINGS_NAMESPACE = "dsh-liangshen";
|
|
405
478
|
/** Prompt assembly must exist before the announcement section can register. */
|
|
406
479
|
const inject = ["systemPrompt"];
|
|
480
|
+
/** The wire presentations the preset's tool catalog accepts. */
|
|
481
|
+
const PRESENTATION_OPTIONS = [
|
|
482
|
+
"ptc",
|
|
483
|
+
"native",
|
|
484
|
+
"both"
|
|
485
|
+
];
|
|
407
486
|
const Config = z.object({
|
|
408
487
|
enabled: z.boolean().default(true),
|
|
409
|
-
announceToAgent: z.boolean().default(false)
|
|
488
|
+
announceToAgent: z.boolean().default(false),
|
|
489
|
+
presentation: z.union([...PRESENTATION_OPTIONS]).default("ptc")
|
|
410
490
|
});
|
|
411
|
-
/** Schema
|
|
491
|
+
/** Schema defaults, re-read for hand-built test contexts. */
|
|
412
492
|
const DEFAULT_ANNOUNCE = false;
|
|
493
|
+
const DEFAULT_PRESENTATION = "ptc";
|
|
413
494
|
/** Order of the announcement section within the tool-guidance band. */
|
|
414
495
|
const SECTION_ORDER = 150;
|
|
415
496
|
/** Model-facing announcement: plugin presence, principle, and limits. */
|
|
416
|
-
const LIANGSHEN_GUIDANCE = "本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona
|
|
497
|
+
const LIANGSHEN_GUIDANCE = "本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(反思熔断——同一假设推演不超过两轮、缺事实立即闭合思考并调用原生检测工具;行动导向——思考只决定下一步具体操作、不在思考中预演代码实现;并发探索——多处独立检查或搜索在单轮内并发发射多个工具调用;YAGNI/PDCA——单步验证单一假设、不写冗余注释),并在组装时追加工作区目录行 Your working directory is <cwd>.。AGENTS.md 工作区指令默认交还宿主自身的 agent-instructions 行,以 user 角色注入,本插件不追加任何系统提示词段、也不改动 pre-step 的消息批次;可选 instructionSource: system-prompt 才由本插件在组装时读取 AGENTS.md 链并追加 workspace-instructions 段(65536 字节预算,每次组装重读)。wire 呈现由 tool-catalog 按会话一次声明,取值 'ptc'(默认:wire 收拢为唯一的 run_code,其余工具经生成的 SDK 触达)、'native'(组装出的原生清单)或 'both'(两者同驻),并可在插件设置界面切换(同步 preset 时写入 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。温和工具分页:匹配 pagedToolPatterns(默认 mcp__*)的工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。working-context 插件在 pre-step 注入单行 [Working Context: ...] 就近状态投射(plan 模式、活跃命名空间、进行中 todo 标题,全部从事件流折叠,读不到则省略,全部为空则不注入)。历史工具结果修剪为 4096 字符阈值(head 1500 / tail 500)。文件操作受宿主沙箱约束;shell 在每个平台都挂上游标准 Stdio 栈(POSIX 为 bash,Windows 为 pwsh),带简短描述标题卡片与确定性退出码。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。";
|
|
417
498
|
/** Absolute path of the bundled preset tree inside this package. */
|
|
418
499
|
function bundledPresetsRoot() {
|
|
419
500
|
return fileURLToPath(new URL("../presets/", import.meta.url));
|
|
@@ -431,13 +512,15 @@ function applyImpl(ctx, config) {
|
|
|
431
512
|
let current = () => config ?? {};
|
|
432
513
|
const resolve = () => ({
|
|
433
514
|
announceToAgent: current().announceToAgent ?? DEFAULT_ANNOUNCE,
|
|
434
|
-
enabled: current().enabled ?? true
|
|
515
|
+
enabled: current().enabled ?? true,
|
|
516
|
+
presentation: current().presentation ?? DEFAULT_PRESENTATION
|
|
435
517
|
});
|
|
436
518
|
const sync = () => {
|
|
437
519
|
const targetRoot = join(dshHome(), ".agent-presets");
|
|
438
520
|
try {
|
|
439
521
|
mkdirSync(targetRoot, { recursive: true });
|
|
440
|
-
const
|
|
522
|
+
const settings = resolve();
|
|
523
|
+
const result = syncPresetTrees(bundledPresetsRoot(), targetRoot, ["liangshen-exact"], { presentation: settings.presentation });
|
|
441
524
|
for (const { id, error } of result.failed) ctx.logger?.warn?.(`dsh-liangshen: preset ${id} sync failed: ${error}`);
|
|
442
525
|
if (result.synced.length > 0) ctx.logger?.info?.(`dsh-liangshen: presets synced into ${targetRoot}: ${result.synced.join(", ")}`);
|
|
443
526
|
if (result.retired.length > 0) ctx.logger?.info?.(`dsh-liangshen: retired stale presets from ${targetRoot}: ${result.retired.join(", ")}`);
|
|
@@ -483,4 +566,4 @@ function applyImpl(ctx, config) {
|
|
|
483
566
|
}, "dsh-liangshen: announcement");
|
|
484
567
|
}
|
|
485
568
|
//#endregion
|
|
486
|
-
export { Config, LIANGSHEN_GUIDANCE, LIANGSHEN_SETTINGS_NAMESPACE, apply, bundledPresetsRoot, dshHome, inject, name };
|
|
569
|
+
export { Config, LIANGSHEN_GUIDANCE, LIANGSHEN_SETTINGS_NAMESPACE, PRESENTATION_OPTIONS, apply, bundledPresetsRoot, dshHome, inject, name };
|