@trinoris/agent-sdk

中文文档
0.3.0发布于 2026/11/03Apache-2.0TypeScriptESM + CJS

Programmatic coordination API — scope locks, handoff claims, stale-lock recovery

原始使用文档

@trinoris/agent-sdk

Filesystem lock engine for the Trinoris multi-agent coordination protocol — for agents and tools that need the protocol in-process rather than through the CLI.

import { acquire, inspect, release, breakLock, claim } from '@trinoris/agent-sdk';

const paths = { root: 'coordination' };
const r = acquire(paths, 'engine', { agent_instance: 'a1', agent_class: 'claude' }, 15);
if (!r.ok) { /* held by a peer — do not spin; pick other work or write a handoff */ }

Why these primitives and not the obvious ones

The engine uses mkdir as its only test-and-set, because it is the only primitive verified atomic across the target filesystems — including WSL2's 9p bridge to a Windows drive. Two designs that look correct were disproved by racing them:

  • mv -n is not an atomic claim. It is stat-then-rename in userspace and returns success when it declines, so two racing agents both conclude they claimed the same handoff. Measured: 2 claimers from 8 racers, 21 failed trials in 100.
  • Breaking a stale lock by delete-then-recreate double-breaks — 25/60 failures at 8 racers, 59/60 at 32 — because once the first breaker re-creates the lock the name is occupied again and a later breaker evicts the new holder. Rename-aside alone does not fix it. Breaking is therefore gated behind an atomic <scope>.breaking token.

flock is deliberately not used: advisory locks over 9p are unreliable, and flock releases on process exit — wrong for agents that work in discrete tool calls.

Lock presence is not ownership. A slow agent whose lease expired and was evicted finds the directory exactly as it left it. Only holder.json's agent_instance is authority, so re-confirm with isHolder() immediately before each batch of writes.

License

Apache-2.0 — see LICENSE.

版本与发布记录

@trinoris/agent-sdk 共发布 4 个版本,首次发布于 2026/10/25;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.3.0latest2026/11/03今天
0.2.02026/10/277 天前
0.1.02026/10/258 天前
0.0.0-stage2026/10/258 天前

关于 @trinoris/agent-sdk 的常见问题

@trinoris/agent-sdk 是什么?

编程协调API范围锁、切换声明、旧锁恢复

如何安装 @trinoris/agent-sdk?

在项目目录运行 npm install @trinoris/agent-sdk,或使用 pnpm add / yarn add / bun add。

@trinoris/agent-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@trinoris/agent-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@trinoris/agent-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@trinoris/agent-sdk 可以商用吗?

@trinoris/agent-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@trinoris/agent-sdk 还在维护吗?

最新版本 0.3.0 发布于 2026/11/03(今天);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/10/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。