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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of the `dsh-coding` bundle.
|
|
3
|
+
*
|
|
4
|
+
* It contributes four surfaces, all as effects so an unload or a slot-owner
|
|
5
|
+
* collapse removes them:
|
|
6
|
+
*
|
|
7
|
+
* 1. the per-turn control card in `conversation.chat.turnTail`, which reads the
|
|
8
|
+
* durable `dshCodingStage` projection and switches mode through `/coding …`;
|
|
9
|
+
* 2. the stage capsule Definition in `conversation.chat.node`, which renders
|
|
10
|
+
* the checkpoint each Coding tool call leaves in `tool/result.meta`;
|
|
11
|
+
* 3. the command row in `conversation.chat.commandview`, which hides the mode
|
|
12
|
+
* switch receipts (they show up in the picker, the card, and the capsule)
|
|
13
|
+
* and keeps every other `/coding` receipt as one text line;
|
|
14
|
+
* 4. the bundle's configuration page in `plugins.bundle.config`.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-coding/client
|
|
17
|
+
*/
|
|
18
|
+
import { createElement as h } from 'react';
|
|
19
|
+
import { CAPSULE_KIND, capsuleDefinition } from './definition.js';
|
|
20
|
+
import { CodingStageCapsule } from './capsule.js';
|
|
21
|
+
import { CodingTurnCard } from './card.js';
|
|
22
|
+
import { CodingModePicker } from './mode-picker.js';
|
|
23
|
+
import { CodingCommandRow } from './command-row.js';
|
|
24
|
+
import { CodingConfigPage, SETTINGS_NAMESPACE, } from './config-page.js';
|
|
25
|
+
import { installStyles } from './styles.js';
|
|
26
|
+
import { en, zh } from './locales.js';
|
|
27
|
+
/** Locale namespace owned by this plugin. */
|
|
28
|
+
export const NS = 'dsh-coding';
|
|
29
|
+
/** The bundle's package name, which is also its configuration-page key. */
|
|
30
|
+
const PACKAGE_NAME = 'dsh-coding';
|
|
31
|
+
/** Client services this half needs before it can register anything. */
|
|
32
|
+
export const inject = ['slots', 'locale', 'uiConversation', 'configForms', 'remote', 'remote.commands', 'remote.llm'];
|
|
33
|
+
/**
|
|
34
|
+
* Register the card, the first-message pickers, the capsule, and the configuration page.
|
|
35
|
+
* @param ctx - client root context.
|
|
36
|
+
*/
|
|
37
|
+
export function apply(ctx) {
|
|
38
|
+
const translate = ctx.locale.bind(NS);
|
|
39
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-coding: dictionaries');
|
|
40
|
+
// One stylesheet for the card, the capsule, and the page; every rule uses a
|
|
41
|
+
// shipped DSH recipe or theme token (see ./styles.ts).
|
|
42
|
+
ctx.effect(() => installStyles(), 'dsh-coding: styles');
|
|
43
|
+
/** Run one `/coding …` line against the session through the Host. */
|
|
44
|
+
const runCommand = (sessionId, line) => {
|
|
45
|
+
const commands = ctx.remote?.commands;
|
|
46
|
+
if (typeof commands?.execute !== 'function' || typeof sessionId !== 'string')
|
|
47
|
+
return undefined;
|
|
48
|
+
return commands.execute(sessionId, line, []);
|
|
49
|
+
};
|
|
50
|
+
// The configuration form is shared: the page edits it, and the per-turn card
|
|
51
|
+
// reads the pinned reasoning policy as a label only. The form owns the write
|
|
52
|
+
// queue (revision fence, Host validation, recovery read).
|
|
53
|
+
const forms = ctx.configForms;
|
|
54
|
+
const form = forms.get(SETTINGS_NAMESPACE);
|
|
55
|
+
// The model catalog lives on the `llm` namespace of the Host Remote, not on
|
|
56
|
+
// the Remote root. Read it from there so `listProviders` /
|
|
57
|
+
// `listConfigurableProviders` / `discoverModels` resolve.
|
|
58
|
+
const llmRemote = ctx.remote?.llm;
|
|
59
|
+
const settingsValue = () => {
|
|
60
|
+
try {
|
|
61
|
+
return form?.getSnapshot?.()?.value?.reasoning;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// ── Per-turn control card ─────────────────────────────────────────────────
|
|
68
|
+
// The card is a plain turn-tail entry, so it renders on every closed Turn of
|
|
69
|
+
// a Coding session — including a turn where the model ran no Coding tool.
|
|
70
|
+
const turnCard = (props) => h(CodingTurnCard, {
|
|
71
|
+
...props,
|
|
72
|
+
t: props.t ?? translate,
|
|
73
|
+
execute: (line) => runCommand(props.sessionId, line),
|
|
74
|
+
settings: settingsValue,
|
|
75
|
+
});
|
|
76
|
+
const slots = ctx.slots;
|
|
77
|
+
ctx.effect(() => slots.inject('conversation.chat.turnTail', () => slots.register({
|
|
78
|
+
name: 'conversation.chat.turnTail',
|
|
79
|
+
id: 'dsh-coding/turn-card',
|
|
80
|
+
order: 50,
|
|
81
|
+
locale: NS,
|
|
82
|
+
}, turnCard)), 'dsh-coding: turn card');
|
|
83
|
+
// ── First-message mode picker ─────────────────────────────────────────────
|
|
84
|
+
// The blank-session hero renders this beside the composer. It sends the
|
|
85
|
+
// silent `/coding set <mode>` so the choice applies to the first Turn without
|
|
86
|
+
// starting one; later switches stay on the per-Turn card.
|
|
87
|
+
const modePicker = (props) => h(CodingModePicker, {
|
|
88
|
+
...props,
|
|
89
|
+
t: props.t ?? translate,
|
|
90
|
+
execute: (line) => runCommand(props.sessionId, line),
|
|
91
|
+
});
|
|
92
|
+
ctx.effect(() => slots.inject('conversation.hero.options', () => slots.register({
|
|
93
|
+
name: 'conversation.hero.options',
|
|
94
|
+
id: 'dsh-coding/mode-picker',
|
|
95
|
+
order: 20,
|
|
96
|
+
locale: NS,
|
|
97
|
+
}, modePicker)), 'dsh-coding: mode picker');
|
|
98
|
+
// ── Stage capsule ─────────────────────────────────────────────────────────
|
|
99
|
+
ctx.effect(() => ctx.uiConversation.events.register(capsuleDefinition), 'dsh-coding: capsule definition');
|
|
100
|
+
ctx.effect(() => slots.inject('conversation.chat.node', () => slots.register({
|
|
101
|
+
name: 'conversation.chat.node',
|
|
102
|
+
key: CAPSULE_KIND,
|
|
103
|
+
locale: NS,
|
|
104
|
+
}, CodingStageCapsule)), 'dsh-coding: capsule node');
|
|
105
|
+
// ── Command row ───────────────────────────────────────────────────────────
|
|
106
|
+
// `conversation.chat.commandview` is keyed by command name, so registering
|
|
107
|
+
// key `coding` replaces the default receipt card for this plugin's command.
|
|
108
|
+
ctx.effect(() => slots.inject('conversation.chat.commandview', () => slots.register({
|
|
109
|
+
name: 'conversation.chat.commandview',
|
|
110
|
+
key: 'coding',
|
|
111
|
+
locale: NS,
|
|
112
|
+
}, CodingCommandRow)), 'dsh-coding: command row');
|
|
113
|
+
// ── Configuration page ────────────────────────────────────────────────────
|
|
114
|
+
// A bundle page receives only `view` as owner props, so the page takes the
|
|
115
|
+
// Host form from `ctx.configForms` by entry id. The form owns the write queue
|
|
116
|
+
// (revision fence, Host validation, recovery read): this page never calls
|
|
117
|
+
// `ctx.remote.settings` itself.
|
|
118
|
+
const configPage = (props) => h(CodingConfigPage, {
|
|
119
|
+
...props,
|
|
120
|
+
form,
|
|
121
|
+
remote: llmRemote,
|
|
122
|
+
t: props.t ?? translate,
|
|
123
|
+
});
|
|
124
|
+
ctx.effect(() => slots.inject('plugins.bundle.config', () => slots.register({
|
|
125
|
+
name: 'plugins.bundle.config',
|
|
126
|
+
key: PACKAGE_NAME,
|
|
127
|
+
locale: NS,
|
|
128
|
+
}, configPage)), 'dsh-coding: configuration page');
|
|
129
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy of the Coding surface, registered as the `dsh-coding` Client locale
|
|
3
|
+
* namespace, so visible UI text never hard-codes a language.
|
|
4
|
+
*
|
|
5
|
+
* @module dsh-coding/client/locales
|
|
6
|
+
*/
|
|
7
|
+
/** English copy. */
|
|
8
|
+
export const en = {
|
|
9
|
+
aria: 'Coding runtime stage',
|
|
10
|
+
'hint.mode': 'Switch mode with /coding auto, /coding consult, /coding review, or /coding codex',
|
|
11
|
+
'picker.label': 'Mode',
|
|
12
|
+
'picker.aria': 'Coding mode for the first message',
|
|
13
|
+
'mode.consult': 'Q&A',
|
|
14
|
+
'mode.review': 'Review',
|
|
15
|
+
'mode.auto': 'Auto',
|
|
16
|
+
'mode.codex': 'Codex',
|
|
17
|
+
'stage.requirements': 'Requirements',
|
|
18
|
+
'stage.plan': 'Plan',
|
|
19
|
+
'stage.implement': 'Implement',
|
|
20
|
+
'stage.verify': 'Verify',
|
|
21
|
+
'stage.deliver': 'Deliver',
|
|
22
|
+
'verification.none': 'not verified',
|
|
23
|
+
'verification.passed': 'verified',
|
|
24
|
+
'verification.failed': 'verification failed',
|
|
25
|
+
'plan.none': 'no task list',
|
|
26
|
+
'plan.progress': '{done}/{total} plan steps',
|
|
27
|
+
'worker.running': '{role} worker running',
|
|
28
|
+
'worker.completed': '{role} worker done',
|
|
29
|
+
'worker.failed': '{role} worker failed',
|
|
30
|
+
pending: 'running {tool}',
|
|
31
|
+
refused: 'advance refused',
|
|
32
|
+
files: '{count} files changed',
|
|
33
|
+
'card.mode': 'Mode',
|
|
34
|
+
'card.stage': 'Stage',
|
|
35
|
+
'card.verify': 'Verification',
|
|
36
|
+
'card.stageHint': 'Edit with /coding stage <stage>',
|
|
37
|
+
'card.switchFailed': 'The mode was not changed. Try /coding <mode>.',
|
|
38
|
+
'card.stale': 'history',
|
|
39
|
+
'card.reasoning': 'Reasoning',
|
|
40
|
+
'reasoning.pending': 'pending',
|
|
41
|
+
'reasoning.sourceAuto': 'automatic',
|
|
42
|
+
'reasoning.sourceOverride': 'session override',
|
|
43
|
+
'reasoning.sourcePick': 'chat-box pick',
|
|
44
|
+
'reasoning.sourceSettings': 'pinned by settings',
|
|
45
|
+
'config.title': 'Coding runtime',
|
|
46
|
+
'config.hint': 'These values are validated when saved and used by every later stage decision and worker dispatch.',
|
|
47
|
+
'config.mode': 'Default mode',
|
|
48
|
+
'config.modeHint': 'Mode a new Coding session starts in; auto chooses the workflow during the requirements stage.',
|
|
49
|
+
'config.implementModel': 'Implement worker model',
|
|
50
|
+
'config.implementModelHint': 'Required provider/model route. Never inherited from the lead.',
|
|
51
|
+
'config.plannerModel': 'Planner worker model',
|
|
52
|
+
'config.plannerModelHint': 'Required provider/model route for the pro planner; it plans, it never edits.',
|
|
53
|
+
'config.verifyModel': 'Verify worker model',
|
|
54
|
+
'config.verifyModelHint': 'Required provider/model route for the read-only verify worker.',
|
|
55
|
+
'config.language': 'Conversation language',
|
|
56
|
+
'config.languageHint': 'Auto follows the DSH interface, then the host locale. Only Chinese and English ship.',
|
|
57
|
+
'config.languageAuto': 'Automatic (follow DSH)',
|
|
58
|
+
'config.reasoning': 'Reasoning level',
|
|
59
|
+
'config.reasoningHint': 'Auto classifies each turn from the request; low, high, or max pins every turn. A chat-box effort pick or coding_reasoning overrides automatic only.',
|
|
60
|
+
'config.reasoningAuto': 'Automatic (recommended)',
|
|
61
|
+
'config.verification': 'Verification',
|
|
62
|
+
'config.verificationHint': 'The verify stage runs these checks; the deliver gate needs a passing result.',
|
|
63
|
+
'config.commands': 'Verification command overrides',
|
|
64
|
+
'config.commandsHint': 'Keyed by kind or kind:scope. Edit them in the bundle patch configuration.',
|
|
65
|
+
'config.save': 'Save',
|
|
66
|
+
'config.saving': 'Saving…',
|
|
67
|
+
'config.saved': 'Saved.',
|
|
68
|
+
'config.saveFailed': 'The configuration was rejected. Check the values and Host authorization.',
|
|
69
|
+
'config.invalidRoute': 'Use provider/model, for example deepseek-account/deepseek-flash.',
|
|
70
|
+
'config.readOnly': 'This deployment stores settings read-only.',
|
|
71
|
+
'config.loading': 'Loading configuration…',
|
|
72
|
+
'config.unavailable': 'This Host does not expose the configuration form for this entry.',
|
|
73
|
+
'config.reset': 'Restore defaults',
|
|
74
|
+
'config.presetWarning': 'Keep every plugin of the Coding preset enabled, or this plugin cannot work.',
|
|
75
|
+
'config.modelWarning': 'Select the worker models carefully. An invalid choice is highlighted and disables Save.',
|
|
76
|
+
'config.modelsLoading': 'Loading models…',
|
|
77
|
+
'config.modelsUnavailable': 'Could not load the configured model list:',
|
|
78
|
+
'config.modelsRetry': 'Reload models',
|
|
79
|
+
'config.modelPlaceholder': 'Select a model',
|
|
80
|
+
'config.modelMissing': 'not in the current model list',
|
|
81
|
+
};
|
|
82
|
+
/** Chinese copy. */
|
|
83
|
+
export const zh = {
|
|
84
|
+
aria: 'Coding 运行时阶段',
|
|
85
|
+
'hint.mode': '用 /coding auto、/coding consult、/coding review、/coding codex 切换模式',
|
|
86
|
+
'picker.label': '工作模式',
|
|
87
|
+
'picker.aria': '首条消息的工作模式',
|
|
88
|
+
'mode.consult': '问答',
|
|
89
|
+
'mode.review': '审查',
|
|
90
|
+
'mode.auto': '自动',
|
|
91
|
+
'mode.codex': 'Codex',
|
|
92
|
+
'stage.requirements': '需求分析',
|
|
93
|
+
'stage.plan': '规划',
|
|
94
|
+
'stage.implement': '实现',
|
|
95
|
+
'stage.verify': '验证',
|
|
96
|
+
'stage.deliver': '交付',
|
|
97
|
+
'verification.none': '未验证',
|
|
98
|
+
'verification.passed': '已验证',
|
|
99
|
+
'verification.failed': '验证失败',
|
|
100
|
+
'plan.none': '无任务单',
|
|
101
|
+
'plan.progress': '任务 {done}/{total}',
|
|
102
|
+
'worker.running': '{role} 子代理运行中',
|
|
103
|
+
'worker.completed': '{role} 子代理完成',
|
|
104
|
+
'worker.failed': '{role} 子代理失败',
|
|
105
|
+
pending: '正在执行 {tool}',
|
|
106
|
+
refused: '阶段推进被拒绝',
|
|
107
|
+
files: '已改 {count} 个文件',
|
|
108
|
+
'card.mode': '模式',
|
|
109
|
+
'card.stage': '阶段',
|
|
110
|
+
'card.verify': '验证',
|
|
111
|
+
'card.stageHint': '用 /coding stage <阶段> 调整',
|
|
112
|
+
'card.switchFailed': '模式未切换成功,请重试或直接执行 /coding <模式>。',
|
|
113
|
+
'card.stale': '历史',
|
|
114
|
+
'card.reasoning': '推理',
|
|
115
|
+
'reasoning.pending': '待确定',
|
|
116
|
+
'reasoning.sourceAuto': '自动',
|
|
117
|
+
'reasoning.sourceOverride': '会话覆盖',
|
|
118
|
+
'reasoning.sourcePick': '对话框选择',
|
|
119
|
+
'reasoning.sourceSettings': '设置固定',
|
|
120
|
+
'config.title': 'Coding 运行时',
|
|
121
|
+
'config.hint': '保存后立即校验;后续每次阶段判定与子代理派发都会使用新值。',
|
|
122
|
+
'config.mode': '默认模式',
|
|
123
|
+
'config.modeHint': '新建 Coding 会话的初始模式;自动模式在需求分析阶段选择工作流。',
|
|
124
|
+
'config.implementModel': '实现 worker 模型',
|
|
125
|
+
'config.implementModelHint': '必填 provider/model 路由,不会继承主代理模型。',
|
|
126
|
+
'config.plannerModel': '规划 worker 模型(pro)',
|
|
127
|
+
'config.plannerModelHint': 'pro 规划 worker 的必填 provider/model 路由;只做规划,不改文件。',
|
|
128
|
+
'config.verifyModel': '验证 worker 模型',
|
|
129
|
+
'config.verifyModelHint': '只读验证 worker 的必填 provider/model 路由。',
|
|
130
|
+
'config.language': '会话语言',
|
|
131
|
+
'config.languageHint': '自动模式先跟随 DSH 界面语言,再跟随宿主环境语言;插件只带中文和英文。',
|
|
132
|
+
'config.languageAuto': '自动(跟随 DSH)',
|
|
133
|
+
'config.reasoning': '推理等级',
|
|
134
|
+
'config.reasoningHint': '自动会按每轮请求分类;low/high/max 固定所有轮次。聊天框选择 effort 或 coding_reasoning 只在自动时生效。',
|
|
135
|
+
'config.reasoningAuto': '自动(推荐)',
|
|
136
|
+
'config.verification': '验证门禁',
|
|
137
|
+
'config.verificationHint': '验证阶段运行这些检查;交付门禁要求一次通过的结果。',
|
|
138
|
+
'config.commands': '验证命令覆盖',
|
|
139
|
+
'config.commandsHint': '按 kind 或 kind:scope 指定;需在插件包配置中修改。',
|
|
140
|
+
'config.save': '保存',
|
|
141
|
+
'config.saving': '保存中…',
|
|
142
|
+
'config.saved': '已保存。',
|
|
143
|
+
'config.saveFailed': '配置被拒绝,请检查取值与 Host 授权。',
|
|
144
|
+
'config.invalidRoute': '请填写 provider/model,例如 deepseek-account/deepseek-flash。',
|
|
145
|
+
'config.readOnly': '当前部署的设置是只读的。',
|
|
146
|
+
'config.loading': '正在加载配置…',
|
|
147
|
+
'config.unavailable': '当前 Host 未为此插件条目提供配置表单。',
|
|
148
|
+
'config.reset': '恢复默认',
|
|
149
|
+
'config.presetWarning': '请保持 Coding 预设全部开启状态,否则本插件无法工作。',
|
|
150
|
+
'config.modelWarning': '请正确勾选子任务智能体模型,如果填写错误或选择错误就用警告色进行提示(禁用保存按钮)。',
|
|
151
|
+
'config.modelsLoading': '正在加载模型列表…',
|
|
152
|
+
'config.modelsUnavailable': '无法加载已配置的模型列表:',
|
|
153
|
+
'config.modelsRetry': '重新加载模型',
|
|
154
|
+
'config.modelPlaceholder': '请选择模型',
|
|
155
|
+
'config.modelMissing': '不在当前模型列表',
|
|
156
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-Turn Coding mode picker.
|
|
3
|
+
*
|
|
4
|
+
* A new Session shows the blank hero before its first Turn. This picker sits in
|
|
5
|
+
* that hero row, next to the composer, so the user can choose auto, consult,
|
|
6
|
+
* review, or codex while writing the first prompt. The choice goes back through
|
|
7
|
+
* the Host as a silent `/coding set <mode>`: the mode applies to the first Turn
|
|
8
|
+
* without starting one. Later switches stay on the per-Turn control card.
|
|
9
|
+
*
|
|
10
|
+
* It reads the durable `dshCodingStage` projection, so the highlighted mode is
|
|
11
|
+
* the same value the card and the stage machine use. It renders nothing outside
|
|
12
|
+
* a Coding session.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-coding/client/mode-picker
|
|
15
|
+
*/
|
|
16
|
+
import { createElement as h, memo, useState } from 'react';
|
|
17
|
+
import { CODING_PROJECTION_KEY } from '../coding-projection.js';
|
|
18
|
+
import { commandRejected } from './command-row.js';
|
|
19
|
+
/** Modes the picker offers, in roster order. */
|
|
20
|
+
const MODES = ['auto', 'consult', 'review', 'codex'];
|
|
21
|
+
/** The command line one pre-Turn choice sends; `set` never starts a Turn. */
|
|
22
|
+
export function pickerCommandFor(mode) {
|
|
23
|
+
return `/coding set ${mode}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The state the picker renders. Pure, so the visible/absent split is testable
|
|
27
|
+
* without a renderer.
|
|
28
|
+
* @param view - current projection value, if the session has one.
|
|
29
|
+
* @returns the selected mode and the offered modes, or null outside a Coding session.
|
|
30
|
+
*/
|
|
31
|
+
export function pickerState(view) {
|
|
32
|
+
if (view === undefined || view.active !== true)
|
|
33
|
+
return null;
|
|
34
|
+
return { mode: MODES.includes(view.mode) ? view.mode : 'auto', modes: MODES };
|
|
35
|
+
}
|
|
36
|
+
/** The first-message mode picker rendered in the blank-session hero. */
|
|
37
|
+
export const CodingModePicker = memo(function CodingModePicker(props) {
|
|
38
|
+
const raw = props.useProjection?.(CODING_PROJECTION_KEY);
|
|
39
|
+
const view = raw === null || typeof raw !== 'object' ? undefined : raw;
|
|
40
|
+
const state = pickerState(view);
|
|
41
|
+
const [busy, setBusy] = useState(null);
|
|
42
|
+
const [failed, setFailed] = useState(false);
|
|
43
|
+
if (state === null)
|
|
44
|
+
return null;
|
|
45
|
+
async function choose(next) {
|
|
46
|
+
if (busy !== null || next === state?.mode)
|
|
47
|
+
return;
|
|
48
|
+
setBusy(next);
|
|
49
|
+
setFailed(false);
|
|
50
|
+
try {
|
|
51
|
+
const result = await props.execute?.(pickerCommandFor(next));
|
|
52
|
+
if (commandRejected(result))
|
|
53
|
+
setFailed(true);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
setFailed(true);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
setBusy(null);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return h('div', {
|
|
63
|
+
className: 'dsh-coding-picker',
|
|
64
|
+
'data-dsh-coding-picker': 'true',
|
|
65
|
+
role: 'group',
|
|
66
|
+
'aria-label': props.t('picker.aria'),
|
|
67
|
+
}, h('span', { className: 'dsh-coding-label' }, props.t('picker.label')), ...state.modes.map(option => h('button', {
|
|
68
|
+
key: option,
|
|
69
|
+
type: 'button',
|
|
70
|
+
className: 'dsh-coding-button',
|
|
71
|
+
disabled: busy !== null,
|
|
72
|
+
'aria-pressed': option === state.mode,
|
|
73
|
+
onClick: () => { void choose(option); },
|
|
74
|
+
}, props.t(`mode.${option}`))), failed
|
|
75
|
+
? h('span', { className: 'dsh-coding-error' }, props.t('card.switchFailed'))
|
|
76
|
+
: null);
|
|
77
|
+
});
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bundle's one stylesheet.
|
|
3
|
+
*
|
|
4
|
+
* Every rule is copied from a DSH component recipe or uses only DSH theme
|
|
5
|
+
* tokens, so the card, the capsule, and the configuration page sit in the
|
|
6
|
+
* conversation with the product's own typography, sizes, and colors:
|
|
7
|
+
*
|
|
8
|
+
* - card chrome: `PlanPreview.module.css` `.card` (bordered `card-fill` surface,
|
|
9
|
+
* `--dsw-radius-lg`, `font: inherit`),
|
|
10
|
+
* - buttons: `PlanPreview.module.css` `.cardOpen` (28px high, 12px/18px,
|
|
11
|
+
* `--dsw-radius-sm`, floating fill) plus the pressed/focus states DSH uses,
|
|
12
|
+
* - text: 12px/18px labels exactly like the shipped status rows,
|
|
13
|
+
* - inputs: `PluginManagerPage.module.css` `.installField input` (40px,
|
|
14
|
+
* `--dsw-radius-md`, `--dsw-alias-border-l4`),
|
|
15
|
+
* - colors: only `--dsw-alias-*` / `--dsw-radius-*` / `--dsw-focus-ring-*`.
|
|
16
|
+
*
|
|
17
|
+
* The module is browser-only and idempotent: one `<style data-plugin-css>`
|
|
18
|
+
* tagged for HMR bookkeeping, replaced if a previous generation left it.
|
|
19
|
+
*
|
|
20
|
+
* @module dsh-coding/client/styles
|
|
21
|
+
*/
|
|
22
|
+
/** Marker the client module system uses to inventory this plugin's styles. */
|
|
23
|
+
export const STYLE_ID = 'dsh-coding/ui.css';
|
|
24
|
+
/** Plugin id recorded on the style tag for HMR ownership. */
|
|
25
|
+
const PLUGIN_ID = 'dsh-coding';
|
|
26
|
+
const CSS = `
|
|
27
|
+
/* Card: the shipped plan-card surface recipe. */
|
|
28
|
+
.dsh-coding-card {
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
gap: 6px;
|
|
33
|
+
margin: 0;
|
|
34
|
+
padding: 8px 10px;
|
|
35
|
+
border: 0.5px solid var(--dsw-alias-border-l1);
|
|
36
|
+
border-radius: var(--dsw-radius-lg);
|
|
37
|
+
background: var(--dsw-alias-card-fill);
|
|
38
|
+
color: var(--dsw-alias-label-primary);
|
|
39
|
+
font: inherit;
|
|
40
|
+
/* One base type for the whole card: the shipped status-row size. Without it
|
|
41
|
+
a color-only utility (verification, separator, history hint) inherits the
|
|
42
|
+
chat body size and the last row mixes two sizes. */
|
|
43
|
+
font-size: 12px;
|
|
44
|
+
line-height: 18px;
|
|
45
|
+
}
|
|
46
|
+
.dsh-coding-row {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
align-items: baseline;
|
|
50
|
+
gap: 6px;
|
|
51
|
+
margin: 0;
|
|
52
|
+
}
|
|
53
|
+
.dsh-coding-label {
|
|
54
|
+
font-size: 12px;
|
|
55
|
+
font-weight: 500;
|
|
56
|
+
line-height: 18px;
|
|
57
|
+
color: var(--dsw-alias-label-primary);
|
|
58
|
+
}
|
|
59
|
+
.dsh-coding-value {
|
|
60
|
+
font-size: 12px;
|
|
61
|
+
line-height: 18px;
|
|
62
|
+
color: var(--dsw-alias-label-secondary);
|
|
63
|
+
}
|
|
64
|
+
.dsh-coding-hint {
|
|
65
|
+
margin: 0;
|
|
66
|
+
font-size: 12px;
|
|
67
|
+
line-height: 18px;
|
|
68
|
+
color: var(--dsw-alias-label-tertiary);
|
|
69
|
+
}
|
|
70
|
+
.dsh-coding-error {
|
|
71
|
+
margin: 0;
|
|
72
|
+
font-size: 12px;
|
|
73
|
+
line-height: 18px;
|
|
74
|
+
color: var(--dsw-alias-state-error-primary);
|
|
75
|
+
}
|
|
76
|
+
.dsh-coding-actions {
|
|
77
|
+
display: flex;
|
|
78
|
+
flex-wrap: wrap;
|
|
79
|
+
gap: 6px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* One coding command receipt: the line, then its own text. */
|
|
83
|
+
.dsh-coding-command {
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
gap: 2px;
|
|
87
|
+
margin: 0;
|
|
88
|
+
font-size: 12px;
|
|
89
|
+
line-height: 18px;
|
|
90
|
+
}
|
|
91
|
+
.dsh-coding-command .dsh-coding-value,
|
|
92
|
+
.dsh-coding-command .dsh-coding-error {
|
|
93
|
+
white-space: pre-wrap;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* First-message mode picker: the same status-row type as the card. */
|
|
97
|
+
.dsh-coding-picker {
|
|
98
|
+
display: flex;
|
|
99
|
+
flex-wrap: wrap;
|
|
100
|
+
align-items: center;
|
|
101
|
+
gap: 6px;
|
|
102
|
+
font-size: 12px;
|
|
103
|
+
line-height: 18px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* Button: the shipped secondary-button recipe. */
|
|
107
|
+
.dsh-coding-button {
|
|
108
|
+
box-sizing: border-box;
|
|
109
|
+
height: 28px;
|
|
110
|
+
padding: 4px 8px;
|
|
111
|
+
border: 0.5px solid var(--dsw-alias-border-l3);
|
|
112
|
+
border-radius: var(--dsw-radius-sm);
|
|
113
|
+
background: var(--dsw-alias-button-floating-fill);
|
|
114
|
+
color: var(--dsw-alias-label-secondary);
|
|
115
|
+
font: inherit;
|
|
116
|
+
font-size: 12px;
|
|
117
|
+
line-height: 18px;
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
transition: background-color 0.12s, color 0.12s;
|
|
120
|
+
}
|
|
121
|
+
@media (hover: hover) {
|
|
122
|
+
.dsh-coding-button:hover:not(:disabled) {
|
|
123
|
+
color: var(--dsw-alias-label-primary);
|
|
124
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
.dsh-coding-button[aria-pressed="true"] {
|
|
128
|
+
border-color: var(--dsw-alias-state-business-primary);
|
|
129
|
+
background: var(--dsw-alias-state-business-tertiary);
|
|
130
|
+
color: var(--dsw-alias-state-business-primary);
|
|
131
|
+
}
|
|
132
|
+
.dsh-coding-button:focus-visible {
|
|
133
|
+
outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
|
|
134
|
+
outline-offset: 2px;
|
|
135
|
+
}
|
|
136
|
+
.dsh-coding-button:disabled {
|
|
137
|
+
opacity: 0.6;
|
|
138
|
+
cursor: default;
|
|
139
|
+
}
|
|
140
|
+
/* The page's primary action: one step up from the card's compact button. */
|
|
141
|
+
.dsh-coding-button-lg {
|
|
142
|
+
height: 40px;
|
|
143
|
+
padding: 8px 20px;
|
|
144
|
+
border-radius: var(--dsw-radius-md);
|
|
145
|
+
font-size: 14px;
|
|
146
|
+
line-height: 20px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Stage path: plain text at the shipped caption size, never a chip. */
|
|
150
|
+
.dsh-coding-stage {
|
|
151
|
+
font-size: 12px;
|
|
152
|
+
line-height: 18px;
|
|
153
|
+
color: var(--dsw-alias-label-tertiary);
|
|
154
|
+
}
|
|
155
|
+
.dsh-coding-stage[data-current="true"] {
|
|
156
|
+
color: var(--dsw-alias-label-primary);
|
|
157
|
+
font-weight: 500;
|
|
158
|
+
}
|
|
159
|
+
.dsh-coding-stage[data-done="true"] {
|
|
160
|
+
color: var(--dsw-alias-label-secondary);
|
|
161
|
+
}
|
|
162
|
+
.dsh-coding-arrow {
|
|
163
|
+
font-size: 12px;
|
|
164
|
+
line-height: 18px;
|
|
165
|
+
color: var(--dsw-alias-label-caption);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Capsule: one status line in the transcript, same type as the rows around it. */
|
|
169
|
+
.dsh-coding-capsule {
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-wrap: wrap;
|
|
172
|
+
align-items: baseline;
|
|
173
|
+
gap: 6px;
|
|
174
|
+
padding: 2px 0;
|
|
175
|
+
font: inherit;
|
|
176
|
+
font-size: 12px;
|
|
177
|
+
line-height: 18px;
|
|
178
|
+
color: var(--dsw-alias-label-secondary);
|
|
179
|
+
}
|
|
180
|
+
.dsh-coding-capsule .dsh-coding-stage,
|
|
181
|
+
.dsh-coding-capsule .dsh-coding-arrow,
|
|
182
|
+
.dsh-coding-capsule .dsh-coding-muted,
|
|
183
|
+
.dsh-coding-capsule .dsh-coding-faint,
|
|
184
|
+
.dsh-coding-capsule .dsh-coding-success,
|
|
185
|
+
.dsh-coding-capsule .dsh-coding-warn {
|
|
186
|
+
font-size: inherit;
|
|
187
|
+
line-height: inherit;
|
|
188
|
+
}
|
|
189
|
+
/* Color utilities also state the type role, so a bare span never inherits a
|
|
190
|
+
different size from its container. */
|
|
191
|
+
.dsh-coding-muted,
|
|
192
|
+
.dsh-coding-faint,
|
|
193
|
+
.dsh-coding-success,
|
|
194
|
+
.dsh-coding-warn {
|
|
195
|
+
font-size: 12px;
|
|
196
|
+
line-height: 18px;
|
|
197
|
+
}
|
|
198
|
+
.dsh-coding-muted { color: var(--dsw-alias-label-secondary); }
|
|
199
|
+
.dsh-coding-faint { color: var(--dsw-alias-label-tertiary); }
|
|
200
|
+
/* The raw success token is a saturated green-500; at 12px on the card it reads
|
|
201
|
+
too bright. Mixing in the theme's own label color keeps it green while giving
|
|
202
|
+
light themes a deeper shade and dark themes a slightly lighter one. */
|
|
203
|
+
.dsh-coding-success {
|
|
204
|
+
color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 72%, var(--dsw-alias-label-primary));
|
|
205
|
+
}
|
|
206
|
+
.dsh-coding-warn { color: var(--dsw-alias-state-warn-primary); }
|
|
207
|
+
|
|
208
|
+
/* Configuration page: shipped field and control recipes. */
|
|
209
|
+
.dsh-coding-form {
|
|
210
|
+
display: flex;
|
|
211
|
+
flex-direction: column;
|
|
212
|
+
gap: 16px;
|
|
213
|
+
padding: 4px 0;
|
|
214
|
+
font: inherit;
|
|
215
|
+
}
|
|
216
|
+
.dsh-coding-field {
|
|
217
|
+
display: flex;
|
|
218
|
+
flex-direction: column;
|
|
219
|
+
gap: 6px;
|
|
220
|
+
}
|
|
221
|
+
.dsh-coding-field > label {
|
|
222
|
+
font-size: 13px;
|
|
223
|
+
line-height: 20px;
|
|
224
|
+
color: var(--dsw-alias-label-primary);
|
|
225
|
+
}
|
|
226
|
+
.dsh-coding-field > .dsh-coding-hint {
|
|
227
|
+
font-size: 12px;
|
|
228
|
+
line-height: 18px;
|
|
229
|
+
}
|
|
230
|
+
.dsh-coding-input {
|
|
231
|
+
box-sizing: border-box;
|
|
232
|
+
width: 100%;
|
|
233
|
+
height: 40px;
|
|
234
|
+
padding: 0 14px;
|
|
235
|
+
border: 0.5px solid var(--dsw-alias-border-l4);
|
|
236
|
+
border-radius: var(--dsw-radius-md);
|
|
237
|
+
outline: none;
|
|
238
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
239
|
+
font: inherit;
|
|
240
|
+
font-size: 13px;
|
|
241
|
+
color: var(--dsw-alias-label-primary);
|
|
242
|
+
}
|
|
243
|
+
.dsh-coding-input:focus {
|
|
244
|
+
border-color: var(--dsw-alias-state-business-primary);
|
|
245
|
+
box-shadow: inset 0 0 0 0.5px var(--dsw-alias-state-business-primary);
|
|
246
|
+
}
|
|
247
|
+
.dsh-coding-input-warn {
|
|
248
|
+
border-color: var(--dsw-alias-state-warn-primary);
|
|
249
|
+
box-shadow: inset 0 0 0 0.5px var(--dsw-alias-state-warn-primary);
|
|
250
|
+
}
|
|
251
|
+
.dsh-coding-notice { margin: 0; font-size: 12px; line-height: 18px; }
|
|
252
|
+
.dsh-coding-notice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
253
|
+
.dsh-coding-mono {
|
|
254
|
+
font-family: var(--ds-font-family-code);
|
|
255
|
+
font-size: 12px;
|
|
256
|
+
line-height: 18px;
|
|
257
|
+
color: var(--dsw-alias-label-secondary);
|
|
258
|
+
white-space: pre-wrap;
|
|
259
|
+
}
|
|
260
|
+
.dsh-coding-footer {
|
|
261
|
+
display: flex;
|
|
262
|
+
flex-wrap: wrap;
|
|
263
|
+
align-items: center;
|
|
264
|
+
gap: 10px;
|
|
265
|
+
}
|
|
266
|
+
`;
|
|
267
|
+
/**
|
|
268
|
+
* Install the bundle stylesheet once per client generation.
|
|
269
|
+
* @returns disposer removing the style tag this call created.
|
|
270
|
+
*/
|
|
271
|
+
export function installStyles() {
|
|
272
|
+
if (typeof document === 'undefined')
|
|
273
|
+
return () => { };
|
|
274
|
+
// A previous generation (HMR) may have left its own tag; replace it so the
|
|
275
|
+
// running page always carries this build's rules.
|
|
276
|
+
document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_ID)}]`)?.remove();
|
|
277
|
+
const tag = document.createElement('style');
|
|
278
|
+
tag.dataset.plugin = PLUGIN_ID;
|
|
279
|
+
tag.dataset.pluginCss = STYLE_ID;
|
|
280
|
+
tag.textContent = CSS;
|
|
281
|
+
document.head.append(tag);
|
|
282
|
+
return () => { tag.remove(); };
|
|
283
|
+
}
|