From bbc9e164c156ea3699c9eced5bd51bf3de8cbbe3 Mon Sep 17 00:00:00 2001 From: Peter Bons Date: Wed, 4 Nov 2026 10:20:31 +0100 Subject: [PATCH 1/3] Classify sessions by intent in the adoption report Every session gets an intent - bug fix, new development, refactoring, tests, planning & design, docs & content, ops & config, review, research & analysis or other - from rules over its commit messages and PR titles, review commands, title, git branch prefix, first prompt and the files it changed. The adoption report adds a Session intent section and a summary line; JSON carries each session's intent and the evidence for it. Claude Code, Copilot and Cursor loaders record the branch, first prompt, commit messages and changed files. Co-Authored-By: Claude Opus 5.5 --- README.md | 16 ++++- skills/report/SKILL.md | 4 ++ src/adoption.mjs | 69 ++++++++++++++++++++- src/copilot.mjs | 20 +++++- src/cursor.mjs | 20 +++++- src/intent.mjs | 134 ++++++++++++++++++++++++++++++++++++++++ src/loader.mjs | 39 +++++++++++- test/adoption.test.mjs | 16 +++++ test/ccreports.test.mjs | 28 +++++++++ test/intent.test.mjs | 68 ++++++++++++++++++++ 10 files changed, 407 insertions(+), 7 deletions(-) create mode 100644 src/intent.mjs create mode 100644 test/intent.test.mjs diff --git a/README.md b/README.md index 79bb90b..c9628c7 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,21 @@ session; the phase mix per week; how many sessions use each capability surface (CLI, desktop, IDE, SDK, and the Copilot and Cursor surfaces with `--source`). PRs are the `pr-link` entries Claude Code records when it creates a PR; prompts exclude agent-to-agent messages and -task notifications. `--json` returns the per-session stats and phase. +task notifications. `--json` returns the per-session stats, phase and intent. + +It closes with **session intent**, what each session was for: bug fix, new +development, refactoring, tests, planning & design, docs & content, ops & +config, review, research & analysis, or other. The intent comes from rules, +not a model, and the strongest signal wins: + +1. conventional commit messages and PR titles the session wrote (`fix:`, `feat:`, `refactor:`, `docs:`, `chore:`, ...), +2. review commands (`/code-review`, `/review`, `/security-review`), +3. words in the session title, then the git branch prefix (`fix/`, `feature/`, ...), then the first prompt, +4. what it changed: only plan / spec documents, docs, tests or CI and config files; mostly new files; or nothing at all (research). + +Each session in `--json` carries its `intent` and the `intentEvidence` that +decided it. Prompts themselves are not in the report. Cursor logs no git +branch. ```sh node bin/ccreports.mjs adoption -s 20261001 -f html -o adoption.html diff --git a/skills/report/SKILL.md b/skills/report/SKILL.md index 87a859a..c7d9b01 100644 --- a/skills/report/SKILL.md +++ b/skills/report/SKILL.md @@ -31,6 +31,7 @@ the request: | what each tool, skill or subagent consumed | add `-b` (breakdown) to a period report | | 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 | +| what sessions were for (bug fixes, features, refactoring, research, ...) | `adoption` (its Session intent section) | | 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` | | the same for Cursor (CLI or editor agent; activity only, no tokens or cost) | any of the above with `--source cursor` | @@ -65,6 +66,9 @@ 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. +- Session intent (bug fix, new development, refactoring, ...) comes from rules + over commit messages, titles, branch names, the first prompt and the files + changed. It is a best guess per session; `--json` shows the evidence. With `--source copilot`, `cursor` or `all`, also keep in mind: diff --git a/src/adoption.mjs b/src/adoption.mjs index c99a32a..a4db436 100644 --- a/src/adoption.mjs +++ b/src/adoption.mjs @@ -4,6 +4,7 @@ import { aggregate } from './aggregate.mjs'; import { money, share, average } from './report.mjs'; +import { INTENTS, classifyIntent, fileKind } from './intent.mjs'; export const PHASES = [ { key: 'chat', title: 'Chat', description: 'Questions and exploration, no code changes' }, @@ -15,6 +16,7 @@ export const PHASES = [ // Tool calls per prompt you typed at which a session counts as agent-first. export const AUTONOMY_THRESHOLD = 10; const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']); +const samePath = (p) => String(p).replace(/\\/g, '/').toLowerCase(); const SURFACES = { cli: 'CLI', @@ -58,8 +60,18 @@ export function sessionStats(data, { since, until, project, timeZone, pricer } = const { buckets } = aggregate(data, { report: 'session', since, until, project, timeZone, pricer }); const inRange = new Set(buckets.map((b) => b.key)); const counts = new Map(); + const changed = new Map(); // sessionId -> { files: Set, newFiles: Set } for (const t of data.tools) { if (!inRange.has(t.sessionId)) continue; + if (t.editFiles || t.writeFile) { + const ch = changed.get(t.sessionId) ?? { files: new Set(), newFiles: new Set() }; + for (const f of t.editFiles ?? []) ch.files.add(samePath(f)); + if (t.writeFile) { + ch.files.add(samePath(t.writeFile)); + ch.newFiles.add(samePath(t.writeFile)); + } + changed.set(t.sessionId, ch); + } const c = counts.get(t.sessionId) ?? { edits: 0, backgroundAgents: 0, worktrees: 0, agentMessages: 0, mcpCalls: 0, webCalls: 0 }; // 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; @@ -70,6 +82,11 @@ export function sessionStats(data, { since, until, project, timeZone, pricer } = if (t.name === 'WebSearch' || t.name === 'WebFetch' || t.web) c.webCalls += 1; counts.set(t.sessionId, c); } + const commandsBySession = new Map(); + for (const c of data.commands ?? []) { + if (!inRange.has(c.sessionId)) continue; + commandsBySession.set(c.sessionId, [...(commandsBySession.get(c.sessionId) ?? []), c.name]); + } return buckets.map((b) => { const info = data.sessions.get(b.key); const s = { @@ -90,6 +107,21 @@ export function sessionStats(data, { since, until, project, timeZone, pricer } = }; s.toolCallsPerPrompt = s.toolCalls / Math.max(s.prompts, 1); s.phase = classify(s); + const ch = changed.get(b.key); + const files = { code: 0, tests: 0, docs: 0, ops: 0, plans: 0 }; + for (const f of ch?.files ?? []) files[fileKind(f)] += 1; + const { intent, evidence } = classifyIntent({ + title: data.titles?.get(b.key), + firstPrompt: info?.firstPrompt, + branches: [...(info?.branches ?? [])], + workMessages: [...(info?.workMessages?.values() ?? [])].flat(), + commands: commandsBySession.get(b.key) ?? [], + files, + newFiles: ch?.newFiles.size ?? 0, + edits: s.edits, + }); + s.intent = intent; + s.intentEvidence = evidence; return s; }); } @@ -225,10 +257,30 @@ export function buildAdoption(data, opts) { return { cells: [label, n, share(n, stats.length)] }; }); + // What sessions were for: one row per intent seen, the most common first, Other last. + const byIntent = INTENTS.map((i) => ({ ...i, list: stats.filter((s) => s.intent === i.key) })) + .filter((i) => i.list.length) + .sort((a, b) => (a.key === 'other') - (b.key === 'other') || b.list.length - a.list.length); + const intentRows = byIntent.map(({ title, description, list }) => ({ + cells: [ + title, + description, + list.length, + share(list.length, stats.length), + sum(list, (s) => s.prs), + average(sum(list, (s) => s.edits), list.length), + ...(opts.tokens !== false ? [Math.round(sum(list, (s) => s.totalTokens) / list.length)] : []), + ...(showCost ? [money(sum(list, (s) => s.costUSD) / list.length)] : []), + ], + })); + const summary = assess(stats, byPhase); + const named = byIntent.filter((i) => i.key !== 'other').slice(0, 3); + if (named.length) summary.push(`By intent: ${named.map((i) => `${i.title.toLowerCase()} ${pct(i.list.length / stats.length)}`).join(', ')}.`); + const range = opts.since || opts.until ? ` (${opts.since ?? '…'} → ${opts.until ?? 'today'})` : ''; return { title: `${opts.product ?? 'Claude Code'} adoption${range}`, - summary: assess(stats, byPhase), + summary, sections: [ { title: 'Adoption cohorts', note: `sessions by how they used ${opts.product ?? 'Claude Code'}`, cards: true, columns: cohortColumns, rows: cohortRows }, { @@ -248,6 +300,21 @@ export function buildAdoption(data, opts) { columns: [left('Surface'), right('Sessions'), right('Share of sessions'), right('PRs')], rows: surfaceRows, }, + { + title: 'Session intent', + note: 'what sessions were for, from commits, titles, branches, prompts and changed files', + columns: [ + left('Intent'), + left('What'), + right('Sessions'), + right('Share of sessions'), + right('PRs'), + right('Edits per session'), + ...(opts.tokens !== false ? [right('Tokens per session')] : []), + ...(showCost ? [right('Cost per session')] : []), + ], + rows: intentRows, + }, ], stats, }; diff --git a/src/copilot.mjs b/src/copilot.mjs index d99efa5..89f38f1 100644 --- a/src/copilot.mjs +++ b/src/copilot.mjs @@ -22,7 +22,8 @@ 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'; +import { errorLine, normalizeSkillName, patchFiles } from './loader.mjs'; +import { promptText, workMessages } from './intent.mjs'; const NANO_AIU_PER_USD = 1e11; const SHELLS = { powershell: 'PowerShell', bash: 'Bash' }; @@ -132,6 +133,9 @@ export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeS prs: new Set(), compactions: new Set(), modes: new Set(), // interactive, plan, autopilot + branches: new Set(), + firstPrompt: null, + workMessages: new Map(), // toolCallId -> commit messages / PR titles }; sessions.set(id, info); @@ -172,6 +176,7 @@ export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeS case 'session.start': case 'session.resume': project ??= data.context?.cwd ?? null; + if (data.context?.branch && data.context.branch !== 'HEAD') info.branches.add(data.context.branch); break; case 'session.mode_changed': @@ -244,6 +249,18 @@ export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeS if (SHELLS[raw] && typeof args.command === 'string') { const names = shellCommands(args.command, SHELLS[raw]); tool.shellCommands = SHELLS[raw] === 'PowerShell' ? names.map(psName) : names; + const messages = workMessages(args.command); + if (messages.length) info.workMessages.set(data.toolCallId ?? d.id, messages); + } + // Changed files, for the session intent. create/write make new files. + if (raw === 'create' || raw === 'write' || (raw === 'str_replace_editor' && args.command === 'create')) { + if (args.path) tool.writeFile = args.path; + } else if ((raw === 'edit' || raw === 'str_replace_editor') && args.command !== 'view') { + if (args.path) tool.editFiles = [args.path]; + } else if (raw === 'apply_patch') { + const { updated, added } = patchFiles(typeof args === 'string' ? args : (args.input ?? args.patch)); + if (updated.length) tool.editFiles = updated; + if (added.length) tool.writeFile = added[0]; } tools.set(data.toolCallId ?? d.id, tool); if (!d.agentId && createsPr(raw, data, args)) prCalls.add(data.toolCallId); @@ -288,6 +305,7 @@ export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeS const content = String(data.content ?? ''); attributionOf(null).human(); info.prompts.add(d.id ?? d.timestamp); + if (!info.firstPrompt) info.firstPrompt = promptText(content) || null; const m = /^\/([\w:.-]+)/.exec(content.trim()); pendingCommand = null; if (m) { diff --git a/src/cursor.mjs b/src/cursor.mjs index 23dbbca..644f2cb 100644 --- a/src/cursor.mjs +++ b/src/cursor.mjs @@ -24,10 +24,12 @@ import { createInterface } from 'node:readline'; import { homedir } from 'node:os'; import path from 'node:path'; import { shellCommands } from './shell.mjs'; -import { normalizeSkillName } from './loader.mjs'; +import { normalizeSkillName, patchFiles } from './loader.mjs'; +import { promptText, workMessages } from './intent.mjs'; const EDIT_TOOLS = new Set(['Write', 'Edit', 'StrReplace', 'MultiEdit', 'Delete', 'ApplyPatch', 'EditNotebook']); const WEB_TOOLS = new Set(['WebSearch', 'WebFetch']); +const FILE_EDIT_TOOLS = new Set(['Edit', 'StrReplace', 'MultiEdit', 'EditNotebook']); const AGENT_TOOLS = new Set(['Task', 'Agent']); // Cursor's Shell tool runs the platform's shell. const SHELL = process.platform === 'win32' ? 'PowerShell' : 'Bash'; @@ -186,6 +188,9 @@ export async function loadCursorRecords({ dirs = defaultCursorDirs(), includeSub prs: new Set(), compactions: new Set(), modes: new Set(), + branches: new Set(), // Cursor logs none + firstPrompt: null, + workMessages: new Map(), // tool call -> commit messages / PR titles }; sessions.set(id, info); @@ -211,6 +216,7 @@ export async function loadCursorRecords({ dirs = defaultCursorDirs(), includeSub turn += 1; timestamp = parsePromptTime(/([^<]+)<\/timestamp>/.exec(text)?.[1]) ?? timestamp; info.prompts.add(turn); + if (!info.firstPrompt) info.firstPrompt = promptText(query[1]) || null; events.push(base()); pendingCommand = null; const cmd = /^\/([\w:.-]+)/.exec(query[1]); @@ -244,6 +250,18 @@ export async function loadCursorRecords({ dirs = defaultCursorDirs(), includeSub if (name === 'Shell' && typeof input.command === 'string') { const names = shellCommands(input.command, SHELL); tool.shellCommands = SHELL === 'PowerShell' ? names.map(psName) : names; + const messages = workMessages(input.command); + if (messages.length) info.workMessages.set(c.id ?? `${turn}:${tools.length}`, messages); + } + // Changed files, for the session intent. + if (name === 'Write' && (input.path ?? input.file_path)) tool.writeFile = input.path ?? input.file_path; + if (FILE_EDIT_TOOLS.has(name) && (input.path ?? input.file_path ?? input.target_notebook)) { + tool.editFiles = [input.path ?? input.file_path ?? input.target_notebook]; + } + if (name === 'ApplyPatch') { + const { updated, added } = patchFiles(Object.values(input).filter((v) => typeof v === 'string').join('\n')); + if (updated.length) tool.editFiles = updated; + if (added.length) tool.writeFile = added[0]; } if (name === 'SwitchMode' && input.target_mode_id) info.modes.add(input.target_mode_id); if (name === 'CreatePlan') info.modes.add('plan'); diff --git a/src/intent.mjs b/src/intent.mjs new file mode 100644 index 0000000..b213779 --- /dev/null +++ b/src/intent.mjs @@ -0,0 +1,134 @@ +// Session intent: what a session was for (bug fix, new development, +// refactoring, ...), from rules over what the logs say about it. Signals, from +// strong to weak: conventional commit and PR titles the session wrote, review +// commands, the session title, the git branch, the first prompt, and what the +// session did (which files it changed, or that it changed none). + +export const INTENTS = [ + { key: 'bugfix', title: 'Bug fix', description: 'Fixing something that is broken' }, + { key: 'feature', title: 'New development', description: 'Adding features, pages, apps' }, + { key: 'refactor', title: 'Refactoring', description: 'Restructuring, renaming, upgrading' }, + { key: 'tests', title: 'Tests', description: 'Writing or fixing tests' }, + { key: 'planning', title: 'Planning & design', description: 'Plans, specs, architecture' }, + { key: 'docs', title: 'Docs & content', description: 'READMEs, docs, articles, course material' }, + { key: 'ops', title: 'Ops & config', description: 'CI, deploys, settings, dependencies' }, + { key: 'review', title: 'Review', description: 'Reviewing code or a PR' }, + { key: 'research', title: 'Research & analysis', description: 'Questions, explanations, investigations' }, + { key: 'other', title: 'Other', description: 'No clear signal' }, +]; +// On a tie the earlier intent wins. +const ORDER = INTENTS.map((i) => i.key); + +// Words in a title, prompt or commit message. English, plus a few Dutch. +const KEYWORDS = { + bugfix: + /\b(bugs?|bugfix|fix(es|ed|ing)?|hotfix|errors?|exceptions?|crash(es|ed|ing)?|broken|breaks|fails?|failing|failed|failure|not working|(does ?n[o']t|did ?n[o']t|is ?n[o']t|wo ?n[o']t) (work|show|load|run|start|give|return)|no output|wrong|incorrect|regression|stack ?trace|debug(ging)?|repro|fout(en|melding)?|werkt niet|kapot)\b/i, + feature: + /\b(add(s|ed|ing)?|implement(s|ed|ing)?|build|new (feature|page|app|application|endpoint|command|option|screen|tool|report)|i want (an?|to have)|support for|introduce|scaffold|make me|features?|improv(e|es|ed|ing|ements?)|enhanc(e|es|ed|ing|ements?)|poc|prototype|toevoegen|bouw)\b/i, + refactor: + /\b(refactor(s|ed|ing)?|renam(e|es|ed|ing)|clean(ing)? ?up|simplif(y|ies|ied|ication)|restructur(e|ing)|extract|reorgani[sz](e|ing)|migrat(e|es|ed|ing|ion)|upgrad(e|es|ed|ing)|moderni[sz]e|dedup(licate)?|split (up|into)|consolidat(e|ing)|opschonen|herschrijf)\b/i, + tests: /\b(unit[- ]?tests?|tests?|testing|test (case|suite)s?|coverage|e2e|playwright|jest|vitest|xunit|nunit|pytest)\b/i, + planning: /\b(plan(s|ning)?(?! mode)|specs?|specification|design( doc)?|architecture|proposal|roadmap|rfc|adr|requirements|feasibility|ideas)\b/i, + docs: /\b(readme|docs|documentation|document(ed|ing)?|changelog|blog|article|course|module|slides?|presentation|tutorial|guide|write[- ]?up|explainer)\b/i, + ops: /\b(deploy(s|ed|ing|ment)?|pipelines?|ci|cd|github actions|workflows?|docker(file)?|kubernetes|k8s|helm|terraform|bicep|infra(structure)?|config(ure|uration)?|settings|install(ation)?|dependenc(y|ies)|packages?|publish(ing)?|release|version bump|permissions?|hooks?)\b/i, + review: /\b(review(ing)?|code review|pull request #?\d+|pr #?\d+|feedback on)\b/i, + research: + /\b(explain|what (is|are|does|do|could)|why|how (does|do|is|can|could|would)|analy[sz](e|is|ing)|investigat(e|ion)|research|compar(e|ing|ison)|evaluat(e|ion)|verif(y|ication)|validat(e|ion)|breakdown|overview|look (at|into)|find (out|anything)|understand|due diligence|options|pros and cons|which|is (it|there)|can you find|vs\.?)\b/i, +}; + +// Conventional commit types, and git branch prefixes. +const COMMIT_TYPES = { fix: 'bugfix', hotfix: 'bugfix', feat: 'feature', feature: 'feature', refactor: 'refactor', perf: 'refactor', style: 'refactor', test: 'tests', tests: 'tests', docs: 'docs', doc: 'docs', chore: 'ops', ci: 'ops', build: 'ops', deps: 'ops' }; +const BRANCH_TYPES = { ...COMMIT_TYPES, bugfix: 'bugfix', bug: 'bugfix', features: 'feature', refactoring: 'refactor', infra: 'ops', ops: 'ops', release: 'ops' }; +const REVIEW_COMMANDS = /^\/(code-review|review|security-review|pr-review|ultrareview)\b/; + +/** The first line of the commit messages and PR titles in one shell command. */ +export function workMessages(command) { + const out = []; + const text = String(command ?? ''); + const re = /\b(?:git\s+commit\b[^\n]*?\s(?:-m|--message)|gh\s+pr\s+create\b[^\n]*?\s(?:-t|--title))[\s=]*(?:"((?:[^"\\]|\\.)*)"|'([^']*)'|@['"]\r?\n([^\r\n]*))/g; + for (const m of text.matchAll(re)) { + const body = (m[1] ?? m[2] ?? m[3] ?? '').replace(/^\$\(cat\s*<<-?\s*'?\w+'?\s*/, ''); + const line = body.split(/\r?\n|\\n/).map((l) => l.trim()).find(Boolean); + if (line) out.push(line.slice(0, 200)); + } + return out; +} + +/** What a prompt says, without the tags Claude Code wraps around commands and attachments. */ +export function promptText(text) { + const args = /([\s\S]*?)<\/command-args>/.exec(text)?.[1]; + const name = /([^<]*)<\/command-name>/.exec(text)?.[1]; + const plain = name ? `${name} ${args ?? ''}` : String(text ?? '').replace(/<[^>]+>[\s\S]*?<\/[^>]+>/g, ' '); + return plain.replace(/\s+/g, ' ').trim().slice(0, 500); +} + +/** A changed file's kind: plans (plan / spec documents), docs, tests, ops (CI, containers, settings, manifests) or code. */ +export function fileKind(file) { + const p = String(file).replace(/\\/g, '/').toLowerCase(); + const name = p.slice(p.lastIndexOf('/') + 1); + if (/\.(md|mdx|markdown|rst|adoc|txt)$/.test(name)) { + const plan = /(^|\/)(specs?|plans?|rfcs?|adrs?|designs?)\//.test(p) || /^(plan|spec|rfc|adr|design)[-_.]/.test(name); + return plan ? 'plans' : 'docs'; + } + if (/(^|\/)(tests?|__tests__|testing)\//.test(p) || /[._-](test|tests|spec)\.[a-z]+$/.test(name) || /^test_/.test(name)) return 'tests'; + if ( + /(^|\/)\.(github|gitlab|azure|circleci|devcontainer|claude|vscode)\//.test(p) || + /\.(ya?ml|tf|tfvars|bicep|toml|ini|env|config|props|targets)$/.test(name) || + /^(dockerfile|docker-compose.*|makefile|package(-lock)?\.json|pnpm-lock\.yaml|.*\.csproj|.*\.sln|nuget\.config|settings(\.local)?\.json|tsconfig.*\.json|\.gitignore|\.gitattributes|\.npmrc|requirements.*\.txt|pyproject\.toml|go\.mod|cargo\.toml)$/.test(name) + ) { + return 'ops'; + } + return 'code'; +} + +const WEIGHTS = { commit: 4, command: 4, title: 3, branch: 2, prompt: 2, activity: 3 }; + +/** + * Places one session in an intent. `s` holds: title, firstPrompt, branches[], + * workMessages[] (commits / PR titles), commands[] (slash commands), files + * { code, tests, docs, ops, plans } (changed files per kind), newFiles, edits. + * Returns { intent, evidence } - evidence names the signals that decided it. + */ +export function classifyIntent(s) { + const score = Object.fromEntries(ORDER.map((k) => [k, 0])); + const why = Object.fromEntries(ORDER.map((k) => [k, new Set()])); + const add = (key, weight, source) => { + score[key] += weight; + why[key].add(source); + }; + const words = (text, weight, source) => { + if (!text) return; + for (const [key, re] of Object.entries(KEYWORDS)) if (re.test(text)) add(key, weight, source); + }; + + for (const msg of s.workMessages ?? []) { + const type = /^(\w+)(\([^)]*\))?!?:/.exec(msg)?.[1]?.toLowerCase(); + if (COMMIT_TYPES[type]) add(COMMIT_TYPES[type], WEIGHTS.commit, 'commit'); + else words(msg, 1, 'commit'); + } + if ((s.commands ?? []).some((c) => REVIEW_COMMANDS.test(c))) add('review', WEIGHTS.command, 'command'); + words(s.title, WEIGHTS.title, 'title'); + for (const branch of s.branches ?? []) { + const prefix = /^([\w-]+)\//.exec(branch)?.[1]?.toLowerCase(); + if (BRANCH_TYPES[prefix]) add(BRANCH_TYPES[prefix], WEIGHTS.branch, 'branch'); + } + words(s.firstPrompt, WEIGHTS.prompt, 'prompt'); + + const f = { code: 0, tests: 0, docs: 0, ops: 0, plans: 0, ...s.files }; + const changed = f.code + f.tests + f.docs + f.ops + f.plans; + if (!changed && !(s.edits > 0) && !(s.workMessages ?? []).length) { + add('research', WEIGHTS.activity, 'activity'); // read and answered, changed nothing + } else if (changed) { + // Research that ends in code changes was work on that code. + score.research /= 2; + if (f.plans === changed) add('planning', WEIGHTS.activity, 'activity'); + else if (f.docs === changed) add('docs', WEIGHTS.activity, 'activity'); + else if (f.tests === changed) add('tests', WEIGHTS.activity, 'activity'); + else if (f.ops === changed) add('ops', WEIGHTS.activity, 'activity'); + else if (s.newFiles >= 2 && s.newFiles >= changed / 2) add('feature', 1, 'activity'); + } + + const best = ORDER.reduce((a, k) => (score[k] > score[a] ? k : a), ORDER[0]); + if (score[best] <= 0) return { intent: 'other', evidence: [] }; + return { intent: best, evidence: [...why[best]] }; +} diff --git a/src/loader.mjs b/src/loader.mjs index a287188..ea6bdfb 100644 --- a/src/loader.mjs +++ b/src/loader.mjs @@ -12,11 +12,24 @@ import { homedir } from 'node:os'; import path from 'node:path'; import { FileAttribution, createCalibration, charsPerToken, resolveTokens } from './attribution.mjs'; import { SHELL_TOOLS, shellCommands } from './shell.mjs'; +import { promptText, workMessages } from './intent.mjs'; const SKILL_CONTENT_PREFIX = 'Base directory for this skill'; const COMMAND_RE = /([^<]+)<\/command-name>/; // "Task" is the tool's name in older Claude Code versions. const AGENT_TOOLS = new Set(['Agent', 'Task']); +// Tools that change part of an existing file (Write creates or replaces one). +const FILE_EDIT_TOOLS = new Set(['Edit', 'MultiEdit', 'NotebookEdit']); +const INTERRUPT_PREFIX = '[Request interrupted by user'; + +/** The files an apply_patch-style patch changes and adds ("*** Update File: ", "*** Add File: "). */ +export function patchFiles(patch) { + const files = { updated: [], added: [] }; + for (const m of String(patch ?? '').matchAll(/^\*\*\* (Update|Add) File: (.+?)\s*$/gm)) { + files[m[1] === 'Add' ? 'added' : 'updated'].push(m[2]); + } + return files; +} async function readAgentType(transcript) { try { @@ -99,10 +112,21 @@ export async function loadRecords({ dirs = defaultProjectDirs(), includeSubagent const commands = new Map(); // user-message uuid -> record const hooks = new Map(); // attachment uuid -> record const titles = new Map(); // sessionId -> ai title - // sessionId -> { entrypoint, prompts: Set, prs: Set, compactions: Set } (adoption / recommendations) + // sessionId -> { entrypoint, prompts: Set, prs: Set, compactions: Set, + // branches: Set, firstPrompt, workMessages: Map } (adoption / recommendations) const sessions = new Map(); const sessionInfo = (id) => { - if (!sessions.has(id)) sessions.set(id, { entrypoint: null, prompts: new Set(), prs: new Set(), compactions: new Set() }); + if (!sessions.has(id)) { + sessions.set(id, { + entrypoint: null, + prompts: new Set(), + prs: new Set(), + compactions: new Set(), + branches: new Set(), + firstPrompt: null, + workMessages: new Map(), + }); + } return sessions.get(id); }; const sessionStart = new Map(); // sessionId -> { rank, timestamp, cwd } of its earliest record @@ -170,6 +194,7 @@ export async function loadRecords({ dirs = defaultProjectDirs(), includeSubagent agent, }; if (!base.timestamp) continue; + if (!agent && d.gitBranch && d.gitBranch !== 'HEAD') sessionInfo(base.sessionId).branches.add(d.gitBranch); // A session's project is where it started: later records follow Claude into // subfolders (and subagents into worktrees), which would split one session // over several projects. @@ -253,7 +278,13 @@ export async function loadRecords({ dirs = defaultProjectDirs(), includeSubagent if (SHELL_TOOLS.has(c.name) && typeof c.input?.command === 'string') { const names = shellCommands(c.input.command, c.name); tool.shellCommands = c.name === 'PowerShell' ? names.map(psName) : names; + const messages = workMessages(c.input.command); + if (messages.length) sessionInfo(base.sessionId).workMessages.set(id, messages); } + // Changed files, for the session intent. + const edited = FILE_EDIT_TOOLS.has(c.name) && (c.input?.file_path ?? c.input?.notebook_path); + if (edited) tool.editFiles = [edited]; + if (c.name === 'Write' && c.input?.file_path) tool.writeFile = c.input.file_path; tools.set(id, tool); attribution.toolUse(key, id, JSON.stringify(c.input ?? {}).length, c.name === 'Skill'); if (c.name === 'Skill' && c.input?.skill) { @@ -287,7 +318,9 @@ export async function loadRecords({ dirs = defaultProjectDirs(), includeSubagent // Prompts a person sent - not agent-to-agent or task notifications, not subagent tasks. const origin = d.origin?.kind ?? 'human'; if (!agent && !d.isSidechain && origin === 'human' && d.promptSource !== 'system') { - sessionInfo(base.sessionId).prompts.add(d.uuid ?? `${file}:${base.timestamp}`); + const info = sessionInfo(base.sessionId); + info.prompts.add(d.uuid ?? `${file}:${base.timestamp}`); + if (!info.firstPrompt && !text.startsWith(INTERRUPT_PREFIX)) info.firstPrompt = promptText(text) || null; } } if (!agent && d.entrypoint) sessionInfo(base.sessionId).entrypoint ??= d.entrypoint; diff --git a/test/adoption.test.mjs b/test/adoption.test.mjs index 5166244..2f31469 100644 --- a/test/adoption.test.mjs +++ b/test/adoption.test.mjs @@ -85,6 +85,22 @@ test('buildAdoption: cohorts, weekly mix, capabilities, surfaces and summary', ( assert.ok(doc.summary.some((l) => l.includes('Not used in this period') && l.includes('worktrees'))); }); +test('buildAdoption: session intent per session and as a section', () => { + const data = fixture(); + data.sessions.get('assist').branches = new Set(['fix/login']); + data.sessions.get('agent').workMessages = new Map([['t', ['feat: new page']]]); + data.sessions.get('multi').firstPrompt = 'rename the services'; + const doc = buildAdoption(data, { timeZone: 'UTC', showCost: false }); + assert.deepEqual( + Object.fromEntries(doc.stats.map((s) => [s.id, s.intent])), + { chat: 'research', assist: 'bugfix', agent: 'feature', multi: 'refactor' }, + ); + assert.deepEqual(doc.stats.find((s) => s.id === 'agent').intentEvidence, ['commit']); + const section = doc.sections.find((s) => s.title === 'Session intent'); + assert.deepEqual(section.rows.map((r) => r.cells[0]), ['Bug fix', 'New development', 'Refactoring', 'Research & analysis']); + assert.ok(doc.summary.some((l) => l.startsWith('By intent: bug fix 25%'))); +}); + test('adoption renders as cards in HTML and as tables in Markdown', () => { const doc = buildAdoption(fixture(), { timeZone: 'UTC', showCost: false }); const html = toHtml(doc); diff --git a/test/ccreports.test.mjs b/test/ccreports.test.mjs index 2651be8..9ec1324 100644 --- a/test/ccreports.test.mjs +++ b/test/ccreports.test.mjs @@ -88,6 +88,34 @@ test('loads and deduplicates records', async () => { } }); +test('records the signals for session intent: branch, first prompt, commits, changed files', async () => { + const root = await mkdtemp(path.join(tmpdir(), 'ccreports-')); + try { + const proj = path.join(root, '-work-app'); + await mkdir(proj, { recursive: true }); + const lines = [ + { ...user('2026-10-01T10:00:00Z', 'u1', 'the login button does not work'), gitBranch: 'fix/login' }, + { ...user('2026-10-01T10:00:01Z', 'u2', 'and the logout one'), gitBranch: 'HEAD' }, + assistant('2026-10-01T10:00:05Z', 'm1', 'r1', [ + { type: 'tool_use', id: 't1', name: 'Edit', input: { file_path: '/work/app/a.js' } }, + { type: 'tool_use', id: 't2', name: 'Write', input: { file_path: '/work/app/b.js', content: '' } }, + { type: 'tool_use', id: 't3', name: 'Bash', input: { command: 'git commit -m "fix: login button"' } }, + ]), + ]; + await writeFile(path.join(proj, 's1.jsonl'), lines.map((l) => JSON.stringify(l)).join('\n') + '\n'); + const data = await loadRecords({ dirs: [root] }); + const info = data.sessions.get('s1'); + assert.deepEqual([...info.branches], ['fix/login']); + assert.equal(info.firstPrompt, 'the login button does not work'); + assert.deepEqual([...info.workMessages.values()], [['fix: login button']]); + const byName = Object.fromEntries(data.tools.map((t) => [t.name, t])); + assert.deepEqual(byName.Edit.editFiles, ['/work/app/a.js']); + assert.equal(byName.Write.writeFile, '/work/app/b.js'); + } finally { + await rm(root, { recursive: true, force: true }); + } +}); + test('a session keeps the project it started in', async () => { const root = await mkdtemp(path.join(tmpdir(), 'ccreports-')); try { diff --git a/test/intent.test.mjs b/test/intent.test.mjs new file mode 100644 index 0000000..ccc27fb --- /dev/null +++ b/test/intent.test.mjs @@ -0,0 +1,68 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { classifyIntent, fileKind, promptText, workMessages } from '../src/intent.mjs'; +import { patchFiles } from '../src/loader.mjs'; + +const intent = (s) => classifyIntent({ files: {}, newFiles: 0, edits: 1, ...s }).intent; + +test('workMessages reads commit messages and PR titles in any quoting', () => { + assert.deepEqual(workMessages('git add . && git commit -m "fix: keep the account" && git push'), ['fix: keep the account']); + assert.deepEqual(workMessages("git commit -q -m 'feat(ui): fullscreen view'"), ['feat(ui): fullscreen view']); + assert.deepEqual(workMessages(`git commit -m "$(cat <<'EOF'\nrefactor: split loader\n\nBody\nEOF\n)"`), ['refactor: split loader']); + assert.deepEqual(workMessages("git commit -q -m @'\nAdd working habits\n\nBody\n'@"), ['Add working habits']); + assert.deepEqual(workMessages('gh pr create --title "docs: README" --body "x"'), ['docs: README']); + assert.deepEqual(workMessages('git status; git log --oneline'), []); +}); + +test('promptText drops the tags around commands and attachments', () => { + assert.equal(promptText('/fix-bug\nlogin fails'), '/fix-bug login fails'); + assert.equal(promptText('ignore why is it slow?'), 'why is it slow?'); +}); + +test('fileKind tells plans, docs, tests, ops and code apart', () => { + assert.equal(fileKind('Z:\\repo\\.agentic\\specs\\plan-caching.md'), 'plans'); + assert.equal(fileKind('docs/plan-x.md'), 'plans'); + assert.equal(fileKind('README.md'), 'docs'); + assert.equal(fileKind('test/adoption.test.mjs'), 'tests'); + assert.equal(fileKind('src/app.spec.ts'), 'tests'); + assert.equal(fileKind('.github/workflows/ci.yml'), 'ops'); + assert.equal(fileKind('src/Api/Api.csproj'), 'ops'); + assert.equal(fileKind('src/loader.mjs'), 'code'); +}); + +test('patchFiles splits updated and added files', () => { + const patch = '*** Begin Patch\n*** Update File: C:\\src\\a.cs\r\n@@\n*** Add File: b.cs\n+z\n*** Update File: src/c.ts\n*** End Patch'; + assert.deepEqual(patchFiles(patch), { updated: ['C:\\src\\a.cs', 'src/c.ts'], added: ['b.cs'] }); + assert.deepEqual(patchFiles(undefined), { updated: [], added: [] }); +}); + +test('classifyIntent: commits outrank branches, titles and prompts', () => { + assert.equal(intent({ workMessages: ['fix: null check'], branches: ['feature/login'] }), 'bugfix'); + assert.equal(intent({ workMessages: ['refactor(loader): split'], title: 'Add a page' }), 'refactor'); + assert.equal(intent({ branches: ['feature/login'], firstPrompt: 'go on' }), 'feature'); + assert.equal(intent({ branches: ['main'], title: 'Login button does not work' }), 'bugfix'); + assert.equal(intent({ title: 'Rename the services and clean up' }), 'refactor'); + assert.equal(intent({ commands: ['/code-review'] }), 'review'); + assert.equal(intent({ title: 'Adoption cohorts plan mode', firstPrompt: 'add plan mode to the report' }), 'feature'); +}); + +test('classifyIntent: what the session changed', () => { + // Read and answered, nothing changed. + assert.equal(classifyIntent({ firstPrompt: 'ls', edits: 0 }).intent, 'research'); + assert.equal(intent({ firstPrompt: 'why is there a single database?', edits: 0 }), 'research'); + // Research words, but code changed: the work wins. + assert.equal(intent({ firstPrompt: 'look at the login, the button is broken', files: { code: 2 } }), 'bugfix'); + assert.equal(intent({ firstPrompt: 'go on', files: { plans: 2 } }), 'planning'); + assert.equal(intent({ firstPrompt: 'go on', files: { docs: 1 } }), 'docs'); + assert.equal(intent({ firstPrompt: 'go on', files: { tests: 3 } }), 'tests'); + assert.equal(intent({ firstPrompt: 'go on', files: { ops: 1 } }), 'ops'); + assert.equal(intent({ firstPrompt: 'go on', files: { code: 3 }, newFiles: 3 }), 'feature'); + const other = classifyIntent({ firstPrompt: 'go on', files: { code: 3 }, newFiles: 0, edits: 3 }); + assert.deepEqual(other, { intent: 'other', evidence: [] }); +}); + +test('classifyIntent names the signals that decided', () => { + const { intent: i, evidence } = classifyIntent({ workMessages: ['feat: x'], branches: ['feature/x'], files: { code: 3 }, newFiles: 3, edits: 3 }); + assert.equal(i, 'feature'); + assert.deepEqual(evidence, ['commit', 'branch', 'activity']); +}); From 38a22194d5e2af5684855bc1faf0f9b0ef700b31 Mon Sep 17 00:00:00 2001 From: Peter Bons Date: Wed, 4 Nov 2026 10:26:15 +0100 Subject: [PATCH 2/3] Let Claude classify session intent from the skill A new `intents` report lists each session's intent and evidence; in JSON it also carries the signals (title, first prompt, branches, commit messages, changed files per kind, the rules' guess). `--intents ` applies intents assigned elsewhere to any report, replacing the rules' guess with evidence "claude". The skill exports the signals, classifies the sessions itself and reruns the report with --intents. Bare slash commands (/clear) no longer count as the first prompt, and "create a tool / app / page" counts as new development. Co-Authored-By: Claude Opus 5.5 --- README.md | 17 +++++++++ bin/ccreports.mjs | 46 +++++++++++++++++++++-- skills/report/SKILL.md | 46 +++++++++++++++++++++-- src/adoption.mjs | 84 +++++++++++++++++++++++++++++++++++++----- src/aggregate.mjs | 2 +- src/intent.mjs | 10 +++-- test/adoption.test.mjs | 29 ++++++++++++++- test/intent.test.mjs | 3 ++ 8 files changed, 216 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c9628c7..27e8870 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,22 @@ Each session in `--json` carries its `intent` and the `intentEvidence` that decided it. Prompts themselves are not in the report. Cursor logs no git branch. +`ccreports intents` lists every session with its intent and evidence. With +`-j` it also prints the signals (title, first prompt, branches, commit +messages, changed files per kind), so that a model can classify the +sessions; `--intents ` then applies its answer to any report, +replacing the rules' guess: + +```sh +node bin/ccreports.mjs intents -j -o signals.json # signals per session +# ... classify, writing {"": "bugfix", ...} to intents.json +node bin/ccreports.mjs adoption --intents intents.json # evidence: claude +``` + +The `/ccreports:report` skill does this itself when you ask what your +sessions were for: Claude reads the signals, classifies each session, and +runs the report with `--intents`. + ```sh node bin/ccreports.mjs adoption -s 20261001 -f html -o adoption.html node bin/ccreports.mjs -s 20261001 --adoption -f html -o report.html # summary + adoption @@ -212,6 +228,7 @@ byte order mark so Excel shows non-ASCII characters correctly. | `-x, --shell` | Programs run by Bash / PowerShell calls, grouped by purpose: a table per shell in the summary, `[bash]` / `[powershell]` sub-rows in period reports | | `-a, --adoption` | Append the adoption assessment to the report | | `-r, --recommendations` | Append best-practice recommendations to the report | +| `--intents ` | Session intents assigned elsewhere (`{"": ""}`), replacing the rules' guess | | `-n, --top ` | Rows per ranked list (`0` = all) | | `-f, --format ` | `table` (default), `json`, `csv`, `markdown` / `md`, `html` | | `-j, --json` | Same as `--format json` | diff --git a/bin/ccreports.mjs b/bin/ccreports.mjs index 3a94e95..ee044d0 100644 --- a/bin/ccreports.mjs +++ b/bin/ccreports.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { writeFile, mkdtemp } from 'node:fs/promises'; +import { writeFile, mkdtemp, readFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { parseArgs } from 'node:util'; @@ -10,7 +10,8 @@ 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'; import { loadPricingTable, createPricer } from '../src/pricing.mjs'; -import { buildAdoption, PHASES, AUTONOMY_THRESHOLD } from '../src/adoption.mjs'; +import { buildAdoption, buildIntents, parseIntents, PHASES, AUTONOMY_THRESHOLD } from '../src/adoption.mjs'; +import { INTENTS } from '../src/intent.mjs'; import { buildRecommendations } from '../src/recommendations.mjs'; import { openFile, FORMAT_EXTENSIONS } from '../src/open.mjs'; import { loadPlugins, pluginRows, pluginsJSON } from '../src/plugins.mjs'; @@ -29,6 +30,9 @@ Reports: session One row per session project One row per project (working directory) adoption Adoption assessment: sessions by phase (chat, assisted, agent-first, multi-agent) + and by intent (bug fix, new development, refactoring, research, ...) + intents Each session's intent and the evidence for it; in JSON also the signals + (title, first prompt, branch, commits, changed files) to classify from recommendations Best-practice recommendations based on your usage, with the cost at stake Options: @@ -41,6 +45,8 @@ Options: -x, --shell Programs run by Bash / PowerShell calls (summary tables, sub-rows in period reports) -a, --adoption Append the adoption assessment to the report -r, --recommendations Append best-practice recommendations to the report + --intents Session intents assigned elsewhere (JSON: {"": ""}), + replacing the rules' guess, e.g. classified by Claude in the skill -n, --top Rows per ranked list (default 15 summary, 5 breakdown; 0 = all) -f, --format table (default), json, csv, markdown (md) or html -j, --json Same as --format json @@ -78,6 +84,7 @@ try { shell: { type: 'boolean', short: 'x' }, adoption: { type: 'boolean', short: 'a' }, recommendations: { type: 'boolean', short: 'r' }, + intents: { type: 'string' }, top: { type: 'string', short: 'n' }, format: { type: 'string', short: 'f' }, json: { type: 'boolean', short: 'j' }, @@ -146,6 +153,23 @@ if (opts.timezone) { } } +let intents; +if (opts.intents) { + let json; + try { + json = JSON.parse((await readFile(opts.intents, 'utf8')).replace(/^/, '')); + } catch (err) { + fail(`cannot read --intents ${opts.intents}: ${err.message}`); + } + const parsedIntents = parseIntents(json); + intents = parsedIntents.intents; + if (parsedIntents.unknown.length) { + console.error( + `ccreports: ignored unknown intents in ${opts.intents}: ${[...new Set(parsedIntents.unknown)].join(', ')} (expected ${INTENTS.map((i) => i.key).join(', ')})`, + ); + } +} + const toTTY = !opts.output && !opts.open && process.stdout.isTTY; const includeSubagents = !opts['no-subagents']; @@ -213,6 +237,7 @@ const docOpts = { pricer, plugins, product, + intents, // No token usage at all (Cursor alone): reports leave out the token columns. tokens: data.usage.length > 0, }; @@ -220,6 +245,7 @@ const docOpts = { // 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 intentDoc = report === 'intents' ? buildIntents(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; @@ -254,6 +280,20 @@ if (format === 'json') { let json; if (report === 'adoption') { json = { ...meta, ...adoptionJson }; + } else if (report === 'intents') { + json = { + ...meta, + intents: INTENTS, + sessions: intentDoc.stats.map((s) => ({ + id: s.id, + title: s.title, + project: s.project, + firstActivity: s.firstActivity, + intent: s.intent, + evidence: s.intentEvidence, + signals: s.intentSignals, + })), + }; } else if (report === 'recommendations') { json = { ...meta, recommendations: advice.items }; } else if (report === 'summary') { @@ -267,7 +307,7 @@ if (format === 'json') { } else if (result.totals.sessions.size === 0) { fail('no usage found for the selected filters.'); } else { - const own = { adoption, recommendations: advice }[report]; + const own = { adoption, intents: intentDoc, recommendations: advice }[report]; let doc = own ?? (report === 'summary' ? buildSummary(result, docOpts) : buildPeriodReport(report, result, docOpts)); // Appended parts: their summary lines on top, their sections after the report's own. for (const part of [adoption, advice]) { diff --git a/skills/report/SKILL.md b/skills/report/SKILL.md index c7d9b01..5223c7d 100644 --- a/skills/report/SKILL.md +++ b/skills/report/SKILL.md @@ -1,7 +1,7 @@ --- name: report -description: Report the user's own Claude Code usage from their local session logs (~/.claude/projects), their GitHub Copilot CLI / VS Code agent usage (~/.copilot/session-state), and their Cursor CLI / editor agent activity (~/.cursor/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, Copilot or Cursor more effectively or cheaply, how their usage of these tools compares, 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]" +description: Report the user's own Claude Code usage from their local session logs (~/.claude/projects), their GitHub Copilot CLI / VS Code agent usage (~/.copilot/session-state), and their Cursor CLI / editor agent activity (~/.cursor/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), what each session was for (bug fix, new development, refactoring, research, ...) 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, what they spend their sessions on, how to use Claude Code, Copilot or Cursor more effectively or cheaply, how their usage of these tools compares, or wants such a report as a table, Markdown, CSV, JSON or HTML page. +argument-hint: "[summary|daily|weekly|monthly|session|project|adoption|intents|recommendations] [options]" --- # ccreports @@ -31,7 +31,7 @@ the request: | what each tool, skill or subagent consumed | add `-b` (breakdown) to a period report | | 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 | -| what sessions were for (bug fixes, features, refactoring, research, ...) | `adoption` (its Session intent section) | +| what sessions were for (bug fixes, features, refactoring, research, ...) | `adoption` (its Session intent section), or `intents` per session; classify them yourself, see [Classifying session intent](#classifying-session-intent) | | 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` | | the same for Cursor (CLI or editor agent; activity only, no tokens or cost) | any of the above with `--source cursor` | @@ -54,6 +54,43 @@ Useful options: `-s/--since` and `-u/--until` (`YYYYMMDD`), `-p/--project not open files unless `--open` is passed. - If Node.js is missing or older than 20, say so; don't install it for them. +## Classifying session intent + +ccreports guesses each session's intent with rules. When the user asks what +their sessions were for, or asks for intent to be classified by Claude, classify +the sessions yourself instead; it is more accurate than the rules. For an +adoption report where intent is not the question, the rules are enough. + +1. Export the signals, with the same `--source`, `-s`, `-u` and `-p` options as + the report, to a temporary file (your scratchpad directory if you have one): + + ```sh + node "/../../bin/ccreports.mjs" intents -j --no-open -o "/ccreports-intent-signals.json" [options] + ``` + + With more than about 200 sessions, narrow the range with `--since` or ask + the user which period to classify. +2. Read the file. `intents` lists the keys to choose from. Each session has a + `title` and `signals`: `firstPrompt`, `branches`, `workMessages` (commit + messages and PR titles it wrote), `commands`, `files` (changed files per + kind: code, tests, docs, ops, plans), `newFiles`, `edits`, and the rules' + guess (`ruleIntent`, `ruleEvidence`). Pick one key per session for its main + purpose: + - Commits and PR titles are the strongest evidence, then the title and the + first prompt, then the branch (a long-lived `feature/` branch also hosts + fixes). + - A session that changed nothing is research, even if it talks about a bug. + - Keep `ruleIntent` when the signals don't point elsewhere; use `other` only + when nothing hints at a purpose. +3. Write `{ "": "", ... }` to `/ccreports-intents.json`. +4. Run the report the user asked for with `--intents "/ccreports-intents.json"`, + e.g. `adoption --intents …` or `intents --intents …` (not `-j`, which would + print the prompts again). The section notes how many sessions you classified; + their evidence reads `claude`. + +The signals hold the user's own prompts from their local logs. Use them only to +classify; don't quote them in the report or the answer unless asked. + ## Explaining the results Lead with what stands out (biggest cost driver, trend, phase), not a restatement @@ -68,7 +105,8 @@ of every table. Keep these caveats in mind and mention them when relevant: Claude Code created. - Session intent (bug fix, new development, refactoring, ...) comes from rules over commit messages, titles, branch names, the first prompt and the files - changed. It is a best guess per session; `--json` shows the evidence. + changed, unless you classified it. Either way it is a best guess per session; + `intents` shows the evidence. With `--source copilot`, `cursor` or `all`, also keep in mind: diff --git a/src/adoption.mjs b/src/adoption.mjs index a4db436..27e9f53 100644 --- a/src/adoption.mjs +++ b/src/adoption.mjs @@ -3,7 +3,7 @@ // compared on PRs, tokens and cost. Built as a report document (src/report.mjs). import { aggregate } from './aggregate.mjs'; -import { money, share, average } from './report.mjs'; +import { money, share, average, sessionName } from './report.mjs'; import { INTENTS, classifyIntent, fileKind } from './intent.mjs'; export const PHASES = [ @@ -56,7 +56,7 @@ const FEATURES = [ ]; /** Per-session stats for the sessions active in the selected range. */ -export function sessionStats(data, { since, until, project, timeZone, pricer } = {}) { +export function sessionStats(data, { since, until, project, timeZone, pricer, intents, withSignals = false } = {}) { const { buckets } = aggregate(data, { report: 'session', since, until, project, timeZone, pricer }); const inRange = new Set(buckets.map((b) => b.key)); const counts = new Map(); @@ -110,18 +110,22 @@ export function sessionStats(data, { since, until, project, timeZone, pricer } = const ch = changed.get(b.key); const files = { code: 0, tests: 0, docs: 0, ops: 0, plans: 0 }; for (const f of ch?.files ?? []) files[fileKind(f)] += 1; - const { intent, evidence } = classifyIntent({ - title: data.titles?.get(b.key), - firstPrompt: info?.firstPrompt, + const signals = { + title: data.titles?.get(b.key) ?? null, + firstPrompt: info?.firstPrompt ?? null, branches: [...(info?.branches ?? [])], workMessages: [...(info?.workMessages?.values() ?? [])].flat(), commands: commandsBySession.get(b.key) ?? [], files, newFiles: ch?.newFiles.size ?? 0, edits: s.edits, - }); - s.intent = intent; - s.intentEvidence = evidence; + }; + const { intent, evidence } = classifyIntent(signals); + // An intent Claude assigned (--intents) replaces the rules' guess. + const assigned = intents?.get(b.key); + s.intent = assigned ?? intent; + s.intentEvidence = assigned ? ['claude'] : evidence; + if (withSignals) s.intentSignals = { ...signals, ruleIntent: intent, ruleEvidence: evidence }; return s; }); } @@ -302,7 +306,7 @@ export function buildAdoption(data, opts) { }, { title: 'Session intent', - note: 'what sessions were for, from commits, titles, branches, prompts and changed files', + note: intentNote(stats), columns: [ left('Intent'), left('What'), @@ -319,3 +323,65 @@ export function buildAdoption(data, opts) { stats, }; } + +function intentNote(stats) { + const byClaude = stats.filter((s) => s.intentEvidence?.includes('claude')).length; + if (!byClaude) return 'what sessions were for, from commits, titles, branches, prompts and changed files'; + if (byClaude === stats.length) return 'what sessions were for, as classified by Claude'; + return `what sessions were for: ${byClaude} of ${stats.length} classified by Claude, the rest by rules`; +} + +/** + * Intents assigned outside ccreports (by Claude, through the skill), from JSON: + * { "": "" }, [{ id, intent }] or { sessions: [{ id, intent }] }. + * Intents are keys or titles from INTENTS. Returns { intents: Map, unknown: [values] }. + */ +export function parseIntents(json) { + const byName = new Map(INTENTS.flatMap((i) => [[i.key, i.key], [i.title.toLowerCase(), i.key]])); + const list = Array.isArray(json) + ? json + : Array.isArray(json?.sessions) + ? json.sessions + : Object.entries(json ?? {}).map(([id, intent]) => ({ id, intent })); + const intents = new Map(); + const unknown = []; + for (const { id, intent } of list) { + const key = byName.get(String(intent ?? '').trim().toLowerCase()); + if (id && key) intents.set(id, key); + else if (id) unknown.push(String(intent)); + } + return { intents, unknown }; +} + +/** + * The `intents` report: one row per session with its intent and the evidence. + * In JSON (see bin) each session also carries the signals, for Claude to classify. + */ +export function buildIntents(data, opts) { + const stats = sessionStats(data, { ...opts, withSignals: true }); + const title = (key) => INTENTS.find((i) => i.key === key)?.title ?? key; + const sorted = [...stats].sort((a, b) => (a.firstActivity < b.firstActivity ? -1 : 1)); + const range = opts.since || opts.until ? ` (${opts.since ?? '…'} → ${opts.until ?? 'today'})` : ''; + return { + title: `${opts.product ?? 'Claude Code'} session intent${range}`, + summary: [], + sections: [ + { + title: 'Sessions', + note: intentNote(stats), + columns: [left('Session'), left('Started'), left('Intent'), left('Evidence'), right('Edits'), right('PRs')], + rows: sorted.map((s) => ({ + cells: [ + sessionName(s.title ?? s.id.slice(0, 8)), + String(s.firstActivity).slice(0, 10), + title(s.intent), + s.intentEvidence.join(', '), + s.edits, + s.prs, + ], + })), + }, + ], + stats, + }; +} diff --git a/src/aggregate.mjs b/src/aggregate.mjs index 07f9263..77966fa 100644 --- a/src/aggregate.mjs +++ b/src/aggregate.mjs @@ -5,7 +5,7 @@ import { commandCategory } from './shell.mjs'; const QUIET_CATEGORY = 'Change directory'; -export const REPORTS = ['summary', 'daily', 'weekly', 'monthly', 'session', 'project', 'adoption', 'recommendations']; +export const REPORTS = ['summary', 'daily', 'weekly', 'monthly', 'session', 'project', 'adoption', 'intents', 'recommendations']; export function dateFormatter(timeZone) { // en-CA formats as YYYY-MM-DD. diff --git a/src/intent.mjs b/src/intent.mjs index b213779..0320a63 100644 --- a/src/intent.mjs +++ b/src/intent.mjs @@ -24,7 +24,7 @@ const KEYWORDS = { bugfix: /\b(bugs?|bugfix|fix(es|ed|ing)?|hotfix|errors?|exceptions?|crash(es|ed|ing)?|broken|breaks|fails?|failing|failed|failure|not working|(does ?n[o']t|did ?n[o']t|is ?n[o']t|wo ?n[o']t) (work|show|load|run|start|give|return)|no output|wrong|incorrect|regression|stack ?trace|debug(ging)?|repro|fout(en|melding)?|werkt niet|kapot)\b/i, feature: - /\b(add(s|ed|ing)?|implement(s|ed|ing)?|build|new (feature|page|app|application|endpoint|command|option|screen|tool|report)|i want (an?|to have)|support for|introduce|scaffold|make me|features?|improv(e|es|ed|ing|ements?)|enhanc(e|es|ed|ing|ements?)|poc|prototype|toevoegen|bouw)\b/i, + /\b(add(s|ed|ing)?|implement(s|ed|ing)?|build|new (feature|page|app|application|endpoint|command|option|screen|tool|report)|(create|write|make) (a|an) (new )?(tool|app|application|script|page|site|website|service|api|cli|bot|dashboard|component|generator|plugin|extension)|i want (an?|to have)|support for|introduce|scaffold|make me|features?|improv(e|es|ed|ing|ements?)|enhanc(e|es|ed|ing|ements?)|poc|prototype|toevoegen|bouw)\b/i, refactor: /\b(refactor(s|ed|ing)?|renam(e|es|ed|ing)|clean(ing)? ?up|simplif(y|ies|ied|ication)|restructur(e|ing)|extract|reorgani[sz](e|ing)|migrat(e|es|ed|ing|ion)|upgrad(e|es|ed|ing)|moderni[sz]e|dedup(licate)?|split (up|into)|consolidat(e|ing)|opschonen|herschrijf)\b/i, tests: /\b(unit[- ]?tests?|tests?|testing|test (case|suite)s?|coverage|e2e|playwright|jest|vitest|xunit|nunit|pytest)\b/i, @@ -54,12 +54,16 @@ export function workMessages(command) { return out; } -/** What a prompt says, without the tags Claude Code wraps around commands and attachments. */ +/** + * What a prompt says, without the tags Claude Code wraps around commands and + * attachments. A bare slash command (/clear, /compact) says nothing: ''. + */ export function promptText(text) { const args = /([\s\S]*?)<\/command-args>/.exec(text)?.[1]; const name = /([^<]*)<\/command-name>/.exec(text)?.[1]; const plain = name ? `${name} ${args ?? ''}` : String(text ?? '').replace(/<[^>]+>[\s\S]*?<\/[^>]+>/g, ' '); - return plain.replace(/\s+/g, ' ').trim().slice(0, 500); + const clean = plain.replace(/\s+/g, ' ').trim(); + return /^\/\S+$/.test(clean) ? '' : clean.slice(0, 500); } /** A changed file's kind: plans (plan / spec documents), docs, tests, ops (CI, containers, settings, manifests) or code. */ diff --git a/test/adoption.test.mjs b/test/adoption.test.mjs index 2f31469..c1711db 100644 --- a/test/adoption.test.mjs +++ b/test/adoption.test.mjs @@ -1,6 +1,6 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; -import { classify, buildAdoption, AUTONOMY_THRESHOLD } from '../src/adoption.mjs'; +import { classify, buildAdoption, buildIntents, parseIntents, AUTONOMY_THRESHOLD } from '../src/adoption.mjs'; import { toHtml, toMarkdown } from '../src/formats.mjs'; const stats = (over) => ({ @@ -101,6 +101,33 @@ test('buildAdoption: session intent per session and as a section', () => { assert.ok(doc.summary.some((l) => l.startsWith('By intent: bug fix 25%'))); }); +test('parseIntents accepts a map, a list or { sessions }, keys or titles', () => { + const { intents, unknown } = parseIntents({ a: 'bugfix', b: 'New development', c: 'banana' }); + assert.deepEqual([...intents], [['a', 'bugfix'], ['b', 'feature']]); + assert.deepEqual(unknown, ['banana']); + assert.deepEqual([...parseIntents([{ id: 'x', intent: 'Research & analysis' }]).intents], [['x', 'research']]); + assert.deepEqual([...parseIntents({ sessions: [{ id: 'y', intent: 'ops' }] }).intents], [['y', 'ops']]); +}); + +test('intents assigned by Claude replace the rules, in adoption and the intents report', () => { + const data = fixture(); + data.sessions.get('assist').branches = new Set(['fix/login']); + const intents = new Map([['assist', 'refactor']]); + const doc = buildAdoption(data, { timeZone: 'UTC', showCost: false, intents }); + const assist = doc.stats.find((s) => s.id === 'assist'); + assert.equal(assist.intent, 'refactor'); + assert.deepEqual(assist.intentEvidence, ['claude']); + assert.equal(assist.intentSignals, undefined); // signals only in the intents report + assert.match(doc.sections.find((s) => s.title === 'Session intent').note, /1 of 4 classified by Claude/); + + const report = buildIntents(data, { timeZone: 'UTC', showCost: false, intents }); + const row = report.sections[0].rows.find((r) => r.cells[2] === 'Refactoring').cells; + assert.equal(row[3], 'claude'); + const signals = report.stats.find((s) => s.id === 'assist').intentSignals; + assert.equal(signals.ruleIntent, 'bugfix'); + assert.deepEqual(signals.branches, ['fix/login']); +}); + test('adoption renders as cards in HTML and as tables in Markdown', () => { const doc = buildAdoption(fixture(), { timeZone: 'UTC', showCost: false }); const html = toHtml(doc); diff --git a/test/intent.test.mjs b/test/intent.test.mjs index ccc27fb..9de5da4 100644 --- a/test/intent.test.mjs +++ b/test/intent.test.mjs @@ -17,6 +17,8 @@ test('workMessages reads commit messages and PR titles in any quoting', () => { test('promptText drops the tags around commands and attachments', () => { assert.equal(promptText('/fix-bug\nlogin fails'), '/fix-bug login fails'); assert.equal(promptText('ignore why is it slow?'), 'why is it slow?'); + assert.equal(promptText('/clear\n'), ''); + assert.equal(promptText('/compact'), ''); }); test('fileKind tells plans, docs, tests, ops and code apart', () => { @@ -43,6 +45,7 @@ test('classifyIntent: commits outrank branches, titles and prompts', () => { assert.equal(intent({ branches: ['main'], title: 'Login button does not work' }), 'bugfix'); assert.equal(intent({ title: 'Rename the services and clean up' }), 'refactor'); assert.equal(intent({ commands: ['/code-review'] }), 'review'); + assert.equal(intent({ firstPrompt: 'create a tool that generates an html file per repo' }), 'feature'); assert.equal(intent({ title: 'Adoption cohorts plan mode', firstPrompt: 'add plan mode to the report' }), 'feature'); }); From 74d799d1811f434f2bd3fdf62db8dc88752497ef Mon Sep 17 00:00:00 2001 From: Peter Bons Date: Wed, 4 Nov 2026 10:29:08 +0100 Subject: [PATCH 3/3] Classify session intent from all prompts in a session The intents signals now carry every prompt typed in a session, in order (resumed copies once, bare slash commands and interrupts left out, each cut at 500 characters), instead of only the first. The skill reads them all and judges the session as a whole. The rules keep using the first prompt. Co-Authored-By: Claude Opus 5.5 --- README.md | 11 ++++++----- skills/report/SKILL.md | 26 ++++++++++++++++---------- src/adoption.mjs | 9 ++++++++- src/copilot.mjs | 7 ++++++- src/cursor.mjs | 7 ++++++- src/loader.mjs | 10 ++++++++-- test/adoption.test.mjs | 7 +++++++ test/ccreports.test.mjs | 1 + 8 files changed, 58 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 27e8870..1a98e9e 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,9 @@ decided it. Prompts themselves are not in the report. Cursor logs no git branch. `ccreports intents` lists every session with its intent and evidence. With -`-j` it also prints the signals (title, first prompt, branches, commit -messages, changed files per kind), so that a model can classify the -sessions; `--intents ` then applies its answer to any report, +`-j` it also prints the signals (title, every prompt typed in the session, +branches, commit messages, changed files per kind), so that a model can +classify the sessions as a whole; `--intents ` then applies its answer to any report, replacing the rules' guess: ```sh @@ -158,8 +158,9 @@ node bin/ccreports.mjs adoption --intents intents.json # evidence: claude ``` The `/ccreports:report` skill does this itself when you ask what your -sessions were for: Claude reads the signals, classifies each session, and -runs the report with `--intents`. +sessions were for: Claude reads all prompts of each session, classifies it, +and runs the report with `--intents`. The rules themselves only look at the +first prompt. ```sh node bin/ccreports.mjs adoption -s 20261001 -f html -o adoption.html diff --git a/skills/report/SKILL.md b/skills/report/SKILL.md index 5223c7d..f7bd16e 100644 --- a/skills/report/SKILL.md +++ b/skills/report/SKILL.md @@ -68,16 +68,22 @@ adoption report where intent is not the question, the rules are enough. node "/../../bin/ccreports.mjs" intents -j --no-open -o "/ccreports-intent-signals.json" [options] ``` - With more than about 200 sessions, narrow the range with `--since` or ask - the user which period to classify. -2. Read the file. `intents` lists the keys to choose from. Each session has a - `title` and `signals`: `firstPrompt`, `branches`, `workMessages` (commit - messages and PR titles it wrote), `commands`, `files` (changed files per - kind: code, tests, docs, ops, plans), `newFiles`, `edits`, and the rules' - guess (`ruleIntent`, `ruleEvidence`). Pick one key per session for its main - purpose: - - Commits and PR titles are the strongest evidence, then the title and the - first prompt, then the branch (a long-lived `feature/` branch also hosts + With more than about 200 sessions, or a file over about 300 KB (every + prompt is in it), narrow the range with `--since` or ask the user which + period to classify. +2. Read the file (in parts if it is large). `intents` lists the keys to choose + from. Each session has a `title` and `signals`: `prompts` (every prompt the + user typed, in order, each cut at 500 characters), `branches`, + `workMessages` (commit messages and PR titles it wrote), `commands`, + `files` (changed files per kind: code, tests, docs, ops, plans), `newFiles`, + `edits`, and the rules' guess (`ruleIntent`, `ruleEvidence`). Read all of a + session's prompts and pick one key for its main purpose: + - Judge the session as a whole: the first prompt sets the task, but later + prompts show where the work went (a question that turns into "now build + it" is new development; a feature session that becomes chasing an error + is a bug fix when most prompts are about that error). + - Commits and PR titles are the strongest evidence, then the prompts and + the title, then the branch (a long-lived `feature/` branch also hosts fixes). - A session that changed nothing is research, even if it talks about a bug. - Keep `ruleIntent` when the signals don't point elsewhere; use `other` only diff --git a/src/adoption.mjs b/src/adoption.mjs index 27e9f53..062dc5d 100644 --- a/src/adoption.mjs +++ b/src/adoption.mjs @@ -125,7 +125,14 @@ export function sessionStats(data, { since, until, project, timeZone, pricer, in const assigned = intents?.get(b.key); s.intent = assigned ?? intent; s.intentEvidence = assigned ? ['claude'] : evidence; - if (withSignals) s.intentSignals = { ...signals, ruleIntent: intent, ruleEvidence: evidence }; + if (withSignals) { + // Every prompt typed in the session, in order (resumed copies counted once). + const prompts = [...(info?.promptTexts?.values() ?? [])] + .sort((a, b) => (a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0)) + .map((p) => p.text); + const { firstPrompt, ...rest } = signals; + s.intentSignals = { ...rest, prompts: prompts.length ? prompts : firstPrompt ? [firstPrompt] : [], ruleIntent: intent, ruleEvidence: evidence }; + } return s; }); } diff --git a/src/copilot.mjs b/src/copilot.mjs index 89f38f1..72ce3e2 100644 --- a/src/copilot.mjs +++ b/src/copilot.mjs @@ -135,6 +135,7 @@ export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeS modes: new Set(), // interactive, plan, autopilot branches: new Set(), firstPrompt: null, + promptTexts: new Map(), // event id -> { timestamp, text } workMessages: new Map(), // toolCallId -> commit messages / PR titles }; sessions.set(id, info); @@ -305,7 +306,11 @@ export async function loadCopilotRecords({ dirs = defaultCopilotDirs(), includeS const content = String(data.content ?? ''); attributionOf(null).human(); info.prompts.add(d.id ?? d.timestamp); - if (!info.firstPrompt) info.firstPrompt = promptText(content) || null; + const said = promptText(content); + if (said) { + info.firstPrompt ??= said; + info.promptTexts.set(d.id ?? d.timestamp, { timestamp: d.timestamp, text: said }); + } const m = /^\/([\w:.-]+)/.exec(content.trim()); pendingCommand = null; if (m) { diff --git a/src/cursor.mjs b/src/cursor.mjs index 644f2cb..d6a303b 100644 --- a/src/cursor.mjs +++ b/src/cursor.mjs @@ -190,6 +190,7 @@ export async function loadCursorRecords({ dirs = defaultCursorDirs(), includeSub modes: new Set(), branches: new Set(), // Cursor logs none firstPrompt: null, + promptTexts: new Map(), // turn -> { timestamp, text } workMessages: new Map(), // tool call -> commit messages / PR titles }; sessions.set(id, info); @@ -216,7 +217,11 @@ export async function loadCursorRecords({ dirs = defaultCursorDirs(), includeSub turn += 1; timestamp = parsePromptTime(/([^<]+)<\/timestamp>/.exec(text)?.[1]) ?? timestamp; info.prompts.add(turn); - if (!info.firstPrompt) info.firstPrompt = promptText(query[1]) || null; + const said = promptText(query[1]); + if (said) { + info.firstPrompt ??= said; + info.promptTexts.set(turn, { timestamp: timestamp ?? mtime, text: said }); + } events.push(base()); pendingCommand = null; const cmd = /^\/([\w:.-]+)/.exec(query[1]); diff --git a/src/loader.mjs b/src/loader.mjs index ea6bdfb..beb2ee1 100644 --- a/src/loader.mjs +++ b/src/loader.mjs @@ -124,6 +124,7 @@ export async function loadRecords({ dirs = defaultProjectDirs(), includeSubagent compactions: new Set(), branches: new Set(), firstPrompt: null, + promptTexts: new Map(), // prompt uuid -> { timestamp, text } workMessages: new Map(), }); } @@ -319,8 +320,13 @@ export async function loadRecords({ dirs = defaultProjectDirs(), includeSubagent const origin = d.origin?.kind ?? 'human'; if (!agent && !d.isSidechain && origin === 'human' && d.promptSource !== 'system') { const info = sessionInfo(base.sessionId); - info.prompts.add(d.uuid ?? `${file}:${base.timestamp}`); - if (!info.firstPrompt && !text.startsWith(INTERRUPT_PREFIX)) info.firstPrompt = promptText(text) || null; + const promptId = d.uuid ?? `${file}:${base.timestamp}`; + info.prompts.add(promptId); + const said = text.startsWith(INTERRUPT_PREFIX) ? '' : promptText(text); + if (said) { + info.firstPrompt ??= said; + info.promptTexts.set(promptId, { timestamp: base.timestamp, text: said }); + } } } if (!agent && d.entrypoint) sessionInfo(base.sessionId).entrypoint ??= d.entrypoint; diff --git a/test/adoption.test.mjs b/test/adoption.test.mjs index c1711db..d2e5fc4 100644 --- a/test/adoption.test.mjs +++ b/test/adoption.test.mjs @@ -112,6 +112,11 @@ test('parseIntents accepts a map, a list or { sessions }, keys or titles', () => test('intents assigned by Claude replace the rules, in adoption and the intents report', () => { const data = fixture(); data.sessions.get('assist').branches = new Set(['fix/login']); + data.sessions.get('assist').firstPrompt = 'login fails'; + data.sessions.get('assist').promptTexts = new Map([ + ['p2', { timestamp: '2026-10-02T10:05:00Z', text: 'now rename it' }], + ['p1', { timestamp: '2026-10-02T10:00:00Z', text: 'login fails' }], + ]); const intents = new Map([['assist', 'refactor']]); const doc = buildAdoption(data, { timeZone: 'UTC', showCost: false, intents }); const assist = doc.stats.find((s) => s.id === 'assist'); @@ -126,6 +131,8 @@ test('intents assigned by Claude replace the rules, in adoption and the intents const signals = report.stats.find((s) => s.id === 'assist').intentSignals; assert.equal(signals.ruleIntent, 'bugfix'); assert.deepEqual(signals.branches, ['fix/login']); + assert.deepEqual(signals.prompts, ['login fails', 'now rename it']); // all prompts, in order + assert.equal(signals.firstPrompt, undefined); }); test('adoption renders as cards in HTML and as tables in Markdown', () => { diff --git a/test/ccreports.test.mjs b/test/ccreports.test.mjs index 9ec1324..0f2aaa6 100644 --- a/test/ccreports.test.mjs +++ b/test/ccreports.test.mjs @@ -107,6 +107,7 @@ test('records the signals for session intent: branch, first prompt, commits, cha const info = data.sessions.get('s1'); assert.deepEqual([...info.branches], ['fix/login']); assert.equal(info.firstPrompt, 'the login button does not work'); + assert.deepEqual([...info.promptTexts.values()].map((p) => p.text), ['the login button does not work', 'and the logout one']); assert.deepEqual([...info.workMessages.values()], [['fix: login button']]); const byName = Object.fromEntries(data.tools.map((t) => [t.name, t])); assert.deepEqual(byName.Edit.editFiles, ['/work/app/a.js']);