@@ -797,7 +797,7 @@ otherwise returns COMMAND unchanged."
797797 (cons :command (map-nested-elt update '(rawInput command)))
798798 (cons :description (map-nested-elt update '(rawInput description)))
799799 (cons :content (map-elt update 'content )))
800- (when-let ((diff (agent-shell--make-diff-info ( map-elt update 'content ) )))
800+ (when-let ((diff (agent-shell--make-diff-info :tool-call update)))
801801 (list (cons :diff diff)))))
802802 (let ((tool-call-labels (agent-shell-make-tool-call-label
803803 state (map-elt update 'toolCallId ))))
@@ -906,7 +906,7 @@ otherwise returns COMMAND unchanged."
906906 " bash" ))
907907 (command (map-nested-elt update '(rawInput command))))
908908 (list (cons :title command)))
909- (when-let ((diff (agent-shell--make-diff-info ( map-elt update 'content ) )))
909+ (when-let ((diff (agent-shell--make-diff-info :tool-call update)))
910910 (list (cons :diff diff)))))
911911 (let* ((diff (map-nested-elt state `(:tool-calls ,.toolCallId :diff )))
912912 (output (concat
@@ -1026,7 +1026,8 @@ otherwise returns COMMAND unchanged."
10261026 (cons :status .params.toolCall.status)
10271027 (cons :kind .params.toolCall.kind)
10281028 (cons :permission-request-id .id))
1029- (when-let ((diff (agent-shell--make-diff-info .params.toolCall.content)))
1029+ (when-let ((diff (agent-shell--make-diff-info
1030+ :tool-call .params.toolCall)))
10301031 (list (cons :diff diff)))))
10311032 (agent-shell--update-fragment
10321033 :state state
@@ -1312,45 +1313,60 @@ Example output:
13121313 'font-lock-face 'font-lock-comment-face ))))
13131314 :joiner " \n " )))
13141315
1315- (defun agent-shell--make-diff-info (acp-content )
1316- " Make diff information from ACP's tool_call_update's ACP-CONTENT .
1316+ (cl- defun agent-shell--make-diff-info (& key tool-call )
1317+ " Make diff information from TOOL-CALL .
13171318
1318- CONTENT is of the the type ToolCallContent as per ACP spec:
1319+ TOOL-CALL is an ACP tool call object that may contain diff info in
1320+ either `content' (standard ACP format) or `rawInput' (eg. Copilot).
13191321
1320- https://agentclientprotocol.com/protocol/schema#toolcallcontent
1322+ Standard ACP format uses content with type \" diff\" containing
1323+ oldText/newText/path fields.
1324+
1325+ See https://agentclientprotocol.com/protocol/schema#toolcallcontent
1326+
1327+ Copilot sends old_str/new_str/path in rawInput instead.
1328+
1329+ See https://github.com/xenodium/agent-shell/issues/217
13211330
13221331Returns in the form:
13231332
13241333 `((:old . old-text)
13251334 (:new . new-text)
13261335 (:file . file-path))."
1327- (when-let* ((diff-item (cond
1328- ; ; Single diff object
1329- ((and acp-content (equal (map-elt acp-content 'type ) " diff" ))
1330- acp-content)
1331- ; ; TODO: Is this needed?
1332- ; ; Isn't acp-content always an alist?
1333- ; ; Vector/array acp-content - find diff item
1334- ((vectorp acp-content)
1335- (seq-find (lambda (item )
1336- (equal (map-elt item 'type ) " diff" ))
1337- acp-content))
1338- ; ; TODO: Is this needed?
1339- ; ; Isn't acp-content always an alist?
1340- ; ; List acp-content - find diff item
1341- ((listp acp-content)
1342- (seq-find (lambda (item )
1343- (equal (map-elt item 'type ) " diff" ))
1344- acp-content))))
1345- ; ; oldText can be nil for Write tools creating new files, default to ""
1346- ; ; TODO: Currently don't have a way to capture overwrites
1347- (old-text (or (map-elt diff-item 'oldText ) " " ))
1348- (new-text (map-elt diff-item 'newText ))
1349- (file-path (map-elt diff-item 'path )))
1350- (append (list (cons :old old-text)
1351- (cons :new new-text))
1352- (when file-path
1353- (list (cons :file file-path))))))
1336+ (let ((content (map-elt tool-call 'content ))
1337+ (raw-input (map-elt tool-call 'rawInput )))
1338+ (when-let* ((diff-item (cond
1339+ ; ; Single diff object
1340+ ((and content (equal (map-elt content 'type ) " diff" ))
1341+ content)
1342+ ; ; TODO: Is this needed?
1343+ ; ; Isn't content always an alist?
1344+ ; ; Vector/array content - find diff item
1345+ ((vectorp content)
1346+ (seq-find (lambda (item )
1347+ (equal (map-elt item 'type ) " diff" ))
1348+ content))
1349+ ; ; TODO: Is this needed?
1350+ ; ; Isn't content always an alist?
1351+ ; ; List content - find diff item
1352+ ((listp content)
1353+ (seq-find (lambda (item )
1354+ (equal (map-elt item 'type ) " diff" ))
1355+ content))
1356+ ; ; Copilot sends old_str/new_str in rawInput
1357+ ((and raw-input (map-elt raw-input 'new_str ))
1358+ `((oldText . ,(or (map-elt raw-input 'old_str ) " " ))
1359+ (newText . ,(map-elt raw-input 'new_str ))
1360+ (path . ,(map-elt raw-input 'path ))))))
1361+ ; ; oldText can be nil for Write tools creating new files, default to ""
1362+ ; ; TODO: Currently don't have a way to capture overwrites
1363+ (old-text (or (map-elt diff-item 'oldText ) " " ))
1364+ (new-text (map-elt diff-item 'newText ))
1365+ (file-path (map-elt diff-item 'path )))
1366+ (append (list (cons :old old-text)
1367+ (cons :new new-text))
1368+ (when file-path
1369+ (list (cons :file file-path)))))))
13541370
13551371
13561372(defun agent-shell--format-diff-as-text (diff )
0 commit comments