Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save johnlindquist/d5631a5fb08a0abb113a2dd869436e37 to your computer and use it in GitHub Desktop.

Select an option

Save johnlindquist/d5631a5fb08a0abb113a2dd869436e37 to your computer and use it in GitHub Desktop.
Microsoft AI Dev Days Talk: Scripting Copilot - Piping Hot Intelligence (Technical Deep-Dive)

Scripting Copilot: Piping Hot Intelligence

Microsoft AI Dev Days - Technical Deep-Dive (15-20 min)


ACT 1: THE HOOK (1-2 minutes)

Opening: The One-Liner

Terminal, large font. Nothing else.

$ ma task.copilot.md

Say this:

"What if your markdown files could run AI? What if that documentation you already write... was executable?"

Pause. Let them process.

"That command just parsed a markdown file, extracted configuration from YAML frontmatter, and spawned an AI agent. But that's the punchline. Let me show you the setup."

The real magic:

$ git diff | copilot -p "review this" -s

"Data in. Intelligence out. The fifty-year-old pipe operator now carries something it never carried before: cognition."


ACT 2: MAIN CONTENT (12-15 minutes)

Section 2.1: The Architecture of AI Piping (2 min)

The Unix Philosophy, Extended

Traditional: grep ERROR log.txt | sort | uniq -c
AI-powered:  git diff | copilot -p "review" -s

What changed:

  • Same | operator
  • Same stdin/stdout contract
  • New capability: the transformation is now semantic, not syntactic

The core equation:

Software = Instructions + Tools

"We're not replacing tools. We're adding a new class of transformation to the pipeline."


Section 2.2: Copilot CLI - The Technical Foundation (6-8 min)

Flag Deep-Dive: -p and -s

The interaction modes:

# Interactive (default) - human in the loop
$ copilot
> What would you like help with?

# Non-interactive with prompt - for scripting
$ copilot -p "explain the error in this file"

# Silent mode - pure output, no chrome
$ copilot -p "explain the error" -s

Why -s is critical for pipelines:

# Without -s: ANSI codes, spinners, stats
$ copilot -p "summarize"
[spinner] Thinking...
Summary: Here's what's happening...
Tokens: 150 | Time: 1.2s

# With -s: Clean, pipeable text only
$ copilot -p "summarize" -s
Summary: Here's what's happening...

"Silent mode strips everything but the answer. That's what makes it composable."


DEMO 1: Basic Piping Patterns

# The fundamental pattern: stdin → AI → stdout
cat error.log | copilot -p "What went wrong?" -s

# Git integration - the killer use case
git diff | copilot -p "Review for bugs" -s

# Test output analysis
npm test 2>&1 | copilot -p "Why is this failing?" -s

# Documentation generation
cat src/utils.ts | copilot -p "Generate JSDoc comments" -s

Under the hood:

  1. Pipe sends data to copilot's stdin
  2. -p provides the instruction
  3. Model processes context + instruction
  4. -s outputs clean text to stdout
  5. Ready for next stage

DEMO 2: Chaining Intelligence

Multi-stage pipeline:

git diff | \
  copilot -p "list changes as bullets" -s | \
  copilot -p "rate each: low/medium/high risk" -s | \
  copilot -p "format as PR description" -s

What's happening at each stage:

Stage 1: raw diff        → structured list
Stage 2: structured list → risk-annotated list
Stage 3: annotated list  → formatted output

"Each stage refines the previous output. This is functional composition, but the functions understand natural language."

Edge case - context accumulation:

# BAD: Context explodes at each stage
big_file.ts | copilot -p "summarize" -s | copilot -p "expand" -s

# GOOD: Filter early, expand late
big_file.ts | copilot -p "extract function signatures only" -s | copilot -p "generate docs" -s

DEMO 3: Model Selection with --model

Available models (as of Dec 2024):

--model claude-haiku-4.5    # Fast, cheap - triage/classification
--model claude-sonnet-4     # Balanced - daily tasks (default)
--model claude-sonnet-4.5   # Enhanced reasoning
--model claude-opus-4.5     # Maximum capability
--model gpt-5.1-codex       # GPT family - code focused
--model gemini-3-pro-preview # Google's model

The escalation pattern:

#!/bin/bash
# Smart escalation based on task complexity

TASK="$1"

# Use fast model to classify
COMPLEXITY=$(echo "$TASK" | copilot -p "Respond ONLY: SIMPLE or COMPLEX" -s --model claude-haiku-4.5)

if [ "$COMPLEXITY" = "COMPLEX" ]; then
  copilot -p "$TASK" -s --model claude-opus-4.5
else
  copilot -p "$TASK" -s --model claude-haiku-4.5
fi

Cost/Speed comparison:

Model Relative Speed Relative Cost Use Case
haiku-4.5 5x faster 10x cheaper Triage, classification, simple transforms
sonnet-4 Baseline Baseline General purpose
opus-4.5 3x slower 15x more Deep analysis, complex reasoning

"Use the fast model to decide if you need the powerful model. Don't pay for Opus to answer 'yes or no' questions."


DEMO 4: Permission Boundaries with --allow-tool

The permission model:

# Deny all tools by default (pure analysis)
copilot -p "Analyze this code" -s

# Allow specific tool patterns
copilot -p "Fix this" -s --allow-tool 'shell(git:*)'

# Allow file operations
copilot -p "Refactor this" -s --allow-tool 'write' --allow-tool 'Read'

# Full autonomy (use with caution)
copilot -p "Implement feature X" -s --allow-all-tools

The tool permission syntax:

# Pattern: 'toolName(pattern)'

--allow-tool 'shell(git:*)'     # All git commands
--allow-tool 'shell(npm:*)'     # All npm commands
--allow-tool 'shell(git push)'  # Specific command
--allow-tool 'Read'             # File reading
--allow-tool 'write'            # File writing

# Deny takes precedence
--allow-tool 'shell(git:*)' --deny-tool 'shell(git push --force)'

Trust ladder for automation:

Level 1: Pure pipes           cat code | copilot -p "find bugs" -s
         (safest)             No tool access, analysis only

Level 2: Read-only            copilot -p "audit" -s --allow-tool 'Read' --allow-tool 'shell(git log)'
         (inspection)         Can read, can't modify

Level 3: Scoped writes        copilot -p "fix lint" -s --allow-tool 'shell(npm:*)' --allow-tool 'write'
         (controlled)         Specific modification rights

Level 4: Full autonomy        copilot -p "implement" -s --allow-all-tools
         (supervised)         Human monitors, agent acts

"The pipe doesn't grant permissions. You do, explicitly, with flags. This is the control surface for AI automation."


Section 2.3: Advanced Patterns (3-4 min)

Pattern 1: Code Review Pipeline

#!/bin/bash
# review-pipeline.sh

git diff main..HEAD | \
  copilot -p "List changes with file:line format" -s --model claude-haiku-4.5 | \
  copilot -p "For each change: [BUG_RISK], [PERF_IMPACT], [SECURITY]" -s --model claude-sonnet-4 | \
  copilot -p "Sort by risk, format as markdown table" -s --model claude-haiku-4.5 > review.md

Why three models?

  • Stage 1 (haiku): Structural transformation - fast, cheap
  • Stage 2 (sonnet): Judgment/evaluation - needs reasoning
  • Stage 3 (haiku): Formatting - mechanical transform

Pattern 2: Debug Pipeline

#!/bin/bash
# debug-pipeline.sh

npm test 2>&1 | \
  copilot -p "Extract ONLY the failing test output" -s --model claude-haiku-4.5 | \
  copilot -p "Identify root cause from stack trace and assertions" -s --model claude-sonnet-4 | \
  copilot -p "Generate a fix with explanation" -s --model claude-opus-4.5

Escalation in action: Filter fast, analyze balanced, generate with maximum capability.


Pattern 3: Batch Processing with xargs

# Process multiple files through AI pipeline
find src -name "*.ts" -print0 | \
  xargs -0 -I {} sh -c 'cat {} | copilot -p "Extract exported types" -s >> types.md'

# Parallel processing (careful with rate limits)
find src -name "*.ts" | \
  xargs -P 4 -I {} sh -c 'cat {} | copilot -p "Generate JSDoc" -s > {}.doc'

ACT 3: THE RESOLUTION (3-4 minutes)

The Problem: Ephemeral Commands

"Everything we've built is powerful. But be honest - will you remember --allow-tool 'shell(git:*)' next week?"

Pain points with raw CLI:

  • Complex flag combinations forgotten
  • Project-specific configurations lost
  • Team patterns shared via... Slack?
  • No version control on prompts

The Reveal: markdown-agent (ma)

The concept:

$ ma review.copilot.md

How the filename works:

  • review = your task name
  • .copilot = execute with copilot CLI
  • .md = it's markdown (you already know this)

The file structure:

---
model: claude-sonnet-4
allow-tool:
  - 'shell(git:*)'
  - Read
silent: true
---

Review these code changes for:
1. Bug risks
2. Performance issues
3. Security concerns

Prioritize by severity.

What ma does:

  1. Parse YAML frontmatter → CLI flags
  2. Process markdown body → prompt
  3. Resolve copilot from filename
  4. Spawn: copilot --model claude-sonnet-4 --allow-tool 'shell(git:*)' --allow-tool Read -s -p "Review these code changes..."

Template Variables: Dynamic Agents

---
model: claude-sonnet-4
args:
  - base_branch
  - focus_area
silent: true
---

## Context
!`git diff {{ base_branch | default: "main" }}..HEAD`

## Instructions
Review changes with focus on {{ focus_area | default: "all areas" }}.

For each change:
- Risk level (low/medium/high)
- Category (bug fix, feature, refactor)
- Concerns if any

Usage:

ma pr-review.copilot.md --base_branch develop --focus_area security

Under the hood:

  • LiquidJS templating engine
  • !backticks`` inline shell commands
  • @./path imports file contents
  • Default values with filters

Piping Into Agents

# Pipe works just like raw copilot
git diff | ma review.copilot.md

# The agent file receives stdin as context
cat error.log | ma diagnose.copilot.md --severity critical

Why this matters:

  • Your pipelines, versioned in git
  • Team patterns, shared via PRs
  • Project standards, automated

CLOSING (1 minute)

The Technical Summary

  1. -s enables composability - Silent mode produces pipeable output
  2. | carries intelligence - Same Unix pipes, new transformation type
  3. --model controls capability/cost - Escalate intentionally
  4. --allow-tool defines trust - Explicit permission boundaries
  5. .copilot.md files capture patterns - Version control your AI workflows

Call to Action

# Step 1: Try piping
git diff | copilot -p "review" -s

# Step 2: Add model selection
git diff | copilot -p "review" -s --model claude-haiku-4.5

# Step 3: Create an agent file
echo "Review this code for bugs" > review.copilot.md
git diff | ma review.copilot.md

# Step 4: Commit your agent
git add review.copilot.md && git commit -m "Add code review agent"

Resources

  • Copilot CLI: copilot --help (it's comprehensive)
  • markdown-agent: github.com/johnlindquist/agents
  • This outline: [gist link]

Final Technical Insight

"The pipe operator hasn't changed in fifty years. What changed is what flows through it. When text carries intention, and tools can interpret that intention, the transformation isn't syntactic anymore. It's semantic. That's the paradigm shift: your shell just learned to understand."


TIMING BREAKDOWN

Section Duration Cumulative
Hook: ma task.copilot.md + git diff demo 2 min 2 min
Architecture: Unix philosophy extended 2 min 4 min
-p and -s flags deep-dive 2 min 6 min
Demo 1: Basic piping patterns 2 min 8 min
Demo 2: Chaining intelligence 2 min 10 min
Demo 3: Model selection (--model) 2 min 12 min
Demo 4: Permission boundaries (--allow-tool) 2 min 14 min
Advanced patterns 2 min 16 min
Resolution: markdown-agent reveal 3 min 19 min
Closing: Technical summary 1 min 20 min

DEMO PREPARATION CHECKLIST

  • Terminal: 24pt+ font, dark theme, minimal prompt
  • Git repo with staged changes for git diff demos
  • Sample error.log with realistic stack traces
  • Pre-written .copilot.md files tested and working
  • copilot CLI authenticated and rate limits checked
  • Backup: Screen recordings of each demo
  • Network: Stable connection, cellular backup
  • Test all pipes 1 hour before talk

DEMO FILES

review.copilot.md

---
model: claude-sonnet-4
allow-tool:
  - 'shell(git:*)'
  - Read
silent: true
---
Review this code for bugs, security issues, and performance concerns.
Prioritize findings by severity.
Format as markdown with headers: ## Critical, ## Warning, ## Info

triage.copilot.md

---
model: claude-haiku-4.5
silent: true
---
Classify this task as SIMPLE or COMPLEX.
Respond with ONLY one word.

escalate.sh

#!/bin/bash
# Demonstrates intelligent model selection

TASK="$1"
COMPLEXITY=$(echo "$TASK" | ma triage.copilot.md)

if [ "$COMPLEXITY" = "COMPLEX" ]; then
  echo "Escalating to Opus..."
  copilot -p "$TASK" -s --model claude-opus-4.5
else
  echo "Handling with Haiku..."
  copilot -p "$TASK" -s --model claude-haiku-4.5
fi

KEY QUOTABLES

"Data in. Intelligence out. The pipe operator now carries cognition."

"Silent mode strips everything but the answer. That's what makes it composable."

"Use the fast model to decide if you need the powerful model."

"The pipe doesn't grant permissions. You do, explicitly, with flags."

"Your shell just learned to understand."


Microsoft AI Dev Days - Technical Deep-Dive "Scripting Copilot: Piping Hot Intelligence" Duration: 15-20 minutes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment