From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: pareto optimal via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Need help interoperating between comint and CLI app's multi-line mode Date: Sun, 10 Dec 2023 12:21:30 +0100 (CET) Message-ID: <2084887661.816349.1702207290891@ichabod.co-bxl> Reply-To: pareto optimal Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40171"; mail-complaints-to="usenet@ciao.gmane.io" To: Help Gnu Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 11 06:30:04 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rCYrj-000ACT-DK for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 11 Dec 2023 06:30:03 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCYqk-0006Um-Li; Mon, 11 Dec 2023 00:29:02 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCHsS-0004oA-Tu for help-gnu-emacs@gnu.org; Sun, 10 Dec 2023 06:21:40 -0500 Original-Received: from wilbur.contactoffice.com ([212.3.242.68]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCHsQ-00047G-Gp for help-gnu-emacs@gnu.org; Sun, 10 Dec 2023 06:21:40 -0500 Original-Received: from ichabod.co-bxl (ichabod.co-bxl [10.2.0.36]) by wilbur.contactoffice.com (Postfix) with ESMTP id 75FDB2970 for ; Sun, 10 Dec 2023 12:21:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1702207292; s=20210208-e7xh; d=mailfence.com; i=pareto.optimal@mailfence.com; h=Date:Message-ID:MIME-Version:Content-Type:To:Subject:From; l=7191; bh=A9fQOeWZd4ddgVBrWSBeUbvN1uDT3Wn5BJQsH1CEOZw=; b=avUmPb0+3EfPXczW3X6hQ4UtmRX0yI8VXEBB5bNXI+Al0IiPp4IRexuu2IM9V1EI 8hkx6BepvmMOCsw1fOZMZ1n7tdFNDjeRhmL3KySBHeyoFuD5INed3OvCNnSQN/mF9HQ t6cqWYPopjOt8Dk9ZrUa+CCzGTcJ48cSw7DRhzEjKbr9B4t6YsU+PE53JkBzK24H7Kc 0OE3ipGADUCBSTKXI/MUMQR3AyPA4chw+fVcvXm21pQGBzEr7qel/qjbPmytEvm/1Qr RCWoc/mubQ3pxhq4RElRQTLBhBHhvv2Qain8su8krfMI/3p7yQ4tddy2+fqO9ussSXZ mv8j/1ZmFg== X-Mailer: ContactOffice Mail X-ContactOffice-Account: com:311504211 Received-SPF: pass client-ip=212.3.242.68; envelope-from=pareto.optimal@mailfence.com; helo=wilbur.contactoffice.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 11 Dec 2023 00:29:01 -0500 Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145636 Archived-At: Hello all, been stuck on this one for quite some hours :) I'm trying to make an inferior comint based mode for memgpt. In a terminal outside of emacs, when I use `memgpt run`, it has a special m= ulti-line mode you can enter with `//`. It looks like: ``` > Enter your message: // > Enter your message:=C2=A0 (Finish with 'Alt+Enter' or 'Esc then Enter') > =C2=A0 - say hi =C2=A0 - count to 10 =C2=A0 - say sayonara (I press Alt+enter) =F0=9F=92=AD User wants to say hi, count to 10, and say sayonara. Handling = the commands one by one. =F0=9F=A4=96 Hello! How are you doing today? I'm all ears. Oh, and one, two= , three... ``` The problem is in emacs if you just do something like this to run it with c= omint: ``` (progn =C2=A0 (make-comint "memgpt" "memgpt" nil "run" "--strip-ui") =C2=A0 (pop-to-buffer "*memgpt*")) ``` Then you go into multi-line mode, you'll get an error about `M-RET` not bei= ng bound. That's surmountable since I can bind `M-RET` to something. ``` (process-send-string "*memgpt*" "\e\r") ;; send escape codes for ESC enter = to underlying process ``` The problem is that process-send-string sends at the beginning of the line. I can prove that. Given comint buffer below and `|` denoting the cursor: ``` > Enter your message:=C2=A0 (Finish with 'Alt+Enter' or 'Esc then Enter') =C2=A0 - say hi =C2=A0 - count to 10 =C2=A0 - say sayonara| ``` Send: ``` (process-send-string "*memgpt*" "****") ``` and you get: ``` > Enter your message:=C2=A0 (Finish with 'Alt+Enter' or 'Esc then Enter') ****=C2=A0 - say hi =C2=A0 - count to 10 =C2=A0 - say sayonara ``` So when I send `(process-send-string "*memgpt*" "\e\r")` I predictably get = this result: ``` Empty input received. Try again! > Enter your message:=C2=A0 (Finish with 'Alt+Enter' or 'Esc then Enter') =C2=A0 - say hi =C2=A0 - count to 10 =C2=A0 - say sayonara ``` Well a little confusing since it puts the response above your input string. Then I went to the docs and found `comint-accumulate`. This is a not too ho= rrible workaround and does work, but the output is a little noisy and stran= ge if you don't know exactly whats happening: ``` > Enter your message:=C2=A0 (Finish with 'Alt+Enter' or 'Esc then Enter') =C2=A0 - say hi =C2=A0 - count to 10 =C2=A0 - say sayonara > =C2=A0=C2=A0=C2=A0 - say hi =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 - count to 10 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 - say sayonara =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 > Enter your message:=C2=A0 (Fin= ish with 'Alt+Enter' or 'Esc then Enter') > =C2=A0=C2=A0=C2=A0 - say hi =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 - count to 10 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 - say sayonara =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =F0=9F=92=AD INSERT silly wrong LLM output ``` Any guidance or advice would really help so I can have a comint memgpt that= isn't much more terrible to use than the normal version. Thanks!