The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(tui): /save writes the session.export transcript locally
Teknium4eb2eea6b0be
diff --git a/ui-tui/src/__tests__/canonicalTuiOps.test.ts b/ui-tui/src/__tests__/canonicalTuiOps.test.tsindex e9df45df8ac..01f9681e968 100644--- a/ui-tui/src/__tests__/canonicalTuiOps.test.ts+++ b/ui-tui/src/__tests__/canonicalTuiOps.test.ts@@ -1,3 +1,7 @@+import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { beforeEach, expect, it, vi } from 'vitest'import { createSlashHandler } from '../app/createSlashHandler.js'@@ -46,14 +50,39 @@ beforeEach(() => {patchUiState({ sid: 'owner' })})-it('/save calls session.save on the shared gateway and reports the saved file', async () => {- const { request, slash, sys } = harness({ 'session.save': { file: '/home/u/.hermes/sessions/saved/x.json' } })+it('/save renders through session.export and Ink writes the file itself (T10)', async () => {+ const dir = mkdtempSync(join(process.env.TMPDIR || tmpdir(), 'ink-save-'))+ const saved = process.env.HERMES_HOME- slash('/save')- await flush()+ process.env.HERMES_HOME = dir++ try {+ const exported = { content: '{"messages": []}', filename: 'hermes_owner.json', format: 'json' }+ const { request, slash, sys } = harness({ 'session.export': exported })++ slash('/save')+ await flush()+ await flush()- expect(request).toHaveBeenCalledWith('session.save', { session_id: 'owner' })- expect(notices(sys)).toContain('conversation saved to: /home/u/.hermes/sessions/saved/x.json')+ expect(request).toHaveBeenCalledWith('session.export', { format: 'json', redact: false, session_id: 'owner' })+ expect(request.mock.calls.some(([method]) => method === 'session.save')).toBe(false)+ const [file] = readdirSync(join(dir, 'sessions', 'saved'))+ expect(file).toMatch(/^hermes_conversation_\d{8}_\d{6}\.json$/)+ expect(readFileSync(join(dir, 'sessions', 'saved', file!), 'utf8')).toBe('{"messages": []}')+ expect(notices(sys)).toContain(`conversation saved to: ${join(dir, 'sessions', 'saved', file!)}`)++ const md = { content: '# t', filename: 'hermes_owner.md', format: 'md' }+ const second = harness({ 'session.export': md })++ second.slash(`/save md ${join(dir, 'out.md')} redact`)+ await flush()+ await flush()+ expect(second.request).toHaveBeenCalledWith('session.export', { format: 'md', redact: true, session_id: 'owner' })+ expect(readFileSync(join(dir, 'out.md'), 'utf8')).toBe('# t')+ } finally {+ process.env.HERMES_HOME = saved+ rmSync(dir, { force: true, recursive: true })+ }})it('/reload calls reload.env for this session on the shared gateway and reports the count', async () => {diff --git a/ui-tui/src/app/slash/commands/core.ts b/ui-tui/src/app/slash/commands/core.tsindex 48e1ea66d87..02f9a5b6c15 100644--- a/ui-tui/src/app/slash/commands/core.ts+++ b/ui-tui/src/app/slash/commands/core.ts@@ -8,6 +8,7 @@ import type {ConfigFullResponse,ConfigGetValueResponse,ConfigSetResponse,+ SessionExportResponse,SessionSaveResponse,SessionStatusResponse,SessionSteerResponse,@@ -19,6 +20,7 @@ import type {import { t } from '../../../i18n/runtime.js'import { writeClipboardText } from '../../../lib/clipboard.js'import { writeOsc52Clipboard } from '../../../lib/osc52.js'+import { writeSessionExport } from '../../../lib/sessionExport.js'import {configureDetectedTerminalKeybindings,configureTerminalKeybindings,@@ -622,7 +624,7 @@ export const coreCommands: SlashCommand[] = [{help: 'save the current transcript to JSON',name: 'save',- run: (_arg, ctx) => {+ run: (arg, ctx) => {const hasConversation = ctx.local.getHistoryItems().some(m => m.role === 'user' || m.role === 'assistant' || m.role === 'tool')@@ -635,6 +637,33 @@ export const coreCommands: SlashCommand[] = [return ctx.transcript.sys(t('slashCmd.core.save.noActiveSession'))}+ // T10: the shared owner renders the transcript (session.export) and Ink writes the file on+ // the user's machine, as the classic CLI's `/save [json|md|html] [filename] [redact]` did.+ // The same verb serves a remote Desktop, where the gateway's disk is not the user's.+ if (ctx.gateway.gw?.isCanonical) {+ const parts = arg.trim().split(/\s+/).filter(Boolean)+ const redact = /^-{0,2}redact$/i.test(parts.at(-1) ?? '')++ if (redact) {+ parts.pop()+ }++ const [format = 'json', filename] = parts++ return void ctx.gateway+ .rpc<SessionExportResponse>('session.export', { format, redact, session_id: ctx.sid })+ .then(+ ctx.guarded<SessionExportResponse>(r => {+ try {+ ctx.transcript.sys(t('slashCmd.core.save.saved', writeSessionExport(r, filename)))+ } catch (e) {+ ctx.transcript.sys(`${t('slashCmd.core.save.failed')}: ${e instanceof Error ? e.message : String(e)}`)+ }+ })+ )+ .catch(ctx.guardedErr)+ }+ctx.gateway.rpc<SessionSaveResponse>('session.save', { session_id: ctx.sid }).then(diff --git a/ui-tui/src/gatewayTypes.ts b/ui-tui/src/gatewayTypes.tsindex 23ab3536d9d..b9551457dd0 100644--- a/ui-tui/src/gatewayTypes.ts+++ b/ui-tui/src/gatewayTypes.ts@@ -501,6 +501,12 @@ export interface ToolsConfigureResponse {// ── MCP ──────────────────────────────────────────────────────────────+export interface SessionExportResponse {+ content: string+ filename?: string+ format: string+}+export interface ReloadMcpResponse {status?: stringmessage?: stringdiff --git a/ui-tui/src/lib/sessionExport.ts b/ui-tui/src/lib/sessionExport.tsnew file mode 100644index 00000000000..608ca8ea688--- /dev/null+++ b/ui-tui/src/lib/sessionExport.ts@@ -0,0 +1,34 @@+import { mkdirSync, writeFileSync } from 'node:fs'+import { homedir } from 'node:os'+import { isAbsolute, join, resolve } from 'node:path'++export interface SessionExportPayload {+ content: string+ filename?: string+ format: string+}++const pad = (n: number) => String(n).padStart(2, '0')++/** `hermes_conversation_YYYYMMDD_HHMMSS.<fmt>`: the classic CLI's /save default name. */+export const defaultSaveName = (format: string, now = new Date()) =>+ `hermes_conversation_${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_` ++ `${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}.${format}`++/** Write a `session.export` payload on THIS machine (the client), never the gateway host: a named+ * file resolves against the cwd like the classic CLI, else `<HERMES_HOME>/sessions/saved/`.+ * Returns the absolute path written. */+export function writeSessionExport(payload: SessionExportPayload, filename?: string): string {+ const home = process.env.HERMES_HOME ?? join(homedir(), '.hermes')++ const path = filename+ ? isAbsolute(filename.replace(/^~(?=$|\/)/, homedir()))+ ? filename.replace(/^~(?=$|\/)/, homedir())+ : resolve(process.cwd(), filename)+ : join(home, 'sessions', 'saved', defaultSaveName(payload.format))++ mkdirSync(join(path, '..'), { recursive: true })+ writeFileSync(path, payload.content, 'utf8')++ return path+}diff --git a/website/docs/developer-guide/gateway-command-parity.md b/website/docs/developer-guide/gateway-command-parity.mdindex bf395ed3bd8..fa8c337ab16 100644--- a/website/docs/developer-guide/gateway-command-parity.md+++ b/website/docs/developer-guide/gateway-command-parity.md@@ -103,7 +103,7 @@ handler does; `client-local (cli_only)` commands are terminal/UI features of a c| `/retry` | refused | HermesCLI._cmd_retry | canonical route | action: retry | session.mutate rewind + resubmit | || `/review` | control | HermesCLI._handle_review_command | slash.exec | slash.exec | slash.exec | || `/rollback` | refused | HermesCLI._handle_rollback_command | rollback.diff, rollback.list, rollback.restore | slash.exec: refused | slash.exec: refused | restores filesystem checkpoints |-| `/save` | refused | HermesCLI.save_conversation | session.save | rpc session.save | slash.exec: refused | writes an export file on the gateway host |+| `/save` | refused | HermesCLI.save_conversation | canonical route | rpc session.save | slash.exec: refused | writes an export file on the gateway host || `/sessions` | refused | HermesCLI._handle_sessions_command | local | picker: session | slash.exec: refused | messaging origin-scoped listing (`/sessions all` needs a messaging admin) || `/sethome` (/set-home) | refused | messaging-only: unknown command | slash.exec: refused | unavailable: terminal | slash.exec: refused | messaging-only || `/skills` | read (bare/`pending`/`diff`; `approve`/`reject`/`approval` control; hub refused) | HermesCLI._cmd_skills | slash.exec; sidecar: skills.manage | slash.exec | slash.exec | client-local (cli_only) |