Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions internal/assets/integrations/copilot-cli/INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# ctx Agent Instructions — Copilot CLI

<!-- ctx:context -->
<!-- DO NOT REMOVE: This marker indicates ctx-managed content -->

## IMPORTANT: You Have Persistent Memory

This project uses Context (`ctx`) for context persistence across sessions.
**Your memory is NOT ephemeral**: it lives in the context directory.

## On Session Start

1. **Run `ctx system bootstrap`**: CRITICAL, not optional.
This tells you where the context directory is. If it fails or returns
no context_dir, STOP and warn the user.
2. **Read AGENT_PLAYBOOK.md** from the context directory: it explains
how to use this system
3. **Run `ctx agent --budget 4000`** for a content summary

## When Asked "Do You Remember?"

When the user asks "Do you remember?", "What were we working on?", or any
memory-related question:

**Do this FIRST (silently):**
- Read TASKS.md, DECISIONS.md, and LEARNINGS.md from the context directory
- Run `ctx recall list --limit 5` for recent session history

**Then respond with a structured readback:**

1. **Last session**: cite the most recent session topic and date
2. **Active work**: list pending or in-progress tasks
3. **Recent context**: mention 1-2 recent decisions or learnings
4. **Next step**: offer to continue or ask what to focus on

**Never** lead with "I don't have memory", "Let me check if there are files",
or narrate your discovery process. The context files are your memory.
Read them silently, then present what you found as recall, not as a search.

## Quick Context Load

```bash
# Get AI-optimized context packet (what you should know)
ctx agent --budget 4000

# Or see full status
ctx status
```

## Context Files

| File | Purpose |
|-----------------|----------------------------------------|
| CONSTITUTION.md | Hard rules — NEVER violate |
| TASKS.md | Current work items |
| DECISIONS.md | Architectural decisions with rationale |
| LEARNINGS.md | Gotchas, tips, lessons learned |
| CONVENTIONS.md | Code patterns and standards |

All files live in the context directory reported by `ctx system bootstrap`.

## Context Updates During Work

Proactively update context files as you work:

| Event | Action |
|-----------------------------|-------------------------------------|
| Made architectural decision | Add to `.context/DECISIONS.md` |
| Discovered gotcha/bug | Add to `.context/LEARNINGS.md` |
| Established new pattern | Add to `.context/CONVENTIONS.md` |
| Completed task | Mark [x] in `.context/TASKS.md` |

## Self-Check

Periodically ask yourself:

> "If this session ended right now, would the next session know what happened?"

If no — save a session file or update context files before continuing.

## Session Persistence

After completing meaningful work, save a session summary to
`.context/sessions/`. Use the `ctx-wrap-up` skill for the full ceremony.

## Build Commands

```bash
make build # or: go build ./cmd/ctx/...
make lint # or: golangci-lint run
make test # or: go test ./...
```

<!-- ctx:end -->
70 changes: 49 additions & 21 deletions internal/assets/integrations/copilot-cli/ctx-hooks.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,68 @@
{
"version": 1,
"hooks": {
"sessionStart": [
{
"type": "command",
"bash": ".github/hooks/scripts/ctx-sessionStart.sh",
"powershell": ".github/hooks/scripts/ctx-sessionStart.ps1",
"cwd": ".",
"timeoutSec": 10
"description": "Bootstrap ctx context on session start",
"command": "ctx system bootstrap"
},
{
"description": "Load AI-optimized context packet",
"command": "ctx agent --budget 4000"
}
],
"preToolUse": [
{
"type": "command",
"bash": ".github/hooks/scripts/ctx-preToolUse.sh",
"powershell": ".github/hooks/scripts/ctx-preToolUse.ps1",
"cwd": ".",
"timeoutSec": 5
"description": "Context load gate — ensure context is loaded before work",
"command": "ctx system context-load-gate"
},
{
"description": "Block dangerous non-path ctx commands",
"matcher": "bash",
"command": "ctx system block-non-path-ctx"
},
{
"description": "QA reminder nudge",
"matcher": "bash",
"command": "ctx system qa-reminder"
}
],
"postToolUse": [
{
"type": "command",
"bash": ".github/hooks/scripts/ctx-postToolUse.sh",
"powershell": ".github/hooks/scripts/ctx-postToolUse.ps1",
"cwd": ".",
"timeoutSec": 5
"description": "Post-commit context persistence check",
"matcher": "bash",
"command": "ctx system post-commit"
},
{
"description": "Check if a task was just completed",
"matcher": "edit",
"command": "ctx system check-task-completion"
},
{
"description": "Check if a task was just completed (write)",
"matcher": "write",
"command": "ctx system check-task-completion"
}
],
"sessionEnd": [
{
"type": "command",
"bash": ".github/hooks/scripts/ctx-sessionEnd.sh",
"powershell": ".github/hooks/scripts/ctx-sessionEnd.ps1",
"cwd": ".",
"timeoutSec": 15
"description": "Check context size for budget drift",
"command": "ctx system check-context-size"
},
{
"description": "Persistence check — unsaved decisions/learnings",
"command": "ctx system check-persistence"
},
{
"description": "Journal export check",
"command": "ctx system check-journal"
},
{
"description": "Version freshness check",
"command": "ctx system check-version"
},
{
"description": "Heartbeat — record session activity",
"command": "ctx system heartbeat"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ctx post-tool-use hook for Copilot CLI (PowerShell)
# Checks for post-commit context and task completion

$Tool = $args[0]

if ($Tool -eq "bash" -or $Tool -eq "powershell") {
try { ctx system post-commit 2>$null } catch {}
}

if ($Tool -eq "edit" -or $Tool -eq "write") {
try { ctx system check-task-completion 2>$null } catch {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# ctx post-tool-use hook for Copilot CLI
# Checks for post-commit context and task completion
set -euo pipefail

TOOL="${1:-}"

if [ "$TOOL" = "bash" ] || [ "$TOOL" = "powershell" ]; then
ctx system post-commit 2>/dev/null || true
fi

if [ "$TOOL" = "edit" ] || [ "$TOOL" = "write" ]; then
ctx system check-task-completion 2>/dev/null || true
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ctx pre-tool-use hook for Copilot CLI (PowerShell)
# Ensures context is loaded and blocks dangerous commands

$Tool = $args[0]

try { ctx system context-load-gate 2>$null } catch {}

if ($Tool -eq "bash" -or $Tool -eq "powershell") {
try { ctx system block-non-path-ctx 2>$null } catch {}
try { ctx system qa-reminder 2>$null } catch {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# ctx pre-tool-use hook for Copilot CLI
# Ensures context is loaded and blocks dangerous commands
set -euo pipefail

TOOL="${1:-}"

# Always check context load gate
ctx system context-load-gate 2>/dev/null || true

# Bash-specific hooks
if [ "$TOOL" = "bash" ] || [ "$TOOL" = "powershell" ]; then
ctx system block-non-path-ctx 2>/dev/null || true
ctx system qa-reminder 2>/dev/null || true
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ctx session end hook for Copilot CLI (PowerShell)
# Checks for unsaved context and records heartbeat

try { ctx system check-context-size 2>$null } catch {}
try { ctx system check-persistence 2>$null } catch {}
try { ctx system check-journal 2>$null } catch {}
try { ctx system check-version 2>$null } catch {}
try { ctx system heartbeat 2>$null } catch {}
10 changes: 10 additions & 0 deletions internal/assets/integrations/copilot-cli/scripts/session-end.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# ctx session end hook for Copilot CLI
# Checks for unsaved context and records heartbeat
set -euo pipefail

ctx system check-context-size 2>/dev/null || true
ctx system check-persistence 2>/dev/null || true
ctx system check-journal 2>/dev/null || true
ctx system check-version 2>/dev/null || true
ctx system heartbeat 2>/dev/null || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ctx session start hook for Copilot CLI (PowerShell)
# Bootstraps context and loads the agent packet

try { ctx system bootstrap 2>$null } catch {}
try { ctx agent --budget 4000 2>$null } catch {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# ctx session start hook for Copilot CLI
# Bootstraps context and loads the agent packet
set -euo pipefail

# Bootstrap ctx context
ctx system bootstrap 2>/dev/null || true

# Load AI-optimized context packet
ctx agent --budget 4000 2>/dev/null || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: _ctx-alignment-audit
description: "Audit alignment between docs and agent instructions. Use when docs make claims about agent behavior that may not be backed by the playbook or skills."
tools: [bash, read, glob, grep]
---

Audit whether behavioral claims in documentation are backed by
actual agent instructions.

## When to Use

- After writing or updating documentation
- After modifying the Agent Playbook or skills
- When a doc makes claims about proactive agent behavior
- Periodically to catch drift between docs and instructions

## When NOT to Use

- For code-level drift (use `ctx-drift` instead)
- For context file staleness (use `ctx-status`)
- When reviewing docs for prose quality (not behavioral claims)

## Process

### Step 1: Collect Claims

Read target docs. Extract every behavioral claim — statements
describing what an agent "will do", "may do", or "offers to do".

### Step 2: Trace Each Claim

Search for matching instructions in:
1. **AGENT_PLAYBOOK.md**: primary behavioral source
2. **skills/*/SKILL.md**: skill-specific instructions
3. **INSTRUCTIONS.md**: project-level instructions

For each claim, determine:
- **Covered**: matching instruction exists
- **Partial**: related but incomplete
- **Gap**: no instruction exists

### Step 3: Report

| Claim (file:line) | Status | Backing instruction | Gap |
|---|---|---|---|
| "agent creates tasks" | Gap | None | Not taught |
| "agent saves learnings" | Covered | Playbook | — |

### Step 4: Fix (if requested)

For each gap, propose:
- **Playbook addition**: if behavior applies broadly
- **Skill addition**: if specific to one skill
- **Doc correction**: if the claim overpromises

## Quality Checklist

- [ ] Every behavioral claim was traced
- [ ] Each claim has clear status (Covered/Partial/Gap)
- [ ] Gaps have proposed fixes
- [ ] No new claims introduced without backing
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: ctx-add-convention
description: "Record a coding convention. Use when a repeated pattern should be codified so all sessions follow it consistently."
tools: [bash]
---

Record a coding convention in CONVENTIONS.md.

## When to Use

- When a pattern has been used 2-3 times and should be standardized
- When establishing a naming, formatting, or structural rule
- When a new contributor would need to know "how we do things here"
- When the user says "codify that" or "make that a convention"

## When NOT to Use

- One-off implementation details (use code comments instead)
- Architectural decisions with trade-offs (use `ctx-add-decision`)
- Debugging insights or gotchas (use `ctx-add-learning`)
- Rules that are already enforced by linters or formatters

## Gathering Information

Conventions are simpler than decisions or learnings. You need:

1. **Name**: What is the convention called?
2. **Rule**: What is the rule? One clear sentence.
3. **Section**: Where does it belong in CONVENTIONS.md?

If the user provides only a description, infer the section from the
topic. Check existing sections in CONVENTIONS.md first to place it
correctly: don't create a new section if an existing one fits.

## Execution

```bash
ctx add convention "Use kebab-case for all CLI flag names" --section "Naming"
```

## Quality Checklist

- [ ] The rule is clear enough that someone unfamiliar could follow it
- [ ] It is specific to this project (not a general rule)
- [ ] It is not already in CONVENTIONS.md (check first)
- [ ] The section matches an existing section, or a new one is needed
- [ ] It describes a pattern, not a one-time choice (that's a decision)
Loading
Loading