Demo 17 - GitHub Copilot CLI
This starter demonstrates an end-to-end Java coding task from the terminal.
TicketQueue compiles, but two methods intentionally throw
UnsupportedOperationException. The tests and TASK.md define the expected
behavior.
Prerequisites
- JDK 17 or later
- Apache Maven 3.9 or later
- PowerShell 6+ on Windows
- An active GitHub Copilot subscription with Copilot CLI enabled
-
GitHub Copilot CLI installed:
winget install GitHub.Copilot
Before presenting, run this from the demo folder to restore dependencies and confirm that the starter fails only because the two methods are unfinished:
mvn test
Live demo
-
Start Copilot CLI in the demo folder:
cd Java\17-github-copilot-cli copilotExplain the trust prompt: Copilot can read, edit, and run files below the trusted directory. Choose session-only trust for a training machine.
-
If needed, authenticate with
/login. Enter?to show available commands, then use/modelto show that the model can be selected without leaving the terminal. -
Demonstrate explicit file context without making changes:
Explain @TASK.md and @src/main/java/com/githubcopilot/demo/TicketQueue.java. Identify the unfinished behavior and the tests that should prove it. Do not edit files yet. -
Press Shift+Tab to enter plan mode, then prompt:
Plan the smallest implementation that satisfies @TASK.md and the existing JUnit tests. Include the validation commands you will run.Review the proposed approach before any code changes. Press Shift+Tab again to return to the normal interactive mode.
-
Ask Copilot to complete the task:
Implement the approved plan. Keep the public API unchanged, add tests only for uncovered edge cases, and run mvn test when finished.Pause at the first tool request. Explain one-time approval, approval for the rest of the session, and rejection with feedback. Approve only the specific file edits and Maven commands needed for this task.
-
Run a shell command directly from the Copilot prompt:
!git diff -- src/main src/testThe
!prefix runs a shell command without a model request. Then ask:Review this diff against @TASK.md. Report correctness issues and missing test cases before suggesting any additional edits. -
Show session controls with
/contextand/usage, then exit. Resume the latest session later with:copilot --continue
Reset after the demo
From the repository root, restore the starter implementation and remove any extra files Copilot created:
git restore Java/17-github-copilot-cli
git clean -fd Java/17-github-copilot-cli
Review untracked files before using git clean on a shared working tree.
Talking points
- Copilot CLI is the coding agent in a terminal, not the legacy
gh copilotcommand for command suggestions. @pathmakes file context explicit; plan mode separates design from editing.- Tool approval keeps file changes and command execution under human control.
- Agentic work must end with executable validation, not a plausible-looking diff.
!command, session resume, context usage, and model selection keep the workflow terminal-native.