The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): /save always reports a failed write
Teknium3b23b5bf2b59
diff --git a/ui-tui/src/__tests__/canonicalTuiOps.test.ts b/ui-tui/src/__tests__/canonicalTuiOps.test.tsindex 5080283d749..d3ad4b899fc 100644--- a/ui-tui/src/__tests__/canonicalTuiOps.test.ts+++ b/ui-tui/src/__tests__/canonicalTuiOps.test.ts@@ -1,4 +1,4 @@-import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'+import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'@@ -122,6 +122,28 @@ it('/save still writes the file when another slash command starts before the exp}})+it('/save still reports a failed write after another slash command started', async () => {+ const dir = mkdtempSync(join(process.env.TMPDIR || tmpdir(), 'ink-save-fail-'))+ let finish!: (value: unknown) => void++ try {+ writeFileSync(join(dir, 'file'), '')+ const { request, slash, sys } = harness({ 'shared_metrics.slash_command': {} })++ request.mockImplementation(async (method: string) =>+ method === 'session.export' ? new Promise(resolve => (finish = resolve)) : {}+ )+ slash(`/save md ${join(dir, 'file', 'out.md')}`)+ slash('/timestamps status')+ finish({ content: 'X', filename: 'x.md', format: 'md' })+ await flush()+ await flush()+ expect(notices(sys).some(n => n.startsWith('failed to save: '))).toBe(true)+ } 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 d75418e04b7..e6d97ae7761 100644--- a/ui-tui/src/app/slash/commands/core.ts+++ b/ui-tui/src/app/slash/commands/core.ts@@ -684,7 +684,7 @@ export const coreCommands: SlashCommand[] = [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).+ // since (the stale-flight guard drops only the success notice; a failure always shows).return void ctx.gateway.rpc<SessionExportResponse>('session.export', { format, redact, session_id: ctx.sid }).then(r => {@@ -692,16 +692,14 @@ export const coreCommands: SlashCommand[] = [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)}`- }+ const notice = t('slashCmd.core.save.saved', writeSessionExport(r, filename, cwd))- if (!ctx.stale()) {- ctx.transcript.sys(notice)+ if (!ctx.stale()) {+ ctx.transcript.sys(notice)+ }+ } catch (e) {+ ctx.transcript.sys(`${t('slashCmd.core.save.failed')}: ${e instanceof Error ? e.message : String(e)}`)}}).catch(ctx.guardedErr)