Skip to content

The agent that grows with you

fix(tui): this PR's Ink strings go through the i18n catalog

Teknium5eb20d269678
diff --git a/ui-tui/src/__tests__/canonicalI18n.test.ts b/ui-tui/src/__tests__/canonicalI18n.test.ts
new file mode 100644
index 00000000000..3437db30b56
--- /dev/null
+++ b/ui-tui/src/__tests__/canonicalI18n.test.ts
@@ -0,0 +1,42 @@
+import { mkdtemp, rm, writeFile } from 'node:fs/promises'
+import { join } from 'node:path'
+
+import { afterEach, expect, it } from 'vitest'
+
+import { canonicalRequest } from '../canonicalGateway.js'
+import { applyLocale, resetLocale } from '../i18n/runtime.js'
+import { stageImagePath } from '../lib/imageAttachments.js'
+
+// pastels §3: this PR's shared-gateway client text (image staging, launch-contract refusals) is
+// resolved through the catalog at call time, so an installed pack translates it.
+
+afterEach(() => resetLocale())
+
+it('shared-gateway refusals render from the active locale pack, English otherwise', async () => {
+ const contract = { sources: ['tui'], parameters: ['request_id', 'source'] }
+
+ const refusal = () => { try { canonicalRequest('session.create', { yolo: true }, contract);
+
+ return '' } catch (e) { return (e as Error).message } }
+
+ const dir = await mkdtemp(join(process.env.TMPDIR ?? '.', 'i18n-canonical-'))
+ const bogus = join(dir, 'not-an-image.png')
+
+ await writeFile(bogus, 'plain text')
+ const imageError = () => stageImagePath(bogus, {} as never, { sid: 's', profileHome: dir } as never).catch((e: Error) => e.message)
+
+ try {
+ expect(refusal()).toBe('gateway does not support TUI launch options: yolo')
+ expect(await imageError()).toBe('Unsupported image: expected PNG, JPEG, GIF, or WebP bytes')
+
+ applyLocale('xx', { lang: 'xx', surface: 'tui', messages: {
+ 'canonical.launch.unsupportedOptions': 'XX-launch {0}',
+ 'canonical.images.unsupported': 'XX-image'
+ } })
+
+ expect(refusal()).toBe('XX-launch yolo')
+ expect(await imageError()).toBe('XX-image')
+ } finally {
+ await rm(dir, { recursive: true, force: true })
+ }
+})
diff --git a/ui-tui/src/app/submissionCore.ts b/ui-tui/src/app/submissionCore.ts
index 5d83452c0f4..821afc81c6c 100644
--- a/ui-tui/src/app/submissionCore.ts
+++ b/ui-tui/src/app/submissionCore.ts
@@ -1,6 +1,7 @@
import type { GatewayClient } from '../gatewayClient.js'
import type { InputDetectDropResponse, PromptSubmitResponse, SessionActivateResponse } from '../gatewayTypes.js'
import type { QueueItem } from '../hooks/useQueue.js'
+import { t } from '../i18n/runtime.js'
import { stageImagePath } from '../lib/imageAttachments.js'
import { pendingInputOwner, savePendingInput } from '../lib/pendingInputs.js'
import type { Msg } from '../types.js'
@@ -147,7 +148,7 @@ function settleControlReply(
item.settle?.(accepted)
if (focused()) {
- deps.sys(accepted ? `correction ${control.status}` : 'correction rejected — input retained')
+ deps.sys(accepted ? t('canonical.submit.correction', control.status) : t('canonical.submit.correctionRejected'))
}
}
@@ -178,8 +179,8 @@ function settleAdmissionReply(item: QueueItem, r: PromptSubmitResponse, ctx: Adm
}
if (!accepted && focused()) {
- deps.sys('admission not confirmed — input retained; use Alt+K to retry with the same identity')
- patchUiState({ status: 'admission unconfirmed' })
+ deps.sys(t('canonical.submit.admissionNotConfirmed'))
+ patchUiState({ status: t('canonical.submit.statusAdmissionUnconfirmed') })
}
}
@@ -221,7 +222,7 @@ function refreshExecutionStatus({ deps, focused, owner, sid }: AdmissionContext)
})
.catch((error: Error) => {
if (focused()) {
- deps.sys(`execution status unconfirmed: ${error.message}`)
+ deps.sys(t('canonical.submit.executionUnconfirmed', error.message))
}
})
}
@@ -234,7 +235,7 @@ async function submitLegacy(
focused: () => boolean
): Promise<void> {
if (focused()) {
- deps.sys('durable admission unavailable for this session — using legacy delivery')
+ deps.sys(t('canonical.submit.legacyDelivery'))
}
try {
@@ -257,18 +258,16 @@ async function submitLegacy(
if (r?.voice_stopped) {
patchUiState({ busy: false, status: 'ready' })
} else if (!accepted) {
- deps.sys('legacy delivery unconfirmed — input retained; check the session before sending a new input')
- patchUiState({ status: 'delivery unconfirmed' })
+ deps.sys(t('canonical.submit.legacyUnconfirmed'))
+ patchUiState({ status: t('canonical.submit.statusDeliveryUnconfirmed') })
}
}
} catch (error) {
item.settle?.(false)
if (focused()) {
- deps.sys(
- `legacy delivery unconfirmed: ${error instanceof Error ? error.message : String(error)} — input retained; check the session before sending a new input`
- )
- patchUiState({ status: 'delivery unconfirmed' })
+ deps.sys(t('canonical.submit.legacyUnconfirmedWith', error instanceof Error ? error.message : String(error)))
+ patchUiState({ status: t('canonical.submit.statusDeliveryUnconfirmed') })
}
}
}
@@ -308,8 +307,8 @@ export function submitPrompt(
opts.queueItem.settle?.(false)
if (focused()) {
- deps.sys('delivery unconfirmed — check the session before sending a new input; retained input was not resent')
- patchUiState({ status: 'delivery unconfirmed' })
+ deps.sys(t('canonical.submit.deliveryNotResent'))
+ patchUiState({ status: t('canonical.submit.statusDeliveryUnconfirmed') })
}
return
@@ -335,7 +334,7 @@ export function submitPrompt(
item.settle?.(false)
if (focused()) {
- deps.sys('busy corrections accept text only — image input retained; submit it with /queue')
+ deps.sys(t('canonical.submit.busyTextOnly'))
}
return
@@ -381,8 +380,8 @@ export function submitPrompt(
item.settle?.(false)
if (focused()) {
- deps.sys(`input retained: ${e.message} — Alt+K retries the same submission`)
- patchUiState({ status: 'admission unconfirmed' })
+ deps.sys(t('canonical.submit.inputRetained', e.message))
+ patchUiState({ status: t('canonical.submit.statusAdmissionUnconfirmed') })
}
return
@@ -444,10 +443,10 @@ export function submitPrompt(
opts.queueItem?.settle?.(false)
if (focused()) {
- deps.sys(`image not submitted: ${error.message} — input retained`)
+ deps.sys(t('canonical.submit.imageNotSubmitted', error.message))
if (ownsTurn()) {
- patchUiState({ busy: false, status: 'image not submitted' })
+ patchUiState({ busy: false, status: t('canonical.submit.statusImageNotSubmitted') })
}
}
})
diff --git a/ui-tui/src/app/turnController.ts b/ui-tui/src/app/turnController.ts
index 60a7d05f457..946f24aa560 100644
--- a/ui-tui/src/app/turnController.ts
+++ b/ui-tui/src/app/turnController.ts
@@ -391,7 +391,7 @@ class TurnController {
}
} catch (error) {
if (isActiveTurn()) {
- sys(`interrupt failed: ${rpcErrorMessage(error)}`)
+ sys(t('canonical.submit.interruptFailed', rpcErrorMessage(error)))
}
return
diff --git a/ui-tui/src/app/useComposerState.ts b/ui-tui/src/app/useComposerState.ts
index e84df251751..f05ead69773 100644
--- a/ui-tui/src/app/useComposerState.ts
+++ b/ui-tui/src/app/useComposerState.ts
@@ -13,6 +13,7 @@ import type { ClipboardPasteResponse, ImageAttachResponse, InputDetectDropRespon
import { useCompletion } from '../hooks/useCompletion.js'
import { useInputHistory } from '../hooks/useInputHistory.js'
import { useQueue } from '../hooks/useQueue.js'
+import { t } from '../i18n/runtime.js'
import { isUsableClipboardText, readClipboardText } from '../lib/clipboard.js'
import { resolveEditor } from '../lib/editor.js'
import { stageClipboardImage, stageImagePath } from '../lib/imageAttachments.js'
@@ -302,7 +303,7 @@ export function useComposerState({ gw, submitRef, sys }: UseComposerStateOptions
})
).catch((error: Error) => {
if (!quiet) {
- sys(`clipboard image failed: ${error.message}`)
+ sys(t('canonical.queue.clipboardImageFailed', error.message))
}
return null
diff --git a/ui-tui/src/app/useSubmission.ts b/ui-tui/src/app/useSubmission.ts
index 17820315e2c..598adbddd40 100644
--- a/ui-tui/src/app/useSubmission.ts
+++ b/ui-tui/src/app/useSubmission.ts
@@ -7,6 +7,7 @@ import { completionToApplyOnSubmit } from '../domain/slash.js'
import type { GatewayClient } from '../gatewayClient.js'
import type { ShellExecResponse } from '../gatewayTypes.js'
import { queueItem, type QueueItem } from '../hooks/useQueue.js'
+import { t } from '../i18n/runtime.js'
import { asRpcResult } from '../lib/rpc.js'
import { hasInterpolation, INTERPOLATION_RE } from '../protocol/interpolation.js'
import type { Msg } from '../types.js'
@@ -340,8 +341,8 @@ export function useSubmission(opts: UseSubmissionOptions) {
return { value }
} catch (error) {
- sys(`input not saved: ${(error as Error).message} — draft kept`)
- patchUiState({ status: 'input not saved' })
+ sys(t('canonical.queue.notSavedDraftKept', (error as Error).message))
+ patchUiState({ status: t('canonical.queue.statusInputNotSaved') })
return undefined
}
diff --git a/ui-tui/src/canonicalGateway.ts b/ui-tui/src/canonicalGateway.ts
index 11c54932e59..e3e37bf0bc6 100644
--- a/ui-tui/src/canonicalGateway.ts
+++ b/ui-tui/src/canonicalGateway.ts
@@ -1,5 +1,7 @@
import { randomUUID } from 'node:crypto'
+import { t } from './i18n/runtime.js'
+
export interface SharedControl { session_id: string; execution_generation: number; prompt_id: string }
export const sharedControlParams = (prompt?: { sharedControl?: SharedControl } | null) => prompt?.sharedControl ?? {}
@@ -13,10 +15,10 @@ export function canonicalRequest(method: string, original: Record<string, unknow
params.source = 'tui'
params.request_id ??= randomUUID()
- if (!contract?.sources.includes('tui')) { throw new Error('gateway does not support tui session policy; update/restart the gateway') }
+ if (!contract?.sources.includes('tui')) { throw new Error(t('canonical.launch.noTuiPolicy')) }
const unsupported = Object.keys(params).filter(key => !contract.parameters.includes(key))
- if (unsupported.length) { throw new Error(`gateway does not support TUI launch options: ${unsupported.join(', ')}`) }
+ if (unsupported.length) { throw new Error(t('canonical.launch.unsupportedOptions', unsupported.join(', '))) }
}
if (['prompt.submit', 'session.steer', 'session.redirect'].includes(method) && params.submission_id) {
@@ -126,7 +128,7 @@ export function launchToolProgress(env = process.env): string | undefined {
if (!raw) { return undefined }
- if (!TOOL_PROGRESS_MODES.has(raw)) { throw new Error(`invalid HERMES_TUI_TOOL_PROGRESS: ${raw}`) }
+ if (!TOOL_PROGRESS_MODES.has(raw)) { throw new Error(t('canonical.launch.invalidToolProgress', raw)) }
return raw
}
diff --git a/ui-tui/src/components/branding.tsx b/ui-tui/src/components/branding.tsx
index cddfd2e612e..6ad258bdebb 100644
--- a/ui-tui/src/components/branding.tsx
+++ b/ui-tui/src/components/branding.tsx
@@ -213,7 +213,8 @@ const SKILLS_MAX = 8
const TOOLSETS_MAX = 8
export function SessionPanel({ info, maxWidth, sid, t }: SessionPanelProps) {
- const T = useT().chatBits.branding
+ const tr = useT()
+ const T = tr.chatBits.branding
const term = useStdout().stdout?.columns ?? 100
const cols = Math.max(20, Math.min(term, maxWidth ?? term))
const heroLines = caduceus(t.color, t.bannerHero || undefined)
@@ -259,10 +260,10 @@ export function SessionPanel({ info, maxWidth, sid, t }: SessionPanelProps) {
return (
<Box flexDirection="column">
<Text>
- <Text color={t.color.sessionLabel}>Session: </Text>
+ <Text color={t.color.sessionLabel}>{T.sessionLabel}</Text>
<Text color={t.color.sessionBorder}>{sid}</Text>
</Text>
- <Text color={t.color.muted}>Tool and skill inventory is not exposed by this runtime.</Text>
+ <Text color={t.color.muted}>{tr.canonical.launch.inventoryUnavailable}</Text>
</Box>
)
}
diff --git a/ui-tui/src/hooks/useQueue.ts b/ui-tui/src/hooks/useQueue.ts
index 68f4ec3c1cc..3232f98851f 100644
--- a/ui-tui/src/hooks/useQueue.ts
+++ b/ui-tui/src/hooks/useQueue.ts
@@ -6,6 +6,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { isServerQueued } from '../app/pendingBubbles.js'
import { captureDestination, type SubmissionDestination } from '../app/submissionDestination.js'
import { $uiState, getUiState, patchUiState } from '../app/uiStore.js'
+import { t } from '../i18n/runtime.js'
import {
loadPendingInputs,
pendingDestinationKey,
@@ -185,8 +186,8 @@ export function useQueue(gw?: { request: (method: string, params: Record<string,
const serverRows = (ui.info?.pending_submissions ?? []).filter(isServerQueued)
const queuedDisplay = [
- ...queueRef.current.map(item => `${item.failed ? '[unconfirmed · Alt+K retry] ' : ''}${item.display}`),
- ...serverRows.map(row => `[${row.status}] ${row.user}`)
+ ...queueRef.current.map(item => `${item.failed ? t('canonical.queue.unconfirmedPrefix') : ''}${item.display}`),
+ ...serverRows.map(row => t('canonical.queue.serverRow', String(row.status), String(row.user)))
]
// Indexes past the local items address server rows (read live, not from
@@ -217,7 +218,7 @@ export function useQueue(gw?: { request: (method: string, params: Record<string,
session_id, admission_id: row.admission_id,
...(unknown ? { execution_generation: row.execution_generation } : {})
}) ?? Promise.resolve()).catch((error: Error) => {
- if (getUiState().sid === session_id) { patchUiState({ status: `discard failed: ${error.message}` }) }
+ if (getUiState().sid === session_id) { patchUiState({ status: t('canonical.queue.discardFailed', error.message) }) }
throw error
})
@@ -307,7 +308,7 @@ export function useQueue(gw?: { request: (method: string, params: Record<string,
if (accepted) {
try { removePendingInput(item) } catch (error) {
- patchUiState({ status: `input delivered; journal cleanup failed: ${(error as Error).message}` })
+ patchUiState({ status: t('canonical.queue.journalCleanupFailed', (error as Error).message) })
}
for (const pending of queues.current.values()) {
@@ -383,7 +384,7 @@ export function useQueue(gw?: { request: (method: string, params: Record<string,
try {
return claim(queue, item)
} catch (error) {
- patchUiState({ status: `input not saved: ${(error as Error).message} — queue kept` })
+ patchUiState({ status: t('canonical.queue.notSavedQueueKept', (error as Error).message) })
return undefined
}
@@ -402,7 +403,7 @@ export function useQueue(gw?: { request: (method: string, params: Record<string,
// draft (Alt+K) instead of admitting a second copy behind the original.
if (server) {
if (server.status === 'unknown') {
- patchUiState({ status: 'unknown execution — Ctrl+X to discard before retrying' })
+ patchUiState({ status: t('canonical.queue.unknownExecution') })
return undefined
}
diff --git a/ui-tui/src/lib/imageAttachments.ts b/ui-tui/src/lib/imageAttachments.ts
index 97335a4ae11..baad940dd39 100644
--- a/ui-tui/src/lib/imageAttachments.ts
+++ b/ui-tui/src/lib/imageAttachments.ts
@@ -8,6 +8,7 @@ import { promisify } from 'node:util'
import type { SubmissionDestination } from '../app/submissionDestination.js'
import type { GatewayClient } from '../gatewayClient.js'
+import { t } from '../i18n/runtime.js'
export interface ImageAttachment { path: string; mime: string }
export interface StagedImage extends ImageAttachment { name: string; remainder?: string }
@@ -31,7 +32,7 @@ function imageFormat(bytes: Buffer): { mime: string; ext: string } {
return { mime: 'image/webp', ext: '.webp' }
}
- throw new Error('Unsupported image: expected PNG, JPEG, GIF, or WebP bytes')
+ throw new Error(t('canonical.images.unsupported'))
}
// Match an existing whole path first, so unquoted filenames with spaces survive.
@@ -57,7 +58,7 @@ async function resolveImagePath(raw: string): Promise<{ path: string; remainder:
if (!info.isFile()) { continue }
- if (info.size > MAX_IMAGE_BYTES) { throw new Error('Image exceeds 20 MiB upload limit') }
+ if (info.size > MAX_IMAGE_BYTES) { throw new Error(t('canonical.images.tooLarge')) }
return { path, remainder: remainder! }
} catch (error) {
@@ -65,7 +66,7 @@ async function resolveImagePath(raw: string): Promise<{ path: string; remainder:
}
}
- throw new Error(`Image not found: ${value}`)
+ throw new Error(t('canonical.images.notFound', value))
}
async function extractClipboardImage(path: string): Promise<boolean> {
@@ -98,7 +99,7 @@ export async function stageImagePath(raw: string, gw: GatewayClient, destination
const source = await resolveImagePath(raw)
const bytes = await readFile(source.path)
- if (bytes.length > MAX_IMAGE_BYTES) { throw new Error('Image exceeds 20 MiB upload limit') }
+ if (bytes.length > MAX_IMAGE_BYTES) { throw new Error(t('canonical.images.tooLarge')) }
const { mime, ext } = imageFormat(bytes)
const name = basename(source.path)
@@ -109,7 +110,7 @@ export async function stageImagePath(raw: string, gw: GatewayClient, destination
session_id: destination.sid, filename: `${randomUUID()}${ext}`, content_base64: bytes.toString('base64')
})
- if (!result?.path) { throw new Error('Image upload did not return an owner path') }
+ if (!result?.path) { throw new Error(t('canonical.images.noOwnerPath')) }
return { path: result.path, mime, name, remainder: source.remainder }
}
diff --git a/ui-tui/src/lib/pendingInputs.ts b/ui-tui/src/lib/pendingInputs.ts
index 212c9ab7e13..fa2f4ed7f83 100644
--- a/ui-tui/src/lib/pendingInputs.ts
+++ b/ui-tui/src/lib/pendingInputs.ts
@@ -15,6 +15,7 @@ import { join } from 'node:path'
import type { SubmissionDestination } from '../app/submissionDestination.js'
import type { QueueItem } from '../hooks/useQueue.js'
+import { t } from '../i18n/runtime.js'
const directory = (home?: string) =>
join(home ?? process.env.HERMES_HOME ?? join(homedir(), '.hermes'), 'tui-pending-inputs')
@@ -164,7 +165,7 @@ export function loadPendingInputs(destination: SubmissionDestination, durableRes
typeof record.text !== 'string' ||
typeof record.display !== 'string'
) {
- throw new Error(`Invalid pending input record: ${name}`)
+ throw new Error(t('canonical.queue.invalidRecord', name))
}
const owner = record.ownerDestination ?? record.destination