tpmjs/packages/tools/official/coverage-tracker/README.md
Ajax Davis 9a0fb5f2d5 feat: add 100+ official TPMJS tools
Implements a comprehensive suite of AI SDK v6 tools across multiple categories:

- Research (5): page-brief, compare-pages, source-credibility, claim-checklist, timeline-from-text
- Web (10): fetch-text, links-catalog, extract-meta, extract-json-ld, redirect-trace, sitemap-read, rss-read, table-extract, robots-policy, url-normalize
- Data (15): csv-parse, csv-stringify, json-repair, json-schema-validate, yaml-parse, yaml-stringify, text-chunk, normalize-whitespace, dedupe-by-key, pivot, rows-filter, rows-sort, rows-group-aggregate, rows-join, schema-infer
- Doc (12): toc-generate, glossary-build, faq-from-text, executive-brief, decision-record-adr, prd-outline, acceptance-criteria, style-rewrite
- Eng (12): diff-text-unified, env-var-docs-generate, dependency-audit-lite, conventional-commit-suggest, markdown-lint-basic, test-case-generate, stacktrace-parse, release-notes, changelog-entry, release-checklist
- Security (7): redact-secrets, secret-scan-text, url-risk-heuristic, csp-compose, hardening-checklist-web, access-control-matrix, data-classification-heuristic
- Stats (9): effect-size-suite, bootstrap-ci, permutation-test, multiple-testing-adjust, linear-regression-ols, logistic-regression, time-series-decompose-lite, anomaly-detect-mad
- Ops (7): slo-draft, runbook-draft, postmortem-draft, postmortem-action-extractor, error-log-triage, coverage-tracker, monitoring-gap-analysis
- Agent (15): prompt-to-workflow-skeleton, workflow-validate-io, workflow-explain, workflow-cost-estimate, tool-call-accuracy-score, eval-fixture-build, guardrail-policy-draft, workflow-auto-repair, tool-selection-plan, novelty-score-workflow, workflow-variant-generate, config-normalize, recipe-*
- Utility (8): base64-encode, base64-decode, hash-text, regex-extract, template-render, date-parse, json-path-query, url-parse
- HTML (3): html-sanitize, html-to-markdown, markdown-to-html

All tools follow AI SDK v6 pattern with tool() and jsonSchema<T>().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-31 22:55:56 +10:00

5.6 KiB

Coverage Tracker

Tracks which tools have been used in a workflow and calculates coverage percentage. Useful for testing workflow completeness and analyzing tool utilization patterns.

Installation

npm install @tpmjs/tools-coverage-tracker

Usage

import { coverageTrackerTool } from '@tpmjs/tools-coverage-tracker';
import { generateText } from 'ai';

const result = await generateText({
  model: yourModel,
  tools: {
    trackCoverage: coverageTrackerTool,
  },
  prompt: 'Track tool usage coverage...',
});

Direct Usage

import { coverageTrackerTool } from '@tpmjs/tools-coverage-tracker';

const result = await coverageTrackerTool.execute({
  availableTools: ['searchWeb', 'fetchUrl', 'summarize', 'translateText', 'saveNote'],
  usedTools: ['searchWeb', 'fetchUrl', 'searchWeb', 'summarize'],
});

console.log(result);
// {
//   coverage: 0.6,
//   usedCount: 3,
//   totalCount: 5,
//   unusedTools: ['translateText', 'saveNote'],
//   usedTools: [
//     { name: 'searchWeb', used: true, usageCount: 2 },
//     { name: 'fetchUrl', used: true, usageCount: 1 },
//     { name: 'summarize', used: true, usageCount: 1 }
//   ],
//   coveragePercent: '60.0%',
//   summary: 'Coverage: 60.0% (3/5 tools) | Unused: translateText, saveNote'
// }

Input Schema

{
  availableTools: string[];  // All available tool names
  usedTools: string[];       // Tools that were actually used (can include duplicates)
}

Output Schema

{
  coverage: number;               // Coverage ratio (0-1)
  usedCount: number;              // Number of unique tools used
  totalCount: number;             // Total number of available tools
  unusedTools: string[];          // List of tools not used
  usedTools: Array<{              // List of used tools with stats
    name: string;                 // Tool name
    used: boolean;                // Always true for this array
    usageCount: number;           // How many times it was called
  }>;
  coveragePercent: string;        // Formatted percentage (e.g., "75.0%")
  summary: string;                // Human-readable summary
}

Coverage Calculation

Coverage = (Number of unique tools used) / (Total available tools)

  • Duplicate tool calls are counted separately in usageCount
  • Coverage is based on unique tools used
  • Tools used but not in availableTools trigger a warning

Use Cases

1. Workflow Testing

Ensure your agent workflow exercises all available tools:

const availableTools = ['search', 'analyze', 'summarize', 'report'];
const usedTools = ['search', 'analyze', 'report'];

const coverage = await coverageTrackerTool.execute({
  availableTools,
  usedTools,
});

if (coverage.coverage < 0.75) {
  console.warn('Low tool coverage - workflow may be incomplete');
}

2. Tool Utilization Analysis

Find which tools are being used most/least:

const result = await coverageTrackerTool.execute({
  availableTools: ['tool1', 'tool2', 'tool3', 'tool4'],
  usedTools: ['tool1', 'tool1', 'tool1', 'tool2', 'tool2', 'tool3'],
});

// result.usedTools sorted by usage:
// [
//   { name: 'tool1', usageCount: 3 },
//   { name: 'tool2', usageCount: 2 },
//   { name: 'tool3', usageCount: 1 },
// ]
// result.unusedTools: ['tool4']

3. Integration Testing

Track tool coverage across test runs:

const testRuns = [
  { name: 'Test 1', used: ['searchWeb', 'fetchUrl'] },
  { name: 'Test 2', used: ['searchWeb', 'summarize'] },
  { name: 'Test 3', used: ['translateText'] },
];

const allTools = ['searchWeb', 'fetchUrl', 'summarize', 'translateText'];

for (const run of testRuns) {
  const coverage = await coverageTrackerTool.execute({
    availableTools: allTools,
    usedTools: run.used,
  });
  console.log(`${run.name}: ${coverage.coveragePercent}`);
}

4. Finding Dead Code

Identify tools that are never used:

const coverage = await coverageTrackerTool.execute({
  availableTools: ['common', 'rare', 'legacy', 'deprecated'],
  usedTools: ['common', 'common', 'common', 'rare'],
});

// coverage.unusedTools: ['legacy', 'deprecated']
// Consider removing these tools

Advanced Features

Duplicate Tracking

The tool tracks how many times each tool is called:

const result = await coverageTrackerTool.execute({
  availableTools: ['api1', 'api2'],
  usedTools: ['api1', 'api1', 'api1', 'api2'],
});

// result.usedTools[0] = { name: 'api1', usageCount: 3 }
// result.usedTools[1] = { name: 'api2', usageCount: 1 }

Unknown Tool Detection

Warns if tools are used that aren't in the available list:

const result = await coverageTrackerTool.execute({
  availableTools: ['tool1', 'tool2'],
  usedTools: ['tool1', 'unknownTool'],
});

// result.summary: "... | Warning: 1 unknown tool(s) used"

Examples

Example 1: Full Coverage

const result = await coverageTrackerTool.execute({
  availableTools: ['a', 'b', 'c'],
  usedTools: ['a', 'b', 'c'],
});
// coverage.coverage = 1.0
// coverage.coveragePercent = "100.0%"
// coverage.unusedTools = []

Example 2: Partial Coverage

const result = await coverageTrackerTool.execute({
  availableTools: ['search', 'fetch', 'save', 'analyze'],
  usedTools: ['search', 'fetch'],
});
// coverage.coverage = 0.5
// coverage.usedCount = 2
// coverage.unusedTools = ['save', 'analyze']

Example 3: No Coverage

const result = await coverageTrackerTool.execute({
  availableTools: ['tool1', 'tool2'],
  usedTools: [],
});
// coverage.coverage = 0
// coverage.unusedTools = ['tool1', 'tool2']

License

MIT