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

@zhin.js/tool

v1.0.13

Published

Convention-based Agent Tool Feature for Zhin Plugin Runtime

Downloads

3,308

Readme

@zhin.js/tool

下一代 Agent Tool Feature。它从 Plugin 或项目根的 tools/<name>.ts 发现 defineAgentTool() definition,并投影为 owner-aware ToolIndex

目录与身份

tools/
├── get-weather.ts
└── search.ts

Tool 目录只允许一级 .ts 文件。文件 basename 是 owner 内部使用的 local name;Agent turn 对模型发布 owner-qualified name。Root 的 get-weather 仍是 get-weather,child root/maps 的同名 Tool 是 maps__get-weather。嵌套目录、TSX 和旧 agent/tools 不属于绿地接口。

定义 Tool

import { defineAgentTool } from '@zhin.js/tool';
import { weatherClientToken } from '../plugin.js';

export default defineAgentTool<{ city: string }>({
  description: 'Query current weather',
  inputSchema: {
    type: 'object',
    properties: { city: { type: 'string' } },
    required: ['city'],
  },
  approval: 'never',
  execute(input, context) {
    return context.use(weatherClientToken).get(input.city, context.config);
  },
});

defineAgentTool() 只校验并冻结声明,不定位当前 Plugin、不注册能力。approval 支持 neveron-riskoncealways,默认 on-risk;批准状态和判定由 Turn Tool Runtime 持有,本包只保留声明。

inputSchema 保持 provider-neutral,可以是 JSON Schema 或模型 adapter 能理解的其它只读描述。本包不引入 Zod,也不在 ToolIndex 重复实现 schema validator。

单文件插件可用 setup({ addTool }) 注册 defineAgentTool(...)。Tool Feature 必须已在 插件 manifest 中挂载;注册结果与 tools/ 目录进入同一 ToolIndex。

Owner 解析

ToolIndex.execute(requester, name, input, invocation) 从 requester 向 Root 查找最近 definition。invocation 必须包含所属 Turn 的 AbortSignal、trace/turn/session identity、principal 与不可变 policy(permissions / unattended / network authority);这些字段会连同声明 owner 的 config/resource 组成 ToolExecutionContext。网络 transport 必须读取该 context 的 authority,不能读取模块全局或自行猜测执行域。child 可覆盖继承的 Root Tool。

list() 返回全树 qualified descriptors;visible(owner) 返回该 owner 可见且完成 override 后的 local descriptors。

HMR

Tool 文件变化只 reload 对应 Slot,再重建 generation projection。正在执行的 Agent turn 持有旧 snapshot lease,继续使用旧 Tool;新 turn 才看到新 definition。

依赖

仅依赖 Next Kernel 与 Feature Kit。AI SDK、模型 provider、approval UI、schema compiler 均不在生产依赖中。

验证

pnpm --filter @zhin.js/tool test
pnpm --filter @zhin.js/tool build