Skip to content

feat(plugins): add plugin system docs, SDK, and example plugins#165

Merged
ChoKhoOu merged 1 commit intomainfrom
feat/plugin-sdk
Feb 25, 2026
Merged

feat(plugins): add plugin system docs, SDK, and example plugins#165
ChoKhoOu merged 1 commit intomainfrom
feat/plugin-sdk

Conversation

@ChoKhoOu
Copy link
Copy Markdown
Owner

Summary

  • Create comprehensive plugin development guide at docs/contributing/plugin-development.md
  • Add API reference documentation at docs/contributing/api-reference.md
  • Provide 2 runnable example plugins: data source (Fear & Greed Index) and strategy template
  • Add plugin scaffolding script for quick plugin initialization

Closes #48

Test Plan

  • bun run typecheck passes
  • bun test passes
  • Example data source plugin loads correctly when placed in ~/.tino/plugins/
  • Example strategy plugin loads correctly when placed in ~/.tino/plugins/
  • Plugin scaffolding script generates valid plugin boilerplate
  • Documentation covers all ToolPlugin interface fields

🤖 Generated with Claude Code

- Plugin development guide (docs/contributing/plugin-development.md)
- API reference for ToolPlugin, ToolContext, GrpcClients (docs/contributing/api-reference.md)
- Data source example plugin: Crypto Fear & Greed Index (examples/plugins/data-source-example/)
- Strategy example plugin: Technical Indicators with RSI/SMA/EMA/Bollinger (examples/plugins/strategy-example/)
- Plugin scaffolding script (scripts/init-plugin.ts)
- 14 tests validating example plugin structure and correctness

Closes #48
@github-actions github-actions bot added type/docs Documentation type/tests Test-related changes labels Feb 25, 2026
Copy link
Copy Markdown
Owner Author

@ChoKhoOu ChoKhoOu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMPLETE

Requirement Verification: PR #165 vs Issue #48 (PRD-046: Plugin System Docs + SDK)

All 5 acceptance criteria from the PRD are fully implemented.

1. Plugin Development Guide Documentation ✅

docs/contributing/plugin-development.md (352 lines) provides a comprehensive guide covering:

  • Overview with plugin architecture diagram and lifecycle
  • Quick Start with a working hello-world example
  • Three plugin type walkthroughs: data source, strategy, exchange adapter
  • Full ToolPlugin interface documentation with field details table
  • Risk level system explanation
  • Guidance on writing effective tool descriptions
  • ToolContext usage (AbortSignal, onProgress, config, gRPC)
  • Testing instructions (manual + automated with code examples)
  • Publishing/distribution via git with naming conventions
  • Scaffolding usage reference

2. At Least 2 Example Plugins Runnable ✅

Two complete, runnable example plugins provided:

  • Data source: examples/plugins/data-source-example/index.ts (117 lines) — Crypto Fear & Greed Index from Alternative.me API, with current and history actions
  • Strategy: examples/plugins/strategy-example/index.ts (233 lines) — Technical indicators (RSI, SMA, EMA, Bollinger Bands) with correct mathematical implementations

Both plugins include comprehensive test coverage in examples/plugins/__tests__/example-plugins.test.ts (170 lines) validating:

  • Dynamic import capability
  • Plugin shape validation
  • Schema validation (valid + invalid inputs)
  • Correct calculation results (RSI bounds, SMA values, EMA values, Bollinger Band ordering)
  • Error handling for insufficient data

3. Plugin Template Scaffolding Available ✅

scripts/init-plugin.ts (188 lines) provides:

  • CLI interface: bun run scripts/init-plugin.ts <name> [--dir <path>]
  • Generates three files: index.ts (plugin template), index.test.ts (test template), README.md
  • Auto-converts kebab-case names to snake_case plugin IDs
  • Defaults to ~/.tino/plugins/<name>, supports custom directory via --dir
  • Includes --help flag with usage examples
  • Guards against overwriting existing directories

4. API Reference Covers All Plugin Interfaces ✅

docs/contributing/api-reference.md (281 lines) documents:

  • ToolPlugin interface: All 6 fields (id, domain, riskLevel, description, schema, execute) with types, conventions, and code examples
  • ToolContext interface: All 4 fields (signal, onProgress, config, grpc) with usage examples
  • GrpcClients interface: All 7 clients (trading, backtest, portfolio, chart, streaming, data, exchange)
  • definePlugin helper: Usage with and without the helper function
  • Plugin discovery details: Scan order, file resolution, deduplication rules, validation criteria
  • Built-in tool IDs: Complete reserved ID table (13 IDs) to avoid conflicts

5. Community Developer Can Independently Create Plugins ✅

The documentation provides a complete self-service workflow:

  1. Read the development guide for concepts and patterns
  2. Use scaffolding script to generate boilerplate
  3. Implement following type-safe ToolPlugin interface
  4. Test with provided test patterns (both manual and automated)
  5. Distribute via git with documented naming conventions

The guide includes three worked plugin type examples (data source, strategy, exchange adapter), making it straightforward for developers to identify which pattern fits their use case.

Technical Notes Compliance

  • Documentation at docs/contributing/plugin-development.md ✅ (matches PRD spec)
  • Example plugins at examples/plugins/ ✅ (matches PRD spec)
  • References existing definePlugin from @/domain/index.js ✅ (reuses existing interfaces per PRD)

Copy link
Copy Markdown
Owner Author

@ChoKhoOu ChoKhoOu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE

Code Review: PR #165 — Plugin System Docs, SDK, and Example Plugins

Overall Assessment

This is a well-executed PR that delivers comprehensive plugin development documentation, two functional example plugins with thorough tests, and a useful scaffolding script. The documentation is clear, well-structured, and accurately reflects the core ToolPlugin and ToolContext interfaces from src/domain/tool-plugin.ts. The example plugins demonstrate real-world patterns that plugin developers can follow.


Positive Highlights

  1. Documentation quality: Both plugin-development.md and api-reference.md are thorough and developer-friendly, with clear code examples, interface tables, and practical guidance.
  2. API reference accuracy: The documented ToolPlugin, ToolContext, and GrpcClients interfaces match the actual definitions in src/domain/tool-plugin.ts exactly.
  3. Test coverage: examples/plugins/__tests__/example-plugins.test.ts is comprehensive — tests plugin shape validation, schema parsing (positive + negative), and actual indicator calculations (RSI, SMA, EMA, Bollinger Bands).
  4. Indicator implementations: The RSI, SMA, EMA, and Bollinger Bands calculations in strategy-example/index.ts use correct mathematical formulas (Wilder's smoothing for RSI, proper EMA multiplier, population std dev for Bollinger).

Issues Found

1. Documentation claims directory-based plugin discovery that the code doesn't support (Medium)

docs/contributing/plugin-development.md shows this architecture:

~/.tino/plugins/
  my-plugin.ts              # Single-file plugin
  my-complex-plugin/
    index.ts                 # Entry point (default export)
    helpers.ts               # Internal modules

However, src/plugins/discover.ts:50-59 only scans for .ts files that are direct children of the plugin directory:

const entries = await readdir(dir, { withFileTypes: true });
const tsFiles = entries
  .filter((e) => e.isFile() && e.name.endsWith('.ts'))
  .map((e) => resolve(dir, e.name));

The e.isFile() filter excludes directories entirely, so my-complex-plugin/index.ts will never be discovered. This will mislead plugin developers.

Suggestion: Either update the docs to only document single-file plugins, or note that directory-based plugins are a planned feature (with a tracking issue).

2. Priority label inconsistency in plugin-development.md (Low)

The architecture section labels .tino/plugins/ as # Project-local plugins (higher priority), but the dedup logic in discover.ts:62-72 scans global (~/.tino/plugins/) first, and uses first-wins dedup. The API reference correctly documents this: "the first one discovered wins (global before project-local)".

The plugin-development.md comment contradicts the actual behavior and the API reference.

3. Example plugin execute signatures don't match ToolPlugin interface (Low)

The ToolPlugin interface defines:

execute: (args: unknown, ctx: ToolContext) => Promise<string>;

But the examples use different signatures:

  • data-source-example/index.ts: async (raw: unknown, ctx?: { signal?: AbortSignal; onProgress?: (msg: string) => void }) => — ctx is optional with inline type
  • strategy-example/index.ts: async (raw: unknown) => — ctx parameter is entirely omitted

While JavaScript allows calling these with extra args, this creates a confusing mismatch for developers learning the interface. The strategy example should at minimum accept _ctx to show the full contract.

4. Scaffolded README has non-portable test path (Low)

In scripts/init-plugin.ts:1355-1356, the generated README embeds the absolute targetDir path:

bun test ${targetDir}/index.test.ts

This resolves to an absolute path like /Users/name/.tino/plugins/my-plugin/index.test.ts in the generated README, which is not portable if the README is shared.

Suggestion: Use a relative path like bun test index.test.ts with a cd instruction, or bun test ~/.tino/plugins/<name>/index.test.ts.


Summary

The PR delivers all acceptance criteria from Issue #48: plugin development guide, 2 runnable example plugins with tests, scaffolding script, and API reference. The documentation is high quality and the indicator implementations are mathematically correct. The issues noted above are all non-blocking improvements that could be addressed in a follow-up. Approving as the overall quality is strong and the deliverables are solid.

@ChoKhoOu ChoKhoOu merged commit ada6b0e into main Feb 25, 2026
3 of 6 checks passed
@ChoKhoOu ChoKhoOu deleted the feat/plugin-sdk branch February 25, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/docs Documentation type/tests Test-related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant