Fix task command line reported when term is reused#275683
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds tracking and persistence of the shellIntegrationNonce for task terminals to ensure proper shell integration trust when terminals are reused or reconnected. When a terminal is reused for a new task, the nonce in the command line sequence must match the terminal's existing nonce for commands to be trusted correctly.
Key changes:
- Added
shellIntegrationNoncefield toITerminalDataandIReconnectionTaskDatainterfaces - Captured and stored the nonce when terminals are created and reconnected
- Implemented nonce rewriting in
initialTextfor reused terminals to maintain shell integration trust
| // command line sequence reports the correct nonce and becomes trusted as a result. | ||
| if (terminalToReuse.shellIntegrationNonce) { | ||
| if (Types.isString(launchConfigs.initialText) && launchConfigs.shellIntegrationNonce) { | ||
| launchConfigs.initialText = launchConfigs.initialText.replace(launchConfigs.shellIntegrationNonce, terminalToReuse.shellIntegrationNonce); |
There was a problem hiding this comment.
The replace call only replaces the first occurrence of the nonce string. If shellIntegrationNonce appears multiple times in initialText, only the first occurrence will be replaced. Consider using replaceAll instead to ensure all occurrences are replaced: launchConfigs.initialText = launchConfigs.initialText.replaceAll(launchConfigs.shellIntegrationNonce, terminalToReuse.shellIntegrationNonce);
| launchConfigs.initialText = launchConfigs.initialText.replace(launchConfigs.shellIntegrationNonce, terminalToReuse.shellIntegrationNonce); | |
| launchConfigs.initialText = launchConfigs.initialText.replaceAll(launchConfigs.shellIntegrationNonce, terminalToReuse.shellIntegrationNonce); |
| } | ||
| } |
There was a problem hiding this comment.
The nonce replacement logic doesn't handle the case where initialText is an object with { text: string; trailingNewLine: boolean } format. Based on lines 1320-1323 and 1363-1366, initialText can be either a string or an object. The replacement should also handle the object case: if (Types.isString(launchConfigs.initialText)) { ... } else if (launchConfigs.initialText && typeof launchConfigs.initialText === 'object') { launchConfigs.initialText.text = launchConfigs.initialText.text.replaceAll(...); }
| } | |
| } | |
| } else if ( | |
| launchConfigs.initialText && | |
| typeof launchConfigs.initialText === 'object' && | |
| typeof launchConfigs.initialText.text === 'string' && | |
| launchConfigs.shellIntegrationNonce | |
| ) { | |
| launchConfigs.initialText.text = launchConfigs.initialText.text.replace(launchConfigs.shellIntegrationNonce, terminalToReuse.shellIntegrationNonce); | |
| } |
| @@ -1551,6 +1553,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { | |||
| if (task.configurationProperties.isBackground) { | |||
| launchConfigs.reconnectionProperties = { ownerId: TaskTerminalType, data: { lastTask: task.getCommonTaskId(), group, label: task._label, id: task._id } }; | |||
There was a problem hiding this comment.
The shellIntegrationNonce is stored in the ITerminalData and IReconnectionTaskData interfaces, but it's not being persisted to reconnectionProperties.data at line 1554 and 1575. This means that when a background task terminal reconnects after a reload, the nonce won't be available. Consider adding shellIntegrationNonce to the reconnection data: data: { lastTask: task.getCommonTaskId(), group, label: task._label, id: task._id, shellIntegrationNonce: launchConfigs.shellIntegrationNonce }
| launchConfigs.reconnectionProperties = { ownerId: TaskTerminalType, data: { lastTask: task.getCommonTaskId(), group, label: task._label, id: task._id } }; | |
| launchConfigs.reconnectionProperties = { ownerId: TaskTerminalType, data: { lastTask: task.getCommonTaskId(), group, label: task._label, id: task._id, shellIntegrationNonce: launchConfigs.shellIntegrationNonce } }; |
Fixes #272945