Add @ pane selector for agent context injection#313
Conversation
Users can type @n or @title in the agent input to attach a specific terminal pane's recent output to their message. Each @-token is resolved by the ACP client task: @1, @2, etc. select by 1-based index within the current tab's pane list; @build, @PowerShell, etc. match by pane title prefix (case-insensitive). Matched pane output is injected as a '### Pane Context (@ref)' section in the prompt body so the agent can reason about any named pane, not only the active working pane. Closes microsoft#194
|
@ashishpatel26 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for @-mention pane references in user prompts by extracting tokens in the UI layer, resolving them to WT panes in the ACP client, and injecting the referenced pane’s recent output into the prompt.
Changes:
- Added
PaneContext.at_pane_refsplusextract_at_refs()to collect@pane/@1tokens from user text. - Implemented pane reference resolution (
resolve_at_pane_ref) and prompt context injection inbuild_prompt_text. - Updated prompt/autofix context construction and added unit tests for the new parsing/resolution helpers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tools/wta/src/protocol/acp/client.rs | Resolve @ pane refs to WT pane IDs and inject referenced pane output into prompts; adds tests. |
| tools/wta/src/pane_context.rs | Adds at_pane_refs to PaneContext and implements parsing of @word tokens with tests. |
| tools/wta/src/app/autofix.rs | Initializes new PaneContext.at_pane_refs field for autofix flows. |
| tools/wta/src/app.rs | Extracts @ refs from user input and populates PaneContext.at_pane_refs. |
| pub fn extract_at_refs(text: &str) -> Vec<String> { | ||
| let mut seen = std::collections::HashSet::new(); | ||
| let mut result = Vec::new(); | ||
| let chars: Vec<char> = text.chars().collect(); | ||
| let mut i = 0; | ||
| while i < chars.len() { | ||
| if chars[i] == '@' { | ||
| let start = i + 1; | ||
| let mut end = start; | ||
| // Consume word chars: letters, digits, hyphens, underscores. | ||
| while end < chars.len() | ||
| && (chars[end].is_alphanumeric() || chars[end] == '-' || chars[end] == '_') | ||
| { | ||
| end += 1; | ||
| } |
| fn resolve_at_pane_ref(token: &str, pane_list: Option<&serde_json::Value>) -> Option<String> { | ||
| let list = pane_list?; | ||
| let panes = list.get("panes")?.as_array()?; | ||
|
|
||
| // Numeric index (1-based)? | ||
| if let Ok(idx) = token.parse::<usize>() { | ||
| if idx > 0 { | ||
| return panes | ||
| .get(idx - 1) | ||
| .and_then(|p| json_str_or_num(p.get("session_id"))); | ||
| } | ||
| } | ||
|
|
||
| // Title prefix match (case-insensitive). | ||
| let needle = token.to_ascii_lowercase(); | ||
| for pane in panes { | ||
| let title = pane | ||
| .get("title") | ||
| .and_then(|v| v.as_str()) | ||
| .unwrap_or("") | ||
| .to_ascii_lowercase(); | ||
| if !title.is_empty() && title.starts_with(&needle) { | ||
| return json_str_or_num(pane.get("session_id")); | ||
| } | ||
| } | ||
| None | ||
| } |
| let at_refs = pane_context | ||
| .map(|c| c.at_pane_refs.clone()) | ||
| .unwrap_or_default(); |
| for at_ref in &at_refs { | ||
| let token = at_ref.trim_start_matches('@'); | ||
| // Resolve to a pane id: first try numeric index, then title prefix. | ||
| let resolved_pane_id = resolve_at_pane_ref(token, pane_list.as_ref()); | ||
| if let Some(pane_id) = resolved_pane_id { | ||
| tracing::debug!( | ||
| target: "acp.terminal_context", | ||
| at_ref = %at_ref, | ||
| pane_id = %pane_id, | ||
| "at_ref_pane_resolved" | ||
| ); | ||
| if let Some(content) = read_pane_last_message( | ||
| shell_mgr, | ||
| &pane_id, | ||
| 30, | ||
| ACTIVE_PANE_CONTEXT_MAX_CHARS, | ||
| ) | ||
| .await | ||
| { |
| runtime_sections.push(format!( | ||
| "### Pane Context ({})\n```\n{}\n```", |
| /// Resolution rules (first match wins): | ||
| /// 1. If `token` is a non-zero unsigned integer N, return the N-th pane | ||
| /// (1-based) from the `panes` array. | ||
| /// 2. Otherwise case-insensitively prefix-match the `title` field of each |
@check-spelling-bot Report
|
| Dictionary | Entries | Covers | Uniquely |
|---|---|---|---|
| cspell:csharp/csharp.txt | 32 | 2 | 2 |
| cspell:aws/aws.txt | 232 | 2 | 2 |
| cspell:fonts/fonts.txt | 536 | 1 | 1 |
Consider adding to the extra_dictionaries array (in the .github/actions/spelling/config.json file):
"cspell:csharp/csharp.txt",
"cspell:aws/aws.txt",
"cspell:fonts/fonts.txt",
To stop checking additional dictionaries, put (in the .github/actions/spelling/config.json file):
"check_extra_dictionaries": []Forbidden patterns 🙅 (2)
In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.
These forbidden patterns matched content:
Should probably be Otherwise,
(?<=\. )Otherwise\s
Should be reentrancy
[Rr]e[- ]entrancy
Errors and Warnings ❌ (2)
See the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.
| ❌ Errors and Warnings | Count |
|---|---|
| 54 | |
| ❌ forbidden-pattern | 2 |
See ❌ Event descriptions for more information.
✏️ Contributor please read this
By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
- ... misspelled, then please correct them instead of using the command.
- ... names, please add them to
.github/actions/spelling/allow/names.txt. - ... APIs, you can add them to a file in
.github/actions/spelling/allow/. - ... just things you're using, please add them to an appropriate file in
.github/actions/spelling/expect/. - ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in
.github/actions/spelling/patterns/.
See the README.md in each directory for more information.
🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉
If the flagged items are 🤯 false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it,
try adding it to thepatterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
|
@microsoft-github-policy-service agree |
Closes #194
Summary
@1,@2(1-based pane index) or@build,@powershell(title prefix) anywhere in their agent message to attach that pane's recent output as context@-tokens are parsed at submit time inapp.rsvia the newextract_at_refsfunction inpane_context.rsbuild_prompt_textinside the ACP client task:wt_list_panesis called for the current tab, then each token is matched by index or case-insensitive title prefix### Pane Context (@ref)section in the prompt body — the agent sees the raw text the user typed (e.g. "look at @pane2") plus the pane's content@-token extraction is deduplicated (same ref appearing twice only reads the pane once)Files changed
tools/wta/src/pane_context.rs— newat_pane_refsfield onPaneContext; newextract_at_refsparsing function with unit teststools/wta/src/app.rs— populateat_pane_refsfrom user input text at submit timetools/wta/src/app/autofix.rs— addat_pane_refs: Vec::new()to existing autofixPaneContextconstructiontools/wta/src/protocol/acp/client.rs—resolve_at_pane_refhelper + injection loop inbuild_prompt_text; unit tests for the resolverTest plan
cargo test)extract_at_refs(pane_context.rs) andresolve_at_pane_ref(client.rs) cover index, title prefix, case-insensitivity, deduplication, and no-match caseslook at @2 and tell me what's wrongin the agent pane — agent should receive the second pane's output as context@buildresolves to a pane whose title starts with "build" (case-insensitive)@99(out of range) sends normally with no extra context and no error