From ffa7c728e48b76e25cea0d835a19b6dda97419a4 Mon Sep 17 00:00:00 2001 From: Peter Bons Date: Tue, 27 Oct 2026 14:24:36 +0100 Subject: [PATCH] Report GitHub Copilot usage with --source copilot|all A new loader (src/copilot.mjs) reads the Copilot CLI's session logs (~/.copilot/session-state//events.jsonl, also written by Copilot's agent in VS Code) into the same records as the Claude Code loader, so every report works on them. --source all combines both products; the default stays claude. - Tokens: per request from session.usage_record where logged, else the per-run totals of session.shutdown (counted as that many requests, with no context size). Copilot's input includes cached tokens; they are subtracted to match Claude's columns. - Cost: what Copilot billed in AI credits (1 AIU = $0.01); unbilled Claude models are priced at API rates (dotted names like claude-sonnet-4.6 now resolve). The summary lists premium requests. - Tokens per tool are estimated as for Claude Code, then scaled down to at most each session's input, and get a matching share of its billed cost. - Tools keep Copilot's names; MCP tools become mcp____, task calls are subagent launches, shell commands are broken down, PRs come from gh pr create / create_pull_request output. - Recommendations run the same checks with Copilot's own advice (copilot-instructions.md, custom agents, explore agent, /compact, plan mode, autopilot); with --source all each product gets its own section. - The report skill knows about --source and the Copilot caveats. Co-Authored-By: Claude Opus 5.5 --- README.md | 66 +++++- bin/ccreports.mjs | 50 ++++- skills/report/SKILL.md | 17 +- src/adoption.mjs | 11 +- src/aggregate.mjs | 21 +- src/attribution.mjs | 5 +- src/copilot.mjs | 435 ++++++++++++++++++++++++++++++++++++++++ src/formats.mjs | 5 +- src/pricing.mjs | 3 +- src/recommendations.mjs | 166 +++++++++++---- src/report.mjs | 11 +- test/copilot.test.mjs | 233 +++++++++++++++++++++ 12 files changed, 961 insertions(+), 62 deletions(-) create mode 100644 src/copilot.mjs create mode 100644 test/copilot.test.mjs diff --git a/README.md b/README.md index df130f2..aadfdb0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ccreports -Reports Claude Code **tool calls, skills, slash commands, subagents, token usage and cost** from +Reports Claude Code (and [GitHub Copilot](#github-copilot)) **tool calls, skills, slash commands, subagents, token usage and cost** from the local session transcripts in `~/.claude/projects`. Inspired by [ccusage](https://github.com/ccusage/ccusage), which covers tokens and cost; ccreports adds what you actually *did* with those tokens. @@ -199,8 +199,72 @@ byte order mark so Excel shows non-ASCII characters correctly. | `--no-subagents` | Exclude subagent transcripts | | `--compact` | Hide cache token columns (automatic below 120 columns) | | `--dir ` | Projects directory (repeatable). Default: `CLAUDE_CONFIG_DIR` (comma-separated) or `~/.claude` / `~/.config/claude` | +| `--source ` | `claude` (default), `copilot` or `all` - see [GitHub Copilot](#github-copilot) | +| `--copilot-dir ` | Copilot session-state directory (repeatable). Default: `COPILOT_HOME` or `~/.copilot`, then `session-state` | | `-v, --version` | Print the ccreports version. Reports name it too: in the HTML header line, as a footer in table and Markdown output, and as `ccreportsVersion` in JSON | +### GitHub Copilot + +`--source copilot` reports GitHub Copilot instead, from the session logs in +`~/.copilot/session-state//events.jsonl`. The Copilot CLI writes them, +and so does Copilot's agent in VS Code. `--source all` combines both tools in +one report. Every report works for Copilot, including `recommendations`. + +```sh +node bin/ccreports.mjs --source copilot # summary +node bin/ccreports.mjs weekly -b --source copilot +node bin/ccreports.mjs --source all -a -f html -o both.html +``` + +How the Copilot logs map onto the reports: + +- **Tokens.** Recent Copilot versions log usage per request + (`session.usage_record`). Older sessions only have totals per model for each + run, written at shutdown. These count as that many requests, at the time of + shutdown, and have no context size. Sessions that never shut down cleanly + have no token counts. Copilot's input tokens include cached tokens, so the + cached tokens are subtracted to match Claude's *Input* column. +- **Cost** is what Copilot billed in AI credits (1 AIU = $0.01). Requests + without AI credits are priced at Claude API rates when the model is a + Claude model; other models (GPT and local ones) are reported as unpriced. + The summary also shows the **premium requests** used. +- **Tools** keep Copilot's names (`view`, `powershell`, `apply_patch`, …). + MCP tools are named `mcp____`. `task` calls are subagent + launches. `-x` breaks down `powershell` / `bash` commands. +- **Tokens per tool** are estimates, as for Claude Code. Copilot logs few + requests that can be measured, and it trims old tool output, so a + session's estimates are scaled down to at most its total input. *Cost (est.)* + is the matching share of what the session was billed. Sessions without + token counts get no estimates. +- **Skills, slash commands, hooks, compactions and prompts** come from their + own events. Hooks are named by event (`PreToolUse`), since Copilot doesn't + log the command. **Pull requests** are the PR links in the output of + `gh pr create` or a `create_pull_request` MCP call. +- Installed plugins are listed for Claude Code only. + +**Recommendations** run the same checks as for Claude Code. Their advice +names Copilot's own levers: `.github/copilot-instructions.md` / `AGENTS.md`, +custom agents (`.github/agents/`), skills, the `explore` agent, `/compact`, +`/clear`, `/context`, `/model`, `/mcp`, and plan mode and autopilot. Some +checks work differently for Copilot: + +- **Long contexts and prompt-cache rebuilds** use only the requests logged one + by one. Shutdown totals have no context size. +- **Delegating exploration** is judged by the share of sessions that launched + a subagent. Older Copilot logs count subagents' tokens as the main + session's, so token shares can't show delegation. +- **The step-by-step coding check** also says how many coding sessions used + plan mode and autopilot. +- **Cheaper models for subagents** is skipped, since Copilot bills at its + own rates and premium-request multipliers. +- **Running work in parallel** looks at background agents only, since + Copilot has no worktree isolation. +- **Failing hooks:** a hook that errors counts as failed, even though Copilot + also denies the tool call it guarded. + +With `--source all`, each product gets its own recommendations, weighed +against its own cost, and in JSON every recommendation has a `source`. + ## What is counted - **Tokens** – `usage` from each assistant message, deduplicated per diff --git a/bin/ccreports.mjs b/bin/ccreports.mjs index 56ba2f8..1ec6775 100644 --- a/bin/ccreports.mjs +++ b/bin/ccreports.mjs @@ -4,6 +4,7 @@ import { tmpdir } from 'node:os'; import path from 'node:path'; import { parseArgs } from 'node:util'; import { loadRecords, defaultProjectDirs } from '../src/loader.mjs'; +import { loadCopilotRecords, defaultCopilotDirs, mergeData } from '../src/copilot.mjs'; import { aggregate, parseDateArg, toJSON, REPORTS } from '../src/aggregate.mjs'; import { buildPeriodReport, buildSummary } from '../src/report.mjs'; import { FORMATS, toTerminal, toMarkdown, toCsv, toHtml } from '../src/formats.mjs'; @@ -14,7 +15,7 @@ import { openFile, FORMAT_EXTENSIONS } from '../src/open.mjs'; import { loadPlugins, pluginRows, pluginsJSON } from '../src/plugins.mjs'; import { VERSION } from '../src/version.mjs'; -const HELP = `ccreports - Claude Code tool, skill, slash-command and token usage +const HELP = `ccreports - Claude Code (and GitHub Copilot) tool, skill, slash-command and token usage Usage: ccreports [report] [options] @@ -30,6 +31,7 @@ Reports: recommendations Best-practice recommendations based on your usage, with the cost at stake Options: + --source claude (default), copilot (GitHub Copilot CLI / VS Code agent) or all -s, --since Include from this date (YYYYMMDD or YYYY-MM-DD) -u, --until Include up to and including this date -p, --project Only projects whose path contains (case-insensitive) @@ -51,6 +53,7 @@ Options: --compact Hide cache token columns (table format) --no-color Disable colors (also honors NO_COLOR) --dir Projects directory to scan (repeatable; default from CLAUDE_CONFIG_DIR or ~/.claude) + --copilot-dir Copilot session-state directory (repeatable; default from COPILOT_HOME or ~/.copilot) -v, --version Show the ccreports version -h, --help Show this help `; @@ -86,6 +89,8 @@ try { compact: { type: 'boolean' }, 'no-color': { type: 'boolean' }, dir: { type: 'string', multiple: true }, + source: { type: 'string' }, + 'copilot-dir': { type: 'string', multiple: true }, version: { type: 'boolean', short: 'v' }, help: { type: 'boolean', short: 'h' }, }, @@ -108,6 +113,8 @@ const report = positionals[0] ?? 'summary'; if (!REPORTS.includes(report)) fail(`unknown report "${report}". Expected one of: ${REPORTS.join(', ')}`); if (positionals.length > 1) fail(`unexpected argument "${positionals[1]}"`); if (opts.order && !['asc', 'desc'].includes(opts.order)) fail('--order must be asc or desc'); +const source = (opts.source ?? 'claude').toLowerCase(); +if (!['claude', 'copilot', 'all'].includes(source)) fail('--source must be claude, copilot or all'); let format = opts.json ? 'json' : (opts.format ?? 'table').toLowerCase(); if (format === 'md') format = 'markdown'; @@ -137,9 +144,17 @@ if (opts.timezone) { const toTTY = !opts.output && !opts.open && process.stdout.isTTY; +const includeSubagents = !opts['no-subagents']; const dirs = opts.dir?.length ? opts.dir : defaultProjectDirs(); -const data = await loadRecords({ dirs, includeSubagents: !opts['no-subagents'] }); -if (data.files === 0) fail(`no transcripts found in: ${dirs.join(', ')}`); +const copilotDirs = opts['copilot-dir']?.length ? opts['copilot-dir'] : defaultCopilotDirs(); +const claudeData = source !== 'copilot' ? await loadRecords({ dirs, includeSubagents }) : null; +const copilotData = source !== 'claude' ? await loadCopilotRecords({ dirs: copilotDirs, includeSubagents }) : null; +const data = claudeData && copilotData ? mergeData(claudeData, copilotData) : claudeData ?? copilotData; +if (data.files === 0) { + const scanned = [...(claudeData ? dirs : []), ...(copilotData ? copilotDirs : [])]; + fail(`no ${source === 'copilot' ? 'sessions' : 'transcripts'} found in: ${scanned.join(', ')}`); +} +const product = { claude: 'Claude Code', copilot: 'GitHub Copilot', all: 'Claude Code and GitHub Copilot' }[source]; const showCost = !opts['no-cost']; let pricer, pricingSource; @@ -162,7 +177,8 @@ if (showCost) { } // Installed plugins and what of each was used, in every report. -const plugins = pluginRows(await loadPlugins(dirs), result.totals, { project: opts.project }); +// (Claude Code plugins only.) +const plugins = claudeData ? pluginRows(await loadPlugins(dirs), result.totals, { project: opts.project }) : []; // Only the terminal table hides columns to fit the screen. const compact = format === 'table' && (opts.compact || (toTTY && process.stdout.columns < 120)); @@ -178,16 +194,36 @@ const docOpts = { project: opts.project, pricer, plugins, + product, }; // The adoption assessment and recommendations: their own reports, or appended // to another with --adoption / --recommendations. const adoption = report === 'adoption' || opts.adoption ? buildAdoption(data, docOpts) : null; -const advice = report === 'recommendations' || opts.recommendations ? buildRecommendations(data, docOpts) : null; +// Recommendations per product: each names its own settings and commands, and +// is weighed against that product's own cost. +let advice = null; +if (report === 'recommendations' || opts.recommendations) { + const parts = [ + ['claude', claudeData], + ['copilot', copilotData], + ] + .filter(([, d]) => d?.files) + .map(([src, d]) => ({ src, doc: buildRecommendations(d, { ...docOpts, source: src }) })); + advice = + parts.length === 1 + ? { ...parts[0].doc, items: parts[0].doc.items.map((i) => ({ ...i, source: parts[0].src })) } + : { + title: `${product} recommendations`, + summary: parts.filter((p) => !p.doc.items.length).map((p) => `${p.doc.title.replace(/ recommendations.*/, '')}: ${p.doc.summary[0]}`), + sections: parts.flatMap((p) => p.doc.sections.map((s) => ({ ...s, title: p.doc.title }))), + items: parts.flatMap((p) => p.doc.items.map((i) => ({ ...i, source: p.src }))), + }; +} let output; if (format === 'json') { - const meta = { report, since, until, pricingSource, ccreportsVersion: VERSION }; + const meta = { report, source, since, until, pricingSource, ccreportsVersion: VERSION }; const adoptionJson = adoption && { summary: adoption.summary, phases: PHASES, @@ -221,7 +257,7 @@ if (format === 'json') { table: () => toTerminal(doc, { color: toTTY && !opts['no-color'] && !process.env.NO_COLOR, version: VERSION }) + '\n', markdown: () => toMarkdown(doc, { version: VERSION }), csv: () => toCsv(doc), - html: () => toHtml(doc, { pricingSource, version: VERSION }), + html: () => toHtml(doc, { pricingSource, version: VERSION, copilot: !!copilotData }), }[format](); } diff --git a/skills/report/SKILL.md b/skills/report/SKILL.md index eb3fd09..dc905de 100644 --- a/skills/report/SKILL.md +++ b/skills/report/SKILL.md @@ -1,6 +1,6 @@ --- name: report -description: Report the user's own Claude Code usage from their local session logs (~/.claude/projects) - tokens and estimated API cost, tool / skill / slash-command / hook / subagent counts and the tokens each consumed, context size, sessions, an adoption assessment (chat, assisted, agent-first, multi-agent) and best-practice recommendations backed by their data. Use when the user asks how much they used or spent, which tools or skills they use most, what consumes their tokens, how their usage trends per day/week/month/project/session, how far they have adopted agentic workflows, how to use Claude Code more effectively or cheaply, or wants such a report as a table, Markdown, CSV, JSON or HTML page. +description: Report the user's own Claude Code usage from their local session logs (~/.claude/projects), and their GitHub Copilot CLI / VS Code agent usage (~/.copilot/session-state) - tokens and estimated API cost, tool / skill / slash-command / hook / subagent counts and the tokens each consumed, context size, sessions, an adoption assessment (chat, assisted, agent-first, multi-agent) and best-practice recommendations backed by their data. Use when the user asks how much they used or spent, which tools or skills they use most, what consumes their tokens, how their usage trends per day/week/month/project/session, how far they have adopted agentic workflows, how to use Claude Code or Copilot more effectively or cheaply, how their Claude Code and Copilot usage compare, or wants such a report as a table, Markdown, CSV, JSON or HTML page. argument-hint: "[summary|daily|weekly|monthly|session|project|adoption|recommendations] [options]" --- @@ -14,7 +14,7 @@ absolute path from the "Base directory for this skill" line, quoted: node "/../../bin/ccreports.mjs" [report] [options] ``` -It only reads local transcripts; the one network call fetches Anthropic's public +It only reads local session logs; the one network call fetches Anthropic's public pricing page for cost estimates (cached for a day; `--offline` skips it). ## Choosing the command @@ -32,6 +32,8 @@ the request: | which programs / CLI commands Bash and PowerShell calls ran | add `-x` (`--shell`) to `summary` or a period report | | an adoption / maturity assessment | `adoption`, or `-a` to add it to another report | | advice: how to use Claude Code better or cheaper | `recommendations`, or `-r` to add it to another report | +| the same for GitHub Copilot (CLI or VS Code agent) | any of the above with `--source copilot` | +| Claude Code and Copilot together, or compared | any of the above with `--source all` (recommendations get a section per product) | Useful options: `-s/--since` and `-u/--until` (`YYYYMMDD`), `-p/--project `, `-n/--top `, `--compact`, `--no-cost`, `-f/--format table|json|csv|markdown|html`, @@ -62,3 +64,14 @@ of every table. Keep these caveats in mind and mention them when relevant: - Context size counts the main conversation only. - The adoption phases are per session, from the user's own logs; PRs are those Claude Code created. + +With `--source copilot` or `all`, also keep in mind: + +- Copilot cost is what it billed in AI credits (1 AIU = $0.01); where nothing + was billed, Claude models are priced at API rates and other models (GPT, + local) show as unpriced. The summary also lists premium requests. +- Older Copilot sessions only log totals per run at shutdown: no context size, + and subagent tokens are folded into the main session. Sessions that never + shut down cleanly have no token counts. +- Copilot's tokens per tool are rougher than Claude Code's: they are scaled + down to at most what each session sent. diff --git a/src/adoption.mjs b/src/adoption.mjs index 5c7a157..e4877db 100644 --- a/src/adoption.mjs +++ b/src/adoption.mjs @@ -25,6 +25,8 @@ const SURFACES = { 'sdk-ts': 'Agent SDK', 'sdk-py': 'Agent SDK', remote: 'Web', + 'copilot-cli': 'Copilot CLI', + 'copilot-vscode': 'Copilot in VS Code', }; /** Places one session's stats in a phase (first matching rule wins). */ @@ -57,12 +59,13 @@ export function sessionStats(data, { since, until, project, timeZone, pricer } = for (const t of data.tools) { if (!inRange.has(t.sessionId)) continue; const c = counts.get(t.sessionId) ?? { edits: 0, backgroundAgents: 0, worktrees: 0, agentMessages: 0, mcpCalls: 0, webCalls: 0 }; - if (EDIT_TOOLS.has(t.name)) c.edits += 1; + // edit / web: flags set by the GitHub Copilot loader, whose tools have other names. + if (EDIT_TOOLS.has(t.name) || t.edit) c.edits += 1; if (t.background) c.backgroundAgents += 1; if (t.worktree) c.worktrees += 1; if (t.name === 'SendMessage') c.agentMessages += 1; if (t.name.startsWith('mcp__')) c.mcpCalls += 1; - if (t.name === 'WebSearch' || t.name === 'WebFetch') c.webCalls += 1; + if (t.name === 'WebSearch' || t.name === 'WebFetch' || t.web) c.webCalls += 1; counts.set(t.sessionId, c); } return buckets.map((b) => { @@ -220,10 +223,10 @@ export function buildAdoption(data, opts) { const range = opts.since || opts.until ? ` (${opts.since ?? '…'} → ${opts.until ?? 'today'})` : ''; return { - title: `Claude Code adoption${range}`, + title: `${opts.product ?? 'Claude Code'} adoption${range}`, summary: assess(stats, byPhase), sections: [ - { title: 'Adoption cohorts', note: 'sessions by how they used Claude Code', cards: true, columns: cohortColumns, rows: cohortRows }, + { title: 'Adoption cohorts', note: `sessions by how they used ${opts.product ?? 'Claude Code'}`, cards: true, columns: cohortColumns, rows: cohortRows }, { title: 'Phase mix per week', note: 'by the week a session started', diff --git a/src/aggregate.mjs b/src/aggregate.mjs index 99b4422..7045b7e 100644 --- a/src/aggregate.mjs +++ b/src/aggregate.mjs @@ -60,6 +60,7 @@ function newBucket(key) { totalTokens: 0, costUSD: 0, requests: 0, + premiumRequests: 0, // GitHub Copilot toolCalls: 0, skillCalls: 0, commandCount: 0, @@ -138,7 +139,9 @@ function addUsage(entry, t, costUSD, f = 1) { /** Prices an attributed item: tool input as output, then cache writes and re-reads. */ function attributedCost(t, pricer) { - if (!pricer || !t.model) return 0; + if (!pricer) return 0; + if (t.costUSD != null) return t.costUSD; // a share of billed GitHub Copilot cost + if (!t.model) return 0; return ( pricer({ model: t.model, @@ -197,9 +200,12 @@ export function aggregate(data, { report = 'summary', since, until, project, tim if (!buckets) continue; const total = rec.inputTokens + rec.outputTokens + rec.cacheCreationTokens + rec.cacheReadTokens; const context = rec.inputTokens + rec.cacheCreationTokens + rec.cacheReadTokens; - const cost = pricer?.(rec) ?? 0; + // Copilot records carry their billed cost; the rest are priced here. + const cost = pricer ? rec.costUSD ?? pricer(rec) ?? 0 : 0; + // A record summing several requests (Copilot without per-request usage) has no context size. + const requests = rec.requests ?? 1; for (const b of buckets) { - if (rec.agent == null) { + if (rec.agent == null && !rec.aggregated) { b.contextTokensSum += context; b.contextRequests += 1; if (context > (b.sessionPeaks.get(rec.sessionId) ?? 0)) b.sessionPeaks.set(rec.sessionId, context); @@ -210,15 +216,16 @@ export function aggregate(data, { report = 'summary', since, until, project, tim b.cacheReadTokens += rec.cacheReadTokens; b.totalTokens += total; b.costUSD += cost; - b.requests += 1; - if (pricer && !pricer.isPriced(rec.model)) b.unpricedModels.add(rec.model); + b.requests += requests; + b.premiumRequests += rec.premiumRequests ?? 0; + if (pricer && rec.costUSD == null && !pricer.isPriced(rec.model)) b.unpricedModels.add(rec.model); const m = b.models.get(rec.model) ?? { requests: 0, totalTokens: 0, costUSD: 0 }; - m.requests += 1; + m.requests += requests; m.totalTokens += total; m.costUSD += cost; b.models.set(rec.model, m); const a = agentEntry(b, rec.agent); - a.requests += 1; + a.requests += requests; a.inputTokens += rec.inputTokens; a.outputTokens += rec.outputTokens; a.cacheCreationTokens += rec.cacheCreationTokens; diff --git a/src/attribution.mjs b/src/attribution.mjs index d3bad2a..8e76819 100644 --- a/src/attribution.mjs +++ b/src/attribution.mjs @@ -101,8 +101,9 @@ export class FileAttribution { } const next = rs[k + 1]; if (!next || r.human) continue; + // NaN when a request's context is unknown (Copilot logs without per-request usage). const delta = next.context - r.context - r.output; - if (delta <= 0) continue; + if (!(delta > 0)) continue; const weight = r.tools.reduce((s, t) => s + t.resultChars, 0); for (const t of r.tools) { t.measuredTokens = weight > 0 ? (delta * t.resultChars) / weight : delta / r.tools.length; @@ -119,7 +120,7 @@ export class FileAttribution { const next = rs[at]; item.model = next?.model ?? this.last?.model; item.cache1hShare = next?.cache1hShare ?? 0; - item.promptTokens = next?.context ?? 0; + item.promptTokens = next?.context || 0; } return this.items; } diff --git a/src/copilot.mjs b/src/copilot.mjs new file mode 100644 index 0000000..9c6d19c --- /dev/null +++ b/src/copilot.mjs @@ -0,0 +1,435 @@ +// Reads GitHub Copilot CLI session logs (~/.copilot/session-state//events.jsonl, +// also written by VS Code's Copilot agent) and returns the same normalized +// records as loadRecords() in src/loader.mjs, so every report works on them. +// +// Differences from Claude Code's transcripts that shape this loader: +// - Token usage is logged per request (session.usage_record) only by recent +// versions; older sessions only have per-model totals per run in +// session.shutdown. Those become one record per run, agent and model, with +// `requests` set and `aggregated` true (they carry no per-request context). +// Sessions that never shut down cleanly have no token counts at all. +// - Copilot's inputTokens include cache reads and writes; Claude's don't. +// - Billing is in AI credits (nano-AIU; 1 AIU = $0.01) and premium requests. +// A record's costUSD is its AI credits when any were billed; otherwise the +// report prices it like a Claude Code request. +// +// The format is undocumented, so every field access is defensive. + +import { createReadStream } from 'node:fs'; +import { readdir, readFile, stat } from 'node:fs/promises'; +import { createInterface } from 'node:readline'; +import { homedir } from 'node:os'; +import path from 'node:path'; +import { FileAttribution, createCalibration, charsPerToken, resolveTokens } from './attribution.mjs'; +import { shellCommands } from './shell.mjs'; +import { errorLine, normalizeSkillName } from './loader.mjs'; + +const NANO_AIU_PER_USD = 1e11; +const SHELLS = { powershell: 'PowerShell', bash: 'Bash' }; +const EDIT_TOOLS = new Set(['edit', 'create', 'apply_patch', 'write', 'str_replace_editor']); +const WEB_TOOLS = new Set(['web_search', 'web_fetch']); +const AGENT_TOOLS = new Set(['task']); +// Copilot logs no PR links of its own: PRs are found in the results of the calls that create them. +const PR_URL = /https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+/; +const createsPr = (raw, data, args) => + /create_pull_request/.test(data.mcpToolName ?? raw) || (SHELLS[raw] && /\bgh\s+pr\s+create\b/.test(String(args.command ?? ''))); + +/** Directories holding Copilot sessions, honoring COPILOT_HOME. */ +export function defaultCopilotDirs() { + const root = process.env.COPILOT_HOME || path.join(homedir(), '.copilot'); + return [path.join(root, 'session-state')]; +} + +async function listSessions(dirs) { + const sessions = []; + for (const dir of dirs) { + let entries; + try { + if (!(await stat(dir)).isDirectory()) continue; + entries = await readdir(dir, { withFileTypes: true }); + } catch { + continue; + } + for (const e of entries) { + if (!e.isDirectory()) continue; + const file = path.join(dir, e.name, 'events.jsonl'); + try { + await stat(file); + } catch { + continue; + } + sessions.push({ id: e.name, dir: path.join(dir, e.name), file }); + } + } + return sessions; +} + +async function exists(file) { + try { + await stat(file); + return true; + } catch { + return false; + } +} + +/** The `name:` line of workspace.yaml: the session's title. */ +async function readTitle(dir) { + try { + const yaml = await readFile(path.join(dir, 'workspace.yaml'), 'utf8'); + const m = /^name:\s*(.+)$/m.exec(yaml); + return m ? m[1].trim().replace(/^(['"])(.*)\1$/, '$2') : null; + } catch { + return null; + } +} + +/** Copilot token counts -> ccreports' (input without cached tokens). */ +function tokens(u) { + const cacheRead = u?.cacheReadTokens ?? 0; + const cacheWrite = u?.cacheWriteTokens ?? 0; + return { + inputTokens: Math.max(0, (u?.inputTokens ?? 0) - cacheRead - cacheWrite), + outputTokens: u?.outputTokens ?? 0, + cacheCreationTokens: cacheWrite, + cacheCreation1hTokens: 0, + cacheReadTokens: cacheRead, + }; +} + +const usd = (nanoAiu) => (nanoAiu > 0 ? nanoAiu / NANO_AIU_PER_USD : undefined); + +const textLength = (result) => + typeof result === 'string' ? result.length : String(result?.content ?? result?.detailedContent ?? '').length; + +/** "postToolUse" -> "PostToolUse", like Claude Code's hook events. */ +const hookEvent = (type) => (type ? type[0].toUpperCase() + type.slice(1) : 'unknown'); + +export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeSubagents = true } = {}) { + const usage = []; + const tools = new Map(); // toolCallId -> record + const skills = new Map(); + const commands = new Map(); + const hooks = new Map(); + const titles = new Map(); + const sessions = new Map(); + const psNames = new Map(); + const psName = (name) => { + if (!psNames.has(name.toLowerCase())) psNames.set(name.toLowerCase(), name); + return psNames.get(name.toLowerCase()); + }; + const calibration = createCalibration(); + const attributed = []; // per session: { items, inputTokens } (inputTokens: all input incl. cache, null when unknown) + + const list = await listSessions(dirs); + + for (const { id, dir, file } of list) { + const title = await readTitle(dir); + if (title) titles.set(id, title); + const info = { + entrypoint: (await exists(path.join(dir, 'vscode.metadata.json'))) ? 'copilot-vscode' : 'copilot-cli', + prompts: new Set(), + prs: new Set(), + compactions: new Set(), + modes: new Set(), // interactive, plan, autopilot + }; + sessions.set(id, info); + + let project = null; + const agentTypes = new Map(); // agentId -> subagent type + const attributions = new Map(); // agentId | '' -> FileAttribution (each agent has its own context) + const attributionOf = (agentId) => { + const key = agentId ?? ''; + if (!attributions.has(key)) attributions.set(key, new FileAttribution(calibration)); + return attributions.get(key); + }; + const contexts = new Map(); // apiCallId -> context of that request (usage_record precedes the message) + const hookRuns = new Map(); // hookInvocationId -> start event + const prCalls = new Set(); // toolCallIds of calls that create a pull request + const requests = []; // per-request usage records of this session + const runs = []; // session.shutdown events + let compactedBefore = false; + let pendingCommand = null; + let pendingSkillCall = null; // a `skill` tool call waiting for its skill.invoked + + const rl = createInterface({ input: createReadStream(file, { encoding: 'utf8' }), crlfDelay: Infinity }); + for await (const line of rl) { + // The large model.* and system.message events are never used. + if (line.startsWith('{"type":"model.') || line.startsWith('{"type":"system.message"')) continue; + let d; + try { + d = JSON.parse(line); + } catch { + continue; + } + const data = d.data ?? {}; + if (!d.timestamp) continue; + const agent = d.agentId ? agentTypes.get(d.agentId) ?? 'unknown' : null; + if (agent && !includeSubagents) continue; + const base = () => ({ timestamp: d.timestamp, sessionId: id, project: project ?? dir, agent, source: 'copilot' }); + + switch (d.type) { + case 'session.start': + case 'session.resume': + project ??= data.context?.cwd ?? null; + break; + + case 'session.mode_changed': + if (data.newMode) info.modes.add(data.newMode); + break; + + case 'subagent.started': + if (d.agentId) agentTypes.set(d.agentId, data.agentType || data.agentName || 'general-purpose'); + break; + + case 'session.compaction_complete': + if (data.success === false) break; + attributionOf(d.agentId).compact(); + if (!d.agentId) { + info.compactions.add(d.id ?? d.timestamp); + compactedBefore = true; + } + break; + + case 'session.usage_record': { + const u = data.usage ?? {}; + const t = tokens(u); + if (u.apiCallId) contexts.set(u.apiCallId, t.inputTokens + t.cacheCreationTokens + t.cacheReadTokens); + requests.push({ + ...base(), + key: u.apiCallId ?? d.id, + model: u.model ?? 'unknown', + ...t, + premiumRequests: u.cost ?? 0, + costUSD: usd(u.copilotUsage?.totalNanoAiu), + afterCompaction: compactedBefore, + }); + compactedBefore = false; + break; + } + + case 'session.shutdown': + runs.push(d); + break; + + case 'assistant.message': { + const key = data.messageId ?? d.id; + const att = attributionOf(d.agentId); + att.response(key, { + context: contexts.get(data.apiCallId) ?? NaN, + output: data.outputTokens ?? 0, + model: data.model ?? 'unknown', + cache1hShare: 0, + }); + for (const r of Array.isArray(data.toolRequests) ? data.toolRequests : []) { + if (r?.toolCallId) att.toolUse(key, r.toolCallId, JSON.stringify(r.arguments ?? {}).length, r.name === 'skill'); + } + break; + } + + case 'tool.execution_start': { + const raw = data.toolName; + if (!raw) break; + const name = data.mcpServerName + ? `mcp__${data.mcpServerName}__${data.mcpToolName ?? raw.replace(`${data.mcpServerName}-`, '')}` + : raw; + const tool = { ...base(), name }; + const args = data.arguments ?? {}; + if (AGENT_TOOLS.has(raw)) { + tool.subagentType = args.agent_type || 'general-purpose'; + if (args.mode === 'background') tool.background = true; + } + if (EDIT_TOOLS.has(raw)) tool.edit = true; + if (WEB_TOOLS.has(raw) || WEB_TOOLS.has(data.mcpToolName)) tool.web = true; + if (SHELLS[raw] && typeof args.command === 'string') { + const names = shellCommands(args.command, SHELLS[raw]); + tool.shellCommands = SHELLS[raw] === 'PowerShell' ? names.map(psName) : names; + } + tools.set(data.toolCallId ?? d.id, tool); + if (!d.agentId && createsPr(raw, data, args)) prCalls.add(data.toolCallId); + if (raw === 'skill') pendingSkillCall = { id: data.toolCallId ?? d.id, agentId: d.agentId }; + break; + } + + case 'tool.execution_complete': { + if (data.toolCallId) attributionOf(d.agentId).toolResult(data.toolCallId, textLength(data.result)); + const url = prCalls.has(data.toolCallId) && data.success !== false && PR_URL.exec(JSON.stringify(data.result ?? '')); + if (url) info.prs.add(url[0]); + break; + } + + case 'skill.invoked': { + const name = normalizeSkillName(data.name); + const att = attributionOf(d.agentId); + const chars = String(data.content ?? '').length; + const byUser = + data.trigger === 'user-invoked' || + (data.trigger == null && pendingCommand?.name === `/${name}`); + if (byUser) { + const skillId = d.id ?? `${id}:${d.timestamp}:${name}`; + skills.set(skillId, { ...base(), name, source: 'user' }); + att.skillContent(chars, skillId); + } else { + // Model-invoked: the record shares the id of its `skill` tool call, and so its tokens. + const skillId = pendingSkillCall?.id ?? d.id; + skills.set(skillId, { ...base(), name, source: 'model' }); + att.skillContent(chars); + } + pendingCommand = null; + pendingSkillCall = null; + break; + } + + case 'user.message': { + if (d.agentId) break; // a subagent's task + if (data.agentMode) info.modes.add(data.agentMode); + const src = data.source; + if (src != null && src !== 'user') break; // skill content, instructions, memory + const content = String(data.content ?? ''); + attributionOf(null).human(); + info.prompts.add(d.id ?? d.timestamp); + const m = /^\/([\w:.-]+)/.exec(content.trim()); + pendingCommand = null; + if (m) { + const name = '/' + normalizeSkillName(m[1]); + commands.set(d.id ?? `${id}:${d.timestamp}`, { ...base(), name }); + pendingCommand = { name }; + } + break; + } + + case 'hook.start': + if (data.hookInvocationId) hookRuns.set(data.hookInvocationId, d); + break; + + case 'hook.end': { + const start = hookRuns.get(data.hookInvocationId); + const event = hookEvent(data.hookType ?? start?.data?.hookType); + const message = data.error?.message ?? ''; + // A hook that errors denies the tool call too, but it failed: only a + // deliberate denial counts as blocking. + const denied = JSON.stringify(data.output ?? '').includes('Denied'); + const outcome = data.success !== false ? 'success' : denied && !data.error ? 'blocking_error' : 'non_blocking_error'; + const hook = { + ...base(), + event, + command: event, + outcome, + run: true, + durationMs: start ? Math.max(0, Date.parse(d.timestamp) - Date.parse(start.timestamp)) : 0, + contextChars: outcome === 'blocking_error' ? message.length : 0, + }; + if (outcome.endsWith('error')) hook.error = errorLine(message.replace(/^Error:\s*Hook command failed[^\n]*\n(Stderr:\s*)?/, '')); + hooks.set(data.hookInvocationId ?? d.id, hook); + break; + } + } + } + + // A session's project is where it started. + if (project) { + for (const map of [tools, skills, commands, hooks]) { + for (const rec of map.values()) if (rec.sessionId === id) rec.project = project; + } + } + + const sessionUsageStart = usage.length; + if (requests.length) { + for (const { key, ...r } of requests) usage.push({ ...r, project: project ?? r.project }); + } else { + // Per run, agent and model totals from each shutdown (each run counts from zero). + for (const run of runs) { + const data = run.data ?? {}; + const byAgent = data.agentMetrics ?? { main: { modelMetrics: data.modelMetrics } }; + for (const [agentId, metrics] of Object.entries(byAgent)) { + const agent = agentId === 'main' ? null : metrics.agentName || agentTypes.get(agentId) || 'unknown'; + if (agent && !includeSubagents) continue; + for (const [model, m] of Object.entries(metrics.modelMetrics ?? {})) { + const count = m.requests?.count ?? 0; + if (!count) continue; + usage.push({ + timestamp: run.timestamp, + sessionId: id, + project: project ?? dir, + agent, + source: 'copilot', + model, + ...tokens(m.usage), + requests: count, + aggregated: true, + premiumRequests: m.requests?.cost ?? 0, + costUSD: usd(m.totalNanoAiu), + }); + } + } + } + } + + const own = usage.slice(sessionUsageStart); + attributed.push({ + items: [...attributions.values()].flatMap((att) => att.finish()), + inputTokens: own.length ? own.reduce((s, r) => s + r.inputTokens + r.cacheCreationTokens + r.cacheReadTokens, 0) : null, + totalTokens: own.reduce((s, r) => s + r.inputTokens + r.outputTokens + r.cacheCreationTokens + r.cacheReadTokens, 0), + // Billed cost, when every request of the session was billed in AI credits. + costUSD: own.length && own.every((r) => r.costUSD != null) ? own.reduce((s, r) => s + r.costUSD, 0) : null, + }); + } + + const cpt = charsPerToken(calibration); + resolveTokens(attributed.flatMap((a) => a.items), cpt); + for (const { items, inputTokens, totalTokens, costUSD } of attributed) { + // Without the session's token counts the estimates have nothing to answer to. + if (inputTokens == null) continue; + // Few requests are measured, and Copilot trims old tool output from the + // context, so the estimates can exceed what the session sent: scale them + // down to at most its input. + const estimated = items.reduce((s, i) => s + i.tokens.cacheWriteTokens + i.tokens.cacheReadTokens, 0); + const f = estimated > inputTokens ? inputTokens / estimated : 1; + for (const item of items) { + const t = item.tokens; + t.cacheWriteTokens = Math.round(t.cacheWriteTokens * f); + t.cacheReadTokens = Math.round(t.cacheReadTokens * f); + t.total = t.outputTokens + t.cacheWriteTokens + t.cacheReadTokens; + // A share of what the session was billed, by tokens (else priced like Claude Code's). + if (costUSD != null && totalTokens) t.costUSD = (costUSD * t.total) / totalTokens; + const record = tools.get(item.id) ?? skills.get(item.id); + if (record) record.tokens = t; + if (tools.has(item.id) && skills.has(item.id)) skills.get(item.id).tokens = t; + } + } + for (const h of hooks.values()) h.contextTokens = Math.round(h.contextChars / cpt); + + return { + sessions, + charsPerToken: cpt, + files: list.length, + usage, + tools: [...tools.values()], + skills: [...skills.values()], + commands: [...commands.values()], + hooks: [...hooks.values()], + titles, + }; +} + +/** Combines the records of several sources into one data set. */ +export function mergeData(...parts) { + const [first, ...rest] = parts; + const out = { + ...first, + sessions: new Map(first.sessions), + titles: new Map(first.titles), + usage: [...first.usage], + tools: [...first.tools], + skills: [...first.skills], + commands: [...first.commands], + hooks: [...first.hooks], + }; + for (const p of rest) { + out.files += p.files; + for (const k of ['usage', 'tools', 'skills', 'commands', 'hooks']) out[k].push(...p[k]); + for (const [k, v] of p.sessions) out.sessions.set(k, v); + for (const [k, v] of p.titles) out.titles.set(k, v); + } + return out; +} diff --git a/src/formats.mjs b/src/formats.mjs index 4779da9..7f2468d 100644 --- a/src/formats.mjs +++ b/src/formats.mjs @@ -248,10 +248,11 @@ function htmlCards({ columns, rows }) { return `
${cards.join('\n')}
`; } -export function toHtml(doc, { generatedAt = new Date(), pricingSource, version } = {}) { +export function toHtml(doc, { generatedAt = new Date(), pricingSource, version, copilot = false } = {}) { const meta = [`Generated ${generatedAt.toLocaleString('sv-SE').slice(0, 16)}${version ? ` with ccreports ${version}` : ''}`]; + if (copilot) meta.push('GitHub Copilot cost from its billed AI credits'); if (pricingSource) { - meta.push(`cost estimates at ${pricingSource === 'builtin' ? 'built-in ' : ''}Claude API list prices`); + meta.push(`${copilot ? 'other ' : ''}cost estimates at ${pricingSource === 'builtin' ? 'built-in ' : ''}Claude API list prices`); } const sections = doc.sections .map((s) => { diff --git a/src/pricing.mjs b/src/pricing.mjs index 60a1757..b0618e5 100644 --- a/src/pricing.mjs +++ b/src/pricing.mjs @@ -149,7 +149,8 @@ function candidates(model) { const plain = model.replace(/\[.*\]$/, ''); // "claude-opus-5-5[1m]" const undated = plain.replace(/-\d{8}$/, ''); // "claude-haiku-4-5-20251001" const legacy = undated.replace(/^claude-(\d+)-(\d+)-([a-z]+)$/, 'claude-$3-$1-$2'); // "claude-3-5-haiku" - return [...new Set([plain, undated, legacy])]; + const dashed = undated.replace(/(\d)\.(\d)/g, '$1-$2'); // GitHub Copilot: "claude-sonnet-4.6" + return [...new Set([plain, undated, legacy, dashed])]; } /** diff --git a/src/recommendations.mjs b/src/recommendations.mjs index 2d2060b..cb03784 100644 --- a/src/recommendations.mjs +++ b/src/recommendations.mjs @@ -32,6 +32,98 @@ const TOOL_ADVICE = { const DEFAULT_TOOL_ADVICE = 'Its results are large: prefer tools or parameters that filter or page the results, lower `MAX_MCP_OUTPUT_TOKENS` (default 25,000) for MCP tools, or ask Claude to call it from a subagent so only a summary reaches your conversation.'; +// The same for GitHub Copilot's tools; what the user controls there: requests, +// `.github/copilot-instructions.md` / `AGENTS.md`, custom agents, skills, MCP servers and hooks. +const COPILOT_SHELL_ADVICE = (filters) => + `Make the repo's test and build scripts quiet (only failures), and ask in \`.github/copilot-instructions.md\` (or \`AGENTS.md\`) for short command output (${filters}). Every line of output stays in the context and is re-sent with each later request.`; +const COPILOT_SEARCH_ADVICE = + 'Ask in `.github/copilot-instructions.md` for narrow searches (a folder or file type, listing matching files before reading matches), and note where things live so Copilot needs fewer searches. For broad questions, ask for the `explore` agent: it searches in its own context.'; +const COPILOT_EDIT_ADVICE = + 'Patches stay in the context: ask Copilot to do sweeping rewrites in a subagent, so the main conversation only keeps the summary, and for large or repetitive files ask for a script that generates them instead of the files themselves.'; +const COPILOT_TOOL_ADVICE = { + powershell: COPILOT_SHELL_ADVICE('`Select-Object -First`, `Select-String`, quiet switches'), + bash: COPILOT_SHELL_ADVICE('`head`, `grep`, quiet flags'), + view: 'Note in `.github/copilot-instructions.md` where things live, so Copilot opens the right file without reading around it; split very large files; and ask for the `explore` agent for broad "find where…" questions, so the file contents stay out of your conversation.', + rg: COPILOT_SEARCH_ADVICE, + grep: COPILOT_SEARCH_ADVICE, + glob: COPILOT_SEARCH_ADVICE, + apply_patch: COPILOT_EDIT_ADVICE, + edit: COPILOT_EDIT_ADVICE, + create: COPILOT_EDIT_ADVICE, + task: 'A subagent\'s final message is what lands in your context: ask for short, structured answers (a list of findings, file paths) in your custom agents\' definitions (`.github/agents/.agent.md`) and when you delegate to built-in ones.', + skill: TOOL_ADVICE.Skill, +}; +const COPILOT_DEFAULT_TOOL_ADVICE = + 'Its results are large: prefer tools or parameters that filter or page the results, turn off MCP servers you don\'t need for the task (`/mcp`), or ask Copilot to call it from a subagent so only a summary reaches your conversation.'; + +// What differs per product: tool names and the advice, which names that product's own levers. +const PRODUCTS = { + claude: { + name: 'Claude Code', + explorationTools: EXPLORATION_TOOLS, + toolAdvice: TOOL_ADVICE, + defaultToolAdvice: DEFAULT_TOOL_ADVICE, + subagentModel: true, + subagentTokens: true, // subagents' tokens are logged separately + worktrees: true, + advice: { + longContext: + 'Start a new session, or `/clear`, when you switch tasks, and `/compact` with a hint of what to keep when a long task has to continue. Each request re-sends the whole context, so a turn at 400k tokens costs about ten times one at 40k.', + delegate: + 'Ask Claude to use an Explore subagent for "find where…" and "how does … work" questions: it reads in its own context and returns a summary, so the file contents never stay in your main conversation.', + compaction: + 'Compaction replaces the conversation with a summary and loses detail. Break big work into tasks that fit one session, `/clear` between them, or run `/compact` yourself at a natural break with instructions on what to keep.', + cache: { + expired: + 'The main conversation\'s cache lasts 5 minutes with an API key or cloud provider and 1 hour on a Claude subscription; the `promptCacheTtl` setting (`5m` or `1h`) chooses it, and 1-hour cache writes cost more. Before you continue a large conversation after a break, `/compact` it (or `/clear` for unrelated work) so a smaller context is rebuilt; `/usage` shows whether the cache is still warm.', + invalidated: + 'A miss without a pause means the start of the prompt changed. With tool search on (the default on supported models) MCP servers connecting mid-session no longer do this; with it off, servers connecting or tools being removed mid-session do, so keep the tool set stable during a conversation.', + 'model switch': 'Each model has its own cache: switching with `/model` mid-conversation re-reads the whole history. Pick the model at the start, or `/compact` before you switch.', + }, + autonomy: + 'Describe the whole task up front - goal, constraints and how to verify it - and let Claude run. Use plan mode for bigger changes, and turn workflows you repeat into skills.', + parallel: + 'Ask Claude to run independent tasks as parallel subagents: they run in the background while you keep working (`Ctrl+B` moves a long-running one there). When several agents change code at the same time, give each its own worktree: `isolation: worktree` in an agent\'s definition, or `claude -w ` for a whole session.', + skills: + 'Capture the instructions you keep repeating (how to test, release, review or plan in this repo) as a skill, so Claude follows them every time without you typing them out.', + hooks: + 'A failing hook gives none of the protection it was added for. Use absolute paths (`"$CLAUDE_PROJECT_DIR"/.claude/hooks/…`) so hooks still resolve when Claude works in a subfolder, check that the interpreter (python, node) is on PATH, and remove stale ones from the settings file that defines them (`/hooks` lists them, read-only).', + }, + }, + copilot: { + name: 'GitHub Copilot', + explorationTools: new Set(['view', 'grep', 'glob', 'rg']), + toolAdvice: COPILOT_TOOL_ADVICE, + defaultToolAdvice: COPILOT_DEFAULT_TOOL_ADVICE, + subagentTokens: false, + subagentModel: false, // Copilot bills by its own rates and multipliers, not Claude's + worktrees: false, + advice: { + longContext: + 'Start a new session, or `/clear`, when you switch tasks, and `/compact` when a long task has to continue; `/context` shows what fills the context. Each request re-sends the whole context, so a turn at 400k tokens costs about ten times one at 40k.', + delegate: + 'Ask Copilot to use the `explore` agent for "find where…" and "how does … work" questions: it reads in its own context and returns a summary, so the file contents never stay in your main conversation.', + compaction: + 'Compaction replaces the conversation with a summary and loses detail. Break big work into tasks that fit one session, `/clear` between them, or run `/compact` yourself at a natural break.', + cache: { + expired: + 'Copilot\'s prompt cache lasts only minutes without a request (your logs show a 5-minute lifetime). Before you continue a large conversation after a break, `/compact` it (or `/clear` for unrelated work) so a smaller context is rebuilt.', + invalidated: + 'A miss without a pause means the start of the prompt changed, for example when MCP servers or tools are added or removed mid-session: keep the tool set stable during a conversation.', + 'model switch': 'Each model has its own cache: switching with `/model` mid-conversation re-reads the whole history. Pick the model at the start, or `/compact` before you switch.', + }, + autonomy: + 'Describe the whole task up front - goal, constraints and how to verify it - and let Copilot run. Use plan mode (`Shift+Tab`) for bigger changes and autopilot to let an approved plan run without check-ins, and turn workflows you repeat into skills.', + parallel: + 'Ask Copilot to run independent tasks as background agents: they keep working while the conversation goes on, and Copilot collects their results when they finish.', + skills: + 'Capture the instructions you keep repeating (how to test, release, review or plan in this repo) as a skill (`.github/skills//SKILL.md`, or `~/.copilot/skills` for all your projects), so Copilot follows them every time without you typing them out.', + hooks: + 'A failing hook gives none of the protection it was added for, and a failing `preToolUse` hook also denies the tool call. Use absolute paths so hooks still resolve when Copilot works in a subfolder, check that the interpreter (python, node) is on PATH, and remove stale ones from the configuration that defines them.', + }, + }, +}; + const fmt = (n) => Math.round(n).toLocaleString('en-US'); const tok = (n) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${Math.round(n / 1e3)}k` : String(Math.round(n))); const pct = (v) => `${Math.round(v * 100)}%`; @@ -48,7 +140,7 @@ const usd = (v) => `$${v.toFixed(2)}`; export function cacheMisses(usage, pricer) { const bySession = new Map(); for (const r of usage) { - if (r.agent) continue; // subagents run without pauses + if (r.agent || r.aggregated) continue; // subagents run without pauses; totals of several requests have no context const list = bySession.get(r.sessionId) ?? []; list.push(r); bySession.set(r.sessionId, list); @@ -90,12 +182,14 @@ export function cacheMisses(usage, pricer) { */ export function recommend(data, opts = {}) { const { pricer } = opts; + const p = PRODUCTS[opts.source ?? 'claude']; const inRange = recordFilter(opts); const usage = data.usage.filter(inRange); if (!usage.length) return []; const { totals } = aggregate(data, { ...opts, report: 'summary' }); const stats = sessionStats(data, opts); - const costOf = (rec) => (pricer ? pricer(rec) ?? 0 : 0); + // GitHub Copilot records carry their billed cost. + const costOf = (rec) => (pricer ? rec.costUSD ?? pricer(rec) ?? 0 : 0); const totalCost = totals.costUSD; const recs = []; // Money where we can price it, else a share of tokens. @@ -106,6 +200,7 @@ export function recommend(data, opts = {}) { let longCost = 0; let longTokens = 0; for (const r of usage) { + if (r.aggregated) continue; // totals of several requests: no context size const context = r.inputTokens + r.cacheCreationTokens + r.cacheReadTokens; if (context > LONG_CONTEXT) { longCost += costOf(r); @@ -122,8 +217,7 @@ export function recommend(data, opts = {}) { atStakeUSD: pricer ? longCost : null, atStakeTokens: longTokens, evidence: `${pct(share)} of your ${pricer ? 'cost' : 'tokens'} (${stake(longCost, longTokens)}) came from requests carrying more than ${tok(LONG_CONTEXT)} tokens of context; ${bigSessions} session${bigSessions === 1 ? '' : 's'} peaked above ${tok(PEAK_CONTEXT)} (largest ${tok(Math.max(...peaks))}).`, - advice: - 'Start a new session, or `/clear`, when you switch tasks, and `/compact` with a hint of what to keep when a long task has to continue. Each request re-sends the whole context, so a turn at 400k tokens costs about ten times one at 40k.', + advice: p.advice.longContext, }); } } @@ -142,11 +236,11 @@ export function recommend(data, opts = {}) { const share = t.tokens / (totals.totalTokens || 1); recs.push({ id: `heavy-tool:${name}`, - title: TOOL_ADVICE[name] ? `Trim what ${name} puts into the context` : `Rein in ${name}'s large results`, + title: p.toolAdvice[name] ? `Trim what ${name} puts into the context` : `Rein in ${name}'s large results`, atStakeUSD: pricer ? t.costUSD : null, atStakeTokens: t.tokens, evidence: `${name}: ${fmt(calls)} call${calls === 1 ? '' : 's'}, ~${tok(t.tokens)} tokens (${pct(share)} of all tokens${pricer ? `, ~${usd(t.costUSD)}` : ''}), ~${tok(t.tokens / calls)} per call including re-reads.`, - advice: TOOL_ADVICE[name] ?? DEFAULT_TOOL_ADVICE, + advice: p.toolAdvice[name] ?? p.defaultToolAdvice, }); } @@ -154,32 +248,40 @@ export function recommend(data, opts = {}) { { let tokens = 0; for (const t of data.tools) { - if (t.agent || !EXPLORATION_TOOLS.has(t.name) || !t.tokens || !inRange(t)) continue; + if (t.agent || !p.explorationTools.has(t.name) || !t.tokens || !inRange(t)) continue; tokens += t.tokens.total; } // The tool totals include subagents' calls; prorate their cost to the main conversation's share. - const exploreTotals = [...EXPLORATION_TOOLS].map((n) => totals.toolTokens.get(n)).filter(Boolean); + const exploreTotals = [...p.explorationTools].map((n) => totals.toolTokens.get(n)).filter(Boolean); const allTokens = exploreTotals.reduce((s, t) => s + t.tokens, 0); const allCost = exploreTotals.reduce((s, t) => s + t.costUSD, 0); const cost = allTokens ? (allCost * tokens) / allTokens : 0; const share = tokens / (totals.totalTokens || 1); const main = totals.agents.get(MAIN_AGENT)?.totalTokens ?? 0; const subagentShare = 1 - main / (totals.totalTokens || 1); - if (share >= 0.12 && subagentShare < 0.25) { + // Older Copilot logs count subagents' tokens as the main session's: there, + // subagent use is the share of sessions that launched one. + const delegating = p.subagentTokens + ? subagentShare + : stats.filter((s) => s.subagentLaunches > 0).length / (stats.length || 1); + if (share >= 0.12 && delegating < 0.25) { recs.push({ id: 'delegate-exploration', title: 'Delegate codebase exploration to subagents', atStakeUSD: pricer ? cost : null, atStakeTokens: tokens, - evidence: `Reading and searching files in your main conversation took ~${tok(tokens)} tokens (${pct(share)} of all), while subagents handled ${pct(subagentShare)} of your tokens.`, - advice: - 'Ask Claude to use an Explore subagent for "find where…" and "how does … work" questions: it reads in its own context and returns a summary, so the file contents never stay in your main conversation.', + evidence: `Reading and searching files in your main conversation took ~${tok(tokens)} tokens (${pct(share)} of all), while ${ + p.subagentTokens + ? `subagents handled ${pct(subagentShare)} of your tokens` + : `${pct(delegating)} of your sessions launched a subagent (${fmt(totals.subagentLaunches)} launches)` + }.`, + advice: p.advice.delegate, }); } } // 5. Subagents on a premium model: reprice their requests on Sonnet. - if (pricer) { + if (pricer && p.subagentModel) { const byType = new Map(); for (const r of usage) { // Forks share the parent's context and model, so they can't run on another one. @@ -216,8 +318,7 @@ export function recommend(data, opts = {}) { title: 'Split long tasks before the context fills up', atStakeUSD: null, evidence: `${compacted.length} of ${stats.length} sessions hit compaction (${count} time${count === 1 ? '' : 's'} in total).`, - advice: - 'Compaction replaces the conversation with a summary and loses detail. Break big work into tasks that fit one session, `/clear` between them, or run `/compact` yourself at a natural break with instructions on what to keep.', + advice: p.advice.compaction, }); } } @@ -240,13 +341,7 @@ export function recommend(data, opts = {}) { invalidated: (c) => `${c.count} without a pause, when something early in the conversation changed`, 'model switch': (c) => `${c.count} after a model switch`, }; - const advice = { - expired: - 'The main conversation\'s cache lasts 5 minutes with an API key or cloud provider and 1 hour on a Claude subscription; the `promptCacheTtl` setting (`5m` or `1h`) chooses it, and 1-hour cache writes cost more. Before you continue a large conversation after a break, `/compact` it (or `/clear` for unrelated work) so a smaller context is rebuilt; `/usage` shows whether the cache is still warm.', - invalidated: - 'A miss without a pause means the start of the prompt changed. With tool search on (the default on supported models) MCP servers connecting mid-session no longer do this; with it off, servers connecting or tools being removed mid-session do, so keep the tool set stable during a conversation.', - 'model switch': 'Each model has its own cache: switching with `/model` mid-conversation re-reads the whole history. Pick the model at the start, or `/compact` before you switch.', - }; + const advice = p.advice.cache; const top = [...causes].sort((a, b) => b.extraUSD - a.extraUSD); recs.push({ id: 'cache-rebuilds', @@ -271,13 +366,17 @@ export function recommend(data, opts = {}) { return v.length ? v[Math.floor(v.length / 2)] : 0; }; const agentic = coding.filter((s) => s.phase !== 'assisted'); + // Copilot logs the modes a session ran in. + const modes = (mode) => coding.filter((s) => data.sessions.get(s.id)?.modes?.has(mode)).length; + const modeText = data.sessions.get(coding[0].id)?.modes + ? ` Plan mode was used in ${modes('plan')} and autopilot in ${modes('autopilot')} of ${coding.length} coding sessions.` + : ''; recs.push({ id: 'autonomy', title: 'Hand over whole tasks', atStakeUSD: null, - evidence: `${pct(assisted.length / coding.length)} of your coding sessions are step by step (median ${median(assisted).toFixed(1)} tool calls per prompt${agentic.length ? `, against ${median(agentic).toFixed(1)} in agent-first sessions` : ''}).`, - advice: - 'Describe the whole task up front - goal, constraints and how to verify it - and let Claude run. Use plan mode for bigger changes, and turn workflows you repeat into skills.', + evidence: `${pct(assisted.length / coding.length)} of your coding sessions are step by step (median ${median(assisted).toFixed(1)} tool calls per prompt${agentic.length ? `, against ${median(agentic).toFixed(1)} in agent-first sessions` : ''}).${modeText}`, + advice: p.advice.autonomy, }); } } @@ -287,14 +386,15 @@ export function recommend(data, opts = {}) { const share = (f) => stats.filter(f).length / stats.length; const background = share((s) => s.backgroundAgents > 0); const worktrees = share((s) => s.worktrees > 0); - if (background < 0.1 && worktrees < 0.1) { + if (background < 0.1 && (!p.worktrees || worktrees < 0.1)) { recs.push({ id: 'parallel', title: 'Run independent work in parallel', atStakeUSD: null, - evidence: `Background agents appear in ${pct(background)} and worktrees in ${pct(worktrees)} of your sessions.`, - advice: - 'Ask Claude to run independent tasks as parallel subagents: they run in the background while you keep working (`Ctrl+B` moves a long-running one there). When several agents change code at the same time, give each its own worktree: `isolation: worktree` in an agent\'s definition, or `claude -w ` for a whole session.', + evidence: p.worktrees + ? `Background agents appear in ${pct(background)} and worktrees in ${pct(worktrees)} of your sessions.` + : `Background agents appear in ${pct(background)} of your sessions.`, + advice: p.advice.parallel, }); } const skills = share((s) => s.skills > 0); @@ -304,8 +404,7 @@ export function recommend(data, opts = {}) { title: 'Turn recurring workflows into skills', atStakeUSD: null, evidence: `Skills were used in ${pct(skills)} of your sessions.`, - advice: - 'Capture the instructions you keep repeating (how to test, release, review or plan in this repo) as a skill, so Claude follows them every time without you typing them out.', + advice: p.advice.skills, }); } } @@ -326,8 +425,7 @@ export function recommend(data, opts = {}) { title: 'Fix or remove hooks that keep failing', atStakeUSD: null, evidence: `${failing.length} hook${failing.length === 1 ? '' : 's'} failed ${fmt(errors)} times (${Math.round(seconds)}s spent): ${shown.join('; ')}${failing.length > 3 ? '; …' : ''}.`, - advice: - 'A failing hook gives none of the protection it was added for. Use absolute paths (`"$CLAUDE_PROJECT_DIR"/.claude/hooks/…`) so hooks still resolve when Claude works in a subfolder, check that the interpreter (python, node) is on PATH, and remove stale ones from the settings file that defines them (`/hooks` lists them, read-only).', + advice: p.advice.hooks, }); } } @@ -351,7 +449,7 @@ export function buildRecommendations(data, opts) { const items = recommend(data, opts); const range = opts.since || opts.until ? ` (${opts.since ?? '…'} → ${opts.until ?? 'today'})` : ''; return { - title: `Claude Code recommendations${range}`, + title: `${PRODUCTS[opts.source ?? 'claude'].name} recommendations${range}`, summary: items.length ? [] : ['No clear improvement found in this period - your usage already follows the patterns checked.'], sections: items.length ? [{ title: 'Recommendations', note: 'most impact first; amounts at stake overlap', items }] diff --git a/src/report.mjs b/src/report.mjs index 0d26006..4857dae 100644 --- a/src/report.mjs +++ b/src/report.mjs @@ -122,6 +122,13 @@ function shortModel(model) { return model.replace(/^claude-/, '').replace(/-\d{8}$/, ''); } +/** GitHub Copilot bills premium requests besides AI credits. */ +function premiumLine(totals) { + if (!totals.premiumRequests) return []; + const n = Math.round(totals.premiumRequests * 100) / 100; + return [`${n.toLocaleString('en-US')} GitHub Copilot premium request${n === 1 ? '' : 's'} (by model multiplier).`]; +} + function rangeText({ since, until }) { return since || until ? ` (${since ?? '…'} → ${until ?? 'today'})` : ''; } @@ -266,7 +273,7 @@ export function buildPeriodReport(report, { buckets, totals }, opts) { }); return { - title: `Claude Code ${PERIOD[report].name} usage${rangeText(opts)}`, + title: `${opts.product ?? 'Claude Code'} ${PERIOD[report].name} usage${rangeText(opts)}`, sections: [{ columns, rows }, ...(opts.plugins?.length ? [pluginSection(opts.plugins)] : [])], }; } @@ -452,5 +459,5 @@ export function buildSummary({ totals }, opts) { ([name, m]) => [name, m.requests, m.totalTokens, ...costCell(m.costUSD), share(m.totalTokens, totals.totalTokens)], ); - return { title: `Claude Code usage summary${rangeText(opts)}`, sections }; + return { title: `${opts.product ?? 'Claude Code'} usage summary${rangeText(opts)}`, summary: premiumLine(totals), sections }; } diff --git a/test/copilot.test.mjs b/test/copilot.test.mjs new file mode 100644 index 0000000..486fa99 --- /dev/null +++ b/test/copilot.test.mjs @@ -0,0 +1,233 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import path from 'node:path'; +import { loadCopilotRecords, mergeData } from '../src/copilot.mjs'; +import { aggregate } from '../src/aggregate.mjs'; +import { createPricer, BUILTIN } from '../src/pricing.mjs'; +import { sessionStats } from '../src/adoption.mjs'; + +const ev = (type, timestamp, data, extra = {}) => ({ type, data, id: `${type}-${timestamp}`, timestamp, ...extra }); + +// A session with per-request usage (recent Copilot versions). +const recent = [ + ev('session.start', '2026-10-01T10:00:00Z', { sessionId: 'c1', context: { cwd: '/work/app' } }), + ev('user.message', '2026-10-01T10:00:01Z', { content: '/forge-plan add a button' }), + ev('skill.invoked', '2026-10-01T10:00:01.5Z', { name: 'forge-plan', content: 'x'.repeat(240) }), + ev('session.usage_record', '2026-10-01T10:00:02Z', { + usage: { + model: 'claude-sonnet-5.5', + apiCallId: 'a1', + inputTokens: 1100, + outputTokens: 50, + cacheReadTokens: 600, + cacheWriteTokens: 400, + cost: 1, + copilotUsage: { totalNanoAiu: 2_000_000_000 }, + }, + }), + ev('assistant.message', '2026-10-01T10:00:03Z', { + messageId: 'm1', + apiCallId: 'a1', + model: 'claude-sonnet-5.5', + outputTokens: 50, + toolRequests: [ + { toolCallId: 't1', name: 'powershell', arguments: { command: 'git status; gh pr create --fill' } }, + { toolCallId: 't2', name: 'apply_patch', arguments: { patch: '...' } }, + ], + }), + ev('tool.execution_start', '2026-10-01T10:00:03Z', { toolCallId: 't1', toolName: 'powershell', arguments: { command: 'git status; gh pr create --fill' } }), + ev('tool.execution_complete', '2026-10-01T10:00:04Z', { + toolCallId: 't1', + success: true, + result: { content: 'https://github.com/acme/app/pull/7' }, + }), + ev('tool.execution_start', '2026-10-01T10:00:04Z', { toolCallId: 't2', toolName: 'apply_patch', arguments: {} }), + ev('tool.execution_complete', '2026-10-01T10:00:05Z', { toolCallId: 't2', success: true, result: { content: 'ok' } }), + ev('tool.execution_start', '2026-10-01T10:00:06Z', { + toolCallId: 't3', + toolName: 'github-mcp-server-search_code', + mcpServerName: 'github-mcp-server', + mcpToolName: 'search_code', + arguments: {}, + }), + ev('hook.start', '2026-10-01T10:00:06Z', { hookInvocationId: 'h1', hookType: 'preToolUse' }), + ev('hook.end', '2026-10-01T10:00:06.5Z', { + hookInvocationId: 'h1', + hookType: 'preToolUse', + success: false, + error: { message: "Error: Hook command failed with code 1\nStderr: Error: Cannot find module 'x'" }, + }), + ev('session.shutdown', '2026-10-01T10:05:00Z', { + // Ignored: the session has per-request usage records. + modelMetrics: { 'claude-sonnet-5.5': { requests: { count: 1, cost: 1 }, usage: { inputTokens: 1100 } } }, + }), +]; + +// An older session: only per-run totals at shutdown, with a subagent. +const older = [ + ev('session.start', '2026-09-01T10:00:00Z', { sessionId: 'c2', context: { cwd: '/work/lib' } }), + ev('user.message', '2026-09-01T10:00:01Z', { content: 'explain this repo' }), + ev('user.message', '2026-09-01T10:00:01Z', { content: 'skill text', source: 'skill-forge-plan' }), + ev('tool.execution_start', '2026-09-01T10:00:02Z', { toolCallId: 'k1', toolName: 'task', arguments: { agent_type: 'explore', mode: 'background' } }), + ev('subagent.started', '2026-09-01T10:00:02Z', { agentType: 'explore', agentName: 'explore' }, { agentId: 'ag1' }), + ev('tool.execution_start', '2026-09-01T10:00:03Z', { toolCallId: 'k2', toolName: 'view', arguments: {} }, { agentId: 'ag1' }), + ev('session.shutdown', '2026-09-01T11:00:00Z', { + agentMetrics: { + main: { modelMetrics: { 'claude-sonnet-4.6': { requests: { count: 4, cost: 2 }, usage: { inputTokens: 1000, outputTokens: 100, cacheReadTokens: 800, cacheWriteTokens: 0 } } } }, + ag1: { agentName: 'explore', modelMetrics: { 'gpt-5.4': { requests: { count: 3, cost: 0 }, usage: { inputTokens: 300, outputTokens: 30 }, totalNanoAiu: 5_000_000_000 } } }, + }, + }), +]; + +async function fixture() { + const root = await mkdtemp(path.join(tmpdir(), 'ccreports-copilot-')); + const write = async (id, events, yaml) => { + await mkdir(path.join(root, id), { recursive: true }); + await writeFile(path.join(root, id, 'events.jsonl'), events.map((e) => JSON.stringify(e)).join('\n') + '\nnot json\n'); + if (yaml) await writeFile(path.join(root, id, 'workspace.yaml'), yaml); + }; + await write('c1', recent, 'id: c1\nname: Add A Button\n'); + await write('c2', older); + await writeFile(path.join(root, 'c2', 'vscode.metadata.json'), '{}'); + await mkdir(path.join(root, 'empty')); + return root; +} + +test('loadCopilotRecords normalizes usage, tools, skills, commands and hooks', async () => { + const root = await fixture(); + try { + const data = await loadCopilotRecords({ dirs: [root] }); + assert.equal(data.files, 2); + assert.equal(data.titles.get('c1'), 'Add A Button'); + + // Per-request record: input excludes the cached tokens; cost from AI credits. + const c1 = data.usage.filter((u) => u.sessionId === 'c1'); + assert.equal(c1.length, 1); + assert.deepEqual( + [c1[0].inputTokens, c1[0].cacheReadTokens, c1[0].cacheCreationTokens, c1[0].premiumRequests, c1[0].costUSD], + [100, 600, 400, 1, 0.02], + ); + assert.equal(c1[0].project, '/work/app'); + + // Shutdown totals: one record per agent and model, summing several requests. + const c2 = data.usage.filter((u) => u.sessionId === 'c2'); + assert.deepEqual( + c2.map((u) => [u.agent, u.model, u.requests, u.aggregated, u.inputTokens]), + [ + [null, 'claude-sonnet-4.6', 4, true, 200], + ['explore', 'gpt-5.4', 3, true, 300], + ], + ); + assert.equal(c2[0].costUSD, undefined); // nothing billed in AI credits: priced by the report + + const tool = (id) => data.tools.find((t) => t.sessionId === id.s && t.name === id.name); + assert.deepEqual(tool({ s: 'c1', name: 'powershell' }).shellCommands, ['git', 'gh']); + assert.equal(tool({ s: 'c1', name: 'apply_patch' }).edit, true); + assert.ok(tool({ s: 'c1', name: 'mcp__github-mcp-server__search_code' })); + const task = tool({ s: 'c2', name: 'task' }); + assert.deepEqual([task.subagentType, task.background], ['explore', true]); + assert.equal(tool({ s: 'c2', name: 'view' }).agent, 'explore'); + + assert.deepEqual(data.commands.map((c) => c.name), ['/forge-plan']); + assert.deepEqual(data.skills.map((s) => [s.name, s.source]), [['forge-plan', 'user']]); + + assert.equal(data.hooks.length, 1); + assert.equal(data.hooks[0].event, 'PreToolUse'); + assert.equal(data.hooks[0].outcome, 'non_blocking_error'); + assert.equal(data.hooks[0].error, "Error: Cannot find module 'x'"); + assert.equal(data.hooks[0].durationMs, 500); + + // Prompts exclude injected skill text; PRs come from `gh pr create` output. + assert.equal(data.sessions.get('c1').prompts.size, 1); + assert.equal(data.sessions.get('c2').prompts.size, 1); + assert.deepEqual([...data.sessions.get('c1').prs], ['https://github.com/acme/app/pull/7']); + assert.equal(data.sessions.get('c1').entrypoint, 'copilot-cli'); + assert.equal(data.sessions.get('c2').entrypoint, 'copilot-vscode'); + + const sub = await loadCopilotRecords({ dirs: [root], includeSubagents: false }); + assert.ok(!sub.usage.some((u) => u.agent) && !sub.tools.some((t) => t.agent)); + } finally { + await rm(root, { recursive: true, force: true }); + } +}); + +test('aggregate uses billed Copilot cost, request counts and premium requests', async () => { + const root = await fixture(); + try { + const data = await loadCopilotRecords({ dirs: [root] }); + const pricer = createPricer(BUILTIN); + const { totals } = aggregate(data, { pricer }); + assert.equal(totals.requests, 1 + 4 + 3); + assert.equal(totals.premiumRequests, 1 + 2); + // Sonnet 4.6 (dotted name) priced at API rates; gpt-5.4 billed 5 AIU = $0.05. + const sonnet = (200 * 3 + 100 * 15 + 800 * 0.3) / 1e6; + assert.ok(Math.abs(totals.costUSD - (0.02 + sonnet + 0.05)) < 1e-9); + assert.equal(totals.unpricedModels.size, 0); + // Context only from per-request records of the main session. + assert.equal(totals.contextRequests, 1); + assert.equal(totals.maxContextTokens, 1100); + + const stats = sessionStats(data, {}); + const c1 = stats.find((s) => s.id === 'c1'); + assert.deepEqual([c1.edits, c1.prs, c1.surface], [1, 1, 'Copilot CLI']); + } finally { + await rm(root, { recursive: true, force: true }); + } +}); + +test('mergeData combines sources', () => { + const part = (id) => ({ + files: 1, + usage: [{ sessionId: id }], + tools: [], + skills: [], + commands: [], + hooks: [], + sessions: new Map([[id, {}]]), + titles: new Map(), + }); + const merged = mergeData(part('a'), part('b')); + assert.equal(merged.files, 2); + assert.equal(merged.usage.length, 2); + assert.deepEqual([...merged.sessions.keys()], ['a', 'b']); +}); + +test('Copilot recommendations use Copilot advice and skip context for shutdown totals', async () => { + const { recommend } = await import('../src/recommendations.mjs'); + const rec = (i, extra) => ({ + timestamp: `2026-10-0${1 + (i % 9)}T10:00:00Z`, + sessionId: `s${i}`, + project: '/work/app', + agent: null, + source: 'copilot', + model: 'gpt-5.4', + inputTokens: 1000, + outputTokens: 100, + cacheCreationTokens: 0, + cacheReadTokens: 0, + costUSD: 1, + ...extra, + }); + const tokens = (total) => ({ total, outputTokens: 0, cacheWriteTokens: total, cacheReadTokens: 0, costUSD: 0.5 }); + const data = { + // Shutdown totals with a huge summed context: not a long-context request. + usage: Array.from({ length: 10 }, (_, i) => rec(i, { cacheReadTokens: 900_000, requests: 50, aggregated: true })), + tools: Array.from({ length: 10 }, (_, i) => ({ ...rec(i), name: 'view', tokens: tokens(300_000) })), + skills: [], + commands: [], + hooks: [], + sessions: new Map(Array.from({ length: 10 }, (_, i) => [`s${i}`, { prompts: new Set([1]), prs: new Set(), compactions: new Set(), modes: new Set() }])), + titles: new Map(), + }; + const items = recommend(data, { source: 'copilot', pricer: Object.assign(() => 0, { isPriced: () => true }) }); + const ids = items.map((r) => r.id); + assert.ok(!ids.includes('long-context')); + assert.ok(!ids.includes('subagent-model')); + const delegate = items.find((r) => r.id === 'delegate-exploration'); + assert.match(delegate.evidence, /0% of your sessions launched a subagent/); + assert.match(delegate.advice, /`explore` agent/); + assert.match(items.find((r) => r.id === 'heavy-tool:view').advice, /copilot-instructions\.md/); + assert.ok(!items.some((r) => /CLAUDE|Claude/.test(r.advice))); +});