# @harness-engineering/orchestrator 中文文档

规范地址：https://npmcn.com/package/%40harness-engineering/orchestrator/

版本：0\.30\.0
npm 元数据更新时间：2026-11-17T01:37:28.004Z
中文译文更新时间：2026-11-17T10:49:19.981Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40harness-engineering/orchestrator
原文对照：https://npmcn.com/package/%40harness-engineering/orchestrator/?lang=original
项目主页：https://github.com/Intense-Visions/harness-engineering/tree/main/packages/orchestrator#readme
源码仓库：https://github.com/Intense-Visions/harness-engineering

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：2.5 MB，8 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：18 个
- 首次发布：2026-03-25T02:52:45.989Z
- 最新版本发布：2026-11-17T01:37:27.558Z
- 近 30 天下载量：9477（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：70（近 12 个月 70 个）

## 中文简介

用于向问题发送编码器的 Orchestrator 守护进程

## 安装

```sh
npm install @harness-engineering/orchestrator
```

也可以使用：`pnpm add @harness-engineering/orchestrator`、`yarn add @harness-engineering/orchestrator`、`bun add @harness-engineering/orchestrator`

## README

# @ harness- engineering/ orchestrator (英语)

Orchestrator 守护进程用于向问题发送编码代理. 投出一个用于候选任务的发行跟踪器,管理平面工作空间,运行代理以解决问题,并更新跟踪器的进度.

## 建筑

```
┌──────────────────────────────────────────────────┐
│                 Issue Tracker                     │
│  RoadmapTrackerAdapter · Linear Extension        │
└──────────────────┬───────────────────────────────┘
                   ▼
┌──────────────────────────────────────────────────┐
│           Intelligence Pipeline (optional)        │
│  SEL (spec enrichment) → CML (complexity) →      │
│  ConcernSignals → PESL (simulation + abort)      │
│  (@harness-engineering/intelligence)             │
└──────────────────┬───────────────────────────────┘
                   ▼
┌──────────────────────────────────────────────────┐
│              Core State Machine                   │
│  Candidate Selection · Concurrency Control       │
│  Model Routing (routeIssue + concern signals)    │
│  Reconciliation · Retry Logic                    │
│  Event Sourcing (applyEvent → side effects)      │
└──────────────────┬───────────────────────────────┘
                   ▼
┌────────────────┐  ┌─────────────────┐
│  Agent Runner  │  │   Workspaces    │
│  Claude Backend│  │  WorkspaceManager│
│  Mock Backend  │  │  WorkspaceHooks │
└───────┬────────┘  └────────┬────────┘
        └────────┬───────────┘
                 ▼
┌──────────────────────────────────────────────────┐
│            Prompt Rendering (LiquidJS)           │
└──────────────────────────────────────────────────┘
```

## 快速启动

```ts
import { Orchestrator, WorkflowLoader } from '@harness-engineering/orchestrator';

// Load workflow definition (config + prompt template) from a harness.orchestrator.md file
const loader = new WorkflowLoader();
const result = await loader.loadWorkflow('./harness.orchestrator.md');
if (!result.ok) throw result.error;

const { config, promptTemplate } = result.value;

// Create and start the orchestrator
const orchestrator = new Orchestrator(config, promptTemplate);
await orchestrator.start();
```

## 核心概念

### 事件来源国家机器

管弦乐团采用事件源架构. 所有州的过渡都以事件为模式(`OrchestratorEvent`产生副作用(`SideEffect`:

```ts
import { applyEvent, createEmptyState } from '@harness-engineering/orchestrator';
import type { WorkflowConfig } from '@harness-engineering/types';

const state = createEmptyState(config); // config: WorkflowConfig
const { state: next, effects } = applyEvent(state, event);
// effects: DispatchEffect, StopEffect, ScheduleRetryEffect, etc.
```

### 候选人的甄选

问题在发送前进行排序和过滤:

```ts
import { sortCandidates, selectCandidates, isEligible } from '@harness-engineering/orchestrator';

const ranked = sortCandidates(issues);
const selected = selectCandidates(ranked, availableSlots);
```

### 情报管道整合

何时 `config.intelligence.enabled` 实值 `true`指挥员在每一滴滴中 都运行情报管道:

1.  **预线** 对于每个候选问题, `preprocessIssue()` 运行SEL(光谱浓缩)和CML(复杂分),生产 `ConcernSignal[]` 输入到 `routeIssue()`用于 `alwaysHuman` 分级,丰富谱被附在人类环境的升级上.
2.  **后路线** ——针对本地流出的问题,PESL模拟运行. 若为 `abort: true` (信心 < 0.3), 调度会升级.
3.  **执行后** - 打开 `worker_exit`,将执行结果记录在图表中,用于未来的CML历史评分.

被禁用( 默认) 时, 管道被全部跳过, 路由会使用空关切信号 .

见 [`@harness-engineering/intelligence` 读取](https://npmcn.com/package/%40harness-engineering/intelligence/README.md) 用于整个管道文件.

### 代理后端

有两个后端:

-   **`ClaudeBackend`** 使用 Claude API 生产后端
-   **`MockBackend`** 测试测试中确定性行为的后端

### 工作空间管理

每一次特工运行都会得到一个带有生命周期钩子的电平工作空间:

```ts
import { WorkspaceManager, WorkspaceHooks } from '@harness-engineering/orchestrator';

const manager = new WorkspaceManager(config);
const hooks = new WorkspaceHooks(config);
```

## API 密码

### 整形仪

连接一切的主课:

-   `start()` - 开始投票和调度
-   `stop()` - 顺利地关闭
-   活动 : `state_change`, (中文(简体) ), `agent_event`

### 核心职能

| 导出 | 说明 |
| --- | --- |
| `applyEvent` | 将事件应用到状态, 返回新状态 + 副作用 |
| `createEmptyState` | 创建初始空管弦乐状态 |
| `sortCandidates` | 按优先权和资格划分的排名问题 |
| `selectCandidates` | 在货币限额内选择顶级候选人 |
| `isEligible` | 检查一个问题是否符合发送条件 |
| `getAvailableSlots` | 获取可用的代理位数 |
| `canDispatch` | 检查在当前状态下是否可能发送 |
| `reconcileRunningIssues` | 校正当前追踪器状态的运行问题 |
| `calculateRetryDelayMs` | 计算指数后退延迟, 以毫秒计 |

### 跟踪器适配器

| 导出 | 说明 |
| --- | --- |
| `RoadmapTrackerAdapter` | 阅读问题 `docs/roadmap.md` |
| `LinearTrackerExtension` | 以线性集成扩展跟踪 _(计划)_ |

### 快速渲染

| 导出 | 说明 |
| --- | --- |
| `PromptRenderer` | 代理提示的 Renders LiquidJS 模板 |

## 许可证

麻省理工学院

## 常见问题

### @harness-engineering/orchestrator 是什么？

用于向问题发送编码器的 Orchestrator 守护进程

### 如何安装 @harness-engineering/orchestrator？

在项目目录运行 npm install @harness-engineering/orchestrator，或使用 pnpm add / yarn add / bun add。

### @harness-engineering/orchestrator 支持 TypeScript 吗？

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

### @harness-engineering/orchestrator 支持 ESM 还是 CommonJS？

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

### @harness-engineering/orchestrator 可以商用吗？

@harness-engineering/orchestrator 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @harness-engineering/orchestrator 的下载量有多少？

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

### @harness-engineering/orchestrator 还在维护吗？

最新版本 0\.30\.0 发布于 2026/11/17（今天）；至今共发布 70 个版本，其中过去 12 个月发布了 70 个；首次发布于 2026/03/25。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

