@mars.liu/dsh-cybernetics 0.6.0 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -1,4 +1,12 @@
1
- // dsh-cybernetics client module: the「目标 / Goal」conversation tab.
1
+ // dsh-cybernetics client module: the「目标 / Goal」conversation tab, the
2
+ //「控制」tab, and (v0.7.2+, fixed in v0.7.3, full volatile coverage in v0.8.1,
3
+ // triageAgentModel added in v0.8.2) the settings card seated on the official
4
+ // Plugins page (plugins.item / plugins.row.config / plugins.bundle.config,
5
+ // bound to the row's ConfigForm in either of the two shapes the seats deliver
6
+ // — volatile writes stay live without a restart). The card is the ONLY GUI
7
+ // surface for the plugin's seven volatile fields: the host Plugins page draws
8
+ // no fields of its own and dsh-client-ui-settings ships the configForms
9
+ // service, not a renderer.
2
10
  // Rendered from the session's `goal` projection (dsh-goal), pushed live by the
3
11
  // host — no plugin HTTP route needed. Hand-written ModuleLoader wrapper, same
4
12
  // format the host bundler emits (see dsh-context / dsh-maze client.js).
@@ -62,6 +70,51 @@ window.__ModuleLoader__.load({
62
70
  // v0.6 executor line: the durable teammate's name (persistent only)
63
71
  'goal.member': '成员 {name}',
64
72
  'control.goals': '目标',
73
+ // v0.7.2 plugins-page settings card (plugins.item / plugins.row.config /
74
+ // plugins.bundle.config). cardLabel titles the 内置插件配置 group card.
75
+ 'settings.cardLabel': 'Cybernetics 编排循环',
76
+ 'settings.title': '全目标模式',
77
+ 'settings.description': '所有用户请求(含只读问题)必须先经 cybernetics goal。保存后即时生效,无需重载。',
78
+ 'settings.on': '开',
79
+ 'settings.off': '关',
80
+ 'settings.summaryOn': '全目标模式:开',
81
+ 'settings.summaryOff': '全目标模式:关',
82
+ 'settings.unavailable': '配置不可用(设置文档未开放或插件未运行)。',
83
+ 'settings.saving': '保存中…',
84
+ 'settings.saveFailed': '保存未生效(宿主拒绝了写入)。',
85
+ // v0.7.6 path-(b) diagnostics: the direct settings-transport retry
86
+ // surfaces the host's exact RemoteError message (the shared
87
+ // ConfigFormController swallows it into a bare `false`).
88
+ 'settings.saveFailedDetail': '保存未生效,宿主拒绝原因:{message}',
89
+ // v0.8.1: the remaining five volatile fields. The card is the ONLY
90
+ // GUI surface for them (see the card region comment): the host has
91
+ // no generic schema-driven field renderer, so every field the card
92
+ // does not draw is invisible everywhere.
93
+ 'settings.taskAgentModel': 'Task agent 模型',
94
+ 'settings.verifyAgentModel': 'Verify agent 模型',
95
+ // v0.8.3: the three model fields are dropdown-backed (datalist over the
96
+ // host's live model catalog, remote.session.modelCatalog) with free
97
+ // manual entry preserved — the datalist input accepts any text.
98
+ 'settings.modelFieldHint': '可从下拉选择当前系统模型(显示 provider · provider/model),也可手工输入「provider/model」或裸模型名;留空 = 与 session agent 一致(继承)。回车或移开焦点即保存。',
99
+ // v0.8.3: configured value no longer in the live catalog = deleted
100
+ // subscription. Warn + one-click clear; NEVER auto-unset (the value
101
+ // may be valid again after resubscribing, and silent rewrites of
102
+ // user config are a side effect) — the runtime already falls back to
103
+ // the session agent model per v0.8.0, so the warning is advisory.
104
+ 'settings.modelUnavailable': '该模型已不在当前系统模型列表中,运行时将回退到 session agent 模型。',
105
+ 'settings.modelClear': '清除',
106
+ // v0.8.2: the triage role's flat model field — triage reads the
107
+ // task/verify results and emits the round's convergence decision
108
+ // (met/continue/human-input/...); quick rounds never invoke it.
109
+ 'settings.triageAgentModel': 'Triage agent 模型',
110
+ 'settings.triageModelHint': '可从下拉选择当前系统模型,也可手工输入「provider/model」或裸模型名;留空 = 与 session agent 一致(继承)。triage 角色读 task/verify 结果输出本轮收敛决策(met/continue/human-input 等),quick 轮不启用。回车或移开焦点即保存。',
111
+ 'settings.roundsPerSubgoal': '子目标轮数上限',
112
+ 'settings.roundsPerSubgoalHint': '同一子目标的最大连续轮数(整数 ≥1,缺省 3);留空恢复默认。回车或移开焦点即保存。',
113
+ 'settings.maxConcurrentRounds': '并行轮数上限',
114
+ 'settings.maxConcurrentRoundsHint': '全局并行轮数上限(整数 ≥0,缺省 0 = 不限);留空恢复默认。回车或移开焦点即保存。',
115
+ // v0.8.4: roles 高级配置不再上卡片(手工编辑 JSON 对用户不友善)——
116
+ // 由 agent 指导用户直接编辑 profile 配置 yaml(见 README)。
117
+ 'settings.invalidNumber': '请输入符合范围的整数,或留空恢复默认。',
65
118
  };
66
119
  const en = {
67
120
  'view.goal': 'Goal',
@@ -102,6 +155,31 @@ window.__ModuleLoader__.load({
102
155
  'goal.revisedFrom': 'Revised from "{title}"',
103
156
  'goal.member': 'Member {name}',
104
157
  'control.goals': 'Goals',
158
+ 'settings.cardLabel': 'Cybernetics goal loop',
159
+ 'settings.title': 'All-goals mode',
160
+ 'settings.description': 'Every user request (including read-only questions) must go through a cybernetics goal first. Takes effect immediately on save; no reload needed.',
161
+ 'settings.on': 'On',
162
+ 'settings.off': 'Off',
163
+ 'settings.summaryOn': 'All-goals mode: on',
164
+ 'settings.summaryOff': 'All-goals mode: off',
165
+ 'settings.unavailable': 'Configuration unavailable (settings document not served or plugin not running).',
166
+ 'settings.saving': 'Saving…',
167
+ 'settings.saveFailed': 'Save did not take effect (the host refused the write).',
168
+ 'settings.saveFailedDetail': 'Save did not take effect — host refusal: {message}',
169
+ // v0.8.1: the remaining five volatile fields (see zh for the rationale).
170
+ 'settings.taskAgentModel': 'Task agent model',
171
+ 'settings.verifyAgentModel': 'Verify agent model',
172
+ 'settings.modelFieldHint': 'Pick from the dropdown of currently available system models (shown as provider · provider/model), or type "provider/model" or a bare model name; empty = inherit the session agent. Enter or blur saves.',
173
+ 'settings.modelUnavailable': 'This model is no longer in the system model list; at runtime the round falls back to the session agent model.',
174
+ 'settings.modelClear': 'Clear',
175
+ // v0.8.2: the triage role's flat model field (see zh for the rationale).
176
+ 'settings.triageAgentModel': 'Triage agent model',
177
+ 'settings.triageModelHint': 'Pick from the dropdown of available system models, or type "provider/model" or a bare model name; empty = inherit the session agent. The triage role reads the task/verify results and emits the round\'s convergence decision (met/continue/human-input/...); quick rounds never invoke it. Enter or blur saves.',
178
+ 'settings.roundsPerSubgoal': 'Rounds per subgoal',
179
+ 'settings.roundsPerSubgoalHint': 'Max consecutive rounds on one subgoal (integer ≥1, default 3); empty restores the default. Enter or blur saves.',
180
+ 'settings.maxConcurrentRounds': 'Concurrent round cap',
181
+ 'settings.maxConcurrentRoundsHint': 'Global cap on rounds in flight (integer ≥0, default 0 = unlimited); empty restores the default. Enter or blur saves.',
182
+ 'settings.invalidNumber': 'Enter an integer in range, or leave blank to restore the default.',
105
183
  };
106
184
  //#endregion
107
185
 
@@ -394,14 +472,516 @@ window.__ModuleLoader__.load({
394
472
  }
395
473
  //#endregion
396
474
 
475
+ //#region plugins-page settings card (v0.7.2)
476
+ // The official Plugins page (@deepseek-ai/dsh-client-ui-plugin-manager, the
477
+ // runtime copy that owns the 内置插件配置/实验性插件/已安装插件 groups) renders a
478
+ // bundle's own configuration ONLY through the slots it declares:
479
+ // plugins.bundle.config keyed by the bundle name (profile dep name)
480
+ // plugins.row.config keyed by `<bundle name>#<row id>`
481
+ // (rowConfigKey in that page's client.js; slot contract in
482
+ // dsh-cordis-client-runner's slot catalog). A server-side Config schema
483
+ // alone surfaces nowhere once the ui-settings-plugins section is disabled
484
+ // by the family plugin-manager — exactly the observed gap.
485
+ // Both entries bind the row's own ConfigForm from ctx.configForms (the
486
+ // namespace id is the loader row id `dsh-cybernetics`, same convention
487
+ // @deepseek-ai/dsh-experimental-client-ui-cot-translation uses). A toggle
488
+ // write goes settings mutate → loader volatile commit
489
+ // (`loader/volatile-update`), so allGoalsMode stays live without a
490
+ // restart — the v0.7.1 volatile semantics, unchanged.
491
+ const SETTINGS_ENTRY_ID = 'dsh-cybernetics';
492
+ const NO_FORM_SNAP = { status: 'unavailable', value: undefined, writable: false };
493
+ const noopSubscribe = () => () => {};
494
+
495
+ var settingsStyles = {
496
+ card: { display: 'flex', flexDirection: 'column', gap: 10, padding: '12px 0' },
497
+ row: { display: 'flex', alignItems: 'center', gap: 12 },
498
+ main: { display: 'flex', flexDirection: 'column', gap: 2, flex: 1, minWidth: 0 },
499
+ title: { fontSize: 13, fontWeight: 600 },
500
+ desc: { fontSize: 12, opacity: 0.65, lineHeight: 1.5 },
501
+ toggle: {
502
+ cursor: 'pointer', borderRadius: 999, width: 40, height: 22,
503
+ border: '1px solid rgba(127,127,127,0.45)', position: 'relative', flex: 'none',
504
+ background: 'transparent', padding: 0,
505
+ },
506
+ knob: {
507
+ position: 'absolute', top: 2, width: 16, height: 16, borderRadius: 999,
508
+ transition: 'left .15s ease',
509
+ },
510
+ trackOn: { background: '#2da44e', borderColor: '#2da44e' },
511
+ trackOff: { background: 'rgba(127,127,127,0.25)' },
512
+ knobOn: { left: 20, background: '#fff' },
513
+ knobOff: { left: 2, background: 'currentColor' },
514
+ unavailable: { fontSize: 12, opacity: 0.6 },
515
+ // v0.8.1: editable volatile fields (text / number inputs).
516
+ field: { display: 'flex', flexDirection: 'column', gap: 4, paddingTop: 6, borderTop: '1px solid rgba(127,127,127,0.18)' },
517
+ input: {
518
+ font: 'inherit', fontSize: 12, color: 'inherit', maxWidth: 320,
519
+ background: 'transparent', border: '1px solid rgba(127,127,127,0.4)',
520
+ borderRadius: 4, padding: '3px 8px', outline: 'none',
521
+ },
522
+ inputInvalid: { borderColor: '#d29922' },
523
+ invalid: { fontSize: 11, color: '#d29922' },
524
+ };
525
+
526
+ // v0.8.1: the card renders ALL volatile fields, not just the
527
+ // allGoalsMode toggle (v0.8.2 adds triageAgentModel → seven). Verified
528
+ // against the running host's sources (2026-11-04): the Plugins page
529
+ // detail view (ItemDetail in @deepseek-ai/dsh-client-ui-plugin-manager
530
+ // lib/client.js) renders a plugin's configuration ONLY through its slot
531
+ // cards — the page itself draws no fields;
532
+ // @deepseek-ai/dsh-client-ui-settings ships the configForms SERVICE
533
+ // (transport + volatileForm serve/write gates) but no generic field
534
+ // renderer; dsh-client-ui-settings-plugins is a read-only inventory
535
+ // shell ("Configuring a built-in plugin happens on the sidebar's
536
+ // Plugins page, where each official plugin's own companion package
537
+ // registers its page"). Official plugins each draw their own card
538
+ // (agent-loop / web-search / …). So a volatile field this card does not
539
+ // render is editable NOWHERE in the GUI — that was the v0.7.9–v0.8.0
540
+ // panel gap. Field types follow the schema (src/index.ts Config):
541
+ // allGoalsMode boolean toggle; taskAgentModel / verifyAgentModel /
542
+ // triageAgentModel text ('' = inherit); roundsPerSubgoal /
543
+ // maxConcurrentRounds integers (≥1 / ≥0; blank restores the default via
544
+ // an `unset` op). v0.8.4: roles is no longer on the card — hand-editing
545
+ // a JSON object in the GUI is unfriendly; roles became non-volatile and
546
+ // is configured directly in the profile yaml (agent-guided, README).
547
+ // The card's field list is back to six:
548
+ // allGoalsMode / taskAgentModel / verifyAgentModel / triageAgentModel /
549
+ // roundsPerSubgoal / maxConcurrentRounds.
550
+ const SETTINGS_FIELDS = [
551
+ // v0.8.3: the three model fields are kind 'model' — datalist-backed
552
+ // dropdown over the live host catalog, manual entry still accepted
553
+ // (a datalist input is a free text input); invalid configured values
554
+ // render the unavailable warning + a one-click clear.
555
+ { field: 'taskAgentModel', labelKey: 'settings.taskAgentModel', hintKey: 'settings.modelFieldHint', kind: 'model' },
556
+ { field: 'verifyAgentModel', labelKey: 'settings.verifyAgentModel', hintKey: 'settings.modelFieldHint', kind: 'model' },
557
+ { field: 'triageAgentModel', labelKey: 'settings.triageAgentModel', hintKey: 'settings.triageModelHint', kind: 'model' },
558
+ { field: 'roundsPerSubgoal', labelKey: 'settings.roundsPerSubgoal', hintKey: 'settings.roundsPerSubgoalHint', kind: 'number', min: 1 },
559
+ { field: 'maxConcurrentRounds', labelKey: 'settings.maxConcurrentRounds', hintKey: 'settings.maxConcurrentRoundsHint', kind: 'number', min: 0 },
560
+ ];
561
+ /** Sentinel for "blank input = restore the schema default" (an unset op). */
562
+ const UNSET = {};
563
+ //#region v0.8.3 model catalog store (dropdown data + invalid-model detection)
564
+ // Host model directory, read the same way the official 子智能体 settings
565
+ // page does (@deepseek-ai/dsh-client-ui-settings-subagent): the
566
+ // `remote.session` namespace answers `modelCatalog()` with
567
+ // { ok, value: { groups: [{id, name, models: [{id, name}]}], failures } }
568
+ // — every currently routable model, grouped by provider. Provider
569
+ // invalidations arrive as `llm/adapters-updated` on ctx.remote. OPTIONAL
570
+ // everywhere: a host without the namespace leaves the store absent, the
571
+ // dropdown empty and the text entry intact — no crash, no warnings.
572
+ function createModelCatalogStore() {
573
+ let snap = { status: 'idle', options: [] };
574
+ const subs = new Set();
575
+ return {
576
+ subscribe(cb) { subs.add(cb); return () => subs.delete(cb); },
577
+ getSnapshot() { return snap; },
578
+ set(next) { snap = next; for (const cb of subs) cb(); },
579
+ load: async (session) => {
580
+ snap = { status: 'loading', options: snap.options };
581
+ for (const cb of subs) cb();
582
+ try {
583
+ const response = await session.modelCatalog();
584
+ if (response && response.ok === true && response.value && Array.isArray(response.value.groups)) {
585
+ const options = [];
586
+ for (const group of response.value.groups) {
587
+ for (const model of (group.models ?? [])) {
588
+ options.push({
589
+ value: group.id + '/' + model.id,
590
+ provider: group.id,
591
+ model: model.id,
592
+ label: (group.name ?? group.id) + ' · ' + group.id + '/' + model.id,
593
+ });
594
+ }
595
+ }
596
+ snap = { status: 'ready', options };
597
+ } else {
598
+ snap = { status: 'error', options: [] };
599
+ }
600
+ } catch {
601
+ snap = { status: 'error', options: [] };
602
+ }
603
+ for (const cb of subs) cb();
604
+ },
605
+ };
606
+ }
607
+ /**
608
+ * Whether a configured model value still resolves against the live
609
+ * catalog. Accepts the same shapes the runtime does (parseAgentModelSpec):
610
+ * `provider/model` (exact option match) or a bare model name (matches any
611
+ * provider's model id). An empty value or an absent/failed catalog never
612
+ * flags — the warning must be provable, not a guess.
613
+ */
614
+ function isConfiguredModelAvailable(value, catalogSnap) {
615
+ const text = (value ?? '').trim();
616
+ if (text === '') return true;
617
+ if (!catalogSnap || catalogSnap.status !== 'ready' || !Array.isArray(catalogSnap.options) || catalogSnap.options.length === 0) return true;
618
+ if (text.indexOf('/') >= 0) {
619
+ return catalogSnap.options.some((opt) => opt.value === text);
620
+ }
621
+ return catalogSnap.options.some((opt) => opt.model === text);
622
+ }
623
+ //#endregion
624
+
625
+ /**
626
+ * The settings card; shared by all three seats. Two form shapes reach
627
+ * it, and the card must speak both:
628
+ * - the LIVE ConfigForm this module injects (ctx.configForms.get):
629
+ * getSnapshot / subscribe / set / unset / mutate — the only shape on
630
+ * the plugins.bundle.config page and in summary rows, whose owners
631
+ * pass no form of their own;
632
+ * - the HOST's ConfigPageForm { state, mutate }: the plugins.item and
633
+ * plugins.row.config detail pages compute it from the same shared
634
+ * mirror (configForms.get(id).getSnapshot()/mutate) and pass it as
635
+ * an OWNER prop, which spreads AFTER inject at the render seam
636
+ * (@deepseek-ai/dsh-client-ui-renderer renderEntry: ...injected,
637
+ * ...ownerProps) — on those pages this shape WINS over the injected
638
+ * form. Reading `.subscribe` on it crashed the first v0.7.2 cut.
639
+ * The host shape carries no subscribe; its `state` is re-computed by
640
+ * the owning page on every mirror update, so reading it per render is
641
+ * already live.
642
+ */
643
+ function SettingsCard(props) {
644
+ const t = props.t;
645
+ const form = props.form;
646
+ // v0.7.6 path-(b) fallback write face: the plugin's own bound
647
+ // remote.settings.mutate. SAME host write path as the ConfigForm
648
+ // (remote.settings.mutate → @deepseek-ai/dsh-settings SettingsForms
649
+ // → @deepseek-ai/dsh-config-editor edit → the USER patch row
650
+ // `{id, name, config}` appended to the profile cordis.patch.yml,
651
+ // reconciled by reconcileProfilePatches) — the only落点 the host
652
+ // accepts. Used ONLY when the primary write refuses, without an
653
+ // expectedRevision (the controller documents undefined as an
654
+ // unconditional write), so a stale-revision refusal heals in place
655
+ // and a hard refusal surfaces its exact host message instead of a
656
+ // bare「宿主拒绝了写入」with no reason.
657
+ const directMutate = props.directMutate;
658
+ const view = props.view === 'summary' ? 'summary' : 'page';
659
+ const live = form !== null && typeof form === 'object'
660
+ && typeof form.subscribe === 'function' && typeof form.getSnapshot === 'function' && typeof form.set === 'function'
661
+ ? form : undefined;
662
+ const host = live === undefined && form !== null && typeof form === 'object'
663
+ && typeof form.mutate === 'function' && form.state !== null && typeof form.state === 'object'
664
+ ? form : undefined;
665
+ const liveSnap = react.useSyncExternalStore(
666
+ live ? (cb) => live.subscribe(cb) : noopSubscribe,
667
+ live ? () => live.getSnapshot() : () => NO_FORM_SNAP,
668
+ );
669
+ const snap = host !== undefined ? host.state : liveSnap;
670
+ const [saving, setSaving] = react.useState(false);
671
+ // `false` = no failure; `true` = failure without a host message;
672
+ // a string = the host's exact refusal (RemoteError.message).
673
+ const [failed, setFailed] = react.useState(false);
674
+ // v0.8.1: per-field edit drafts (field → text; absent = untouched,
675
+ // the control shows the snapshot value) and the field whose current
676
+ // draft failed local validation ('' = none). A failed SAVE keeps
677
+ // the draft for correction; an accepted write clears it.
678
+ const [drafts, setDrafts] = react.useState({});
679
+ const [invalid, setInvalid] = react.useState('');
680
+ // v0.8.3: the live model catalog face (optional prop; absent on hosts
681
+ // without remote.session — the dropdown then renders empty and no
682
+ // availability warning is ever shown).
683
+ const catalog = props.catalog;
684
+ const catalogSnap = react.useSyncExternalStore(
685
+ catalog ? (cb) => catalog.subscribe(cb) : noopSubscribe,
686
+ catalog ? () => catalog.getSnapshot() : () => NO_FORM_SNAP,
687
+ );
688
+ const catalogOptions = catalogSnap && Array.isArray(catalogSnap.options) ? catalogSnap.options : [];
689
+ const on = snap.status === 'ready' && snap.value != null && snap.value.allGoalsMode === true;
690
+ const cfg = snap.status === 'ready' && snap.value !== null && typeof snap.value === 'object' ? snap.value : {};
691
+ const disabled = (live === undefined && host === undefined) || snap.status !== 'ready' || snap.writable === false || saving;
692
+ const setDraft = (field, text) => setDrafts((d) => ({ ...d, [field]: text }));
693
+ const clearDraft = (field) => setDrafts((d) => {
694
+ if (!(field in d)) return d;
695
+ const next = { ...d };
696
+ delete next[field];
697
+ return next;
698
+ });
699
+
700
+ // One write for any volatile field; the toggle is
701
+ // writeField('allGoalsMode', !on). Both write paths land in the same
702
+ // host mutation: ConfigForm.set/unset are one-field sugar over
703
+ // ConfigForm.mutate, and the host's ConfigPageForm.mutate IS that
704
+ // form's mutate (the expected revision carried explicitly). The
705
+ // host commits the write into the running plugin instance
706
+ // (volatile) and the next snapshot / page render pushes the
707
+ // accepted value back here.
708
+ // Failure policy (v0.7.4): the transport can REFUSE (settles
709
+ // false) or stall (the observed "保存中" hang). Neither is
710
+ // silent: a refused write shows saveFailed for a few seconds,
711
+ // and a stalled write releases the controls after 15 s with the
712
+ // same hint — every control always returns to the snapshot value,
713
+ // which is the only state the host confirmed.
714
+ // v0.7.6: a refused write is retried ONCE through the direct
715
+ // settings transport (props.directMutate, no expectedRevision).
716
+ // Same落点 (user patch row via configEditor), unconditional
717
+ // revision — a stale-revision conflict therefore heals, and any
718
+ // remaining refusal reports its host message verbatim.
719
+ const writeField = (field, value) => {
720
+ if (disabled) return;
721
+ setSaving(true);
722
+ setFailed(false);
723
+ setInvalid('');
724
+ let settled = false;
725
+ const finish = (ok, detail) => {
726
+ if (settled) return;
727
+ settled = true;
728
+ setSaving(false);
729
+ if (ok) { clearDraft(field); return; }
730
+ setFailed(detail || true);
731
+ setTimeout(() => setFailed(false), 6000);
732
+ };
733
+ const guard = setTimeout(() => finish(false), 15000);
734
+ const op = value === UNSET
735
+ ? { op: 'unset', path: [field] }
736
+ : { op: 'set', path: [field], value };
737
+ const write = live !== undefined
738
+ ? (value === UNSET ? live.unset(field) : live.set(field, value))
739
+ : host.mutate([op], snap.revision);
740
+ Promise.resolve(write)
741
+ .then(async (accepted) => {
742
+ if (accepted !== false) { clearTimeout(guard); finish(true); return; }
743
+ if (typeof directMutate !== 'function') { clearTimeout(guard); finish(false); return; }
744
+ try {
745
+ const answer = await directMutate([op]);
746
+ clearTimeout(guard);
747
+ if (answer && typeof answer === 'object' && answer.ok === false) {
748
+ finish(false, answer.error && answer.error.message);
749
+ } else finish(true);
750
+ } catch (error) {
751
+ clearTimeout(guard);
752
+ finish(false, error && error.message);
753
+ }
754
+ })
755
+ .catch((error) => { clearTimeout(guard); finish(false, error && error.message); });
756
+ };
757
+ const toggle = () => writeField('allGoalsMode', !on);
758
+
759
+ // Text/number commit (Enter or blur): an untouched field never
760
+ // writes; a draft equal to the snapshot just clears; a blank draft
761
+ // restores the schema default through an `unset` op; a number
762
+ // outside its range flags the field instead of writing.
763
+ const commitField = (spec) => {
764
+ const draft = drafts[spec.field];
765
+ if (draft === undefined) return;
766
+ const current = cfg[spec.field];
767
+ const text = draft.trim();
768
+ if (text === (current === undefined || current === null ? '' : String(current))) {
769
+ clearDraft(spec.field);
770
+ setInvalid('');
771
+ return;
772
+ }
773
+ if (text === '') { writeField(spec.field, UNSET); return; }
774
+ if (spec.kind === 'number') {
775
+ const n = Number(text);
776
+ if (!Number.isInteger(n) || n < spec.min) { setInvalid(spec.field); return; }
777
+ writeField(spec.field, n);
778
+ return;
779
+ }
780
+ writeField(spec.field, text);
781
+ };
782
+
783
+ if (view === 'summary') {
784
+ return jsx.jsx('span', { children: snap.status === 'ready' ? t(on ? 'settings.summaryOn' : 'settings.summaryOff') : t('settings.unavailable') });
785
+ }
786
+
787
+ const fieldRow = (spec) => {
788
+ // v0.8.3: availability verdict for the configured (snapshot) value —
789
+ // drafts are uncommitted text and never warn. Only a loaded catalog
790
+ // can flag; an empty/failed catalog keeps every value "available".
791
+ const configuredValue = cfg[spec.field] === undefined || cfg[spec.field] === null ? '' : String(cfg[spec.field]);
792
+ const modelUnavailable = spec.kind === 'model'
793
+ && !isConfiguredModelAvailable(configuredValue, catalogSnap);
794
+ const listId = 'cybernetics-models-' + spec.field;
795
+ return jsx.jsxs('div', { style: settingsStyles.field, children: [
796
+ jsx.jsx('div', { style: settingsStyles.title, children: t(spec.labelKey) }),
797
+ jsx.jsx('div', { style: settingsStyles.desc, children: t(spec.hintKey) }),
798
+ snap.status === 'ready'
799
+ ? jsx.jsxs('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 }, children: [
800
+ jsx.jsx('input', {
801
+ type: 'text',
802
+ // datalist: native dropdown over the catalog options; the
803
+ // input stays a free text field, so manual entry is the
804
+ // built-in fallback (and values off-catalog still commit).
805
+ list: spec.kind === 'model' && catalogOptions.length > 0 ? listId : undefined,
806
+ inputMode: spec.kind === 'number' ? 'numeric' : undefined,
807
+ 'aria-label': t(spec.labelKey),
808
+ 'aria-invalid': invalid === spec.field || undefined,
809
+ disabled,
810
+ value: drafts[spec.field] !== undefined
811
+ ? drafts[spec.field]
812
+ : configuredValue,
813
+ onChange: (e) => setDraft(spec.field, e && e.target ? String(e.target.value) : ''),
814
+ onKeyDown: (e) => {
815
+ if (!e) return;
816
+ if (e.key === 'Enter') commitField(spec);
817
+ if (e.key === 'Escape') { clearDraft(spec.field); setInvalid(''); }
818
+ },
819
+ onBlur: () => commitField(spec),
820
+ style: { ...settingsStyles.input, ...(invalid === spec.field ? settingsStyles.inputInvalid : {}) },
821
+ }),
822
+ spec.kind === 'model' && catalogOptions.length > 0
823
+ ? jsx.jsx('datalist', { id: listId, children: catalogOptions.map((opt) =>
824
+ jsx.jsx('option', { value: opt.value, label: opt.label ?? opt.value }, opt.value)) })
825
+ : null,
826
+ ] })
827
+ : null,
828
+ modelUnavailable
829
+ ? jsx.jsxs('div', { style: { ...settingsStyles.invalid, color: '#d29922', display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }, children: [
830
+ jsx.jsx('span', { children: t('settings.modelUnavailable') }),
831
+ // One-click clear = an explicit user action writing an unset
832
+ // op (same writeField path as blanking the field) — never a
833
+ // silent auto-unset of stored config (recorded trade-off in
834
+ // docs/CHANGELOG.md v0.8.3).
835
+ jsx.jsx('button', {
836
+ type: 'button',
837
+ 'aria-label': t('settings.modelClear') + ' ' + t(spec.labelKey),
838
+ disabled,
839
+ onClick: () => writeField(spec.field, UNSET),
840
+ style: { ...settingsStyles.apply, alignSelf: 'auto' },
841
+ children: t('settings.modelClear'),
842
+ }),
843
+ ] })
844
+ : null,
845
+ invalid === spec.field ? jsx.jsx('div', { style: settingsStyles.invalid, children: t('settings.invalidNumber') }) : null,
846
+ ] }, spec.field);
847
+ };
848
+
849
+ return jsx.jsxs('div', { style: settingsStyles.card, children: [
850
+ jsx.jsxs('div', { style: settingsStyles.row, children: [
851
+ jsx.jsxs('div', { style: settingsStyles.main, children: [
852
+ jsx.jsx('div', { style: settingsStyles.title, children: t('settings.title') }),
853
+ jsx.jsx('div', { style: settingsStyles.desc, children: t('settings.description') }),
854
+ ] }),
855
+ snap.status === 'ready'
856
+ ? jsx.jsx('button', {
857
+ type: 'button', role: 'switch', 'aria-checked': on, 'aria-label': t('settings.title'),
858
+ disabled, onClick: toggle,
859
+ style: { ...settingsStyles.toggle, ...(on ? settingsStyles.trackOn : settingsStyles.trackOff) },
860
+ children: jsx.jsx('span', { style: { ...settingsStyles.knob, ...(on ? settingsStyles.knobOn : settingsStyles.knobOff) } }),
861
+ })
862
+ : null,
863
+ ] }),
864
+ ...SETTINGS_FIELDS.map(fieldRow),
865
+ snap.status !== 'ready' ? jsx.jsx('div', { style: settingsStyles.unavailable, children: t('settings.unavailable') }) : null,
866
+ saving ? jsx.jsx('div', { style: settingsStyles.unavailable, children: t('settings.saving') }) : null,
867
+ !saving && failed ? jsx.jsx('div', { style: { ...settingsStyles.unavailable, color: '#d29922' }, children: failed === true ? t('settings.saveFailed') : t('settings.saveFailedDetail', { message: failed }) }) : null,
868
+ ] });
869
+ }
870
+ //#endregion
871
+
397
872
  //#region plugin apply
398
873
  const name = 'dsh-cybernetics';
399
- const inject = ['slots', 'sessions', 'locale'];
874
+ // configForms: the per-entry ConfigForm registry (@deepseek-ai/dsh-client-ui-settings)
875
+ // that backs the plugins-page settings card below.
876
+ const inject = ['slots', 'sessions', 'locale', 'configForms',
877
+ // v0.7.6: the settings card's diagnostic fallback write rides the
878
+ // same namespace remote the official ui-settings declares
879
+ // (["remote", "remote.settings"]). Both are required: ctx access is
880
+ // gated by the inject declaration (client-runner guard), so an
881
+ // undeclared `remote` would throw on read and silently disable the
882
+ // fallback. Optional at runtime (guarded in apply): a host without
883
+ // the namespace parks this client module exactly as it would
884
+ // ui-settings itself — the web profile always serves it.
885
+ 'remote', 'remote.settings',
886
+ // v0.8.3: the settings card's model dropdown reads the host model
887
+ // catalog through the session namespace (same service the official
888
+ // ui-settings-subagent page declares). Guarded at runtime: absent →
889
+ // no dropdown, no warnings, text entry as before.
890
+ 'remote.session'];
400
891
 
401
892
  function apply(ctx) {
402
893
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-cybernetics: dictionaries');
403
894
  const t = ctx.locale.bind(NS);
404
895
 
896
+ // v0.7.2: bind the row's ConfigForm once per apply body. The namespace
897
+ // is the loader row id (`dsh-cybernetics`), the same convention the
898
+ // official cot-translation bundle uses (`ctx.configForms.get(ns)`). If
899
+ // the host does not serve this namespace yet, the card renders its
900
+ // unavailable state instead of throwing.
901
+ let settingsForm;
902
+ try {
903
+ settingsForm = ctx.configForms.get(SETTINGS_ENTRY_ID);
904
+ } catch {
905
+ settingsForm = undefined;
906
+ }
907
+ // v0.7.6 path-(b) diagnostics face: the direct settings transport,
908
+ // bound from this module's own context (`remote.settings` inject).
909
+ // Guarded: a deployment without the namespace leaves it undefined
910
+ // and the card falls back to the v0.7.4 hint-only failure state.
911
+ let settingsDirectMutate;
912
+ try {
913
+ if (ctx.remote && ctx.remote.settings && typeof ctx.remote.settings.mutate === 'function') {
914
+ settingsDirectMutate = (ops, expectedRevision) => ctx.remote.settings.mutate(SETTINGS_ENTRY_ID, ops, expectedRevision);
915
+ }
916
+ } catch {
917
+ settingsDirectMutate = undefined;
918
+ }
919
+ // v0.8.3: the live model catalog for the settings card's dropdown +
920
+ // invalid-model warnings. OPTIONAL: a host without the remote.session
921
+ // namespace (or without modelCatalog) leaves it undefined — the card
922
+ // renders text-only fields exactly as pre-v0.8.3, no crash, no
923
+ // false warnings. Refresh on `llm/adapters-updated` (the same
924
+ // invalidation the 子智能体 settings page listens to), so a model
925
+ // deleted/added in the model settings updates the dropdown live.
926
+ let catalogStore;
927
+ try {
928
+ if (ctx.remote && ctx.remote.session && typeof ctx.remote.session.modelCatalog === 'function') {
929
+ catalogStore = createModelCatalogStore();
930
+ ctx.effect(() => {
931
+ catalogStore.load(ctx.remote.session);
932
+ if (ctx.remote.$on && typeof ctx.remote.$on === 'function') {
933
+ ctx.remote.$on('llm/adapters-updated', () => { catalogStore.load(ctx.remote.session); });
934
+ }
935
+ }, 'dsh-cybernetics: model catalog');
936
+ }
937
+ } catch {
938
+ catalogStore = undefined;
939
+ }
940
+ const settingsInject = () => ({ form: settingsForm, directMutate: settingsDirectMutate, catalog: catalogStore });
941
+ // v0.7.2 (the actual gap): the official Plugins page renders the
942
+ // 内置插件配置 group cards ONLY from the `plugins.item` slot
943
+ // (ItemCard in @deepseek-ai/dsh-client-ui-plugin-manager client.js:
944
+ // basicCards = ledger.items from slot "plugins.item"; ItemDetail
945
+ // renders view "page" with the host form for item.id). The keyed
946
+ // seats below surface only on an installed bundle's own page, which
947
+ // this linked bundle never reaches in the 已安装插件 group — that was
948
+ // why v0.7.1's schema alone (and the first v0.7.2 cut) showed no card.
949
+ // Register the list card UNCONDITIONALLY (v0.7.5 hardening): the earlier
950
+ // cut gated it on configForms.whileServed, so a deployment where the
951
+ // host does not (yet) serve the `dsh-cybernetics` namespace showed NO
952
+ // card at all — indistinguishable from the registration never running.
953
+ // ctx.configForms.get() binds a live ConfigFormController that follows
954
+ // the shared describe mirror (ConfigForms.get → new ConfigFormController
955
+ // + mirror.ensure), so a card registered before the namespace appears
956
+ // flips to the toggle the moment the host starts serving it; while it
957
+ // does not, the card renders its `settings.unavailable` line — visible
958
+ // and diagnosable instead of absent.
959
+ ctx.effect(() => ctx.slots.inject('plugins.item', () => ctx.slots.register({
960
+ name: 'plugins.item',
961
+ id: SETTINGS_ENTRY_ID,
962
+ order: 80,
963
+ label: () => t('settings.cardLabel'),
964
+ locale: NS,
965
+ inject: settingsInject,
966
+ }, SettingsCard)), 'dsh-cybernetics: plugins-page settings card');
967
+ // The dispatch key bundles use the profile dependency name (the value
968
+ // in dsh.profile.bundles = `dsh-cybernetics`); register the scoped
969
+ // package manifest name too, so either resolution finds the card.
970
+ for (const bundleKey of ['dsh-cybernetics', '@mars.liu/dsh-cybernetics']) {
971
+ ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
972
+ name: 'plugins.row.config',
973
+ key: bundleKey + '#' + SETTINGS_ENTRY_ID,
974
+ locale: NS,
975
+ inject: settingsInject,
976
+ }, SettingsCard));
977
+ ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
978
+ name: 'plugins.bundle.config',
979
+ key: bundleKey,
980
+ locale: NS,
981
+ inject: settingsInject,
982
+ }, SettingsCard));
983
+ }
984
+
405
985
  // Conversation-view tab, same slot the trajectory/context tabs use.
406
986
  // `t` reaches the view as a slot-provided prop from `locale: NS`
407
987
  // (PropsLocale) — do NOT also pass a hand-bound t through inject:
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@mars.liu/dsh-cybernetics",
3
- "version": "0.6.0",
3
+ "version": "0.8.4",
4
+ "license": "MIT",
4
5
  "private": false,
5
6
  "files": [
6
7
  "src",
@@ -33,12 +34,16 @@
33
34
  "@deepseek-ai/dsh-client-locale",
34
35
  "@deepseek-ai/dsh-client-ui-conversation",
35
36
  "@deepseek-ai/dsh-client-ui-renderer",
36
- "@deepseek-ai/dsh-client-ui-session"
37
+ "@deepseek-ai/dsh-client-ui-session",
38
+ "@deepseek-ai/dsh-client-ui-settings"
37
39
  ],
38
40
  "platform": "web",
39
41
  "immediately": true
40
42
  }
41
43
  },
44
+ "dependencies": {
45
+ "@deepseek-ai/schemastery": "^3.18.5"
46
+ },
42
47
  "peerDependencies": {
43
48
  "@deepseek-ai/dsh-session": "*"
44
49
  }