Skip to content

Fix finam-trade plugin compliance with teleton-agent plugin loader#169

Merged
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-168-6153bde12d68
Apr 20, 2026
Merged

Fix finam-trade plugin compliance with teleton-agent plugin loader#169
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-168-6153bde12d68

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Apr 20, 2026

Fixes #168.

Root Cause Analysis

After reviewing the teleton-agent source (src/agent/tools/plugin-validator.ts, src/agent/tools/plugin-loader.ts, src/webui/services/marketplace.ts), the following issues were found that prevented the plugin from installing or working correctly:

Issues Fixed

1. Manifest name failed Zod validation

The inline manifest export in index.js had name: "Finam Trade Pro". The agent's ManifestSchema validates name against /^[a-z0-9][a-z0-9-]*$/ — spaces and uppercase letters fail. Result: the manifest was silently discarded, the plugin loaded with fallback metadata, and the Zod validation warning was logged.

Fix: Changed name to "finam-trade" (the plugin folder ID).

2. Manifest author failed Zod validation

author: { name: "Teleton Community", url: "..." } is an object; the schema requires z.string().max(128). Same silent discard.

Fix: Changed to author: "Teleton Community".

3. Manifest contained non-schema fields

id, license, entry, teleton, permissions, tags, tools, repository, funding are not part of ManifestSchema. They're stripped by Zod's default behavior but bloated the inline manifest unnecessarily.

Fix: Removed all fields not in ManifestSchema from the inline export. The manifest.json file retains full metadata for the registry/marketplace.

4. start() crashed with TypeError when called by the agent

The agent's adaptPlugin wraps start(ctx) and passes an EnhancedPluginContext that has { bridge, db, config, pluginConfig, log } — no sdk field. The plugin called getRuntime(ctx?.sdk)getRuntime(undefined). In getRuntime, null?.sdk === undefined was true (wrong guard), returning null, then null.config threw a TypeError. This was caught by the loader wrapper and logged as an error, but the start function never completed.

Fix:

  • Use activeRuntime ?? getRuntime(ctx?.sdk) — reuse the runtime already built by tools(sdk), which is called before start.
  • Use ctx?.log (the prefixed logger from the loader) for log calls.
  • Guard getRuntime with activeRuntime && instead of activeRuntime?. to prevent false equality on null.

5. gRPC packages loaded eagerly at module import time

grpc.js imported @grpc/grpc-js and @grpc/proto-loader as top-level static imports. If the plugin's node_modules were not present (e.g. during local validation without running npm ci first), the entire module failed to import. Since gRPC is only needed when enable_grpc_jwt_renewal: true (off by default), the packages should be resolved lazily.

Fix: Replaced static imports with lazy createRequire() calls inside property getters on FinamGrpcJwtRenewal. The packages are only loaded when the gRPC stream is actually started.

Verification

node --test plugins/finam-trade/tests/*.test.js
→ 16 passed, 0 failed

node scripts/validate-plugins.mjs
→ [OK] finam-trade: 27 tool(s) validated

npm test
→ 398 passed, 0 failed

npm run lint
→ 0 errors (33 pre-existing warnings in other plugins, unchanged)

konard added 2 commits April 20, 2026 11:24
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#168
- manifest export: name changed from "Finam Trade Pro" to "finam-trade" to
  pass Zod /^[a-z0-9][a-z0-9-]*$/ validation in plugin-validator.ts
- manifest export: author changed from object to string as required by
  ManifestSchema (z.string().max(128))
- manifest export: stripped fields not in ManifestSchema (id, license,
  entry, teleton, permissions, tags, tools, repository, funding) to keep
  the inline manifest minimal and schema-compliant
- start(): use activeRuntime directly instead of getRuntime(ctx?.sdk),
  since the PluginContext passed by the agent has no sdk field; also use
  ctx.log (the prefixed logger provided by the loader) for log calls
- getRuntime(): guard against null activeRuntime before identity check to
  prevent a TypeError when sdk is undefined
- grpc.js: replace eager top-level import of @grpc/grpc-js and
  @grpc/proto-loader with lazy createRequire() calls via property getters,
  so the module loads without the optional gRPC packages installed and
  only resolves them when the renewal stream is actually started

All 16 plugin tests pass; validate-plugins reports 27 tools, 0 errors.
@konard konard changed the title [WIP] Check the Finam Trade plugin Fix finam-trade plugin compliance with teleton-agent plugin loader Apr 20, 2026
@konard konard marked this pull request as ready for review April 20, 2026 11:40
@konard
Copy link
Copy Markdown
Author

konard commented Apr 20, 2026

Solution summary

All done. Here's a summary of what was found and fixed:

Root causes identified and fixed

By reading the teleton-agent source directly (plugin-validator.ts, plugin-loader.ts, marketplace.ts), four concrete bugs were found in the finam-trade plugin:

  1. manifest.name failed Zod validation"Finam Trade Pro" doesn't match /^[a-z0-9][a-z0-9-]*$/. The agent silently discarded the entire inline manifest. Fixed to "finam-trade".

  2. manifest.author failed Zod validation — an object was provided; the schema requires a plain string. Fixed to "Teleton Community".

  3. start() crashed with TypeError — the agent's EnhancedPluginContext has no sdk field. Calling getRuntime(ctx?.sdk)getRuntime(undefined) on a null activeRuntime returned null due to a faulty ?. guard, then null.config threw. Fixed by reusing activeRuntime (set during tools() which runs before start()) and correcting the null guard.

  4. gRPC packages loaded eagerly — top-level import grpc from "@grpc/grpc-js" failed in environments without node_modules installed (e.g. local npm run validate). Fixed with lazy createRequire() in property getters — packages are only resolved when the gRPC renewal stream is actually started.

All 16 plugin tests pass, validate-plugins reports 27 tools with 0 errors, full 398-test suite passes, all CI checks green: #169


This summary was automatically extracted from the AI working session output.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 20, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $2.876294

📊 Context and tokens usage:

Claude Sonnet 4.6:

  • 100.1K / 1M (10%) input tokens, 22.9K / 64K (36%) output tokens

Total: (93.5K + 6.9M cached) input tokens, 22.9K output tokens, $2.777573 cost

Claude Haiku 4.5:

  • 2.8K / 64K (4%) output tokens

Total: (46.8K + 261.4K cached) input tokens, 2.8K output tokens, $0.098721 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Main model: Claude Sonnet 4.6 (claude-sonnet-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (2847KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 20, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@xlabtg xlabtg merged commit edb950a into xlabtg:main Apr 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check the Finam Trade plugin

2 participants