The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): /save writes in the user's folder, survives the next slash, uses the owner's name
Teknium88071fa55047
diff --git a/ui-tui/src/__tests__/canonicalTuiOps.test.ts b/ui-tui/src/__tests__/canonicalTuiOps.test.tsindex 01f9681e968..5080283d749 100644--- a/ui-tui/src/__tests__/canonicalTuiOps.test.ts+++ b/ui-tui/src/__tests__/canonicalTuiOps.test.ts@@ -67,7 +67,7 @@ it('/save renders through session.export and Ink writes the file itself (T10)',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(file).toBe('hermes_owner.json') // the owner's name, so Ink and Desktop agreeexpect(readFileSync(join(dir, 'sessions', 'saved', file!), 'utf8')).toBe('{"messages": []}')expect(notices(sys)).toContain(`conversation saved to: ${join(dir, 'sessions', 'saved', file!)}`)@@ -85,6 +85,43 @@ it('/save renders through session.export and Ink writes the file itself (T10)',}})+it('/save resolves a relative name in the user\'s folder, not the install cwd Node runs in', async () => {+ const dir = mkdtempSync(join(process.env.TMPDIR || tmpdir(), 'ink-save-cwd-'))++ try {+ patchUiState({ info: { cwd: dir } as any })+ const { slash } = harness({ 'session.export': { content: 'REL', filename: 'x.md', format: 'md' } })++ slash('/save md rel-out.md')+ await flush()+ await flush()+ expect(readFileSync(join(dir, 'rel-out.md'), 'utf8')).toBe('REL')+ } finally {+ rmSync(dir, { force: true, recursive: true })+ }+})++it('/save still writes the file when another slash command starts before the export returns', async () => {+ const dir = mkdtempSync(join(process.env.TMPDIR || tmpdir(), 'ink-save-race-'))+ let finish!: (value: unknown) => void++ try {+ const { request, slash } = harness({ 'shared_metrics.slash_command': {} })++ request.mockImplementation(async (method: string) =>+ method === 'session.export' ? new Promise(resolve => (finish = resolve)) : {}+ )+ slash(`/save md ${join(dir, 'race.md')}`)+ slash('/timestamps status')+ finish({ content: 'RACE', filename: 'x.md', format: 'md' })+ await flush()+ await flush()+ expect(readFileSync(join(dir, 'race.md'), 'utf8')).toBe('RACE')+ } finally {+ rmSync(dir, { force: true, recursive: true })+ }+})+it('/reload calls reload.env for this session on the shared gateway and reports the count', async () => {const { request, slash, sys } = harness({ 'reload.env': { updated: 2 } })diff --git a/ui-tui/src/app/slash/commands/core.ts b/ui-tui/src/app/slash/commands/core.tsindex 3017cdd9a7b..ed0b808d2e4 100644--- a/ui-tui/src/app/slash/commands/core.ts+++ b/ui-tui/src/app/slash/commands/core.ts@@ -29,7 +29,7 @@ import {import type { Msg, PanelSection } from '../../../types.js'import type { StatusBarMode } from '../../interfaces.js'import { patchOverlayState } from '../../overlayStore.js'-import { patchUiState } from '../../uiStore.js'+import { patchUiState, sessionCwd } from '../../uiStore.js'import { canonicalRewind, canonicalTitle } from '../canonicalSessionCommands.js'import type { SlashCommand, SlashRunCtx } from '../types.js'@@ -675,18 +675,32 @@ export const coreCommands: SlashCommand[] = [}const [format = 'json', filename] = parts+ // The user's folder, fixed now: a local session's cwd, else the launch HERMES_CWD (a remote+ // session's folder names the gateway host's disk, not this one).+ const remote = Boolean(process.env.HERMES_TUI_GATEWAY_URL?.trim())+ const cwd = (remote ? process.env.HERMES_CWD : sessionCwd()) || process.cwd()+ // The write is the user's accepted request: it runs even when another slash has started+ // since (the stale-flight guard drops only the notice).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)}`)- }- })- )+ .then(r => {+ if (!r) {+ return+ }++ let notice: string++ try {+ notice = t('slashCmd.core.save.saved', writeSessionExport(r, filename, cwd))+ } catch (e) {+ notice = `${t('slashCmd.core.save.failed')}: ${e instanceof Error ? e.message : String(e)}`+ }++ if (!ctx.stale()) {+ ctx.transcript.sys(notice)+ }+ }).catch(ctx.guardedErr)}diff --git a/ui-tui/src/lib/sessionExport.ts b/ui-tui/src/lib/sessionExport.tsindex 608ca8ea688..a7abd8134b7 100644--- a/ui-tui/src/lib/sessionExport.ts+++ b/ui-tui/src/lib/sessionExport.ts@@ -1,6 +1,6 @@import { mkdirSync, writeFileSync } from 'node:fs'import { homedir } from 'node:os'-import { isAbsolute, join, resolve } from 'node:path'+import { basename, isAbsolute, join, resolve } from 'node:path'export interface SessionExportPayload {content: string@@ -16,16 +16,16 @@ export const defaultSaveName = (format: string, now = new Date()) =>`${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 {+ * file resolves against `cwd` (the user's launch folder: the launcher starts Node inside the+ * install), else `<HERMES_HOME>/sessions/saved/<the owner's filename>`. Returns the path written. */+export function writeSessionExport(payload: SessionExportPayload, filename?: string, cwd = process.cwd()): 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))+ : resolve(cwd, filename)+ : join(home, 'sessions', 'saved', basename(payload.filename || defaultSaveName(payload.format)))mkdirSync(join(path, '..'), { recursive: true })writeFileSync(path, payload.content, 'utf8')