Skip to content

Commit 0d154b6

Browse files
authored
Add the ability to connect to a running instance of the Copilot CLI (#346)
* Add the ability to connect to a running instance of the Copilot CLI * format, lint and document new flags * Fix lint
1 parent 73c1431 commit 0d154b6

File tree

24 files changed

+1611
-141
lines changed

24 files changed

+1611
-141
lines changed

.github/aw/github-agentic-workflows.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,18 @@ The YAML frontmatter supports these fields:
214214
The `custom` engine allows you to define your own GitHub Actions steps instead of using an AI processor. Each step in the `steps` array follows standard GitHub Actions step syntax with `name`, `uses`/`run`, `with`, `env`, etc. This is useful for deterministic workflows that don't require AI processing.
215215

216216
**Environment Variables Available to Custom Engines:**
217-
217+
218218
Custom engine steps have access to the following environment variables:
219-
219+
220220
- **`$GH_AW_PROMPT`**: Path to the generated prompt file (`/tmp/gh-aw/aw-prompts/prompt.txt`) containing the markdown content from the workflow. This file contains the natural language instructions that would normally be sent to an AI processor. Custom engines can read this file to access the workflow's markdown content programmatically.
221221
- **`$GH_AW_SAFE_OUTPUTS`**: Path to the safe outputs file (when safe-outputs are configured). Used for writing structured output that gets processed automatically.
222222
- **`$GH_AW_MAX_TURNS`**: Maximum number of turns/iterations (when max-turns is configured in engine config).
223-
223+
224224
Example of accessing the prompt content:
225225
```bash
226226
# Read the workflow prompt content
227227
cat $GH_AW_PROMPT
228-
228+
229229
# Process the prompt content in a custom step
230230
- name: Process workflow instructions
231231
run: |
@@ -253,7 +253,7 @@ The YAML frontmatter supports these fields:
253253
log-level: debug # Optional: debug, info (default), warn, error
254254
args: ["--custom-arg", "value"] # Optional: additional AWF arguments
255255
```
256-
256+
257257
- **`sandbox:`** - Sandbox configuration for AI engines (string or object)
258258
- String format: `"default"` (no sandbox), `"awf"` (Agent Workflow Firewall), `"srt"` or `"sandbox-runtime"` (Anthropic Sandbox Runtime)
259259
- Object format for full configuration:
@@ -703,7 +703,7 @@ cache:
703703
restore-keys: |
704704
node-modules-
705705
- key: build-cache-${{ github.sha }}
706-
path:
706+
path:
707707
- dist
708708
- .cache
709709
restore-keys:
@@ -963,7 +963,7 @@ All other expressions are dissallowed.
963963
The `needs.activation.outputs.text` value provides automatically sanitized content based on the triggering event:
964964

965965
- **Issues**: `title + "\n\n" + body`
966-
- **Pull Requests**: `title + "\n\n" + body`
966+
- **Pull Requests**: `title + "\n\n" + body`
967967
- **Issue Comments**: `comment.body`
968968
- **PR Review Comments**: `comment.body`
969969
- **PR Reviews**: `review.body`
@@ -1163,7 +1163,7 @@ permissions:
11631163
11641164
safe-outputs:
11651165
create-issue: # Automatic issue creation
1166-
add-comment: # Automatic comment creation
1166+
add-comment: # Automatic comment creation
11671167
create-pull-request: # Automatic PR creation
11681168
```
11691169

@@ -1437,7 +1437,7 @@ The `--start-date` and `--end-date` flags support delta time syntax for relative
14371437

14381438
**Supported Time Units:**
14391439
- **Days**: `-1d`, `-7d`
1440-
- **Weeks**: `-1w`, `-4w`
1440+
- **Weeks**: `-1w`, `-4w`
14411441
- **Months**: `-1mo`, `-6mo`
14421442
- **Hours/Minutes**: `-12h`, `-30m` (for sub-day precision)
14431443
- **Combinations**: `-1mo2w3d`, `-2w5d12h`
@@ -1447,7 +1447,7 @@ The `--start-date` and `--end-date` flags support delta time syntax for relative
14471447
# Get runs from the last week
14481448
gh aw logs --start-date -1w
14491449
1450-
# Get runs up to yesterday
1450+
# Get runs up to yesterday
14511451
gh aw logs --end-date -1d
14521452
14531453
# Get runs from the last month
@@ -1502,7 +1502,7 @@ permissions:
15021502
GitHub Agentic Workflows supports security scanning during compilation with `--actionlint`, `--zizmor`, and `--poutine` flags.
15031503

15041504
**actionlint** - Lints GitHub Actions workflows and validates shell scripts with integrated shellcheck
1505-
**zizmor** - Scans for security vulnerabilities, privilege escalation, and secret exposure
1505+
**zizmor** - Scans for security vulnerabilities, privilege escalation, and secret exposure
15061506
**poutine** - Analyzes supply chain risks and third-party action usage
15071507

15081508
```bash
@@ -1559,7 +1559,7 @@ gh aw mcp list-tools github weekly-research
15591559

15601560
This command is useful for:
15611561
- **Discovering capabilities**: See what tools are available from each MCP server
1562-
- **Workflow discovery**: Find which workflows use a specific MCP server
1562+
- **Workflow discovery**: Find which workflows use a specific MCP server
15631563
- **Permission debugging**: Check which tools are allowed in your workflow configuration
15641564

15651565
## Compilation Process
@@ -1588,7 +1588,7 @@ Agentic workflows compile to GitHub Actions YAML:
15881588

15891589
1. **Use descriptive workflow names** that clearly indicate purpose
15901590
2. **Set appropriate timeouts** to prevent runaway costs
1591-
3. **Include security notices** for workflows processing user content
1591+
3. **Include security notices** for workflows processing user content
15921592
4. **Use the `imports:` field** in frontmatter for common patterns and security boilerplate
15931593
5. **ALWAYS run `gh aw compile` after every change** to generate the GitHub Actions workflow (or `gh aw compile <workflow-id>` for specific workflows)
15941594
6. **Review generated `.lock.yml`** files before deploying
@@ -1651,4 +1651,4 @@ gh aw logs <workflow-id>
16511651

16521652
### Documentation
16531653

1654-
For complete CLI documentation, see: https://githubnext.github.io/gh-aw/setup/cli/
1654+
For complete CLI documentation, see: https://githubnext.github.io/gh-aw/setup/cli/

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,10 @@ By default, the SDK automatically manages the Copilot CLI process lifecycle, sta
954954

955955
### Running the CLI in Server Mode
956956

957-
Start the CLI in server mode using the `--server` flag and optionally specify a port:
957+
Start the CLI in server mode using the `--headless` flag and optionally specify a port:
958958

959959
```bash
960-
copilot --server --port 4321
960+
copilot --headless --port 4321
961961
```
962962

963963
If you don't specify a port, the CLI will choose a random available port.

dotnet/README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,43 @@ List all available sessions.
124124

125125
Delete a session and its data from disk.
126126

127+
##### `GetForegroundSessionIdAsync(): Task<string?>`
128+
129+
Get the ID of the session currently displayed in the TUI. Only available when connecting to a server running in TUI+server mode (`--ui-server`).
130+
131+
##### `SetForegroundSessionIdAsync(string sessionId): Task`
132+
133+
Request the TUI to switch to displaying the specified session. Only available in TUI+server mode.
134+
135+
##### `On(Action<SessionLifecycleEvent> handler): IDisposable`
136+
137+
Subscribe to all session lifecycle events. Returns an `IDisposable` that unsubscribes when disposed.
138+
139+
```csharp
140+
using var subscription = client.On(evt =>
141+
{
142+
Console.WriteLine($"Session {evt.SessionId}: {evt.Type}");
143+
});
144+
```
145+
146+
##### `On(string eventType, Action<SessionLifecycleEvent> handler): IDisposable`
147+
148+
Subscribe to a specific lifecycle event type. Use `SessionLifecycleEventTypes` constants.
149+
150+
```csharp
151+
using var subscription = client.On(SessionLifecycleEventTypes.Foreground, evt =>
152+
{
153+
Console.WriteLine($"Session {evt.SessionId} is now in foreground");
154+
});
155+
```
156+
157+
**Lifecycle Event Types:**
158+
- `SessionLifecycleEventTypes.Created` - A new session was created
159+
- `SessionLifecycleEventTypes.Deleted` - A session was deleted
160+
- `SessionLifecycleEventTypes.Updated` - A session was updated
161+
- `SessionLifecycleEventTypes.Foreground` - A session became the foreground session in TUI
162+
- `SessionLifecycleEventTypes.Background` - A session is no longer the foreground session
163+
127164
---
128165

129166
### CopilotSession
@@ -462,13 +499,13 @@ var session = await client.CreateSessionAsync(new SessionConfig
462499
// request.Question - The question to ask
463500
// request.Choices - Optional list of choices for multiple choice
464501
// request.AllowFreeform - Whether freeform input is allowed (default: true)
465-
502+
466503
Console.WriteLine($"Agent asks: {request.Question}");
467504
if (request.Choices?.Count > 0)
468505
{
469506
Console.WriteLine($"Choices: {string.Join(", ", request.Choices)}");
470507
}
471-
508+
472509
// Return the user's response
473510
return new UserInputResponse
474511
{
@@ -501,7 +538,7 @@ var session = await client.CreateSessionAsync(new SessionConfig
501538
AdditionalContext = "Extra context for the model"
502539
};
503540
},
504-
541+
505542
// Called after each tool execution
506543
OnPostToolUse = async (input, invocation) =>
507544
{
@@ -511,7 +548,7 @@ var session = await client.CreateSessionAsync(new SessionConfig
511548
AdditionalContext = "Post-execution notes"
512549
};
513550
},
514-
551+
515552
// Called when user submits a prompt
516553
OnUserPromptSubmitted = async (input, invocation) =>
517554
{
@@ -521,7 +558,7 @@ var session = await client.CreateSessionAsync(new SessionConfig
521558
ModifiedPrompt = input.Prompt // Optionally modify the prompt
522559
};
523560
},
524-
561+
525562
// Called when session starts
526563
OnSessionStart = async (input, invocation) =>
527564
{
@@ -531,14 +568,14 @@ var session = await client.CreateSessionAsync(new SessionConfig
531568
AdditionalContext = "Session initialization context"
532569
};
533570
},
534-
571+
535572
// Called when session ends
536573
OnSessionEnd = async (input, invocation) =>
537574
{
538575
Console.WriteLine($"Session ended: {input.Reason}");
539576
return null;
540577
},
541-
578+
542579
// Called when an error occurs
543580
OnErrorOccurred = async (input, invocation) =>
544581
{

0 commit comments

Comments
 (0)