PHPackages                             cognesy/instructor-hub - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. cognesy/instructor-hub

ActiveLibrary[CLI &amp; Console](/categories/cli)

cognesy/instructor-hub
======================

CLI tool to work with Instructor PHP code examples and docs

v2.3.1(1mo ago)00MITPHPPHP ^8.3

Since Apr 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/cognesy/instructor-hub)[ Packagist](https://packagist.org/packages/cognesy/instructor-hub)[ Docs](https://instructorphp.com)[ RSS](/packages/cognesy-instructor-hub/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (86)Used By (0)

Hub - Example Execution &amp; Tracking
======================================

[](#hub---example-execution--tracking)

Hub provides example execution with comprehensive status tracking, selective re-execution, and performance analytics.

Quick Start
-----------

[](#quick-start)

```
# Run single example (raw output, colors preserved)
composer hub run 1
composer hub run basics/Basic

# List all examples
composer hub list
composer hub -- list --tag=agents
composer hub -- list --tags='[agents,streaming]'

# Run all examples with tracking
composer hub all

# Check execution status
composer hub status
```

Core Commands
-------------

[](#core-commands)

### Single Example Execution

[](#single-example-execution)

```
# Raw output (default) - preserves colors, streaming, TTY
composer hub run 35                    # Real-time streaming output
composer hub raw 35                    # Alias for raw output

# With tracking (stores execution metadata)
composer hub -- run 35 --track         # Tracked execution

> **Note**: When using options with composer scripts, use `composer hub --  --option`
> to ensure arguments are passed through correctly.
```

### Bulk Execution

[](#bulk-execution)

```
# Run all examples with tracking
composer hub all                       # Start from beginning
composer hub all 50                    # Start from example 50

# Selective execution
composer hub -- all --filter=pending   # Only unexecuted examples
composer hub -- all --filter=errors    # Only failed examples
composer hub -- all --filter=stale     # Only examples with modified files
composer hub -- all --dry-run          # Preview without executing

# Dedicated commands
composer hub errors                    # Re-run failed examples
composer hub stale                     # Run examples with modified files
```

### Status &amp; Analytics

[](#status--analytics)

```
# Status overview
composer hub status                    # Summary view
composer hub -- status --detailed      # Per-example breakdown
composer hub -- status --errors-only   # Show only failures
composer hub -- status --format=json   # JSON output for automation

# Performance analytics
composer hub stats                     # Performance metrics
composer hub -- stats --slowest=20     # Show 20 slowest examples
```

### Maintenance

[](#maintenance)

```
# Clean status data
composer hub -- clean --completed      # Remove successful runs
composer hub -- clean --older-than="1 week"  # Remove old data
composer hub -- clean --all --backup   # Reset all (with backup)
```

Status Tracking
---------------

[](#status-tracking)

### Status File Location

[](#status-file-location)

- **File**: `.hub/status.json` (git-excluded)
- **Contains**: Execution metadata, timing, errors, attempts
- **Format**: JSON with metadata, examples, and statistics sections

### Execution States

[](#execution-states)

- `pending` - Never executed
- `running` - Currently executing
- `completed` - Successful execution
- `error` - Failed execution
- `interrupted` - Interrupted by Ctrl+C
- `stale` - Source file modified since last run

### Status Data Structure

[](#status-data-structure)

```
{
  "metadata": {
    "version": "1.0",
    "lastUpdated": "2024-12-07T15:30:45Z",
    "totalExamples": 213
  },
  "examples": {
    "1": {
      "index": 1,
      "name": "Basic",
      "status": "completed",
      "executionTime": 1.245,
      "lastExecuted": "2024-12-07T15:25:30Z",
      "attempts": 1,
      "errors": [],
      "exitCode": 0
    }
  },
  "statistics": {
    "totalExecuted": 150,
    "completed": 148,
    "errors": 2,
    "averageExecutionTime": 1.234
  }
}
```

Filtering System
----------------

[](#filtering-system)

### Example Metadata Filtering

[](#example-metadata-filtering)

```
# List examples with a single tag
composer hub -- list --tag=agents

# Repeat --tag to require multiple tags
composer hub -- list --tag=agents --tag=streaming

# Or pass multiple tags as a bracket/comma list
composer hub -- list --tags='[agents,streaming]'
composer hub -- list --tags='agents,streaming'
```

When multiple tags are provided, hub lists examples that contain all requested tags.

### Filter Modes

[](#filter-modes)

- `all` - All examples (default)
- `pending` - Never executed examples
- `errors` - Failed examples only
- `stale` - Examples with modified source files
- `completed` - Successfully executed examples

### Usage Patterns

[](#usage-patterns)

```
# Command variations (all equivalent)
composer hub all --filter=errors
composer hub errors
composer hub -- all --filter=errors

# Multiple filters
composer hub all --filter=pending --dry-run
composer hub all --filter=stale --stop-on-error
```

Output Formats
--------------

[](#output-formats)

### Table Format (Default)

[](#table-format-default)

```
Total Examples: 213
Executed:       150
Completed:      148
Errors:         2
Success Rate:   98.67%

```

### JSON Format

[](#json-format)

```
composer hub status --format=json
# Returns structured JSON for automation
```

### CSV Export

[](#csv-export)

```
composer hub stats --format=csv > performance.csv
# Exports performance data for analysis
```

Performance Features
--------------------

[](#performance-features)

### Execution Timing

[](#execution-timing)

- **Per-example timing**: Precise execution duration
- **Aggregate statistics**: Average, median, std deviation
- **Performance ranking**: Slowest/fastest examples
- **Trend analysis**: Execution time over multiple runs

### Error Tracking

[](#error-tracking)

- **Error classification**: Fatal errors, timeouts, exceptions
- **Failure patterns**: Frequently failing examples
- **Recovery tracking**: Success after failure count
- **Error details**: Full error messages and stack traces

### Interruption Handling

[](#interruption-handling)

- **Graceful Ctrl+C**: Preserves execution state
- **Resume capability**: Continue from interruption point
- **Partial results**: Status saved for completed examples
- **Signal handling**: Clean shutdown with state preservation

Integration &amp; Automation
----------------------------

[](#integration--automation)

### CI/CD Integration

[](#cicd-integration)

```
# Run only failing tests in CI
composer hub errors --format=json > failed-tests.json

# Check if any examples are failing
composer hub status --errors-only --format=json | jq '.examples | length'

# Get performance baseline
composer hub stats --format=json > performance-baseline.json
```

### Git Integration

[](#git-integration)

- **Automatic .gitignore**: `.hub/` directory excluded
- **Stale detection**: Modified file tracking
- **Branch isolation**: Status per branch/worktree
- **Hook integration**: Pre-commit validation possible

### IDE Integration

[](#ide-integration)

```
// .vscode/tasks.json
{
  "tasks": [
    {
      "label": "Hub: Run Example",
      "type": "shell",
      "command": "composer hub run ${input:exampleNumber}"
    },
    {
      "label": "Hub: Check Status",
      "type": "shell",
      "command": "composer hub status"
    }
  ]
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Parallel Development

[](#parallel-development)

```
# Different status per worktree
git worktree add ../feature-branch feature/new-functionality
cd ../feature-branch
composer hub all --filter=pending  # Independent status tracking
```

### Custom Workflows

[](#custom-workflows)

```
# Development workflow
composer hub all --filter=stale     # Run modified examples
composer hub errors                 # Fix any failures
composer hub status --detailed      # Review results

# Performance monitoring
composer hub stats --slowest=10     # Identify bottlenecks
composer hub run 65 --track         # Profile specific example
composer hub clean --older-than="1 day"  # Cleanup old data
```

### Debugging &amp; Troubleshooting

[](#debugging--troubleshooting)

```
# Raw execution for debugging
composer hub run 35                 # Full output with colors

# Tracked execution for analysis
composer hub -- run 35 --track      # Status persistence

# Error investigation
composer hub status --errors-only --detailed
composer hub run   # Debug with full output
```

Architecture
------------

[](#architecture)

### DDD Implementation

[](#ddd-implementation)

- **Value Objects**: ExecutionResult, ExecutionError, ExecutionStatus
- **Entities**: ExampleExecutionStatus with business logic
- **Services**: StatusRepository, ExecutionTracker, EnhancedRunner
- **Interfaces**: CanTrackExecution, CanPersistStatus, CanExecuteExample

### File Organization

[](#file-organization)

```
packages/hub/src/
├── Commands/           # Console commands
├── Contracts/          # Domain interfaces
├── Data/              # Value objects & entities
├── Services/          # Application services
└── Exceptions/        # Domain exceptions

```

Backward Compatibility
----------------------

[](#backward-compatibility)

All existing workflows continue unchanged:

- `composer hub list` - Example listing
- `composer hub run 1` - Single execution (now with raw output)
- `composer hub all` - Bulk execution (now with tracking)
- `composer hub show 1` - Example details

New capabilities are additive and optional.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

85

Last Release

49d ago

Major Versions

0.17.11 → 1.0-rc12025-06-11

v1.22.0 → v2.0.02026-03-13

PHP version history (2 changes)0.13.9PHP ^8.2

v1.19.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/d11593cece5bb65ba5eea704a91e1dda72362e86f8fe0e99295f291ba7628cac?d=identicon)[ddebowczyk](/maintainers/ddebowczyk)

---

Top Contributors

[![ddebowczyk](https://avatars.githubusercontent.com/u/184133?v=4)](https://github.com/ddebowczyk "ddebowczyk (158 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cognesy-instructor-hub/health.svg)

```
[![Health](https://phpackages.com/badges/cognesy-instructor-hub/health.svg)](https://phpackages.com/packages/cognesy-instructor-hub)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.1k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)[codedungeon/php-cli-colors

Liven up you PHP Console Apps with standard colors

10210.1M26](/packages/codedungeon-php-cli-colors)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
