From 5ae96d4e9e0eeebddf545f2d85431ae6f48f76dc Mon Sep 17 00:00:00 2001 From: Joey Guerra Date: Wed, 14 Aug 2024 16:14:06 -0500 Subject: [PATCH] fix: Shell adapter history is not persisting --- src/adapters/Shell.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/adapters/Shell.mjs b/src/adapters/Shell.mjs index 860e65bbb..5e4bcb32e 100644 --- a/src/adapters/Shell.mjs +++ b/src/adapters/Shell.mjs @@ -92,9 +92,15 @@ class Shell extends Adapter { await this.receive(message) this.#rl.prompt() }) + this.#rl.on('history', async (history) => { - await fs.promises.writeFile(historyPath, history.reverse().join('\n')) + if (history.length === 0) return + await fs.promises.appendFile(historyPath, `${history[0]}\n`) }) + + let existingHistory = (await fs.promises.readFile(historyPath, 'utf8')).split('\n') + existingHistory.forEach(line => this.#rl.history.push(line)) + try { this.#rl.prompt() this.emit('connected', this)