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)