Session M2-03 lab: Build a Space, then compare context¶
Duration: 2 hours Deliverable: One working Copilot Space, a short instructions file, and a filled-in comparison of four runs of the same task
Lab overview¶
You add one endpoint to a small Storefront API four times. Each run gets different context. You score the results and see which mechanism supplied what.
| Part | Work | Time |
|---|---|---|
| 1 | Set up the project and a private repository | 15 min |
| 2 | Build the Space | 25 min |
| 3 | Run the task with no context, then with the Space | 25 min |
| 4 | Write the instructions | 20 min |
| 5 | Run with instructions, then with both | 25 min |
| 6 | Compare and decide | 10 min |
Stretch tasks at the end are optional and sit outside the 2 hours.
Before you start¶
You need:
- a GitHub account with Copilot, and access to Copilot Spaces;
- the standalone Copilot CLI from Session M2-01;
- Git, the
ghCLI (signed in), and Node.js 18 or later.
Use only the synthetic Storefront files in this lab. Put them in a private repository on your personal account. Don't add real company code or data to the Space.
Part 1: Set up¶
Make two copies of the project. The full copy goes to GitHub and feeds the Space. The bare copy has only src/ and package.json. You run every task in the bare copy, so Copilot can't read the docs on its own.
mkdir -p ~/copilot-labs/session-m2-03
cd ~/copilot-labs/session-m2-03
cp -R <path-to-repo>/sessions/session-m2-03-spaces-and-context/lab/starter/ecommerce-project storefront-api
cp <path-to-repo>/sessions/session-m2-03-spaces-and-context/lab/starter/context-comparison.md .
cd storefront-api
git init -q -b main && git add -A && git commit -qm "Start"
gh repo create storefront-api-lab --private --source . --push
cd ..
mkdir bare-api && cp -R storefront-api/src storefront-api/package.json bare-api/
cd bare-api
npm install
printf 'node_modules\n' > .gitignore
git init -q -b main && git add -A && git commit -qm "Bare start"
Open storefront-api/docs/api-spec.md and read the Low-stock report section. Your task needs that behavior, and the code doesn't contain it.
Checkpoint: storefront-api-lab exists on GitHub with docs/ on main. bare-api has no docs/ folder.
Part 2: Build the Space¶
Go to github.com/copilot/spaces.
- Click Create space. Name it
Storefront API reference. Choose your personal account as owner. - Add Instructions. Paste the text from
lab/solution/space-setup.md, or write your own in five lines or fewer. - Click Add sources, then Add files and repositories. Pick
storefront-api-laband add these four files, not the repository: docs/api-spec.mddocs/architecture.mdsrc/models/product.jssrc/routes/products.js- Leave the Space private.
Why files and not the repository? Copilot loads a file into the context window in full, for every question. It searches a repository and pulls only what looks relevant. For a few key documents, files are more predictable. For a large docs tree, a repository is the better source.
Test the Space¶
Ask in the Space chat:
You should get a threshold of 10, with inactive and discontinued products excluded, taken from api-spec.md.
Watch a source refresh¶
GitHub files in a Space follow the main branch of their repository. Check it:
- In
storefront-api, change the default threshold indocs/api-spec.mdfrom 10 to 20. Commit and push tomain. - Ask the same question in the Space. The change may take a moment to show up. If it doesn't, check the current docs.
- Change the threshold back to 10 and push again.
This helps when docs change. It hurts when someone pushes a bad change. A Space is only as current and as correct as main.
Checkpoint: The Space answers from the spec, and you saw one answer change after a push.
Part 3: Run the task twice¶
Use this exact prompt every time:
Add GET /api/products/low-stock that lists products running low on stock.
Put it in its own route file and add tests. Run the tests.
For each run: branch from main, start a fresh Copilot session, paste the prompt, save the diff, and go back to main.
Run 1: no context¶
Paste the prompt. Allow file writes and npm commands when asked. When it finishes, exit and save the result:
Run 2: with the Space¶
The CLI's built-in GitHub MCP server doesn't include Spaces tools by default. Enable them for the session:
Paste the prompt with one extra line:
Look for a get_copilot_space tool call. If Copilot doesn't make one, repeat the request and name the Space owner.
Save the diff as run-2.diff the same way, then git switch main.
If your CLI can't reach Spaces, check the current docs. As a fallback, ask the prompt in the Space chat on github.com and paste the code it returns into the bare copy. The surface differs, so note that in your comparison.
Checkpoint: You have run-1.diff and run-2.diff. Fill in the first two columns of context-comparison.md.
Part 4: Write the instructions¶
Instructions load every time, without you asking. Keep them short, so they don't crowd out the task.
In bare-api, create two files. Write them yourself first. Open lab/solution/.github/ only to compare.
.github/copilot-instructions.md applies to the whole repository. Include:
- language style: ES modules, file naming;
- how responses and errors are shaped;
- how to test: the framework, how to start the app, the command to run;
- one thing to avoid, such as new dependencies.
Aim for 12 lines or fewer. Use short imperative bullets. Skip anything the code already shows clearly.
.github/instructions/routes.instructions.md applies only to matching files. It needs frontmatter:
Add two or three rules that matter only in route files. applyTo takes glob patterns, such as src/routes/**/*.js or **/*.ts,**/*.tsx.
Commit both files on main:
Checkpoint: Two files under .github/, committed on main. Neither repeats the low-stock spec.
Part 5: Run with instructions, then with both¶
Run 3: instructions only¶
Paste the plain prompt, with no Space line. Save run-3.diff and git switch main.
Run 4: instructions and Space¶
Paste the prompt with the Space line. Save run-4.diff and git switch main.
Checkpoint: Four diffs. Fill in the last two columns of your comparison.
Part 6: Compare and decide¶
Fill in the last two sections of context-comparison.md:
- What changed between runs. Name one behavior the Space fixed and one the instructions fixed.
- Which context would you keep. For each line below, pick Space, repository instructions, path-specific instructions, prompt file, or nothing:
- "Our API returns
{ data }envelopes." - "The spec for the low-stock report."
- "Use
node:testin this repo." - "Summarize this stack trace."
- "Review a PR with our checklist, when I ask."
Compare your table with lab/solution/expected-comparison.md. Model output varies, so your runs may differ. Rerun a prompt if a result looks odd.
Stretch tasks¶
Pick one if you finish early.
- See what the CLI loaded. Run
/instructionsin the Copilot CLI to list the instruction files it found, and switch one off. Run/envto see what else is loaded. Check the current CLI docs for details. - Prompt file. In VS Code, create
.github/prompts/low-stock-report.prompt.mdthat holds the task prompt, and run it from chat. Prompt-file support differs by tool and VS Code version, so check the current docs. If it doesn't run, skip this task. - Stale instruction. Add a rule to
routes.instructions.mdthat contradicts the code, such as "use CommonJS". Rerun and see what happens. Delete it. - Share a Space. Create a Space under an organization you can use and compare its sharing options with your personal one.
Final deliverable¶
- A private
storefront-api-labrepository and a Space with four file sources and short instructions. .github/copilot-instructions.mdand one.instructions.mdfile with anapplyTopattern.- Four diffs (
run-1.difftorun-4.diff). - A filled-in
context-comparison.md, including your choices from Part 6.