@khorsheed/dsh-local-agent-kimi 0.1.0-rc.6

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.
Files changed (50) hide show
  1. package/README.en.md +132 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +132 -0
  4. package/cordis.patch.yml +34 -0
  5. package/lib/client.js +1066 -0
  6. package/lib/index.js +4716 -0
  7. package/lib/invariant.js +31 -0
  8. package/lib/types/client/SettingsCard.d.ts +77 -0
  9. package/lib/types/client/SettingsCard.js +197 -0
  10. package/lib/types/client/icons.d.ts +18 -0
  11. package/lib/types/client/icons.js +2 -0
  12. package/lib/types/client/index.d.ts +42 -0
  13. package/lib/types/client/index.js +89 -0
  14. package/lib/types/client/locales.d.ts +64 -0
  15. package/lib/types/client/locales.js +55 -0
  16. package/lib/types/credential-guard.d.ts +29 -0
  17. package/lib/types/credential-guard.js +107 -0
  18. package/lib/types/index.d.ts +69 -0
  19. package/lib/types/index.js +270 -0
  20. package/lib/types/invariant.d.ts +16 -0
  21. package/lib/types/invariant.js +33 -0
  22. package/lib/types/kimi-cli-provider.d.ts +215 -0
  23. package/lib/types/kimi-cli-provider.js +855 -0
  24. package/lib/types/live-driver.d.ts +245 -0
  25. package/lib/types/live-driver.js +1312 -0
  26. package/lib/types/live-switch.d.ts +78 -0
  27. package/lib/types/live-switch.js +112 -0
  28. package/lib/types/member-bridge-config.d.ts +43 -0
  29. package/lib/types/member-bridge-config.js +80 -0
  30. package/lib/types/model-broker.d.ts +97 -0
  31. package/lib/types/model-broker.js +205 -0
  32. package/lib/types/model-catalog.d.ts +26 -0
  33. package/lib/types/model-catalog.js +86 -0
  34. package/lib/types/model-configuration.d.ts +11 -0
  35. package/lib/types/model-configuration.js +55 -0
  36. package/lib/types/preset-tools.d.ts +20 -0
  37. package/lib/types/preset-tools.js +36 -0
  38. package/lib/types/provision.d.ts +131 -0
  39. package/lib/types/provision.js +363 -0
  40. package/lib/types/records.d.ts +35 -0
  41. package/lib/types/records.js +85 -0
  42. package/lib/types/session-configuration.d.ts +5 -0
  43. package/lib/types/session-configuration.js +26 -0
  44. package/lib/types/session-mirror.d.ts +180 -0
  45. package/lib/types/session-mirror.js +446 -0
  46. package/lib/types/session-view.d.ts +121 -0
  47. package/lib/types/session-view.js +423 -0
  48. package/locale/en.json +6 -0
  49. package/locale/zh.json +6 -0
  50. package/package.json +107 -0
@@ -0,0 +1,31 @@
1
+ //#region lib/types/invariant.js
2
+ /**
3
+ * Package-owned invariant companion for `@khorsheed/dsh-local-agent-kimi`.
4
+ * @module @khorsheed/dsh-local-agent-kimi/invariant
5
+ */
6
+ const PACKAGE_NAME = "@khorsheed/dsh-local-agent-kimi";
7
+ /** Cordis companion plugin name. */
8
+ const name = "local-agent-kimi-invariant";
9
+ /** Service required before the companion can reserve package ownership. */
10
+ const inject = ["invariants"];
11
+ /**
12
+ * The kimi harness definition is this bundle's contract with the core
13
+ * registry: whenever a `kimi` harness registers, its scoped-home variable must
14
+ * be the one this bundle pins.
15
+ */
16
+ const install = (ctx, fail) => {
17
+ ctx.on("internal/dispatch", (_mode, eventName, args) => {
18
+ if (eventName !== "localAgent/harness-added") return;
19
+ const harness = args[0];
20
+ if (harness.name !== "kimi") return;
21
+ if (harness.homeEnvVar !== "KIMI_CODE_HOME") fail("kimi harness registered with a home env other than the local-agent-kimi contract");
22
+ }, { global: true });
23
+ };
24
+ /**
25
+ * Register this package's invariant companion.
26
+ * @param ctx - plugin context carrying the invariant registry.
27
+ * @returns the installed registration's disposer.
28
+ */
29
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
30
+ //#endregion
31
+ export { apply, inject, name };
@@ -0,0 +1,77 @@
1
+ import type { HarnessModelPickerInput } from '@khorsheed/dsh-local-agent/client';
2
+ import type { ReactNode } from 'react';
3
+ import type { SettingsScope } from '@khorsheed/dsh-local-agent/src/client/settings-scope.ts';
4
+ import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
5
+ import type { LocalAgentModelInfo } from '@khorsheed/dsh-local-agent/types';
6
+ import { type ProviderAuthBlockProps, type ProviderAuthInjected } from '@khorsheed/dsh-local-agent/src/client/ProviderAuthBlock.tsx';
7
+ import { NS } from './locales.ts';
8
+ /** The `local-agent-kimi` settings namespace section the card edits. */
9
+ export interface KimiLiveSettings {
10
+ /** Resident (live) mode: one resident `kimi acp` process per member. */
11
+ live?: boolean;
12
+ /** Live mirror granularity: folded events or per-chunk streaming. */
13
+ liveMirrorGranularity?: 'event' | 'token';
14
+ /**
15
+ * The model every delegation round starts the CLI with. Absent (the field
16
+ * cleared) means the plugin passes no model at all — the scoped `config.toml`'s `default_model` decides,
17
+ * exactly as before the key existed.
18
+ */
19
+ model?: string;
20
+ /** Model identifiers saved before; the input's suggestions, capped at five. */
21
+ recentModels?: readonly string[];
22
+ }
23
+ /** Injected face of the kimi settings card. */
24
+ export interface KimiSettingsCardInjected {
25
+ renderModelPicker?: ((props: HarnessModelPickerInput) => ReactNode) | undefined;
26
+ /** Bound settings scope for the local-agent-kimi namespace. */
27
+ scope: SettingsScope<KimiLiveSettings>;
28
+ /** The auth block's query/command faces, backed by the family core Remote. */
29
+ auth: ProviderAuthInjected;
30
+ /** Translate bound to the family core's `local-agent` namespace (the auth block's copy lives there). */
31
+ authT: ProviderAuthBlockProps['t'];
32
+ /**
33
+ * The harness's memberless model surface (the gateway's `harnessModel`
34
+ * Remote). Undefined means the broker is absent (a core without one): the
35
+ * card then renders exactly the pre-broker free-text field, with no
36
+ * effective-model line and the recent-models suggestions.
37
+ */
38
+ harnessModel: () => Promise<LocalAgentModelInfo | undefined>;
39
+ hooks: {
40
+ /** The same scope as a hooks source, so the card reacts to external writes. */
41
+ settings: SettingsScope<KimiLiveSettings>;
42
+ };
43
+ }
44
+ /**
45
+ * Full props of the 0.1.5 settings.plugin.item card entry. The removed slot's
46
+ * owner share was intentionally empty and its root scope delivered the global
47
+ * seats; the structural type below is exact about the one seat the auth block
48
+ * consumes (the slot name is gone from the alpha.2 SlotMap, so the
49
+ * registration goes through a duck-typed narrow — see client/index.ts).
50
+ */
51
+ export type KimiSettingsCardProps = InjectFace<KimiSettingsCardInjected> & PropsLocale<typeof NS> & {
52
+ /** The standing root-scope global seat (ui-session's merge), delivered to the 0.1.5 card by the renderer. */
53
+ useSessions: ProviderAuthBlockProps['useSessions'];
54
+ };
55
+ /** Full props of the alpha.2 plugins.bundle.config entry (owner prop `view`). */
56
+ export type KimiBundleConfigProps = PropsRuntime<'plugins.bundle.config'> & InjectFace<KimiSettingsCardInjected> & PropsLocale<typeof NS>;
57
+ /**
58
+ * The kimi harness settings card in the 0.1.5 plugin configuration tab: the
59
+ * same collapsible chrome the official plugin cards use, re-implemented
60
+ * locally (the bundle-purity gate forbids value-importing the official chrome
61
+ * — the context-guard pattern), with the at-a-glance credential dot in the
62
+ * header. Explanation copy lives in hover/focus bubbles behind ⓘ anchors —
63
+ * the card's rows stay one line each.
64
+ * @param props - the injected scope/auth faces and copy.
65
+ * @returns the card.
66
+ */
67
+ export declare function KimiSettingsCard(props: KimiSettingsCardProps): import("react").JSX.Element;
68
+ /**
69
+ * The bundle's configuration on the alpha.2 Plugins page
70
+ * (`plugins.bundle.config`, keyed by package name): the page draws the title,
71
+ * the icon, and the crumb itself, so the entry renders the one-liner for the
72
+ * `summary` view and the bare form — with its own save control — for `page`.
73
+ * @param props - the owner view, the injected scope/auth faces, and copy.
74
+ * @returns the entry.
75
+ */
76
+ export declare function KimiBundleConfig({ view, useSettings, scope, auth, authT, renderModelPicker, harnessModel, useSessions, t }: KimiBundleConfigProps): import("react").JSX.Element;
77
+ //# sourceMappingURL=SettingsCard.d.ts.map
@@ -0,0 +1,197 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { Tooltip } from '@deepseek-ai/dsh-client-ui-primitives';
4
+ import { IconChevronDownOutlineMedium } from './icons.js';
5
+ // The shared auth block is bundled from the family core's source — the
6
+ // sanctioned core/companion edge (the host half already depends on the core);
7
+ // the block carries no runtime identity to share.
8
+ import { ProviderAuthBlock, } from '@khorsheed/dsh-local-agent/src/client/ProviderAuthBlock.tsx';
9
+ import { AuthStatusDot } from '@khorsheed/dsh-local-agent/src/client/AuthStatusDot.tsx';
10
+ import { useHarnessAuthStatus } from '@khorsheed/dsh-local-agent/src/client/auth-status.ts';
11
+ import css from './SettingsCard.module.css';
12
+ /** How many previously-saved model identifiers the input suggests. */
13
+ const RECENT_MODEL_LIMIT = 5;
14
+ /**
15
+ * The staged card state both settings surfaces share: the resident-mode and
16
+ * model edits write through the bound settingsScope immediately
17
+ * (revision-fenced), so a flip takes effect on the next delegation round
18
+ * without a reload; the memberless model surface is re-read whenever the
19
+ * stored model changes — a save can move the effective layer between settings
20
+ * and the CLI's own default.
21
+ * @param active - whether the surface reads the model surface at all (the summary one-liner never does).
22
+ * @param useSettings - the bound settings hook from the inject hooks compartment.
23
+ * @param scope - the bound settings scope the writes go through.
24
+ * @param harnessModel - the harness's memberless model surface read.
25
+ * @param t - copy.
26
+ */
27
+ function useCardState(active, useSettings, scope, harnessModel, t) {
28
+ const snapshot = useSettings(value => value);
29
+ const [saved, setSaved] = useState(false);
30
+ const [error, setError] = useState(false);
31
+ const ready = snapshot.status === 'ready' && snapshot.writable;
32
+ const live = snapshot.value?.live ?? false;
33
+ // The model input is a DRAFT until saved: `null` means "showing whatever the
34
+ // scope holds", so an external write (another tab, a YAML reload) still
35
+ // reaches the field while the user is not typing in it.
36
+ const storedModel = snapshot.value?.model ?? '';
37
+ const recentModels = snapshot.value?.recentModels ?? [];
38
+ const [modelDraft, setModelDraft] = useState(null);
39
+ const [modelSaved, setModelSaved] = useState(false);
40
+ const [modelError, setModelError] = useState(false);
41
+ const modelValue = modelDraft ?? storedModel;
42
+ // The memberless model surface (effective model + its source + the pickable
43
+ // vocabulary), re-read whenever the stored model changes — a save can move
44
+ // the effective layer between settings and the CLI's own default.
45
+ const [modelInfo, setModelInfo] = useState(undefined);
46
+ useEffect(() => {
47
+ if (!active)
48
+ return;
49
+ let stale = false;
50
+ void harnessModel().then((info) => { if (!stale)
51
+ setModelInfo(info); });
52
+ return () => { stale = true; };
53
+ }, [active, harnessModel, storedModel]);
54
+ /**
55
+ * Commit the model field. A blank value UNSETS the key rather than storing
56
+ * an empty string, so the field re-inherits the YAML composition base — and
57
+ * with no base, the harness is back to passing no model at all.
58
+ */
59
+ const saveModel = () => {
60
+ const next = modelValue.trim();
61
+ setModelSaved(false);
62
+ setModelError(false);
63
+ const write = next === '' ? scope.unset('model') : scope.set('model', next);
64
+ void write.then(async () => {
65
+ // Most-recent-first, deduplicated, capped: the suggestion list is a
66
+ // memory of what this instance has actually run, never a catalog.
67
+ if (next !== '') {
68
+ await scope.set('recentModels', [next, ...recentModels.filter(value => value !== next)].slice(0, RECENT_MODEL_LIMIT));
69
+ }
70
+ setModelDraft(null);
71
+ setModelSaved(true);
72
+ }, () => { setModelError(true); });
73
+ };
74
+ const write = (field, value) => {
75
+ setSaved(false);
76
+ setError(false);
77
+ void scope.set(field, value).then(() => { setSaved(true); }, () => { setError(true); });
78
+ };
79
+ // The suggestion vocabulary: the broker's deduped union when the surface
80
+ // answered, the card's own recent-models memory when it did not. Never a
81
+ // hardcoded catalog. A non-empty list turns the field into a select-like
82
+ // control: the always-visible chevron opens the same vocabulary as a menu.
83
+ const choices = modelInfo?.choices ?? recentModels;
84
+ const [modelMenuOpen, setModelMenuOpen] = useState(false);
85
+ const [modelMenuUp, setModelMenuUp] = useState(false);
86
+ const modelFieldRef = useRef(null);
87
+ // Click-outside and Esc close the model menu (the member composer's picker
88
+ // pattern); the upward flip is measured when the menu opens.
89
+ useEffect(() => {
90
+ if (!modelMenuOpen)
91
+ return;
92
+ const onPointerDown = (event) => {
93
+ if (modelFieldRef.current?.contains(event.target) === true)
94
+ return;
95
+ setModelMenuOpen(false);
96
+ };
97
+ const onKeyDown = (event) => {
98
+ if (event.key === 'Escape')
99
+ setModelMenuOpen(false);
100
+ };
101
+ document.addEventListener('mousedown', onPointerDown);
102
+ document.addEventListener('keydown', onKeyDown);
103
+ return () => {
104
+ document.removeEventListener('mousedown', onPointerDown);
105
+ document.removeEventListener('keydown', onKeyDown);
106
+ };
107
+ }, [modelMenuOpen]);
108
+ const toggleModelMenu = () => {
109
+ if (!modelMenuOpen) {
110
+ const rect = modelFieldRef.current?.getBoundingClientRect();
111
+ if (rect !== undefined) {
112
+ const spaceBelow = window.innerHeight - rect.bottom;
113
+ setModelMenuUp(spaceBelow < 260 && rect.top > spaceBelow);
114
+ }
115
+ }
116
+ setModelMenuOpen(open => !open);
117
+ };
118
+ // An unset field DISPLAYS the default it follows (dimmed, as the input's
119
+ // placeholder — inherited, never pinned), down the chain the broker
120
+ // reports: the scoped config's model, then a cli-builtin source that still
121
+ // names its default (a harness catalog's isDefault entry), then the last
122
+ // observed model the records know, and last the generic copy.
123
+ const inheritedModel = modelInfo?.cliDefault !== undefined && modelInfo.cliDefault !== ''
124
+ ? modelInfo.cliDefault
125
+ : modelInfo?.source === 'cli-builtin' && modelInfo.effective !== undefined && modelInfo.effective !== ''
126
+ ? modelInfo.effective
127
+ : modelInfo?.lastObserved !== undefined && modelInfo.lastObserved !== ''
128
+ ? modelInfo.lastObserved
129
+ : undefined;
130
+ const modelPlaceholder = inheritedModel ?? t('model.placeholder');
131
+ // The menu's leading item: the same chain, spelled as the follow-default
132
+ // choice. It reads checked while the field is unset, and picking it clears
133
+ // the draft back to follow-default (a save then unsets the key).
134
+ const modelDefaultItem = modelInfo?.cliDefault !== undefined && modelInfo.cliDefault !== ''
135
+ ? t('model.menuDefault.cliConfig', { model: modelInfo.cliDefault })
136
+ : modelInfo?.source === 'cli-builtin' && modelInfo.effective !== undefined && modelInfo.effective !== ''
137
+ ? t('model.menuDefault.cliBuiltin', { model: modelInfo.effective })
138
+ : modelInfo?.lastObserved !== undefined && modelInfo.lastObserved !== ''
139
+ ? t('model.menuDefault.lastObserved', { model: modelInfo.lastObserved })
140
+ : t('model.menuDefault');
141
+ return {
142
+ snapshot, saved, error, ready, live, storedModel, modelValue, modelSaved,
143
+ modelError, choices, modelMenuOpen, modelMenuUp, modelFieldRef,
144
+ modelPlaceholder, modelDefaultItem, saveModel, write, toggleModelMenu,
145
+ setModelDraft, setModelMenuOpen,
146
+ };
147
+ }
148
+ /** The card body both settings surfaces share: the auth block, the default-model block, and the resident-mode block. */
149
+ function CardBody({ state, auth, authT, renderModelPicker, useSessions, t }) {
150
+ const { snapshot, saved, error, ready, live, storedModel, modelValue, modelSaved, modelError, choices, modelMenuOpen, modelMenuUp, modelFieldRef, modelPlaceholder, modelDefaultItem, saveModel, write, toggleModelMenu, setModelDraft, setModelMenuOpen, } = state;
151
+ // The free-text input, single-sourced for both presentations: bare when no
152
+ // vocabulary exists (a fresh install degrades to exactly the pre-picker
153
+ // field), or inside the select-like field next to its chevron. No datalist:
154
+ // the chevron menu is the single choice list.
155
+ const modelInputElement = (_jsx("input", { type: "text", className: css.modelInput, value: modelValue, placeholder: modelPlaceholder, "aria-label": t('model.title'), disabled: !ready, onChange: (event) => { setModelDraft(event.target.value); } }));
156
+ return (_jsxs("div", { className: css.body, children: [_jsxs("section", { className: css.block, children: [_jsx("h3", { className: css.blockTitle, children: t('auth.title') }), _jsx(ProviderAuthBlock, { harness: { id: 'kimi', label: 'Kimi Code' }, useSessions: useSessions, status: auth.status, runCommand: auth.runCommand, t: authT })] }), _jsxs("section", { className: css.block, children: [_jsxs("h3", { className: css.blockTitle, children: [t('model.title'), _jsx(Tooltip, { label: t('model.info'), side: "bottom", maxWidth: 360, children: _jsx("button", { type: "button", className: css.info, "aria-label": t('model.info.aria'), children: "\u24D8" }) })] }), _jsxs("div", { className: css.row, children: [renderModelPicker?.({ value: modelValue, onChange: setModelDraft, disabled: !ready, defaultLabel: modelDefaultItem }) ?? (choices.length > 0 ? (_jsxs("div", { className: css.modelField, ref: modelFieldRef, children: [modelInputElement, _jsx("button", { type: "button", className: css.modelMenuButton, "aria-label": t('model.menu'), "aria-haspopup": "menu", "aria-expanded": modelMenuOpen, disabled: !ready, onClick: () => { toggleModelMenu(); }, children: _jsx(IconChevronDownOutlineMedium, { className: modelMenuOpen ? `${css.modelMenuChevron} ${css.modelMenuChevronOpen}` : css.modelMenuChevron }) }), modelMenuOpen && (_jsxs("div", { className: modelMenuUp ? `${css.modelMenu} ${css.modelMenuUp}` : css.modelMenu, role: "menu", "aria-label": t('model.menu'), children: [_jsxs("button", { type: "button", role: "menuitemradio", "aria-checked": modelValue.trim() === '', className: modelValue.trim() === '' ? `${css.modelItemDefault} ${css.modelItemCurrent}` : css.modelItemDefault, onClick: () => { setModelDraft(''); setModelMenuOpen(false); }, children: [_jsx("span", { className: css.modelItemLabel, children: modelDefaultItem }), _jsx("span", { className: css.modelItemCheck, "aria-hidden": true, children: modelValue.trim() === '' ? '✓' : '' })] }), choices.map(choice => (_jsxs("button", { type: "button", role: "menuitemradio", "aria-checked": choice === modelValue, className: choice === modelValue ? css.modelItemCurrent : css.modelItem, onClick: () => { setModelDraft(choice); setModelMenuOpen(false); }, children: [_jsx("span", { className: css.modelItemLabel, children: choice }), _jsx("span", { className: css.modelItemCheck, "aria-hidden": true, children: choice === modelValue ? '✓' : '' })] }, choice)))] }))] })) : modelInputElement), _jsx("button", { type: "button", className: css.modelSave, disabled: !ready || modelValue.trim() === storedModel, onClick: () => { saveModel(); }, children: t('model.save') })] }), modelSaved && _jsx("span", { className: css.saved, children: t('model.applied') }), modelError && _jsx("span", { className: css.errorText, children: t('model.error') })] }), _jsxs("section", { className: css.block, children: [_jsxs("div", { className: css.row, children: [_jsxs("span", { className: css.rowLabel, children: [t('live.title'), _jsx(Tooltip, { label: t('live.info'), side: "bottom", maxWidth: 360, children: _jsx("button", { type: "button", className: css.info, "aria-label": t('live.info.aria'), children: "\u24D8" }) })] }), _jsx("button", { type: "button", role: "switch", "aria-checked": live, "aria-label": t('live.title'), className: live ? `${css.switch} ${css.switchOn}` : css.switch, disabled: !ready, onClick: () => { write('live', !live); }, children: _jsx("span", { className: css.knob }) })] }), saved && _jsx("span", { className: css.saved, children: t('live.applied') }), error && _jsx("span", { className: css.errorText, children: t('live.error') }), snapshot.status === 'unavailable' && (_jsx("span", { className: css.hint, children: t('live.unavailable') }))] })] }));
157
+ }
158
+ /**
159
+ * The kimi harness settings card in the 0.1.5 plugin configuration tab: the
160
+ * same collapsible chrome the official plugin cards use, re-implemented
161
+ * locally (the bundle-purity gate forbids value-importing the official chrome
162
+ * — the context-guard pattern), with the at-a-glance credential dot in the
163
+ * header. Explanation copy lives in hover/focus bubbles behind ⓘ anchors —
164
+ * the card's rows stay one line each.
165
+ * @param props - the injected scope/auth faces and copy.
166
+ * @returns the card.
167
+ */
168
+ export function KimiSettingsCard(props) {
169
+ const { useSettings, scope, auth, authT, renderModelPicker, harnessModel, useSessions, t } = props;
170
+ const [open, setOpen] = useState(false);
171
+ // The model surface read is NOT open-gated on this surface (it warms the
172
+ // vocabulary while the card is collapsed), so the 0.1.5 card always reads.
173
+ const state = useCardState(true, useSettings, scope, harnessModel, t);
174
+ // The at-a-glance credential dot in the collapsed header: every mount
175
+ // re-probes (a credential expiring mid-session must flip the dot at the
176
+ // next view); the bus dedupes identical results, so no re-render storm.
177
+ const authStatus = useHarnessAuthStatus('kimi', auth.status);
178
+ const dotLabel = authT(authStatus === 'authenticated' ? 'settings.authenticated'
179
+ : authStatus === 'anonymous' ? 'settings.notAuthenticated'
180
+ : authStatus === 'checking' ? 'loading' : 'error');
181
+ const title = t('card.title');
182
+ return (_jsxs("li", { className: open ? `${css.card} ${css.cardOpen}` : css.card, children: [_jsxs("button", { type: "button", className: css.header, "aria-expanded": open, "aria-label": `${t(open ? 'card.collapse' : 'card.expand')}: ${title}`, onClick: () => { setOpen(!open); }, children: [_jsxs("span", { className: css.headText, children: [_jsxs("span", { className: css.nameRow, children: [_jsx("span", { className: css.name, children: title }), _jsx(AuthStatusDot, { status: authStatus, label: dotLabel })] }), _jsx("span", { className: css.description, children: t('card.description') })] }), _jsx(IconChevronDownOutlineMedium, { className: open ? `${css.chevron} ${css.chevronOpen}` : css.chevron })] }), open && _jsx(CardBody, { state: state, auth: auth, authT: authT, renderModelPicker: renderModelPicker, useSessions: useSessions, t: t })] }));
183
+ }
184
+ /**
185
+ * The bundle's configuration on the alpha.2 Plugins page
186
+ * (`plugins.bundle.config`, keyed by package name): the page draws the title,
187
+ * the icon, and the crumb itself, so the entry renders the one-liner for the
188
+ * `summary` view and the bare form — with its own save control — for `page`.
189
+ * @param props - the owner view, the injected scope/auth faces, and copy.
190
+ * @returns the entry.
191
+ */
192
+ export function KimiBundleConfig({ view, useSettings, scope, auth, authT, renderModelPicker, harnessModel, useSessions, t }) {
193
+ const state = useCardState(view === 'page', useSettings, scope, harnessModel, t);
194
+ if (view === 'summary')
195
+ return _jsx("span", { className: css.description, children: t('card.description') });
196
+ return _jsx(CardBody, { state: state, auth: auth, authT: authT, renderModelPicker: renderModelPicker, useSessions: useSessions, t: t });
197
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Generated by scripts/sync-icon-artwork.mts from @deepseek-ai/dsh-client-ui-primitives
3
+ * (v0.1.7-rc.1, harness 46a7f68b09) — do not edit by hand. The 0.1.5 and rc.1 host lines
4
+ * share no icon export name, so the rc.1 artwork is inlined here: pure SVG,
5
+ * no host runtime identity, identical on every line. Re-run the generator
6
+ * after adding an icon import or bumping the harness checkout.
7
+ *
8
+ * @module @khorsheed/dsh-local-agent-kimi/client
9
+ */
10
+ /** Shared props for every product icon component (mirrors the upstream IconProps). */
11
+ export interface IconProps {
12
+ /** Square edge in px; defaults to the glyph's own drawn size. */
13
+ size?: number | undefined;
14
+ /** Extra class for layout placement; color rides currentColor. */
15
+ className?: string | undefined;
16
+ }
17
+ export declare const IconChevronDownOutlineMedium: ({ size, className }: IconProps) => import("react").JSX.Element;
18
+ //# sourceMappingURL=icons.d.ts.map
@@ -0,0 +1,2 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const IconChevronDownOutlineMedium = ({ size = 14, className }) => (_jsx("svg", { width: size, height: size, className: className, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", strokeWidth: 1.3, children: _jsx("path", { d: "M4 6L7.29289 9.29289C7.68342 9.68342 8.31658 9.68342 8.70711 9.29289L12 6", stroke: "currentColor" }) }));
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Local-agent-kimi plugin, browser half: the kimi settings surface, one face
3
+ * per install shape and host line — a standalone install renders the
4
+ * bundle's own configuration on its Plugins-page detail view
5
+ * (`plugins.bundle.config`, keyed by package name), a family-bundle install
6
+ * renders the same card through the row-level configure entry on the
7
+ * BUNDLE's detail view (`plugins.row.config`, keyed
8
+ * `@khorsheed/dsh-bundle-local-agent#local-agent-kimi`), and 0.1.5 renders
9
+ * the `settings.plugin.item` card (keyed to the `local-agent-kimi`
10
+ * settings namespace the host half registers) in the official
11
+ * Plugins → 可配置插件 tab. The card carries the family core's shared
12
+ * ProviderAuthBlock (login/logout/device-code, backed by the core's
13
+ * localAgentGateway Remote and the commands channel), the default-model block
14
+ * (free-text field, the broker-fed effective-model line and choices), and the
15
+ * resident-mode switch, whose writes ride the bound settingsScope — the host
16
+ * watcher hot-applies them, no reload. Every read degrades: an absent gateway
17
+ * renders the auth block's 'unavailable' state and drops the effective-model
18
+ * line, an unregistered namespace disables the live controls.
19
+ * @module @khorsheed/dsh-local-agent-kimi/client
20
+ */
21
+ import type { Context } from '@deepseek-ai/cordis';
22
+ import { en, NS, zh, type LocalAgentKimiKey } from './locales.ts';
23
+ export { KimiBundleConfig, KimiSettingsCard } from './SettingsCard.tsx';
24
+ export type { KimiLiveSettings, KimiBundleConfigProps, KimiSettingsCardInjected, KimiSettingsCardProps, } from './SettingsCard.tsx';
25
+ export { en, NS, zh };
26
+ export type { LocalAgentKimiKey };
27
+ /**
28
+ * Required services: slot registry, command Remote, and locale registry. The
29
+ * settings scope is NOT a static inject — its service name differs per host
30
+ * line (`settingsScope` on 0.1.5, `configForms` on rc.1), so a static entry
31
+ * would pend the whole client plugin on the other line; bindSettingsScope
32
+ * probes the serving one instead (the settings client package is a declared
33
+ * client inject, so one of them is always already up).
34
+ */
35
+ export declare const inject: string[];
36
+ /**
37
+ * Client plugin body: register the dictionaries and the kimi settings
38
+ * surfaces bound to the local-agent-kimi namespace.
39
+ * @param ctx - client root context.
40
+ */
41
+ export declare function apply(ctx: Context): void;
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,89 @@
1
+ import { bindSettingsScope } from '@khorsheed/dsh-local-agent/src/client/settings-scope.ts';
2
+ import { en, NS, zh } from './locales.js';
3
+ import { KimiBundleConfig, KimiSettingsCard, } from './SettingsCard.js';
4
+ export { KimiBundleConfig, KimiSettingsCard } from './SettingsCard.js';
5
+ export { en, NS, zh };
6
+ /**
7
+ * This bundle's package name — the key the Plugins page dispatches
8
+ * `plugins.bundle.config` entries on (identity triangle: cordis.patch.yml,
9
+ * tsdown.config.ts, invariant.ts).
10
+ */
11
+ const PACKAGE_NAME = '@khorsheed/dsh-local-agent-kimi';
12
+ /**
13
+ * Required services: slot registry, command Remote, and locale registry. The
14
+ * settings scope is NOT a static inject — its service name differs per host
15
+ * line (`settingsScope` on 0.1.5, `configForms` on rc.1), so a static entry
16
+ * would pend the whole client plugin on the other line; bindSettingsScope
17
+ * probes the serving one instead (the settings client package is a declared
18
+ * client inject, so one of them is always already up).
19
+ */
20
+ export const inject = ['slots', 'remote', 'remote.commands', 'locale'];
21
+ /**
22
+ * Client plugin body: register the dictionaries and the kimi settings
23
+ * surfaces bound to the local-agent-kimi namespace.
24
+ * @param ctx - client root context.
25
+ */
26
+ export function apply(ctx) {
27
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'local-agent-kimi: dictionaries');
28
+ const scope = bindSettingsScope(ctx, 'local-agent-kimi');
29
+ // The auth block's copy lives in the family core's dictionary; binding is
30
+ // stable per namespace and late dictionary registration still resolves.
31
+ const authT = ctx.locale.bind('local-agent');
32
+ // The gateway namespace is mounted by the family core's client half; read it
33
+ // lazily from the global store so boot order between the two client plugins
34
+ // never matters, and degrade to the auth block's 'unavailable' state when
35
+ // the core client is absent.
36
+ const gateway = () => ctx.get('remote.localAgentGateway');
37
+ // Both settings surfaces inject the same face.
38
+ const cardInject = () => ({
39
+ scope,
40
+ hooks: { settings: scope },
41
+ authT,
42
+ renderModelPicker: props => ctx.get('localAgentUi')?.renderHarnessModelPicker('kimi', props),
43
+ // The broker's memberless surface (effective model + pickable
44
+ // vocabulary). Null — a core without a model broker — degrades to the
45
+ // pre-broker card: the free-text field alone, no effective-model line.
46
+ harnessModel: () => gateway()?.harnessModel('kimi').then(result => (result.ok ? result.value ?? undefined : undefined))
47
+ ?? Promise.resolve(undefined),
48
+ auth: {
49
+ status: name =>
50
+ // The Remote declares (name, scope?) and the client enforces exact arity:
51
+ // pass the default scope explicitly (undefined reads as omitted host-side).
52
+ gateway()?.status(name, undefined).then(result => (result.ok ? result.value : undefined))
53
+ ?? Promise.resolve(undefined),
54
+ runCommand: (sessionId, line) => ctx.remote.commands.execute(sessionId, line, [])
55
+ .then(result => (result.ok ? result.value?.result.text : undefined)),
56
+ },
57
+ });
58
+ // The settings surface follows the host line AND the install shape — three
59
+ // tracks, all riding slots.inject so each fires only where its declaration
60
+ // exists. Standalone install: the package's own Plugins-page detail view
61
+ // (`plugins.bundle.config`, keyed by package name). Installed as a family
62
+ // member: the member is no longer the profile's direct dependency, so only
63
+ // the bundle gets a detail view — the card rides the row-level slot
64
+ // (`plugins.row.config`, keyed `<bundle package>#<row id>` with the row id
65
+ // the bundle's patch declares) and the bundle's page gains a configure
66
+ // entry opening it. 0.1.5: the legacy configurable-plugins tab card
67
+ // (`settings.plugin.item`, keyed by the settings namespace) through a
68
+ // string-keyed duck narrow of the same service (the slot name is gone from
69
+ // the alpha.2 SlotMap).
70
+ ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
71
+ name: 'plugins.bundle.config',
72
+ key: PACKAGE_NAME,
73
+ locale: NS,
74
+ inject: cardInject,
75
+ }, KimiBundleConfig));
76
+ ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
77
+ name: 'plugins.row.config',
78
+ key: '@khorsheed/dsh-bundle-local-agent#local-agent-kimi',
79
+ locale: NS,
80
+ inject: cardInject,
81
+ }, KimiBundleConfig));
82
+ const legacy = ctx.slots;
83
+ legacy.inject('settings.plugin.item', () => legacy.register({
84
+ name: 'settings.plugin.item',
85
+ key: 'local-agent-kimi',
86
+ locale: NS,
87
+ inject: cardInject,
88
+ }, KimiSettingsCard));
89
+ }
@@ -0,0 +1,64 @@
1
+ /** `local-agent-kimi` namespace dictionaries. */
2
+ /** Dictionary namespace owned by this plugin (matches the settings namespace). */
3
+ export declare const NS = "local-agent-kimi";
4
+ /** Simplified Chinese dictionary (the key-set source of truth). */
5
+ export declare const zh: {
6
+ 'card.title': string;
7
+ 'card.description': string;
8
+ 'card.expand': string;
9
+ 'card.collapse': string;
10
+ 'auth.title': string;
11
+ 'model.title': string;
12
+ 'model.info.aria': string;
13
+ 'model.info': string;
14
+ 'model.placeholder': string;
15
+ 'model.menu': string;
16
+ 'model.menuDefault': string;
17
+ 'model.menuDefault.cliConfig': string;
18
+ 'model.menuDefault.cliBuiltin': string;
19
+ 'model.menuDefault.lastObserved': string;
20
+ 'model.save': string;
21
+ 'model.applied': string;
22
+ 'model.error': string;
23
+ 'live.title': string;
24
+ 'live.info.aria': string;
25
+ 'live.info': string;
26
+ 'live.applied': string;
27
+ 'live.error': string;
28
+ 'live.unavailable': string;
29
+ };
30
+ /** The local-agent-kimi namespace key union. */
31
+ export type LocalAgentKimiKey = keyof typeof zh;
32
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
33
+ interface LocaleNamespaceMap {
34
+ /** The kimi harness settings card copy. */
35
+ 'local-agent-kimi': LocalAgentKimiKey;
36
+ }
37
+ }
38
+ /** English dictionary, checked complete against the zh key set. */
39
+ export declare const en: {
40
+ 'card.title': string;
41
+ 'card.description': string;
42
+ 'card.expand': string;
43
+ 'card.collapse': string;
44
+ 'auth.title': string;
45
+ 'model.title': string;
46
+ 'model.info.aria': string;
47
+ 'model.info': string;
48
+ 'model.placeholder': string;
49
+ 'model.menu': string;
50
+ 'model.menuDefault': string;
51
+ 'model.menuDefault.cliConfig': string;
52
+ 'model.menuDefault.cliBuiltin': string;
53
+ 'model.menuDefault.lastObserved': string;
54
+ 'model.save': string;
55
+ 'model.applied': string;
56
+ 'model.error': string;
57
+ 'live.title': string;
58
+ 'live.info.aria': string;
59
+ 'live.info': string;
60
+ 'live.applied': string;
61
+ 'live.error': string;
62
+ 'live.unavailable': string;
63
+ };
64
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1,55 @@
1
+ /** `local-agent-kimi` namespace dictionaries. */
2
+ /** Dictionary namespace owned by this plugin (matches the settings namespace). */
3
+ export const NS = 'local-agent-kimi';
4
+ /** Simplified Chinese dictionary (the key-set source of truth). */
5
+ export const zh = {
6
+ 'card.title': 'Local Agent · Kimi',
7
+ 'card.description': 'Kimi Code 委派:登录授权与常驻模式(live)',
8
+ 'card.expand': '展开',
9
+ 'card.collapse': '收起',
10
+ 'auth.title': '认证',
11
+ 'model.title': '默认模型',
12
+ 'model.info.aria': '默认模型说明',
13
+ 'model.info': '留空 = 跟随默认(输入框里显示的就是当前跟随的模型)。从列表选择或手动输入一个模型名后保存,之后的每轮委派都以它起 CLI(一次性轮次走 `kimi -m <模型>`;常驻模式的 `kimi acp` 没有模型旗标,改为起进程前把作用域 config.toml 的 default_model 写成该值);手动输入的模型名要是作用域 config.toml 里已定义的那一个([models."…"] 的键)。成员会话里还可用作曲器按会话切换,不影响这里的默认。改动在下一轮委派生效,进行中的轮次不受影响;评测 run 的条件在建立时冻结,中途换模型会被下一轮的模型回读判为 misattributed 而拦下。',
14
+ 'model.placeholder': '留空 = 不传模型,用 CLI 自己的默认',
15
+ 'model.menu': '选择模型',
16
+ 'model.menuDefault': '默认(跟随 CLI 内置默认)',
17
+ 'model.menuDefault.cliConfig': '默认(跟随 CLI 配置:{model})',
18
+ 'model.menuDefault.cliBuiltin': '默认(跟随 CLI 默认:{model})',
19
+ 'model.menuDefault.lastObserved': '默认(跟随 CLI 内置默认(最近:{model}))',
20
+ 'model.save': '保存',
21
+ 'model.applied': '已保存,下一轮委派生效;进行中的轮次不受影响',
22
+ 'model.error': '保存失败,请重试',
23
+ 'live.title': '常驻模式(live)',
24
+ 'live.info.aria': '常驻模式说明',
25
+ 'live.info': '常驻模式 = 成员进程常驻:输出实时流入成员会话、取消不杀进程、崩溃后自动续上原会话;关闭则每轮独立进程,跑完一次性出结果。设置为全局偏好,对所有后续委派生效。',
26
+ 'live.applied': '已保存,下一轮委派生效;进行中的轮次不受影响',
27
+ 'live.error': '保存失败,请重试',
28
+ 'live.unavailable': '设置服务不可用(宿主未注册 local-agent-kimi 命名空间)',
29
+ };
30
+ /** English dictionary, checked complete against the zh key set. */
31
+ export const en = {
32
+ 'card.title': 'Local Agent · Kimi',
33
+ 'card.description': 'Kimi Code delegation: sign-in and resident (live) mode',
34
+ 'card.expand': 'Expand',
35
+ 'card.collapse': 'Collapse',
36
+ 'auth.title': 'Authentication',
37
+ 'model.title': 'Default model',
38
+ 'model.info.aria': 'About the default model',
39
+ 'model.info': "Blank = follow the default (the input shows the model it currently follows). Pick from the list or type a model name by hand and save, and every later delegation round starts the CLI with it (`kimi -m <model>` for one-shot rounds; `kimi acp` has no model flag, so resident mode writes the value into `default_model` in the scoped config.toml before spawning); a hand-typed name must be one the scoped config.toml defines (a `[models.\"…\"]` key). Inside a member session the composer can also switch the model per session, without touching this default. A change applies to the next round and never disturbs a round in flight; an evaluation run freezes its condition at setup, so switching mid-run is caught by the model read-back on the next round and fails the run as misattributed.",
40
+ 'model.placeholder': "Blank = pass no model, keep the CLI's own default",
41
+ 'model.menu': 'Pick a model',
42
+ 'model.menuDefault': "Default (follow the CLI's built-in default)",
43
+ 'model.menuDefault.cliConfig': 'Default (follow the CLI config: {model})',
44
+ 'model.menuDefault.cliBuiltin': 'Default (follow the CLI default: {model})',
45
+ 'model.menuDefault.lastObserved': "Default (follow the CLI's built-in default (last: {model}))",
46
+ 'model.save': 'Save',
47
+ 'model.applied': 'Saved — takes effect on the next delegation round; rounds in flight are unaffected',
48
+ 'model.error': 'Save failed, please retry',
49
+ 'live.title': 'Resident mode (live)',
50
+ 'live.info.aria': 'About resident mode',
51
+ 'live.info': 'Resident mode keeps the member process alive: output streams into the member session in real time, cancelling does not kill the process, and a crash resumes the same session. Off means every round runs as an independent one-shot process. The setting is global and applies to every later delegation.',
52
+ 'live.applied': 'Saved — takes effect on the next delegation round; rounds in flight are unaffected',
53
+ 'live.error': 'Save failed, please retry',
54
+ 'live.unavailable': 'Settings service unavailable (the host did not register the local-agent-kimi namespace)',
55
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Kimi credential sentinel. The kimi CLI occasionally wipes
3
+ * `credentials/kimi-code.json` into an empty shell (both tokens zero-length)
4
+ * on its own failure paths — observed twice in production, each time killing
5
+ * every later delegation with "Authentication required" until someone
6
+ * restored the file by hand. The sentinel:
7
+ *
8
+ * - backs the file up whenever a VALID credential is observed (the backup
9
+ * lives inside `credentials/` so the family's logout — a directory delete —
10
+ * clears it too);
11
+ * - restores the backup when the file is an exact empty shell (both tokens
12
+ * empty strings) — the only corruption signature we trust;
13
+ * - logs every state transition with a process snapshot, so the next wipe
14
+ * can be attributed (which process, at which moment).
15
+ *
16
+ * Restore is deliberately narrow: a revoked-elsewhere credential never takes
17
+ * the empty-shell shape, and a stale backup at worst produces one more loud
18
+ * 401, never silent misbehavior.
19
+ * @module @khorsheed/dsh-local-agent-kimi/credential-guard
20
+ */
21
+ /**
22
+ * Guard the scoped home's kimi credential: back up a valid file, restore the
23
+ * backup over an empty shell, log transitions.
24
+ * @param homeDir - the `kimi` harness's scoped home.
25
+ * @param log - warn channel (plugin logger when available).
26
+ * @returns true when a usable credential exists after the guard ran.
27
+ */
28
+ export declare function guardKimiCredential(homeDir: string, log?: (message: string) => void): Promise<boolean>;
29
+ //# sourceMappingURL=credential-guard.d.ts.map