dsh-coding 0.0.1 → 0.1.1-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -58
- package/cordis.patch.yml +231 -4
- package/docs/DETAIL.md +183 -0
- package/docs/DEVELOPMENT.md +189 -0
- package/icon.svg +4 -4
- package/lib/apply-patch.js +268 -0
- package/lib/client/capsule.js +120 -0
- package/lib/client/card.js +220 -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 +156 -0
- package/lib/client/mode-picker.js +77 -0
- package/lib/client/styles.js +283 -0
- package/lib/client.js +1691 -0
- package/lib/coding-projection.js +349 -0
- package/lib/config.js +204 -0
- package/lib/contract.js +124 -0
- package/lib/editor.js +23 -0
- package/lib/failures.js +142 -0
- package/lib/handoff.js +312 -0
- package/lib/index.js +109 -7
- package/lib/language.js +136 -0
- package/lib/messages.js +43 -0
- package/lib/models.js +154 -0
- package/lib/patch.js +235 -0
- package/lib/preset.js +1488 -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 +306 -0
- package/lib/state.js +550 -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 +72 -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 +193 -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 +112 -0
- package/lib/types/index.d.ts +144 -0
- package/lib/types/language.d.ts +56 -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 +164 -0
- package/lib/types/state.d.ts +261 -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 +83 -9
- package/lib/index.d.ts +0 -11
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-turn Coding control card, rendered at the tail of every closed Turn.
|
|
3
|
+
*
|
|
4
|
+
* This is the surface the old plugin had — one card per Turn showing the mode
|
|
5
|
+
* that Turn ran under and letting the newest card switch it — extended with the
|
|
6
|
+
* runtime's stage, plan, and verification state. It reads the durable
|
|
7
|
+
* `dshCodingStage` projection, never the Host's in-memory machine, so a
|
|
8
|
+
* reloaded session shows what actually happened.
|
|
9
|
+
*
|
|
10
|
+
* Only the newest Turn's card is a control. Older cards keep the mode and stage
|
|
11
|
+
* they ran under, with their buttons disabled, so a later switch never rewrites
|
|
12
|
+
* history. Mode buttons go back through the Host as the silent `/coding set`
|
|
13
|
+
* verb, so pressing one applies the mode without starting a Turn or producing a
|
|
14
|
+
* model reply.
|
|
15
|
+
*
|
|
16
|
+
* All visual styling lives in `./styles.ts` and follows DSH's own recipes; this
|
|
17
|
+
* component only composes the shipped classes.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-coding/client/card
|
|
20
|
+
*/
|
|
21
|
+
import { createElement as h, memo, useState } from 'react';
|
|
22
|
+
import { CODING_PROJECTION_KEY, } from '../coding-projection.js';
|
|
23
|
+
import { REASONING_PROJECTION_KEY, } from '../reasoning-projection.js';
|
|
24
|
+
import { levelForEffort } from '../reasoning-levels.js';
|
|
25
|
+
import { STAGES_BY_MODE } from '../stages.js';
|
|
26
|
+
import { commandRejected } from './command-row.js';
|
|
27
|
+
/** Modes the card can switch to, in roster order. */
|
|
28
|
+
const MODES = ['auto', 'consult', 'review', 'codex'];
|
|
29
|
+
/**
|
|
30
|
+
* The state one card renders: the live projection for the newest closed Turn,
|
|
31
|
+
* or the frozen snapshot that Turn ran under. Pure, so the split between a
|
|
32
|
+
* control card and a history card is testable without React.
|
|
33
|
+
* @param view - current projection value.
|
|
34
|
+
* @param turn - Turn the card belongs to, when the owner declares one.
|
|
35
|
+
* @returns the values rendered, plus whether this card may switch the mode.
|
|
36
|
+
*/
|
|
37
|
+
export function cardState(view, turn) {
|
|
38
|
+
const turns = Array.isArray(view.turns) ? view.turns : [];
|
|
39
|
+
const frozen = turn === undefined ? undefined : turns.find(item => item.turn === turn);
|
|
40
|
+
// A tail is published on `turn/end`, so a Turn that merely started has no
|
|
41
|
+
// card; treating a newer Turn as live keeps the newest card switchable.
|
|
42
|
+
const live = turn === undefined || turn >= view.latest;
|
|
43
|
+
const mode = (live ? view.mode : frozen?.mode ?? view.mode);
|
|
44
|
+
const stage = (live ? view.stage : frozen?.stage ?? view.stage);
|
|
45
|
+
const verification = (live ? view.verification : frozen?.verification ?? view.verification) ?? null;
|
|
46
|
+
// Freeze numbers with the rest of the turn: a history card must not show the
|
|
47
|
+
// live session's plan progress or edit total.
|
|
48
|
+
const numbers = live || frozen === undefined
|
|
49
|
+
? { planItems: view.planItems, openPlanItems: view.openPlanItems, edits: view.edits }
|
|
50
|
+
: { planItems: frozen.planItems, openPlanItems: frozen.openPlanItems, edits: frozen.edits };
|
|
51
|
+
// A wire value from an older build may name a mode this build does not know;
|
|
52
|
+
// fall back to the codex stage set instead of crashing the chat render.
|
|
53
|
+
return { live, mode, stage, verification, allowed: STAGES_BY_MODE[mode] ?? STAGES_BY_MODE.codex, ...numbers };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The command line one mode switch sends back through the Host. A card sits at
|
|
57
|
+
* a closed turn's tail, and switching mode is a control action, not a prompt:
|
|
58
|
+
* the silent `set` verb applies the mode and tool table without starting a
|
|
59
|
+
* Turn, so the model never answers a button press. Typed `/coding <mode>` keeps
|
|
60
|
+
* its "switch and open a turn" meaning.
|
|
61
|
+
*/
|
|
62
|
+
export function commandFor(mode) {
|
|
63
|
+
return `/coding set ${mode}`;
|
|
64
|
+
}
|
|
65
|
+
/** Read the Turn number out of the owner props. */
|
|
66
|
+
function turnOf(value) {
|
|
67
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
68
|
+
return value;
|
|
69
|
+
const turn = value?.turn;
|
|
70
|
+
return typeof turn === 'number' && Number.isFinite(turn) ? turn : undefined;
|
|
71
|
+
}
|
|
72
|
+
/** Verification text for one card. */
|
|
73
|
+
/**
|
|
74
|
+
* The card's verification cell: status only, never the command. The command
|
|
75
|
+
* still rides the capsule tooltip and the `run_verification` result, where a
|
|
76
|
+
* reader can act on it; the 12px card row stays scannable.
|
|
77
|
+
* @param verification - recorded outcome, or null before the first run.
|
|
78
|
+
* @param t - locale lookup.
|
|
79
|
+
* @returns the label and the color class that carries its meaning.
|
|
80
|
+
*/
|
|
81
|
+
export function verificationText(verification, t) {
|
|
82
|
+
if (verification === null) {
|
|
83
|
+
return { text: t('verification.none'), className: 'dsh-coding-value' };
|
|
84
|
+
}
|
|
85
|
+
return verification.passed
|
|
86
|
+
? { text: t('verification.passed'), className: 'dsh-coding-success' }
|
|
87
|
+
: { text: t('verification.failed'), className: 'dsh-coding-warn' };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Read one override/effort slice. The state is read defensively because a wire
|
|
91
|
+
* value from an older build may miss a field the current type declares.
|
|
92
|
+
*/
|
|
93
|
+
function sliceDisplay(slice) {
|
|
94
|
+
if (slice.override === 'low' || slice.override === 'high' || slice.override === 'max') {
|
|
95
|
+
return { level: slice.override, source: 'override' };
|
|
96
|
+
}
|
|
97
|
+
if (typeof slice.userEffort === 'string' && slice.userEffort.trim() !== '') {
|
|
98
|
+
return { level: levelForEffort(slice.userEffort.trim()), source: 'pick' };
|
|
99
|
+
}
|
|
100
|
+
if (typeof slice.effort === 'string' && slice.effort.trim() !== '') {
|
|
101
|
+
return { level: levelForEffort(slice.effort.trim()), source: 'auto' };
|
|
102
|
+
}
|
|
103
|
+
return { level: null, source: 'pending' };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The reasoning row one card renders. A closed turn keeps the state frozen at
|
|
107
|
+
* its own `turn/end`, so history cards never borrow a later turn's level; an
|
|
108
|
+
* unknown history turn stays pending instead of copying the live state.
|
|
109
|
+
* @param state - durable reasoning projection, when the Host serves it.
|
|
110
|
+
* @param turn - Turn the card belongs to.
|
|
111
|
+
* @param settings - configured policy: `auto`, or a pinned level.
|
|
112
|
+
*/
|
|
113
|
+
export function reasoningDisplay(state, turn, settings) {
|
|
114
|
+
const pinned = settings === 'low' || settings === 'high' || settings === 'max' ? settings : undefined;
|
|
115
|
+
if (state === undefined) {
|
|
116
|
+
return pinned === undefined
|
|
117
|
+
? { level: null, source: 'pending' }
|
|
118
|
+
: { level: pinned, source: 'settings' };
|
|
119
|
+
}
|
|
120
|
+
const turns = Array.isArray(state.turns) ? state.turns : [];
|
|
121
|
+
const frozen = turn === undefined ? undefined : turns.find(item => item.turn === turn);
|
|
122
|
+
if (frozen !== undefined) {
|
|
123
|
+
const display = sliceDisplay(frozen);
|
|
124
|
+
// A pin labels the turn only when the turn actually ran at that level.
|
|
125
|
+
return pinned !== undefined && display.level === pinned
|
|
126
|
+
? { level: pinned, source: 'settings' }
|
|
127
|
+
: display;
|
|
128
|
+
}
|
|
129
|
+
const latest = typeof state.latest === 'number' ? state.latest : 0;
|
|
130
|
+
if (turn !== undefined && turn < latest)
|
|
131
|
+
return { level: null, source: 'pending' };
|
|
132
|
+
if (pinned !== undefined)
|
|
133
|
+
return { level: pinned, source: 'settings' };
|
|
134
|
+
return sliceDisplay(state);
|
|
135
|
+
}
|
|
136
|
+
/** Locale key per reasoning source. */
|
|
137
|
+
const REASONING_SOURCE_KEY = {
|
|
138
|
+
settings: 'reasoning.sourceSettings',
|
|
139
|
+
override: 'reasoning.sourceOverride',
|
|
140
|
+
pick: 'reasoning.sourcePick',
|
|
141
|
+
auto: 'reasoning.sourceAuto',
|
|
142
|
+
pending: 'reasoning.pending',
|
|
143
|
+
};
|
|
144
|
+
/** Display label for a level; `Low`/`High`/`Max` are provider-level names. */
|
|
145
|
+
function levelLabel(level) {
|
|
146
|
+
return level === null ? null : level === 'low' ? 'Low' : level === 'high' ? 'High' : 'Max';
|
|
147
|
+
}
|
|
148
|
+
/** The per-turn Coding control card. */
|
|
149
|
+
export const CodingTurnCard = memo(function CodingTurnCard(props) {
|
|
150
|
+
const { t } = props;
|
|
151
|
+
const raw = props.useProjection?.(CODING_PROJECTION_KEY);
|
|
152
|
+
const reasoningRaw = props.useProjection?.(REASONING_PROJECTION_KEY);
|
|
153
|
+
const view = raw === null || typeof raw !== 'object' ? undefined : raw;
|
|
154
|
+
const [busy, setBusy] = useState(null);
|
|
155
|
+
const [error, setError] = useState(null);
|
|
156
|
+
if (view === undefined || view.active !== true)
|
|
157
|
+
return null;
|
|
158
|
+
const turn = turnOf(props.turn);
|
|
159
|
+
const { live, mode, stage, verification, allowed, ...numbers } = cardState(view, turn);
|
|
160
|
+
const reasoningState = reasoningRaw === null || typeof reasoningRaw !== 'object'
|
|
161
|
+
? undefined
|
|
162
|
+
: reasoningRaw;
|
|
163
|
+
const reasoning = reasoningDisplay(reasoningState, turn, props.settings?.());
|
|
164
|
+
const stageIndex = allowed.indexOf(stage);
|
|
165
|
+
// A wire value from a partial or older build still renders numbers.
|
|
166
|
+
const number = (value) => (typeof value === 'number' && Number.isFinite(value) ? value : 0);
|
|
167
|
+
const planItems = number(numbers.planItems);
|
|
168
|
+
const openPlanItems = number(numbers.openPlanItems);
|
|
169
|
+
const state = verificationText(verification, t);
|
|
170
|
+
const enabled = live && busy === null;
|
|
171
|
+
async function choose(next) {
|
|
172
|
+
if (next === mode || busy !== null || !live)
|
|
173
|
+
return;
|
|
174
|
+
setBusy(next);
|
|
175
|
+
setError(null);
|
|
176
|
+
try {
|
|
177
|
+
const result = await props.execute?.(commandFor(next));
|
|
178
|
+
if (commandRejected(result))
|
|
179
|
+
setError(t('card.switchFailed'));
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
setError(t('card.switchFailed'));
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
setBusy(null);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return h('div', {
|
|
189
|
+
className: 'dsh-coding-card',
|
|
190
|
+
'data-dsh-coding-card': 'true',
|
|
191
|
+
'data-live': live ? 'true' : 'false',
|
|
192
|
+
'aria-label': t('aria'),
|
|
193
|
+
}, h('div', { className: 'dsh-coding-row' }, h('span', { className: 'dsh-coding-label' }, t('card.mode')), h('div', { className: 'dsh-coding-actions' }, ...MODES.map(option => h('button', {
|
|
194
|
+
key: option,
|
|
195
|
+
type: 'button',
|
|
196
|
+
className: 'dsh-coding-button',
|
|
197
|
+
disabled: !enabled,
|
|
198
|
+
'aria-pressed': option === mode,
|
|
199
|
+
onClick: () => { void choose(option); },
|
|
200
|
+
}, t(`mode.${option}`)))), live ? null : h('span', { className: 'dsh-coding-hint' }, t('card.stale'))), h('div', { className: 'dsh-coding-row' }, h('span', { className: 'dsh-coding-label' }, t('card.stage')), ...allowed.flatMap((item, index) => [
|
|
201
|
+
...index === 0 ? [] : [h('span', { key: `${item}-arrow`, className: 'dsh-coding-arrow', 'aria-hidden': 'true' }, '→')],
|
|
202
|
+
h('span', {
|
|
203
|
+
key: item,
|
|
204
|
+
className: 'dsh-coding-stage',
|
|
205
|
+
'data-current': item === stage ? 'true' : undefined,
|
|
206
|
+
'data-done': index < stageIndex ? 'true' : undefined,
|
|
207
|
+
'data-stage': item,
|
|
208
|
+
}, t(`stage.${item}`)),
|
|
209
|
+
]), h('span', { className: 'dsh-coding-hint' }, t('card.stageHint'))), h('div', { className: 'dsh-coding-row' }, h('span', { className: 'dsh-coding-label' }, t('card.reasoning')), h('span', {
|
|
210
|
+
className: reasoning.level === null ? 'dsh-coding-hint' : 'dsh-coding-value',
|
|
211
|
+
'data-reasoning-level': reasoning.level ?? 'pending',
|
|
212
|
+
'data-reasoning-source': reasoning.source,
|
|
213
|
+
}, levelLabel(reasoning.level) ?? t('reasoning.pending')), h('span', { className: 'dsh-coding-faint', 'aria-hidden': 'true' }, '·'), h('span', { className: 'dsh-coding-hint' }, t(REASONING_SOURCE_KEY[reasoning.source]))), h('div', { className: 'dsh-coding-row' }, h('span', { className: 'dsh-coding-label' }, t('card.verify')), h('span', { className: state.className }, state.text), h('span', { className: 'dsh-coding-faint', 'aria-hidden': 'true' }, '·'), h('span', { className: 'dsh-coding-value' }, planItems === 0
|
|
214
|
+
? t('plan.none')
|
|
215
|
+
: t('plan.progress')
|
|
216
|
+
.replace('{done}', String(Math.max(0, planItems - openPlanItems)))
|
|
217
|
+
.replace('{total}', String(planItems))), h('span', { className: 'dsh-coding-faint', 'aria-hidden': 'true' }, '·'), h('span', { className: 'dsh-coding-value' }, t('files').replace('{count}', String(number(numbers.edits)))), view.pending === null
|
|
218
|
+
? null
|
|
219
|
+
: h('span', { className: 'dsh-coding-value' }, t('pending').replace('{tool}', view.pending.tool))), error === null ? null : h('p', { className: 'dsh-coding-error' }, error));
|
|
220
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One `/coding` command receipt in the Chat flow.
|
|
3
|
+
*
|
|
4
|
+
* Mode switching is already visible where it belongs: the blank-hero picker
|
|
5
|
+
* highlights the chosen mode, the newest turn card shows it as `aria-pressed`,
|
|
6
|
+
* and the next stage capsule records it. Repeating that as a command card in
|
|
7
|
+
* the transcript adds nothing and — before this row existed — a failed switch
|
|
8
|
+
* left a red error card behind. So `/coding set <mode>` and the bare
|
|
9
|
+
* `/coding <mode>` switch render nothing here: the change reads off the
|
|
10
|
+
* controls, not the transcript.
|
|
11
|
+
*
|
|
12
|
+
* Every other `/coding` line still renders one plain status line — the command
|
|
13
|
+
* and its own text — because a status query or a stage move is worth keeping.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-coding/client/command-row
|
|
16
|
+
*/
|
|
17
|
+
import { createElement as h, memo } from 'react';
|
|
18
|
+
/** The modes a bare `/coding <mode>` switches to, in roster order. */
|
|
19
|
+
const SWITCH_WORDS = ['auto', 'consult', 'review', 'codex'];
|
|
20
|
+
/**
|
|
21
|
+
* Decide what one command receipt renders. Pure, so the hiding rule — the whole
|
|
22
|
+
* point of this module — is testable without a renderer.
|
|
23
|
+
* @param node - the `CommandNode` the Chat owner passes down.
|
|
24
|
+
* @returns the visible/absent split for this receipt.
|
|
25
|
+
*/
|
|
26
|
+
export function commandRowOf(node) {
|
|
27
|
+
const line = `/${node.name ?? 'coding'}${node.args ?? ''}`;
|
|
28
|
+
const words = (node.args ?? '').trim().toLowerCase().split(/\s+/u).filter(Boolean);
|
|
29
|
+
// A mode switch: either the silent `set <mode>` or the bare switch command.
|
|
30
|
+
const switches = words[0] === 'set'
|
|
31
|
+
|| (words.length === 1 && SWITCH_WORDS.includes(words[0]));
|
|
32
|
+
if (switches)
|
|
33
|
+
return { hidden: true, line, text: null, failed: false };
|
|
34
|
+
const outcome = node.outcome;
|
|
35
|
+
// A command that has not settled yet has no body worth a row.
|
|
36
|
+
if (outcome == null)
|
|
37
|
+
return { hidden: true, line, text: null, failed: false };
|
|
38
|
+
const text = typeof outcome.text === 'string' && outcome.text.length > 0 ? outcome.text : null;
|
|
39
|
+
return { hidden: false, line, text, failed: outcome.kind === 'error' };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Whether a commands Remote result is a command-level failure.
|
|
43
|
+
*
|
|
44
|
+
* Two shapes mean failure: the Remote itself failed (`{ ok: false }`), or the
|
|
45
|
+
* Remote succeeded while the command handler rejected the line
|
|
46
|
+
* (`{ ok: true, value: { result: { kind: 'error' } } }`). Only the first used to
|
|
47
|
+
* be checked, so a rejected switch looked like a success.
|
|
48
|
+
* @param result - whatever `remote.commands.execute()` returned.
|
|
49
|
+
* @returns true when the command did not apply.
|
|
50
|
+
*/
|
|
51
|
+
export function commandRejected(result) {
|
|
52
|
+
if (result === null || typeof result !== 'object')
|
|
53
|
+
return false;
|
|
54
|
+
if (result.ok === false)
|
|
55
|
+
return true;
|
|
56
|
+
const value = result.value;
|
|
57
|
+
if (value === null || typeof value !== 'object')
|
|
58
|
+
return false;
|
|
59
|
+
const inner = value.result;
|
|
60
|
+
if (inner === null || typeof inner !== 'object')
|
|
61
|
+
return false;
|
|
62
|
+
return inner.kind === 'error';
|
|
63
|
+
}
|
|
64
|
+
/** One `/coding` command receipt, or nothing for a mode switch. */
|
|
65
|
+
export const CodingCommandRow = memo(function CodingCommandRow(props) {
|
|
66
|
+
const view = commandRowOf(props.node);
|
|
67
|
+
if (view.hidden)
|
|
68
|
+
return null;
|
|
69
|
+
return h('div', {
|
|
70
|
+
className: 'dsh-coding-command',
|
|
71
|
+
'data-command': props.node.name ?? 'coding',
|
|
72
|
+
...view.failed ? { 'data-error': 'true' } : {},
|
|
73
|
+
}, h('span', { className: 'dsh-coding-label' }, view.line), view.text === null
|
|
74
|
+
? null
|
|
75
|
+
: h('span', { className: view.failed ? 'dsh-coding-error' : 'dsh-coding-value' }, view.text));
|
|
76
|
+
});
|