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,349 @@
|
|
|
1
|
+
import { STAGES_BY_MODE, asCheckpoint, asStage, entryStage, isCodingTool, stageInMode, } from './stages.js';
|
|
2
|
+
/** Projection key shared by the Host fold and every client reader. */
|
|
3
|
+
export const CODING_PROJECTION_KEY = 'dshCodingStage';
|
|
4
|
+
/** Preset id this bundle declares in `cordis.patch.yml`. */
|
|
5
|
+
export const CODING_PRESET_ID = 'dsh-coding';
|
|
6
|
+
/** How many closed turns one projection keeps; older cards fall back to live state. */
|
|
7
|
+
const MAX_TURNS = 60;
|
|
8
|
+
/** Whether a session header names this bundle's user-facing preset. */
|
|
9
|
+
export function isCodingSession(header) {
|
|
10
|
+
return header?.agentPreset === CODING_PRESET_ID
|
|
11
|
+
&& (typeof header.delegationDepth === 'number' ? header.delegationDepth : 0) === 0;
|
|
12
|
+
}
|
|
13
|
+
/** Projection value before any event is folded. */
|
|
14
|
+
export function initialView(defaultMode) {
|
|
15
|
+
return {
|
|
16
|
+
active: false,
|
|
17
|
+
mode: defaultMode,
|
|
18
|
+
stage: entryStage(defaultMode),
|
|
19
|
+
allowedStages: STAGES_BY_MODE[defaultMode],
|
|
20
|
+
planItems: 0,
|
|
21
|
+
openPlanItems: 0,
|
|
22
|
+
edits: 0,
|
|
23
|
+
verification: null,
|
|
24
|
+
checkpoint: null,
|
|
25
|
+
plan: [],
|
|
26
|
+
pending: null,
|
|
27
|
+
latest: 0,
|
|
28
|
+
turns: [],
|
|
29
|
+
updatedAt: 0,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Reduced verification evidence, or null. */
|
|
33
|
+
function verificationOf(value) {
|
|
34
|
+
if (typeof value !== 'object' || value === null)
|
|
35
|
+
return null;
|
|
36
|
+
const v = value;
|
|
37
|
+
if (typeof v['passed'] !== 'boolean')
|
|
38
|
+
return null;
|
|
39
|
+
return {
|
|
40
|
+
passed: v['passed'],
|
|
41
|
+
kind: typeof v['kind'] === 'string' ? v['kind'] : '',
|
|
42
|
+
scope: typeof v['scope'] === 'string' ? v['scope'] : '',
|
|
43
|
+
command: typeof v['command'] === 'string' ? v['command'] : '',
|
|
44
|
+
failedTests: Array.isArray(v['failedTests'])
|
|
45
|
+
? v['failedTests'].filter((item) => typeof item === 'string')
|
|
46
|
+
: [],
|
|
47
|
+
ranAt: typeof v['ranAt'] === 'number' ? v['ranAt'] : 0,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The stage or mode a Coding tool call is asking for, for the pending label. */
|
|
51
|
+
function requestedOf(tool, raw) {
|
|
52
|
+
if (typeof raw !== 'string')
|
|
53
|
+
return null;
|
|
54
|
+
let parsed;
|
|
55
|
+
try {
|
|
56
|
+
const value = JSON.parse(raw);
|
|
57
|
+
if (typeof value !== 'object' || value === null)
|
|
58
|
+
return null;
|
|
59
|
+
parsed = value;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
for (const key of ['stage', 'mode', 'kind']) {
|
|
65
|
+
const candidate = parsed[key];
|
|
66
|
+
if (typeof candidate === 'string' && candidate !== '')
|
|
67
|
+
return candidate;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
/** A mode value, when the checkpoint or command args name one. */
|
|
72
|
+
function modeOf(value) {
|
|
73
|
+
return value === 'auto' || value === 'consult' || value === 'review' || value === 'codex' ? value : undefined;
|
|
74
|
+
}
|
|
75
|
+
/** A stage value, when the command args name one. */
|
|
76
|
+
function stageOf(value) {
|
|
77
|
+
return asStage(value);
|
|
78
|
+
}
|
|
79
|
+
/** One task-list status value, or undefined when the event did not record one. */
|
|
80
|
+
function planStatusOf(item) {
|
|
81
|
+
const status = item.status;
|
|
82
|
+
return status === 'pending' || status === 'in_progress' || status === 'completed' ? status : undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Fold one committed Session event into the projection.
|
|
86
|
+
* @param state - value covering every earlier event.
|
|
87
|
+
* @param event - next committed event.
|
|
88
|
+
* @param defaultMode - configured mode, used when a session switches preset mid-flight.
|
|
89
|
+
* @returns the next value; the same reference when the event is unrelated.
|
|
90
|
+
*/
|
|
91
|
+
export function applyEvent(state, event, defaultMode) {
|
|
92
|
+
const data = event.data;
|
|
93
|
+
switch (event.type) {
|
|
94
|
+
case 'agent-preset/selected': {
|
|
95
|
+
if (typeof data?.agentPreset !== 'string')
|
|
96
|
+
return state;
|
|
97
|
+
const active = data.agentPreset === CODING_PRESET_ID;
|
|
98
|
+
if (active === state.active)
|
|
99
|
+
return state;
|
|
100
|
+
if (!active)
|
|
101
|
+
return { ...state, active: false };
|
|
102
|
+
// Joining the preset mid-session: reset to the configured entry state.
|
|
103
|
+
return {
|
|
104
|
+
...state,
|
|
105
|
+
active: true,
|
|
106
|
+
mode: defaultMode,
|
|
107
|
+
stage: entryStage(defaultMode),
|
|
108
|
+
allowedStages: STAGES_BY_MODE[defaultMode],
|
|
109
|
+
checkpoint: null,
|
|
110
|
+
plan: [],
|
|
111
|
+
planItems: 0,
|
|
112
|
+
openPlanItems: 0,
|
|
113
|
+
edits: 0,
|
|
114
|
+
verification: null,
|
|
115
|
+
pending: null,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
case 'tool/call': {
|
|
119
|
+
const name = data?.name;
|
|
120
|
+
if (typeof name !== 'string' || !isCodingTool(name))
|
|
121
|
+
return state;
|
|
122
|
+
return {
|
|
123
|
+
...state,
|
|
124
|
+
pending: {
|
|
125
|
+
tool: name,
|
|
126
|
+
requested: requestedOf(name, data?.arguments),
|
|
127
|
+
callId: typeof data?.callId === 'string' ? data.callId : null,
|
|
128
|
+
},
|
|
129
|
+
updatedAt: typeof event.time === 'number' ? event.time : state.updatedAt,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
case 'tool/result': {
|
|
133
|
+
// A checkpoint is whole-value, so it is adopted even when the matching
|
|
134
|
+
// `tool/call` sits before the loaded window (history paging) or the fold
|
|
135
|
+
// resumed from a persisted cache.
|
|
136
|
+
const checkpoint = asCheckpoint(data?.meta);
|
|
137
|
+
const sameCall = state.pending !== null
|
|
138
|
+
&& (state.pending.callId === null
|
|
139
|
+
|| state.pending.callId === data?.message?.toolCallId);
|
|
140
|
+
if (checkpoint === undefined) {
|
|
141
|
+
return sameCall ? { ...state, pending: null } : state;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
...state,
|
|
145
|
+
mode: checkpoint.mode,
|
|
146
|
+
stage: checkpoint.stage,
|
|
147
|
+
allowedStages: checkpoint.allowedStages,
|
|
148
|
+
planItems: checkpoint.planItems,
|
|
149
|
+
openPlanItems: checkpoint.openPlanItems,
|
|
150
|
+
edits: checkpoint.edits,
|
|
151
|
+
verification: verificationOf(checkpoint.verification),
|
|
152
|
+
checkpoint,
|
|
153
|
+
pending: sameCall || state.pending === null ? null : state.pending,
|
|
154
|
+
updatedAt: checkpoint.updatedAt,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
case 'command/run': {
|
|
158
|
+
if (data?.name !== 'coding')
|
|
159
|
+
return state;
|
|
160
|
+
const args = typeof data?.args === 'string' ? data.args.trim().toLowerCase() : '';
|
|
161
|
+
const [head, ...rest] = args.split(/\s+/u);
|
|
162
|
+
if (head === 'stage') {
|
|
163
|
+
const target = stageOf(rest.join(' '));
|
|
164
|
+
// A stage the mode does not open was refused by the live gate; folding
|
|
165
|
+
// the requested value would make the card show a stage that never ran.
|
|
166
|
+
if (target === undefined || !stageInMode(state.mode, target))
|
|
167
|
+
return state;
|
|
168
|
+
return { ...state, stage: target };
|
|
169
|
+
}
|
|
170
|
+
// `/coding set <mode>` is the silent pre-Turn picker path; `/coding <mode>`
|
|
171
|
+
// is the Turn-scoped switch. Both move the same card state.
|
|
172
|
+
if (head === 'set') {
|
|
173
|
+
const mode = modeOf(rest.join(' '));
|
|
174
|
+
if (mode === undefined)
|
|
175
|
+
return state;
|
|
176
|
+
return {
|
|
177
|
+
...state,
|
|
178
|
+
mode,
|
|
179
|
+
stage: stageInMode(mode, state.stage) ? state.stage : entryStage(mode),
|
|
180
|
+
allowedStages: STAGES_BY_MODE[mode],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const mode = modeOf(head);
|
|
184
|
+
if (mode === undefined)
|
|
185
|
+
return state;
|
|
186
|
+
return {
|
|
187
|
+
...state,
|
|
188
|
+
mode,
|
|
189
|
+
stage: stageInMode(mode, state.stage) ? state.stage : entryStage(mode),
|
|
190
|
+
allowedStages: STAGES_BY_MODE[mode],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
case 'todo/write': {
|
|
194
|
+
const todos = data?.todos;
|
|
195
|
+
if (!Array.isArray(todos))
|
|
196
|
+
return state;
|
|
197
|
+
const plan = [];
|
|
198
|
+
for (const item of todos) {
|
|
199
|
+
if (typeof item !== 'object' || item === null)
|
|
200
|
+
continue;
|
|
201
|
+
const content = item.content;
|
|
202
|
+
const status = planStatusOf(item);
|
|
203
|
+
if (typeof content === 'string' && status !== undefined)
|
|
204
|
+
plan.push({ content, status });
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
...state,
|
|
208
|
+
plan,
|
|
209
|
+
planItems: plan.length,
|
|
210
|
+
openPlanItems: plan.filter(item => item.status !== 'completed').length,
|
|
211
|
+
updatedAt: typeof event.time === 'number' ? event.time : state.updatedAt,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
case 'turn/start': {
|
|
215
|
+
// A new turn means no earlier call can still be running.
|
|
216
|
+
return state.pending === null ? state : { ...state, pending: null };
|
|
217
|
+
}
|
|
218
|
+
case 'turn/end': {
|
|
219
|
+
const turn = data?.turn;
|
|
220
|
+
if (typeof turn !== 'number' || !Number.isFinite(turn))
|
|
221
|
+
return state;
|
|
222
|
+
const latest = Math.max(state.latest, turn);
|
|
223
|
+
const frozen = {
|
|
224
|
+
turn,
|
|
225
|
+
mode: state.mode,
|
|
226
|
+
stage: state.stage,
|
|
227
|
+
verification: state.verification,
|
|
228
|
+
planItems: state.planItems,
|
|
229
|
+
openPlanItems: state.openPlanItems,
|
|
230
|
+
edits: state.edits,
|
|
231
|
+
};
|
|
232
|
+
const turns = [...state.turns.filter(item => item.turn !== turn), frozen].slice(-MAX_TURNS);
|
|
233
|
+
return { ...state, latest, turns, pending: null };
|
|
234
|
+
}
|
|
235
|
+
default:
|
|
236
|
+
return state;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/** Throw a helpful error for a value that cannot be a projection state. */
|
|
240
|
+
function invalid(what) {
|
|
241
|
+
throw new Error(`dsh-coding: ${what} is not a Coding stage projection value`);
|
|
242
|
+
}
|
|
243
|
+
/** Validate one persisted or wire value as {@link CodingStageView}. */
|
|
244
|
+
export function parseView(value) {
|
|
245
|
+
if (typeof value !== 'object' || value === null)
|
|
246
|
+
invalid('state');
|
|
247
|
+
const v = value;
|
|
248
|
+
if (typeof v['active'] !== 'boolean')
|
|
249
|
+
invalid('active');
|
|
250
|
+
const mode = modeOf(v['mode']) ?? invalid('mode');
|
|
251
|
+
const stage = stageOf(v['stage']) ?? invalid('stage');
|
|
252
|
+
if (!Array.isArray(v['allowedStages']))
|
|
253
|
+
invalid('allowedStages');
|
|
254
|
+
if (!Array.isArray(v['turns']))
|
|
255
|
+
invalid('turns');
|
|
256
|
+
const numeric = ['planItems', 'openPlanItems', 'edits', 'latest', 'updatedAt'];
|
|
257
|
+
for (const key of numeric)
|
|
258
|
+
if (typeof v[key] !== 'number')
|
|
259
|
+
invalid(key);
|
|
260
|
+
return {
|
|
261
|
+
active: v['active'],
|
|
262
|
+
mode,
|
|
263
|
+
stage,
|
|
264
|
+
allowedStages: v['allowedStages'].map(item => stageOf(item) ?? invalid('allowedStages')),
|
|
265
|
+
planItems: v['planItems'],
|
|
266
|
+
openPlanItems: v['openPlanItems'],
|
|
267
|
+
edits: v['edits'],
|
|
268
|
+
verification: verificationOf(v['verification']),
|
|
269
|
+
checkpoint: asCheckpoint(v['checkpoint']) ?? null,
|
|
270
|
+
plan: (Array.isArray(v['plan']) ? v['plan'] : []).map((item) => {
|
|
271
|
+
if (typeof item !== 'object' || item === null)
|
|
272
|
+
invalid('plan');
|
|
273
|
+
const entry = item;
|
|
274
|
+
const status = planStatusOf(entry) ?? invalid('plan.status');
|
|
275
|
+
const content = entry['content'];
|
|
276
|
+
if (typeof content !== 'string')
|
|
277
|
+
invalid('plan.content');
|
|
278
|
+
return { content, status };
|
|
279
|
+
}),
|
|
280
|
+
pending: pendingOf(v['pending']),
|
|
281
|
+
latest: v['latest'],
|
|
282
|
+
updatedAt: v['updatedAt'],
|
|
283
|
+
turns: v['turns'].map((item) => {
|
|
284
|
+
if (typeof item !== 'object' || item === null)
|
|
285
|
+
invalid('turns');
|
|
286
|
+
const turn = item;
|
|
287
|
+
return {
|
|
288
|
+
turn: typeof turn['turn'] === 'number' ? turn['turn'] : invalid('turns.turn'),
|
|
289
|
+
mode: modeOf(turn['mode']) ?? invalid('turns.mode'),
|
|
290
|
+
stage: stageOf(turn['stage']) ?? invalid('turns.stage'),
|
|
291
|
+
planItems: typeof turn['planItems'] === 'number' ? turn['planItems'] : invalid('turns.planItems'),
|
|
292
|
+
openPlanItems: typeof turn['openPlanItems'] === 'number' ? turn['openPlanItems'] : invalid('turns.openPlanItems'),
|
|
293
|
+
edits: typeof turn['edits'] === 'number' ? turn['edits'] : invalid('turns.edits'),
|
|
294
|
+
verification: verificationOf(turn['verification']),
|
|
295
|
+
};
|
|
296
|
+
}),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** Validate a pending label, or null. */
|
|
300
|
+
function pendingOf(value) {
|
|
301
|
+
if (value === null || value === undefined)
|
|
302
|
+
return null;
|
|
303
|
+
if (typeof value !== 'object')
|
|
304
|
+
invalid('pending');
|
|
305
|
+
const pending = value;
|
|
306
|
+
if (typeof pending['tool'] !== 'string')
|
|
307
|
+
invalid('pending.tool');
|
|
308
|
+
return {
|
|
309
|
+
tool: pending['tool'],
|
|
310
|
+
requested: typeof pending['requested'] === 'string' ? pending['requested'] : null,
|
|
311
|
+
callId: typeof pending['callId'] === 'string' ? pending['callId'] : null,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Build the registrable projection definition.
|
|
316
|
+
*
|
|
317
|
+
* `defaultMode` is read lazily: the projection is folded during Session opens
|
|
318
|
+
* that can happen long after mount, and a page edit must apply to the next one.
|
|
319
|
+
*
|
|
320
|
+
* @param defaultMode - configured initial mode for a Coding session.
|
|
321
|
+
* @returns definition object accepted by `ctx.sessionProjections.register`.
|
|
322
|
+
*/
|
|
323
|
+
export function codingProjection(defaultMode) {
|
|
324
|
+
const mode = () => modeOf(defaultMode()) ?? 'auto';
|
|
325
|
+
return {
|
|
326
|
+
key: CODING_PROJECTION_KEY,
|
|
327
|
+
// Bump when the fold's meaning changes: the persisted cache replays the
|
|
328
|
+
// suffix on top of a validated state, so an old checkpoint must be dropped.
|
|
329
|
+
// v2 added the whole-value checkpoint and the task-list snapshot a resume reads.
|
|
330
|
+
// v3 freezes plan progress and the edit total in every turn snapshot, so an
|
|
331
|
+
// old cache must be rebuilt or a history card cannot read those fields.
|
|
332
|
+
// v4 renames the first stage `recon` → `requirements`; legacy persisted values
|
|
333
|
+
// still parse through asStage, but the cache is rebuilt to drop the old id.
|
|
334
|
+
stateVersion: 4,
|
|
335
|
+
stateSchema: { parse: parseView },
|
|
336
|
+
init: (header) => ({
|
|
337
|
+
...initialView(mode()),
|
|
338
|
+
active: isCodingSession(header),
|
|
339
|
+
}),
|
|
340
|
+
apply: (state, event) => applyEvent(state, event, mode()),
|
|
341
|
+
wire: {
|
|
342
|
+
viewSchema: { parse: parseView },
|
|
343
|
+
view: state => state,
|
|
344
|
+
// The tuple of closed turns is per-session detail; keeping it out of
|
|
345
|
+
// summaries avoids copying it into every Session-list row.
|
|
346
|
+
summary: false,
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration contract of the `dsh-coding` bundle.
|
|
3
|
+
*
|
|
4
|
+
* The same contract is stated three ways on purpose: {@link CodingConfig} for
|
|
5
|
+
* TypeScript, {@link Config} (Schemastery) for the Loader's activation-time
|
|
6
|
+
* validation, and {@link configJsonSchema} for non-Loader consumers such as the
|
|
7
|
+
* plugin page and the tests. `normalizeConfig` adds the checks a schema cannot
|
|
8
|
+
* state — in particular that a worker model names a real `provider/model`
|
|
9
|
+
* route, because a silent fall-back to the lead's own model is the one outcome
|
|
10
|
+
* this plugin must never allow.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-coding/config
|
|
13
|
+
*/
|
|
14
|
+
import z from '@deepseek-ai/schemastery';
|
|
15
|
+
import { CODING_MODES } from './stages.js';
|
|
16
|
+
import { LANGUAGE_MODES, normalizeLanguageMode } from './language.js';
|
|
17
|
+
import { volatileValue } from './volatile.js';
|
|
18
|
+
export { volatileValue };
|
|
19
|
+
/** Reasoning-level policies the plugin accepts. */
|
|
20
|
+
export const REASONING_MODES = ['auto', 'low', 'high', 'max'];
|
|
21
|
+
/** planner 门禁策略:`complex` 对复杂 codex 任务强制 planner,`off` 关闭该门禁。 */
|
|
22
|
+
export const PLANNER_GATE_MODES = ['complex', 'off'];
|
|
23
|
+
/** Schemastery schema the Loader validates the bundle row's `config` with. */
|
|
24
|
+
export const Config = z.object({
|
|
25
|
+
// Volatile: the plugin manager page edits these in place, and the runtime
|
|
26
|
+
// reads the live value on every stage decision and dispatch.
|
|
27
|
+
defaultMode: z.union(CODING_MODES).default('auto').volatile(),
|
|
28
|
+
implementWorkerModel: z.string().required().volatile(),
|
|
29
|
+
verifyWorkerModel: z.string().required().volatile(),
|
|
30
|
+
plannerWorkerModel: z.string().required().volatile(),
|
|
31
|
+
// planner 门禁:不可在插件页修改,改动写入 bundle 的 patch config。
|
|
32
|
+
requirePlanner: z.union(PLANNER_GATE_MODES).default('complex'),
|
|
33
|
+
// Volatile: the plugin page switches the conversation language in place, and
|
|
34
|
+
// the prompt reads the live value at assembly time.
|
|
35
|
+
language: z.union(LANGUAGE_MODES).default('auto').volatile(),
|
|
36
|
+
// Volatile: the plugin page switches the level in place, and every stage's
|
|
37
|
+
// reasoning decision reads the live value.
|
|
38
|
+
reasoning: z.union(REASONING_MODES).default('auto').volatile(),
|
|
39
|
+
// Retry budgets of the verify loop; a blocked delivery is the exit that keeps
|
|
40
|
+
// a failing run from looping. Change them in the bundle's patch config.
|
|
41
|
+
maxVerifyAttempts: z.natural().default(5),
|
|
42
|
+
maxSameFailure: z.natural().default(2),
|
|
43
|
+
// Hard deadline of one verification command (six minutes by default), so a
|
|
44
|
+
// hanging test script is terminated instead of awaited forever.
|
|
45
|
+
verificationTimeoutMs: z.natural().default(360000),
|
|
46
|
+
// A record has no volatile form; change it in the bundle's patch config.
|
|
47
|
+
verificationCommands: z.dict(z.string()).default({}),
|
|
48
|
+
});
|
|
49
|
+
/** The same contract as plain JSON Schema, for consumers that never load the plugin. */
|
|
50
|
+
export const configJsonSchema = {
|
|
51
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
52
|
+
title: 'dsh-coding configuration',
|
|
53
|
+
type: 'object',
|
|
54
|
+
additionalProperties: false,
|
|
55
|
+
required: ['implementWorkerModel', 'verifyWorkerModel', 'plannerWorkerModel'],
|
|
56
|
+
properties: {
|
|
57
|
+
defaultMode: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
enum: [...CODING_MODES],
|
|
60
|
+
default: 'auto',
|
|
61
|
+
description: 'Mode a new Coding session starts in.',
|
|
62
|
+
},
|
|
63
|
+
implementWorkerModel: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
pattern: '^[^/\\s]+/[^/\\s]+$',
|
|
66
|
+
description: 'provider/model route for the implement worker; never inherited from the lead.',
|
|
67
|
+
},
|
|
68
|
+
verifyWorkerModel: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
pattern: '^[^/\\s]+/[^/\\s]+$',
|
|
71
|
+
description: 'provider/model route for the verify worker; never inherited from the lead.',
|
|
72
|
+
},
|
|
73
|
+
plannerWorkerModel: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
pattern: '^[^/\\s]+/[^/\\s]+$',
|
|
76
|
+
description: 'provider/model route for the planner worker (pro model); never inherited from the lead.',
|
|
77
|
+
},
|
|
78
|
+
requirePlanner: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
enum: [...PLANNER_GATE_MODES],
|
|
81
|
+
default: 'complex',
|
|
82
|
+
description: 'Require the planner worker for a complex codex run; complex or off.',
|
|
83
|
+
},
|
|
84
|
+
language: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
enum: [...LANGUAGE_MODES],
|
|
87
|
+
default: 'auto',
|
|
88
|
+
description: 'Conversation language: auto follows the DSH interface, then the host locale.',
|
|
89
|
+
},
|
|
90
|
+
reasoning: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
enum: [...REASONING_MODES],
|
|
93
|
+
default: 'auto',
|
|
94
|
+
description: 'Reasoning level: auto classifies each turn; low, high, and max pin every turn.',
|
|
95
|
+
},
|
|
96
|
+
maxVerifyAttempts: {
|
|
97
|
+
type: 'integer',
|
|
98
|
+
minimum: 0,
|
|
99
|
+
default: 5,
|
|
100
|
+
description: 'Failed verifications allowed before the run delivers blocked; 0 means no limit.',
|
|
101
|
+
},
|
|
102
|
+
maxSameFailure: {
|
|
103
|
+
type: 'integer',
|
|
104
|
+
minimum: 0,
|
|
105
|
+
default: 2,
|
|
106
|
+
description: 'Repeats of the identical failure allowed before delivering blocked; 0 means no limit.',
|
|
107
|
+
},
|
|
108
|
+
verificationTimeoutMs: {
|
|
109
|
+
type: 'integer',
|
|
110
|
+
minimum: 0,
|
|
111
|
+
default: 360000,
|
|
112
|
+
description: 'Longest running time of one verification command in ms; a timeout counts as a failed verification; 0 means no limit.',
|
|
113
|
+
},
|
|
114
|
+
verificationCommands: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
additionalProperties: { type: 'string' },
|
|
117
|
+
default: {},
|
|
118
|
+
description: 'Verification command overrides keyed by kind or kind:scope.',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
/** The verification kinds `run_verification` accepts. */
|
|
123
|
+
export const VERIFICATION_KINDS = ['test', 'build', 'lint', 'typecheck'];
|
|
124
|
+
/** The verification scopes `run_verification` accepts. */
|
|
125
|
+
export const VERIFICATION_SCOPES = ['targeted', 'package', 'full'];
|
|
126
|
+
/**
|
|
127
|
+
* Parse a `provider/model` route. Both halves are required: an omitted provider
|
|
128
|
+
* would let the request silently inherit the lead's route, which is exactly the
|
|
129
|
+
* fall-back the plugin refuses.
|
|
130
|
+
* @param raw - configured route text.
|
|
131
|
+
* @param field - configuration field name, for an actionable failure.
|
|
132
|
+
* @returns the split route.
|
|
133
|
+
* @throws when the value is not exactly `provider/model`.
|
|
134
|
+
*/
|
|
135
|
+
export function parseWorkerRoute(raw, field) {
|
|
136
|
+
const text = typeof raw === 'string' ? raw.trim() : '';
|
|
137
|
+
if (text === '') {
|
|
138
|
+
throw new Error(`dsh-coding: ${field} is required and must be a "provider/model" route `
|
|
139
|
+
+ '(for example "deepseek-account/deepseek-flash"); the worker never inherits the lead\'s model');
|
|
140
|
+
}
|
|
141
|
+
const match = /^([^/\s]+)\/([^/\s]+)$/u.exec(text);
|
|
142
|
+
if (match === null) {
|
|
143
|
+
throw new Error(`dsh-coding: ${field} must be "provider/model" (got ${JSON.stringify(text)}); `
|
|
144
|
+
+ 'the worker never inherits the lead\'s model');
|
|
145
|
+
}
|
|
146
|
+
return { provider: match[1], model: match[2] };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Verify a decoded (or directly applied) configuration and fill the defaults a
|
|
150
|
+
* direct `apply()` call would otherwise miss.
|
|
151
|
+
* @param raw - Loader-validated config, or a hand-authored object in tests.
|
|
152
|
+
* @returns the verified configuration.
|
|
153
|
+
* @throws when a worker route is absent or malformed.
|
|
154
|
+
*/
|
|
155
|
+
export function normalizeConfig(raw) {
|
|
156
|
+
const mode = volatileValue(raw?.defaultMode);
|
|
157
|
+
const maxVerifyAttempts = volatileValue(raw?.maxVerifyAttempts);
|
|
158
|
+
const maxSameFailure = volatileValue(raw?.maxSameFailure);
|
|
159
|
+
const verificationTimeoutMs = volatileValue(raw?.verificationTimeoutMs);
|
|
160
|
+
const commands = volatileValue(raw?.verificationCommands);
|
|
161
|
+
const clean = {};
|
|
162
|
+
if (typeof commands === 'object' && commands !== null) {
|
|
163
|
+
for (const [key, value] of Object.entries(commands)) {
|
|
164
|
+
if (typeof value === 'string' && value.trim() !== '')
|
|
165
|
+
clean[key] = value;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const implementWorkerModel = volatileValue(raw?.implementWorkerModel);
|
|
169
|
+
const verifyWorkerModel = volatileValue(raw?.verifyWorkerModel);
|
|
170
|
+
const plannerWorkerModel = volatileValue(raw?.plannerWorkerModel);
|
|
171
|
+
const requirePlanner = volatileValue(raw?.requirePlanner);
|
|
172
|
+
const language = volatileValue(raw?.language);
|
|
173
|
+
const reasoning = volatileValue(raw?.reasoning);
|
|
174
|
+
// Parse eagerly so a malformed route fails activation, not the first dispatch.
|
|
175
|
+
parseWorkerRoute(implementWorkerModel, 'implementWorkerModel');
|
|
176
|
+
parseWorkerRoute(verifyWorkerModel, 'verifyWorkerModel');
|
|
177
|
+
parseWorkerRoute(plannerWorkerModel, 'plannerWorkerModel');
|
|
178
|
+
return {
|
|
179
|
+
defaultMode: mode !== undefined && CODING_MODES.includes(mode) ? mode : 'auto',
|
|
180
|
+
implementWorkerModel: String(implementWorkerModel).trim(),
|
|
181
|
+
verifyWorkerModel: String(verifyWorkerModel).trim(),
|
|
182
|
+
plannerWorkerModel: String(plannerWorkerModel).trim(),
|
|
183
|
+
requirePlanner: PLANNER_GATE_MODES.includes(requirePlanner)
|
|
184
|
+
? requirePlanner
|
|
185
|
+
: 'complex',
|
|
186
|
+
language: normalizeLanguageMode(language),
|
|
187
|
+
reasoning: REASONING_MODES.includes(reasoning)
|
|
188
|
+
? reasoning
|
|
189
|
+
: 'auto',
|
|
190
|
+
maxVerifyAttempts: retryBudget(maxVerifyAttempts, 5),
|
|
191
|
+
maxSameFailure: retryBudget(maxSameFailure, 2),
|
|
192
|
+
verificationTimeoutMs: retryBudget(verificationTimeoutMs, 360000),
|
|
193
|
+
verificationCommands: clean,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Read one non-negative integer setting (a retry budget or a timeout): the
|
|
198
|
+
* value when it is a non-negative integer, the default otherwise.
|
|
199
|
+
* @param value - decoded configuration value.
|
|
200
|
+
* @param fallback - default used when the value is absent or out of range.
|
|
201
|
+
* @returns the budget or timeout, where `0` means unlimited.
|
|
202
|
+
*/
|
|
203
|
+
function retryBudget(value, fallback) {
|
|
204
|
+
return Number.isInteger(value) && value >= 0 ? value : fallback;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Pick the configured command for a verification request.
|
|
208
|
+
* @param config - verified configuration.
|
|
209
|
+
* @param kind - requested kind.
|
|
210
|
+
* @param scope - requested scope.
|
|
211
|
+
* @returns the most specific configured command, when one exists.
|
|
212
|
+
*/
|
|
213
|
+
export function configuredCommand(config, kind, scope) {
|
|
214
|
+
const scoped = config.verificationCommands[`${kind}:${scope}`];
|
|
215
|
+
if (scoped !== undefined)
|
|
216
|
+
return scoped;
|
|
217
|
+
return config.verificationCommands[kind];
|
|
218
|
+
}
|