tpmjs/packages/tools/official/workflow-variant-generate/README.md
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

6.3 KiB

Workflow Variant Generate

Generate multiple variations of a workflow with configurable constraints for testing, optimization, and exploration.

Installation

npm install @tpmjs/tools-workflow-variant-generate

Usage

import { workflowVariantGenerateTool } from '@tpmjs/tools-workflow-variant-generate';

const result = await workflowVariantGenerateTool.execute({
  workflow: {
    name: 'CI/CD Pipeline',
    description: 'Continuous integration and deployment',
    steps: [
      { action: 'checkout', details: 'Clone repository', duration: 1 },
      { action: 'test', details: 'Run test suite', duration: 5 },
      { action: 'build', details: 'Build production bundle', duration: 3 },
      { action: 'deploy', details: 'Deploy to production', duration: 2 }
    ]
  },
  variationCount: 3,
  constraints: {
    allowStepRemoval: true,
    allowStepModification: true,
    allowReordering: false,
    requiredSteps: ['checkout', 'deploy']
  }
});

console.log(result.variants);
// [
//   {
//     name: 'CI/CD Pipeline (Variant 1)',
//     steps: [...], // Modified version
//     metadata: {
//       variantNumber: 1,
//       hash: 'abc123...',
//       modifications: ['Modified test duration: 5m → 7m']
//     }
//   },
//   ...
// ]

Constraints

Control how variants are generated:

Step Count Constraints

  • maxSteps (number) - Maximum steps per variant (default: 20)
  • minSteps (number) - Minimum steps per variant (default: 1)

Modification Constraints

  • allowStepRemoval (boolean) - Allow removing steps (default: true)
  • allowStepModification (boolean) - Allow modifying step properties (default: true)
  • allowReordering (boolean) - Allow reordering steps (default: true)
  • preserveOrder (boolean) - Force original order (default: false)

Step Constraints

  • requiredSteps (string[]) - Step actions that must be included
  • forbiddenSteps (string[]) - Step actions that must not be included

Features

  • Deterministic Generation: Same input produces same variants
  • Constraint Validation: Ensures variants meet all constraints
  • Hash Tracking: Each variant has a unique hash for identification
  • Modification Logs: Track what changed in each variant
  • Dependency Awareness: Respects step dependencies when reordering

Examples

Generate Simple Variants

const result = await workflowVariantGenerateTool.execute({
  workflow: {
    name: 'Deployment',
    steps: [
      { action: 'build' },
      { action: 'test' },
      { action: 'deploy' }
    ]
  },
  variationCount: 5
});

Preserve Order, Allow Modifications

const result = await workflowVariantGenerateTool.execute({
  workflow: {
    name: 'Data Pipeline',
    steps: [
      { action: 'extract', duration: 10 },
      { action: 'transform', duration: 20 },
      { action: 'load', duration: 5 }
    ]
  },
  variationCount: 3,
  constraints: {
    preserveOrder: true,
    allowStepModification: true,
    allowStepRemoval: false
  }
});
// Variants will have same order but different durations/details

Required and Forbidden Steps

const result = await workflowVariantGenerateTool.execute({
  workflow: {
    name: 'Security Scan',
    steps: [
      { action: 'scan-dependencies' },
      { action: 'scan-code' },
      { action: 'scan-secrets' },
      { action: 'generate-report' },
      { action: 'upload-results' }
    ]
  },
  variationCount: 4,
  constraints: {
    requiredSteps: ['generate-report'], // Must include
    forbiddenSteps: ['upload-results'], // Must exclude
    allowStepRemoval: true
  }
});

Optimize for Speed (Fewer Steps)

const result = await workflowVariantGenerateTool.execute({
  workflow: {
    name: 'Full Test Suite',
    steps: [
      { action: 'unit-tests', duration: 5 },
      { action: 'integration-tests', duration: 10 },
      { action: 'e2e-tests', duration: 20 },
      { action: 'performance-tests', duration: 15 },
      { action: 'security-tests', duration: 8 }
    ]
  },
  variationCount: 3,
  constraints: {
    maxSteps: 3, // Optimize by reducing steps
    requiredSteps: ['unit-tests']
  }
});

Generate Test Scenarios

const result = await workflowVariantGenerateTool.execute({
  workflow: {
    name: 'User Onboarding',
    steps: [
      { action: 'create-account' },
      { action: 'verify-email' },
      { action: 'complete-profile' },
      { action: 'setup-preferences' },
      { action: 'tutorial' }
    ]
  },
  variationCount: 5,
  constraints: {
    requiredSteps: ['create-account', 'verify-email'],
    allowStepRemoval: true,
    allowReordering: true
  }
});
// Creates different user flow variants for testing

Output Structure

{
  variants: [
    {
      name: 'Workflow Name (Variant 1)',
      description: 'Workflow description - Variant 1',
      steps: [
        { action: 'step1', details: '...', duration: 5 }
      ],
      metadata: {
        variantNumber: 1,
        derivedFrom: 'Workflow Name',
        generatedAt: '2025-01-01T00:00:00.000Z',
        hash: 'abc123...', // Variant hash
        modifications: [
          'Modified step1 duration: 5m → 7m',
          'Removed step: step2'
        ]
      }
    }
  ],
  originalHash: 'xyz789...', // Original workflow hash
  variantHashes: ['abc123...', 'def456...'] // All variant hashes
}

Use Cases

  • A/B Testing: Generate workflow variants for comparison
  • Optimization: Explore different execution strategies
  • Test Coverage: Create diverse test scenarios
  • What-If Analysis: Explore alternative approaches
  • Load Testing: Generate varied workload patterns
  • Documentation: Show multiple implementation options

Modification Types

The tool can apply these modifications:

  1. Step Removal: Remove non-required steps
  2. Duration Adjustment: Modify step durations
  3. Details Enhancement: Add optimization notes to details
  4. Step Reordering: Swap adjacent independent steps
  5. Constraint Filtering: Remove forbidden steps

Each variant tracks its modifications in the metadata.

Hash Usage

Hashes can be used for:

  • Deduplication: Identify identical variants
  • Caching: Cache results by variant hash
  • Comparison: Track changes between variants
  • Versioning: Version workflows by hash

License

MIT