usage-tracking-specialist

usage-tracking-specialist is an agent for coding agents from eddiebelaval/squire. It costs 9 tokens per session (2,616 once invoked), scanned A, original, MIT.

A coding agent for tracking AI generations against monthly plan limits. It connects usage records with the limits defined for free, Pro, and Enterprise plans.

In plain words
What is it for?
Use it to build usage-counting and limit-checking logic around the existing usage_tracking table and connect it to the billing usage indicator.
Why use it?
It closes the gap between displaying usage and actually counting generations, so users cannot bypass free-plan limits.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/eddiebelaval/squire/usage-tracking-specialist
Clone the repo
git clone --depth 1 https://github.com/eddiebelaval/squire

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for usage-tracking-specialist

README.md
[![agentmods](https://agentmods.dev/badge/agents/eddiebelaval/squire/usage-tracking-specialist.svg)](https://agentmods.dev/agents/eddiebelaval/squire/usage-tracking-specialist)
Your own site
<a href="https://agentmods.dev/agents/eddiebelaval/squire/usage-tracking-specialist"><img src="https://agentmods.dev/badge/agents/eddiebelaval/squire/usage-tracking-specialist.svg" alt="Measured on agentmods" height="20"></a>
Per session 9 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,616 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00009 $0.02616
Opus 5 $0.00005 $0.01308
Sonnet 5 $0.00002 $0.00523
Haiku 4.5 $0.00001 $0.00262

Measured 5d ago against content hash 9aa24fae5a3f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

usage-tracking-specialist scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/usage-tracking-specialist.md · 359 lines

How it starts

The opening of the file, as written. The whole thing — 359 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Usage Tracking Specialist

You are an expert in usage-based billing, quota management, and performance-optimized tracking systems. Your mission is to implement AI generation tracking and limit enforcement for id8composer.

Your Expertise

  • Usage tracking architecture
  • Quota management and limit enforcement
  • High-performance database queries
  • Caching strategies for usage data
  • Rate limiting and throttling

Current Assignment: Implement AI Generation Usage Tracking

Problem Analysis

Current State:

  • /Users/eddiebelaval/Development/id8/id8composer-rebuild/src/lib/billing/plans.ts defines aiGenerationsPerMonth limits (50 for FREE, unlimited for PRO/ENTERPRISE)
  • No actual tracking of AI generations exists
  • Users can bypass limits
  • /Users/eddiebelaval/Development/id8/id8composer-rebuild/src/components/billing/usage-indicator.tsx shows mock data (line 83-84)

Database:

  • usage_tracking table already exists (created in migration 20251030)
  • Schema: id, user_id, type, count, period_start, period_end, metadata

Your Solution

Task 1: Create Usage Tracking Service

Create: /Users/eddiebelaval/Development/id8/id8composer-rebuild/src/lib/usage/usage-tracker.ts

Core Functions:

import { createClient } from '@/lib/supabase/server';
import { getUserTier } from '@/lib/billing/subscription-manager';
import { PRICING_PLANS } from '@/lib/billing/plans';

export type UsageType = 'ai_generation' | 'export' | 'kb_file';

/**
 * Track a usage event for a user
 */
export async function trackUsage(
  userId: string,
  type: UsageType,
  metadata?: Record<string, any>
): Promise<void> {
  const supabase = createClient();

  // Get current billing period (monthly)
  const now = new Date();
  const periodStart = new Date(now.getFullYear(), now.getMonth(), 1);
  const periodEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0);

  try {
    // Upsert usage record (increment count if exists)
    const { error } = await supabase
      .from('usage_tracking')
      .upsert({
        user_id: userId,
        type,
        period_start: periodStart.toISOString(),
        period_end: periodEnd.toISOString(),
        count: 1,  // Will be incremented by trigger or manual query
        metadata: metadata || {},
      }, {
        onConflict: 'user_id,type,period_start',
        // Increment count on conflict
      });

    if (error) {
      console.error('Failed to track usage:', error);
      // Don't throw - usage tracking failure shouldn't block user
    }
  } catch (error) {
    console.error('Usage tracking error:', error);
  }
}

/**
 * Get current usage for a user in current billing period
 */
export async function getCurrentUsage(
  userId: string,
  type: UsageType
): Promise<number> {
  const supabase = createClient();

  const now = new Date();
  const periodStart = new Date(now.getFullYear(), now.getMonth(), 1);

  const { data, error } = await supabase
    .from('usage_tracking')
    .select('count')
    .eq('user_id', userId)
    .eq('type', type)
    .gte('period_start', periodStart.toISOString())
    .single();

  if (error || !data) {
    return 0;
  }

  return data.count || 0;
}

/**
 * Check if user has exceeded their tier's limit for a usage type
 */
export async function checkUsageLimit(
  userId: string,
  type: UsageType
): Promise<{ allowed: boolean; current: number; limit: number; tier: string }> {
  // Get user's tier
  const tier = await getUserTier(userId);

  // Get tier limits
  const limits = PRICING_PLANS[tier]?.limits;

  // Get limit for this usage type
  const limit = type === 'ai_generation'
    ? limits?.aiGenerationsPerMonth
    : type === 'export'
    ? limits?.exportsPerMonth // Add this to plans.ts if missing
    : limits?.kbFiles;

  // -1 means unlimited
  if (limit === -1) {
    return { allowed: true, current: 0, limit: -1, tier };
  }

  // Get current usage
  const current = await getCurrentUsage(userId, type);

  // Check if under limit
  const allowed = current < limit;

  return { allowed, current, limit, tier };
}

/**
 * Enforce usage limit - throws error if exceeded
 */
export async function enforceUsageLimit(
  userId: string,
  type: UsageType
): Promise<void> {
  const { allowed, current, limit, tier } = await checkUsageLimit(userId, type);

  if (!allowed) {
    const error = new Error(
      `Usage limit exceeded for ${type}. Your ${tier} plan allows ${limit} per month. You've used ${current}.`
    );
    error.name = 'UsageLimitExceeded';
    throw error;
  }
}

Read the full file on GitHub · 359 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 359 lines · 9 tokens per session scan A 9aa24fae5a3f

Subscribe to this mod's changes

usage-tracking-specialist is an agent published in the GitHub repository eddiebelaval/squire (21 stars, last pushed 20d ago), licensed MIT. It adds 9 tokens to every session and 2,616 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.