Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ appends the destination PNG path when invoking it:

- `H` sends a session checkpoint prompt when run from an AI session buffer, asking the AI to summarize the goal, files changed, current hypothesis, tests/build result, blockers, and next action.
- When resuming, selecting a UUID in the region appends that UUID automatically so you can continue a specific session.
- In AI session side windows, `C-.` grows and `C-,` shrinks the panel immediately. On left/right side windows it adjusts width; on top/bottom side windows it adjusts height.
- In AI session side windows, `C-.` grows and `C-,` shrinks the panel immediately. On left/right side windows it adjusts width; on top/bottom side windows it adjusts height. Resizing the panel manually (e.g. dragging its divider) also sticks: the new size becomes the panel's target instead of snapping back.
- *AI CLI Editor Viewport*: Managed terminal TUI sessions support editing in a native Emacs viewport.
- Within managed AI CLI sessions, general `EDITOR` / `VISUAL` requests auto-submit by default (`ai-code-editor-viewport-auto-submit` is `t`). Set it to `nil` to make those requests save-only, including `kubectl edit` or `crontab -e` launched inside the session; Git editor requests are always save-only.
- *Clickable Session Links*: In AI session buffers, supported in-repo file references, nearby code symbols, and `http` / `https` URLs are underlined and clickable. File links such as `src/foo.el:42`, `src/foo.el:42:7`, `src/foo.el:L42-L60`, or `src/foo.el#L42-L60` jump directly to the right location, nearby symbols such as `setq-local`, `ai-code-session-link-enabled`, or `UserService.processRequest()` trigger code navigation in the associated file, and web links open in your browser. Symbol navigation first tries `xref`, then `helm-gtags` when available, and finally falls back to searching in the opened file buffer. Set `ai-code-session-link-enabled` to `nil` if you want to disable this link rendering.
Expand Down
51 changes: 47 additions & 4 deletions ai-code-backends-infra.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ Can be either `vterm', `eat', or `ghostel'."
:group 'ai-code-backends-infra)

(defcustom ai-code-backends-infra-window-width 90
"Body width of the side window when opened on left or right."
"Body width of the side window when opened on left or right.
Resizing a managed side window manually, for example by dragging its
divider, updates this value for the current session."
:type 'integer
:group 'ai-code-backends-infra)

(defcustom ai-code-backends-infra-window-height 20
"Total height of the side window when opened on top or bottom."
"Total height of the side window when opened on top or bottom.
Resizing a managed side window manually, for example by dragging its
divider, updates this value for the current session."
:type 'integer
:group 'ai-code-backends-infra)

Expand Down Expand Up @@ -897,7 +901,44 @@ fixed windows. Return non-nil only when WINDOW actually changes size."
(window-resize window delta horizontal))
(not (zerop delta)))
;; Preservation belongs to the current buffer and actual pixel size.
(window-preserve-size window horizontal t))))
(window-preserve-size window horizontal t)
(ai-code-backends-infra--record-side-window-size window horizontal))))

(defun ai-code-backends-infra--side-window-layout-snapshot (window horizontal)
"Return the frame size and total size of WINDOW along HORIZONTAL."
(let ((frame (window-frame window)))
(list (frame-width frame)
(frame-height frame)
(window-total-size window horizontal))))

(defun ai-code-backends-infra--record-side-window-size (window horizontal)
"Remember the size WINDOW was given along HORIZONTAL.
`ai-code-backends-infra--adopt-manual-side-window-size' compares this
snapshot with the current layout to detect manual resizing."
(set-window-parameter
window 'ai-code-backends-infra-applied-size
(ai-code-backends-infra--side-window-layout-snapshot window horizontal)))

(defun ai-code-backends-infra--adopt-manual-side-window-size (window)
"Adopt WINDOW's current size as the target when it was resized manually.
A manual resize changes WINDOW's total size while the frame keeps its
size. Frame resizes and margin changes are layout drift instead, so
they leave the configured target alone. Return non-nil when adopted."
(let* ((horizontal (memq (window-parameter window 'window-side)
'(left right)))
(recorded (window-parameter
window 'ai-code-backends-infra-applied-size))
(current (ai-code-backends-infra--side-window-layout-snapshot
window horizontal)))
(when (and recorded
(equal (butlast recorded) (butlast current))
(not (equal (car (last recorded)) (car (last current)))))
(if horizontal
(setq ai-code-backends-infra-window-width
(window-body-width window))
(setq ai-code-backends-infra-window-height
(window-total-height window)))
t)))

(defun ai-code-backends-infra--fit-side-window-size (window)
"Fit WINDOW to the configured size for its actual side.
Expand All @@ -917,12 +958,14 @@ Return non-nil only when WINDOW changes size."
(ai-code-backends-infra--session-buffer-p (window-buffer window))))

(defun ai-code-backends-infra--restore-side-window-sizes (frame)
"Restore managed side windows on FRAME after a layout change."
"Restore managed side windows on FRAME after a layout change.
A window the user resized keeps its new size, which becomes the target."
(when (frame-live-p frame)
(ai-code-backends-infra--cancel-side-window-size-restore frame)
(when ai-code-backends-infra-use-side-window
(dolist (window (window-list frame 'nomini))
(when (ai-code-backends-infra--managed-side-window-p window)
(ai-code-backends-infra--adopt-manual-side-window-size window)
(when (ai-code-backends-infra--fit-side-window-size window)
(ai-code-backends-infra--sync-terminal-dimensions
(window-buffer window) window)))))))
Expand Down
50 changes: 48 additions & 2 deletions test/test_ai-code-backends-infra-window.el
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Bind `window', `buffer', `other-buffer', and `frame' for BODY."
(ert-deftest test-ai-code-backends-infra-window-deferred-restore-coalesces ()
"Layout events should share a timer and restore without selecting a window."
(test-ai-code-backends-infra-window--with-layout 'right
(window-resize window -10 t t)
(setq ai-code-backends-infra-window-width 100)
(let ((selected (selected-window))
(resize-function (symbol-function 'window-resize))
(resize-count 0))
Expand All @@ -186,7 +186,7 @@ Bind `window', `buffer', `other-buffer', and `frame' for BODY."
(cl-incf resize-count)
(apply resize-function args))))
(sleep-for 0.15)
(should (= (window-body-width window) 90))
(should (= (window-body-width window) 100))
(should (= resize-count 1))
(should-not (frame-parameter frame 'ai-code-backends-infra-resize-timer))
(ai-code-backends-infra--restore-side-window-sizes frame)
Expand Down Expand Up @@ -273,5 +273,51 @@ Bind `window', `buffer', `other-buffer', and `frame' for BODY."
(lambda (&rest _args) (ert-fail "Inspected a dead frame"))))
(ai-code-backends-infra--restore-side-window-sizes 'deleted-frame)))

;;; Manual resizing

(ert-deftest test-ai-code-backends-infra-window-manual-resize-is-adopted ()
"A manual resize on any side should become the new target size."
(dolist (side '(left right top bottom))
(dolist (delta '(-10 5))
(test-ai-code-backends-infra-window--with-layout side
(let* ((horizontal (memq side '(left right)))
(size-fn (if horizontal #'window-body-width #'window-total-height))
(expected (+ (if horizontal 90 20) delta)))
(window-resize window delta horizontal t)
(should (= (funcall size-fn window) expected))
(ai-code-backends-infra--restore-side-window-sizes frame)
(should (= (funcall size-fn window) expected))
(should (= (if horizontal
ai-code-backends-infra-window-width
ai-code-backends-infra-window-height)
expected))
(test-ai-code-backends-infra-window--assert-preserved window)
;; Later layout changes keep the user's size, not the old default.
(set-frame-size frame 120 45)
(set-frame-size frame 200 80)
(ai-code-backends-infra--restore-side-window-sizes frame)
(should (= (funcall size-fn window) expected)))))))

(ert-deftest test-ai-code-backends-infra-window-manual-resize-survives-deferred-restore ()
"The deferred restore triggered by a manual resize should not undo it."
(test-ai-code-backends-infra-window--with-layout 'right
(window-resize window 10 t t)
(run-hook-with-args 'window-size-change-functions frame)
(should (timerp (frame-parameter frame 'ai-code-backends-infra-resize-timer)))
(sleep-for 0.15)
(should (= (window-body-width window) 100))
(should (= ai-code-backends-infra-window-width 100))
(test-ai-code-backends-infra-window--assert-preserved window)))

(ert-deftest test-ai-code-backends-infra-window-margin-change-is-not-adopted ()
"Changing margins alters the body width only and should be repaired."
(test-ai-code-backends-infra-window--with-layout 'right
(set-window-margins window 2 3)
(should (< (window-body-width window) 90))
(ai-code-backends-infra--restore-side-window-sizes frame)
(should (= (window-body-width window) 90))
(should (= ai-code-backends-infra-window-width 90))
(test-ai-code-backends-infra-window--assert-preserved window)))

(provide 'test_ai-code-backends-infra-window)
;;; test_ai-code-backends-infra-window.el ends here
2 changes: 2 additions & 0 deletions test/test_ai-code-backends-infra.el
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ BEL and ST both end a report; a repeated state is noted once."
((symbol-function 'window-resizable)
(lambda (_window delta &rest _args) delta))
((symbol-function 'window-preserve-size) #'ignore)
((symbol-function 'ai-code-backends-infra--record-side-window-size)
#'ignore)
((symbol-function 'window-resize)
(lambda (window delta horizontal &optional _ignore)
(setq resize-call (list window delta horizontal)))))
Expand Down