@dougbots/avenor-core

中文文档
0.26.0发布于 2026/11/13TypeScriptES Module构建来源已验证近 30 天下载 3350

Control socket client, supervisor lifecycle, and tool implementations for the avenor agent runner.

原始使用文档
文档目录16 节
  1. Binary discovery
  2. Core concepts
  3. Client
  4. Supervisor
  5. Tools
  6. spawnTool
  7. Roster selection
  8. statusTool
  9. resultTool
  10. answerPermissionTool
  11. messageTool
  12. peersTool
  13. eventsTool
  14. shutdownTool
  15. Quick start
  16. Exports

@dougbots/avenor-core

Control socket client, supervisor lifecycle, and tool implementations for the avenor agent runner.

Avenor is a CLI daemon that runs AI agent sessions. This package manages that daemon's process and provides typed wrappers around its JSON-RPC control socket — the interface used to spawn runs, check status, follow up on sessions, and shut everything down cleanly.

It is a private workspace package consumed by @dougbots/avenor-mcp and @dougbots/avenor-opencode. It is not published to npm.

Binary discovery

The avenor binary is located through a three-step fallback:

  1. AVENOR_BIN environment variable
  2. avenor on PATH (via which avenor)
  3. ~/.botfiles/bin/avenor

The exported helper findAvenorBinary() runs this discovery. The Supervisor calls it automatically if no explicit binaryPath is given.

Core concepts

Client

dial(socketPath) connects to an avenor control socket and returns a Client. The Client speaks JSON-RPC over a Unix socket and exposes methods like spawn(), status(), list(), shutdown(), answerPermission(), prompt(), and cancel(). It also provides an async iterable events() for streaming runtime events.

Supervisor

Supervisor.get() is a singleton that ensures one avenor stable process is running, bound to a per-PID control socket. It starts the binary with avenor stable --control-socket <path> --idle-timeout 30m, retries the socket dial until it's ready, and registers signal handlers to clean up on exit.

Spawned runs are tracked in-memory (label → runtime ID, sentinel path, event log path) so follow-ups and status checks can resolve the right runtime.

Tools

The package exports six self-contained tool functions. Each is designed for embedding in MCP servers or CLI handlers.

spawnTool

Starts a new agent run.

import { spawnTool } from '@dougbots/avenor-core'

const result = await spawnTool({
  agent: 'codex',
  prompt: 'Write a function to reverse a string',
  label: 'reverse-string',
  model: 'claude-sonnet-4',
  backend: 'opencode-http',
  serverUrl: 'http://127.0.0.1:4096',
})
// { run_id: '...', label: 'reverse-string', supervisor_id: '/path/to/socket' }

Accepts agent, prompt, promptFile, label, dir, timeout, model, thinking, backend, rosterFile, rosterEntry, serverUrl, sessionId, and supervisorId (to target a specific socket).

Roster selection

rosterFile is the path to a top-level JSON roster map and rosterEntry is the key selected from it. Each entry must contain backend and at least one of agent or model:

{
  "planner": {
    "backend": "opencode-acp",
    "model": "provider/planner"
  }
}

A direct roster spawn forwards both selectors and must not also provide agent, model, or backend. Direct mode without a roster allows each of those identity fields to be omitted independently, including a backend-only request; the selected runtime supplies defaults for omitted values. thinking is run-level, not a roster field, and is checked against the effective backend. The shared selector validation rejects missing selector pairs, mixed direct/roster fields, and unknown selector keys. Roster-file loading rejects deferred entry fields such as system; thinking remains a valid run-level option but is never read from a roster entry.

await spawnTool({
  prompt: 'Analyze the repository',
  dir: '/repo',
  rosterFile: '/repo/roster.json',
  rosterEntry: 'planner',
})

Roster phase selection is resolved by Avenor's Go workflow runners. A roster entry may override backend/agent/model per phase. CLI workflow fallback and nested roster inheritance are CLI-only; stable nesting keeps its existing behavior. A resumed session must use the same effective backend as the original session.

statusTool

Reports status for one or all runs. When runId is omitted it lists every run across the supervisor.

import { statusTool } from '@dougbots/avenor-core'

const status = await statusTool({ runId: 'reverse-string', view: 'lifecycle' })
// { run_id: 'reverse-string', label: 'reverse-string', status: 'running', ... }

Status values: running, waiting, done, failed, timeout, killed, and unknown when the supervisor reports no status or one this package does not recognize. done, failed, timeout and killed are terminal; unknown is not. If a permission request is pending, the result includes pending_permission with available options. The lifecycle view omits final output and diagnostic metadata; full remains the default for compatibility.

resultTool

Waits for one run to finish and returns its complete final output without transcript or event details.

import { resultTool } from '@dougbots/avenor-core'

const result = await resultTool({ runId: 'reverse-string', timeout: '5m' })
// { run_id: 'reverse-string', status: 'done', ready: true, output: '...' }

Set wait: false for a non-blocking availability check. A pending permission returns immediately; an expired result wait returns ready: false and timed_out: true without stopping the run.

answerPermissionTool

Answers a pending permission request for a run. If requestId is omitted, it looks up the currently pending request automatically.

import { answerPermissionTool } from '@dougbots/avenor-core'

await answerPermissionTool({ runId: 'my-run', optionId: 'allow-once' })
// { ok: true }

messageTool

One tool for every message between runs: tell, ask, reply, resume, withdraw and control_reply. It takes a bound MessageProvider, which supplies who the call speaks as, how a target resolves, and only the actions that surface can perform.

import { messageTool } from '@dougbots/avenor-core'

await messageTool({ action: 'resume', target: 'reverse-string', message: 'Now optimize it for speed' }, provider)
// { action: 'resume', outcome: 'resumed', text: '...', runId: '...', label: '...' }

peersTool

Lists connected runs, renames a run's display label, or reads a peer's last agent message. Like messageTool, it reads through the bound provider.

import { peersTool } from '@dougbots/avenor-core'

const result = await peersTool({ action: 'list' }, provider)
console.log(result.text)

eventsTool

Reads recent events from a run's on-disk event log. Optionally filters by event type and limits the count (default 50, max 1000).

import { eventsTool } from '@dougbots/avenor-core'

const events = await eventsTool({ runId: 'my-run', types: ['tool_use', 'error'], limit: 20 })

⚠️ Only supported through the singleton Supervisor — passing an explicit supervisorId will throw.

shutdownTool

Shuts down the avenor daemon. Pass force: true for an immediate kill instead of graceful termination. Cleans up sentinel files and event logs for tracked runs.

import { shutdownTool } from '@dougbots/avenor-core'

const result = await shutdownTool({ force: false })
// { ok: true, cleaned_up: ['/path/to/sentinel.done', ...] }

Quick start

import { Supervisor, resultTool, spawnTool, shutdownTool } from '@dougbots/avenor-core'

// 1. The supervisor auto-starts avenor. Call get() early — it's a singleton.
const sup = await Supervisor.get()

// 2. Spawn a run
const { run_id } = await spawnTool({
  agent: 'codex',
  prompt: 'Review src/app.ts for security issues',
  label: 'security-review',
})

// 3. Wait for the complete final output
const result = await resultTool({ runId: run_id })
console.log(result) // { run_id, label, status: 'done', ready: true, output: '...' }

// 4. Clean up
await shutdownTool()

Exports

ExportKindDescription
dialfunctionConnect to a control socket, returning a Client
ClientclassJSON-RPC client for the avenor daemon
SupervisorclassSingleton avenor process lifecycle manager
findAvenorBinaryfunctionDiscover the avenor binary path
spawnToolfunctionStart a new agent run
statusToolfunctionQuery run lifecycle status (single or all)
resultToolfunctionWait for and retrieve one run's complete final output
answerPermissionToolfunctionAnswer a pending permission request
peersToolfunctionList runs, rename a run's display label, or read a peer's last message
messageToolfunctionTell, ask, reply, resume, withdraw or answer a control message
eventsToolfunctionRead recent events from a run's event log
shutdownToolfunctionStop the avenor daemon and clean up

版本与发布记录

@dougbots/avenor-core 共发布 49 个版本,首次发布于 2026/05/17;过去 12 个月发布了 49 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.26.0latest2026/11/13今天
0.25.02026/11/13今天
0.24.02026/11/093 天前
0.23.02026/11/057 天前
0.22.02026/11/0310 天前
0.21.02026/11/0112 天前

关于 @dougbots/avenor-core 的常见问题

@dougbots/avenor-core 是什么?

Control socket client, supervisor lifecycle, and tool implementations for the avenor agent runner.

如何安装 @dougbots/avenor-core?

在项目目录运行 npm install @dougbots/avenor-core,或使用 pnpm add / yarn add / bun add。

@dougbots/avenor-core 支持 TypeScript 吗?

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

@dougbots/avenor-core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dougbots/avenor-core 可以商用吗?

@dougbots/avenor-core 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dougbots/avenor-core 的下载量有多少?

根据 npm 官方下载统计,@dougbots/avenor-core 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,350 次,日均约 112 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dougbots/avenor-core 还在维护吗?

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