返回目录
模型与 MCP 插件

tokenomics-plugin

z99wE/tokenomics-plugin

Token- and context-aware efficiency layer for AI agents — compresses prose, minimizes code via YAGNI, tracks savings. DeepSeek Harness (DSH), Claude Code, Cursor, Codex & Hermes.

Stars
0
Forks
0
Issues
2
更新
5 天前

PROJECT TOPICS

项目标签

INSTALL REFERENCE

安装参考

未验证
dsh plugin --profile web add github:z99wE/tokenomics-plugin

该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。

PROJECT README

README

Tokenomics

Tokenomics

Small mouth, big brain. Minimum code, maximum impact.
Agentic efficiency layer for AI agents — compresses prose, minimizes code, tracks savings.

License: MIT Python 3.9+ npm: @soch-tokenomics/tokenomics-dsh-plugin DSH Plugin Tests: 135 passing Claude Code Cursor Antigravity Codex Hermes


Tokenomics

Tokenomics is an agentic efficiency layer that sits between your AI agent and its output. It compresses agent prose, minimizes code generation, tracks token savings, and learns from your behavior — all while keeping safety and authorization at the forefront.

Tokenomics is inspired by the concepts behind caveman (prose compression) and ponytail (code minimization), but it is engineered independently as its own system with context awareness, learned compression, gamification, subagent propagation, token budgeting, and cross-agent memory.


What Makes Tokenomics Different

Capability Caveman Ponytail Tokenomics v2.3
Compresses prose ✅ ❌ ✅
Minimizes code ❌ ✅ ✅
Context-aware (code vs docs vs secrets) ❌ ❌ ✅
Learned compression (adapts to your reverts) ❌ ❌ ✅
Selective domain rules ❌ ❌ ✅
Token budget with 80%/100% alerts ❌ ❌ ✅
Project-type smart defaults ❌ ❌ ✅
Gamification (levels, XP, streaks) ❌ ❌ ✅
Subagent propagation ❌ ❌ ✅
Preview widget ❌ ❌ ✅
No injection hook N/A N/A ✅
135 test cases ❌ ❌ ✅

Tokenomics is not a wrapper around either tool. It is a separate engineering project that draws inspiration from their concepts and builds its own architecture on top.


Architecture

flowchart TD
    A([User Request]) --> B{Tokenomics<br/>Enabled?}
    B -->|No| R[Normal Output<br/>No Compression]
    B -->|Yes| D[Context Detection<br/>Code · Docs · Config · Secrets · SQL · Prose]

    D --> E{Security<br/>Sensitive?}
    E -->|Yes| F[Skip Compression<br/>Safety First]
    E -->|No| G[Safe to Compress]

    F --> D
    G --> H[Selective Domain Rules<br/>Never · Always · Force Preset]
    H --> I[Learned Compression<br/>Adapts to Revert Patterns]
    I --> J[Caveman-Inspired<br/>Prose Compression]
    J --> K[Ponytail-Inspired<br/>Code Minimization]
    K --> L[Token Savings<br/>Estimation]

    L --> M[Token Budget Check<br/>80% / 100% Alerts]
    M --> N[Gamification<br/>XP · Level · Streak · Achievements]
    N --> O[Preview Widget<br/>HTML Dashboard]
    O --> P[Subagent Propagation<br/>delegate_task Context]
    P --> Q([Output + Savings Footer])

    classDef entry fill:#dbeafe,stroke:#1e40af,stroke-width:2px,color:#1e3a8a
    classDef gate fill:#fef3c7,stroke:#92400e,stroke-width:2px,color:#78350f
    classDef safety fill:#fee2e2,stroke:#991b1b,stroke-width:2px,color:#7f1d1d
    classDef compress fill:#dcfce7,stroke:#166534,stroke-width:2px,color:#14532d
    classDef feature fill:#ede9fe,stroke:#5b21b6,stroke-width:2px,color:#4c1d95
    classDef done fill:#d1fae5,stroke:#065f46,stroke-width:2px,color:#064e3b
    classDef skip fill:#fecaca,stroke:#b91c1c,stroke-width:2px,color:#7f1d1d

    class A,Q entry
    class B,D,E gate
    class F safety
    class G,H,I,J,K,L compress
    class M,N,O,P feature
    class Q done
    class F skip
    class R skip

Ponytail-Inspired Decision Ladder

Before writing any code, climb this ladder and stop at the first rung that holds:

flowchart LR
    R1["1 · Does it need to exist?<br/>(YAGNI — skip it)"] --> R2["2 · Already in codebase?<br/>(reuse it)"]
    R2 --> R3["3 · Stdlib does it?<br/>(use it)"]
    R3 --> R4["4 · Native platform feature?<br/>(use it)"]
    R4 --> R5["5 · Installed dependency?<br/>(use it)"]
    R5 --> R6["6 · Can it be one line?<br/>(write one line)"]
    R6 --> R7["7 · Minimum code<br/>that works"]

    classDef ask fill:#fee2e2,stroke:#991b1b,stroke-width:2px,color:#7f1d1d
    classDef reuse fill:#fef3c7,stroke:#92400e,stroke-width:2px,color:#78350f
    classDef stdlib fill:#dcfce7,stroke:#166534,stroke-width:2px,color:#14532d
    classDef native fill:#dbeafe,stroke:#1e40af,stroke-width:2px,color:#1e3a8a
    classDef dep fill:#ede9fe,stroke:#5b21b6,stroke-width:2px,color:#4c1d95
    classDef oneline fill:#fae8ff,stroke:#86198f,stroke-width:2px,color:#701a75
    classDef write fill:#d1fae5,stroke:#065f46,stroke-width:2px,color:#064e3b

    class R1 ask
    class R2 reuse
    class R3 stdlib
    class R4 native
    class R5 dep
    class R6 oneline
    class R7 write

Subagent Propagation

When you delegate work to a subagent, Tokenomics context (compression rules, learned patterns, safety gates) travels with it.

sequenceDiagram
    autonumber
    participant U as User
    participant A as Agent
    participant S as Subagent

    U->>A: delegate_task(task)
    Note over A: Tokenomics enabled → inject<br/>context + YAGNI guidance
    A->>S: task + tokenomics note
    S->>S: Compress prose · Apply YAGNI ladder · Track savings
    S->>A: Compressed output + savings footer
    A->>U: Aggregated result

Context-Aware Compression

Tokenomics doesn't blindly compress everything. It first detects what kind of content it's looking at:

Content Type Strategy Example
Code Minimal — preserve structure, imports, comments Only remove truly redundant patterns
Docs Moderate — keep structure, cut filler Remove "basically", "actually", etc.
Commits Aggressive — conventional commit style "Fix bug" not "Fix the bug in the login function"
Secrets / Auth Never compress API keys, passwords, tokens left untouched
SQL Light — preserve query structure Remove whitespace, keep semantics
Prose Standard — drop articles, filler, hedging Remove "just", "really", "basically"

Security-sensitive content (API keys, passwords, crypto keys) is never compressed or modified.


Core Features

Caveman-Inspired Prose Compression

Drops articles (a/an/the), filler words (just/really/basically), pleasantries (sure/certainly), and hedging (maybe/I think). Keeps code blocks, technical terms, API names, and error strings exact.

Ponytail-Inspired Code Minimization

Before writing code, climbs the YAGNI ladder:

  1. Does this need to exist? → Skip it
  2. Already in codebase? → Reuse it
  3. Stdlib does it? → Use it
  4. Native platform feature? → Use it
  5. Installed dependency? → Use it
  6. Can it be one line? → Write one line
  7. Only then: minimum code that works

Token Savings Estimation

Real token counting via tiktoken (cl100k_base) with character-count fallback. Every compressed output shows estimated tokens saved.

Token Budget with Alerts

Set a daily token budget and get notified at 80% and 100% usage:

tokenomics budget set 5000      # Set daily limit
tokenomics budget record 4200   # Record tokens used
# ⚠️ Token budget alert: 4200/5000 used (84%)

Gamification

Levels, XP, streaks, and achievements (First Savings, Token Hoarder, Token Miser, Lazy Senior Dev, YAGNI Master, Three-Day Streak, Week Warrior) give you feedback on your token efficiency.

Selective Domain Compression

Never compress security/auth/crypto content. Always compress docs/changelog. Force specific presets per domain. Learned compression adapts based on what you revert vs accept.

Auto-Learn

Tokenomics tracks which compression patterns you revert vs accept, and automatically adapts future compression decisions.

Project-Type Smart Defaults

Set your project type (web/cli/library/api) for smart default domain rules.


Subagent Propagation

When you delegate a task to a subagent, Tokenomics context is automatically applied — the compression rules, learned patterns, and safety guidelines all carry over.


Hermes Plugin: 11 Tools, 5 Hooks

Tools: | Tool | What it does | |------|-----------| | tokenomics.enable | Activate compression + savings display | | tokenomics.disable | Deactivate — no compression, no footer | | tokenomics.status | Cumulative savings, level, streak, achievements | | tokenomics.estimate | Preview savings for specific text | | tokenomics.review | Ponytail-inspired over-engineering review | | tokenomics.audit | Full audit with recommendations | | tokenomics.domain | Manage selective compression rules | | tokenomics.achievements | Check newly unlocked achievements | | tokenomics.budget | Daily token budget + 80%/100% alerts | | tokenomics.project | Project type for smart defaults | | tokenomics.learn | Auto-learn from user revert patterns |

Hooks: | Hook | What it does | |------|-----------| | pre_tool_call | Compresses string arguments before tool execution | | post_tool_call | Compresses tool result output + tracks savings | | on_session_start | Writes preview widget | | on_session_end | Final state save + preview refresh | | delegate_task | Propagates tokenomics context to subagents |

No injection hook. The pre_llm_call hook was removed in v2.1.0. Tokenomics never prepends hidden instructions to your LLM prompts.


CLI Reference

tokenomics <command> [options]

Commands:
  enable      Activate compression + savings display
  disable     Deactivate — no compression, no footer
  status      Show cumulative savings and compression ratio
  estimate    Preview token savings for specific text
  review      Ponytail-style over-engineering review of code
  audit       Full audit: savings, ratio, recommendations
  ladder      Show ponytail YAGNI decision ladder
  logo        Show ASCII logo
  domain      Manage selective compression rules
  achievements Check for newly unlocked achievements
  budget      Daily token budget + alerts
  record      Record tokens consumed and check budget
  project     Set project type for smart defaults
  learn       Toggle auto-learn from user reverts
  defaults    Toggle smart default suggestions

Examples:

tokenomics enable
tokenomics estimate "This is a really simple test."
tokenomics review --code "class UserFactoryManagerServiceController: ..."
tokenomics budget set 5000
tokenomics budget record 4200
tokenomics project web
tokenomics learn true
tokenomics disable

Installation

Option 1: pip (recommended)

pip install tokenomics
tokenomics enable

Option 2: With real tokenizer

pip install "tokenomics[tiktoken]"
tokenomics enable

Option 3: From source

git clone https://github.com/z99wE/tokenomics-plugin.git
cd tokenomics
pip install -e .
tokenomics enable

Option 4: Manual skill copy

Copy SKILL.md to your agent's skills directory:

Platform Path
Claude Code ~/.claude/skills/tokenomics/SKILL.md
Cursor ~/.cursor/skills/tokenomics/SKILL.md
Antigravity ~/.antigravity/skills/tokenomics/SKILL.md
Codex ~/.agents/skills/tokenomics/SKILL.md
OpenAI Codex ~/.codex/skills/tokenomics/SKILL.md
Hermes ~/.hermes/skills/tokenomics/SKILL.md + plugin install

All platforms use the same open SKILL.md standard (agentskills.io).

Option 5: DeepSeek Harness (DSH Plugin)

Install directly from the npm registry for in-app integration:

dsh plugin --profile web add @soch-tokenomics/tokenomics-dsh-plugin

Or install from source:

dsh plugin --profile web add github:z99wE/tokenomics-plugin

Testing

Tokenomics has 135 test cases covering core compression, state management, Hermes plugin handlers/hooks, and CLI commands:

python -m unittest tokenomics.tests.test_core tokenomics.tests.test_hermes tokenomics.tests.test_cli -v

All 135 tests pass. The project uses ruff for linting:

ruff check .

License

MIT License. See LICENSE for details.


Inspiration & Attribution

Tokenomics is inspired by the concepts behind:

Tokenomics is engineered independently as its own project. It reimplements these concepts with its own architecture, context detection, learned compression, gamification, token budgeting, and agentic features. All code in this repository is original work by the Tokenomics contributors.


Links


DeepSeek Harness (DSH Plugin)

Tokenomics is available as a community plugin for DeepSeek Harness (DSH).

Install

Install via the DSH CLI (web profile):

dsh plugin --profile web add @soch-tokenomics/tokenomics-dsh-plugin

Or install directly from source:

dsh plugin --profile web add github:z99wE/tokenomics-plugin

Registered Tools

When mounted in DeepSeek Harness, Tokenomics registers the following tools into the DSH environment:

Tool Description
tokenomics_status View current token savings, streak, XP, and efficiency achievements.
tokenomics_estimate Calculate estimated token savings for any prompt or text.
tokenomics_review Run an anti-overengineering YAGNI code review on a code snippet.

Privacy & Trust

  • 100% Local: Zero network requests, zero telemetry, and zero tracking.
  • Safe & Non-Destructive: Strictly avoids altering secrets, tokens, credentials, and crypto/SQL code.
  • Lightweight: Requires no extra services beyond the companion CLI (pip install tokenomics).

CLASSIFICATION EVIDENCE

分类依据

项目类型插件
功能分类模型与 MCP
规则置信度高

系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek、deepseek-harness。