tpmjs/packages/tools/official/toc-generate
Ajax Davis 5d2096fb5d 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
..
src feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
package.json feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
README.md feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsconfig.json feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsup.config.ts feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00

@tpmjs/tools-toc-generate

Generate table of contents from markdown headings.

Features

  • Parses ATX-style markdown headings (#, ##, ###, etc.)
  • Generates formatted TOC with anchor links
  • Configurable maximum depth (default: 3)
  • Handles duplicate headings with unique slugs
  • Returns structured heading data with line numbers

Installation

npm install @tpmjs/tools-toc-generate

Usage

import { tocGenerateTool } from '@tpmjs/tools-toc-generate';

const result = await tocGenerateTool.execute({
  markdown: `
# Introduction
## Overview
## Getting Started
### Installation
### Configuration
# Advanced Topics
## API Reference
`,
  maxDepth: 3, // Optional, default is 3
});

console.log(result.toc);
// Output:
// - [Introduction](#introduction)
//   - [Overview](#overview)
//   - [Getting Started](#getting-started)
//     - [Installation](#installation)
//     - [Configuration](#configuration)
// - [Advanced Topics](#advanced-topics)
//   - [API Reference](#api-reference)

console.log(result.headings);
// [
//   { level: 1, text: 'Introduction', slug: 'introduction', line: 2 },
//   { level: 2, text: 'Overview', slug: 'overview', line: 3 },
//   ...
// ]

console.log(result.depth);
// { min: 1, max: 3, included: 7 }

API

tocGenerateTool.execute(input)

Input

  • markdown (string, required): The markdown content to parse
  • maxDepth (number, optional): Maximum heading depth to include (1-6, default: 3)

Output

Returns a TocResult object:

interface TocResult {
  toc: string;              // Formatted TOC markdown
  headings: Heading[];      // Array of parsed headings
  depth: {
    min: number;            // Minimum heading level found
    max: number;            // Maximum heading level found
    included: number;       // Number of headings included in TOC
  };
}

interface Heading {
  level: number;            // Heading level (1-6)
  text: string;             // Heading text
  slug: string;             // URL-safe slug
  line: number;             // Line number in source
}

Examples

Basic TOC

const result = await tocGenerateTool.execute({
  markdown: '# Title\n## Section 1\n## Section 2',
});

console.log(result.toc);
// - [Title](#title)
//   - [Section 1](#section-1)
//   - [Section 2](#section-2)

Limit Depth

const result = await tocGenerateTool.execute({
  markdown: '# Title\n## Section\n### Subsection\n#### Details',
  maxDepth: 2, // Only include h1 and h2
});

console.log(result.toc);
// - [Title](#title)
//   - [Section](#section)

Custom Anchor IDs

const result = await tocGenerateTool.execute({
  markdown: '# Introduction {#intro}\n## Overview {#overview}',
});

console.log(result.toc);
// - [Introduction](#intro)
//   - [Overview](#overview)

Use Cases

  • Generate navigation for long markdown documents
  • Create automatic table of contents for READMEs
  • Extract document structure for analysis
  • Build documentation site navigation

License

MIT