dsh-coding 0.0.1 → 0.1.1-rc2
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/AGENTS.md +80 -0
- package/LICENSE +21 -21
- package/README.md +120 -54
- package/cordis.patch.yml +274 -4
- package/docs/CHANGELOG.md +47 -0
- package/docs/DETAIL.md +272 -0
- package/icon.svg +6 -6
- package/lib/apply-patch.js +268 -0
- package/lib/client/capsule.js +120 -0
- package/lib/client/card.js +308 -0
- package/lib/client/command-row.js +76 -0
- package/lib/client/config-page.js +392 -0
- package/lib/client/definition.js +164 -0
- package/lib/client/index.js +129 -0
- package/lib/client/locales.js +170 -0
- package/lib/client/mode-picker.js +77 -0
- package/lib/client/styles.js +283 -0
- package/lib/client.js +1802 -0
- package/lib/coding-projection.js +349 -0
- package/lib/config.js +218 -0
- package/lib/contract.js +138 -0
- package/lib/editor.js +23 -0
- package/lib/failures.js +142 -0
- package/lib/handoff.js +347 -0
- package/lib/index.js +110 -7
- package/lib/language.js +136 -0
- package/lib/memory.js +336 -0
- package/lib/messages.js +43 -0
- package/lib/models.js +154 -0
- package/lib/patch.js +235 -0
- package/lib/preset.js +1552 -0
- package/lib/reasoning-levels.js +28 -0
- package/lib/reasoning-projection.js +178 -0
- package/lib/reasoning.js +585 -0
- package/lib/stages.js +344 -0
- package/lib/state.js +585 -0
- package/lib/system-language.js +56 -0
- package/lib/types/apply-patch.d.ts +13 -0
- package/lib/types/client/capsule.d.ts +9 -0
- package/lib/types/client/card.d.ts +76 -0
- package/lib/types/client/command-row.d.ts +42 -0
- package/lib/types/client/config-page.d.ts +136 -0
- package/lib/types/client/definition.d.ts +51 -0
- package/lib/types/client/index.d.ts +10 -0
- package/lib/types/client/locales.d.ts +18 -0
- package/lib/types/client/mode-picker.d.ts +25 -0
- package/lib/types/client/styles.d.ts +28 -0
- package/lib/types/coding-projection.d.ts +116 -0
- package/lib/types/config.d.ts +208 -0
- package/lib/types/contract.d.ts +33 -0
- package/lib/types/editor.d.ts +9 -0
- package/lib/types/failures.d.ts +62 -0
- package/lib/types/handoff.d.ts +132 -0
- package/lib/types/index.d.ts +150 -0
- package/lib/types/language.d.ts +56 -0
- package/lib/types/memory.d.ts +71 -0
- package/lib/types/messages.d.ts +27 -0
- package/lib/types/models.d.ts +82 -0
- package/lib/types/patch.d.ts +37 -0
- package/lib/types/preset.d.ts +22 -0
- package/lib/types/reasoning-levels.d.ts +20 -0
- package/lib/types/reasoning-projection.d.ts +64 -0
- package/lib/types/reasoning.d.ts +141 -0
- package/lib/types/stages.d.ts +193 -0
- package/lib/types/state.d.ts +273 -0
- package/lib/types/system-language.d.ts +10 -0
- package/lib/types/verification-tool.d.ts +32 -0
- package/lib/types/verification.d.ts +77 -0
- package/lib/types/verifier.d.ts +9 -0
- package/lib/types/volatile.d.ts +17 -0
- package/lib/verification-tool.js +176 -0
- package/lib/verification.js +337 -0
- package/lib/verifier.js +25 -0
- package/lib/volatile.js +20 -0
- package/locale/en.json +3 -2
- package/locale/zh.json +3 -2
- package/package.json +84 -9
- package/lib/index.d.ts +0 -11
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Coding runtime's configuration page on the bundle's plugin page.
|
|
3
|
+
*
|
|
4
|
+
* The plugin manager renders `plugins.bundle.config` between a bundle's
|
|
5
|
+
* description and its rows, but hands a bundle page only `view` — the Host
|
|
6
|
+
* `ConfigForm` is passed to row pages, not bundle pages. A bundle page obtains
|
|
7
|
+
* the same form through `ctx.configForms.get(entryId)`, which owns the
|
|
8
|
+
* revision-fenced write queue; the page therefore never touches
|
|
9
|
+
* `ctx.remote.settings` itself and never edits the profile file.
|
|
10
|
+
*
|
|
11
|
+
* `entryId` is the Host plugin entry id of the bundle row, which is this
|
|
12
|
+
* package's name and the row id declared in `cordis.patch.yml`.
|
|
13
|
+
*
|
|
14
|
+
* Controls follow the shipped DSH recipes (label 13px, 40px field with
|
|
15
|
+
* `--dsw-radius-md`, secondary button); the classes live in `./styles.ts`.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-coding/client/config-page
|
|
18
|
+
*/
|
|
19
|
+
import { createElement as h, useCallback, useEffect, useState, useSyncExternalStore } from 'react';
|
|
20
|
+
/** Settings namespace key: the bundle row id. */
|
|
21
|
+
export const SETTINGS_NAMESPACE = 'dsh-coding';
|
|
22
|
+
/** Modes this page offers, matching the Host's `defaultMode` enum. */
|
|
23
|
+
export const MODES = ['auto', 'consult', 'review', 'codex'];
|
|
24
|
+
/** Languages this package ships. */
|
|
25
|
+
export const LANGUAGES = ['auto', 'zh', 'en'];
|
|
26
|
+
/** Reasoning policies this page offers, matching the Host's `reasoning` enum. */
|
|
27
|
+
export const REASONING_MODES = ['auto', 'low', 'high', 'max'];
|
|
28
|
+
/** `provider/model`; the Host applies the same rule at activation. */
|
|
29
|
+
const ROUTE = /^[^/\s]+\/[^/\s]+$/u;
|
|
30
|
+
/** Read one string field from a settings value. */
|
|
31
|
+
export function fieldOf(value, key, fallback = '') {
|
|
32
|
+
const raw = value?.[key];
|
|
33
|
+
return typeof raw === 'string' ? raw : fallback;
|
|
34
|
+
}
|
|
35
|
+
/** The defaults the page restores, matching `cordis.patch.yml`. */
|
|
36
|
+
export const DEFAULT_DRAFT = {
|
|
37
|
+
defaultMode: 'auto',
|
|
38
|
+
plannerWorkerModel: 'deepseek-account/deepseek-v4-pro',
|
|
39
|
+
implementWorkerModel: 'deepseek-account/deepseek-flash',
|
|
40
|
+
verifyWorkerModel: 'deepseek-account/deepseek-flash',
|
|
41
|
+
language: 'auto',
|
|
42
|
+
reasoning: 'auto',
|
|
43
|
+
};
|
|
44
|
+
/** Built-in fallbacks for providers that register an adapter but no discovery. */
|
|
45
|
+
const BUILTIN_MODELS = {
|
|
46
|
+
'deepseek-account': [
|
|
47
|
+
{ id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro' },
|
|
48
|
+
{ id: 'deepseek-flash', name: 'DeepSeek Flash' },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
/** Draft built from the accepted Host value. */
|
|
52
|
+
export function draftOf(value) {
|
|
53
|
+
return {
|
|
54
|
+
defaultMode: fieldOf(value, 'defaultMode', 'auto'),
|
|
55
|
+
implementWorkerModel: fieldOf(value, 'implementWorkerModel'),
|
|
56
|
+
plannerWorkerModel: fieldOf(value, 'plannerWorkerModel'),
|
|
57
|
+
verifyWorkerModel: fieldOf(value, 'verifyWorkerModel'),
|
|
58
|
+
language: fieldOf(value, 'language', 'auto'),
|
|
59
|
+
reasoning: fieldOf(value, 'reasoning', 'auto'),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Whether every worker route names a `provider/model` pair. */
|
|
63
|
+
export function draftIsValid(draft) {
|
|
64
|
+
return ROUTE.test(draft.implementWorkerModel.trim())
|
|
65
|
+
&& ROUTE.test(draft.plannerWorkerModel.trim())
|
|
66
|
+
&& ROUTE.test(draft.verifyWorkerModel.trim());
|
|
67
|
+
}
|
|
68
|
+
/** The message of a thrown value, for the catalog error notice. */
|
|
69
|
+
function messageOf(error) {
|
|
70
|
+
if (error instanceof Error)
|
|
71
|
+
return error.message;
|
|
72
|
+
return typeof error === 'string' ? error : 'Unknown error.';
|
|
73
|
+
}
|
|
74
|
+
/** Read one `ok`/`value` envelope, throwing its message when it carries no list. */
|
|
75
|
+
function resultList(result, fallback) {
|
|
76
|
+
if (result.ok !== true || !Array.isArray(result.value)) {
|
|
77
|
+
throw new Error(result.error?.message || fallback);
|
|
78
|
+
}
|
|
79
|
+
return result.value;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Load every `provider/model` the Host has configured.
|
|
83
|
+
*
|
|
84
|
+
* The catalog is the union of the providers the registry knows and the ones
|
|
85
|
+
* the settings service can describe, each asked for its own models. A provider
|
|
86
|
+
* that fails discovery keeps its error and falls back to its built-in models
|
|
87
|
+
* when it has them, so one broken provider never hides the rest; only an empty
|
|
88
|
+
* catalog is an error.
|
|
89
|
+
* @param remote - the Host LLM Remote, absent on an older Host.
|
|
90
|
+
* @returns the sorted options, one per advertised model.
|
|
91
|
+
*/
|
|
92
|
+
export async function loadModelOptions(remote) {
|
|
93
|
+
// Keep the receiver: the Host's Remote methods may read `this`, and they are
|
|
94
|
+
// also called from inside a `map` callback where narrowing would end.
|
|
95
|
+
const listProviders = remote?.listProviders?.bind(remote);
|
|
96
|
+
const listConfigurableProviders = remote?.listConfigurableProviders?.bind(remote);
|
|
97
|
+
const discoverModels = remote?.discoverModels?.bind(remote);
|
|
98
|
+
if (listProviders === undefined || listConfigurableProviders === undefined || discoverModels === undefined) {
|
|
99
|
+
throw new Error('The Host does not expose the LLM model Remote.');
|
|
100
|
+
}
|
|
101
|
+
const [registered, configurable] = await Promise.all([listProviders(), listConfigurableProviders()]);
|
|
102
|
+
const providers = resultList(registered, 'Could not read the configured providers.');
|
|
103
|
+
const entries = resultList(configurable, 'Could not read the configured providers.');
|
|
104
|
+
const known = new Set(providers.map(provider => provider.id));
|
|
105
|
+
const usable = entries.filter(entry => known.has(entry.provider)
|
|
106
|
+
&& typeof entry.settingsNs === 'string'
|
|
107
|
+
&& entry.settingsNs.trim() !== '');
|
|
108
|
+
const errors = [];
|
|
109
|
+
const discovered = await Promise.all(usable.map(async (entry) => {
|
|
110
|
+
try {
|
|
111
|
+
const result = await discoverModels(entry.settingsNs, { provider: entry.provider });
|
|
112
|
+
if (result.ok !== true || !Array.isArray(result.value)) {
|
|
113
|
+
errors.push(result.error?.message || `Could not read the models of ${entry.provider}.`);
|
|
114
|
+
return { entry, models: [] };
|
|
115
|
+
}
|
|
116
|
+
return { entry, models: result.value };
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
errors.push(messageOf(error));
|
|
120
|
+
return { entry, models: [] };
|
|
121
|
+
}
|
|
122
|
+
}));
|
|
123
|
+
const byValue = new Map();
|
|
124
|
+
for (const item of discovered) {
|
|
125
|
+
const models = item.models.length > 0
|
|
126
|
+
? item.models
|
|
127
|
+
: BUILTIN_MODELS[item.entry.provider] ?? [];
|
|
128
|
+
for (const model of models) {
|
|
129
|
+
if (typeof model?.id !== 'string' || model.id.trim() === '')
|
|
130
|
+
continue;
|
|
131
|
+
const value = `${item.entry.provider}/${model.id}`;
|
|
132
|
+
if (byValue.has(value))
|
|
133
|
+
continue;
|
|
134
|
+
byValue.set(value, {
|
|
135
|
+
value,
|
|
136
|
+
provider: item.entry.provider,
|
|
137
|
+
model: model.id,
|
|
138
|
+
label: `${item.entry.displayName || item.entry.provider} · ${model.name?.trim() || model.id}`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const options = [...byValue.values()];
|
|
143
|
+
options.sort((left, right) => (left.provider === right.provider
|
|
144
|
+
? left.label.localeCompare(right.label)
|
|
145
|
+
: left.provider.localeCompare(right.provider)));
|
|
146
|
+
if (options.length === 0) {
|
|
147
|
+
throw new Error(errors[0] || 'No configured provider advertised a model.');
|
|
148
|
+
}
|
|
149
|
+
return options;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Add the stored routes the catalog no longer advertises, marked `missing`, so
|
|
153
|
+
* a select can still show what the settings hold instead of silently dropping it.
|
|
154
|
+
* @param options - the loaded catalog.
|
|
155
|
+
* @param current - the routes the draft currently holds.
|
|
156
|
+
* @returns the options plus one entry per unknown stored route.
|
|
157
|
+
*/
|
|
158
|
+
export function mergeCurrentModels(options, current) {
|
|
159
|
+
const merged = [...options];
|
|
160
|
+
const values = new Set(options.map(option => option.value));
|
|
161
|
+
for (const route of current) {
|
|
162
|
+
const value = route.trim();
|
|
163
|
+
if (value === '' || values.has(value))
|
|
164
|
+
continue;
|
|
165
|
+
values.add(value);
|
|
166
|
+
const [provider = '', ...rest] = value.split('/');
|
|
167
|
+
merged.push({ value, provider, model: rest.join('/'), label: value, missing: true });
|
|
168
|
+
}
|
|
169
|
+
return merged;
|
|
170
|
+
}
|
|
171
|
+
/** Whether every worker route is non-empty and present in the catalog. */
|
|
172
|
+
export function draftModelsValid(draft, options) {
|
|
173
|
+
const values = new Set(options.map(option => option.value));
|
|
174
|
+
return [draft.plannerWorkerModel, draft.implementWorkerModel, draft.verifyWorkerModel]
|
|
175
|
+
.every(route => {
|
|
176
|
+
const value = route.trim();
|
|
177
|
+
return value !== '' && values.has(value);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The namespace mutation one save submits, revision fence owned by the caller.
|
|
182
|
+
* A field the served schema does not advertise is left out: an older Host
|
|
183
|
+
* would reject the whole mutation for an unknown property.
|
|
184
|
+
* That guard also covers `reasoning`: a Host that does not declare it gets no
|
|
185
|
+
* reasoning op, so the mutation is never rejected as a whole.
|
|
186
|
+
* @param draft - edited values.
|
|
187
|
+
* @param served - the accepted Host value the form was built from.
|
|
188
|
+
* @returns the ordered operations.
|
|
189
|
+
*/
|
|
190
|
+
export function buildConfigOps(draft, served = { language: draft.language, reasoning: draft.reasoning }) {
|
|
191
|
+
const ops = [
|
|
192
|
+
{ op: 'set', path: ['defaultMode'], value: draft.defaultMode },
|
|
193
|
+
{ op: 'set', path: ['implementWorkerModel'], value: draft.implementWorkerModel.trim() },
|
|
194
|
+
{ op: 'set', path: ['plannerWorkerModel'], value: draft.plannerWorkerModel.trim() },
|
|
195
|
+
{ op: 'set', path: ['verifyWorkerModel'], value: draft.verifyWorkerModel.trim() },
|
|
196
|
+
];
|
|
197
|
+
if ('language' in served)
|
|
198
|
+
ops.push({ op: 'set', path: ['language'], value: draft.language });
|
|
199
|
+
if ('reasoning' in served)
|
|
200
|
+
ops.push({ op: 'set', path: ['reasoning'], value: draft.reasoning });
|
|
201
|
+
return ops;
|
|
202
|
+
}
|
|
203
|
+
/** Rendered command overrides, one `key = command` line each. */
|
|
204
|
+
function commandLines(value) {
|
|
205
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
206
|
+
return [];
|
|
207
|
+
return Object.entries(value)
|
|
208
|
+
.filter((entry) => typeof entry[1] === 'string')
|
|
209
|
+
.map(([key, command]) => `${key} = ${command}`);
|
|
210
|
+
}
|
|
211
|
+
/** One text field row. */
|
|
212
|
+
function field(id, label, hint, input) {
|
|
213
|
+
return h('div', { className: 'dsh-coding-field' }, h('label', { htmlFor: id }, label), input, h('span', { className: 'dsh-coding-hint' }, hint));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* One worker-model field: a select over the configured catalog. A value the
|
|
217
|
+
* catalog does not hold keeps its own `missing` entry, so the control shows it
|
|
218
|
+
* and marks the field invalid instead of quietly picking a neighbour.
|
|
219
|
+
*/
|
|
220
|
+
function modelField(id, label, hint, value, options, invalid, readOnly, onChange, t) {
|
|
221
|
+
return field(id, label, hint, h('select', {
|
|
222
|
+
id,
|
|
223
|
+
className: 'dsh-coding-input' + (invalid ? ' dsh-coding-input-warn' : ''),
|
|
224
|
+
value,
|
|
225
|
+
disabled: readOnly,
|
|
226
|
+
'aria-invalid': invalid,
|
|
227
|
+
onChange: (event) => { onChange(event.target.value); },
|
|
228
|
+
}, h('option', { key: '', value: '', disabled: true }, t('config.modelPlaceholder')), ...options.map(option => h('option', { key: option.value, value: option.value }, option.missing ? `${option.label} — ${t('config.modelMissing')}` : option.label))));
|
|
229
|
+
}
|
|
230
|
+
/** The bundle configuration page. */
|
|
231
|
+
export function CodingConfigPage(props) {
|
|
232
|
+
const { form, t } = props;
|
|
233
|
+
if (props.view === 'summary')
|
|
234
|
+
return h('span', null, t('config.title'));
|
|
235
|
+
// The form's methods are class methods: pass bound wrappers, or React calls
|
|
236
|
+
// them with an undefined receiver and the controller's store lookup fails.
|
|
237
|
+
const subscribe = useCallback((listener) => form.subscribe(listener), [form]);
|
|
238
|
+
const getSnapshot = useCallback(() => form.getSnapshot(), [form]);
|
|
239
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot);
|
|
240
|
+
const [draft, setDraft] = useState(() => draftOf(snapshot.value));
|
|
241
|
+
const [status, setStatus] = useState('idle');
|
|
242
|
+
const [catalog, setCatalog] = useState({ status: 'loading' });
|
|
243
|
+
const [catalogRevision, setCatalogRevision] = useState(0);
|
|
244
|
+
// Adopt every accepted Host value: a save, or another page's write, replaces
|
|
245
|
+
// the draft instead of silently diverging from what the Host now holds.
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
setDraft(draftOf(snapshot.value));
|
|
248
|
+
}, [snapshot.value]);
|
|
249
|
+
// The selectable routes come from the Host's configured model catalog. A
|
|
250
|
+
// failure disables Save rather than letting an unverified route through.
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
let cancelled = false;
|
|
253
|
+
setCatalog({ status: 'loading' });
|
|
254
|
+
loadModelOptions(props.remote)
|
|
255
|
+
.then(options => { if (!cancelled)
|
|
256
|
+
setCatalog({ status: 'ready', options }); })
|
|
257
|
+
.catch(error => { if (!cancelled)
|
|
258
|
+
setCatalog({ status: 'error', message: messageOf(error) }); });
|
|
259
|
+
return () => { cancelled = true; };
|
|
260
|
+
}, [props.remote, catalogRevision]);
|
|
261
|
+
if (snapshot.status === 'loading') {
|
|
262
|
+
return h('p', { className: 'dsh-coding-hint' }, t('config.loading'));
|
|
263
|
+
}
|
|
264
|
+
if (snapshot.status === 'unavailable') {
|
|
265
|
+
return h('p', { className: 'dsh-coding-hint' }, t('config.unavailable'));
|
|
266
|
+
}
|
|
267
|
+
const value = snapshot.value ?? {};
|
|
268
|
+
const routesValid = draftIsValid(draft);
|
|
269
|
+
const options = catalog.status === 'ready' ? catalog.options : [];
|
|
270
|
+
const modelOptions = mergeCurrentModels(options, [
|
|
271
|
+
draft.plannerWorkerModel,
|
|
272
|
+
draft.implementWorkerModel,
|
|
273
|
+
draft.verifyWorkerModel,
|
|
274
|
+
]);
|
|
275
|
+
const modelsValid = catalog.status === 'ready' && draftModelsValid(draft, options);
|
|
276
|
+
const routeKnown = (route) => options.some(option => option.value === route.trim());
|
|
277
|
+
const dirty = draft.defaultMode !== fieldOf(value, 'defaultMode', 'auto')
|
|
278
|
+
|| draft.implementWorkerModel !== fieldOf(value, 'implementWorkerModel')
|
|
279
|
+
|| draft.plannerWorkerModel !== fieldOf(value, 'plannerWorkerModel')
|
|
280
|
+
|| draft.verifyWorkerModel !== fieldOf(value, 'verifyWorkerModel')
|
|
281
|
+
|| draft.language !== fieldOf(value, 'language', 'auto')
|
|
282
|
+
|| draft.reasoning !== fieldOf(value, 'reasoning', 'auto');
|
|
283
|
+
const commands = commandLines(value['verificationCommands']);
|
|
284
|
+
const readOnly = snapshot.writable !== true;
|
|
285
|
+
const modelNotice = catalog.status === 'ready'
|
|
286
|
+
? {
|
|
287
|
+
text: t('config.modelWarning'),
|
|
288
|
+
className: modelsValid ? 'dsh-coding-hint dsh-coding-notice' : 'dsh-coding-warn dsh-coding-notice',
|
|
289
|
+
}
|
|
290
|
+
: catalog.status === 'error'
|
|
291
|
+
? {
|
|
292
|
+
text: `${t('config.modelsUnavailable')} ${catalog.message}`,
|
|
293
|
+
className: 'dsh-coding-warn dsh-coding-notice',
|
|
294
|
+
}
|
|
295
|
+
: { text: t('config.modelsLoading'), className: 'dsh-coding-hint dsh-coding-notice' };
|
|
296
|
+
async function save() {
|
|
297
|
+
if (status === 'saving' || !routesValid || !modelsValid || readOnly)
|
|
298
|
+
return;
|
|
299
|
+
setStatus('saving');
|
|
300
|
+
try {
|
|
301
|
+
const accepted = await form.mutate(buildConfigOps(draft, value), snapshot.revision);
|
|
302
|
+
setStatus(accepted ? 'saved' : 'error');
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
setStatus('error');
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/** Put the shipped defaults back into the draft; saving stays explicit. */
|
|
309
|
+
function resetDefaults() {
|
|
310
|
+
setDraft(DEFAULT_DRAFT);
|
|
311
|
+
setStatus('idle');
|
|
312
|
+
}
|
|
313
|
+
const statusText = status === 'saving'
|
|
314
|
+
? t('config.saving')
|
|
315
|
+
: status === 'saved'
|
|
316
|
+
? t('config.saved')
|
|
317
|
+
: status === 'error'
|
|
318
|
+
? t('config.saveFailed')
|
|
319
|
+
: routesValid ? '' : t('config.invalidRoute');
|
|
320
|
+
const statusClass = status === 'error'
|
|
321
|
+
? 'dsh-coding-error'
|
|
322
|
+
: status === 'saved' ? 'dsh-coding-success' : 'dsh-coding-hint';
|
|
323
|
+
return h('div', { className: 'dsh-coding-form', 'data-dsh-coding-config': 'true' }, h('p', { className: 'dsh-coding-warn dsh-coding-notice' }, t('config.presetWarning')), field('dsh-coding-mode', t('config.mode'), t('config.modeHint'), h('select', {
|
|
324
|
+
id: 'dsh-coding-mode',
|
|
325
|
+
className: 'dsh-coding-input',
|
|
326
|
+
value: draft.defaultMode,
|
|
327
|
+
disabled: readOnly,
|
|
328
|
+
onChange: (event) => {
|
|
329
|
+
setDraft(current => ({ ...current, defaultMode: event.target.value }));
|
|
330
|
+
setStatus('idle');
|
|
331
|
+
},
|
|
332
|
+
}, ...MODES.map(option => h('option', { key: option, value: option }, t(`mode.${option}`))))), 'language' in value
|
|
333
|
+
? field('dsh-coding-language', t('config.language'), t('config.languageHint'), h('select', {
|
|
334
|
+
id: 'dsh-coding-language',
|
|
335
|
+
className: 'dsh-coding-input',
|
|
336
|
+
value: draft.language,
|
|
337
|
+
disabled: readOnly,
|
|
338
|
+
onChange: (event) => {
|
|
339
|
+
setDraft(current => ({ ...current, language: event.target.value }));
|
|
340
|
+
setStatus('idle');
|
|
341
|
+
},
|
|
342
|
+
}, ...LANGUAGES.map((option) => {
|
|
343
|
+
const label = option === 'auto'
|
|
344
|
+
? t('config.languageAuto')
|
|
345
|
+
: option === 'zh' ? '中文' : 'English';
|
|
346
|
+
return h('option', { key: option, value: option }, label);
|
|
347
|
+
})))
|
|
348
|
+
: null, 'reasoning' in value
|
|
349
|
+
? field('dsh-coding-reasoning', t('config.reasoning'), t('config.reasoningHint'), h('select', {
|
|
350
|
+
id: 'dsh-coding-reasoning',
|
|
351
|
+
className: 'dsh-coding-input',
|
|
352
|
+
value: draft.reasoning,
|
|
353
|
+
disabled: readOnly,
|
|
354
|
+
onChange: (event) => {
|
|
355
|
+
setDraft(current => ({ ...current, reasoning: event.target.value }));
|
|
356
|
+
setStatus('idle');
|
|
357
|
+
},
|
|
358
|
+
}, ...REASONING_MODES.map((option) => {
|
|
359
|
+
const label = option === 'auto'
|
|
360
|
+
? t('config.reasoningAuto')
|
|
361
|
+
: option === 'low' ? 'Low' : option === 'high' ? 'High' : 'Max';
|
|
362
|
+
return h('option', { key: option, value: option }, label);
|
|
363
|
+
})))
|
|
364
|
+
: null, h('div', { className: 'dsh-coding-notice-row' }, h('p', { className: modelNotice.className }, modelNotice.text), catalog.status === 'error'
|
|
365
|
+
? h('button', {
|
|
366
|
+
type: 'button',
|
|
367
|
+
className: 'dsh-coding-button',
|
|
368
|
+
onClick: () => { setCatalogRevision(current => current + 1); },
|
|
369
|
+
}, t('config.modelsRetry'))
|
|
370
|
+
: null), modelField('dsh-coding-planner', t('config.plannerModel'), t('config.plannerModelHint'), draft.plannerWorkerModel, modelOptions, catalog.status === 'ready' && !routeKnown(draft.plannerWorkerModel), readOnly, (next) => {
|
|
371
|
+
setDraft(current => ({ ...current, plannerWorkerModel: next }));
|
|
372
|
+
setStatus('idle');
|
|
373
|
+
}, t), modelField('dsh-coding-implement', t('config.implementModel'), t('config.implementModelHint'), draft.implementWorkerModel, modelOptions, catalog.status === 'ready' && !routeKnown(draft.implementWorkerModel), readOnly, (next) => {
|
|
374
|
+
setDraft(current => ({ ...current, implementWorkerModel: next }));
|
|
375
|
+
setStatus('idle');
|
|
376
|
+
}, t), modelField('dsh-coding-verify', t('config.verifyModel'), t('config.verifyModelHint'), draft.verifyWorkerModel, modelOptions, catalog.status === 'ready' && !routeKnown(draft.verifyWorkerModel), readOnly, (next) => {
|
|
377
|
+
setDraft(current => ({ ...current, verifyWorkerModel: next }));
|
|
378
|
+
setStatus('idle');
|
|
379
|
+
}, t), h('div', { className: 'dsh-coding-field' }, h('label', null, t('config.commands')), h('span', { className: 'dsh-coding-mono' }, commands.length === 0
|
|
380
|
+
? t('config.verification')
|
|
381
|
+
: commands.join('\n')), h('span', { className: 'dsh-coding-hint' }, t('config.commandsHint'))), h('div', { className: 'dsh-coding-footer' }, h('button', {
|
|
382
|
+
type: 'button',
|
|
383
|
+
className: 'dsh-coding-button dsh-coding-button-lg',
|
|
384
|
+
disabled: readOnly || status === 'saving' || !routesValid || !modelsValid || !dirty,
|
|
385
|
+
onClick: () => { void save(); },
|
|
386
|
+
}, status === 'saving' ? t('config.saving') : t('config.save')), h('button', {
|
|
387
|
+
type: 'button',
|
|
388
|
+
className: 'dsh-coding-button',
|
|
389
|
+
disabled: readOnly || status === 'saving',
|
|
390
|
+
onClick: () => { resetDefaults(); },
|
|
391
|
+
}, t('config.reset')), statusText === '' ? null : h('span', { className: statusClass }, statusText), readOnly ? h('span', { className: 'dsh-coding-hint' }, t('config.readOnly')) : null));
|
|
392
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { asCheckpoint, isCodingTool, } from '../stages.js';
|
|
2
|
+
/** Definition kind; also the renderer key in `conversation.chat.node`. */
|
|
3
|
+
export const CAPSULE_KIND = 'coding-stage';
|
|
4
|
+
/** Chat target this Definition publishes to. */
|
|
5
|
+
export const CAPSULE_TARGET = 'chat';
|
|
6
|
+
/** Context identity: one capsule per Turn. */
|
|
7
|
+
function contextId(turn) {
|
|
8
|
+
return `coding-turn-${turn}`;
|
|
9
|
+
}
|
|
10
|
+
/** Extract a durable checkpoint from a `tool/result` event. */
|
|
11
|
+
function checkpointOf(event) {
|
|
12
|
+
if (event.type !== 'tool/result')
|
|
13
|
+
return undefined;
|
|
14
|
+
const meta = event.data.meta;
|
|
15
|
+
const checkpoint = asCheckpoint(meta);
|
|
16
|
+
if (checkpoint === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
// The turn in `meta` must agree with the event's own coordinates: a
|
|
19
|
+
// checkpoint from a different turn would place the capsule on the wrong row.
|
|
20
|
+
const turn = event.data.turn;
|
|
21
|
+
if (typeof turn === 'number' && checkpoint.turn !== turn)
|
|
22
|
+
return undefined;
|
|
23
|
+
return checkpoint;
|
|
24
|
+
}
|
|
25
|
+
/** Extract the requested stage or mode from one Coding tool call's arguments. */
|
|
26
|
+
function requestedOf(event) {
|
|
27
|
+
if (event.type !== 'tool/call')
|
|
28
|
+
return undefined;
|
|
29
|
+
const data = event.data;
|
|
30
|
+
if (typeof data.name !== 'string' || !isCodingTool(data.name))
|
|
31
|
+
return undefined;
|
|
32
|
+
if (typeof data.turn !== 'number')
|
|
33
|
+
return undefined;
|
|
34
|
+
let requested;
|
|
35
|
+
if (typeof data.arguments === 'string') {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(data.arguments);
|
|
38
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
39
|
+
if (typeof parsed['stage'] === 'string')
|
|
40
|
+
requested = parsed['stage'];
|
|
41
|
+
else if (typeof parsed['mode'] === 'string')
|
|
42
|
+
requested = parsed['mode'];
|
|
43
|
+
else if (typeof parsed['kind'] === 'string')
|
|
44
|
+
requested = parsed['kind'];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Unparseable arguments still identify the call by tool name.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { tool: data.name, ...requested === undefined ? {} : { requested }, turn: data.turn };
|
|
52
|
+
}
|
|
53
|
+
/** The turn a `turn/end` event closes. */
|
|
54
|
+
function endedTurn(event) {
|
|
55
|
+
if (event.type !== 'turn/end')
|
|
56
|
+
return undefined;
|
|
57
|
+
const turn = event.data.turn;
|
|
58
|
+
return typeof turn === 'number' ? turn : undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Data built from one complete checkpoint. */
|
|
61
|
+
function fromCheckpoint(checkpoint, inherited) {
|
|
62
|
+
return {
|
|
63
|
+
runId: checkpoint.runId,
|
|
64
|
+
turn: checkpoint.turn,
|
|
65
|
+
mode: checkpoint.mode,
|
|
66
|
+
stage: checkpoint.stage,
|
|
67
|
+
checkpoint,
|
|
68
|
+
...inherited === undefined ? {} : { inherited },
|
|
69
|
+
partial: false,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Data built from a call whose result is still outstanding. */
|
|
73
|
+
function fromCall(call, at, previous) {
|
|
74
|
+
return {
|
|
75
|
+
runId: previous?.runId ?? '',
|
|
76
|
+
turn: call.turn,
|
|
77
|
+
mode: previous?.mode ?? 'auto',
|
|
78
|
+
stage: previous?.stage ?? 'requirements',
|
|
79
|
+
...previous === undefined ? {} : { inherited: previous },
|
|
80
|
+
pending: { tool: call.tool, ...call.requested === undefined ? {} : { requested: call.requested }, at },
|
|
81
|
+
partial: true,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Turn-end data: keep what this Context knows, otherwise inherit the last checkpoint. */
|
|
85
|
+
function fromTurnEnd(turn, previous, current) {
|
|
86
|
+
if (current !== undefined) {
|
|
87
|
+
// The turn is over: a call whose result never arrived is no longer pending.
|
|
88
|
+
const { pending: _pending, ...rest } = current;
|
|
89
|
+
return { ...rest, partial: current.checkpoint === undefined && previous === undefined };
|
|
90
|
+
}
|
|
91
|
+
if (previous !== undefined) {
|
|
92
|
+
return {
|
|
93
|
+
...fromCheckpoint(previous, previous),
|
|
94
|
+
turn,
|
|
95
|
+
partial: false,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return { runId: '', turn, mode: 'auto', stage: 'requirements', partial: true };
|
|
99
|
+
}
|
|
100
|
+
/** Event router: the durable Coding events this plugin produces. */
|
|
101
|
+
const match = (event) => {
|
|
102
|
+
const checkpoint = checkpointOf(event);
|
|
103
|
+
if (checkpoint !== undefined)
|
|
104
|
+
return { id: contextId(checkpoint.turn), role: 'start' };
|
|
105
|
+
const call = requestedOf(event);
|
|
106
|
+
if (call !== undefined)
|
|
107
|
+
return { id: contextId(call.turn), role: 'start' };
|
|
108
|
+
const turn = endedTurn(event);
|
|
109
|
+
if (turn !== undefined)
|
|
110
|
+
return { id: contextId(turn), role: 'start' };
|
|
111
|
+
return null;
|
|
112
|
+
};
|
|
113
|
+
/** The Coding capsule Definition. */
|
|
114
|
+
export const capsuleDefinition = {
|
|
115
|
+
kind: CAPSULE_KIND,
|
|
116
|
+
target: CAPSULE_TARGET,
|
|
117
|
+
match,
|
|
118
|
+
start(context, matchResult, reader) {
|
|
119
|
+
const event = matchResult.event;
|
|
120
|
+
const checkpoint = checkpointOf(event);
|
|
121
|
+
if (checkpoint !== undefined)
|
|
122
|
+
return fromCheckpoint(checkpoint);
|
|
123
|
+
const call = requestedOf(event);
|
|
124
|
+
if (call !== undefined) {
|
|
125
|
+
const previous = reader.previous(CAPSULE_KIND)?.state.checkpoint;
|
|
126
|
+
return fromCall(call, event.time, previous);
|
|
127
|
+
}
|
|
128
|
+
const turn = endedTurn(event);
|
|
129
|
+
const previous = reader.previous(CAPSULE_KIND)?.state.checkpoint;
|
|
130
|
+
return fromTurnEnd(turn ?? 0, previous);
|
|
131
|
+
},
|
|
132
|
+
update(context, updateMatch) {
|
|
133
|
+
const event = updateMatch.event;
|
|
134
|
+
const current = context.state;
|
|
135
|
+
const checkpoint = checkpointOf(event);
|
|
136
|
+
if (checkpoint !== undefined)
|
|
137
|
+
return fromCheckpoint(checkpoint, current.inherited);
|
|
138
|
+
const call = requestedOf(event);
|
|
139
|
+
if (call !== undefined) {
|
|
140
|
+
return { ...current, ...fromCall(call, event.time, current.checkpoint ?? current.inherited) };
|
|
141
|
+
}
|
|
142
|
+
const turn = endedTurn(event);
|
|
143
|
+
if (turn !== undefined) {
|
|
144
|
+
return fromTurnEnd(turn, current.checkpoint ?? current.inherited, current);
|
|
145
|
+
}
|
|
146
|
+
return current;
|
|
147
|
+
},
|
|
148
|
+
buildViewNode(context) {
|
|
149
|
+
const data = context.state;
|
|
150
|
+
const startMatch = context.start;
|
|
151
|
+
if (data === undefined || startMatch === undefined)
|
|
152
|
+
return null;
|
|
153
|
+
return {
|
|
154
|
+
key: context.key,
|
|
155
|
+
kind: CAPSULE_KIND,
|
|
156
|
+
id: context.id,
|
|
157
|
+
target: CAPSULE_TARGET,
|
|
158
|
+
anchorSeq: startMatch.event.seq,
|
|
159
|
+
location: startMatch.location,
|
|
160
|
+
visibility: 'visible',
|
|
161
|
+
data,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
};
|