dsh-oc-tui 0.1.4 → 0.2.0-pre.13
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 +179 -28
- package/bin/apply-update.cjs +187 -0
- package/bin/mcp-sse-bridge.mjs +499 -0
- package/cordis.patch.yml +46 -32
- package/docs//347/224/250/346/210/267/346/211/213/345/206/214.md +560 -424
- package/dsh-plugin.json +65 -65
- package/lib/caps.js +83 -0
- package/lib/i18n.js +283 -0
- package/lib/image.js +326 -0
- package/lib/index.js +980 -185
- package/lib/locales/ar.js +561 -0
- package/lib/locales/de.js +530 -0
- package/lib/locales/en.js +548 -0
- package/lib/locales/es.js +530 -0
- package/lib/locales/fr.js +530 -0
- package/lib/locales/id.js +532 -0
- package/lib/locales/it.js +530 -0
- package/lib/locales/ja.js +530 -0
- package/lib/locales/ko.js +530 -0
- package/lib/locales/nl.js +530 -0
- package/lib/locales/pl.js +544 -0
- package/lib/locales/pt-BR.js +530 -0
- package/lib/locales/ru.js +544 -0
- package/lib/locales/tr.js +530 -0
- package/lib/locales/vi.js +532 -0
- package/lib/locales/zh-CN.js +531 -0
- package/lib/locales/zh-TW.js +531 -0
- package/lib/markdown.js +560 -297
- package/lib/mcp-skill.js +93 -0
- package/lib/mcp.js +838 -0
- package/lib/mermaid-ascii.js +138 -0
- package/lib/mermaid.js +137 -0
- package/lib/rewind.js +15 -14
- package/lib/splash-opencode.js +108 -0
- package/lib/startup.js +16 -10
- package/lib/term.js +242 -10
- package/lib/ui.js +1265 -406
- package/lib/updates.js +1028 -697
- package/lib/util.js +85 -27
- package/lib/web-settings.js +846 -454
- package/package.json +145 -100
- package/skills/mcp-import/SKILL.md +216 -0
package/lib/index.js
CHANGED
|
@@ -3,18 +3,23 @@
|
|
|
3
3
|
// routes human input back via followup/steer.
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
5
|
import { dirname, isAbsolute, join, parse, resolve } from 'node:path'
|
|
6
|
-
import { readFile, readdir, rm } from 'node:fs/promises'
|
|
6
|
+
import { readFile, readdir, rm, stat } from 'node:fs/promises'
|
|
7
7
|
import Schema from '@deepseek-ai/schemastery'
|
|
8
8
|
import { contentHasImage, createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
9
9
|
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
10
10
|
import { parseCommand } from '@deepseek-ai/dsh-commands'
|
|
11
11
|
import { Terminal } from './term.js'
|
|
12
12
|
import { App, noteFromContext, cursorAtVisual } from './ui.js'
|
|
13
|
+
import { probeCapabilities } from './caps.js'
|
|
14
|
+
import { renderImage, sha16 } from './image.js'
|
|
15
|
+
import { createMermaidRenderer } from './mermaid.js'
|
|
13
16
|
import { SessionMetrics, mergeSessionStats } from './metrics.js'
|
|
14
17
|
import { InterruptState } from './interrupt.js'
|
|
15
|
-
import { SETTINGS_MENU, installWebSettingSchemas, loadModelSettings, loadProviderModels, loadWebSettings, saveWebSetting } from './web-settings.js'
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
+
import { SETTINGS_MENU, applyLocalePreference, buildMcpFormItems, describeLocale, installWebSettingSchemas, loadMcpSettings, loadModelSettings, loadProviderModels, loadWebSettings, readTuiSetting, saveWebSetting } from './web-settings.js'
|
|
19
|
+
import { McpManager, collectServers, createToolProbe, draftFromEntry, emptyDraft, pathConfigPath, removeServer, saveDraft, userConfigPath, validateDraft } from './mcp.js'
|
|
20
|
+
import { registerMcpSkill } from './mcp-skill.js'
|
|
21
|
+
import { contentImages, contentText, decodeDataUrl, detectImageMediaType, formatError, localImagePath, timeString, userContentBlocks } from './util.js'
|
|
22
|
+
import { DSH_PACKAGE, TUI_PACKAGE, buildVersionItems, cachedTarballVersions, clearStagedInstall, detectDshInstall, detectDshLocks, dshManifestPath, dshProcessArgs, dshShimPath, formatDownloadProgress, installMarkerPath, loadUpdateView, registryInfo, restartPlan, spawnApplyUpdater, stageInstall, tarballCachePath, tuiInstallIsLocal, tuiInstalledManifestPath, tuiInstalledVersion, updateStatus } from './updates.js'
|
|
18
23
|
import {
|
|
19
24
|
backupRootFor,
|
|
20
25
|
canRestoreFiles,
|
|
@@ -34,6 +39,7 @@ import { notificationLevel, approvalOutcome, copyTextOptions, deadlineDelay, toT
|
|
|
34
39
|
// profile start, so importing that module here would make the TUI fail to load
|
|
35
40
|
// wherever the optional peer is absent.
|
|
36
41
|
import { TUI_OWNED_COMMANDS, COMMAND_DESCRIPTIONS } from './std/command-list.js'
|
|
42
|
+
import { getLocale, resolveLocale, setLocale, t, tn } from './i18n.js'
|
|
37
43
|
|
|
38
44
|
const ESC_DOUBLE_MS = 800
|
|
39
45
|
// The outcome of a modal wait whose request deadline passed. A Symbol on
|
|
@@ -48,10 +54,10 @@ const TUI_EXCLUSIVE_COMMANDS = new Set(['rewind'])
|
|
|
48
54
|
// The conversation-only restore is first so the default Enter never touches the
|
|
49
55
|
// working tree: undoing file writes is destructive and opt-in.
|
|
50
56
|
const REWIND_RESTORE_OPTIONS = [
|
|
51
|
-
{ id: 'conversation', label
|
|
52
|
-
{ id: 'both', label
|
|
53
|
-
{ id: 'code', label
|
|
54
|
-
{ id: 'cancel', label
|
|
57
|
+
{ id: 'conversation', get label() { return t('rewind.option.conversation') } },
|
|
58
|
+
{ id: 'both', get label() { return t('rewind.option.both') } },
|
|
59
|
+
{ id: 'code', get label() { return t('rewind.option.code') } },
|
|
60
|
+
{ id: 'cancel', get label() { return t('rewind.option.cancel') } },
|
|
55
61
|
]
|
|
56
62
|
|
|
57
63
|
// Remove one persisted session by deleting its own directory under the harness
|
|
@@ -117,16 +123,55 @@ export const name = 'dsh-oc-tui'
|
|
|
117
123
|
|
|
118
124
|
export const inject = ['agents', 'commands', 'sessionPersistence', 'tuiStartup']
|
|
119
125
|
|
|
126
|
+
// dsh 0.2.0 derives the settings page from per-entry Config forms instead of a
|
|
127
|
+
// namespace registry, so a field the TUI owns has to be declared here to have a
|
|
128
|
+
// row at all — and `volatile()` is what lets the host push an edit into the
|
|
129
|
+
// running config reference without remounting the plugin (a language switch
|
|
130
|
+
// that remounted the TUI would lose the session view). An older schemastery
|
|
131
|
+
// without `volatile` keeps working: the field is then plain, which is exactly
|
|
132
|
+
// what a 0.1.x host expects.
|
|
133
|
+
const volatileField = (schema) => (typeof schema?.volatile === 'function' ? schema.volatile() : schema)
|
|
134
|
+
|
|
120
135
|
export const Config = Schema.object({
|
|
121
136
|
sidebar: Schema.boolean().default(true),
|
|
122
137
|
showReasoning: Schema.boolean().default(true),
|
|
123
138
|
defaultModel: Schema.string(),
|
|
124
139
|
defaultProvider: Schema.string(),
|
|
140
|
+
// The settings this plugin owns, mirrored onto its Config so a 0.2.0 host
|
|
141
|
+
// (whose settings page is derived from Config forms, not a namespace
|
|
142
|
+
// registry) shows a row for each and can push an edit into the running
|
|
143
|
+
// reference without remounting the TUI. lib/web-settings.js owns the
|
|
144
|
+
// legacy-namespace names and the read/write resolution; these field names are
|
|
145
|
+
// the contract between the two.
|
|
146
|
+
locale: volatileField(Schema.string().default('system')),
|
|
147
|
+
busyEnter: volatileField(Schema.union(['queue', 'steer']).default('queue')),
|
|
148
|
+
graphics: volatileField(Schema.union(['auto', 'off']).default('auto')),
|
|
149
|
+
imageFallback: volatileField(Schema.union(['halfblock', 'chip']).default('halfblock')),
|
|
150
|
+
imageMaxRows: volatileField(Schema.union(['10', '15', '20', '28', '40']).default('20')),
|
|
151
|
+
mermaid: volatileField(Schema.union(['auto', 'local', 'off']).default('auto')),
|
|
152
|
+
startupCheck: volatileField(Schema.union(['on', 'off']).default('on')),
|
|
125
153
|
})
|
|
126
154
|
|
|
127
155
|
export function apply(ctx, config) {
|
|
128
156
|
const startup = ctx.tuiStartup ?? {}
|
|
129
157
|
installWebSettingSchemas(ctx)
|
|
158
|
+
// Resolve the interface language before anything paints. The stored
|
|
159
|
+
// preference wins; `system` falls through to the OS language variables, and
|
|
160
|
+
// an unrecognised language lands on English rather than an empty screen.
|
|
161
|
+
applyLocalePreference(ctx, config)
|
|
162
|
+
|
|
163
|
+
// There is deliberately no "this TUI is too old for this dsh" version gate
|
|
164
|
+
// here, even though one was asked for: it cannot fire. The check can only read
|
|
165
|
+
// the version of the copy that is running — there is no older build to
|
|
166
|
+
// compare it against — so a gate written into 0.1.5 compares 0.1.5 against
|
|
167
|
+
// 0.1.5. The incompatible combination the rename created is a pre-0.1.5
|
|
168
|
+
// bundle naming the old roster provider, and dsh itself reports that row at
|
|
169
|
+
// boot ("Plugin @deepseek-ai/dsh-agent-presets@… is incompatible with dsh
|
|
170
|
+
// 0.2.0-rc.1 …"); this bundle mounts no roster at all (see cordis.patch.yml),
|
|
171
|
+
// so the report never appears. Users arrive at the upgrade from dsh's own
|
|
172
|
+
// message and from the release notes, which is the only surface a build too
|
|
173
|
+
// old to know about the problem can be reached on.
|
|
174
|
+
|
|
130
175
|
const term = new Terminal()
|
|
131
176
|
if (!term.isTTY()) {
|
|
132
177
|
console.error('dsh-oc-tui: stdin/stdout are not a TTY; run in an interactive terminal (dsh --profile tui)')
|
|
@@ -138,6 +183,183 @@ export function apply(ctx, config) {
|
|
|
138
183
|
const app = new App(term)
|
|
139
184
|
// Session history is available from Settings -> Manage sessions.
|
|
140
185
|
app.sidebarVisible = false
|
|
186
|
+
// The status rail's footer names the running builds: this plugin's own
|
|
187
|
+
// manifest and the dsh install on PATH (both reads are millisecond-scale,
|
|
188
|
+
// no spawn).
|
|
189
|
+
app.versions = { tui: tuiInstalledVersion() ?? '', dsh: detectDshInstall().version ?? '' }
|
|
190
|
+
|
|
191
|
+
// ---- image pipeline -----------------------------------------------------
|
|
192
|
+
// The view model only decides WHEN an image is needed; byte resolution and
|
|
193
|
+
// rendering happen here. Paste-path sources carry their bytes already, event
|
|
194
|
+
// and replay sources carry stored attachment refs, markdown sources carry
|
|
195
|
+
// remote URLs. A protocol render also registers its payload with the
|
|
196
|
+
// terminal so paint() can transmit/place it.
|
|
197
|
+
app.onImageRequest = (src) => { void resolveImage(src) }
|
|
198
|
+
async function resolveImage(src) {
|
|
199
|
+
try {
|
|
200
|
+
const bytes = await resolveImageBytes(src)
|
|
201
|
+
// cropCells arrives on a source the view re-requested because the
|
|
202
|
+
// transcript scrolled past the top of the image: the variant carries only
|
|
203
|
+
// the rows still on screen.
|
|
204
|
+
const render = await renderImage({ bytes }, { ...app.imageRenderOptions(), cropCells: src.cropCells ?? 0 })
|
|
205
|
+
if (render.protocol === 'error') {
|
|
206
|
+
app.setImageResult(src.key, { state: 'error', error: render.error })
|
|
207
|
+
} else {
|
|
208
|
+
if (render.payload) term._imagePayloads.set(src.key, render.payload)
|
|
209
|
+
app.setImageResult(src.key, {
|
|
210
|
+
state: 'done',
|
|
211
|
+
protocol: render.protocol,
|
|
212
|
+
cellsW: render.cellsW,
|
|
213
|
+
cellsH: render.cellsH,
|
|
214
|
+
segLines: render.segLines,
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
} catch (error) {
|
|
218
|
+
app.setImageResult(src.key, { state: 'error', error: formatError(error) })
|
|
219
|
+
}
|
|
220
|
+
paintSoon()
|
|
221
|
+
}
|
|
222
|
+
async function resolveImageBytes(src) {
|
|
223
|
+
if (src.kind === 'bytes') {
|
|
224
|
+
if (src.bytes) return src.bytes
|
|
225
|
+
throw new Error('image bytes unavailable')
|
|
226
|
+
}
|
|
227
|
+
if (src.kind === 'ref') {
|
|
228
|
+
const attachments = ctx.get('attachments')
|
|
229
|
+
if (typeof attachments?.readImage === 'function') {
|
|
230
|
+
const stored = await attachments.readImage(src.ref)
|
|
231
|
+
const data = stored?.data ?? stored?.bytes
|
|
232
|
+
if (data) return Buffer.from(data)
|
|
233
|
+
}
|
|
234
|
+
const hostPath = typeof attachments?.imageHostPath === 'function' ? attachments.imageHostPath(src.ref) : undefined
|
|
235
|
+
if (hostPath) return readFile(hostPath)
|
|
236
|
+
throw new Error('attachment store unavailable')
|
|
237
|
+
}
|
|
238
|
+
if (src.kind === 'url') {
|
|
239
|
+
const res = await fetch(src.url, { signal: AbortSignal.timeout(10000) })
|
|
240
|
+
if (!res.ok) throw new Error('fetch failed: ' + res.status)
|
|
241
|
+
const buf = Buffer.from(await res.arrayBuffer())
|
|
242
|
+
if (buf.length > 20 * 1024 * 1024) throw new Error('image larger than 20MB')
|
|
243
|
+
return buf
|
|
244
|
+
}
|
|
245
|
+
throw new Error('unknown image source')
|
|
246
|
+
}
|
|
247
|
+
// Terminal capability probing runs in parallel with the first frame (the
|
|
248
|
+
// probes are escape sequences the client terminal answers, so they work
|
|
249
|
+
// unchanged over SSH). When they land, the render protocol upgrades and the
|
|
250
|
+
// screen repaints; until then images render as ANSI halfblocks.
|
|
251
|
+
let probedProtocol = 'halfblock'
|
|
252
|
+
function graphicsSettings() {
|
|
253
|
+
const read = (field, fallback) => readTuiSetting(ctx, config, 'tui-graphics', field) ?? fallback
|
|
254
|
+
return {
|
|
255
|
+
graphics: read('graphics', 'auto'),
|
|
256
|
+
imageFallback: read('imageFallback', 'halfblock'),
|
|
257
|
+
imageMaxRows: read('imageMaxRows', '20'),
|
|
258
|
+
mermaid: read('mermaid', 'auto'),
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function applyGraphicsSettings() {
|
|
262
|
+
const g = graphicsSettings()
|
|
263
|
+
const off = g.graphics === 'off'
|
|
264
|
+
app.graphicsProtocol = off ? 'halfblock' : probedProtocol
|
|
265
|
+
// Chip fallback: on a no-protocol terminal the user can keep text chips
|
|
266
|
+
// instead of halfblock pixels; `graphics: off` suppresses pixels on any
|
|
267
|
+
// terminal.
|
|
268
|
+
app.imagePixels = off ? g.imageFallback === 'halfblock' : (probedProtocol !== 'halfblock' || g.imageFallback !== 'chip')
|
|
269
|
+
const rows = Number(g.imageMaxRows ?? '20')
|
|
270
|
+
app.imageMaxRows = Number.isFinite(rows) ? Math.min(40, Math.max(4, rows)) : 20
|
|
271
|
+
// `off` turns a diagram back into its source: no native art, no provider
|
|
272
|
+
// chain, nothing leaves the machine.
|
|
273
|
+
app.mermaidMode = g.mermaid ?? 'auto'
|
|
274
|
+
}
|
|
275
|
+
applyGraphicsSettings()
|
|
276
|
+
probeCapabilities(term).then((caps) => {
|
|
277
|
+
// Hand the probe result to the terminal itself: paint() gates every
|
|
278
|
+
// graphics-protocol emission on term.caps, so without this the App would
|
|
279
|
+
// reserve image rows the terminal never paints (blank bubbles).
|
|
280
|
+
term.caps = caps
|
|
281
|
+
probedProtocol = caps.kitty ? 'kitty' : caps.iterm2 ? 'iterm2' : caps.sixel ? 'sixel' : 'halfblock'
|
|
282
|
+
app.imageCellW = caps.cellW
|
|
283
|
+
app.imageCellH = caps.cellH
|
|
284
|
+
applyGraphicsSettings()
|
|
285
|
+
paintSoon()
|
|
286
|
+
}).catch(() => { /* probing is best-effort; halfblock stays */ })
|
|
287
|
+
// Mermaid diagrams the engine cannot draw natively fall back to the provider
|
|
288
|
+
// chain (local mmdc, then the mermaid.ink network service per the mermaid
|
|
289
|
+
// setting) into the same image pipeline; a chain failure keeps the
|
|
290
|
+
// highlighted source.
|
|
291
|
+
const renderMermaid = createMermaidRenderer({ mode: () => graphicsSettings().mermaid ?? 'auto' })
|
|
292
|
+
app.onMermaidRequest = (code, key) => { void resolveMermaid(code, key) }
|
|
293
|
+
async function resolveMermaid(code, key) {
|
|
294
|
+
try {
|
|
295
|
+
const opts = app.imageRenderOptions()
|
|
296
|
+
const rendered = await renderMermaid(code, { pxWidth: Math.min(1600, opts.maxCellsW * opts.cellW) })
|
|
297
|
+
if (!rendered) {
|
|
298
|
+
app.setMermaidResult(key, { state: 'fallback' })
|
|
299
|
+
} else {
|
|
300
|
+
const imageKey = key.replace('mermaid:', 'mermaid-img:')
|
|
301
|
+
const render = await renderImage({ bytes: rendered.bytes }, app.imageRenderOptions())
|
|
302
|
+
if (render.protocol === 'error') {
|
|
303
|
+
app.setMermaidResult(key, { state: 'fallback' })
|
|
304
|
+
} else {
|
|
305
|
+
if (render.payload) term._imagePayloads.set(imageKey, render.payload)
|
|
306
|
+
app.setImageResult(imageKey, {
|
|
307
|
+
state: 'done',
|
|
308
|
+
protocol: render.protocol,
|
|
309
|
+
cellsW: render.cellsW,
|
|
310
|
+
cellsH: render.cellsH,
|
|
311
|
+
segLines: render.segLines,
|
|
312
|
+
})
|
|
313
|
+
app.setMermaidResult(key, { state: 'done', imageKey })
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} catch {
|
|
317
|
+
app.setMermaidResult(key, { state: 'fallback' })
|
|
318
|
+
}
|
|
319
|
+
paintSoon()
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ---- MCP -----------------------------------------------------------------
|
|
323
|
+
// MCP servers are mounted per session: each configured server becomes one
|
|
324
|
+
// `@deepseek-ai/dsh-mcp-client` plugin instance on the live agent's scope,
|
|
325
|
+
// which registers its tools as `mcp__<name>__<tool>` on that agent. Nothing
|
|
326
|
+
// here is required for the TUI to run — the host client, the scope key and
|
|
327
|
+
// the tool registry are all optional, and every one of them failing leaves a
|
|
328
|
+
// row on the MCP settings page instead of a broken session.
|
|
329
|
+
//
|
|
330
|
+
// The server list lives in `mcp.json` files (user scope + any ancestor
|
|
331
|
+
// project scope), not in DSH settings: the host's 0.2.0 settings service only
|
|
332
|
+
// writes fields of a composed plugin entry, and per-directory scope needs
|
|
333
|
+
// files anyway. `lib/mcp.js` owns that format.
|
|
334
|
+
let mcpProbe = null
|
|
335
|
+
const mcpManager = new McpManager({
|
|
336
|
+
probe: (agentCtx, serverName) => (mcpProbe ? mcpProbe(agentCtx, serverName) : null),
|
|
337
|
+
})
|
|
338
|
+
createToolProbe().then((probe) => { mcpProbe = probe }).catch(() => { mcpProbe = null })
|
|
339
|
+
|
|
340
|
+
// Read the files for one working directory and hand the result to the
|
|
341
|
+
// manager. A read failure is an empty list, never an exception into the
|
|
342
|
+
// session; the page reports the unreadable file on its own row.
|
|
343
|
+
async function loadMcpConfigured(cwd) {
|
|
344
|
+
try {
|
|
345
|
+
const collected = await collectServers(cwd)
|
|
346
|
+
mcpManager.setConfigured(collected.servers)
|
|
347
|
+
return collected
|
|
348
|
+
} catch (error) {
|
|
349
|
+
mcpManager.setConfigured([])
|
|
350
|
+
return { servers: [], files: [], error }
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// The bundled mcp-import skill teaches a model to add servers by writing
|
|
355
|
+
// exactly these files. Best effort: a host without the skill service still
|
|
356
|
+
// gets the settings page, and the model simply does not see the skill.
|
|
357
|
+
try {
|
|
358
|
+
const registered = registerMcpSkill(ctx)
|
|
359
|
+
if (!registered.ok) ctx.logger?.debug?.('dsh-oc-tui: mcp-import skill not registered: ' + registered.reason)
|
|
360
|
+
} catch (error) {
|
|
361
|
+
try { ctx.logger?.warn?.('dsh-oc-tui: mcp-import skill registration failed: ' + formatError(error)) } catch { /* logging is optional */ }
|
|
362
|
+
}
|
|
141
363
|
|
|
142
364
|
// Live session state.
|
|
143
365
|
let handle = null
|
|
@@ -147,7 +369,11 @@ export function apply(ctx, config) {
|
|
|
147
369
|
let lifecycleVersion = 0
|
|
148
370
|
let lastUserText = null
|
|
149
371
|
let lastUserTime = 0
|
|
372
|
+
let lastUserHadImages = false
|
|
150
373
|
let lastEscAt = 0
|
|
374
|
+
// Optimistic submits carry `[Image N]` markers that the durable event drops
|
|
375
|
+
// (replaced by image blocks); both sides compare marker-stripped.
|
|
376
|
+
const stripImageMarkers = (s) => String(s ?? '').replace(/\[Image \d+\]/g, '').trim()
|
|
151
377
|
const metrics = new SessionMetrics()
|
|
152
378
|
const interrupt = new InterruptState()
|
|
153
379
|
let showReasoning = config.showReasoning !== false
|
|
@@ -212,6 +438,31 @@ export function apply(ctx, config) {
|
|
|
212
438
|
paint()
|
|
213
439
|
}
|
|
214
440
|
term.on('resize', () => paintNow())
|
|
441
|
+
// The language is a live setting. A host that writes it through its own
|
|
442
|
+
// settings surface — or a profile patch edited by hand while the TUI runs —
|
|
443
|
+
// pushes the new value into the volatile Config reference instead of
|
|
444
|
+
// remounting this plugin, so the running interface has to re-read it and
|
|
445
|
+
// repaint itself from the new catalog. A committed row takes the direct path
|
|
446
|
+
// in commitSetting below; this covers every other writer.
|
|
447
|
+
//
|
|
448
|
+
// While a locale commit of our own is in flight the host announces the same
|
|
449
|
+
// change mid-write. Rebuilding from that announcement would race the refresh
|
|
450
|
+
// commitSetting is about to do, and would rebuild it with the index of the
|
|
451
|
+
// option list that is still open rather than the row it was opened from — the
|
|
452
|
+
// highlight would land a few rows down. commitSetting already repaints the
|
|
453
|
+
// page in the new language, so the announcement has nothing to add here.
|
|
454
|
+
let localeCommitInFlight = false
|
|
455
|
+
ctx.on('loader/volatile-update', () => {
|
|
456
|
+
const before = getLocale()
|
|
457
|
+
applyLocalePreference(ctx, config)
|
|
458
|
+
if (getLocale() === before) return
|
|
459
|
+
if (localeCommitInFlight) return
|
|
460
|
+
if (app.overlay === 'settings') void refreshSettings(app.settingsSelection)
|
|
461
|
+
paint()
|
|
462
|
+
})
|
|
463
|
+
// The mermaid engine loads on the first ```mermaid fence and arrives after
|
|
464
|
+
// the paint that showed its placeholder; a late art asks for a repaint here.
|
|
465
|
+
app._needsRepaint = paintSoon
|
|
215
466
|
paint()
|
|
216
467
|
|
|
217
468
|
// ---- session stats (web stats strip / token usage port) -----------------
|
|
@@ -243,6 +494,9 @@ export function apply(ctx, config) {
|
|
|
243
494
|
pressure: values?.contextPressure,
|
|
244
495
|
breakdown: values?.contextBreakdown,
|
|
245
496
|
})
|
|
497
|
+
// The status rail's GOAL section reads the `goal` projection the harness's
|
|
498
|
+
// dsh-goal row registers; a profile without it simply leaves null here.
|
|
499
|
+
app.setGoal(values?.goal ?? null)
|
|
246
500
|
}
|
|
247
501
|
{
|
|
248
502
|
const projections = ctx.get('sessionProjections')
|
|
@@ -250,19 +504,68 @@ export function apply(ctx, config) {
|
|
|
250
504
|
projections.onChanged((session, key) => {
|
|
251
505
|
if (!currentAgent || session.id !== currentAgent.session.id) return
|
|
252
506
|
if (key !== 'sessionStats' && key !== 'tokenUsage'
|
|
253
|
-
&& key !== 'contextPressure' && key !== 'contextBreakdown'
|
|
507
|
+
&& key !== 'contextPressure' && key !== 'contextBreakdown'
|
|
508
|
+
&& key !== 'goal') return
|
|
254
509
|
refreshSessionStats()
|
|
255
510
|
paintSoon()
|
|
256
511
|
})
|
|
257
512
|
}
|
|
258
513
|
}
|
|
259
514
|
|
|
515
|
+
// ---- status rail: subagent activity --------------------------------------
|
|
516
|
+
// The rail's SUBAGENTS section lists the delegation tree rooted at the open
|
|
517
|
+
// session (`ctx.subagents.listDescendants`). The service is optional — a
|
|
518
|
+
// composition without dsh-subagent leaves the section empty. Lifecycle edges
|
|
519
|
+
// are published scoped to the delegating parent, so the listeners register
|
|
520
|
+
// globally and just trigger a re-list rooted at the current session.
|
|
521
|
+
let subagentListVersion = 0
|
|
522
|
+
async function refreshSubagents() {
|
|
523
|
+
const version = ++subagentListVersion
|
|
524
|
+
const agent = currentAgent
|
|
525
|
+
const subagents = agent ? ctx.get('subagents') : null
|
|
526
|
+
let rows = []
|
|
527
|
+
if (agent && subagents && typeof subagents.listDescendants === 'function') {
|
|
528
|
+
try {
|
|
529
|
+
const listed = await subagents.listDescendants(String(agent.session.id))
|
|
530
|
+
// The list resolves after an async gap; a session switch in between
|
|
531
|
+
// must not describe the old session in the new one's rail.
|
|
532
|
+
if (version !== subagentListVersion || !currentAgent
|
|
533
|
+
|| String(currentAgent.session.id) !== String(agent.session.id)) return
|
|
534
|
+
rows = Array.isArray(listed) ? listed : []
|
|
535
|
+
} catch {
|
|
536
|
+
// Listing is best-effort; an unavailable store shows an empty section
|
|
537
|
+
// rather than taking the frame down.
|
|
538
|
+
rows = []
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (version !== subagentListVersion) return
|
|
542
|
+
app.setSubagents(rows)
|
|
543
|
+
paintSoon()
|
|
544
|
+
}
|
|
545
|
+
ctx.on('subagent/start', () => { void refreshSubagents() }, { global: true })
|
|
546
|
+
ctx.on('subagent/end', () => { void refreshSubagents() }, { global: true })
|
|
547
|
+
|
|
260
548
|
// Drive the activity animations (flowing spinners for thinking / running
|
|
261
549
|
// tools like read/write). Paints are cheap (bounded render), and the loop
|
|
262
550
|
// only repaints while something is actually animating.
|
|
263
551
|
const animationTimer = setInterval(() => {
|
|
264
552
|
if (term.started && app.hasAnimation()) paint()
|
|
265
553
|
}, 80)
|
|
554
|
+
// While the MCP page is open, re-read the config files and the live
|
|
555
|
+
// connections: a mount that has not settled yet shows its outcome, a server
|
|
556
|
+
// whose tool list changed after connecting is corrected, and a server the
|
|
557
|
+
// model imported through the bundled skill (which writes the same files)
|
|
558
|
+
// appears and connects without restarting the session.
|
|
559
|
+
const mcpPollTimer = setInterval(() => {
|
|
560
|
+
// Re-rendering means openSettings, which puts the overlay back up: the
|
|
561
|
+
// poll has to stop the moment the dialog is dismissed, or Esc never sticks.
|
|
562
|
+
if (app.overlay !== 'settings') return
|
|
563
|
+
if (settingsView.kind !== 'mcp' && settingsView.kind !== 'mcp-form') return
|
|
564
|
+
if (app.settingsEditing !== null || app.settingsConfirm) return
|
|
565
|
+
mcpManager.refresh()
|
|
566
|
+
if (settingsView.kind === 'mcp') void pollMcpList()
|
|
567
|
+
else renderMcpForm(mcpFormDraft, mcpFormIsEdit, app.settingsSelection)
|
|
568
|
+
}, 500)
|
|
266
569
|
|
|
267
570
|
// ---- session lifecycle -------------------------------------------------
|
|
268
571
|
|
|
@@ -276,6 +579,7 @@ export function apply(ctx, config) {
|
|
|
276
579
|
const old = handle
|
|
277
580
|
handle = null
|
|
278
581
|
currentAgent = null
|
|
582
|
+
void mcpManager.detachAgent()
|
|
279
583
|
try { await old.dispose() } catch { /* already settling */ }
|
|
280
584
|
}
|
|
281
585
|
if (version !== lifecycleVersion) return
|
|
@@ -345,6 +649,7 @@ export function apply(ctx, config) {
|
|
|
345
649
|
const old = handle
|
|
346
650
|
handle = null
|
|
347
651
|
currentAgent = null
|
|
652
|
+
void mcpManager.detachAgent()
|
|
348
653
|
try { await old.dispose() } catch { /* already settling */ }
|
|
349
654
|
}
|
|
350
655
|
if (version !== lifecycleVersion) return false
|
|
@@ -354,7 +659,7 @@ export function apply(ctx, config) {
|
|
|
354
659
|
app.inputImages = []
|
|
355
660
|
app.sidebarSelection = -1
|
|
356
661
|
app.resetView()
|
|
357
|
-
app.setSession({ title: '
|
|
662
|
+
app.setSession({ title: '' })
|
|
358
663
|
// Resolve the model selection: explicit preference (flag/config//model)
|
|
359
664
|
// wins, then the deployment's agent-default-model service (settings).
|
|
360
665
|
const agentOptions = resolveAgentOptions()
|
|
@@ -375,6 +680,13 @@ export function apply(ctx, config) {
|
|
|
375
680
|
}
|
|
376
681
|
handle = openedHandle
|
|
377
682
|
currentAgent = openedHandle.agent
|
|
683
|
+
// The configured MCP servers connect to this agent's scope: a server that
|
|
684
|
+
// fails to connect is recorded on its MCP page row, and the session keeps
|
|
685
|
+
// running without it. The list is read first (it lives in files), then the
|
|
686
|
+
// mount starts — attachAgent is not awaited, so a slow server cannot hold
|
|
687
|
+
// up the first frame.
|
|
688
|
+
const mcpCwd = currentAgent.session?.header?.cwd ?? process.cwd()
|
|
689
|
+
void loadMcpConfigured(mcpCwd).then(() => mcpManager.attachAgent(currentAgent.ctx, mcpCwd))
|
|
378
690
|
app.setSession({
|
|
379
691
|
id: String(currentAgent.session.id),
|
|
380
692
|
model: currentAgent.options.model ?? '',
|
|
@@ -384,7 +696,8 @@ export function apply(ctx, config) {
|
|
|
384
696
|
void loadEffortSlider()
|
|
385
697
|
replay(currentAgent.session)
|
|
386
698
|
refreshSessionStats()
|
|
387
|
-
|
|
699
|
+
void refreshSubagents()
|
|
700
|
+
app.addSystem(t(resume ? 'session.resumed' : 'session.started', { id: currentAgent.session.id }) + ' · ' + process.cwd(), 'info')
|
|
388
701
|
app.setStatus('idle')
|
|
389
702
|
void refreshRecentSessions()
|
|
390
703
|
paint()
|
|
@@ -393,7 +706,7 @@ export function apply(ctx, config) {
|
|
|
393
706
|
if (version !== lifecycleVersion) return false
|
|
394
707
|
handle = null
|
|
395
708
|
currentAgent = null
|
|
396
|
-
app.addSystem('
|
|
709
|
+
app.addSystem(t('session.openFailed', { error: formatError(error) }), 'error')
|
|
397
710
|
app.setStatus('idle')
|
|
398
711
|
paint()
|
|
399
712
|
return false
|
|
@@ -447,7 +760,7 @@ export function apply(ctx, config) {
|
|
|
447
760
|
// by a preceding splice, so it is labeled rather than treated as a
|
|
448
761
|
// fresh turn.
|
|
449
762
|
const steering = app.consumeClaimed(event.data.id)
|
|
450
|
-
if (src?.kind === 'user') app.addUser(text, { steering })
|
|
763
|
+
if (src?.kind === 'user') app.addUser(text, { steering, images: contentImages(event.data.content) })
|
|
451
764
|
else addContextMessage(src, text)
|
|
452
765
|
break
|
|
453
766
|
}
|
|
@@ -467,6 +780,8 @@ export function apply(ctx, config) {
|
|
|
467
780
|
asst.time = event.time
|
|
468
781
|
asst.rev = (asst.rev ?? 0) + 1
|
|
469
782
|
if (asst.reasoning && asst.thinkingCollapsed === undefined) asst.thinkingCollapsed = true
|
|
783
|
+
const asstImages = contentImages(msg.content)
|
|
784
|
+
if (asstImages.length > 0) asst.images = asstImages
|
|
470
785
|
for (const block of msg.content) {
|
|
471
786
|
if (block.type === 'tool-call') {
|
|
472
787
|
app.startTool({ callId: block.id, name: block.name, args: block.arguments })
|
|
@@ -479,7 +794,11 @@ export function apply(ctx, config) {
|
|
|
479
794
|
const text = contentText(msg.content)
|
|
480
795
|
const isError = event.data.error !== undefined
|
|
481
796
|
|| msg.content[0]?.isError === true
|
|
482
|
-
app.updateTool(msg.source.callId, {
|
|
797
|
+
app.updateTool(msg.source.callId, {
|
|
798
|
+
status: isError ? 'error' : 'ok',
|
|
799
|
+
result: text,
|
|
800
|
+
...(contentImages(msg.content).length > 0 ? { images: contentImages(msg.content) } : {}),
|
|
801
|
+
})
|
|
483
802
|
break
|
|
484
803
|
}
|
|
485
804
|
case 'todo/write': {
|
|
@@ -537,6 +856,7 @@ export function apply(ctx, config) {
|
|
|
537
856
|
case 'user/message': {
|
|
538
857
|
const src = event.data.source
|
|
539
858
|
const text = contentText(event.data.content)
|
|
859
|
+
const images = contentImages(event.data.content)
|
|
540
860
|
// `user/message` is the only admission log the loop writes, so the
|
|
541
861
|
// preceding inbox splice is what distinguishes a steered turn from a
|
|
542
862
|
// fresh one. Consuming the classification also keeps the id from
|
|
@@ -544,10 +864,18 @@ export function apply(ctx, config) {
|
|
|
544
864
|
const steering = app.consumeClaimed(event.data.id)
|
|
545
865
|
if (src?.kind === 'user') {
|
|
546
866
|
const now = Date.now()
|
|
547
|
-
|
|
548
|
-
|
|
867
|
+
// The optimistic submit shows the turn with `[Image N]` markers,
|
|
868
|
+
// while the event's content has the markers replaced by image
|
|
869
|
+
// blocks — compare marker-stripped text or every image paste adds a
|
|
870
|
+
// second block. Images the optimistic path could not have shown (a
|
|
871
|
+
// turn queued from another surface) attach to that block instead.
|
|
872
|
+
if (!steering && stripImageMarkers(text) === lastUserText && now - lastUserTime < 8000) {
|
|
873
|
+
if (images.length > 0 && !lastUserHadImages) app.attachImagesToLastUser(images)
|
|
874
|
+
return
|
|
875
|
+
}
|
|
876
|
+
lastUserText = stripImageMarkers(text)
|
|
549
877
|
lastUserTime = now
|
|
550
|
-
app.addUser(text, { steering })
|
|
878
|
+
app.addUser(text, { steering, images })
|
|
551
879
|
} else {
|
|
552
880
|
addContextMessage(src, text)
|
|
553
881
|
}
|
|
@@ -589,6 +917,8 @@ export function apply(ctx, config) {
|
|
|
589
917
|
asst.time = event.time
|
|
590
918
|
asst.rev = (asst.rev ?? 0) + 1
|
|
591
919
|
if (asst.reasoning && asst.thinkingCollapsed === undefined) asst.thinkingCollapsed = true
|
|
920
|
+
const asstImages = contentImages(msg.content)
|
|
921
|
+
if (asstImages.length > 0) asst.images = asstImages
|
|
592
922
|
for (const block of msg.content) {
|
|
593
923
|
if (block.type === 'tool-call') {
|
|
594
924
|
app.startTool({ callId: block.id, name: block.name, args: block.arguments })
|
|
@@ -606,7 +936,11 @@ export function apply(ctx, config) {
|
|
|
606
936
|
const msg = event.data.message
|
|
607
937
|
const text = contentText(msg.content)
|
|
608
938
|
const isError = event.data.error !== undefined || msg.content[0]?.isError === true
|
|
609
|
-
app.updateTool(msg.source.callId, {
|
|
939
|
+
app.updateTool(msg.source.callId, {
|
|
940
|
+
status: isError ? 'error' : 'ok',
|
|
941
|
+
result: text,
|
|
942
|
+
...(contentImages(msg.content).length > 0 ? { images: contentImages(msg.content) } : {}),
|
|
943
|
+
})
|
|
610
944
|
break
|
|
611
945
|
}
|
|
612
946
|
case 'todo/write': {
|
|
@@ -635,7 +969,7 @@ export function apply(ctx, config) {
|
|
|
635
969
|
})
|
|
636
970
|
ctx.on('agent/error', ({ agent, error }) => {
|
|
637
971
|
if (!currentAgent || agent.id !== currentAgent.id) return
|
|
638
|
-
app.addSystem('error
|
|
972
|
+
app.addSystem(t('session.error', { error: formatError(error) }), 'error')
|
|
639
973
|
app.setStatus('idle')
|
|
640
974
|
paint()
|
|
641
975
|
})
|
|
@@ -694,14 +1028,14 @@ export function apply(ctx, config) {
|
|
|
694
1028
|
}
|
|
695
1029
|
|
|
696
1030
|
async function forkAndSwitch({ cut, restoreFiles, label }) {
|
|
697
|
-
if (!currentAgent) throw new Error('
|
|
698
|
-
if (app.status === 'running') throw new Error(
|
|
1031
|
+
if (!currentAgent) throw new Error(t('session.startFirst'))
|
|
1032
|
+
if (app.status === 'running') throw new Error(t('session.interruptFirst'))
|
|
699
1033
|
const version = ++lifecycleVersion
|
|
700
1034
|
const parent = currentAgent
|
|
701
1035
|
const events = sessionEvents(parent.session)
|
|
702
1036
|
const cwd = parent.session.header.cwd ?? process.cwd()
|
|
703
1037
|
const parentId = parent.session.id
|
|
704
|
-
let fileNote = '
|
|
1038
|
+
let fileNote = t('session.conversationOnly')
|
|
705
1039
|
let fileLevel = 'info'
|
|
706
1040
|
if (restoreFiles) {
|
|
707
1041
|
const { result } = await restoreFilesAfter(parent, cut)
|
|
@@ -749,9 +1083,10 @@ export function apply(ctx, config) {
|
|
|
749
1083
|
replay(currentAgent.session)
|
|
750
1084
|
showWorkspace(currentAgent.session)
|
|
751
1085
|
refreshSessionStats()
|
|
1086
|
+
void refreshSubagents()
|
|
752
1087
|
void loadEffortSlider()
|
|
753
|
-
app.addSystem(
|
|
754
|
-
+ (inheritedPending > 0 ? '
|
|
1088
|
+
app.addSystem(t('session.forkSummary', { label, parent: parentId, files: fileNote })
|
|
1089
|
+
+ (inheritedPending > 0 ? t('session.forkDropped', { count: inheritedPending }) : ''), fileLevel)
|
|
755
1090
|
app.setStatus('idle')
|
|
756
1091
|
app.closeRewind()
|
|
757
1092
|
void refreshRecentSessions()
|
|
@@ -761,12 +1096,12 @@ export function apply(ctx, config) {
|
|
|
761
1096
|
|
|
762
1097
|
function openRewindOverlay() {
|
|
763
1098
|
if (!currentAgent) {
|
|
764
|
-
app.showToast('
|
|
1099
|
+
app.showToast(t('session.startFirst'), 'warn')
|
|
765
1100
|
paint()
|
|
766
1101
|
return
|
|
767
1102
|
}
|
|
768
1103
|
if (app.status === 'running') {
|
|
769
|
-
app.showToast('
|
|
1104
|
+
app.showToast(t('session.interruptFirstEsc'), 'warn')
|
|
770
1105
|
paint()
|
|
771
1106
|
return
|
|
772
1107
|
}
|
|
@@ -777,7 +1112,7 @@ export function apply(ctx, config) {
|
|
|
777
1112
|
time: point.time,
|
|
778
1113
|
label: point.n + '. ' + point.label,
|
|
779
1114
|
}))
|
|
780
|
-
items.push({ n: items.length + 1, seq: null, label: '
|
|
1115
|
+
items.push({ n: items.length + 1, seq: null, label: t('rewind.current'), current: true })
|
|
781
1116
|
// Land on the most recent real point: the trailing "(current)" row is a
|
|
782
1117
|
// no-op, so defaulting to it would make Enter-Enter do nothing.
|
|
783
1118
|
app.openRewind({ items, restoreOptions: REWIND_RESTORE_OPTIONS, defaultIndex: Math.max(0, points.length - 1) })
|
|
@@ -785,7 +1120,7 @@ export function apply(ctx, config) {
|
|
|
785
1120
|
}
|
|
786
1121
|
|
|
787
1122
|
async function applyRewindChoice(item, mode) {
|
|
788
|
-
if (!currentAgent) throw new Error('
|
|
1123
|
+
if (!currentAgent) throw new Error(t('session.startFirst'))
|
|
789
1124
|
if (item?.current || item?.seq == null) {
|
|
790
1125
|
app.closeRewind()
|
|
791
1126
|
paint()
|
|
@@ -795,14 +1130,14 @@ export function apply(ctx, config) {
|
|
|
795
1130
|
if (mode === 'code') {
|
|
796
1131
|
const { result } = await restoreFilesAfter(currentAgent, rewindCut(events, item.seq))
|
|
797
1132
|
app.closeRewind()
|
|
798
|
-
app.addSystem('files
|
|
1133
|
+
app.addSystem(t('session.files', { summary: formatRestore(result) }), result.ok === false ? 'warn' : 'info')
|
|
799
1134
|
paint()
|
|
800
1135
|
return
|
|
801
1136
|
}
|
|
802
1137
|
await forkAndSwitch({
|
|
803
1138
|
cut: rewindCut(events, item.seq),
|
|
804
1139
|
restoreFiles: mode !== 'conversation',
|
|
805
|
-
label: '
|
|
1140
|
+
label: t('session.rewindLabel', { n: item.n }),
|
|
806
1141
|
})
|
|
807
1142
|
}
|
|
808
1143
|
|
|
@@ -950,7 +1285,7 @@ export function apply(ctx, config) {
|
|
|
950
1285
|
}
|
|
951
1286
|
void loadEffortSlider().then(() => {
|
|
952
1287
|
if (!app.effortSlider) {
|
|
953
|
-
app.showToast('
|
|
1288
|
+
app.showToast(t('session.noReasoningLevels'), 'warn')
|
|
954
1289
|
paint()
|
|
955
1290
|
return
|
|
956
1291
|
}
|
|
@@ -990,15 +1325,15 @@ export function apply(ctx, config) {
|
|
|
990
1325
|
async function commitEffort(id) {
|
|
991
1326
|
const settings = ctx.get('settings')
|
|
992
1327
|
if (!settings) {
|
|
993
|
-
app.showToast('
|
|
1328
|
+
app.showToast(t('session.settingsUnavailable'), 'warn')
|
|
994
1329
|
paint()
|
|
995
1330
|
return
|
|
996
1331
|
}
|
|
997
1332
|
try {
|
|
998
1333
|
await settings.update('agent-default-model', { reasoningEffort: id })
|
|
999
|
-
app.showToast('
|
|
1334
|
+
app.showToast(t('model.reasoning') + ': ' + id, 'info')
|
|
1000
1335
|
} catch (error) {
|
|
1001
|
-
app.showToast('settings
|
|
1336
|
+
app.showToast(t('settings.error', { error: formatError(error) }), 'error')
|
|
1002
1337
|
await loadEffortSlider()
|
|
1003
1338
|
}
|
|
1004
1339
|
paint()
|
|
@@ -1350,16 +1685,16 @@ export function apply(ctx, config) {
|
|
|
1350
1685
|
const draft = activeDraft()
|
|
1351
1686
|
const custom = String(draft.custom ?? '').trim()
|
|
1352
1687
|
if (draft.selected.length === 0 && custom === '') {
|
|
1353
|
-
return emptyMessage ?? '
|
|
1688
|
+
return emptyMessage ?? t('session.answerRequired')
|
|
1354
1689
|
}
|
|
1355
1690
|
// Only a text field's answer is the custom string: a select field's free
|
|
1356
1691
|
// text is dropped by the adapter, so bounds do not apply to it.
|
|
1357
1692
|
if (question?.kind === 'text' && custom !== '') {
|
|
1358
1693
|
if (question.minLength !== undefined && custom.length < question.minLength) {
|
|
1359
|
-
return '
|
|
1694
|
+
return t('session.minChars', { count: question.minLength })
|
|
1360
1695
|
}
|
|
1361
1696
|
if (question.maxLength !== undefined && custom.length > question.maxLength) {
|
|
1362
|
-
return '
|
|
1697
|
+
return t('session.maxChars', { count: question.maxLength })
|
|
1363
1698
|
}
|
|
1364
1699
|
}
|
|
1365
1700
|
return null
|
|
@@ -1412,7 +1747,7 @@ export function apply(ctx, config) {
|
|
|
1412
1747
|
const question = activeQuestion()
|
|
1413
1748
|
const optionCount = question.options.length
|
|
1414
1749
|
if (pending.customMode) {
|
|
1415
|
-
const error = questionAnswerError('
|
|
1750
|
+
const error = questionAnswerError(t('session.typeAnswer'))
|
|
1416
1751
|
if (error !== null) {
|
|
1417
1752
|
questionError(error)
|
|
1418
1753
|
return
|
|
@@ -1645,13 +1980,16 @@ export function apply(ctx, config) {
|
|
|
1645
1980
|
|
|
1646
1981
|
function attachImage(data, mediaType) {
|
|
1647
1982
|
const n = app.inputImages.length + 1
|
|
1648
|
-
|
|
1983
|
+
// `data` stays on the entry so the optimistic transcript block can render
|
|
1984
|
+
// the image without a read-back; it lives only until submit clears the
|
|
1985
|
+
// composer.
|
|
1986
|
+
const entry = { status: 'pending', ref: null, mediaType, label: 'Image ' + n, promise: null, data }
|
|
1649
1987
|
app.inputImages.push(entry)
|
|
1650
1988
|
insert('[Image ' + n + ']')
|
|
1651
1989
|
const attachments = ctx.get('attachments')
|
|
1652
1990
|
if (!attachments || typeof attachments.saveImage !== 'function') {
|
|
1653
1991
|
entry.status = 'error'
|
|
1654
|
-
app.showToast('
|
|
1992
|
+
app.showToast(t('session.attachmentsUnavailable'), 'warn')
|
|
1655
1993
|
paint()
|
|
1656
1994
|
return
|
|
1657
1995
|
}
|
|
@@ -1662,7 +2000,7 @@ export function apply(ctx, config) {
|
|
|
1662
2000
|
entry.status = 'ready'
|
|
1663
2001
|
} catch (error) {
|
|
1664
2002
|
entry.status = 'error'
|
|
1665
|
-
app.showToast('
|
|
2003
|
+
app.showToast(t('session.imageAttachFailed', { error: formatError(error) }), 'error')
|
|
1666
2004
|
}
|
|
1667
2005
|
paint()
|
|
1668
2006
|
return entry.ref
|
|
@@ -1701,6 +2039,10 @@ export function apply(ctx, config) {
|
|
|
1701
2039
|
} else if (app.overlay === 'settings') {
|
|
1702
2040
|
// Scroll the settings content window instead of moving focus
|
|
1703
2041
|
app.scrollSettingsWindow(direction * 3)
|
|
2042
|
+
} else if (app.hitTest(mouse.x, mouse.y, ['rail'])) {
|
|
2043
|
+
// The pointer rests over the status rail: scroll the rail, not the
|
|
2044
|
+
// transcript beneath it.
|
|
2045
|
+
app.scrollRail(direction * 3)
|
|
1704
2046
|
} else {
|
|
1705
2047
|
app.scrollTranscript(-direction * 3)
|
|
1706
2048
|
}
|
|
@@ -1726,7 +2068,7 @@ export function apply(ctx, config) {
|
|
|
1726
2068
|
if (text) {
|
|
1727
2069
|
app.textSelection.text = text
|
|
1728
2070
|
term.copyToClipboard(text)
|
|
1729
|
-
app.showToast('copied
|
|
2071
|
+
app.showToast(tn('session.copied', text.split('\n').length, { count: text.split('\n').length }))
|
|
1730
2072
|
paint()
|
|
1731
2073
|
}
|
|
1732
2074
|
return
|
|
@@ -1801,6 +2143,12 @@ export function apply(ctx, config) {
|
|
|
1801
2143
|
paint()
|
|
1802
2144
|
return
|
|
1803
2145
|
}
|
|
2146
|
+
// Tool activity cards expand to the full result on click.
|
|
2147
|
+
if (region?.kind === 'tool') {
|
|
2148
|
+
app.toggleTool(region.toolBlock)
|
|
2149
|
+
paint()
|
|
2150
|
+
return
|
|
2151
|
+
}
|
|
1804
2152
|
// Left-drag inside the transcript selects text (right-click copies it).
|
|
1805
2153
|
if (region?.kind === 'transcript') {
|
|
1806
2154
|
app.startTextSelection(mouse.x, mouse.y)
|
|
@@ -1859,7 +2207,7 @@ export function apply(ctx, config) {
|
|
|
1859
2207
|
|
|
1860
2208
|
} else if (key.name === 'n' || key.name === 'N' || key.name === 'escape') {
|
|
1861
2209
|
|
|
1862
|
-
app.showToast('
|
|
2210
|
+
app.showToast(t('session.deleteCancelled'))
|
|
1863
2211
|
paint()
|
|
1864
2212
|
}
|
|
1865
2213
|
return
|
|
@@ -1893,17 +2241,17 @@ export function apply(ctx, config) {
|
|
|
1893
2241
|
// contractual.)
|
|
1894
2242
|
const length = state.draft.length
|
|
1895
2243
|
if (length === 0) {
|
|
1896
|
-
state.error = '
|
|
2244
|
+
state.error = t('session.valueRequired')
|
|
1897
2245
|
paint()
|
|
1898
2246
|
return
|
|
1899
2247
|
}
|
|
1900
2248
|
if (state.minLength !== undefined && length < state.minLength) {
|
|
1901
|
-
state.error = '
|
|
2249
|
+
state.error = t('session.minChars', { count: state.minLength })
|
|
1902
2250
|
paint()
|
|
1903
2251
|
return
|
|
1904
2252
|
}
|
|
1905
2253
|
if (state.maxLength !== undefined && length > state.maxLength) {
|
|
1906
|
-
state.error = '
|
|
2254
|
+
state.error = t('session.maxChars', { count: state.maxLength })
|
|
1907
2255
|
paint()
|
|
1908
2256
|
return
|
|
1909
2257
|
}
|
|
@@ -1974,6 +2322,13 @@ export function apply(ctx, config) {
|
|
|
1974
2322
|
case 'home': app.inputCursor = 0; paint(); break
|
|
1975
2323
|
case 'end': app.inputCursor = app.inputText.length; paint(); break
|
|
1976
2324
|
case 'up': {
|
|
2325
|
+
// Shift+Up scrolls the status rail when it is on screen; without the
|
|
2326
|
+
// rail (or without Shift) the arrow keeps its composer meanings.
|
|
2327
|
+
if (key.shift && app._layout().railW > 0) {
|
|
2328
|
+
app.scrollRail(-3)
|
|
2329
|
+
paint()
|
|
2330
|
+
break
|
|
2331
|
+
}
|
|
1977
2332
|
// Multi-line input: Up moves the caret one visual row up (keeping the
|
|
1978
2333
|
// column), and only the first row falls back to input history. The
|
|
1979
2334
|
// width comes from the renderer's own layout so caret math matches
|
|
@@ -1988,6 +2343,11 @@ export function apply(ctx, config) {
|
|
|
1988
2343
|
break
|
|
1989
2344
|
}
|
|
1990
2345
|
case 'down': {
|
|
2346
|
+
if (key.shift && app._layout().railW > 0) {
|
|
2347
|
+
app.scrollRail(3)
|
|
2348
|
+
paint()
|
|
2349
|
+
break
|
|
2350
|
+
}
|
|
1991
2351
|
// Down moves the caret one visual row down; only the last row falls
|
|
1992
2352
|
// back to input history.
|
|
1993
2353
|
const layout = app._layout()
|
|
@@ -2020,7 +2380,7 @@ export function apply(ctx, config) {
|
|
|
2020
2380
|
} else if (app.status === 'running') {
|
|
2021
2381
|
lastEscAt = 0
|
|
2022
2382
|
if (currentAgent) currentAgent.cancel({ kind: 'user' })
|
|
2023
|
-
app.showToast('
|
|
2383
|
+
app.showToast(t('session.interruptRequested'))
|
|
2024
2384
|
paint()
|
|
2025
2385
|
} else if (app.inputText.length > 0 || app.inputImages.length > 0) {
|
|
2026
2386
|
lastEscAt = 0
|
|
@@ -2045,17 +2405,20 @@ export function apply(ctx, config) {
|
|
|
2045
2405
|
}
|
|
2046
2406
|
})
|
|
2047
2407
|
|
|
2048
|
-
|
|
2049
|
-
//
|
|
2050
|
-
//
|
|
2051
|
-
// menu-less sub-views rendered in the same overlay.
|
|
2408
|
+
// Settings views: 'main', 'model', 'update' and 'mcp' are the left-menu tabs
|
|
2409
|
+
// of the settings dialog; 'choice', 'sessions', 'mcp-form' and
|
|
2410
|
+
// 'provider-models' are menu-less sub-views rendered in the same overlay.
|
|
2052
2411
|
let settingsView = { kind: 'main' }
|
|
2053
2412
|
// The last selection per menu tab, restored when Tab switches back.
|
|
2054
|
-
const menuSelections = { main: 0, model: 0, update: 0 }
|
|
2413
|
+
const menuSelections = { main: 0, model: 0, update: 0, mcp: 0 }
|
|
2055
2414
|
let settingsLoadVersion = 0
|
|
2056
2415
|
// The last-loaded update page snapshot (installed versions, registry results,
|
|
2057
2416
|
// dsh entry, active profile) so version pickers and installs can reuse it.
|
|
2058
2417
|
let updateState = null
|
|
2418
|
+
// The in-app download, while one is running: { pkg, version, label,
|
|
2419
|
+
// controller, progressRow }. Null otherwise; Esc aborts the controller.
|
|
2420
|
+
let updateDownload = null
|
|
2421
|
+
let sharedSettings = null
|
|
2059
2422
|
|
|
2060
2423
|
function showSettings(loaded, selection = 0) {
|
|
2061
2424
|
sharedSettings = loaded.settings
|
|
@@ -2077,9 +2440,9 @@ export function apply(ctx, config) {
|
|
|
2077
2440
|
// The registry checks can take seconds; show the Update tab at once so
|
|
2078
2441
|
// the check/switch entries are immediately visible while it fetches.
|
|
2079
2442
|
app.settingsBusy = true
|
|
2080
|
-
app.openSettings([{ kind: 'update-loading', label: '
|
|
2081
|
-
title: '
|
|
2082
|
-
subtitle: 'fetching
|
|
2443
|
+
app.openSettings([{ kind: 'update-loading', label: t('update.checking'), value: '', disabled: true }], {
|
|
2444
|
+
title: t('update.title'),
|
|
2445
|
+
subtitle: t('update.fetching'),
|
|
2083
2446
|
menu: SETTINGS_MENU,
|
|
2084
2447
|
menuIndex: 2,
|
|
2085
2448
|
})
|
|
@@ -2090,12 +2453,13 @@ export function apply(ctx, config) {
|
|
|
2090
2453
|
try {
|
|
2091
2454
|
if (tab === 'update') loaded = await loadUpdateView(ctx)
|
|
2092
2455
|
else if (tab === 'model') loaded = await loadModelSettings(ctx)
|
|
2456
|
+
else if (tab === 'mcp') loaded = await loadMcpSettings(ctx, mcpManager, { cwd: mcpCwd() })
|
|
2093
2457
|
else loaded = await loadWebSettings(ctx)
|
|
2094
2458
|
} catch (error) {
|
|
2095
2459
|
if (tab === 'update') app.settingsBusy = false
|
|
2096
2460
|
if (version !== settingsLoadVersion) return
|
|
2097
2461
|
sharedSettings = null
|
|
2098
|
-
app.openSettings([{ label: '
|
|
2462
|
+
app.openSettings([{ label: t('settings.dshSettings'), value: formatError(error), disabled: true }])
|
|
2099
2463
|
paint()
|
|
2100
2464
|
return
|
|
2101
2465
|
}
|
|
@@ -2103,6 +2467,12 @@ export function apply(ctx, config) {
|
|
|
2103
2467
|
if (version !== settingsLoadVersion || settingsView.kind !== tab) return
|
|
2104
2468
|
if (tab === 'update') updateState = loaded.state ?? null
|
|
2105
2469
|
showSettings(loaded, selection ?? menuSelections[tab] ?? 0)
|
|
2470
|
+
// The MCP tab's change poll compares file mtimes against this baseline, so
|
|
2471
|
+
// opening the page has to record the state it just rendered.
|
|
2472
|
+
if (tab === 'mcp') {
|
|
2473
|
+
mcpFiles = loaded.files ?? []
|
|
2474
|
+
mcpFileSignature = await mcpFilesSignature(mcpFiles)
|
|
2475
|
+
}
|
|
2106
2476
|
paint()
|
|
2107
2477
|
}
|
|
2108
2478
|
|
|
@@ -2112,7 +2482,7 @@ export function apply(ctx, config) {
|
|
|
2112
2482
|
if (!Array.isArray(menu) || menu.length === 0) return
|
|
2113
2483
|
const target = menu[((index % menu.length) + menu.length) % menu.length]
|
|
2114
2484
|
if (!target || settingsView.kind === target.id) return
|
|
2115
|
-
if (settingsView.kind === 'main' || settingsView.kind === 'model' || settingsView.kind === 'update') {
|
|
2485
|
+
if (settingsView.kind === 'main' || settingsView.kind === 'model' || settingsView.kind === 'update' || settingsView.kind === 'mcp') {
|
|
2116
2486
|
menuSelections[settingsView.kind] = app.settingsSelection
|
|
2117
2487
|
}
|
|
2118
2488
|
void openSettingsTab(target.id)
|
|
@@ -2131,9 +2501,9 @@ export function apply(ctx, config) {
|
|
|
2131
2501
|
sessionId: session.id,
|
|
2132
2502
|
disabled: false,
|
|
2133
2503
|
}))
|
|
2134
|
-
app.openSettings(items.length > 0 ? items : [{ kind: 'session-empty', label: '
|
|
2135
|
-
title: '
|
|
2136
|
-
subtitle: '
|
|
2504
|
+
app.openSettings(items.length > 0 ? items : [{ kind: 'session-empty', label: t('session.noSaved'), value: '', disabled: true }], {
|
|
2505
|
+
title: t('session.manageTitle'),
|
|
2506
|
+
subtitle: t('session.manageSubtitle'),
|
|
2137
2507
|
})
|
|
2138
2508
|
app.setSettingsSelection(selection)
|
|
2139
2509
|
paint()
|
|
@@ -2142,9 +2512,9 @@ export function apply(ctx, config) {
|
|
|
2142
2512
|
async function openSessionManager(selection = 0) {
|
|
2143
2513
|
settingsView = { kind: 'sessions' }
|
|
2144
2514
|
// Show loading state immediately while fetching sessions
|
|
2145
|
-
app.openSettings([{ kind: 'session-loading', label: '
|
|
2146
|
-
title: '
|
|
2147
|
-
subtitle: '
|
|
2515
|
+
app.openSettings([{ kind: 'session-loading', label: t('session.loading'), value: '', disabled: true }], {
|
|
2516
|
+
title: t('session.manageTitle'),
|
|
2517
|
+
subtitle: t('session.manageSubtitle'),
|
|
2148
2518
|
})
|
|
2149
2519
|
paint()
|
|
2150
2520
|
// A fresh listing can take seconds (reading every session's title snapshot)
|
|
@@ -2174,10 +2544,10 @@ export function apply(ctx, config) {
|
|
|
2174
2544
|
await currentHandle.dispose()
|
|
2175
2545
|
}
|
|
2176
2546
|
if (!await deleteSessionDirectory(item.sessionId)) {
|
|
2177
|
-
throw new Error('
|
|
2547
|
+
throw new Error(t('session.deleteNotFound'))
|
|
2178
2548
|
}
|
|
2179
2549
|
app.settingsConfirm = null
|
|
2180
|
-
app.showToast('deleted
|
|
2550
|
+
app.showToast(t('session.deleted', { label: item.label }))
|
|
2181
2551
|
if (deletingCurrent) await showTitleScreen()
|
|
2182
2552
|
else await openSessionManager(Math.max(0, app.settingsSelection - 1))
|
|
2183
2553
|
} catch (error) {
|
|
@@ -2185,7 +2555,7 @@ export function apply(ctx, config) {
|
|
|
2185
2555
|
// surface left to show.
|
|
2186
2556
|
if (deletingCurrent && !handle) await showTitleScreen()
|
|
2187
2557
|
app.settingsConfirm = null
|
|
2188
|
-
app.showToast('
|
|
2558
|
+
app.showToast(t('session.deleteFailed', { error: formatError(error) }), 'error')
|
|
2189
2559
|
paint()
|
|
2190
2560
|
}
|
|
2191
2561
|
}
|
|
@@ -2199,14 +2569,14 @@ export function apply(ctx, config) {
|
|
|
2199
2569
|
? settingsView.parentSelection
|
|
2200
2570
|
: app.settingsSelection
|
|
2201
2571
|
settingsView = { kind: 'provider-models', provider: providerId, parentSelection }
|
|
2202
|
-
app.openSettings([{ label: '
|
|
2572
|
+
app.openSettings([{ label: t('model.fetching'), value: '', disabled: true }], { title: t('model.models'), subtitle: t('model.autoFetching') })
|
|
2203
2573
|
paint()
|
|
2204
2574
|
let loaded
|
|
2205
2575
|
try {
|
|
2206
2576
|
loaded = await loadProviderModels(ctx, providerId)
|
|
2207
2577
|
} catch (error) {
|
|
2208
2578
|
if (version !== settingsLoadVersion) return
|
|
2209
|
-
app.showToast('settings
|
|
2579
|
+
app.showToast(t('settings.error', { error: formatError(error) }), 'error')
|
|
2210
2580
|
await openSettingsTab('model', parentSelection)
|
|
2211
2581
|
return
|
|
2212
2582
|
}
|
|
@@ -2220,16 +2590,219 @@ export function apply(ctx, config) {
|
|
|
2220
2590
|
else if (settingsView.kind === 'sessions') await openSessionManager(selection)
|
|
2221
2591
|
else if (settingsView.kind === 'update') await openSettingsTab('update', selection)
|
|
2222
2592
|
else if (settingsView.kind === 'model') await openSettingsTab('model', selection)
|
|
2593
|
+
else if (settingsView.kind === 'mcp') await openSettingsTab('mcp', selection)
|
|
2594
|
+
else if (settingsView.kind === 'mcp-form') renderMcpForm(mcpFormDraft, mcpFormIsEdit, selection)
|
|
2223
2595
|
else await openSettingsTab('main', selection)
|
|
2224
2596
|
}
|
|
2225
2597
|
|
|
2598
|
+
// ---- MCP settings tab ----------------------------------------------------
|
|
2599
|
+
// The config files are re-read for every render, so a server added, edited or
|
|
2600
|
+
// removed by another process — or by the model through the bundled skill
|
|
2601
|
+
// above — shows up without restarting anything.
|
|
2602
|
+
|
|
2603
|
+
let mcpFormDraft = emptyDraft()
|
|
2604
|
+
let mcpFormIsEdit = false
|
|
2605
|
+
// The files the current page was read from and their mtime/size signature:
|
|
2606
|
+
// the poll above compares against it to notice an external write.
|
|
2607
|
+
let mcpFiles = []
|
|
2608
|
+
let mcpFileSignature = ''
|
|
2609
|
+
let mcpPollBusy = false
|
|
2610
|
+
|
|
2611
|
+
// The working directory this session's MCP servers are scoped to. On the
|
|
2612
|
+
// title screen (no live agent) the process directory is the honest stand-in.
|
|
2613
|
+
function mcpCwd() {
|
|
2614
|
+
return currentAgent?.session?.header?.cwd ?? process.cwd()
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
async function mcpFilesSignature(files) {
|
|
2618
|
+
const parts = []
|
|
2619
|
+
for (const file of files) {
|
|
2620
|
+
try {
|
|
2621
|
+
const info = await stat(file.path)
|
|
2622
|
+
parts.push(file.path + ':' + info.mtimeMs + ':' + info.size)
|
|
2623
|
+
} catch {
|
|
2624
|
+
// A missing file is a state of its own ("not created yet"), and it is
|
|
2625
|
+
// exactly the state that changes when a server is first written.
|
|
2626
|
+
parts.push(file.path + ':-')
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
return parts.join('|')
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
// Re-render the MCP list. The selection and scroll offset are carried over:
|
|
2633
|
+
// the connection poll rebuilds these items while the page is open, and a
|
|
2634
|
+
// repaint must never move the row the user is on.
|
|
2635
|
+
async function renderMcpList() {
|
|
2636
|
+
const selection = app.settingsSelection
|
|
2637
|
+
const scroll = app.settingsScrollOffset
|
|
2638
|
+
let loaded
|
|
2639
|
+
try {
|
|
2640
|
+
loaded = await loadMcpSettings(ctx, mcpManager, { cwd: mcpCwd() })
|
|
2641
|
+
} catch (error) {
|
|
2642
|
+
app.showToast(t('session.mcpError', { error: formatError(error) }), 'error')
|
|
2643
|
+
paint()
|
|
2644
|
+
return
|
|
2645
|
+
}
|
|
2646
|
+
// The user can leave the tab while the files are being read.
|
|
2647
|
+
if (settingsView.kind !== 'mcp') return
|
|
2648
|
+
app.openSettings(loaded.items, {
|
|
2649
|
+
title: loaded.title,
|
|
2650
|
+
subtitle: loaded.subtitle,
|
|
2651
|
+
menu: loaded.menu,
|
|
2652
|
+
menuIndex: loaded.menuIndex,
|
|
2653
|
+
})
|
|
2654
|
+
app.setSettingsSelection(Math.min(selection, Math.max(0, app.settingsItems.length - 1)))
|
|
2655
|
+
app.settingsScrollOffset = scroll
|
|
2656
|
+
mcpFiles = loaded.files ?? []
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
// The file-change half of the poll: re-read, and when the on-disk content
|
|
2660
|
+
// changed, remount so a server added from outside this process (the model
|
|
2661
|
+
// writing the config, an editor saving it) actually connects.
|
|
2662
|
+
async function pollMcpList() {
|
|
2663
|
+
if (mcpPollBusy) return
|
|
2664
|
+
mcpPollBusy = true
|
|
2665
|
+
try {
|
|
2666
|
+
const before = mcpFileSignature
|
|
2667
|
+
await renderMcpList()
|
|
2668
|
+
if (settingsView.kind !== 'mcp') return
|
|
2669
|
+
mcpFileSignature = await mcpFilesSignature(mcpFiles)
|
|
2670
|
+
if (mcpFileSignature !== before) {
|
|
2671
|
+
await mcpManager.sync()
|
|
2672
|
+
await renderMcpList()
|
|
2673
|
+
}
|
|
2674
|
+
paint()
|
|
2675
|
+
} catch {
|
|
2676
|
+
// A failed poll is a stale page, never a broken session; the next tick
|
|
2677
|
+
// retries.
|
|
2678
|
+
} finally {
|
|
2679
|
+
mcpPollBusy = false
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
function renderMcpForm(draft, isEdit, selection = app.settingsSelection) {
|
|
2684
|
+
const scroll = app.settingsScrollOffset
|
|
2685
|
+
mcpFormDraft = draft
|
|
2686
|
+
mcpFormIsEdit = isEdit
|
|
2687
|
+
settingsView = { kind: 'mcp-form' }
|
|
2688
|
+
app.openSettings(buildMcpFormItems(draft, { isEdit }), {
|
|
2689
|
+
title: isEdit ? t('mcp.titleEdit') : t('mcp.titleAdd'),
|
|
2690
|
+
subtitle: t('mcp.editSubtitle'),
|
|
2691
|
+
})
|
|
2692
|
+
app.setSettingsSelection(Math.min(selection, Math.max(0, app.settingsItems.length - 1)))
|
|
2693
|
+
app.settingsScrollOffset = scroll
|
|
2694
|
+
paint()
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
// Read the files again and remount, then redraw the page: the shared tail of
|
|
2698
|
+
// every write path (save, remove, scope move).
|
|
2699
|
+
async function reloadMcpAndSync() {
|
|
2700
|
+
const loaded = await loadMcpSettings(ctx, mcpManager, { cwd: mcpCwd() })
|
|
2701
|
+
mcpFiles = loaded.files ?? []
|
|
2702
|
+
await mcpManager.sync()
|
|
2703
|
+
mcpFileSignature = await mcpFilesSignature(mcpFiles)
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
function openMcpForm(entry) {
|
|
2707
|
+
const isEdit = Boolean(entry?.name)
|
|
2708
|
+
// An add starts from the empty draft; `draftFromEntry` renders a stored
|
|
2709
|
+
// record's env/headers back as JSON text and is only meaningful with one.
|
|
2710
|
+
const draft = isEdit ? draftFromEntry(entry) : emptyDraft()
|
|
2711
|
+
// Where the record lives decides the scope rows: an entry read from a
|
|
2712
|
+
// project file opens as path-scoped on that directory (draftFromEntry
|
|
2713
|
+
// already resolved it from the source path).
|
|
2714
|
+
if (isEdit) draft.scope = entry.scope === 'path' ? 'path' : 'user'
|
|
2715
|
+
// Start on the first row that does something. The list's own selection is
|
|
2716
|
+
// meaningless here — the form is a different item list — so inheriting it
|
|
2717
|
+
// would drop the cursor on an arbitrary field.
|
|
2718
|
+
const items = buildMcpFormItems(draft, { isEdit })
|
|
2719
|
+
const start = items.findIndex((item) => item.kind === 'mcp-field' && !item.disabled)
|
|
2720
|
+
renderMcpForm(draft, isEdit, Math.max(0, start))
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
// The file a draft would be written to; '' when a path-scoped draft has no
|
|
2724
|
+
// usable path yet (validation reports that, not this helper).
|
|
2725
|
+
function mcpTargetPath(draft) {
|
|
2726
|
+
if (draft.scope !== 'path') return userConfigPath()
|
|
2727
|
+
const directory = String(draft.path ?? '').trim()
|
|
2728
|
+
return directory === '' ? '' : pathConfigPath(resolve(directory))
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
// Windows paths are case-insensitive, so a scope change has to be recognized
|
|
2732
|
+
// as a move even when only the path's case differs.
|
|
2733
|
+
function samePath(left, right) {
|
|
2734
|
+
return resolve(left).toLowerCase() === resolve(right).toLowerCase()
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
// The inline text edit writes straight into the form draft and only "Save"
|
|
2738
|
+
// touches storage. Switching type or scope changes which rows exist, so the
|
|
2739
|
+
// form is rebuilt around the same cursor position.
|
|
2740
|
+
function commitMcpField(item, value, selection = app.settingsSelection) {
|
|
2741
|
+
const draft = { ...mcpFormDraft }
|
|
2742
|
+
if (item.field === 'enabled') draft.enabled = value !== 'off'
|
|
2743
|
+
else draft[item.field] = value
|
|
2744
|
+
mcpFormDraft = draft
|
|
2745
|
+
renderMcpForm(draft, mcpFormIsEdit, selection)
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
async function saveMcpForm() {
|
|
2749
|
+
const draft = mcpFormDraft
|
|
2750
|
+
const cwd = mcpCwd()
|
|
2751
|
+
// One read serves both the duplicate-name check and the move check; a read
|
|
2752
|
+
// failure only costs the duplicate warning.
|
|
2753
|
+
let collected = { servers: [] }
|
|
2754
|
+
try { collected = await collectServers(cwd) } catch { /* reported on save */ }
|
|
2755
|
+
const existing = collected.servers.filter((entry) => entry.name !== draft.originalName)
|
|
2756
|
+
const result = validateDraft(draft, { existing })
|
|
2757
|
+
if (!result.ok) {
|
|
2758
|
+
app.showToast(t('session.mcpError', { error: result.error }), 'error')
|
|
2759
|
+
paint()
|
|
2760
|
+
return
|
|
2761
|
+
}
|
|
2762
|
+
try {
|
|
2763
|
+
const original = draft.originalName
|
|
2764
|
+
const target = original ? mcpTargetPath(draft) : ''
|
|
2765
|
+
const current = original ? collected.servers.find((entry) => entry.name === original) : null
|
|
2766
|
+
await saveDraft({ cwd, draft })
|
|
2767
|
+
// Changing scope while editing moves the record: the new file has it now,
|
|
2768
|
+
// so the old one is dropped. Writing first means a failed write leaves the
|
|
2769
|
+
// original untouched — and the removal names the old document explicitly,
|
|
2770
|
+
// because resolving by name would now find the copy just written.
|
|
2771
|
+
if (original && current?.sourcePath && target && !samePath(current.sourcePath, target)) {
|
|
2772
|
+
await removeServer({ cwd, name: original, sourcePath: current.sourcePath })
|
|
2773
|
+
}
|
|
2774
|
+
await reloadMcpAndSync()
|
|
2775
|
+
app.showToast(original ? t('mcp.saved') : t('mcp.added'), 'info')
|
|
2776
|
+
await openSettingsTab('mcp', menuSelections.mcp ?? 0)
|
|
2777
|
+
} catch (error) {
|
|
2778
|
+
app.showToast(t('session.mcpError', { error: formatError(error) }), 'error')
|
|
2779
|
+
await openSettingsTab('mcp', menuSelections.mcp ?? 0)
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
async function removeMcpServer(name) {
|
|
2784
|
+
const cwd = mcpCwd()
|
|
2785
|
+
try {
|
|
2786
|
+
await removeServer({ cwd, name })
|
|
2787
|
+
await reloadMcpAndSync()
|
|
2788
|
+
app.showToast(t('mcp.removed'), 'info')
|
|
2789
|
+
} catch (error) {
|
|
2790
|
+
app.showToast(t('session.mcpError', { error: formatError(error) }), 'error')
|
|
2791
|
+
}
|
|
2792
|
+
await openSettingsTab('mcp', menuSelections.mcp ?? 0)
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2226
2795
|
function openSettingChoices(item, parentSelection) {
|
|
2227
2796
|
if (!Array.isArray(item.options) || item.options.length === 0) {
|
|
2228
|
-
app.showToast('
|
|
2797
|
+
app.showToast(t('settings.noOptions', { label: item.label }), 'warn')
|
|
2229
2798
|
paint()
|
|
2230
2799
|
return
|
|
2231
2800
|
}
|
|
2232
|
-
|
|
2801
|
+
// A committed option, and Esc, both return to the view the list was opened
|
|
2802
|
+
// from. Deriving it from that view keeps a list opened inside the MCP form
|
|
2803
|
+
// (transport, enabled) coming back to the form instead of dumping the user
|
|
2804
|
+
// on the Main tab with the draft lost.
|
|
2805
|
+
const parent = settingsView.kind === 'choice' ? settingsView.parent : settingsView.kind
|
|
2233
2806
|
settingsView = { kind: 'choice', parentSelection, parent }
|
|
2234
2807
|
const settingItem = { ...item, returnSelection: parentSelection }
|
|
2235
2808
|
// Options are either plain strings (label and value are the same id) or
|
|
@@ -2247,17 +2820,17 @@ export function apply(ctx, config) {
|
|
|
2247
2820
|
settingItem,
|
|
2248
2821
|
// Sensitive options (e.g. unrestricted access) confirm in place before
|
|
2249
2822
|
// the choice is committed.
|
|
2250
|
-
confirm: item.confirmValue === value ? (item.confirmText ?? '
|
|
2823
|
+
confirm: item.confirmValue === value ? (item.confirmText ?? t('settings.confirmChange')) : undefined,
|
|
2251
2824
|
disabled: false,
|
|
2252
2825
|
}))
|
|
2253
|
-
app.openSettings(items, { title: item.label, subtitle: '
|
|
2826
|
+
app.openSettings(items, { title: item.label, subtitle: t('settings.optionList') })
|
|
2254
2827
|
app.setSettingsSelection(Math.max(0, options.findIndex(({ value }) => value === item.value)))
|
|
2255
2828
|
paint()
|
|
2256
2829
|
}
|
|
2257
2830
|
|
|
2258
2831
|
function requestSettingCommit(item, value) {
|
|
2259
2832
|
if (item.confirmValue === value || item.kind === 'remove-provider') {
|
|
2260
|
-
app.settingsConfirm = { item, value, text: item.confirmText ?? '
|
|
2833
|
+
app.settingsConfirm = { item, value, text: item.confirmText ?? t('settings.confirmChange') }
|
|
2261
2834
|
paint()
|
|
2262
2835
|
return
|
|
2263
2836
|
}
|
|
@@ -2279,115 +2852,208 @@ export function apply(ctx, config) {
|
|
|
2279
2852
|
const parentSelection = app.settingsSelection
|
|
2280
2853
|
settingsView = { kind: 'update-versions', pkg, parentSelection }
|
|
2281
2854
|
const pkgLabel = pkg === 'dsh' ? DSH_PACKAGE : TUI_PACKAGE
|
|
2282
|
-
app.openSettings([{ kind: 'update-version-loading', label: '
|
|
2283
|
-
title: pkgLabel + ' · versions',
|
|
2284
|
-
subtitle: 'fetching
|
|
2855
|
+
app.openSettings([{ kind: 'update-version-loading', label: t('update.fetchingVersions'), value: '', disabled: true }], {
|
|
2856
|
+
title: pkgLabel + ' · ' + t('update.versions').toLowerCase(),
|
|
2857
|
+
subtitle: t('update.fetching'),
|
|
2285
2858
|
})
|
|
2286
2859
|
paint()
|
|
2287
2860
|
let registry
|
|
2288
2861
|
try {
|
|
2862
|
+
const t0 = Date.now()
|
|
2289
2863
|
registry = await registryInfo(pkg === 'dsh' ? DSH_PACKAGE : TUI_PACKAGE)
|
|
2290
2864
|
} catch (error) {
|
|
2291
2865
|
if (version !== settingsLoadVersion) return
|
|
2292
|
-
app.showToast('
|
|
2866
|
+
app.showToast(t('session.versionsError', { error: formatError(error) }), 'error')
|
|
2293
2867
|
await openSettingsTab('update', parentSelection)
|
|
2294
2868
|
return
|
|
2295
2869
|
}
|
|
2296
2870
|
if (version !== settingsLoadVersion || settingsView.kind !== 'update-versions' || settingsView.pkg !== pkg) return
|
|
2297
2871
|
const installed = pkg === 'dsh' ? (updateState?.dsh?.installed ?? null) : (updateState?.tui?.installed ?? null)
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2872
|
+
const staged = updateState?.staged
|
|
2873
|
+
app.openSettings(buildVersionItems(registry, installed, {
|
|
2874
|
+
// Tarballs already on disk make a rollback (or a retry) instant — the
|
|
2875
|
+
// rows say so, and stageInstall verifies a cache hit instead of trusting
|
|
2876
|
+
// it.
|
|
2877
|
+
cached: cachedTarballVersions(pkg === 'dsh' ? DSH_PACKAGE : TUI_PACKAGE),
|
|
2878
|
+
staged: staged && staged.pkg === pkg ? staged.version : null,
|
|
2879
|
+
}), {
|
|
2880
|
+
title: pkgLabel + ' · ' + t('update.versions').toLowerCase(),
|
|
2881
|
+
subtitle: t('update.versionsSubtitle'),
|
|
2301
2882
|
})
|
|
2302
2883
|
app.setSettingsSelection(0)
|
|
2303
2884
|
paint()
|
|
2304
2885
|
}
|
|
2305
2886
|
|
|
2306
2887
|
// Inline y/n confirm before switching a version. For a locally-installed TUI
|
|
2307
|
-
// the copy warns that the local path install becomes a registry
|
|
2888
|
+
// the copy warns that the local path install becomes a registry version; a
|
|
2889
|
+
// tarball already on disk (from this run or an earlier one) skips the
|
|
2890
|
+
// download and goes straight to the restart.
|
|
2308
2891
|
function requestUpdateInstall(item) {
|
|
2309
2892
|
const pkg = settingsView.pkg
|
|
2310
2893
|
const target = item.version
|
|
2311
2894
|
const label = pkg === 'dsh' ? DSH_PACKAGE : TUI_PACKAGE
|
|
2312
|
-
let text =
|
|
2895
|
+
let text = item.cached === true
|
|
2896
|
+
? t('update.restartApplyQ', { label, version: target })
|
|
2897
|
+
: t('update.downloadQ', { label, version: target })
|
|
2313
2898
|
if (pkg === 'tui' && updateState?.profile && tuiInstallIsLocal(updateState.profile)) {
|
|
2314
|
-
text += '
|
|
2899
|
+
text += t('update.localSwitch')
|
|
2315
2900
|
}
|
|
2316
2901
|
app.settingsConfirm = { item, value: target, text, updateInstall: { pkg, version: target } }
|
|
2317
2902
|
paint()
|
|
2318
2903
|
}
|
|
2319
2904
|
|
|
2320
|
-
//
|
|
2321
|
-
//
|
|
2322
|
-
// and
|
|
2323
|
-
//
|
|
2324
|
-
//
|
|
2325
|
-
//
|
|
2326
|
-
//
|
|
2327
|
-
|
|
2328
|
-
|
|
2905
|
+
// ---- download + restart to apply ---------------------------------------
|
|
2906
|
+
// The update path never installs inline. The tarball is downloaded here with
|
|
2907
|
+
// live progress and staged under $DSH_HOME/updates; applying it is a
|
|
2908
|
+
// restart. A detached applier waits for this process to exit, installs from
|
|
2909
|
+
// the staged tarball (so no npm/pnpm write ever races a live dsh), verifies
|
|
2910
|
+
// the on-disk version, writes the install marker, then relaunches dsh in this
|
|
2911
|
+
// terminal. Esc aborts an in-flight download.
|
|
2912
|
+
|
|
2913
|
+
function updatePackageLabel(pkg) {
|
|
2914
|
+
return pkg === 'dsh' ? DSH_PACKAGE : TUI_PACKAGE
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
// Everything the applier needs, resolved while this process is still alive
|
|
2918
|
+
// and can see both trees (the global install and the profile).
|
|
2919
|
+
function buildApplyPlan(record) {
|
|
2920
|
+
const profile = record.profile ?? updateState?.profile ?? 'tui'
|
|
2921
|
+
const dshEntry = updateState?.dsh?.entry ?? null
|
|
2922
|
+
const args = dshProcessArgs()
|
|
2923
|
+
return restartPlan({
|
|
2924
|
+
pkg: record.pkg,
|
|
2925
|
+
packageName: record.packageName ?? updatePackageLabel(record.pkg),
|
|
2926
|
+
version: record.version,
|
|
2927
|
+
tarball: record.tarball,
|
|
2928
|
+
profile,
|
|
2929
|
+
cwd: record.cwd ?? process.cwd(),
|
|
2930
|
+
verifyPath: record.pkg === 'dsh' ? dshManifestPath() : tuiInstalledManifestPath(profile),
|
|
2931
|
+
marker: installMarkerPath(),
|
|
2932
|
+
dsh: dshEntry ? { command: process.execPath, args: [dshEntry] } : null,
|
|
2933
|
+
dshShim: dshShimPath(),
|
|
2934
|
+
dshArgs: args,
|
|
2935
|
+
relaunch: dshEntry ? { command: process.execPath, args: [dshEntry, ...args] } : null,
|
|
2936
|
+
})
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2329
2939
|
async function startUpdateInstall(pkg, version) {
|
|
2330
|
-
if (app.settingsBusy) return
|
|
2940
|
+
if (app.settingsBusy || updateDownload) return
|
|
2941
|
+
const label = updatePackageLabel(pkg)
|
|
2942
|
+
const cachePath = tarballCachePath(label, version)
|
|
2943
|
+
const load = ++settingsLoadVersion
|
|
2944
|
+
settingsView = { kind: 'update-download', pkg, version, parentSelection: app.settingsSelection }
|
|
2331
2945
|
app.settingsBusy = true
|
|
2332
|
-
|
|
2333
|
-
|
|
2946
|
+
app.openSettings([
|
|
2947
|
+
{ kind: 'header', label: t('update.download'), value: '', disabled: true },
|
|
2948
|
+
{ kind: 'update-progress', label, value: t('update.contacting'), percent: null, disabled: true },
|
|
2949
|
+
{ kind: 'update-info', label: t('update.version'), value: version, disabled: true },
|
|
2950
|
+
{ kind: 'update-info', label: t('update.savingTo'), value: cachePath, disabled: true },
|
|
2951
|
+
], {
|
|
2952
|
+
title: label + ' · ' + t('update.download').toLowerCase(),
|
|
2953
|
+
subtitle: t('update.escCancels'),
|
|
2954
|
+
})
|
|
2955
|
+
app.setSettingsSelection(1)
|
|
2334
2956
|
paint()
|
|
2957
|
+
const controller = new AbortController()
|
|
2958
|
+
const progressRow = app.settingsItems.find((item) => item.kind === 'update-progress')
|
|
2959
|
+
updateDownload = { pkg, version, label, controller, progressRow }
|
|
2960
|
+
const onProgress = ({ received, total }) => {
|
|
2961
|
+
const progress = formatDownloadProgress(received, total)
|
|
2962
|
+
if (progressRow) {
|
|
2963
|
+
progressRow.value = progress.text
|
|
2964
|
+
progressRow.percent = progress.percent
|
|
2965
|
+
}
|
|
2966
|
+
app.settingsSubtitle = version + ' · ' + progress.text
|
|
2967
|
+
paint()
|
|
2968
|
+
}
|
|
2335
2969
|
try {
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
if (locks.length > 0) {
|
|
2351
|
-
app.showToast(`cannot update dsh while it is running (${locks.length} other dsh process${locks.length === 1 ? '' : 'es'}) — close them and retry`, 'error')
|
|
2352
|
-
paint()
|
|
2353
|
-
return
|
|
2354
|
-
}
|
|
2355
|
-
}
|
|
2356
|
-
const result = pkg === 'dsh'
|
|
2357
|
-
? await installDsh(version)
|
|
2358
|
-
: await installTui(version, updateState?.profile ?? 'tui', updateState?.dsh?.entry)
|
|
2359
|
-
let outcome = null
|
|
2360
|
-
if (pkg === 'dsh') {
|
|
2361
|
-
// npm exit 0 is not proof: verify the on-disk manifest.
|
|
2362
|
-
const after = detectDshInstall()
|
|
2363
|
-
outcome = installResultFrom(result, after.found ? { version: after.version } : null, version)
|
|
2364
|
-
} else if (result.code === 0) {
|
|
2365
|
-
outcome = { kind: 'installed', code: 0, stderr: '', reason: '' }
|
|
2366
|
-
} else {
|
|
2367
|
-
outcome = { kind: 'failed', code: result.code, stderr: result.stderr, reason: stderrSummary(result.stderr) || `install exited ${result.code}` }
|
|
2368
|
-
}
|
|
2369
|
-
if (outcome.kind === 'installed') {
|
|
2370
|
-
app.showToast((pkg === 'dsh' ? 'dsh' : 'dsh-oc-tui') + ' ' + version + ' installed — restart to apply')
|
|
2371
|
-
} else if (outcome.kind === 'corrupt') {
|
|
2372
|
-
app.showToast('install corrupt: ' + outcome.reason, 'error')
|
|
2373
|
-
} else {
|
|
2374
|
-
app.showToast('install failed: ' + (outcome.reason || stderrSummary(outcome.stderr)), 'error')
|
|
2375
|
-
}
|
|
2970
|
+
const record = await stageInstall({
|
|
2971
|
+
pkg,
|
|
2972
|
+
version,
|
|
2973
|
+
profile: updateState?.profile ?? 'tui',
|
|
2974
|
+
cwd: process.cwd(),
|
|
2975
|
+
onProgress,
|
|
2976
|
+
signal: controller.signal,
|
|
2977
|
+
})
|
|
2978
|
+
updateDownload = null
|
|
2979
|
+
app.settingsBusy = false
|
|
2980
|
+
updateState = updateState ? { ...updateState, staged: record } : updateState
|
|
2981
|
+
if (load !== settingsLoadVersion) {
|
|
2982
|
+
// The user navigated away while the last chunk was landing.
|
|
2983
|
+
app.showToast(t('update.downloadedToast', { label, version }))
|
|
2376
2984
|
paint()
|
|
2985
|
+
return
|
|
2377
2986
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2987
|
+
app.settingsSubtitle = t('update.downloaded')
|
|
2988
|
+
app.settingsConfirm = {
|
|
2989
|
+
item: progressRow ?? { kind: 'update-progress', label, disabled: true },
|
|
2990
|
+
value: '',
|
|
2991
|
+
text: t(record.cached ? 'update.alreadyDownloadedConfirm' : 'update.downloadedConfirm', { label, version }),
|
|
2992
|
+
updateRestart: record,
|
|
2381
2993
|
}
|
|
2382
|
-
} catch (error) {
|
|
2383
|
-
app.showToast('install: ' + formatError(error), 'error')
|
|
2384
2994
|
paint()
|
|
2385
|
-
}
|
|
2995
|
+
} catch (error) {
|
|
2996
|
+
updateDownload = null
|
|
2386
2997
|
app.settingsBusy = false
|
|
2998
|
+
if (controller.signal.aborted) app.showToast(t('update.downloadCancelled'))
|
|
2999
|
+
else app.showToast(t('update.downloadFailed', { error: formatError(error) }), 'error')
|
|
3000
|
+
if (load === settingsLoadVersion) await openSettingsTab('update', settingsView.parentSelection ?? 0)
|
|
2387
3001
|
paint()
|
|
2388
3002
|
}
|
|
2389
3003
|
}
|
|
2390
3004
|
|
|
3005
|
+
// Apply a staged install by restarting. The applier is spawned *before* the
|
|
3006
|
+
// shutdown so a spawn failure can still be reported; it only polls this pid,
|
|
3007
|
+
// so nothing is installed until this process is really gone.
|
|
3008
|
+
async function restartToApply(record) {
|
|
3009
|
+
if (app.settingsBusy) return
|
|
3010
|
+
const label = record.packageName ?? updatePackageLabel(record.pkg)
|
|
3011
|
+
if (!record.tarball) {
|
|
3012
|
+
app.showToast(t('update.stagedGone'), 'error')
|
|
3013
|
+
paint()
|
|
3014
|
+
return
|
|
3015
|
+
}
|
|
3016
|
+
// A global install (or profile reinstall) over another live dsh is the
|
|
3017
|
+
// hybrid-tree hazard; refuse while any other dsh process is alive.
|
|
3018
|
+
const locks = await detectDshLocks(process.pid)
|
|
3019
|
+
if (locks.length > 0) {
|
|
3020
|
+
app.showToast(tn('update.locks', locks.length, { count: locks.length }), 'error')
|
|
3021
|
+
paint()
|
|
3022
|
+
return
|
|
3023
|
+
}
|
|
3024
|
+
const plan = buildApplyPlan(record)
|
|
3025
|
+
if (record.pkg === 'dsh' && !plan.npm) {
|
|
3026
|
+
app.showToast(t('update.noNpm'), 'error')
|
|
3027
|
+
paint()
|
|
3028
|
+
return
|
|
3029
|
+
}
|
|
3030
|
+
if (record.pkg === 'tui' && !plan.dsh) {
|
|
3031
|
+
app.showToast(t('update.noDshCli'), 'error')
|
|
3032
|
+
paint()
|
|
3033
|
+
return
|
|
3034
|
+
}
|
|
3035
|
+
if (!spawnApplyUpdater(plan)) {
|
|
3036
|
+
app.showToast(t('update.installerFailed', { label }), 'error')
|
|
3037
|
+
paint()
|
|
3038
|
+
return
|
|
3039
|
+
}
|
|
3040
|
+
app.settingsConfirm = null
|
|
3041
|
+
app.settingsBusy = true
|
|
3042
|
+
app.showToast(t('update.applying', { label }))
|
|
3043
|
+
paint()
|
|
3044
|
+
// Graceful shutdown: confirm-to-quit still applies, and the applier starts
|
|
3045
|
+
// installing the moment this pid disappears.
|
|
3046
|
+
setTimeout(() => quit(), 250)
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
// Drop the staged download (the cached tarball stays for a later retry).
|
|
3050
|
+
function discardStagedDownload() {
|
|
3051
|
+
clearStagedInstall()
|
|
3052
|
+
if (updateState) updateState = { ...updateState, staged: null }
|
|
3053
|
+
app.showToast(t('update.stagedDiscarded'))
|
|
3054
|
+
void openSettingsTab('update', app.settingsSelection)
|
|
3055
|
+
}
|
|
3056
|
+
|
|
2391
3057
|
function handleSettingsKey(key) {
|
|
2392
3058
|
if (settingsView.kind === 'sessions' && key.ctrl && key.name === 'd') {
|
|
2393
3059
|
const item = app.settingsItems[app.settingsSelection]
|
|
@@ -2397,17 +3063,34 @@ export function apply(ctx, config) {
|
|
|
2397
3063
|
app.settingsConfirm = null
|
|
2398
3064
|
void deleteManagedSession(item)
|
|
2399
3065
|
} else {
|
|
2400
|
-
app.settingsConfirm = { item, value: '', text: '
|
|
3066
|
+
app.settingsConfirm = { item, value: '', text: t('settings.deleteTwice') + item.label }
|
|
2401
3067
|
}
|
|
2402
3068
|
} else {
|
|
2403
|
-
app.showToast('
|
|
3069
|
+
app.showToast(t('settings.noSession'), 'warn')
|
|
2404
3070
|
}
|
|
2405
3071
|
paint()
|
|
2406
3072
|
return
|
|
2407
3073
|
}
|
|
3074
|
+
// Delete on a server row uninstalls it without opening the form first.
|
|
3075
|
+
if (settingsView.kind === 'mcp' && (key.name === 'delete' || key.name === 'backspace')) {
|
|
3076
|
+
const item = app.settingsItems[app.settingsSelection]
|
|
3077
|
+
if (item?.kind === 'mcp-server' && item.record?.name) {
|
|
3078
|
+
if (app.settingsConfirm?.item === item) {
|
|
3079
|
+
app.settingsConfirm = null
|
|
3080
|
+
void removeMcpServer(item.record.name)
|
|
3081
|
+
} else {
|
|
3082
|
+
app.settingsConfirm = { item, value: '', text: t('settings.deleteMcpTwice') + item.record.name }
|
|
3083
|
+
paint()
|
|
3084
|
+
}
|
|
3085
|
+
} else {
|
|
3086
|
+
app.showToast(t('settings.noMcp'), 'warn')
|
|
3087
|
+
paint()
|
|
3088
|
+
}
|
|
3089
|
+
return
|
|
3090
|
+
}
|
|
2408
3091
|
const count = app.settingsItems.length
|
|
2409
3092
|
if (count === 0) {
|
|
2410
|
-
app.showToast('
|
|
3093
|
+
app.showToast(t('settings.noSessions'), 'warn')
|
|
2411
3094
|
paint()
|
|
2412
3095
|
return
|
|
2413
3096
|
}
|
|
@@ -2419,9 +3102,19 @@ export function apply(ctx, config) {
|
|
|
2419
3102
|
app.settingsConfirm = null
|
|
2420
3103
|
paint()
|
|
2421
3104
|
}
|
|
3105
|
+
} else if (pending.item.kind === 'mcp-server') {
|
|
3106
|
+
// A second Delete removes the server; anything else cancels the prompt.
|
|
3107
|
+
if (key.name === 'delete' || key.name === 'backspace') {
|
|
3108
|
+
app.settingsConfirm = null
|
|
3109
|
+
void removeMcpServer(pending.item.record.name)
|
|
3110
|
+
} else {
|
|
3111
|
+
app.settingsConfirm = null
|
|
3112
|
+
paint()
|
|
3113
|
+
}
|
|
2422
3114
|
} else if (key.name === 'y' || key.text?.toLowerCase() === 'y' || key.name === 'return' || key.name === 'enter') {
|
|
2423
3115
|
app.settingsConfirm = null
|
|
2424
3116
|
if (pending.updateInstall) void startUpdateInstall(pending.updateInstall.pkg, pending.updateInstall.version)
|
|
3117
|
+
else if (pending.updateRestart) void restartToApply(pending.updateRestart)
|
|
2425
3118
|
else void commitSetting(pending.value, pending.commitItem ?? pending.item)
|
|
2426
3119
|
} else if (key.name === 'n' || key.text?.toLowerCase() === 'n' || key.name === 'escape') {
|
|
2427
3120
|
app.settingsConfirm = null
|
|
@@ -2448,11 +3141,22 @@ export function apply(ctx, config) {
|
|
|
2448
3141
|
}
|
|
2449
3142
|
|
|
2450
3143
|
if (key.name === 'escape') {
|
|
2451
|
-
if (settingsView.kind === 'choice'
|
|
3144
|
+
if (settingsView.kind === 'choice' && settingsView.parent === 'mcp-form') {
|
|
3145
|
+
// Backing out of the transport/enabled list keeps the half-filled form.
|
|
3146
|
+
renderMcpForm(mcpFormDraft, mcpFormIsEdit, settingsView.parentSelection)
|
|
3147
|
+
} else if (settingsView.kind === 'choice') void openSettingsTab(settingsView.parent, settingsView.parentSelection)
|
|
3148
|
+
else if (settingsView.kind === 'mcp-form') void openSettingsTab('mcp', menuSelections.mcp ?? 0)
|
|
2452
3149
|
else if (settingsView.kind === 'provider-models') void openSettingsTab('model', settingsView.parentSelection ?? 0)
|
|
2453
3150
|
else if (settingsView.kind === 'sessions') void openSettingsTab('main')
|
|
2454
3151
|
else if (settingsView.kind === 'update-versions') void openSettingsTab('update', settingsView.parentSelection ?? 0)
|
|
2455
|
-
else
|
|
3152
|
+
else if (settingsView.kind === 'update-download') {
|
|
3153
|
+
// Esc aborts the fetch; the staged record (if any) stays for later.
|
|
3154
|
+
const download = updateDownload
|
|
3155
|
+
updateDownload = null
|
|
3156
|
+
app.settingsBusy = false
|
|
3157
|
+
if (download) download.controller.abort()
|
|
3158
|
+
void openSettingsTab('update', settingsView.parentSelection ?? 0)
|
|
3159
|
+
} else app.overlay = null
|
|
2456
3160
|
} else if (key.name === 'up') {
|
|
2457
3161
|
app.moveSettingsSelection(-1)
|
|
2458
3162
|
} else if (key.name === 'down') {
|
|
@@ -2460,7 +3164,7 @@ export function apply(ctx, config) {
|
|
|
2460
3164
|
} else if (key.name === 'tab' || key.name === 'shift-tab') {
|
|
2461
3165
|
// On the menu tabs, Tab switches the left menu; everywhere else it
|
|
2462
3166
|
// keeps moving the item list like Down.
|
|
2463
|
-
if ((settingsView.kind === 'main' || settingsView.kind === 'model' || settingsView.kind === 'update') && app.settingsMenu.length > 0) {
|
|
3167
|
+
if ((settingsView.kind === 'main' || settingsView.kind === 'model' || settingsView.kind === 'update' || settingsView.kind === 'mcp') && app.settingsMenu.length > 0) {
|
|
2464
3168
|
switchSettingsTab(app.settingsMenuIndex + (key.name === 'shift-tab' ? -1 : 1))
|
|
2465
3169
|
return
|
|
2466
3170
|
}
|
|
@@ -2491,10 +3195,40 @@ export function apply(ctx, config) {
|
|
|
2491
3195
|
void openUpdateVersions(item.pkg)
|
|
2492
3196
|
return
|
|
2493
3197
|
}
|
|
3198
|
+
if (item.kind === 'update-restart') {
|
|
3199
|
+
void restartToApply(item.staged)
|
|
3200
|
+
return
|
|
3201
|
+
}
|
|
3202
|
+
if (item.kind === 'update-discard') {
|
|
3203
|
+
discardStagedDownload()
|
|
3204
|
+
return
|
|
3205
|
+
}
|
|
2494
3206
|
if (item.kind === 'update-version') {
|
|
2495
3207
|
requestUpdateInstall(item)
|
|
2496
3208
|
return
|
|
2497
3209
|
}
|
|
3210
|
+
if (item.kind === 'mcp-add') {
|
|
3211
|
+
openMcpForm(null)
|
|
3212
|
+
return
|
|
3213
|
+
}
|
|
3214
|
+
if (item.kind === 'mcp-server') {
|
|
3215
|
+
openMcpForm(item.record)
|
|
3216
|
+
return
|
|
3217
|
+
}
|
|
3218
|
+
if (item.kind === 'mcp-save') {
|
|
3219
|
+
void saveMcpForm()
|
|
3220
|
+
return
|
|
3221
|
+
}
|
|
3222
|
+
if (item.kind === 'mcp-remove') {
|
|
3223
|
+
if (app.settingsConfirm?.item === item) {
|
|
3224
|
+
app.settingsConfirm = null
|
|
3225
|
+
void removeMcpServer(item.serverName)
|
|
3226
|
+
} else {
|
|
3227
|
+
app.settingsConfirm = { item, value: '', text: item.confirmText ?? t('mcp.removeConfirm') }
|
|
3228
|
+
}
|
|
3229
|
+
paint()
|
|
3230
|
+
return
|
|
3231
|
+
}
|
|
2498
3232
|
if (item.kind === 'setting-option') {
|
|
2499
3233
|
if (item.confirm) {
|
|
2500
3234
|
// Sensitive option: confirm in place before committing the choice.
|
|
@@ -2531,6 +3265,18 @@ export function apply(ctx, config) {
|
|
|
2531
3265
|
requestSettingCommit(item, '')
|
|
2532
3266
|
return
|
|
2533
3267
|
}
|
|
3268
|
+
if (settingsView.kind === 'mcp-form' && item.kind === 'mcp-field') {
|
|
3269
|
+
// Choice rows go through the shared option list; text rows through the
|
|
3270
|
+
// inline editor. Both land in commitMcpField via commitSetting.
|
|
3271
|
+
if (!item.disabled && item.options?.length > 0) openSettingChoices(item, app.settingsSelection)
|
|
3272
|
+
else if (!item.disabled) {
|
|
3273
|
+
app.settingsEditing = app.settingsSelection
|
|
3274
|
+
app.settingsSecret = false
|
|
3275
|
+
app.settingsDraft = String(item.value ?? '')
|
|
3276
|
+
}
|
|
3277
|
+
paint()
|
|
3278
|
+
return
|
|
3279
|
+
}
|
|
2534
3280
|
if (!item.disabled) {
|
|
2535
3281
|
app.settingsEditing = app.settingsSelection
|
|
2536
3282
|
app.settingsSecret = item.kind === 'secret'
|
|
@@ -2545,11 +3291,39 @@ export function apply(ctx, config) {
|
|
|
2545
3291
|
app.settingsEditing = null
|
|
2546
3292
|
app.settingsDraft = ''
|
|
2547
3293
|
app.settingsSecret = false
|
|
3294
|
+
// The MCP form is a draft, not a settings field: its commit writes into the
|
|
3295
|
+
// draft and re-renders, and only "Save and connect" touches storage. The
|
|
3296
|
+
// row that was edited is `returnSelection`; `app.settingsSelection` still
|
|
3297
|
+
// points into the option list that just closed.
|
|
3298
|
+
if (settingsView.kind === 'mcp-form' && item?.kind === 'mcp-field') {
|
|
3299
|
+
commitMcpField(item, value, selection)
|
|
3300
|
+
paint()
|
|
3301
|
+
return
|
|
3302
|
+
}
|
|
2548
3303
|
if (!sharedSettings || !item || (value.trim() === '' && !['path', 'enable-provider', 'remove-provider'].includes(item.kind))) {
|
|
2549
3304
|
paint()
|
|
2550
3305
|
return
|
|
2551
3306
|
}
|
|
2552
3307
|
try {
|
|
3308
|
+
if (item.kind === 'locale') {
|
|
3309
|
+
// The host announces a committed Config field as it writes it, and the
|
|
3310
|
+
// volatile-update handler stands down for the duration so the two
|
|
3311
|
+
// rebuilds cannot race (see the note where it is declared).
|
|
3312
|
+
localeCommitInFlight = true
|
|
3313
|
+
try {
|
|
3314
|
+
await saveWebSetting(ctx, sharedSettings, item, value)
|
|
3315
|
+
} finally {
|
|
3316
|
+
localeCommitInFlight = false
|
|
3317
|
+
}
|
|
3318
|
+
// A language switch repaints the whole interface from the new catalog, so
|
|
3319
|
+
// it lands before the settings view is rebuilt (the rebuilt rows are then
|
|
3320
|
+
// already in the new language).
|
|
3321
|
+
setLocale(resolveLocale(value))
|
|
3322
|
+
app.showToast(t('settings.languageSaved', { language: describeLocale(value) }))
|
|
3323
|
+
await refreshSettings(selection)
|
|
3324
|
+
paint()
|
|
3325
|
+
return
|
|
3326
|
+
}
|
|
2553
3327
|
await saveWebSetting(ctx, sharedSettings, item, value)
|
|
2554
3328
|
if (item.kind === 'provider-model') {
|
|
2555
3329
|
modelPreference.provider = item.providerId
|
|
@@ -2567,12 +3341,13 @@ export function apply(ctx, config) {
|
|
|
2567
3341
|
app.setSession({ provider: modelPreference.provider, model: modelPreference.model ?? '' })
|
|
2568
3342
|
}
|
|
2569
3343
|
if (item.ns === 'agent-default-model' || item.kind === 'provider-model') void loadEffortSlider()
|
|
2570
|
-
|
|
3344
|
+
if (item.settingGroup === 'tui-graphics') applyGraphicsSettings()
|
|
3345
|
+
app.showToast(item.kind === 'remove-provider' ? t('settings.providerRemoved') : t('settings.saved'))
|
|
2571
3346
|
if (item.kind === 'remove-provider') await openSettingsTab('model')
|
|
2572
3347
|
else await refreshSettings(selection)
|
|
2573
3348
|
} catch (error) {
|
|
2574
|
-
const conflict = error?.code === 'SETTINGS_CONFLICT' ? 'settings
|
|
2575
|
-
app.showToast('settings
|
|
3349
|
+
const conflict = error?.code === 'SETTINGS_CONFLICT' ? t('settings.conflict') : formatError(error)
|
|
3350
|
+
app.showToast(t('settings.error', { error: conflict }), 'error')
|
|
2576
3351
|
await refreshSettings(selection)
|
|
2577
3352
|
}
|
|
2578
3353
|
}
|
|
@@ -2588,12 +3363,12 @@ export function apply(ctx, config) {
|
|
|
2588
3363
|
app.inputText = ''
|
|
2589
3364
|
app.inputCursor = 0
|
|
2590
3365
|
app.inputImages = []
|
|
2591
|
-
app.showToast('
|
|
3366
|
+
app.showToast(t('session.promptCleared'))
|
|
2592
3367
|
} else if (action === 'cancel') {
|
|
2593
3368
|
if (currentAgent) currentAgent.cancel({ kind: 'user' })
|
|
2594
|
-
app.showToast('
|
|
3369
|
+
app.showToast(t('session.interruptRequested'))
|
|
2595
3370
|
} else if (action === 'arm-exit') {
|
|
2596
|
-
app.showToast('
|
|
3371
|
+
app.showToast(t('session.exitAgain'))
|
|
2597
3372
|
} else if (action === 'exit') {
|
|
2598
3373
|
quit(true)
|
|
2599
3374
|
return
|
|
@@ -2688,21 +3463,38 @@ export function apply(ctx, config) {
|
|
|
2688
3463
|
async function sendMessage(text, images = []) {
|
|
2689
3464
|
if (!currentAgent) return
|
|
2690
3465
|
const wasRunning = app.status === 'running'
|
|
2691
|
-
lastUserText = text
|
|
3466
|
+
lastUserText = stripImageMarkers(text)
|
|
2692
3467
|
lastUserTime = Date.now()
|
|
2693
|
-
|
|
3468
|
+
// The optimistic block renders images straight from the paste bytes — no
|
|
3469
|
+
// attachment read-back needed; the event path matches this block via the
|
|
3470
|
+
// marker-stripped text and attaches nothing.
|
|
3471
|
+
lastUserHadImages = images.some((img) => img.status === 'ready' || img.status === 'pending')
|
|
3472
|
+
app.addUser(text, {
|
|
3473
|
+
images: images
|
|
3474
|
+
.filter((img) => img.data || usableRef(img))
|
|
3475
|
+
.map((img) => img.data
|
|
3476
|
+
? { kind: 'bytes', key: sha16(img.data), bytes: img.data, mediaType: img.mediaType }
|
|
3477
|
+
: { kind: 'ref', key: 'ref:' + img.ref.attachmentId, ref: img.ref, mediaType: img.mediaType }),
|
|
3478
|
+
})
|
|
2694
3479
|
app.setStatus('running')
|
|
2695
3480
|
const content = await buildUserContent(text, images)
|
|
2696
3481
|
const message = createUserMessage({
|
|
2697
3482
|
content: content.length > 0 ? content : [{ type: 'text', text }],
|
|
2698
3483
|
source: { kind: 'user' },
|
|
2699
3484
|
})
|
|
2700
|
-
|
|
3485
|
+
// `settings.get(ns)` exists on the 0.1.x namespace provider; the 0.2.0 form
|
|
3486
|
+
// service dropped it and carries the same preference as a Config field
|
|
3487
|
+
// instead, so the read goes through the generation-aware resolver.
|
|
3488
|
+
const busyEnter = readTuiSetting(ctx, config, 'ui-conversation', 'busyEnter') ?? 'queue'
|
|
2701
3489
|
if (wasRunning && busyEnter === 'steer') currentAgent.steer(message)
|
|
2702
3490
|
else currentAgent.followup(message)
|
|
2703
3491
|
paint()
|
|
2704
3492
|
}
|
|
2705
3493
|
|
|
3494
|
+
function usableRef(img) {
|
|
3495
|
+
return img.ref && typeof img.ref.attachmentId === 'string'
|
|
3496
|
+
}
|
|
3497
|
+
|
|
2706
3498
|
async function createSessionAndSend(text, images = []) {
|
|
2707
3499
|
app.setStatus('running')
|
|
2708
3500
|
paint()
|
|
@@ -2750,7 +3542,7 @@ export function apply(ctx, config) {
|
|
|
2750
3542
|
app.inputText = ''
|
|
2751
3543
|
app.inputCursor = 0
|
|
2752
3544
|
app.inputImages = []
|
|
2753
|
-
app.showToast('
|
|
3545
|
+
app.showToast(t('session.modelNoImages', { model: refusing }), 'error')
|
|
2754
3546
|
paint()
|
|
2755
3547
|
return
|
|
2756
3548
|
}
|
|
@@ -2791,7 +3583,7 @@ export function apply(ctx, config) {
|
|
|
2791
3583
|
if (!TUI_EXCLUSIVE_COMMANDS.has(parsed.name)
|
|
2792
3584
|
&& ctx.commands.find(currentAgent ?? undefined, parsed.name)) {
|
|
2793
3585
|
if (!currentAgent) {
|
|
2794
|
-
app.showToast('/' + parsed.name + ':
|
|
3586
|
+
app.showToast('/' + parsed.name + ': ' + t('session.startFirst'), 'warn')
|
|
2795
3587
|
paint()
|
|
2796
3588
|
return
|
|
2797
3589
|
}
|
|
@@ -2821,7 +3613,7 @@ export function apply(ctx, config) {
|
|
|
2821
3613
|
// The details window needs a session: its figures describe a durable
|
|
2822
3614
|
// log, and the title screen has none.
|
|
2823
3615
|
if (!currentAgent) {
|
|
2824
|
-
feedback('
|
|
3616
|
+
feedback(t('session.startFirst'), 'warn')
|
|
2825
3617
|
break
|
|
2826
3618
|
}
|
|
2827
3619
|
app.statsOpen = !app.statsOpen
|
|
@@ -2832,7 +3624,7 @@ export function apply(ctx, config) {
|
|
|
2832
3624
|
case 'resume': {
|
|
2833
3625
|
const id = parsed.rawInput.trim()
|
|
2834
3626
|
if (!id) {
|
|
2835
|
-
feedback('
|
|
3627
|
+
feedback(t('session.usageResume'), 'warn')
|
|
2836
3628
|
break
|
|
2837
3629
|
}
|
|
2838
3630
|
void openSession({ resume: id })
|
|
@@ -2841,24 +3633,24 @@ export function apply(ctx, config) {
|
|
|
2841
3633
|
case 'model': {
|
|
2842
3634
|
const id = parsed.rawInput.trim()
|
|
2843
3635
|
if (!id) {
|
|
2844
|
-
feedback('
|
|
3636
|
+
feedback(t('session.currentModel', { model: modelPreference.model || app.model }), 'info')
|
|
2845
3637
|
break
|
|
2846
3638
|
}
|
|
2847
3639
|
modelPreference.model = id
|
|
2848
3640
|
app.setSession({ model: id })
|
|
2849
|
-
feedback('
|
|
3641
|
+
feedback(t('session.modelSet', { model: id }), 'info')
|
|
2850
3642
|
void loadEffortSlider()
|
|
2851
3643
|
break
|
|
2852
3644
|
}
|
|
2853
3645
|
case 'provider': {
|
|
2854
3646
|
const id = parsed.rawInput.trim()
|
|
2855
3647
|
if (!id) {
|
|
2856
|
-
feedback('
|
|
3648
|
+
feedback(t('session.currentProvider', { provider: modelPreference.provider || app.provider }), 'info')
|
|
2857
3649
|
break
|
|
2858
3650
|
}
|
|
2859
3651
|
modelPreference.provider = id
|
|
2860
3652
|
app.setSession({ provider: id })
|
|
2861
|
-
feedback('
|
|
3653
|
+
feedback(t('session.providerSet', { provider: id }), 'info')
|
|
2862
3654
|
void loadEffortSlider()
|
|
2863
3655
|
break
|
|
2864
3656
|
}
|
|
@@ -2869,9 +3661,9 @@ export function apply(ctx, config) {
|
|
|
2869
3661
|
case 'cancel': {
|
|
2870
3662
|
if (currentAgent && app.status === 'running') {
|
|
2871
3663
|
currentAgent.cancel({ kind: 'user' })
|
|
2872
|
-
app.showToast('
|
|
3664
|
+
app.showToast(t('session.interruptRequested'))
|
|
2873
3665
|
} else {
|
|
2874
|
-
app.showToast(currentAgent ? '
|
|
3666
|
+
app.showToast(currentAgent ? t('session.nothingToInterrupt') : t('session.noSessionRunning'), 'warn')
|
|
2875
3667
|
}
|
|
2876
3668
|
paint()
|
|
2877
3669
|
break
|
|
@@ -2881,7 +3673,7 @@ export function apply(ctx, config) {
|
|
|
2881
3673
|
case 'rewind': {
|
|
2882
3674
|
void (async () => {
|
|
2883
3675
|
if (!currentAgent) {
|
|
2884
|
-
feedback('
|
|
3676
|
+
feedback(t('session.startFirst'), 'warn')
|
|
2885
3677
|
return
|
|
2886
3678
|
}
|
|
2887
3679
|
const parsedArgs = parseRewindArgs(parsed.rawInput)
|
|
@@ -2899,14 +3691,14 @@ export function apply(ctx, config) {
|
|
|
2899
3691
|
break
|
|
2900
3692
|
}
|
|
2901
3693
|
default:
|
|
2902
|
-
feedback('
|
|
3694
|
+
feedback(t('session.unknownCommand', { name: parsed.name }), 'warn')
|
|
2903
3695
|
}
|
|
2904
3696
|
}
|
|
2905
3697
|
|
|
2906
3698
|
async function listSessionsCommand() {
|
|
2907
3699
|
const sq = ctx.get('sessionQuery')
|
|
2908
3700
|
if (!sq) {
|
|
2909
|
-
app.addSystem('session
|
|
3701
|
+
app.addSystem(t('session.queryMissing'), 'warn')
|
|
2910
3702
|
paint()
|
|
2911
3703
|
return
|
|
2912
3704
|
}
|
|
@@ -2922,9 +3714,9 @@ export function apply(ctx, config) {
|
|
|
2922
3714
|
return timeString(r.header.createdAt) + ' ' + String(r.header.id).slice(0, 20).padEnd(20, ' ')
|
|
2923
3715
|
+ ' ' + title
|
|
2924
3716
|
})
|
|
2925
|
-
app.addSystem(lines.length > 0 ? '
|
|
3717
|
+
app.addSystem(lines.length > 0 ? t('session.listHeader') + '\n' + lines.join('\n') : t('session.noPersisted'), 'info')
|
|
2926
3718
|
} catch (error) {
|
|
2927
|
-
app.addSystem('
|
|
3719
|
+
app.addSystem(t('session.listFailed', { error: formatError(error) }), 'error')
|
|
2928
3720
|
}
|
|
2929
3721
|
paint()
|
|
2930
3722
|
}
|
|
@@ -2933,6 +3725,9 @@ export function apply(ctx, config) {
|
|
|
2933
3725
|
if (!alreadyRequested && !interrupt.requestExit()) return
|
|
2934
3726
|
term.stop()
|
|
2935
3727
|
const exit = ctx.get('appExit')
|
|
3728
|
+
// Disconnect the MCP servers first: each one may own a child process that
|
|
3729
|
+
// has to be closed before the harness home stops being writable.
|
|
3730
|
+
void mcpManager.detachAgent()
|
|
2936
3731
|
const cleanup = handle ? handle.dispose().catch(() => undefined) : Promise.resolve()
|
|
2937
3732
|
cleanup.finally(() => {
|
|
2938
3733
|
if (exit) exit(0)
|
|
@@ -2956,13 +3751,7 @@ export function apply(ctx, config) {
|
|
|
2956
3751
|
// updates. Network failures are silently ignored — the Update page has a
|
|
2957
3752
|
// manual "Check now".
|
|
2958
3753
|
async function startupUpdateCheck() {
|
|
2959
|
-
|
|
2960
|
-
try {
|
|
2961
|
-
const settings = ctx.get('settings')
|
|
2962
|
-
const descriptor = settings?.describe?.({ redactSecrets: true })?.find((entry) => String(entry.ns) === 'tui-updates')
|
|
2963
|
-
startupCheck = descriptor?.value?.startupCheck ?? 'on'
|
|
2964
|
-
} catch { /* default on */ }
|
|
2965
|
-
if (startupCheck !== 'on') return
|
|
3754
|
+
if ((readTuiSetting(ctx, config, 'tui-updates', 'startupCheck') ?? 'on') !== 'on') return
|
|
2966
3755
|
const dshInstall = detectDshInstall()
|
|
2967
3756
|
const tuiInstalled = tuiInstalledVersion()
|
|
2968
3757
|
const [dshReg, tuiReg] = await Promise.all([
|
|
@@ -2979,7 +3768,7 @@ export function apply(ctx, config) {
|
|
|
2979
3768
|
if (status.kind === 'available') available.push('dsh-oc-tui ' + status.target)
|
|
2980
3769
|
}
|
|
2981
3770
|
if (available.length > 0) {
|
|
2982
|
-
app.showToast('
|
|
3771
|
+
app.showToast(t('session.updatesAvailable', { list: available.join(' · ') }))
|
|
2983
3772
|
paint()
|
|
2984
3773
|
}
|
|
2985
3774
|
}
|
|
@@ -3071,7 +3860,7 @@ export function apply(ctx, config) {
|
|
|
3071
3860
|
return { status: 'cancelled' }
|
|
3072
3861
|
}
|
|
3073
3862
|
}
|
|
3074
|
-
return { status: 'unavailable', reason: '
|
|
3863
|
+
return { status: 'unavailable', reason: t('session.unsupportedInteraction', { kind: String(request.kind) }) }
|
|
3075
3864
|
},
|
|
3076
3865
|
|
|
3077
3866
|
async notify(request) {
|
|
@@ -3085,7 +3874,7 @@ export function apply(ctx, config) {
|
|
|
3085
3874
|
// be pinned without a terminal; its comment there explains why private
|
|
3086
3875
|
// text must not reach the PowerShell fallback.
|
|
3087
3876
|
const ok = term.copyToClipboard(String(request.text), copyTextOptions(request))
|
|
3088
|
-
if (!ok) return { status: 'unavailable', reason: '
|
|
3877
|
+
if (!ok) return { status: 'unavailable', reason: t('session.noClipboard') }
|
|
3089
3878
|
return { status: 'submitted', value: { accepted: true } }
|
|
3090
3879
|
},
|
|
3091
3880
|
|
|
@@ -3093,10 +3882,14 @@ export function apply(ctx, config) {
|
|
|
3093
3882
|
// The TUI's own command line is served from the local switch in
|
|
3094
3883
|
// runCommand; this is the discoverable view of it. Descriptions mirror
|
|
3095
3884
|
// the manifest contributions in dsh-plugin.json.
|
|
3096
|
-
return TUI_OWNED_COMMANDS.map((name) =>
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3885
|
+
return TUI_OWNED_COMMANDS.map((name) => {
|
|
3886
|
+
// `command-list.js` stays import-free (it must not pull a peer in), so
|
|
3887
|
+
// the catalog is resolved here; the map is the English fallback for a
|
|
3888
|
+
// name the catalogs do not cover yet.
|
|
3889
|
+
const key = 'command.' + name
|
|
3890
|
+
const message = t(key)
|
|
3891
|
+
return { name, description: message === key ? (COMMAND_DESCRIPTIONS[name] ?? '') : message }
|
|
3892
|
+
})
|
|
3100
3893
|
},
|
|
3101
3894
|
|
|
3102
3895
|
async executeCommand(line) {
|
|
@@ -3122,9 +3915,11 @@ export function apply(ctx, config) {
|
|
|
3122
3915
|
process.on('SIGINT', onSigint)
|
|
3123
3916
|
return () => {
|
|
3124
3917
|
clearInterval(animationTimer)
|
|
3918
|
+
clearInterval(mcpPollTimer)
|
|
3125
3919
|
clearTimeout(startupCheckTimer)
|
|
3126
3920
|
process.off('exit', onExit)
|
|
3127
3921
|
process.off('SIGINT', onSigint)
|
|
3922
|
+
void mcpManager.detachAgent()
|
|
3128
3923
|
releaseLiveTui()
|
|
3129
3924
|
restore()
|
|
3130
3925
|
}
|