Prefer work buffers to temp buffers
The macro with-work-buffer is much more efficient than with-temp-buffer as it reuses buffers from a shared pool and eliminates gc pressure.
Despite work buffers being new to Emacs 31, the Emacs compat library supports with-work-buffer so perhaps backward compatibility is solved and no agent-shell wrapper is needed to switch to work buffers. See https://github.com/emacs-compat/compat/blob/a0d646554730471579de8b33b0194077fd05abe1/compat-31.el#L387
Thanks! Added in https://github.com/xenodium/agent-shell/commit/0904a247abc2ed286e76370861f231f3bd3e49db
This broke agent-shell for me in Emacs GNU Emacs 30.2 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.4, Xaw3d scroll bars). The debug error is below. Curiously, it complains about the function being invalid yet can navigate to it. Pinning to the previous commit resolved the issue.
Debugger entered--Lisp error: (invalid-function with-work-buffer)
with-work-buffer(nil nil 789 "")
agent-shell-ui--required-newlines(2)
agent-shell-ui-update-fragment(((:namespace-id . "bootstrapping") (:block-id . "starting") (:label-left . #(" … Starting agent" 0 3 (font-lock-face ((warning (:inverse-video t)) default)) 4 18 (font-lock-face font-lock-doc-markup-face))) (:label-right) (:body . "Creating client...")) :navigation nil :append nil :create-new t :expanded nil :no-undo t)
agent-shell--update-fragment(:state ((:agent-config (:identifier . claude-code) (:mode-line-name . "Claude") (:welcome-function . agent-shell-anthropic--claude-code-welcome-message) (:buffer-name . "Claude") (:shell-prompt . "Claude> ") (:shell-prompt-regexp . "Claude> ") (:client-maker . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>) (:needs-authentication) (:authenticate-request-maker) (:default-model-id . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_6>) (:default-session-mode-id . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_7>) (:icon-name . "claudecode.png") (:install-instructions . "See https://github.com/agentclientprotocol/claude-agent-acp for installation.")) (:buffer . #<buffer Claude Agent @ tom>) (:client) (:client-maker . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>) (:outgoing-request-decorator) (:heartbeat (:heartbeat-timer . [nil 27213 659 301054 0.1 #f(compiled-function () #<bytecode 0x4060d642f711dae>) nil nil 710000 nil]) (:beats-per-second . 10) (:on-heartbeat . #f(compiled-function (heartbeat status) #<bytecode -0x13b9a336866230d2>)) (:value . 0) (:status . started)) (:initialized) (:needs-authentication) (:authenticate-request-maker) (:authenticated) (:set-model) (:set-session-mode) (:session (:id) (:config-options) (:model-id) (:models) (:mode-id) (:modes) (:title)) (:config-options) (:last-entry-type) (:chunked-group-count . 0) (:request-count . 0) (:last-activity-time 27213 659 301039 539000) (:tool-calls) (:available-commands) (:available-modes) (:supports-session-list) (:supports-session-load) (:supports-session-resume) (:supports-session-fork) (:resume-session-id) (:fork-session-id) (:pending-restore) (:prompt-capabilities) (:event-subscriptions) (:idle-timer) (:sleep-token) (:active-requests) (:pending-requests) (:usage (:total-tokens . 0) (:input-tokens . 0) (:output-tokens . 0) (:thought-tokens . 0) (:cached-read-tokens . 0) (:cached-write-tokens . 0) (:context-used . 0) (:context-size . 0) (:cost-amount . 0.0) (:cost-currency))) :namespace-id "bootstrapping" :block-id "starting" :label-left #(" … Starting agent" 0 3 (font-lock-face ((warning (:inverse-video t)) default)) 4 18 (font-lock-face font-lock-doc-markup-face)) :body "Creating client..." :create-new t)
agent-shell--initialize-client()
agent-shell--handle(:shell-buffer #<buffer Claude Agent @ tom>)
agent-shell--start(:config ((:identifier . claude-code) (:mode-line-name . "Claude") (:welcome-function . agent-shell-anthropic--claude-code-welcome-message) (:buffer-name . "Claude") (:shell-prompt . "Claude> ") (:shell-prompt-regexp . "Claude> ") (:client-maker . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>) (:needs-authentication) (:authenticate-request-maker) (:default-model-id . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_6>) (:default-session-mode-id . #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_7>) (:icon-name . "claudecode.png") (:install-instructions . "See https://github.com/agentclientprotocol/claude-agent-acp for installation.")) :no-focus t :new-session t :session-strategy prompt)
agent-shell--shell-buffer()
agent-shell--dwim()
agent-shell(nil)
funcall-interactively(agent-shell nil)
command-execute(agent-shell record)
execute-extended-command(nil "agent-shell" "e")
funcall-interactively(execute-extended-command nil "agent-shell" "e")
command-execute(execute-extended-command)
@tdavis Do you have compat installed?
Yes, version 31 is in my elpa packages. I can even manually eval (with-work-buffer) without error.
May be a byte-compilation issue. Having said that, I'd rather avoid these kinds of issues, so I'm removing the compat dependency and only use work buffers when available https://github.com/xenodium/agent-shell/commit/41a2fa7cc606f6fc1e72ae7c87c4f40b9bd93236
You're awesome, thanks! I love agent-shell, it's so nice to stay in emacs. ❤️
I love agent-shell, it's so nice to stay in emacs. ❤️
Glad to hear it! If you're in a position to do so, please consider sponsoring to make the effort sustainable. Better yet, get your employer to do so.