npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ebowwa/glm-daemon-examples

v0.1.0

Published

Example applications demonstrating the GLM daemon in action

Readme

@ebowwa/glm-daemon-examples

Example applications demonstrating the GLM daemon in action.

Overview

This package contains comprehensive examples that demonstrate how to use the GLM daemon for autonomous AI agent workflows. Each example is self-contained, well-documented, and runnable.

Prerequisites

Required

  • Node.js 18+ or Bun 1.0+
  • @ebowwa/glm-daemon package installed
  • @ebowwa/teammates package installed
  • GLM API credentials configured

Optional (for specific examples)

  • Git - for GitHub PR Bot example
  • GitHub CLI (gh) - for creating actual PRs
  • MCP servers - for tool integration examples

Installation

# Install the package
bun add @ebowwa/glm-daemon-examples

# Or install from source
cd packages/src/glm-daemon-examples
bun install

Quick Start

# List all available examples
bun run example list

# Run a specific example
bun run example run simple-butler

# Get information about an example
bun run example info github-bot

# Run with custom task
bun run example run simple-butler --task "Write a hello world program"

Examples

1. Simple Butler Demo

Complexity: Simple

File: examples/simple-butler.ts

Features:

  • State persistence
  • Hook usage (onSessionStart, onSessionEnd)
  • Simple request/response pattern
  • Clean shutdown

Description: A basic butler that demonstrates the most fundamental aspects of the GLM daemon. It shows how to create a daemon, monitor lifecycle events through hooks, and observe state persistence.

Run:

bun run example run simple-butler

Custom Task:

bun run example run simple-butler --task "Write a greeting to hello.txt"

Expected Output:

[SimpleButler] ==================================================
[SimpleButler] Simple Butler Demo
[SimpleButler] ==================================================
[SimpleButler] Task: Write a simple greeting message...
[SimpleButler] Work directory: /path/to/dir
[SimpleButler] Team name: simple-butler-team
[SimpleButler]
[SimpleButler] --- Starting Butler ---
[SimpleButler] [onSessionStart] Session starting!
[SimpleButler] [onSessionStart] Initial state: {...}
[SimpleButler] ✓ Butler started!
...
[SimpleButler] --- Stopping Butler ---
[SimpleButler] ✓ Butler stopped!

2. GitHub PR Bot

Complexity: Medium

File: examples/github-bot.ts

Features:

  • Git workflow integration
  • Worktree isolation for parallel execution
  • Automatic commits and PR creation
  • Clean cleanup of worktrees

Description: A dev personality that demonstrates automated PR workflows. It creates a git worktree for isolated changes, makes code changes based on a task, commits with descriptive messages, and can create a pull request.

Prerequisites:

  • Git repository initialized
  • GitHub CLI (gh) installed and authenticated (for actual PR creation)

Run:

# In your git repository
bun run example run github-bot

# With custom task
bun run example run github-bot --task "Add a new utility function"

Expected Output:

[GitHubBot] ==================================================
[GitHubBot] GitHub PR Bot Demo
[GitHubBot] ==================================================
[GitHubBot] Repository: /path/to/repo
[GitHubBot] Task: Add a new utility function...
[GitHubBot] Base branch: dev
[GitHubBot] Auto commit: true
[GitHubBot]
[GitHubBot] --- Starting GitHub Bot ---
[GitHubBot] [onSessionStart] GitHub Bot starting!
[GitHubBot] [onSessionStart] Branch: feat/glm-...
[GitHubBot] ✓ GitHub Bot started!
[GitHubBot]
[GitHubBot] --- Monitoring progress ---
[GitHubBot] Status update:
[GitHubBot]   Phase: executing
[GitHubBot]   Iteration: 1
[GitHubBot]   Progress: 2/5 subtasks
...
[GitHubBot] --- Bot Complete! ---
[GitHubBot] ✓ GitHub Bot stopped!

3. Multi-Agent Coordination

Complexity: Complex

File: examples/team-coordination.ts

Features:

  • Team creation and lifecycle
  • Spawning multiple teammates with different roles
  • Inter-agent messaging (direct and broadcast)
  • Coordinated task execution
  • Team cleanup

Description: Demonstrates multi-agent coordination using the teammates system. It creates a team with multiple specialized agents (planner, explorer, implementer, reviewer), shows how they communicate through messages, and coordinates their work.

Run:

bun run example run team-coordination

Expected Output:

[TeamCoordination] ==================================================
[TeamCoordination] Multi-Agent Coordination Demo
[TeamCoordination] ==================================================
[TeamCoordination] Task: Create a REST API...
[TeamCoordination] Team name: coordination-demo-team
[TeamCoordination]
[TeamCoordination] --- Creating Team ---
[TeamCoordination] ✓ Team created: coordination-demo-team
[TeamCoordination]
[TeamCoordination] --- Spawning Teammates ---
[TeamCoordination] Spawning planner...
[TeamCoordination] ✓ Spawned: planner
[TeamCoordination] Spawning explorer...
[TeamCoordination] ✓ Spawned: explorer
...
[TeamCoordination] Total teammates: 4
[TeamCoordination]
[TeamCoordination] --- Coordinating Work ---
[TeamCoordination] Sending task to planner...
[TeamCoordination] Sending exploration task...
...
[TeamCoordination] --- Coordinating Shutdown ---
[TeamCoordination] Requesting shutdown from planner...
...
[TeamCoordination] --- Cleaning Up Team ---
[TeamCoordination] ✓ Team deleted
[TeamCoordination]
[TeamCoordination] ==================================================
[TeamCoordination] Demo Complete!
[TeamCoordination] ==================================================

4. Custom Hooks

Complexity: Medium

File: examples/custom-hooks.ts

Features:

  • Priority-based execution
  • Conditional execution with filters
  • Pre-tool-use validation
  • Post-tool-use logging and analysis
  • Hook chaining

Description: Demonstrates advanced hook patterns including priority-based execution, conditional filtering, security validation, and performance monitoring. Shows how hooks can be chained and ordered.

Run:

bun run example run custom-hooks

Expected Output:

[CustomHooks] ==================================================
[CustomHooks] Custom Hooks Demo
[CustomHooks] ==================================================
[CustomHooks] Active hooks:
[CustomHooks]   - Session Logger (priority: 100)
[CustomHooks]   - Security Validator (priority: 90)
[CustomHooks]   - Performance Monitor (priority: 50)
[CustomHooks]   - File Tracker (priority: 30)
[CustomHooks]   - Conditional Logger (priority: 20)
[CustomHooks]   - Token Monitor (priority: 10)
[CustomHooks]
[CustomHooks] --- Starting Daemon with Custom Hooks ---
[CustomHooks] [SessionLogger] ==================================================
[CustomHooks] [SessionLogger] Session Starting
[CustomHooks] [SessionLogger] Prompt: Create a TypeScript function...
[CustomHooks] [SessionLogger] Start time: 2026-02-05T...
...
[CustomHooks] [TokenMonitor] ==================================================
[CustomHooks] [TokenMonitor] Token Usage Summary
[CustomHooks] [TokenMonitor] Total input tokens: 1234
[CustomHooks] [TokenMonitor] Total output tokens: 5678
...
[CustomHooks] ✓ Custom hooks demonstrated!

5. Tool Integration

Complexity: Medium

File: examples/tool-integration.ts

Features:

  • MCP server integration
  • Custom tool registration
  • Tool filtering (allowed/blocked)
  • Tool timeout configuration
  • Retry logic with exponential backoff

Description: Shows how to integrate MCP tools, register custom tools, configure tool filtering, and handle timeouts and retries. Demonstrates both built-in tools and custom tool creation.

Run:

bun run example run tool-integration

Expected Output:

[ToolIntegration] ==================================================
[ToolIntegration] Tool Integration Demo
[ToolIntegration] ==================================================
[ToolIntegration] MCP enabled: true
[ToolIntegration] Tool timeout: 30000ms
[ToolIntegration] Max retries: 3
[ToolIntegration]
[ToolIntegration] --- Registering Custom Tools ---
[ToolIntegration] ✓ Custom tools registered:
[ToolIntegration]   - factorial: Calculate n!
[ToolIntegration]   - generatePassword: Generate secure passwords
[ToolIntegration]   - fetchWeather: Get weather information
[ToolIntegration]
[ToolIntegration] --- Testing Custom Tools ---
[ToolIntegration] ✓ factorial(5) = 120
[ToolIntegration] ✓ Generated password: aB3$xY9...
[ToolIntegration] ✓ Weather in San Francisco: {...}
...
[ToolIntegration] ✓ Tool integration demonstrated!

CLI Commands

List Examples

bun run example list

Shows all available examples with their descriptions, complexity, and features.

Get Example Info

bun run example info <name>

Shows detailed information about a specific example, including prerequisites and usage options.

Run Example

# Run with default task
bun run example run <name>

# Run with custom task
bun run example run <name> --task "your custom task"

# Run in specific directory
bun run example run <name> --work-dir /path/to/dir

# Run with custom team name
bun run example run <name> --team-name my-team

Validate Installation

bun run example validate

Checks that all required dependencies are installed.

Run All Examples

bun run example run-all

# Skip specific examples
bun run example run-all --skip simple-butler,github-bot

Tips for Customization

1. Modify Tasks

Each example accepts a custom task:

import { simpleButlerExample } from "@ebowwa/glm-daemon-examples";

await simpleButlerExample("Your custom task here", {
  workDir: process.cwd(),
  teamName: "my-custom-team",
  maxIterations: 5,
});

2. Add Custom Hooks

const config = {
  // ... other config
  hooks: {
    onSessionStart: async (state) => {
      console.log("Custom session start logic");
    },
    onPreToolUse: async (tool, args) => {
      // Custom validation
      return true;
    },
  },
};

3. Configure Tools

const config = {
  // ... other config
  tools: {
    enableMCP: true,
    allowedTools: ["Read", "Write", "Edit"],
    blockedTools: ["rm", "delete"],
    toolTimeout: 30000,
    maxRetries: 3,
  },
};

4. Add Teammates

import { Teammate } from "@ebowwa/teammates";

const teammate = await Teammate.create("my-team", {
  name: "custom-agent",
  subagentType: "general-purpose",
  prompt: "You are a specialized agent for...",
  model: "glm-4.7",
});

Architecture

Each example follows this structure:

example-name.ts
├── Example function (main entry point)
│   ├── Configuration setup
│   ├── Daemon creation
│   ├── Execution
│   └── Cleanup
└── Default run function (for CLI)

Examples use shared utilities from src/utils/:

  • logger.ts - Colored console logging
  • helpers.ts - File operations, timeouts, retries

Troubleshooting

Daemon doesn't start

Check that:

  1. GLM API credentials are configured
  2. Working directory exists
  3. Required dependencies are installed

Run bun run example validate to check.

Hooks not executing

Verify:

  1. Hook functions return true for validation hooks
  2. Hook IDs are unique
  3. Hooks are registered before daemon starts

Tools not available

Check:

  1. MCP servers are running
  2. Tools are in allowedTools list
  3. Tools are not in blockedTools list

Contributing

To add a new example:

  1. Create file in src/examples/
  2. Export example function and default run function
  3. Add to EXAMPLES object in src/cli.ts
  4. Document in this README

Example template:

/**
 * Your Example Description
 */
export async function yourExample(
  task: string,
  options: { /* options */ } = {}
): Promise<void> {
  // Implementation
}

export async function runYourExample(): Promise<void> {
  await yourExample("default task");
}

License

MIT